-----------------------------------
-- Area: Jugner Forest
--   NM: Fraelissa
-----------------------------------
local ID = zones[xi.zone.JUGNER_FOREST]
-----------------------------------
---@type TMobEntity
local entity = {}

local fraelissaSpawnPoints =
{
    { x = -36.053, y = -7.943, z = -485.956 },
    { x = -32.552, y = -9.002, z = -474.435 },
    { x = -30.207, y = -5.549, z = -460.885 },
    { x = -35.174, y = -1.684, z = -450.960 },
    { x = -31.886, y = -1.752, z = -438.911 },
    { x = -29.480, y = -2.939, z = -430.934 },
    { x = -26.718, y = -2.825, z = -422.256 },
    { x = -23.777, y = -1.446, z = -411.779 },
    { x = -15.372, y = -0.368, z = -406.452 },
    { x = -12.130, y = 0.187,  z = -398.014 },
    { x = -6.504,  y = 0.375,  z = -392.454 },
    { x = -1.621,  y = 0.709,  z = -385.107 },
    { x = 3.343,   y = 0.918,  z = -378.388 },
    { x = 9.320,   y = -0.493, z = -371.654 },
    { x = 14.527,  y = -0.063, z = -366.150 },
    { x = 22.521,  y = 0.826,  z = -359.849 },
    { x = 30.066,  y = 0.252,  z = -352.284 },
    { x = 36.316,  y = 0.768,  z = -341.293 },
    { x = 41.044,  y = 0.273,  z = -329.481 },
    { x = 43.361,  y = 0.000,  z = -318.522 },
    { x = 44.656,  y = 0.331,  z = -304.552 },
    { x = 45.279,  y = 0.050,  z = -291.648 },
    { x = 46.312,  y = -0.926, z = -280.252 },
    { x = 48.866,  y = -1.170, z = -266.033 },
    { x = 54.975,  y = -1.694, z = -253.984 },
    { x = 67.137,  y = -1.422, z = -248.949 },
    { x = 76.573,  y = -0.901, z = -246.241 },
    { x = 87.343,  y = 0.058,  z = -244.344 },
    { x = 98.928,  y = 0.658,  z = -237.993 },
    { x = 110.255, y = 0.275,  z = -233.674 },
    { x = 122.516, y = 0.111,  z = -233.906 },
    { x = 133.046, y = 0.534,  z = -238.654 },
    { x = 142.354, y = 0.881,  z = -241.905 },
    { x = 148.066, y = -0.522, z = -249.350 },
    { x = 152.090, y = -0.560, z = -257.402 },
    { x = 153.926, y = -0.298, z = -266.347 },
    { x = 155.073, y = -0.349, z = -274.829 },
    { x = 156.954, y = -0.013, z = -283.759 },
    { x = 161.421, y = 0.521,  z = -292.341 },
    { x = 166.312, y = -0.448, z = -302.504 },
    { x = 174.128, y = 0.571,  z = -309.110 },
    { x = 182.766, y = 0.446,  z = -316.806 },
    { x = 190.242, y = 0.038,  z = -325.548 },
    { x = 195.769, y = 0.589,  z = -334.999 },
    { x = 196.908, y = 0.684,  z = -345.119 },
    { x = 197.572, y = 0.000,  z = -356.353 },
    { x = 197.987, y = -3.632, z = -376.425 },
    { x = 200.561, y = -6.615, z = -389.385 },
    { x = 202.317, y = -8.000, z = -402.152 },
    { x = 202.223, y = -7.582, z = -420.354 },
}

local updateRegen = function(mob)
    local hour = VanadielHour()
    if hour >= 4 and hour < 20 then
        mob:setMod(xi.mod.REGEN, 25)
    else
        mob:setMod(xi.mod.REGEN, 0)
    end
end

entity.onMobInitialize = function(mob)
    xi.mob.updateNMSpawnPoint(mob, fraelissaSpawnPoints)
    mob:setRespawnTime(math.random(3600, 4500)) -- 60 to 75 minutes
end

entity.onMobSpawn = function(mob)
    updateRegen(mob)
end

entity.onMobFight = function(mob)
    updateRegen(mob)
end

entity.onMobRoam = function(mob)
    updateRegen(mob)
end

entity.onMobDeath = function(mob, player, optParams)
    xi.hunts.checkHunt(mob, player, 158)
end

entity.onMobDespawn = function(mob)
    xi.mob.updateNMSpawnPoint(mob, fraelissaSpawnPoints)

    local params = { }

    if not xi.mob.phOnDespawn(mob, ID.mob.FRADUBIO, 10, 75600, params) then -- 21 hour minimum
        mob:setRespawnTime(math.random(3600, 4500)) -- 60 to 75 minutes
    end
end

return entity
