當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Weapon::getUserDefenseWeaponsCount方法代碼示例

本文整理匯總了PHP中Weapon::getUserDefenseWeaponsCount方法的典型用法代碼示例。如果您正苦於以下問題:PHP Weapon::getUserDefenseWeaponsCount方法的具體用法?PHP Weapon::getUserDefenseWeaponsCount怎麽用?PHP Weapon::getUserDefenseWeaponsCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Weapon的用法示例。


在下文中一共展示了Weapon::getUserDefenseWeaponsCount方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: array

	public function
	getWeaponAlloacation($isAttack, $count = null) {

		$ret = array(
			'trained'   => array(
				'weapons'   => 0,
				'noweapons' => 0,
			),
			'mercs'     => array(
				'weapons'   => 0,
				'noweapons' => 0,
			),
			'untrained' => array(
				'weapons'   => 0,
				'noweapons' => 0,
			),
		);

		$weaponCount = $count;

		// If the count isn't provided, grab it
		if ($weaponCount == null) {

			$weaponCount = $isAttack ?
				Weapon::getUserAttackWeaponsCount($this->id) :
				Weapon::getUserDefenseWeaponsCount($this->id);
		}

		$trainedCount   = $isAttack ? $this->sasoldiers : $this->dasoldiers;
		$mercCount      = $isAttack ? $this->samercs    : $this->damercs;
		$untrainedCount = $this->uu;

		// Can't have a merc-only army
		if ($trainedCount == 0) {
			// they'll be unarmed
			$ret['mercs']['noweapons'] = $mercCount;
			$mercCount = 0;
		}
		// Mercs can only be a max of 30% of the trained force
		if ($mercCount > $thirty = floor($trainedCount * 0.3)) {
			$ret['mercs']['noweapons'] = $mercCount - $thirty;
			$mercCount = $thirty;
		}

		// There are more weapons than trained soldiers,
		// so all soldiers will have weapons
		if ($weaponCount > $trainedCount) {
			$ret['trained']['weapons'  ] = $trainedCount;
			$weaponCount -= $trainedCount;
		}
		// Not enough weapons for any mercs or untrained
		else {
			$ret['trained']['weapons'  ] = $weaponCount;
			$ret['trained']['noweapons'] = $trainedCount - $weaponCount;
			$weaponCount = 0;
		}

		// There's enough weapons for the mercs
		if ($weaponCount > $mercCount) {
			$ret['mercs']['weapons'  ]   = $mercCount;
			$weaponCount -= $mercCount;
		}
		// only some or none of the mercs will have weapons
		else {
			$ret['mercs']['weapons'  ] = $weaponCount;
			$ret['mercs']['noweapons'] = $mercCount - $weaponCount;
			$weaponCount = 0;
		}

		// There's enough for the untrained
		if ($weaponCount > $untrainedCount) {
			$ret['untrained']['weapons'] = $untrainedCount;
		}
		// some or none of the untrained will have weapons
		else {
			$ret['untrained']['weapons'  ] = $weaponCount;
			$ret['untrained']['noweapons'] = $untrainedCount - $weaponCount;
		}

		return $ret;
	}
開發者ID:Naddiseo,項目名稱:WW2Game,代碼行數:81,代碼來源:User.php


注:本文中的Weapon::getUserDefenseWeaponsCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。