本文整理汇总了PHP中Weapon::getUserAttackWeaponsCount方法的典型用法代码示例。如果您正苦于以下问题:PHP Weapon::getUserAttackWeaponsCount方法的具体用法?PHP Weapon::getUserAttackWeaponsCount怎么用?PHP Weapon::getUserAttackWeaponsCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Weapon
的用法示例。
在下文中一共展示了Weapon::getUserAttackWeaponsCount方法的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;
}