Location: PHPKode > projects > PhpBlock > A9.8/script/weapon.class.php
<?php
include_once $PATH_TO_CODE."/script/zone.class.php";
include_once $PATH_TO_CODE."/script/realobject.class.php";

include_once $PATH_TO_CODE."/script/imagemanager.class.php";

include_once $PATH_TO_CODE."/script/log.class.php";

class Weapon {
    public static $WEAPON_TYPE_MEDIUM_CANON=1;
    public static $WEAPON_RANGE_MEDIUM_CANON=3;
    
    public static $WEAPON_TYPE_AXIS=2;
    //<weaponlist>
    public static $WEAPON_TYPE_TRAP=10002;
    //</weaponlist>

    public static $WEAPON_RANGE_HAND_TO_HAND=1;
    public static $WEAPON_RANGE_ON_UNIT=0;
    
    
    public function __construct($parRealObject, $parWeaponNum, $parTargetId, $parAimPercentStartFire, $parAccurency, $parRange, $parDamage)
    {
        $this->realObject = $parRealObject;
        $this->weaponNum = $parWeaponNum;
        $this->aimPercentStartFire = $parAimPercentStartFire;
        $this->accurency = $parAccurency;
        $this->range = $parRange;
        $this->setRangeZ($parRange);
        $this->damage = $parDamage;

        $this->currentTargetId = $parTargetId;
        $this->luckStrike = 0;

        Log::debug("Weapon__construct(parRealObject->realObjectId=$parRealObject->realObjectId, parWeaponNum=$parWeaponNum, parTargetId=$parTargetId, parAimPercentStartFire=$parAimPercentStartFire, parAccurency=$parAccurency, parRange=$parRange, parDamage=$parDamage)");
    }

    protected function setRangeZ() {
        $this->rangeZ = ceil($this->range*Constante::$WEAPON_RATIO_Z);
    }


    public function getTargets() {
        return executer("SELECT objectId, zoneId, isLobotomize
                FROM object FORCE KEY(zoneId)
                WHERE allianceId <> ".$this->realObject->allianceId."
                AND isLobotomize <> ".RealObject::$UNIT_IS_DEAD."
                AND category IN (".$this->getScannedCategory().")
                AND (zoneId IN ".Zone::getStaticZoneIdsWhereClauseList($this->realObject->zoneId, $this->range, $this->range, 0)."
				OR zoneId IN ".Zone::getStaticZoneIdsWhereClauseList($this->realObject->zoneId, 0, 0, $this->rangeZ)."
                ) ORDER BY isLobotomize ASC");
    }

    protected function getScannedCategory() {
        return DungeonConstante::$REAL_OBJECT_CATEGORY_MEDIUM_INFANTERY;
    }

    protected function doAttackCurrentTarget() {
        $locRandom = getMediumExtendedRandom10(2, true);
        $locMargin = $locRandom + $this->luckStrike;
        $this->debug("attackCurrentTarget", "locRandom=$locRandom; margin=$locMargin; this->luckStrike=$this->luckStrike");
        if($locMargin >= 0) {
            executer("INSERT INTO objectInfo(objectId, type1, type2, value) VALUES($this->currentTargetId, ".RealObject::$REAL_OBJECT_INFO_TYPE1_GRAPHIC.",".RealObject::$REAL_OBJECT_INFO_VALUE_HURT_TYPE_HIT_IMAGE.",".RealObject::$REAL_OBJECT_INFO_VALUE_HURT_TYPE_HIT_IMAGE.")");
            $locNewObjectInfoId = getLastInsertedId();

            executer("INSERT INTO objectInfoTTL(objectInfoId, ttl) VALUES($locNewObjectInfoId, ".Constante::$DEFAULT_TTL_FOR_ATTACK_TEMP.")");

            $locTarget = $this->getCurrentTarget();
            $locDamage = $this->damage+$locMargin;
            $this->debug("attackCurrentTarget", "margin=$locMargin; damage=$locDamage");
            $locTarget->damage($this->realObject, $locDamage);

            if(!$locTarget->isAlive()) {
                $this->setCurrentTargetId(false);
            }
        }
    }
    public function getCurrentTarget() {
        global $gloObjectManager;
        return $gloObjectManager->getRealObject($this->currentTargetId);
    }
    
    public function attackCurrentTarget()
    {
        $this->debug("attackCurrentTarget", "this->currentTargetId: $this->currentTargetId, this->luckStrike: $this->luckStrike");
        if($this->currentTargetId) {
            $this->doAttackCurrentTarget();
        }
    }

    public function setCurrentTargetId($parTargetId=false, $parluckStrike=0)
    {
        if(!$parTargetId) {
            $parTargetId = 0;
        }
        $this->currentTargetId = $parTargetId;
        $this->luckStrike = $parluckStrike;
        $this->realObject->setObjectInfos(RealObject::$REAL_OBJECT_INFO_TYPE1_TARGET_OBJECT_ID, $this->weaponNum, $parTargetId);
    }

    public function scan() {
        $locAimPercentStartFire = ($this->getAimPercentStartFire()/10.0)-5;
        $locAccurency = $this->accurency;
        $this->debug("scan", "locAimStartFire=$locAimPercentStartFire");
        $locWeaponRange = $this->getRange();
        $this->debug("scan", "locWeaponRange=$locWeaponRange");
        $this->debug("scan", "locAccurency=$locAccurency");

        $locBestTargetId = false;
        $locBestLuckStrike = $locAimPercentStartFire-1;
        $res = $this->getTargets($locWeaponRange);
        while($row = mysql_fetch_array($res))
        {
            $locZoneId = $row[1];
            $locRange = Zone::getRange3d($this->realObject->zoneId, $locZoneId);
            $locLuckStrike = $locAccurency+($locWeaponRange-2*$locRange);
            if($locAimPercentStartFire <= $locLuckStrike && $locLuckStrike > $locBestLuckStrike)
            {
                $locBestTargetId = $row[0];
                $locIsLobotomize = $row[2];
                if($locIsLobotomize == RealObject::$UNIT_IS_LOBOTOMIZE) {
                    //No interest to strike a lobotmize unit !
                    $locBestLuckStrike = -9999;
                } else {
                    $locBestLuckStrike = $locLuckStrike;
                }
                $locRealLuckStrike = $locLuckStrike;
                $this->debug("scan()", "locBestTargetId: $locBestTargetId, locRealLuckStrike : $locRealLuckStrike, locRealLuckStrike: $locRealLuckStrike, locLuckStrike: $locLuckStrike");
            }
        }
        $this->setCurrentTargetId($locBestTargetId, $locRealLuckStrike);
    }

    public function getCurrentTargetId()
    {
        return $this->currentTargetId;
    }
    
    public function getAimPercentStartFire()
    {
        return $this->aimPercentStartFire;
    }

    public function getRange()
    {
        return $this->range;
    }
    public function getluckStrike()
    {
        return $this->luckStrike;
    }
    private function debug($parFunctionName, $parMessage) {
    	if(Log::getInstance()->isDebugOn()) {
        	Log::debug("Weapon(realObjectId=".$this->realObject->realObjectId.")->$parFunctionName => $parMessage");
    	}
    }
}
?>
Return current item: PhpBlock