-----------------------------------
-- Area: Eastern Altepa Desert
-- NM  : Cactrot Rapido
-----------------------------------
---@type TMobEntity
local entity = {}

local pathNodes =
{
    { x = -45, y = 0, z = -204 },
    { x = -99, y = 0, z = -179 },
    { x = -100, y = -1, z = -179 },
    { x = -103, y = -2, z = -178 },
    { x = -105, y = -3, z = -178 },
    { x = -110, y = -4, z = -177 },
    { x = -111, y = -5, z = -177 },
    { x = -116, y = -4, z = -176 },
    { x = -120, y = -3, z = -173 },
    { x = -122, y = -2, z = -171 },
    { x = -127, y = 0, z = -166 },
    { x = -136, y = 3, z = -153 },
    { x = -138, y = 3, z = -149 },
    { x = -140, y = 4, z = -142 },
    { x = -141, y = 4, z = -140 },
    { x = -141, y = 5, z = -138 },
    { x = -143, y = 5, z = -117 },
    { x = -144, y = 3, z = -110 },
    { x = -144, y = 2, z = -109 },
    { x = -144, y = 1, z = -107 },
    { x = -144, y = 0, z = -106 },
    { x = -144, y = 0, z = -105 },
    { x = -143, y = -1, z = -103 },
    { x = -142, y = -2, z = -102 },
    { x = -141, y = -1, z = -99 },
    { x = -140, y = 0, z = -96 },
    { x = -136, y = 1, z = -89 },
    { x = -133, y = 2, z = -83 },
    { x = -129, y = 1, z = -75 },
    { x = -126, y = 0, z = -69 },
    { x = -109, y = 0, z = -33 },
    { x = -104, y = -2, z = -24 },
    { x = -101, y = -3, z = -18 },
    { x = -97, y = -5, z = -11 },
    { x = -94, y = -7, z = -6 },
    { x = -87, y = -8, z =  8 },
    { x = -82, y = -10, z = 17 },
    { x = -78, y = -12, z = 24 },
    { x = -74, y = -13, z = 25 },
    { x = -69, y = -12, z = 25 },
    { x = -50, y = -13, z = 23 },
    { x = -44, y = -12, z = 22 },
    { x = -23, y = -12, z = 21 },
    { x = -18, y = -11, z = 20 },
    { x = -15, y = -11, z = 20 },
    { x = -10, y = -11, z = 20 },
    { x = -5, y = -11, z = 20 },
    { x = -2, y = -11, z = 20 },
    { x = 1, y =  -11, z = 20 },
    { x = 8, y =  -12, z = 19 },
    { x = 12, y = -13, z = 18 },
    { x = 16, y = -15, z = 17 },
    { x = 20, y = -16, z = 16 },
    { x = 23, y = -17, z = 16 },
    { x = 25, y = -16, z = 15 },
    { x = 27, y = -14, z = 15 },
    { x = 29, y = -13, z = 15 },
    { x = 32, y = -11, z = 14 },
    { x = 35, y = -10, z = 13 },
    { x = 38, y = -9, z =  12 },
    { x = 45, y = -8, z =  10 },
    { x = 59, y = -7, z =  5 },
    { x = 92, y = -7, z = -9 },
    { x = 95, y = -8, z = -12 },
    { x = 102, y = -8, z = -16 },
    { x = 105, y = -9, z = -19 },
    { x = 106, y = -9, z = -20 },
    { x = 107, y = -10, z = -21 },
    { x = 110, y = -11, z = -23 },
    { x = 112, y = -11, z = -25 },
    { x = 116, y = -10, z = -28 },
    { x = 116, y = -9, z = -29 },
    { x = 123, y = -8, z = -39 },
    { x = 124, y = -7, z = -41 },
    { x = 130, y = -7, z = -61 },
    { x = 129, y = -8, z = -66 },
    { x = 120, y = -8, z = -80 },
    { x = 119, y = -8, z = -81 },
    { x = 114, y = -7, z = -83 },
    { x = 100, y = -7, z = -87 },
    { x = 78, y = -9, z = -92 },
    { x = 74, y = -9, z = -96 },
    { x = 72, y = -10, z = -100 },
    { x = 65, y = -12, z = -110 },
    { x = 57, y = -12, z = -123 },
    { x = 54, y = -11, z = -129 },
    { x = 51, y = -12, z = -133 },
    { x = 47, y = -13, z = -138 },
    { x = 45, y = -14, z = -140 },
    { x = 45, y = -13, z = -142 },
    { x = 43, y = -12, z = -144 },
    { x = 42, y = -11, z = -146 },
    { x = 36, y = -8, z = -154 },
    { x = 33, y = -7, z = -159 },
    { x = 28, y = -7, z = -167 },
    { x = 22, y = -4, z = -177 },
    { x = 20, y = -3, z = -180 },
    { x = 19, y = -3, z = -182 },
    { x = 14, y = -2, z = -183 },
    { x = 13, y = -1, z = -184 },
    { x = -5, y = -1, z = -188 },
    { x = -10, y = 0, z = -189 },
    { x = -21, y = 0, z = -194 },
    { x = -29, y = 0, z = -198 },
    { x = -40, y = 0, z = -203 },
}

