@@ -1283,63 +1283,70 @@ function Player:resetTaints(skipCheckTime)
12831283end
12841284
12851285function Monster :tryTeleportToPlayer (sayMessage )
1286+ if math.random (100 ) > 10 then
1287+ return
1288+ end
1289+
12861290 local range = 30
1287- local spectators = Game .getSpectators (self :getPosition (), false , false , range , range , range , range )
1291+ local selfPos = self :getPosition ()
1292+
1293+ local spectators = Game .getSpectators (selfPos , false , true , range , range , range , range )
12881294 local maxDistance = 0
12891295 local farthestPlayer = nil
12901296
1291- for i , spectator in ipairs (spectators ) do
1292- if spectator :isPlayer () then
1293- local player = spectator :getPlayer ()
1294- if player :getTaintNameByNumber (1 ) and player :getSoulWarZoneMonster () ~= nil then
1295- local distance = self :getPosition ():getDistance (player :getPosition ())
1296- if distance > maxDistance then
1297- maxDistance = distance
1298- farthestPlayer = player
1299- logger .trace (" Found player {} to teleport" , player :getName ())
1300- end
1297+ for i = 1 , # spectators do
1298+ local player = spectators [i ]
1299+ if player and player :getTaintNameByNumber (1 ) and player :getSoulWarZoneMonster () ~= nil then
1300+ local playerPos = player :getPosition ()
1301+ local distance = selfPos :getDistance (playerPos )
1302+ if distance > maxDistance then
1303+ maxDistance = distance
1304+ farthestPlayer = player
1305+ logger .trace (" Found player {} to teleport" , player :getName ())
13011306 end
13021307 end
13031308 end
13041309
1305- if farthestPlayer and math.random (100 ) <= 10 then
1306- local playerPosition = farthestPlayer :getPosition ()
1307- if TaintTeleportCooldown [farthestPlayer :getId ()] then
1308- logger .trace (" Cooldown is active to player {}" , farthestPlayer :getName ())
1310+ if not farthestPlayer then
1311+ return
1312+ end
1313+
1314+ if TaintTeleportCooldown [farthestPlayer :getId ()] then
1315+ logger .trace (" Cooldown is active to player {}" , farthestPlayer :getName ())
1316+ return
1317+ end
1318+
1319+ TaintTeleportCooldown [farthestPlayer :getId ()] = true
1320+
1321+ logger .trace (" Scheduling player {} to teleport" , farthestPlayer :getName ())
1322+ selfPos :sendMagicEffect (CONST_ME_MORTAREA )
1323+ farthestPlayer :getPosition ():sendMagicEffect (CONST_ME_MORTAREA )
1324+
1325+ addEvent (function (playerId , monsterId , sayText )
1326+ local monsterEvent = Monster (monsterId )
1327+ local playerEvent = Player (playerId )
1328+ if not monsterEvent or not playerEvent then
13091329 return
13101330 end
13111331
1312- if not TaintTeleportCooldown [farthestPlayer :getId ()] then
1313- TaintTeleportCooldown [farthestPlayer :getId ()] = true
1314-
1315- logger .trace (" Scheduling player {} to teleport" , farthestPlayer :getName ())
1316- self :getPosition ():sendMagicEffect (CONST_ME_MORTAREA )
1317- farthestPlayer :getPosition ():sendMagicEffect (CONST_ME_MORTAREA )
1318- addEvent (function (playerId , monsterId )
1319- local monsterEvent = Monster (monsterId )
1320- local playerEvent = Player (playerId )
1321- if monsterEvent and playerEvent then
1322- local destinationTile = Tile (playerPosition )
1323- if destinationTile and not (destinationTile :hasProperty (CONST_PROP_BLOCKPROJECTILE ) or destinationTile :hasProperty (CONST_PROP_MOVEABLE )) then
1324- monsterEvent :say (sayMessage )
1325- monsterEvent :getPosition ():sendMagicEffect (CONST_ME_TELEPORT )
1326- monsterEvent :teleportTo (playerPosition , true )
1327- monsterEvent :getPosition ():sendMagicEffect (CONST_ME_TELEPORT )
1328- end
1329- end
1330- end , 2000 , farthestPlayer :getId (), self :getId ())
1331-
1332- addEvent (function (playerId )
1333- local playerEvent = Player (playerId )
1334- if not playerEvent then
1335- return
1336- end
1332+ local destinationPos = playerEvent :getPosition ()
1333+ local destinationTile = Tile (destinationPos )
1334+ if destinationTile and not (destinationTile :hasProperty (CONST_PROP_BLOCKPROJECTILE ) or destinationTile :hasProperty (CONST_PROP_MOVEABLE )) then
1335+ monsterEvent :say (sayText )
1336+ monsterEvent :getPosition ():sendMagicEffect (CONST_ME_TELEPORT )
1337+ monsterEvent :teleportTo (destinationPos , true )
1338+ monsterEvent :getPosition ():sendMagicEffect (CONST_ME_TELEPORT )
1339+ end
1340+ end , 2000 , farthestPlayer :getId (), self :getId (), sayMessage )
13371341
1338- logger .trace (" Cleaning player cooldown" )
1339- TaintTeleportCooldown [playerEvent :getId ()] = nil
1340- end , 10000 , farthestPlayer :getId ())
1342+ addEvent (function (playerId )
1343+ local playerEvent = Player (playerId )
1344+ if not playerEvent then
1345+ return
13411346 end
1342- end
1347+ logger .trace (" Cleaning player cooldown" )
1348+ TaintTeleportCooldown [playerEvent :getId ()] = nil
1349+ end , 10000 , farthestPlayer :getId ())
13431350end
13441351
13451352function Monster :getSoulWarKV ()
0 commit comments