当前位置: 首页>>代码示例>>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;未经允许,请勿转载。