<?php
include_once $PATH_TO_CODE."/script/zone.class.php";
include_once $PATH_TO_CODE."/script/imagemanager.class.php";
include_once $PATH_TO_CODE."/script/weapon.class.php";
include_once $PATH_TO_CODE."/script/log.class.php";
include_once $PATH_TO_CODE."/script/event/realobjectmoveevent.class.php";
class RealObject
{
//<isLobotomize value>
public static $UNIT_IS_NOT_LOBOTOMIZE = 0;
public static $UNIT_IS_LOBOTOMIZE = 1;
public static $UNIT_IS_DEAD = 2;
//</isLobotomize value>
public static $REAL_OBJECT_VISIBLE_STATE_VISIBLE_BY_ALL = 0;
public static $REAL_OBJECT_VISIBLE_STATE_VISIBLE_BY_ALLIANCE = 1;
//Type2 is type of graphic
public static $REAL_OBJECT_INFO_TYPE1_GRAPHIC=1;
public static $REAL_OBJECT_INFO_TYPE1_COUNTER=2;
public static $REAL_OBJECT_INFO_TYPE2_LOBOTOMIZE_TIME=0;
//Il n'existe qu'un seul type de point d'action
public static $REAL_OBJECT_INFO_TYPE1_ACTION_POINT=1000;
public static $REAL_OBJECT_INFO_TYPE1_ACTION_COST=1001;
public static $REAL_OBJECT_INFO_TYPE2_ACTION_POINT=1000;
public static $REAL_OBJECT_INFO_TYPE2_ACTION_MOVE_COST=1001;
public static $REAL_OBJECT_INFO_TYPE2_ACTION_DIG_COST=1003;
public static $REAL_OBJECT_INFO_TYPE2_ACTION_SEARCH_TRAP_COST=1006;
public static $REAL_OBJECT_INFO_TYPE2_MAX_POINT=1004;
public static $REAL_OBJECT_INFO_TYPE2_CURRENT_POINT=1005;
public static $REAL_OBJECT_INFO_TYPE1_FIGHT_ACTION_POINT=1010;
public static $REAL_OBJECT_INFO_TYPE2_FIGHT_ACTION_POINT=1010;
public static $REAL_OBJECT_INFO_TYPE2_ACTION_FIGHT_COST=1011;
public static $REAL_OBJECT_INFO_TYPE1_COST=1012;
public static $REAL_OBJECT_INFO_TYPE2_CURRENT_UPKEEP_COST=1013;
//Note Type 2 is used to weapon number
public static $REAL_OBJECT_INFO_TYPE1_WEAPON_COUNT=10000;
public static $REAL_OBJECT_INFO_TYPE1_AIM_PERCENT_START_FIRE=10001;
public static $REAL_OBJECT_INFO_TYPE1_SHOOTING_RANGE=10002;
public static $REAL_OBJECT_INFO_TYPE1_TARGET_OBJECT_ID=10003;
public static $REAL_OBJECT_INFO_TYPE1_WEAPON_TYPE=10004;
public static $REAL_OBJECT_INFO_TYPE1_AIM_ACCURENCY=10005;
public static $REAL_OBJECT_INFO_TYPE1_LIFE_POINT=10006;
public static $REAL_OBJECT_INFO_TYPE1_SHIELD_POINT=10007;
public static $REAL_OBJECT_INFO_TYPE1_WEAPON_DAMAGE=10008;
//Trier par ordre d'affichage ! (le plus petit nombre s'affiche en premier)
public static $REAL_OBJECT_INFO_VALUE_BACKGROUND_IMAGE=20001;
public static $REAL_OBJECT_INFO_VALUE_TEMPORARY_IMAGE=20002;
public static $REAL_OBJECT_INFO_VALUE_DEFAULT_IMAGE=20003;
public static $REAL_OBJECT_INFO_VALUE_RIP_IMAGE=20004;
public static $REAL_OBJECT_INFO_VALUE_EXPLOSION_TYPE_1_IMAGE=29999;
public static $REAL_OBJECT_INFO_VALUE_HURT_TYPE_1_IMAGE=29998;
public static $REAL_OBJECT_INFO_VALUE_HURT_TYPE_2_IMAGE=29997;
public static $REAL_OBJECT_INFO_VALUE_HURT_TYPE_3_IMAGE=29996;
public static $REAL_OBJECT_INFO_VALUE_HURT_TYPE_4_IMAGE=29995;
public static $REAL_OBJECT_INFO_VALUE_HURT_TYPE_HIT_IMAGE=29994;
//IA Mode
public static $IA_MODE_NO = 0;
public static $IA_MODE_LOBOTOMIZE = 1;
public static $IA_MODE_STATIC = 5;
public static $IA_MODE_LOW = 10;
public static $IA_MODE_MEDIUM = 100;
public static $IA_MODE_MEDIUM_AGRESSIVE = 101;
public static $IA_MODE_HIGH = 1000;
private $moveAlgo=false;
public function __construct($parObjectInfo) {
$this->realObjectId = $parObjectInfo[0];
$this->debug("__construct", "");
$this->initObject($parObjectInfo);
}
public static function getStaticObjectSQLRaw($parRealObjectId) {
return mysql_fetch_array(executer("SELECT objectId, blockId, zoneId, objectType, displayPriority, moveIndex,
timestamp, isBackground, playerId, allianceId, isLobotomize, visibleState, timeInMsSinceNoDecision, timeInMsBeforeADecision,
isBattling, IAMode, heroMode
FROM object WHERE objectId=$parRealObjectId"));
}
public static function getStaticObjectsSQLRes($parRealObjectIds) {
if(count($parRealObjectIds) == 0) {
return executer("SELECT 1 FROM object WHERE false");
} else {
return executer("SELECT objectId, blockId, zoneId, objectType, displayPriority, moveIndex,
timestamp, isBackground, playerId, allianceId, isLobotomize, visibleState, timeInMsSinceNoDecision, timeInMsBeforeADecision,
isBattling, IAMode, heroMode
FROM object FORCE KEY(PRIMARY) WHERE objectId IN ".getWhereClauseList($parRealObjectIds));
}
}
protected function initObject($parObjectInfo) {
$this->blockId = $parObjectInfo[1];
$this->zoneId = $parObjectInfo[2];
$this->realObjectType = $parObjectInfo[3];
$this->displayPriority = $parObjectInfo[4];
$this->moveIndex = $parObjectInfo[5];
$this->timestamp = $parObjectInfo[6];
$this->isBackground = $parObjectInfo[7];
$this->playerId = $parObjectInfo[8];
$this->allianceId = $parObjectInfo[9];
$this->isLobotomize = $parObjectInfo[10];
$this->visibleState = $parObjectInfo[11];
$this->timeInMsSinceNoDecision = $parObjectInfo[12];
$this->timeInMsBeforeADecision = $parObjectInfo[13];
$this->isBattling = $parObjectInfo[14];
$this->IAMode = $parObjectInfo[15];
$this->heroMode = $parObjectInfo[16];
}
public static function createObject($parObjectType,
$parPlayer, $parZone, $parObjectCategory, $parIsLobotomize=false, $parDisplayPriority=1,
$parVisibleState=0, $parCanTakeControl=1) {
executer("INSERT INTO `object` ( `objectType` , blockId, `zoneId`, displayPriority, isBackground, timestamp, playerId, allianceId, category, isLobotomize, visibleState, canTakeControl) VALUES
($parObjectType, $parZone->blockId, $parZone->zoneId, $parDisplayPriority, 0, ".time().", $parPlayer->playerId, "
.$parPlayer->allianceId.",$parObjectCategory, ".($parIsLobotomize?"1":"0").", $parVisibleState, $parCanTakeControl)");
$locObjectId = getLastInsertedId();
executer("INSERT INTO objectInfo(objectId, type1, type2, value) VALUES (
$locObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_WEAPON_COUNT.",
".RealObject::$REAL_OBJECT_INFO_TYPE1_WEAPON_COUNT.",
0)");
return $locObjectId;
}
/**Add one to weapon count and add this weapon to $parObjectId object*/
public static function insertWeapon($parObjectId, $locWeaponNumber, $parAimPercentStartFire,
$parAimAccurency, $parShootingRange, $parWeaponType,
$parWeaponDamage) {
executer("UPDATE objectInfo SET value=value+1
WHERE objectId=$parObjectId
AND type1=".RealObject::$REAL_OBJECT_INFO_TYPE1_WEAPON_COUNT."
AND type2=".RealObject::$REAL_OBJECT_INFO_TYPE1_WEAPON_COUNT);
executer("INSERT INTO objectInfo(objectId, type1, type2, value) VALUES
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_AIM_PERCENT_START_FIRE.",
$locWeaponNumber,
$parAimPercentStartFire),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_AIM_ACCURENCY.",
$locWeaponNumber,
$parAimAccurency),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_SHOOTING_RANGE.",
$locWeaponNumber,
$parShootingRange
),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_WEAPON_TYPE.",
$locWeaponNumber,
$parWeaponType
),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_TARGET_OBJECT_ID.",
$locWeaponNumber,
0),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_WEAPON_DAMAGE.",
$locWeaponNumber,
$parWeaponDamage)");
}
public static function insertObjectInfo($parObjectId, $parType1, $parType2, $parValue) {
executer("INSERT INTO objectInfo(objectId, type1, type2, value) VALUES
($parObjectId,
$parType1,
$parType2,
$parValue)");
}
public static function insertInfo($parObjectId, $parMaxPoint, $parLifePoint, $parShield,
$parMaxActionPoint,
$parMaxFightPoint,
$parMoveCost, $parDigCost, $parFightCost, $parLobotomizeCounter=0) {
$locReqIsLobotomize="";
if($parLobotomizeCounter > 0) {
$locReqIsLobotomize = "($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_COUNTER.",
".RealObject::$REAL_OBJECT_INFO_TYPE2_LOBOTOMIZE_TIME.",
$parLobotomizeCounter),";
}
executer("INSERT INTO objectInfo(objectId, type1, type2, value) VALUES
$locReqIsLobotomize
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_WEAPON_COUNT.",
".RealObject::$REAL_OBJECT_INFO_TYPE1_WEAPON_COUNT.",
0),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_LIFE_POINT.",
".RealObject::$REAL_OBJECT_INFO_TYPE2_MAX_POINT.",
$parMaxPoint),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_LIFE_POINT.",
".RealObject::$REAL_OBJECT_INFO_TYPE2_CURRENT_POINT.",
$parLifePoint),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_SHIELD_POINT.",
".RealObject::$REAL_OBJECT_INFO_TYPE2_CURRENT_POINT.",
$parShield),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_ACTION_POINT.",
".RealObject::$REAL_OBJECT_INFO_TYPE2_MAX_POINT.",
$parMaxActionPoint),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_ACTION_POINT.",
".RealObject::$REAL_OBJECT_INFO_TYPE2_ACTION_POINT.",
$parMaxActionPoint),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_ACTION_COST.",
".RealObject::$REAL_OBJECT_INFO_TYPE2_ACTION_MOVE_COST.",
$parMoveCost),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_ACTION_COST.",
".RealObject::$REAL_OBJECT_INFO_TYPE2_ACTION_DIG_COST.",
$parDigCost),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_FIGHT_ACTION_POINT.",
".RealObject::$REAL_OBJECT_INFO_TYPE2_MAX_POINT.",
$parMaxFightPoint),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_FIGHT_ACTION_POINT.",
".RealObject::$REAL_OBJECT_INFO_TYPE2_FIGHT_ACTION_POINT.",
$parMaxFightPoint),
($parObjectId,
".RealObject::$REAL_OBJECT_INFO_TYPE1_FIGHT_ACTION_POINT.",
".RealObject::$REAL_OBJECT_INFO_TYPE2_ACTION_FIGHT_COST.",
$parFightCost)
");
}
public function getImage($parSize, $parIsInternalRequest=false)
{
return RealObject::getStaticImage($parSize, $this->getImageParameters($parIsInternalRequest));
}
public static function getStaticImage($parSize, $parImageParameters)
{
Log::debug("RealObject::getStaticImage($parSize, $parImageParameters)");
$locImgObject = imagecreatetruecolor($parSize, $parSize);
imagealphablending($locImgObject, false);
imagesavealpha($locImgObject, true);
$locImageColorTransparent = imagecolorallocatealpha($locImgObject, 255, 255, 255, 127);
imagefill($locImgObject, 0, 0, $locImageColorTransparent);
$locImagePaths = ObjectManager::getInstance()->getImageDefaultPaths($parImageParameters);
$locAlphaColor = array_pop($locImagePaths);
$locAllianceColor = array_pop($locImagePaths);
$locPlayerColor = array_pop($locImagePaths);
//echo "alliancec: $locAllianceColor<br/>";
//echo "playerc: $locPlayerColor<br/>";
//echo "alphac: $locAlphaColor<br/>";
imagealphablending($locImgObject, true);
foreach($locImagePaths as $locImagePath) {
//TODO : Faire un cache pour les images qui sont fixes comme celles ci-dessus pour �viter de tous r��chantillonner � chaque fois
list($locWidthImageFromFile, $locHeightImageFromFile, $locType, $locAttr) = getimagesize($locImagePath);
$locImgObjectFromFile = imagecreatefrompng($locImagePath);
if($locImgObjectFromFile) {
imagecopyresampled($locImgObject, $locImgObjectFromFile, 0, 0, 0, 0, $parSize, $parSize, $locWidthImageFromFile, $locHeightImageFromFile);
ImageDestroy($locImgObjectFromFile);
}
}
$locImagePlayerColor1 = &getImageColorFromHexWithAlpha($locImgObject,
Constante::getColor(intval(substr($locPlayerColor, 0, 2))), $locAlphaColor);
$locImagePlayerColor2 = &getImageColorFromHexWithAlpha($locImgObject,
Constante::getColor(intval(substr($locPlayerColor, 2, 2))), $locAlphaColor);
$locImagePlayerColor3 = &getImageColorFromHexWithAlpha($locImgObject,
Constante::getColor(intval(substr($locPlayerColor, 4, 2))), $locAlphaColor);
$locImageAllianceColor1 = &getImageColorFromHexWithAlpha($locImgObject,
Constante::getColor(intval(substr($locAllianceColor, 0, 2))), $locAlphaColor);
$locImageAllianceColor2 = &getImageColorFromHexWithAlpha($locImgObject,
Constante::getColor(intval(substr($locAllianceColor, 2, 2))), $locAlphaColor);
$locImageAllianceColor3 = &getImageColorFromHexWithAlpha($locImgObject,
Constante::getColor(intval(substr($locAllianceColor, 4, 2))), $locAlphaColor);
imagefilledrectangle($locImgObject, 0, 0, $parSize*1/3, $parSize, $locImageAllianceColor1);
imagefilledrectangle($locImgObject, $parSize*1/3, 0, $parSize*2/3, $parSize, $locImageAllianceColor2);
imagefilledrectangle($locImgObject, $parSize*2/3, 0, $parSize, $parSize, $locImageAllianceColor3);
//imageline ( resource image, int x1, int y1, int x2, int y2, int color );
//Top
imageline ($locImgObject, 0, 0, $parSize-1, 0, $locImagePlayerColor2);
imageline ($locImgObject, 1, 1, $parSize-2, 1, $locImagePlayerColor2);
//Right
imageline ($locImgObject, $parSize-1, 0, $parSize-1, $parSize-1, $locImagePlayerColor3);
imageline ($locImgObject, $parSize-2, 1, $parSize-2, $parSize-2, $locImagePlayerColor3);
//Bottom
imageline ($locImgObject, $parSize-1, $parSize-1, 0, $parSize-1, $locImagePlayerColor2);
imageline ($locImgObject, $parSize-2, $parSize-2, 1, $parSize-2, $locImagePlayerColor2);
//Left
imageline ($locImgObject, 0, $parSize-1, 0, 0, $locImagePlayerColor1);
imageline ($locImgObject, 1, $parSize-2, 1, 1, $locImagePlayerColor1);
return $locImgObject;
}
public function addObjectInfos($parInfoType1, $parInfoType2, $parCount) {
$this->setObjectInfos($parInfoType1, $parInfoType2, $this->getObjectInfo($parInfoType1, $parInfoType2) + $parCount);
}
public function setObjectInfos($parInfoType1, $parInfoType2, $parCount) {
$locObjectInfosType1 = &$this->getObjectInfos($parInfoType1);
if(isset($locObjectInfosType1[$parInfoType2])){
$locObjectInfosType1[$parInfoType2] = $parCount;
executer("UPDATE objectInfo SET value=$parCount WHERE objectId=$this->realObjectId AND type1=$parInfoType1 AND type2=$parInfoType2");
}
}
public function getObjectInfo($parInfoType1, $parInfoType2)
{
$locObjectInfosType1 = $this->getObjectInfos($parInfoType1);
return $locObjectInfosType1[$parInfoType2];
}
/**Return an array pointer of parInfoType information type*/
public function &getObjectInfos($parInfoType1)
{
//$this->debug("getObjectInfos", "parInfoType1=$parInfoType1");
if(!isset($this->infos))
{
$this->infos = array();
$res = executer("SELECT type1, type2, value FROM objectInfo WHERE objectId=$this->realObjectId ORDER BY type1, type2, value ASC");
$locLastType = -1;
while($row = mysql_fetch_array($res))
{
$locType1 = $row[0];
$locType2 = $row[1];
$locValue = $row[2];
//$this->debug("getObjectInfos", "locType1=$locType1");
//$this->debug("getObjectInfos", "locType2=$locType2");
if($locLastType != $locType1)
{
//$this->debug("getObjectInfos", "create array of infos for $locType1");
//$locArrayOfInfo=array();
$this->infos[$locType1]=array();
$locArrayOfInfo=&$this->infos[$locType1];
}
$locArrayOfInfo[$locType2] = $locValue;
//$this->debug("getObjectInfos", "locArrayOfInfo[$locType2]=".$locArrayOfInfo[$locType2]);
//$this->debug("getObjectInfos", "this->infos[$locType1][$locType2]=".$this->infos[$locType1][$locType2]);
$locLastType = $locType1;
}
}
//$this->debug("getObjectInfos", "this->infos[$parInfoType1][10000]=".$this->infos[$parInfoType1][10000]);
if(!isset($this->infos[$parInfoType1]))
{
//$this->debug("getObjectInfos", "create array of infos for $parInfoType1");
$this->infos[$parInfoType1] = array();
}
//$this->debug("getObjectInfos", "this->infos[$parInfoType1][10000]=".$this->infos[$parInfoType1][10000]);
/*$this->debug("getObjectInfos", "count(this->infos)=".count($this->infos));
$this->debug("getObjectInfos", "count(this->infos[$parInfoType1])=".count(&$this->infos[$parInfoType1]));
foreach($this->infos[$parInfoType1] as $locKey=>$locValue)
{
$this->debug("getObjectInfos", "this->infos[$parInfoType1][locKey=$locKey=>locValue=$locValue]");
}
foreach($this->infos as $locKey=>$locValue)
{
$this->debug("getObjectInfos", "this->infos[locKey=$locKey=>locValue=$locValue]");
foreach($locValue as $locKey2=>$locValue2)
{
$this->debug("getObjectInfos", "$locValue [locKey=$locKey2=>locValue=$locValue2]");
}
}
*/
return $this->infos[$parInfoType1];
}
public function getObjectInfoValueImage() {
return RealObject::$REAL_OBJECT_INFO_VALUE_DEFAULT_IMAGE;
}
protected function getExtraImageParameters() {
$locArray = array();
return $locArray;
}
/*TODO : create a class for that !*/
/**Return always more than one result for get image path*/
public function getImageParameters($parIsInternalRequest=false, $parAllianceId=false)
{
$locImageParameters;
//TODO : create an array instead of switch
if($this->isAlive()) {
$locImageParameters=$this->getObjectInfoValueImage();
$locArrayGraphicInfo = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_GRAPHIC);
foreach($locArrayGraphicInfo as $locGraphicInfo)
{
$locImageParameters = $locImageParameters.Constante::$SEP_URL_4."$locGraphicInfo";
}
$locCounter = $this->getLobotomizeCounter();
if($locCounter > 0) {
$locImageParameters = $locImageParameters.Constante::$SEP_URL_4."c$locCounter";
}
if($this->isBattling) {
$locImageParameters = $locImageParameters.Constante::$SEP_URL_4."b";
}
if(!$parAllianceId || $parAllianceId==$this->allianceId ) {
if($this->moveIndex > 0) {
$locImageParameters = $locImageParameters.Constante::$SEP_URL_4."m";
}
}
switch(round($this->getLife()/$this->getMaxLife()*10)) {
case 0:
case 1:
case 2:
case 3:
$locImageParameters = $locImageParameters.Constante::$SEP_URL_4.RealObject::$REAL_OBJECT_INFO_VALUE_HURT_TYPE_4_IMAGE;
break;
case 4:
case 5:
$locImageParameters = $locImageParameters.Constante::$SEP_URL_4.RealObject::$REAL_OBJECT_INFO_VALUE_HURT_TYPE_3_IMAGE;
break;
case 6:
case 7:
$locImageParameters = $locImageParameters.Constante::$SEP_URL_4.RealObject::$REAL_OBJECT_INFO_VALUE_HURT_TYPE_2_IMAGE;
break;
case 8:
case 9:
$locImageParameters = $locImageParameters.Constante::$SEP_URL_4.RealObject::$REAL_OBJECT_INFO_VALUE_HURT_TYPE_1_IMAGE;
break;
default:
}
$locImageParaArray = $this->getExtraImageParameters();
if(count($locImageParaArray) > 0) {
$locImageParameters = $locImageParameters.Constante::$SEP_URL_4.implode(Constante::$SEP_URL_4, $locImageParaArray);
}
} else {
$locImageParameters=RealObject::$REAL_OBJECT_INFO_VALUE_RIP_IMAGE;
}
global $gloObjectManager;
$locPlayer = $gloObjectManager->getPlayer($this->playerId);
$locPlayerColor = $locPlayer->color;
//TODO : alliance color !!!
$locAllianceColor = $locPlayerColor;
if(!$parIsInternalRequest) {
$locImageParameters = $locImageParameters.Constante::$SEP_URL_5.$locPlayerColor;
$locImageParameters = $locImageParameters.Constante::$SEP_URL_5.$locAllianceColor;
$locImageParameters = $locImageParameters.Constante::$SEP_URL_5.Constante::$ALPHA_OBJECT_PLAYER_OWNER;
//Catch by javascript ! TODO : clarify !
$locImageParameters = $locImageParameters.Constante::$SEP_URL_5.$this->playerId;
$locImageParameters = $locImageParameters.Constante::$SEP_URL_5.$this->allianceId;
$locImageParameters = $locImageParameters.Constante::$SEP_URL_5.Constante::$ALPHA_OBJECT_ALLIANCE_OWNER;
} else {
$locImageParameters = $locImageParameters.Constante::$SEP_URL_5.Constante::$ALPHA_FULL;
$locImageParameters = $locImageParameters.Constante::$SEP_URL_5.$locPlayerColor;
$locImageParameters = $locImageParameters.Constante::$SEP_URL_5.$locAllianceColor;
}
return $locImageParameters;
}
public function getLobotomizeCounter() {
$locArrayGraphicCounter = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_COUNTER);
if(isset($locArrayGraphicCounter[RealObject::$REAL_OBJECT_INFO_TYPE2_LOBOTOMIZE_TIME])) {
return $locArrayGraphicCounter[RealObject::$REAL_OBJECT_INFO_TYPE2_LOBOTOMIZE_TIME];
}
return false;
}
public function getUniqueString($parSize, &$parArrayOfDataType)
{
return "".Constante::$SEP_URL_UNIQUE_STRING.$parSize;//.print_r($parArrayOfDataType, true);
}
public function setMoveAlgo($parMoveAlgo) {
$this->moveAlgo = $parMoveAlgo;
}
public function move($parTargetZoneId, &$parResultMessage)
{
$parResultMessage = "";
//$locBegin = microtime(true);
executer("DELETE FROM move WHERE objectId = $this->realObjectId");
if($this->zoneId == $parTargetZoneId) {
$this->moveIndex = 0;
$locIsSuccess=true;
} else {
global $gloObjectManager;
//echo "a ".((microtime(true)-$locBegin)*1000)."ms<br>";
if(!$this->moveAlgo) {
$this->moveAlgo = $gloObjectManager->getPathFinder();
}
$locIsSuccess = $this->moveAlgo->getPathZoneId(
$this,
$gloObjectManager->getZone($this->zoneId),
$gloObjectManager->getZone($parTargetZoneId),
$parResultMessage,
$locListZoneIdForMove);
//echo "b ".((microtime(true)-$locBegin)*1000)."ms<br>";
if($locIsSuccess) {
//Remove target zone
if(count($locListZoneIdForMove) > 0) {
array_pop($locListZoneIdForMove);
$locMoveRequest = "INSERT INTO move(objectId, zoneId, moveIndex) VALUES ";
$locMoveIndex = 1;
for($i=0; $i < count($locListZoneIdForMove); $i++) {
$locZoneId = $locListZoneIdForMove[$i];
$locMoveRequest .= " ($this->realObjectId, $locZoneId, $locMoveIndex)";
if($i != count($locListZoneIdForMove)-1) {
$locMoveRequest .= ",";
}
$locMoveIndex++;
}
//$locMoveRequest .= " ($this->realObjectId, $parTargetZoneId, $locMoveIndex)";
executer($locMoveRequest);
//echo "c ".((microtime(true)-$locBegin)*1000)."ms<br>";
$this->moveIndex = 1;
$this->forceTakeDecision();
} else {
$this->moveIndex = 0;
}
//echo "d ".((microtime(true)-$locBegin)*1000)."ms<br>";
} else {
$locIsSuccess = true;
$this->moveIndex = 0;
}
}
$this->hasBeenModified();
executer("UPDATE object SET moveIndex = $this->moveIndex WHERE objectId = $this->realObjectId");
// echo "e ".((microtime(true)-$locBegin)*1000)."ms<br>";
return $locIsSuccess;
}
public function getNextMoveCost() {
if($locNextZone = $this->getNextZone()) {
$locZCost = 0.0;
if($locNextZone->isAffectedByUpAndDownCost()) {
list($x, $y, $z) = Zone::getZoneCoord($this->zoneId);
list($xNext, $yNext, $zNext) = Zone::getZoneCoord($locNextZone->zoneId);
if($zNext != $z) {
$locZCost = Constante::$MOVE_Z_COST;
}
}
return $this->getMoveCost() * ($locNextZone->getMoveCostFactor() + $locZCost);
} else {
return 0;
}
}
public function getNextZone() {
if($this->moveIndex <> 0) {
//Use moveIndex of object here to avoid unsynchronize between database and cache
$res = executer("SELECT move.zoneId, object.moveIndex FROM move JOIN object ON (move.objectId = object.objectId AND move.moveIndex = object.moveIndex)
WHERE object.objectId = $this->realObjectId");
if($row = mysql_fetch_array($res)) {
global $gloObjectManager;
$locNewZoneId = $row[0];
$locNewZone = $gloObjectManager->getZone($locNewZoneId);
//Synchronize moveIndex
$this->moveIndex = $row[1];
return $locNewZone;
}
}
$this->moveIndex = 0;
return false;
}
public function moveNext($parNextMoveCost=0)
{
$locUnitHasMove = false;
if($this->moveIndex <> 0) {
$locDeleteMove = false;
//On collision no update
$locCollision = false;
if($locNewZone = $this->getNextZone()) {
if($locNewZone->zoneId == $this->zoneId) {
//Bug, next move is the same move ...
$this->moveIndex++;
$parNextMoveCost = 0;
} else if(!$locNewZone->isAccessibleForIt($this)) {
$this->debug("moveNext", "collision on $locNewZone->zoneId");
$locCollision = true;
} else {
$this->moveIndex++;
global $gloObjectManager;
$locZone = $gloObjectManager->getZone($this->zoneId);
$locOldZone = $locZone;
$locZone->leaveWithMovable();
if($this->isBackground == 1) {
$locBlock = $gloObjectManager->getBlock($this->blockId);
$locZone->zoneHasBeenModified($locBlock);
}
$this->zoneId = $locNewZone->zoneId;
$locZone = $gloObjectManager->getZone($this->zoneId);
$this->blockId = $locZone->blockId;
$locZone->occupedWithMovable();
if($this->isBackground == 1) {
$this->debug("moveNext", "locNewZoneId: $locNewZone->zoneId is isOccupedWithMovable");
$locBlock = $gloObjectManager->getBlock($this->blockId);
$locZone->zoneHasBeenModified($locBlock);
}
}
if($locCollision) {
if($locNewZone->isDigableForUnit($this)) {
if($this->getActionPoint() >= $this->getDigCost()) {
$this->dig($locNewZone->zoneId);
}
}
} else {
//Remove action point
$this->addActionPoint(-$parNextMoveCost);
$this->timestamp = time();
executer("UPDATE object SET timestamp = $this->timestamp, blockId = $this->blockId, zoneId = $this->zoneId, moveIndex = $this->moveIndex WHERE objectId = $this->realObjectId");
global $gloObjectManager;
//Notify must be done after move
$gloObjectManager->notifyEvent(new RealObjectMoveEvent($this, $locOldZone, $locNewZone));
$locUnitHasMove = true;
}
} else {
$locDeleteMove = true;
}
if(!$locDeleteMove && !$this->getNextZone()) {
$locDeleteMove = true;
}
if($locDeleteMove) {
$this->debug("moveNext", "no more movement");
executer("DELETE FROM move WHERE objectId=$this->realObjectId");
$this->timestamp = time();
$this->moveIndex = 0;
executer("UPDATE object SET timestamp = $this->timestamp, moveIndex = $this->moveIndex WHERE objectId = $this->realObjectId");
}
return $locUnitHasMove;
} else
{
return $locUnitHasMove;
}
}
public function getMoveNext() {
$locPath = array();
//Use moveIndex of object here to avoid unsynchronize between database and cache
$res = executer("SELECT move.zoneId
FROM move JOIN object ON (object.objectId=move.objectId)
WHERE object.objectId = $this->realObjectId AND move.moveIndex >= object.moveIndex");
while($row = mysql_fetch_array($res)) {
array_push($locPath, $row[0]);
}
return $locPath;
}
public function getWeaponsCount() {
return $this->getObjectInfo(RealObject::$REAL_OBJECT_INFO_TYPE1_WEAPON_COUNT, RealObject::$REAL_OBJECT_INFO_TYPE1_WEAPON_COUNT);
}
public function &getWeaponsList() {
$this->debug("getWeaponsList", "()");
if(!isset($this->weaponsList))
{
global $gloObjectManager;
$this->debug("getWeaponsList", "create weapons list");
$this->weaponsList = array();
$locWeaponsCount = $this->getWeaponsCount();
$this->debug("getWeaponsList", "locWeaponsCount=$locWeaponsCount");
if($locWeaponsCount > 0) {
$locAimPercentFires = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_AIM_PERCENT_START_FIRE);
$locAccurencies = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_AIM_ACCURENCY);
$locShootingRanges = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_SHOOTING_RANGE);
$locTargetIds = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_TARGET_OBJECT_ID);
$locDamages = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_WEAPON_DAMAGE);
$locWeaponTypes = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_WEAPON_TYPE);
//$this->debug("getWeaponsList", "count(locAimPercentFires)=".count($locAimPercentFires));
//$this->debug("getWeaponsList", "count(locShootingRanges)=".count($locShootingRanges));
//$this->debug("getWeaponsList", "count(locAccurencies)=".count($locTargetIds));
//$this->debug("getWeaponsList", "count(locTargetIds)=".count($locAccurencies));
//$this->debug("getWeaponsList", "count(locShootingRanges)=".count($locShootingRanges));
//$this->debug("getWeaponsList", "locShootingRanges[0]=".$locShootingRanges[0]);
foreach($locAimPercentFires as $locWeaponNum=>$locAimPercentFire) {
//$this->debug("getWeaponsList", "locWeaponNum=$locWeaponNum");
//$this->weaponsList[$locWeaponNum] = &$gloObjectManager->getWeapon($this, $locWeaponNum, $locWeaponTypes[$locWeaponNum], $locTargetIds[$locWeaponNum], $locAimPercentFires[$locWeaponNum], $locAccurencies[$locWeaponNum], $locShootingRanges[$locWeaponNum], $locDamages[$locWeaponNum]);
$this->weaponsList[$locWeaponNum] = &$gloObjectManager->getWeapon($this, $locWeaponNum, $locWeaponTypes[$locWeaponNum], $locTargetIds[$locWeaponNum], $locAimPercentFires[$locWeaponNum], $locAccurencies[$locWeaponNum], $locShootingRanges[$locWeaponNum], $locDamages[$locWeaponNum]);
}
}
}
return $this->weaponsList;
}
public function scan()
{
$this->debug("scan()", "");
global $gloObjectManager;
$locWeaponsList = &$this->getWeaponsList();
foreach($locWeaponsList as $locWeapon)
{
$locWeapon->scan();
}
}
public function hasAtLeastOneTarget()
{
$this->debug("hasAtLeastOneTarget();", "");
$locWeaponsList = &$this->getWeaponsList();
foreach($locWeaponsList as $locWeapon)
{
$this->debug("hasAtLeastOneTarget();", "Has weapons");
if($locWeapon->getCurrentTargetId())
{
$this->debug("hasAtLeastOneTarget();", "Target found");
return True;
}
}
$this->debug("hasAtLeastOneTarget();", "Target not found");
return False;
}
public function addActionPoint($parCount) {
$this->addObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_ACTION_POINT, RealObject::$REAL_OBJECT_INFO_TYPE2_ACTION_POINT, $parCount);
}
public function getMaxFightActionPoint() {
$locActionPoint = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_FIGHT_ACTION_POINT);
return $locActionPoint[RealObject::$REAL_OBJECT_INFO_TYPE2_MAX_POINT];
}
public function getMaxActionPoint() {
$locActionPoint = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_ACTION_POINT);
return $locActionPoint[RealObject::$REAL_OBJECT_INFO_TYPE2_MAX_POINT];
}
public function getActionPoint() {
$locActionPoint = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_ACTION_POINT);
return $locActionPoint[RealObject::$REAL_OBJECT_INFO_TYPE2_ACTION_POINT];
}
public function setActionPoint($parActionPoint) {
$this->setObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_ACTION_POINT,
RealObject::$REAL_OBJECT_INFO_TYPE2_ACTION_POINT, $parActionPoint);
}
public function setFightPoint($parActionPoint) {
$this->setObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_FIGHT_ACTION_POINT,
RealObject::$REAL_OBJECT_INFO_TYPE2_FIGHT_ACTION_POINT, $parActionPoint);
}
public function addFightActionPoint($parCount) {
$this->addObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_FIGHT_ACTION_POINT,
RealObject::$REAL_OBJECT_INFO_TYPE2_FIGHT_ACTION_POINT, $parCount);
}
public function getFightActionPoint() {
$locActionPoint = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_FIGHT_ACTION_POINT);
return $locActionPoint[RealObject::$REAL_OBJECT_INFO_TYPE2_FIGHT_ACTION_POINT];
}
public function getUpkeepCost() {
$locActionPoint = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_COST);
return $locActionPoint[RealObject::$REAL_OBJECT_INFO_TYPE2_CURRENT_UPKEEP_COST];
}
public function getFightCost() {
$locActionPoint = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_FIGHT_ACTION_POINT);
return $locActionPoint[RealObject::$REAL_OBJECT_INFO_TYPE2_ACTION_FIGHT_COST];
}
public function getDigCost() {
return $this->getActionCost(RealObject::$REAL_OBJECT_INFO_TYPE2_ACTION_DIG_COST);
}
public function getMoveCost() {
return $this->getActionCost(RealObject::$REAL_OBJECT_INFO_TYPE2_ACTION_MOVE_COST);
}
public function getTrapSearchCost() {
return $this->getActionCost(RealObject::$REAL_OBJECT_INFO_TYPE2_ACTION_SEARCH_TRAP_COST);
}
public function getActionCost($parActionType2) {
$locActionPoint = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_ACTION_COST);
if(isset($locActionPoint[$parActionType2])) {
return $locActionPoint[$parActionType2];
} else {
echo "$parActionType2 is not an action cost present for this realobject: $this->realObjectId";
exit(0);
}
}
public function dig($parTargetZoneId) {
global $gloObjectManager;
$locTargetZone = $gloObjectManager->getZone($parTargetZoneId);
$locTargetZone->dig(DungeonConstante::$ZONE_DIG_UNIT_PER_ACTION);
$this->addActionPoint(-$this->getDigCost());
return true;
}
public function setTimeInMsSinceNoDecision($parValue) {
$this->timeInMsSinceNoDecision=$parValue;
executer("UPDATE object SET timeInMsSinceNoDecision=$this->timeInMsSinceNoDecision WHERE objectId=$this->realObjectId");
}
public function addTimeInMsSinceNoDecision($parElapsedTime) {
$this->setTimeInMsSinceNoDecision($this->timeInMsSinceNoDecision+$parElapsedTime);
}
public function increaseTimeInMsBeforeADecision() {
$locValue = $this->timeInMsBeforeADecision;
if($this->timeInMsBeforeADecision < 1000) {
$locValue = $locValue*10;
} elseif ($this->timeInMsBeforeADecision < 100000) {
$locValue = $locValue*5;
} else {
$locValue = $locValue*2;
}
$locValue = max(Constante::$MIN_TIME_MS_BEFORE_A_DECISION, $locValue);
$locValue = min(Constante::$MAX_TIME_MS_BEFORE_A_DECISION, $locValue);
$this->setTimeInMsBeforeADecision($locValue);
}
/**
* Constante::$MIN_TIME_MS_BEFORE_A_DECISION and Constante::$MAX_TIME_MS_BEFORE_A_DECISION
* have to be manage in an another function !
* @see increaseTimeInMsBeforeADecision
*/
public function setTimeInMsBeforeADecision($parValue) {
$this->timeInMsBeforeADecision = $parValue;
executer("UPDATE object SET timeInMsBeforeADecision=$this->timeInMsBeforeADecision WHERE objectId=$this->realObjectId");
}
public function setBattling($parValue) {
if($parValue != $this->isBattling) {
executer("UPDATE object set isBattling=$parValue WHERE objectId=$this->realObjectId");
$this->isBattling = $parValue;
}
}
public function manageAction($parElapsedTime)
{
$this->debug("manageAction", "parElapsedTime=$parElapsedTime");
if(!$this->isLobotomize()) {
if($this->timeInMsSinceNoDecision >= $this->timeInMsBeforeADecision) {
$locObjectDoAThing = false;
$this->addTimeInMsSinceNoDecision(-$this->timeInMsBeforeADecision);
$this->scan();
if($this->hasAtLeastOneTarget()) {
$this->setBattling(1);
if($this->getFightActionPoint() >= $this->getFightCost()) {
$this->addFightActionPoint(-$this->getFightCost());
$this->debug("manageAction", "attackCurrentTargets();");
$this->attackCurrentTargets();
$locObjectDoAThing = true;
} else {
$this->debug("manageAction", "no enough point to fight (cost=".$this->getFightCost().")");
}
} else {
$this->setBattling(0);
$locActionPoint = $this->getActionPoint();
$this->debug("manageAction", "this->getActionPoint()=$locActionPoint");
$locNextMoveCost = $this->getNextMoveCost();
if($locActionPoint >= $locNextMoveCost
||$locActionPoint == $this->getMaxActionPoint()) {
$this->debug("manageAction", "moveNext();");
$locObjectDoAThing = $this->moveNext($locNextMoveCost);
} else {
$this->debug("manageAction", "no enough point to move (cost=".$this->getMoveCost().")");
}
}
if($locObjectDoAThing) {
$this->debug("manageAction", "do something");
RealObject::forceTakeDecisionNear($this->zoneId);
} else {
$this->debug("manageAction", "do nothing");
$this->increaseTimeInMsBeforeADecision();
}
}
}
}
/**All units in a range of 1 zone have forceTakeDecision call*/
public static function forceTakeDecisionNearInBlock($parBlockId) {
global $gloObjectManager;
$res = executer("SELECT objectId FROM object WHERE blockId IN ".Block::getStaticBlockIdsWhereClauseList($parBlockId, 1, 1, 1));
while($row = mysql_fetch_array($res)) {
$locRealObject = $gloObjectManager->getRealObject($row[0]);
$locRealObject->forceTakeDecision();
}
}
/**All units in a range of 1 zone have forceTakeDecision call*/
public static function forceTakeDecisionNear($parZoneId) {
global $gloObjectManager;
$res = executer("SELECT objectId FROM object WHERE zoneId IN ".Zone::getStaticZoneIdsWhereClauseList($parZoneId, 1, 1, 1));
$locObjectIdList = array();
while($row = mysql_fetch_array($res)) {
array_push($locObjectIdList, $row[0]);
}
$locObjectList = $gloObjectManager->getRealObjects($locObjectIdList);
foreach($locObjectList as $locRealObject) {
$locRealObject->forceTakeDecision();
}
}
/**
* timeInMsBeforeADecision and timeInMsSinceNoDecision are set to 0
*/
public function forceTakeDecision() {
$this->setTimeInMsBeforeADecision(0);
$this->setTimeInMsSinceNoDecision(0);
executer("UPDATE object SET objectTickIndex=0 WHERE objectId=$this->realObjectId");
}
protected function attackCurrentTargets()
{
global $gloObjectManager;
$locBlock = $gloObjectManager->getBlock($this->blockId);
$locWeaponsList = $this->getWeaponsList();
foreach($locWeaponsList as $locWeapon)
{
$locWeapon->attackCurrentTarget();
}
}
public function isLobotomize() {
return $this->isLobotomize<>RealObject::$UNIT_IS_NOT_LOBOTOMIZE;
}
public function lobotomize() {
$this->setIsLobotomize(RealObject::$UNIT_IS_LOBOTOMIZE);
}
public function unLobotomize() {
$this->setIsLobotomize(RealObject::$UNIT_IS_NOT_LOBOTOMIZE);
}
public function setIsLobotomize($parValue) {
if($parValue == RealObject::$UNIT_IS_NOT_LOBOTOMIZE) {
$this->forceTakeDecisionNear($this->blockId);
if($parValue <> $this->isLobotomize) {
executer("UPDATE object SET isLobotomize=$parValue WHERE objectId=$this->realObjectId");
}
} else {
if($parValue <> $this->isLobotomize) {
executer("UPDATE object SET isLobotomize=$parValue WHERE objectId=$this->realObjectId");
}
}
$this->isLobotomize=$parValue;
}
public function doBeforeKill($parKilledUnit) {
}
public function doAfterKill($parKilledUnit) {
}
public function sendMessageHasBeenKilled($parKiller, $parSendAMessageToOwner=true) {
if ($parKiller) {
$locKillerStr = $parKiller->toStringMessage();
} else {
$locKillerStr = "not identified or natural death as earthquake";
}
$locMessage = "unit '$locKillerStr' kills '".$this->toStringMessage()."'";
if($parSendAMessageToOwner) {
PlayerMessage::getInstance()->addPlayerInfo($this->playerId, $locMessage, PlayerMessage::$VERY_BAD, $this->zoneId);
}
if($parKiller) {
PlayerMessage::getInstance()->addPlayerInfo($parKiller->playerId, $locMessage, PlayerMessage::$GOOD, $this->zoneId);
}
}
/**Update object in background mode*/
public function kill($parKiller, $parSendAMessageToOwner=true, $parDeleteObject=false) {
if ($parKiller) {
$parKiller->doBeforeKill($this);
}
$this->sendMessageHasBeenKilled($parKiller, $parSendAMessageToOwner);
$this->internalKill();
if ($parKiller) {
$parKiller->doAfterKill($this);
}
if($parDeleteObject) {
$this->deleteObject();
}
}
/**Update object in background mode*/
public function killWithAMessage($parKillerMessage, $parCausis=false) {
$locMessage = "'$parKillerMessage' kills '".$this->toStringMessage()."'".($parCausis?" with $parCausis":"");
PlayerMessage::getInstance()->addPlayerInfo($this->playerId, $locMessage, PlayerMessage::$BAD, $this->zoneId);
$this->internalKill();
}
protected function internalKill() {
if($this->isBackground == 0) {
$this->isBackground = 1;
global $gloObjectManager;
$locZone = $gloObjectManager->getZone($this->zoneId);
$locZone->leaveWithMovable();
executer("UPDATE object SET isBackground=$this->isBackground WHERE objectId=$this->realObjectId");
RealObject::staticAddInDeleted($this->realObjectId, $this->blockId, $this->zoneId);
}
if($this->visibleState == RealObject::$REAL_OBJECT_VISIBLE_STATE_VISIBLE_BY_ALLIANCE) {
$this->visibleState=RealObject::$REAL_OBJECT_VISIBLE_STATE_VISIBLE_BY_ALL;
executer("UPDATE object SET visibleState=$this->visibleState WHERE objectId=$this->realObjectId");
}
$this->setIsLobotomize(RealObject::$UNIT_IS_DEAD);
$this->setBattling(0);
executer("INSERT INTO objectTTL(objectId, ttl)
VALUES ($this->realObjectId, ".Constante::$DEFAULT_TTL_FOR_DELETE_BODY.")");
$this->hasBeenModified();
}
public static function staticAddInDeleted($parRealObjectId, $parBlockId, $parZoneId) {
executer("INSERT INTO objectDeleted(objectId, blockId, zoneId, timestamp)
VALUES ($parRealObjectId, $parBlockId, $parZoneId,".time().")");
}
public function isAlive() {
return $this->isLobotomize <> RealObject::$UNIT_IS_DEAD;
}
public function getMaxLife() {
$locLifePoint = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_LIFE_POINT);
return $locLifePoint[RealObject::$REAL_OBJECT_INFO_TYPE2_MAX_POINT];
}
public function getLife() {
$locLifePoint = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_LIFE_POINT);
return $locLifePoint[RealObject::$REAL_OBJECT_INFO_TYPE2_CURRENT_POINT];
}
public function getShield() {
$locLifePoint = &$this->getObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_SHIELD_POINT);
return $locLifePoint[RealObject::$REAL_OBJECT_INFO_TYPE2_CURRENT_POINT];
}
public function setLife($parLife) {
$this->setObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_LIFE_POINT, RealObject::$REAL_OBJECT_INFO_TYPE2_CURRENT_POINT, $parLife);
$this->hasBeenModified();
}
public function getIAMode() {
return $this->IAMode;
}
public function setIAMode($parIAMode) {
$this->IAMode = $parIAMode;
executer("update object set IAMode=$parIAMode WHERE objectId=$this->realObjectId");
}
public function setHeroMode($parHeroMode) {
$this->heroMode = $parHeroMode;
executer("update object set heroMode=$parHeroMode WHERE objectId=$this->realObjectId");
}
public function getHeroMode() {
return $this->heroMode;
}
public function damage($parDamager, $parDamage, $parDamagerName=false, $parCausis=false) {
if($this->isAlive()) {
$locDamage = round($parDamage - $this->getShield());
if($locDamage > 0) {
$locLife = $this->getLife();
$locLife -= $locDamage;
$this->setLife($locLife);
if($parDamager) {
// $locMessage = "unit: ".$parDamager->toStringMessage()." damages $locDamage on: ".$this->toStringMessage();
// PlayerMessage::getInstance()->addPlayerInfo($this->playerId, $locMessage,
// PlayerMessage::$BAD, $parDamager->zoneId);
// PlayerMessage::getInstance()->addPlayerInfo($parDamager->playerId, $locMessage,
// PlayerMessage::$NEUTRAL_GOOD, $this->zoneId);
} else{
if($parDamagerName) {
// $locMessage = "'$parDamagerName' damages $locDamage on: ".$this->toStringMessage().($parCausis?" with $parCausis":"");
// PlayerMessage::getInstance()->addPlayerInfo($this->playerId, $locMessage,
// PlayerMessage::$BAD, $this->zoneId);
}
}
if($locLife <= 0) {
if($parDamager) {
$this->kill($parDamager);
} else {
$this->killWithAMessage($parDamagerName, $parCausis);
}
} else {
$this->addActionPoint(-$locDamage*Constante::$REAL_OBJECT_DAMAGE_MUX_FOR_ACTION_POINT_LOST);
}
}
}
}
public function deleteObject() {
RealObject::staticDeleteObject($this->realObjectId, $this->blockId, $this->zoneId, $this->isBackground);
}
/**Delete all informations about $parObjectId*/
public static function staticDeleteObject($parObjectId, $parBlockId, $parZoneId, $parIsBackground)
{
global $gloObjectManager;
$locZone = $gloObjectManager->getZone($parZoneId);
if(1 == $parIsBackground) {
$locBlock = $gloObjectManager->getBlock($parBlockId);
$locZone->zoneHasBeenModified($locBlock);
}
executer("DELETE objectInfoTTL
FROM objectInfoTTL, objectInfo
WHERE objectInfoTTL.objectInfoId=objectInfo.objectInfoId
AND objectInfo.objectId=$parObjectId");
executer("DELETE FROM objectInfo WHERE objectId = $parObjectId");
executer("DELETE FROM move WHERE objectId = $parObjectId");
executer("DELETE FROM object WHERE objectId = $parObjectId");
executer("DELETE FROM objectTTL WHERE objectId = $parObjectId");
if(0 == $parIsBackground) {
RealObject::staticAddInDeleted($parObjectId, $parBlockId, $parZoneId);
}
}
public function hasBeenModified()
{
$this->timestamp = time();
executer("UPDATE object SET timestamp=$this->timestamp WHERE objectId=$this->realObjectId");
if($this->isBackground)
{
global $gloObjectManager;
$locZone = $gloObjectManager->getZone($this->zoneId);
$locBlock = $gloObjectManager->getZone($this->blockId);
$locZone->zoneHasBeenModified($locBlock);
}
}
private function debug($parFunctionName, $parMessage) {
Log::debug("RealObject($this->realObjectId)->$parFunctionName => $parMessage");
}
public function setAllianceId($parAllianceId) {
$this->allianceId = $parAllianceId;
executer("UPDATE object SET allianceId = $parAllianceId WHERE objectId=$this->realObjectId");
$this->hasBeenModified();
}
public static function getObjectsWithResult($resWithRealObjectId) {
global $gloObjectManager;
$locResult=array();
while($row=mysql_fetch_array($resWithRealObjectId)) {
$locRealObject = $gloObjectManager->getRealObject($row[0]);
array_push($locResult, $locRealObject);
}
return $locResult;
}
public function getName() {
return "unknown";
}
public function toStringMessage() {
global $gloObjectManager;
$locPlayer = $gloObjectManager->getPlayer($this->playerId);
$locResult = $this->getName()." owner: ".$locPlayer->playerName;
return $locResult;
}
public function toStringForAlliance($parAllianceId) {
if($parAllianceId == $this->allianceId) {
return $this->toString();
} else {
return $this->toStringPublicInfo();
}
}
public function toStringPublicInfo() {
$gloObjectManager=ObjectManager::getInstance();
$locPlayer = $gloObjectManager->getPlayer($this->playerId);
$locResult = $this->realObjectId."-".$this->getName().($this->heroMode>0?" (hero)":"")."\nowner: ".$locPlayer->playerName;
switch($this->isLobotomize) {
case RealObject::$UNIT_IS_DEAD:
$locResult.=", unit is dead";
break;
case RealObject::$UNIT_IS_LOBOTOMIZE:
$locResult.=", unit is recruiting (remaining ".$this->getLobotomizeCounter()." turns)";
default:
$locResult.= "\nlife: ".$this->getLife()."/".$this->getMaxLife().", shield: ".$this->getShield();
}
return $locResult;
}
public function toString() {
$gloObjectManager=ObjectManager::getInstance();
$locPlayer = $gloObjectManager->getPlayer($this->playerId);
$locResult = $this->toStringPublicInfo();
switch($this->isLobotomize) {
case RealObject::$UNIT_IS_LOBOTOMIZE:
case RealObject::$UNIT_IS_DEAD:
break;
default:
$locResult.=$locResultCarac."\naction point: ".$this->getActionPoint()."/".$this->getMaxActionPoint().", dig: ".$this->getDigCost().", move: ".$this->getMoveCost().", search trap: ".$this->getTrapSearchCost();
$locResult.="\nfight point: ".$this->getFightActionPoint()."/".$this->getMaxFightActionPoint().", cost: ".$this->getFightCost();
$locResult.="\nupkeep cost: ".$this->getUpkeepCost();
}
return $locResult;
}
}
?>