entity.spawnPoints =
{
    { x =  -43.733, y =   0.029, z =  -205.890 },
    { x =  -26.834, y =  -2.920, z =  -183.684 },
    { x =   72.849, y =  -7.547, z =  -207.622 },
    { x =  225.075, y =  -5.462, z =   -73.460 },
    { x =   97.334, y = -13.890, z =  -116.290 },
    { x =   21.130, y = -20.765, z =   143.381 },
    { x =  167.395, y =  -7.425, z =  -230.588 },
    { x =  209.036, y =  -8.379, z =   -64.954 },
    { x =   62.594, y = -18.367, z =   119.870 },
    { x =   -7.862, y = -14.669, z =   184.072 },
    { x =  204.896, y =   0.044, z =     3.060 },
    { x =  129.604, y =  -8.359, z =   -69.037 },
    { x =   48.970, y =  -9.183, z =  -157.981 },
    { x =  147.488, y =  -7.989, z =   107.295 },
    { x =  199.520, y =  -0.495, z =    -7.907 },
    { x =   59.675, y = -14.091, z =  -155.496 },
    { x =   37.798, y = -22.609, z =   136.094 },
    { x =   -0.093, y = -16.000, z =   196.311 },
    { x =  -36.339, y =   0.000, z =  -196.558 },
    { x =   10.562, y =  -7.763, z =  -153.151 },
    { x =   47.843, y = -21.390, z =   129.461 },
    { x =  212.223, y =  -5.971, z =  -202.506 },
    { x =   91.295, y = -22.441, z =  -133.185 },
    { x =  -36.339, y =   0.000, z =  -196.558 },
    { x =  -36.339, y =   0.000, z =  -196.558 },
    { x =  204.107, y =  -8.062, z =    85.677 },
    { x =   61.654, y =  -7.113, z =  -202.886 },
    { x =  144.240, y = -12.902, z =   149.280 },
    { x =  228.024, y =  -9.949, z =    74.323 },
    { x =  148.003, y =  -9.460, z =    28.999 },
    { x =  195.466, y =  -2.154, z =  -225.452 },
    { x =   69.335, y = -19.906, z =  -150.315 },
    { x =  259.785, y =  -1.055, z =   -58.388 },
    { x =  148.563, y =  -9.651, z =    16.788 },
    { x =   38.579, y =  -8.000, z =  -159.953 },
    { x =   25.823, y = -15.431, z =   155.779 },
    { x =  121.918, y =  -8.169, z =   -85.653 },
    { x =  297.468, y =   0.181, z =  -109.136 },
    { x =  117.167, y = -15.802, z =   154.863 },
    { x =  198.270, y =  -7.032, z =   -59.389 },
    { x =  149.410, y = -10.013, z =    -1.530 },
    { x =   16.300, y = -16.153, z =   177.281 },
    { x =   -1.399, y = -15.415, z =   173.901 },
    { x =  105.762, y = -11.687, z =  -109.258 },
    { x =  143.842, y = -11.473, z =    58.988 },
    { x =   -8.384, y =  -9.174, z =  -163.234 },
    { x =  225.180, y =  -4.675, z =    47.242 },
    { x =  -44.821, y =   0.040, z =  -204.137 },
    { x =  280.895, y =   0.000, z =   -40.171 },
    { x =   90.956, y = -14.351, z =   119.106 },
}

entity.onMobInitialize = function(mob)
    xi.mob.updateNMSpawnPoint(mob)
    mob:setRespawnTime(math.random(172800, 259200)) -- When server restarts, reset timer
end

entity.onMobSpawn = function(mob)
    mob:setMobMod(xi.mobMod.ONE_WAY_LINKING, 1)
    mob:setBaseSpeed(72)
    mob:setAnimationSpeed(180)
    mob:pathThrough(pathNodes, bit.bor(xi.path.flag.PATROL, xi.path.flag.RUN))
end

entity.onMobDisengage = function(mob)
    mob:setAnimationSub(5)
end

entity.onMobEngage = function(mob, target)
    mob:setAnimationSub(0)
end

entity.onMobDeath = function(mob, player, optParams)
    player:addTitle(xi.title.CACTROT_DESACELERADOR)
end

entity.onMobDespawn = function(mob)
    xi.mob.updateNMSpawnPoint(mob)
    mob:setRespawnTime(math.random(172800, 259200)) -- 2 to 3 days
end

return entity
