-----------------------------------
-- Area: Lufaise Meadows
--   NM: Padfoot
-- !pos -43.689 0.487 -328.028 24
-- !pos 260.445 -1.761 -27.862 24
-- !pos 412.447 -0.057 -200.161 24
-- !pos -378.950 -15.742 144.215 24
-- !pos -141.523 -15.529 91.709 24
-----------------------------------
local ID = zones[xi.zone.LUFAISE_MEADOWS]
-----------------------------------
---@type TMobEntity
local entity = {}

entity.spawnPoints =
{
    [ID.mob.PADFOOT[1]] =
    {
        { x = -88.575, y = -8.221, z = -272.966 },
        { x = -85.977, y = -8.096, z = -277.417 },
        { x = -80.868, y = -8.000, z = -281.892 },
        { x = -74.162, y = -8.099, z = -289.796 },
        { x = -68.140, y = -7.524, z = -276.522 },
        { x = -64.047, y = -7.936, z = -268.584 },
        { x = -74.623, y = -7.931, z = -256.932 },
        { x = -78.276, y = -7.818, z = -251.188 },
        { x = -81.370, y = -8.021, z = -245.328 },
        { x = -75.793, y = -8.000, z = -243.587 },
        { x = -70.136, y = -8.040, z = -244.463 },
        { x = -65.517, y = -8.017, z = -246.914 },
        { x = -61.487, y = -7.769, z = -250.766 },
        { x = -56.883, y = -7.818, z = -253.699 },
        { x = -49.765, y = -7.680, z = -254.494 },
        { x = -44.834, y = -7.763, z = -249.543 },
        { x = -46.626, y = -8.000, z = -243.454 },
        { x = -52.230, y = -7.496, z = -231.496 },
        { x = -57.321, y = -7.372, z = -221.150 },
        { x = -63.631, y = -7.409, z = -215.153 },
        { x = -68.368, y = -7.332, z = -209.143 },
        { x = -73.650, y = -7.712, z = -203.239 },
        { x = -77.108, y = -8.000, z = -199.196 },
        { x = -81.502, y = -7.948, z = -193.043 },
        { x = -80.431, y = -7.476, z = -186.724 },
        { x = -78.631, y = -7.018, z = -179.644 },
        { x = -72.215, y = -7.490, z = -178.147 },
        { x = -69.414, y = -7.667, z = -182.213 },
        { x = -64.594, y = -7.500, z = -187.363 },
        { x = -60.188, y = -7.187, z = -193.036 },
        { x = -55.436, y = -7.260, z = -199.153 },
        { x = -51.546, y = -7.697, z = -206.094 },
        { x = -46.652, y = -7.368, z = -212.585 },
        { x = -42.978, y = -6.988, z = -218.496 },
        { x = -40.210, y = -7.225, z = -224.098 },
        { x = -36.639, y = -7.447, z = -228.766 },
        { x = -34.087, y = -7.699, z = -234.318 },
        { x = -31.030, y = -7.752, z = -239.399 },
        { x = -27.033, y = -6.569, z = -246.640 },
        { x = -14.856, y = -6.952, z = -245.924 },
        { x = -12.096, y = -7.563, z = -239.475 },
        { x = -10.540, y = -7.526, z = -229.263 },
        { x = -12.520, y = -7.581, z = -221.948 },
        { x = -15.925, y = -7.186, z = -212.567 },
        { x = -16.698, y = -7.219, z = -202.835 },
        { x = -17.935, y = -7.275, z = -193.850 },
        { x = -13.269, y = -7.500, z = -187.850 },
        { x = -4.301,  y = -7.451, z = -186.429 },
        { x = 2.654,   y = -7.879, z = -190.491 },
    },

    [ID.mob.PADFOOT[2]] =
    {
        { x = 69.100,  y = -7.025, z = 19.250   },
        { x = 63.459,  y = -7.607, z = 8.474    },
        { x = 59.649,  y = -7.461, z = -7.462   },
        { x = 68.632,  y = -7.462, z = -19.285  },
        { x = 80.022,  y = -7.606, z = -12.032  },
        { x = 95.135,  y = -7.214, z = -1.257   },
        { x = 107.382, y = -6.778, z = 7.905    },
        { x = 122.022, y = -7.501, z = 12.872   },
        { x = 132.091, y = -8.162, z = 3.367    },
        { x = 130.289, y = -8.500, z = -10.404  },
        { x = 116.819, y = -7.086, z = -20.584  },
        { x = 106.825, y = -7.136, z = -21.108  },
        { x = 97.535,  y = -7.068, z = -28.927  },
        { x = 82.723,  y = -7.781, z = -34.357  },
        { x = 82.275,  y = -7.710, z = -49.802  },
        { x = 95.035,  y = -7.733, z = -47.413  },
        { x = 106.435, y = -7.364, z = -38.932  },
        { x = 115.354, y = -7.864, z = -29.702  },
        { x = 126.921, y = -7.509, z = -18.833  },
        { x = 141.863, y = -8.508, z = -18.329  },
        { x = 137.470, y = -7.598, z = -34.453  },
        { x = 124.874, y = -8.249, z = -47.783  },
        { x = 116.421, y = -7.342, z = -56.451  },
        { x = 106.370, y = -7.134, z = -64.089  },
        { x = 95.269,  y = -6.913, z = -68.633  },
        { x = 83.281,  y = -7.977, z = -78.404  },
        { x = 80.047,  y = -7.154, z = -96.939  },
        { x = 94.718,  y = -7.316, z = -95.076  },
        { x = 108.346, y = -7.627, z = -87.207  },
        { x = 119.140, y = -7.978, z = -77.807  },
        { x = 129.459, y = -8.553, z = -66.172  },
        { x = 132.530, y = -8.500, z = -54.629  },
        { x = 143.121, y = -7.306, z = -49.875  },
        { x = 154.805, y = -7.933, z = -45.097  },
        { x = 157.676, y = -8.000, z = -31.959  },
        { x = 145.868, y = -8.435, z = -27.305  },
        { x = 135.782, y = -7.539, z = -74.903  },
        { x = 128.623, y = -7.130, z = -86.183  },
        { x = 116.899, y = -7.690, z = -90.406  },
        { x = 110.498, y = -7.090, z = -102.915 },
        { x = 101.618, y = -7.052, z = -111.146 },
        { x = 87.314,  y = -7.773, z = -116.710 },
        { x = 98.837,  y = -7.242, z = -126.898 },
        { x = 112.591, y = -7.487, z = -132.320 },
        { x = 118.264, y = -7.550, z = -147.467 },
        { x = 128.881, y = -8.248, z = -155.643 },
        { x = 137.552, y = -8.690, z = -146.332 },
        { x = 112.531, y = -7.109, z = -103.173 },
        { x = 97.837,  y = -7.413, z = -95.469  },
        { x = 93.034,  y = -7.275, z = -83.660  },
    },

    [ID.mob.PADFOOT[3]] =
    {
        { x = 362.510, y = 0.005, z = -200.339 },
        { x = 359.808, y = 0.043, z = -194.843 },
        { x = 358.535, y = 0.368, z = -188.613 },
        { x = 354.727, y = 0.776, z = -181.143 },
        { x = 352.592, y = 0.542, z = -173.704 },
        { x = 346.370, y = 0.531, z = -165.259 },
        { x = 342.727, y = 0.520, z = -152.263 },
        { x = 346.061, y = 0.473, z = -142.207 },
        { x = 353.137, y = 0.790, z = -139.437 },
        { x = 358.597, y = 0.577, z = -146.183 },
        { x = 362.688, y = 0.216, z = -156.206 },
        { x = 365.833, y = 0.374, z = -163.199 },
        { x = 369.278, y = 0.744, z = -176.273 },
        { x = 373.163, y = 0.513, z = -186.458 },
        { x = 374.466, y = 0.544, z = -194.223 },
        { x = 379.831, y = 0.749, z = -204.969 },
        { x = 390.396, y = 0.035, z = -204.216 },
        { x = 387.892, y = 0.638, z = -196.297 },
        { x = 387.043, y = 0.522, z = -187.683 },
        { x = 382.231, y = 0.627, z = -177.436 },
        { x = 381.466, y = 1.053, z = -167.912 },
        { x = 377.572, y = 0.876, z = -160.024 },
        { x = 372.401, y = 0.534, z = -151.387 },
        { x = 369.010, y = 1.049, z = -141.381 },
        { x = 363.812, y = 0.061, z = -129.348 },
        { x = 363.877, y = 0.223, z = -116.206 },
        { x = 364.431, y = 0.945, z = -101.145 },
        { x = 373.598, y = 0.754, z = -94.647  },
        { x = 379.805, y = 0.706, z = -104.458 },
        { x = 388.180, y = 0.238, z = -124.722 },
        { x = 393.761, y = 0.888, z = -136.126 },
        { x = 399.010, y = 0.567, z = -145.777 },
        { x = 406.976, y = 0.081, z = -158.684 },
        { x = 411.877, y = 0.353, z = -175.322 },
        { x = 415.952, y = 0.771, z = -186.673 },
        { x = 419.505, y = 1.159, z = -196.136 },
        { x = 425.723, y = 0.494, z = -205.690 },
        { x = 436.269, y = 0.202, z = -204.016 },
        { x = 439.137, y = 0.152, z = -194.412 },
        { x = 445.120, y = 0.939, z = -181.178 },
        { x = 434.130, y = 0.406, z = -167.885 },
        { x = 436.845, y = 0.123, z = -154.010 },
        { x = 434.516, y = 0.934, z = -141.737 },
        { x = 427.534, y = 0.851, z = -136.407 },
        { x = 431.739, y = 0.208, z = -124.717 },
        { x = 420.004, y = 0.998, z = -116.967 },
        { x = 403.663, y = 0.000, z = -117.257 },
        { x = 398.464, y = 0.774, z = -104.208 },
        { x = 391.999, y = 0.760, z = -94.061  },
        { x = 376.827, y = 0.936, z = -88.724  },
    },

    [ID.mob.PADFOOT[4]] =
    {
        { x = -325.319, y = -16.231, z = 109.389 },
        { x = -324.789, y = -16.072, z = 121.850 },
        { x = -339.076, y = -15.453, z = 130.503 },
        { x = -342.253, y = -15.113, z = 120.352 },
        { x = -345.955, y = -15.530, z = 106.524 },
        { x = -350.027, y = -16.034, z = 83.108  },
        { x = -360.942, y = -16.025, z = 73.854  },
        { x = -369.426, y = -15.712, z = 85.877  },
        { x = -367.696, y = -15.332, z = 97.571  },
        { x = -362.545, y = -15.323, z = 102.510 },
        { x = -358.682, y = -15.939, z = 113.421 },
        { x = -353.164, y = -15.859, z = 121.379 },
        { x = -349.119, y = -15.500, z = 131.966 },
        { x = -357.150, y = -15.164, z = 143.261 },
        { x = -365.765, y = -15.650, z = 133.648 },
        { x = -371.332, y = -15.643, z = 121.343 },
        { x = -386.138, y = -16.649, z = 109.227 },
        { x = -399.076, y = -16.000, z = 113.558 },
        { x = -395.642, y = -15.699, z = 125.302 },
        { x = -389.669, y = -15.098, z = 141.360 },
        { x = -383.733, y = -14.984, z = 156.597 },
        { x = -380.573, y = -15.496, z = 171.710 },
        { x = -394.769, y = -15.160, z = 178.818 },
        { x = -399.010, y = -15.733, z = 169.353 },
        { x = -403.929, y = -15.863, z = 156.510 },
        { x = -406.654, y = -15.098, z = 144.603 },
        { x = -404.275, y = -15.974, z = 128.185 },
        { x = -411.023, y = -15.512, z = 116.397 },
        { x = -422.677, y = -14.595, z = 115.301 },
        { x = -423.356, y = -15.313, z = 123.474 },
        { x = -420.787, y = -15.259, z = 134.824 },
        { x = -417.717, y = -15.318, z = 143.712 },
        { x = -411.529, y = -15.400, z = 152.566 },
        { x = -402.956, y = -15.885, z = 164.009 },
        { x = -397.530, y = -15.651, z = 170.987 },
        { x = -394.758, y = -15.241, z = 181.581 },
        { x = -399.316, y = -15.977, z = 194.638 },
        { x = -407.923, y = -15.656, z = 190.202 },
        { x = -415.607, y = -15.257, z = 178.386 },
        { x = -423.478, y = -15.256, z = 165.526 },
        { x = -431.080, y = -15.067, z = 138.046 },
        { x = -439.231, y = -15.798, z = 127.138 },
        { x = -449.792, y = -16.216, z = 133.637 },
        { x = -448.957, y = -16.740, z = 147.241 },
        { x = -449.725, y = -16.000, z = 158.323 },
        { x = -442.379, y = -15.581, z = 173.685 },
        { x = -439.658, y = -15.914, z = 194.650 },
        { x = -417.977, y = -15.102, z = 200.772 },
        { x = -409.828, y = -15.544, z = 190.020 },
        { x = -402.453, y = -14.879, z = 180.504 },
    },

    [ID.mob.PADFOOT[5]] =
    {
        { x = -130.337, y = -15.392, z = 53.742  },
        { x = -124.195, y = -15.496, z = 56.344  },
        { x = -115.969, y = -15.762, z = 60.643  },
        { x = -118.774, y = -15.822, z = 72.432  },
        { x = -134.336, y = -16.500, z = 66.666  },
        { x = -146.804, y = -16.165, z = 65.926  },
        { x = -155.453, y = -15.500, z = 67.191  },
        { x = -152.513, y = -16.000, z = 75.550  },
        { x = -141.692, y = -15.420, z = 78.296  },
        { x = -130.449, y = -15.500, z = 87.314  },
        { x = -122.514, y = -15.059, z = 97.170  },
        { x = -124.760, y = -15.747, z = 107.962 },
        { x = -134.562, y = -15.427, z = 102.393 },
        { x = -144.789, y = -15.268, z = 94.676  },
        { x = -154.226, y = -15.589, z = 84.894  },
        { x = -163.871, y = -16.068, z = 70.740  },
        { x = -179.486, y = -14.525, z = 74.531  },
        { x = -175.200, y = -15.282, z = 89.553  },
        { x = -168.967, y = -15.295, z = 99.438  },
        { x = -163.277, y = -15.512, z = 110.166 },
        { x = -173.942, y = -15.410, z = 123.591 },
        { x = -183.698, y = -15.031, z = 113.707 },
        { x = -187.491, y = -15.111, z = 99.545  },
        { x = -190.147, y = -15.708, z = 81.589  },
        { x = -197.922, y = -15.714, z = 74.599  },
        { x = -202.372, y = -15.858, z = 83.986  },
        { x = -205.030, y = -15.297, z = 96.539  },
        { x = -205.375, y = -15.382, z = 107.930 },
        { x = -206.721, y = -15.919, z = 118.958 },
        { x = -202.156, y = -15.931, z = 127.320 },
        { x = -199.794, y = -15.187, z = 136.276 },
        { x = -201.416, y = -15.687, z = 151.397 },
        { x = -212.317, y = -15.295, z = 151.462 },
        { x = -214.115, y = -15.478, z = 141.150 },
        { x = -229.502, y = -15.400, z = 133.412 },
        { x = -235.808, y = -15.801, z = 146.404 },
        { x = -254.526, y = -15.500, z = 130.307 },
        { x = -260.286, y = -15.077, z = 115.027 },
        { x = -247.547, y = -15.468, z = 104.485 },
        { x = -234.972, y = -15.561, z = 86.440  },
        { x = -216.514, y = -15.158, z = 85.257  },
        { x = -197.868, y = -15.669, z = 73.461  },
        { x = -208.389, y = -15.591, z = 66.559  },
        { x = -222.931, y = -16.397, z = 63.935  },
        { x = -237.041, y = -15.570, z = 62.783  },
        { x = -242.312, y = -15.705, z = 52.356  },
        { x = -234.127, y = -16.000, z = 39.332  },
        { x = -232.092, y = -16.170, z = 30.354  },
        { x = -227.212, y = -15.182, z = 96.178  },
        { x = -225.557, y = -15.151, z = 113.588 },
    }
}

