<?php
include_once $PATH_TO_CODE."/script/tick/allincludefortick.php";
class EarthquakeTick extends TickRunnable {
public function getName() {
return "Ground collapse";
}
public function run() {
$this->trapDiedAwayHome();
$res=executer("SELECT zoneId FROM zone
WHERE
(zoneType = ".Constante::$ZONE_TYPE_PLAIN."
AND RAND() < 0.01)
OR
(zoneType=".DungeonConstante::$ZONE_TYPE_ROAD."
AND RAND() < 0.001)
OR
(zoneType=".DungeonConstante::$ZONE_TYPE_DOOR."
AND RAND() < 0.0001)
OR
(zoneType=".DungeonConstante::$ZONE_TYPE_STAIR."
AND RAND() < 0.0001)
");
global $gloObjectManager;
while($row=mysql_fetch_array($res)) {
$locZoneId = $row[0];
$locZone = $gloObjectManager->getZone($locZoneId);
if($locZone->isSurface()) {
Log::debug("No earthquake on $locZoneId, caused by: surface, use bottom zone");
$locZone = $locZone->getBottomZone();
}
if($locZone->isEarthquakable()) {
$locBlock = $gloObjectManager->getBlock($locZone->blockId);
if($locBlock->allianceId > 1) {
if(rand(1, 100) <= 99) {//99% of do nothing
continue;
}
}
Log::info("Earthquake on $locZoneId with strengh ".($locZone->getRockStrength())." and zone type ".$locZone->zoneType);
$locBlock = $gloObjectManager->getBlock($locZone->blockId);
$locZone->setZoneType(DungeonConstante::$ZONE_TYPE_ROCK);
} else {
Log::debug("No earthquake on $locZoneId, caused by: not earthquakable");
}
}
}
public function trapDiedAwayHome() {
global $gloObjectManager;
$res = executer("SELECT objectId
FROM object, block
WHERE object.objectType=".DungeonConstante::$REAL_OBJECT_TYPE_TRAP."
AND object.blockId=block.blockId
AND object.allianceId <> block.allianceId
AND 0.01 >= RAND()");
while($row=mysql_fetch_array($res)) {
$locObjectId = $row[0];
$locObject = $gloObjectManager->getRealObject($locObjectId);
$locObject->kill(false);
PlayerMessage::getInstance()->addPlayerInfo($locObject->playerId, "trap is broken because it is outside of your land", PlayerMessage::$BAD, $locObject->zoneId);
}
}
}
?>