entity.onMobInitialize = function(mob)
    xi.mob.updateNMSpawnPoint(mob)

    mob:addListener('ITEM_DROPS', 'ITEM_DROPS_PADFOOT', function(mobArg, loot)
        if mob:getID() == ID.mob.PADFOOT[GetServerVariable('realPadfoot')] then
            loot:addGroup(xi.drop_rate.GUARANTEED,
            {
                { item = xi.item.ASSAILANTS_RING, weight = 750 },
                { item = xi.item.ASTRAL_EARRING, weight = 250 },
            })
        else
            loot:addItem(xi.item.SHEEPSKIN, xi.drop_rate.VERY_COMMON)
            loot:addItem(xi.item.LANOLIN_CUBE, xi.drop_rate.GUARANTEED)
        end
    end)
end

entity.onMobDeath = function(mob, player, optParams)
end

entity.onMobDespawn = function(mob)
    local mobId = mob:getID()

    if mobId == ID.mob.PADFOOT[GetServerVariable('realPadfoot')] then
        local respawn = math.random(75600, 86400) -- 21-24 hours

        for _, v in pairs(ID.mob.PADFOOT) do
            if v ~= mobId and GetMobByID(v):isSpawned() then
                DespawnMob(v)
            end

            xi.mob.updateNMSpawnPoint(v)
            GetMobByID(v):setRespawnTime(respawn)
        end

        SetServerVariable('realPadfoot', math.random(1, 5))
    end
end

return entity
