We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
| 198 | 198 | return array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
| 199 | 199 | } |
| 200 | - $damage =& $this->getModifiedDamage(); |
|
| 200 | + $damage = & $this->getModifiedDamage(); |
|
| 201 | 201 | return $damage; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
| 207 | 207 | return array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
| 208 | 208 | } |
| 209 | - $damage =& $this->getModifiedDamage(); |
|
| 209 | + $damage = & $this->getModifiedDamage(); |
|
| 210 | 210 | return $damage; |
| 211 | 211 | } |
| 212 | 212 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
| 216 | 216 | return array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
| 217 | 217 | } |
| 218 | - $damage =& $this->getModifiedDamage(); |
|
| 218 | + $damage = & $this->getModifiedDamage(); |
|
| 219 | 219 | |
| 220 | 220 | $planetMod = self::PLANET_DAMAGE_MOD; |
| 221 | 221 | $damage['MaxDamage'] = ICeil($damage['MaxDamage'] * $planetMod); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $return = array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
| 236 | 236 | return $return; |
| 237 | 237 | } |
| 238 | - $damage =& $this->getModifiedDamage(); |
|
| 238 | + $damage = & $this->getModifiedDamage(); |
|
| 239 | 239 | return $damage; |
| 240 | 240 | } |
| 241 | 241 | |
@@ -1,35 +1,35 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -$CombatPort =& $PortCombatResults['Port']; |
|
| 2 | +$CombatPort = & $PortCombatResults['Port']; |
|
| 3 | 3 | $TotalDamage = $PortCombatResults['TotalDamage']; |
| 4 | -if($MinimalDisplay) { |
|
| 4 | +if ($MinimalDisplay) { |
|
| 5 | 5 | echo $CombatPort->getDisplayName(); |
| 6 | - if($TotalDamage > 0) { |
|
| 6 | + if ($TotalDamage > 0) { |
|
| 7 | 7 | ?> hit for a total of <span class="red"><?php echo $TotalDamage ?></span> damage in this round of combat of which <span class="red"><?php echo $PortCombatResults['TotalDamagePerTargetPlayer'][$ThisPlayer->getAccountID()]; ?></span> was done to you<?php |
| 8 | 8 | } else { |
| 9 | 9 | ?> does no damage this round<?php |
| 10 | 10 | } ?>. <?php echo $AttackLogLink; |
| 11 | 11 | return; |
| 12 | 12 | } |
| 13 | -if(isset($PortCombatResults['Weapons']) && is_array($PortCombatResults['Weapons'])) { |
|
| 14 | - foreach($PortCombatResults['Weapons'] as $WeaponResults) { |
|
| 15 | - $ShootingWeapon =& $WeaponResults['Weapon']; |
|
| 16 | - $ShotHit =& $WeaponResults['Hit']; |
|
| 17 | - $ActualDamage =& $WeaponResults['ActualDamage']; |
|
| 18 | - $WeaponDamage =& $WeaponResults['WeaponDamage']; |
|
| 19 | - $TargetPlayer =& $WeaponResults['TargetPlayer']; |
|
| 13 | +if (isset($PortCombatResults['Weapons']) && is_array($PortCombatResults['Weapons'])) { |
|
| 14 | + foreach ($PortCombatResults['Weapons'] as $WeaponResults) { |
|
| 15 | + $ShootingWeapon = & $WeaponResults['Weapon']; |
|
| 16 | + $ShotHit = & $WeaponResults['Hit']; |
|
| 17 | + $ActualDamage = & $WeaponResults['ActualDamage']; |
|
| 18 | + $WeaponDamage = & $WeaponResults['WeaponDamage']; |
|
| 19 | + $TargetPlayer = & $WeaponResults['TargetPlayer']; |
|
| 20 | 20 | |
| 21 | - echo $CombatPort->getDisplayName() ?> fires an <?php echo $ShootingWeapon->getName() ?> at <?php if($ShotHit && $ActualDamage['TargetAlreadyDead']){ ?> the debris that was once <?php } echo $TargetPlayer->getDisplayName(); |
|
| 21 | + echo $CombatPort->getDisplayName() ?> fires an <?php echo $ShootingWeapon->getName() ?> at <?php if ($ShotHit && $ActualDamage['TargetAlreadyDead']) { ?> the debris that was once <?php } echo $TargetPlayer->getDisplayName(); |
|
| 22 | 22 | if (!$ShotHit || !$ActualDamage['TargetAlreadyDead']) { |
| 23 | - if(!$ShotHit) { |
|
| 23 | + if (!$ShotHit) { |
|
| 24 | 24 | ?> and misses<?php |
| 25 | - } else if($ActualDamage['TotalDamage'] == 0) { |
|
| 26 | - if($WeaponDamage['Shield'] > 0) { |
|
| 27 | - if($ActualDamage['HasCDs']) { |
|
| 25 | + } else if ($ActualDamage['TotalDamage'] == 0) { |
|
| 26 | + if ($WeaponDamage['Shield'] > 0) { |
|
| 27 | + if ($ActualDamage['HasCDs']) { |
|
| 28 | 28 | ?> which proves ineffective against their combat drones<?php |
| 29 | 29 | } else { |
| 30 | 30 | ?> which washes harmlessly over their hull<?php |
| 31 | 31 | } |
| 32 | - } else if($WeaponDamage['Armour'] > 0) { |
|
| 32 | + } else if ($WeaponDamage['Armour'] > 0) { |
|
| 33 | 33 | ?> which is deflected by their shields<?php |
| 34 | 34 | } else { |
| 35 | 35 | ?> but it cannot do any damage<?php |
@@ -37,49 +37,49 @@ discard block |
||
| 37 | 37 | } else { |
| 38 | 38 | ?> destroying <?php |
| 39 | 39 | $DamageTypes = 0; |
| 40 | - if($ActualDamage['Shield'] > 0){ $DamageTypes = $DamageTypes+1; } |
|
| 41 | - if($ActualDamage['NumCDs'] > 0){ $DamageTypes = $DamageTypes+1; } |
|
| 42 | - if($ActualDamage['Armour'] > 0){ $DamageTypes = $DamageTypes+1; } |
|
| 40 | + if ($ActualDamage['Shield'] > 0) { $DamageTypes = $DamageTypes + 1; } |
|
| 41 | + if ($ActualDamage['NumCDs'] > 0) { $DamageTypes = $DamageTypes + 1; } |
|
| 42 | + if ($ActualDamage['Armour'] > 0) { $DamageTypes = $DamageTypes + 1; } |
|
| 43 | 43 | |
| 44 | - if($ActualDamage['Shield'] > 0) { |
|
| 44 | + if ($ActualDamage['Shield'] > 0) { |
|
| 45 | 45 | ?><span class="shields"><?php echo number_format($ActualDamage['Shield']) ?></span> shields<?php |
| 46 | 46 | $this->doDamageTypeReductionDisplay($DamageTypes); |
| 47 | 47 | } |
| 48 | - if($ActualDamage['NumCDs'] > 0) { |
|
| 48 | + if ($ActualDamage['NumCDs'] > 0) { |
|
| 49 | 49 | ?><span class="cds"><?php echo number_format($ActualDamage['NumCDs']) ?></span> combat drones<?php |
| 50 | 50 | $this->doDamageTypeReductionDisplay($DamageTypes); |
| 51 | 51 | } |
| 52 | - if($ActualDamage['Armour'] > 0) { |
|
| 52 | + if ($ActualDamage['Armour'] > 0) { |
|
| 53 | 53 | ?><span class="red"><?php echo number_format($ActualDamage['Armour']) ?></span> plates of armour<?php |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | } ?>. |
| 57 | 57 | <br /><?php |
| 58 | 58 | if ($ShotHit && $ActualDamage['KillingShot']) { |
| 59 | - $this->includeTemplate('includes/TraderCombatKillMessage.inc',array('KillResults'=>$WeaponResults['KillResults'],'TargetPlayer'=>$TargetPlayer)); |
|
| 59 | + $this->includeTemplate('includes/TraderCombatKillMessage.inc', array('KillResults'=>$WeaponResults['KillResults'], 'TargetPlayer'=>$TargetPlayer)); |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | -if(isset($PortCombatResults['Drones'])) { |
|
| 64 | - $Drones =& $PortCombatResults['Drones']; |
|
| 65 | - $ActualDamage =& $Drones['ActualDamage']; |
|
| 66 | - $WeaponDamage =& $Drones['WeaponDamage']; |
|
| 67 | - $TargetPlayer =& $Drones['TargetPlayer']; |
|
| 63 | +if (isset($PortCombatResults['Drones'])) { |
|
| 64 | + $Drones = & $PortCombatResults['Drones']; |
|
| 65 | + $ActualDamage = & $Drones['ActualDamage']; |
|
| 66 | + $WeaponDamage = & $Drones['WeaponDamage']; |
|
| 67 | + $TargetPlayer = & $Drones['TargetPlayer']; |
|
| 68 | 68 | |
| 69 | 69 | echo $CombatPort->getDisplayName(); |
| 70 | - if($WeaponDamage['Launched'] == 0) { |
|
| 70 | + if ($WeaponDamage['Launched'] == 0) { |
|
| 71 | 71 | ?> fails to launch it's combat drones<?php |
| 72 | 72 | } else { |
| 73 | - ?> launches <span class="cds"><?php echo $WeaponDamage['Launched'] ?></span> combat drones at <?php if($ActualDamage['TargetAlreadyDead']){ ?>the debris that was once <?php } echo $TargetPlayer->getDisplayName(); |
|
| 74 | - if(!$ActualDamage['TargetAlreadyDead']) { |
|
| 75 | - if($ActualDamage['TotalDamage'] == 0) { |
|
| 76 | - if($WeaponDamage['Shield'] > 0) { |
|
| 77 | - if($ActualDamage['HasCDs']) { |
|
| 73 | + ?> launches <span class="cds"><?php echo $WeaponDamage['Launched'] ?></span> combat drones at <?php if ($ActualDamage['TargetAlreadyDead']) { ?>the debris that was once <?php } echo $TargetPlayer->getDisplayName(); |
|
| 74 | + if (!$ActualDamage['TargetAlreadyDead']) { |
|
| 75 | + if ($ActualDamage['TotalDamage'] == 0) { |
|
| 76 | + if ($WeaponDamage['Shield'] > 0) { |
|
| 77 | + if ($ActualDamage['HasCDs']) { |
|
| 78 | 78 | ?> which prove ineffective against their combat drones<?php |
| 79 | 79 | } else { |
| 80 | 80 | ?> which washes harmlessly over their hull<?php |
| 81 | 81 | } |
| 82 | - } else if($WeaponDamage['Armour'] > 0) { |
|
| 82 | + } else if ($WeaponDamage['Armour'] > 0) { |
|
| 83 | 83 | ?> which is deflected by their shields<?php |
| 84 | 84 | } else { |
| 85 | 85 | ?> but they cannot do any damage<?php |
@@ -1,10 +1,10 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -foreach($TraderTeamCombatResults['Traders'] as $AccountID => $TraderResults) { |
|
| 3 | - $ShootingPlayer =& $TraderResults['Player']; |
|
| 4 | - $TotalDamage =& $TraderResults['TotalDamage']; |
|
| 5 | - if($MinimalDisplay && !$ThisPlayer->equals($ShootingPlayer)) { |
|
| 2 | +foreach ($TraderTeamCombatResults['Traders'] as $AccountID => $TraderResults) { |
|
| 3 | + $ShootingPlayer = & $TraderResults['Player']; |
|
| 4 | + $TotalDamage = & $TraderResults['TotalDamage']; |
|
| 5 | + if ($MinimalDisplay && !$ThisPlayer->equals($ShootingPlayer)) { |
|
| 6 | 6 | echo $ShootingPlayer->getDisplayName(); |
| 7 | - if($TotalDamage > 0) { |
|
| 7 | + if ($TotalDamage > 0) { |
|
| 8 | 8 | ?> hits for a total of <span class="red"><?php echo $TotalDamage ?></span> damage in this round of combat<?php |
| 9 | 9 | } else { |
| 10 | 10 | ?> does no damage this round<?php |
@@ -12,29 +12,29 @@ discard block |
||
| 12 | 12 | continue; |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | - if($TraderResults['DeadBeforeShot']) { |
|
| 15 | + if ($TraderResults['DeadBeforeShot']) { |
|
| 16 | 16 | echo $ShootingPlayer->getDisplayName() ?> died before they were able to attack!<br /><?php |
| 17 | 17 | } else { |
| 18 | - if(isset($TraderResults['Weapons']) && is_array($TraderResults['Weapons'])) { |
|
| 19 | - foreach($TraderResults['Weapons'] as $WeaponResults) { |
|
| 20 | - $ShootingWeapon =& $WeaponResults['Weapon']; |
|
| 21 | - $ShotHit =& $WeaponResults['Hit']; |
|
| 22 | - $ActualDamage =& $WeaponResults['ActualDamage']; |
|
| 23 | - $WeaponDamage =& $WeaponResults['WeaponDamage']; |
|
| 24 | - $TargetPort =& $WeaponResults['TargetPort']; |
|
| 18 | + if (isset($TraderResults['Weapons']) && is_array($TraderResults['Weapons'])) { |
|
| 19 | + foreach ($TraderResults['Weapons'] as $WeaponResults) { |
|
| 20 | + $ShootingWeapon = & $WeaponResults['Weapon']; |
|
| 21 | + $ShotHit = & $WeaponResults['Hit']; |
|
| 22 | + $ActualDamage = & $WeaponResults['ActualDamage']; |
|
| 23 | + $WeaponDamage = & $WeaponResults['WeaponDamage']; |
|
| 24 | + $TargetPort = & $WeaponResults['TargetPort']; |
|
| 25 | 25 | |
| 26 | - echo $ShootingPlayer->getDisplayName() ?> fires their <?php echo $ShootingWeapon->getName() ?> at <?php if($ShotHit && $ActualDamage['TargetAlreadyDead']){ ?>the remnants of <?php } echo $TargetPort->getDisplayName(); |
|
| 26 | + echo $ShootingPlayer->getDisplayName() ?> fires their <?php echo $ShootingWeapon->getName() ?> at <?php if ($ShotHit && $ActualDamage['TargetAlreadyDead']) { ?>the remnants of <?php } echo $TargetPort->getDisplayName(); |
|
| 27 | 27 | if (!$ShotHit || !$ActualDamage['TargetAlreadyDead']) { |
| 28 | - if(!$ShotHit) { |
|
| 28 | + if (!$ShotHit) { |
|
| 29 | 29 | ?> and misses every critical system<?php |
| 30 | - } else if($ActualDamage['TotalDamage'] == 0) { |
|
| 31 | - if($WeaponDamage['Shield'] > 0) { |
|
| 32 | - if($ActualDamage['HasCDs']) { |
|
| 30 | + } else if ($ActualDamage['TotalDamage'] == 0) { |
|
| 31 | + if ($WeaponDamage['Shield'] > 0) { |
|
| 32 | + if ($ActualDamage['HasCDs']) { |
|
| 33 | 33 | ?> which proves ineffective against their combat drones<?php |
| 34 | 34 | } else { |
| 35 | 35 | ?> which proves ineffective against it's armour<?php |
| 36 | 36 | } |
| 37 | - } else if($WeaponDamage['Armour'] > 0) { |
|
| 37 | + } else if ($WeaponDamage['Armour'] > 0) { |
|
| 38 | 38 | ?> which is deflected by their shields<?php |
| 39 | 39 | } else { |
| 40 | 40 | ?> but it cannot do any damage<?php |
@@ -42,55 +42,55 @@ discard block |
||
| 42 | 42 | } else { |
| 43 | 43 | ?> destroying <?php |
| 44 | 44 | $DamageTypes = 0; |
| 45 | - if($ActualDamage['Shield'] > 0){ $DamageTypes = $DamageTypes+1; } |
|
| 46 | - if($ActualDamage['NumCDs'] > 0){ $DamageTypes = $DamageTypes+1; } |
|
| 47 | - if($ActualDamage['Armour'] > 0){ $DamageTypes = $DamageTypes+1; } |
|
| 45 | + if ($ActualDamage['Shield'] > 0) { $DamageTypes = $DamageTypes + 1; } |
|
| 46 | + if ($ActualDamage['NumCDs'] > 0) { $DamageTypes = $DamageTypes + 1; } |
|
| 47 | + if ($ActualDamage['Armour'] > 0) { $DamageTypes = $DamageTypes + 1; } |
|
| 48 | 48 | |
| 49 | - if($ActualDamage['Shield'] > 0) { |
|
| 49 | + if ($ActualDamage['Shield'] > 0) { |
|
| 50 | 50 | ?><span class="shields"><?php echo number_format($ActualDamage['Shield']) ?></span> shields<?php |
| 51 | 51 | $this->doDamageTypeReductionDisplay($DamageTypes); |
| 52 | 52 | } |
| 53 | - if($ActualDamage['NumCDs'] > 0) { |
|
| 53 | + if ($ActualDamage['NumCDs'] > 0) { |
|
| 54 | 54 | ?><span class="cds"><?php echo number_format($ActualDamage['NumCDs']) ?></span> combat drones<?php |
| 55 | 55 | $this->doDamageTypeReductionDisplay($DamageTypes); |
| 56 | 56 | } |
| 57 | - if($ActualDamage['Armour'] > 0) { |
|
| 57 | + if ($ActualDamage['Armour'] > 0) { |
|
| 58 | 58 | ?><span class="red"><?php echo number_format($ActualDamage['Armour']) ?></span> plates of armour<?php |
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | } ?>. |
| 62 | 62 | <br /><?php |
| 63 | 63 | if ($ShotHit && $ActualDamage['KillingShot']) { |
| 64 | - $this->includeTemplate('includes/PortKillMessage.inc',array('KillResults'=>$WeaponResults['KillResults'],'TargetPort'=>$TargetPort,'ShootingPlayer'=>$ShootingPlayer)); |
|
| 64 | + $this->includeTemplate('includes/PortKillMessage.inc', array('KillResults'=>$WeaponResults['KillResults'], 'TargetPort'=>$TargetPort, 'ShootingPlayer'=>$ShootingPlayer)); |
|
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | - if(isset($TraderResults['Drones'])) { |
|
| 69 | - $Drones =& $TraderResults['Drones']; |
|
| 70 | - $ActualDamage =& $Drones['ActualDamage']; |
|
| 71 | - $WeaponDamage =& $Drones['WeaponDamage']; |
|
| 72 | - $TargetPort =& $Drones['TargetPort']; |
|
| 68 | + if (isset($TraderResults['Drones'])) { |
|
| 69 | + $Drones = & $TraderResults['Drones']; |
|
| 70 | + $ActualDamage = & $Drones['ActualDamage']; |
|
| 71 | + $WeaponDamage = & $Drones['WeaponDamage']; |
|
| 72 | + $TargetPort = & $Drones['TargetPort']; |
|
| 73 | 73 | |
| 74 | 74 | echo $ShootingPlayer->getDisplayName(); |
| 75 | - if($WeaponDamage['Launched'] == 0) { |
|
| 75 | + if ($WeaponDamage['Launched'] == 0) { |
|
| 76 | 76 | ?> fails to launch their combat drones<?php |
| 77 | 77 | } else { |
| 78 | 78 | ?> launches <span class="cds"><?php echo $WeaponDamage['Launched'] ?></span> combat drones at <?php |
| 79 | - if($ActualDamage['TargetAlreadyDead']) { |
|
| 79 | + if ($ActualDamage['TargetAlreadyDead']) { |
|
| 80 | 80 | ?>the debris that was once <?php |
| 81 | 81 | } |
| 82 | 82 | echo $TargetPort->getDisplayName(); |
| 83 | 83 | |
| 84 | - if(!$ActualDamage['TargetAlreadyDead']) { |
|
| 85 | - if($ActualDamage['TotalDamage'] == 0) { |
|
| 86 | - if($WeaponDamage['Shield'] > 0) { |
|
| 87 | - if($ActualDamage['HasCDs']) { |
|
| 84 | + if (!$ActualDamage['TargetAlreadyDead']) { |
|
| 85 | + if ($ActualDamage['TotalDamage'] == 0) { |
|
| 86 | + if ($WeaponDamage['Shield'] > 0) { |
|
| 87 | + if ($ActualDamage['HasCDs']) { |
|
| 88 | 88 | ?> which prove ineffective against their combat drones<?php |
| 89 | 89 | } else { |
| 90 | 90 | ?> which proves ineffective against it's armour<?php |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | - if($ActualDamage['Armour'] > 0) { |
|
| 93 | + if ($ActualDamage['Armour'] > 0) { |
|
| 94 | 94 | ?> which is deflected by their shields<?php |
| 95 | 95 | } else { |
| 96 | 96 | ?> but they cannot do any damage<?php |
@@ -85,68 +85,68 @@ |
||
| 85 | 85 | abstract public function &getModifiedForceDamageAgainstPlayer(SmrForce $forces, AbstractSmrPlayer $targetPlayer); |
| 86 | 86 | |
| 87 | 87 | protected function &doPlayerDamageToForce(array &$return, AbstractSmrPlayer $weaponPlayer, SmrForce $forces) { |
| 88 | - $return['WeaponDamage'] =& $this->getModifiedDamageAgainstForces($weaponPlayer,$forces); |
|
| 89 | - $return['ActualDamage'] =& $forces->doWeaponDamage($return['WeaponDamage']); |
|
| 90 | - if($return['ActualDamage']['KillingShot']) { |
|
| 91 | - $return['KillResults'] =& $forces->killForcesByPlayer($weaponPlayer); |
|
| 88 | + $return['WeaponDamage'] = & $this->getModifiedDamageAgainstForces($weaponPlayer, $forces); |
|
| 89 | + $return['ActualDamage'] = & $forces->doWeaponDamage($return['WeaponDamage']); |
|
| 90 | + if ($return['ActualDamage']['KillingShot']) { |
|
| 91 | + $return['KillResults'] = & $forces->killForcesByPlayer($weaponPlayer); |
|
| 92 | 92 | } |
| 93 | 93 | return $return; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | protected function &doPlayerDamageToPlayer(array &$return, AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer) { |
| 97 | - $return['WeaponDamage'] =& $this->getModifiedDamageAgainstPlayer($weaponPlayer,$targetPlayer); |
|
| 98 | - $return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
| 97 | + $return['WeaponDamage'] = & $this->getModifiedDamageAgainstPlayer($weaponPlayer, $targetPlayer); |
|
| 98 | + $return['ActualDamage'] = & $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
| 99 | 99 | |
| 100 | - if($return['ActualDamage']['KillingShot']) { |
|
| 101 | - $return['KillResults'] =& $targetPlayer->killPlayerByPlayer($weaponPlayer); |
|
| 100 | + if ($return['ActualDamage']['KillingShot']) { |
|
| 101 | + $return['KillResults'] = & $targetPlayer->killPlayerByPlayer($weaponPlayer); |
|
| 102 | 102 | } |
| 103 | 103 | return $return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | protected function &doPlayerDamageToPort(array &$return, AbstractSmrPlayer $weaponPlayer, SmrPort $port) { |
| 107 | - $return['WeaponDamage'] =& $this->getModifiedDamageAgainstPort($weaponPlayer,$port); |
|
| 108 | - $return['ActualDamage'] =& $port->doWeaponDamage($return['WeaponDamage']); |
|
| 109 | - if($return['ActualDamage']['KillingShot']) { |
|
| 110 | - $return['KillResults'] =& $port->killPortByPlayer($weaponPlayer); |
|
| 107 | + $return['WeaponDamage'] = & $this->getModifiedDamageAgainstPort($weaponPlayer, $port); |
|
| 108 | + $return['ActualDamage'] = & $port->doWeaponDamage($return['WeaponDamage']); |
|
| 109 | + if ($return['ActualDamage']['KillingShot']) { |
|
| 110 | + $return['KillResults'] = & $port->killPortByPlayer($weaponPlayer); |
|
| 111 | 111 | } |
| 112 | 112 | return $return; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | protected function &doPlayerDamageToPlanet(array &$return, AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet, $delayed) { |
| 116 | - $return['WeaponDamage'] =& $this->getModifiedDamageAgainstPlanet($weaponPlayer,$planet); |
|
| 117 | - $return['ActualDamage'] =& $planet->doWeaponDamage($return['WeaponDamage'],$delayed); |
|
| 118 | - if($return['ActualDamage']['KillingShot']) { |
|
| 119 | - $return['KillResults'] =& $planet->killPlanetByPlayer($weaponPlayer); |
|
| 116 | + $return['WeaponDamage'] = & $this->getModifiedDamageAgainstPlanet($weaponPlayer, $planet); |
|
| 117 | + $return['ActualDamage'] = & $planet->doWeaponDamage($return['WeaponDamage'], $delayed); |
|
| 118 | + if ($return['ActualDamage']['KillingShot']) { |
|
| 119 | + $return['KillResults'] = & $planet->killPlanetByPlayer($weaponPlayer); |
|
| 120 | 120 | } |
| 121 | 121 | return $return; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | protected function &doPortDamageToPlayer(array &$return, SmrPort $port, AbstractSmrPlayer $targetPlayer) { |
| 125 | - $return['WeaponDamage'] =& $this->getModifiedPortDamageAgainstPlayer($port,$targetPlayer); |
|
| 126 | - $return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
| 125 | + $return['WeaponDamage'] = & $this->getModifiedPortDamageAgainstPlayer($port, $targetPlayer); |
|
| 126 | + $return['ActualDamage'] = & $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
| 127 | 127 | |
| 128 | - if($return['ActualDamage']['KillingShot']) { |
|
| 129 | - $return['KillResults'] =& $targetPlayer->killPlayerByPort($port); |
|
| 128 | + if ($return['ActualDamage']['KillingShot']) { |
|
| 129 | + $return['KillResults'] = & $targetPlayer->killPlayerByPort($port); |
|
| 130 | 130 | } |
| 131 | 131 | return $return; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | protected function &doPlanetDamageToPlayer(array &$return, SmrPlanet $planet, AbstractSmrPlayer $targetPlayer) { |
| 135 | - $return['WeaponDamage'] =& $this->getModifiedPlanetDamageAgainstPlayer($planet,$targetPlayer); |
|
| 136 | - $return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
| 135 | + $return['WeaponDamage'] = & $this->getModifiedPlanetDamageAgainstPlayer($planet, $targetPlayer); |
|
| 136 | + $return['ActualDamage'] = & $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
| 137 | 137 | |
| 138 | - if($return['ActualDamage']['KillingShot']) { |
|
| 139 | - $return['KillResults'] =& $targetPlayer->killPlayerByPlanet($planet); |
|
| 138 | + if ($return['ActualDamage']['KillingShot']) { |
|
| 139 | + $return['KillResults'] = & $targetPlayer->killPlayerByPlanet($planet); |
|
| 140 | 140 | } |
| 141 | 141 | return $return; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | protected function &doForceDamageToPlayer(array &$return, SmrForce $forces, AbstractSmrPlayer $targetPlayer) { |
| 145 | - $return['WeaponDamage'] =& $this->getModifiedForceDamageAgainstPlayer($forces,$targetPlayer); |
|
| 146 | - $return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
| 145 | + $return['WeaponDamage'] = & $this->getModifiedForceDamageAgainstPlayer($forces, $targetPlayer); |
|
| 146 | + $return['ActualDamage'] = & $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
| 147 | 147 | |
| 148 | - if($return['ActualDamage']['KillingShot']) { |
|
| 149 | - $return['KillResults'] =& $targetPlayer->killPlayerByForces($forces); |
|
| 148 | + if ($return['ActualDamage']['KillingShot']) { |
|
| 149 | + $return['KillResults'] = & $targetPlayer->killPlayerByForces($forces); |
|
| 150 | 150 | } |
| 151 | 151 | return $return; |
| 152 | 152 | } |
@@ -52,10 +52,10 @@ |
||
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | public function isAttacking(array &$board, array &$hasMoved, $king, $x = -1, $y = -1) { |
| 55 | - $moves =& $this->getPossibleMoves($board, $hasMoved, null, true); |
|
| 56 | - foreach($moves as &$move) { |
|
| 57 | - $p =& $board[$move[1]][$move[0]]; |
|
| 58 | - if(($move[0] == $x && $move[1] == $y) || ($king === true && $p != null && $p->pieceID == self::KING && $this->colour != $p->colour)) { |
|
| 55 | + $moves = & $this->getPossibleMoves($board, $hasMoved, null, true); |
|
| 56 | + foreach ($moves as &$move) { |
|
| 57 | + $p = & $board[$move[1]][$move[0]]; |
|
| 58 | + if (($move[0] == $x && $move[1] == $y) || ($king === true && $p != null && $p->pieceID == self::KING && $this->colour != $p->colour)) { |
|
| 59 | 59 | return true; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | $this->cargo_left = $this->getCargoHolds(); |
| 18 | 18 | } |
| 19 | 19 | protected function doFullUNO() { |
| 20 | - foreach($this->getMaxHardware() as $hardwareTypeID => $max) { |
|
| 20 | + foreach ($this->getMaxHardware() as $hardwareTypeID => $max) { |
|
| 21 | 21 | $this->hardware[$hardwareTypeID] = $max; |
| 22 | 22 | $this->oldHardware[$hardwareTypeID] = $max; |
| 23 | 23 | } |
@@ -47,8 +47,8 @@ discard block |
||
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | public function getIllusionShip() { |
| 50 | - if(!isset($this->illusionShip)) { |
|
| 51 | - $this->illusionShip=false; |
|
| 50 | + if (!isset($this->illusionShip)) { |
|
| 51 | + $this->illusionShip = false; |
|
| 52 | 52 | } |
| 53 | 53 | return $this->illusionShip; |
| 54 | 54 | } |
@@ -58,20 +58,20 @@ discard block |
||
| 58 | 58 | $db = new SmrMySqlDatabase(); |
| 59 | 59 | $db->query('REPLACE INTO cached_dummys ' . |
| 60 | 60 | '(type, id, info) ' . |
| 61 | - 'VALUES (\'DummyShip\', '.$db->escapeString($this->getPlayer()->getPlayerName()).', '.$db->escapeString($cache).')'); |
|
| 61 | + 'VALUES (\'DummyShip\', ' . $db->escapeString($this->getPlayer()->getPlayerName()) . ', ' . $db->escapeString($cache) . ')'); |
|
| 62 | 62 | unserialize($cache); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | public static function getCachedDummyShip(AbstractSmrPlayer $player) { |
| 66 | - if(!isset(self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()])) { |
|
| 66 | + if (!isset(self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()])) { |
|
| 67 | 67 | $db = new SmrMySqlDatabase(); |
| 68 | 68 | $db->query('SELECT info FROM cached_dummys |
| 69 | 69 | WHERE type = \'DummyShip\' |
| 70 | 70 | AND id = ' . $db->escapeString($player->getPlayerName()) . ' LIMIT 1'); |
| 71 | - if($db->nextRecord()) { |
|
| 71 | + if ($db->nextRecord()) { |
|
| 72 | 72 | $return = unserialize($db->getField('info')); |
| 73 | 73 | $return->regenerate($player); |
| 74 | - self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()] =& $return; |
|
| 74 | + self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()] = & $return; |
|
| 75 | 75 | } else { |
| 76 | 76 | self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()] = new DummyShip($player); |
| 77 | 77 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $db->query('SELECT id FROM cached_dummys |
| 85 | 85 | WHERE type = \'DummyShip\''); |
| 86 | 86 | $dummyNames = array(); |
| 87 | - while($db->nextRecord()) { |
|
| 87 | + while ($db->nextRecord()) { |
|
| 88 | 88 | $dummyNames[] = $db->getField('id'); |
| 89 | 89 | } |
| 90 | 90 | return $dummyNames; |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | |
| 95 | 95 | public function __sleep() { |
| 96 | - return array('gameID','weapons'); |
|
| 96 | + return array('gameID', 'weapons'); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | public function __wakeup() { |
@@ -10,22 +10,22 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | debug('Script started'); |
| 12 | 12 | define('SCRIPT_ID', $db->getInsertID()); |
| 13 | - $db->query('UPDATE npc_logs SET script_id='.SCRIPT_ID.' WHERE log_id='.SCRIPT_ID); |
|
| 13 | + $db->query('UPDATE npc_logs SET script_id=' . SCRIPT_ID . ' WHERE log_id=' . SCRIPT_ID); |
|
| 14 | 14 | |
| 15 | 15 | define('NPC_SCRIPT', true); |
| 16 | 16 | |
| 17 | 17 | $descriptorSpec = array( |
| 18 | - 0 => array("pipe", "r"), // stdin is a pipe that the child will read from |
|
| 18 | + 0 => array("pipe", "r"), // stdin is a pipe that the child will read from |
|
| 19 | 19 | 1 => array("pipe", "w") // stdout is a pipe that the child will write to |
| 20 | 20 | ); |
| 21 | 21 | $engine = proc_open(UCI_CHESS_ENGINE, $descriptorSpec, $pipes); |
| 22 | - $toEngine =& $pipes[0]; |
|
| 23 | - $fromEngine =& $pipes[1]; |
|
| 22 | + $toEngine = & $pipes[0]; |
|
| 23 | + $fromEngine = & $pipes[1]; |
|
| 24 | 24 | |
| 25 | 25 | function readFromEngine($block = true) { |
| 26 | 26 | global $fromEngine; |
| 27 | 27 | stream_set_blocking($fromEngine, $block == true ? 1 : 0); |
| 28 | - while(($s = fgets($fromEngine)) !== false) { |
|
| 28 | + while (($s = fgets($fromEngine)) !== false) { |
|
| 29 | 29 | debug('<-- ' . trim($s)); |
| 30 | 30 | stream_set_blocking($fromEngine, 0); |
| 31 | 31 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | global $toEngine; |
| 35 | 35 | debug('--> ' . $s); |
| 36 | 36 | fputs($toEngine, $s . EOL); |
| 37 | - if($read === true) { |
|
| 37 | + if ($read === true) { |
|
| 38 | 38 | readFromEngine($block); |
| 39 | 39 | } |
| 40 | 40 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | writeToEngine('isready'); |
| 46 | 46 | writeToEngine('ucinewgame', false); |
| 47 | 47 | |
| 48 | - while(true) { |
|
| 48 | + while (true) { |
|
| 49 | 49 | //Redefine MICRO_TIME and TIME, the rest of the game expects them to be the single point in time that the script is executing, with it being redefined for each page load - unfortunately NPCs are one consistent script so we have to do a hack and redefine it (or change every instance of the TIME constant). |
| 50 | 50 | runkit_constant_redefine('MICRO_TIME', microtime(true)); |
| 51 | 51 | runkit_constant_redefine('TIME', IFloor(MICRO_TIME)); |
@@ -55,9 +55,9 @@ discard block |
||
| 55 | 55 | writeToEngine('position fen ' . $chessGame->getFENString(), false); |
| 56 | 56 | writeToEngine('go ' . ($chessGame->getCurrentTurnColour() == ChessGame::PLAYER_WHITE ? 'w' : 'b') . 'time ' . UCI_TIME_PER_MOVE_MS, true, false); |
| 57 | 57 | stream_set_blocking($fromEngine, 1); |
| 58 | - while(stripos($move = trim(fgets($fromEngine)), 'bestmove') !== 0) { |
|
| 58 | + while (stripos($move = trim(fgets($fromEngine)), 'bestmove') !== 0) { |
|
| 59 | 59 | debug('<-- ' . $move); |
| 60 | - if(stripos($move, 'Seg') === 0) { |
|
| 60 | + if (stripos($move, 'Seg') === 0) { |
|
| 61 | 61 | // Segfault |
| 62 | 62 | debug('UCI engine segfaulted?'); |
| 63 | 63 | exit; |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | fclose($toEngine); |
| 78 | 78 | fclose($fromEngine); |
| 79 | 79 | proc_close($engine); |
| 80 | -} catch(Throwable $e) { |
|
| 80 | +} catch (Throwable $e) { |
|
| 81 | 81 | logException($e); |
| 82 | 82 | exit; |
| 83 | 83 | } |
| 84 | 84 | function debug($message, $debugObject = null) { |
| 85 | - global $account,$var,$db; |
|
| 86 | - echo date('Y-m-d H:i:s - ').$message.($debugObject!==null?EOL.var_export($debugObject,true):'').EOL; |
|
| 87 | - $db->query('INSERT INTO npc_logs (script_id, npc_id, time, message, debug_info, var) VALUES ('.(defined('SCRIPT_ID')?SCRIPT_ID:0).', '.(is_object($account)?$account->getAccountID():0).',NOW(),'.$db->escapeString($message).','.$db->escapeString(var_export($debugObject,true)).','.$db->escapeString(var_export($var,true)).')'); |
|
| 85 | + global $account, $var, $db; |
|
| 86 | + echo date('Y-m-d H:i:s - ') . $message . ($debugObject !== null ?EOL.var_export($debugObject, true) : '') . EOL; |
|
| 87 | + $db->query('INSERT INTO npc_logs (script_id, npc_id, time, message, debug_info, var) VALUES (' . (defined('SCRIPT_ID') ?SCRIPT_ID:0) . ', ' . (is_object($account) ? $account->getAccountID() : 0) . ',NOW(),' . $db->escapeString($message) . ',' . $db->escapeString(var_export($debugObject, true)) . ',' . $db->escapeString(var_export($var, true)) . ')'); |
|
| 88 | 88 | } |
@@ -3,11 +3,11 @@ |
||
| 3 | 3 | // Holds information linking the received message and the game data |
| 4 | 4 | class GameLink |
| 5 | 5 | { |
| 6 | - public $valid = false; // identifies if the message is linked to game data |
|
| 7 | - public $user; // Discord user associated with the message |
|
| 8 | - public $account; // SmrAccount instance |
|
| 9 | - public $alliance; // SmrAlliance instance |
|
| 10 | - public $player; // SmrPlayer instance |
|
| 6 | + public $valid = false; // identifies if the message is linked to game data |
|
| 7 | + public $user; // Discord user associated with the message |
|
| 8 | + public $account; // SmrAccount instance |
|
| 9 | + public $alliance; // SmrAlliance instance |
|
| 10 | + public $player; // SmrPlayer instance |
|
| 11 | 11 | |
| 12 | 12 | // Takes the following arguments: |
| 13 | 13 | // channel = Discord\Parts\Channel\Channel instance |
@@ -201,29 +201,29 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | public function getFENString() { |
| 203 | 203 | $fen = ''; |
| 204 | - $board =& $this->getBoard(); |
|
| 204 | + $board = & $this->getBoard(); |
|
| 205 | 205 | $blanks = 0; |
| 206 | - for($y=0; $y < 8; $y++) { |
|
| 207 | - if($y > 0) { |
|
| 206 | + for ($y = 0; $y < 8; $y++) { |
|
| 207 | + if ($y > 0) { |
|
| 208 | 208 | $fen .= '/'; |
| 209 | 209 | } |
| 210 | - for($x=0; $x < 8; $x++) { |
|
| 211 | - if($board[$y][$x] == null) { |
|
| 210 | + for ($x = 0; $x < 8; $x++) { |
|
| 211 | + if ($board[$y][$x] == null) { |
|
| 212 | 212 | $blanks++; |
| 213 | 213 | } else { |
| 214 | - if($blanks > 0) { |
|
| 214 | + if ($blanks > 0) { |
|
| 215 | 215 | $fen .= $blanks; |
| 216 | 216 | $blanks = 0; |
| 217 | 217 | } |
| 218 | 218 | $fen .= $board[$y][$x]->getPieceLetter(); |
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | - if($blanks > 0) { |
|
| 221 | + if ($blanks > 0) { |
|
| 222 | 222 | $fen .= $blanks; |
| 223 | 223 | $blanks = 0; |
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | - switch($this->getCurrentTurnColour()) { |
|
| 226 | + switch ($this->getCurrentTurnColour()) { |
|
| 227 | 227 | case self::PLAYER_WHITE: |
| 228 | 228 | $fen .= ' w '; |
| 229 | 229 | break; |
@@ -449,72 +449,72 @@ discard block |
||
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | public static function movePiece(array &$board, array &$hasMoved, $x, $y, $toX, $toY, $pawnPromotionPiece = ChessPiece::QUEEN) { |
| 452 | - if(!self::isValidCoord($x, $y, $board)) { |
|
| 452 | + if (!self::isValidCoord($x, $y, $board)) { |
|
| 453 | 453 | throw new Exception('Invalid from coordinates, x=' . $x . ', y=' . $y); |
| 454 | 454 | } |
| 455 | - if(!self::isValidCoord($toX, $toY, $board)) { |
|
| 455 | + if (!self::isValidCoord($toX, $toY, $board)) { |
|
| 456 | 456 | throw new Exception('Invalid to coordinates, x=' . $toX . ', y=' . $toY); |
| 457 | 457 | } |
| 458 | 458 | $pieceTaken = $board[$toY][$toX]; |
| 459 | 459 | $board[$toY][$toX] = $board[$y][$x]; |
| 460 | - $p =& $board[$toY][$toX]; |
|
| 460 | + $p = & $board[$toY][$toX]; |
|
| 461 | 461 | $board[$y][$x] = null; |
| 462 | - if($p == null) { |
|
| 462 | + if ($p == null) { |
|
| 463 | 463 | throw new Exception('Trying to move non-existent piece: ' . var_export($board, true)); |
| 464 | 464 | } |
| 465 | 465 | $p->setX($toX); |
| 466 | 466 | $p->setY($toY); |
| 467 | 467 | |
| 468 | 468 | $oldPawnMovement = $hasMoved[ChessPiece::PAWN]; |
| 469 | - $nextPawnMovement = array(-1,-1); |
|
| 469 | + $nextPawnMovement = array(-1, -1); |
|
| 470 | 470 | $castling = false; |
| 471 | 471 | $enPassant = false; |
| 472 | 472 | $rookMoved = false; |
| 473 | 473 | $rookTaken = false; |
| 474 | 474 | $pawnPromotion = false; |
| 475 | - if($p->pieceID == ChessPiece::KING) { |
|
| 475 | + if ($p->pieceID == ChessPiece::KING) { |
|
| 476 | 476 | //Castling? |
| 477 | 477 | $castling = self::isCastling($x, $toX); |
| 478 | - if($castling !== false) { |
|
| 478 | + if ($castling !== false) { |
|
| 479 | 479 | $hasMoved[$p->colour][ChessPiece::KING] = true; |
| 480 | 480 | $hasMoved[$p->colour][ChessPiece::ROOK][$castling['Type']] = true; |
| 481 | - if($board[$y][$castling['X']] == null) { |
|
| 481 | + if ($board[$y][$castling['X']] == null) { |
|
| 482 | 482 | throw new Exception('Cannot castle with non-existent castle.'); |
| 483 | 483 | } |
| 484 | 484 | $board[$toY][$castling['ToX']] = $board[$y][$castling['X']]; |
| 485 | 485 | $board[$toY][$castling['ToX']]->setX($castling['ToX']); |
| 486 | 486 | $board[$y][$castling['X']] = null; |
| 487 | 487 | } |
| 488 | - } elseif($p->pieceID == ChessPiece::PAWN) { |
|
| 489 | - if($toY == 0 || $toY == 7) { |
|
| 488 | + } elseif ($p->pieceID == ChessPiece::PAWN) { |
|
| 489 | + if ($toY == 0 || $toY == 7) { |
|
| 490 | 490 | $pawnPromotion = $p->promote($pawnPromotionPiece, $board); |
| 491 | 491 | } |
| 492 | 492 | //Double move to track? |
| 493 | - elseif(($y == 1 || $y == 6) && ($toY == 3 || $toY == 4)) { |
|
| 493 | + elseif (($y == 1 || $y == 6) && ($toY == 3 || $toY == 4)) { |
|
| 494 | 494 | $nextPawnMovement = array($toX, $toY); |
| 495 | 495 | } |
| 496 | 496 | //En passant? |
| 497 | - elseif($hasMoved[ChessPiece::PAWN][0] == $toX && |
|
| 497 | + elseif ($hasMoved[ChessPiece::PAWN][0] == $toX && |
|
| 498 | 498 | ($hasMoved[ChessPiece::PAWN][1] == 3 && $toY == 2 || $hasMoved[ChessPiece::PAWN][1] == 4 && $toY == 5)) { |
| 499 | 499 | $enPassant = true; |
| 500 | 500 | $pieceTaken = $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]]; |
| 501 | - if($board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] == null) { |
|
| 501 | + if ($board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] == null) { |
|
| 502 | 502 | throw new Exception('Cannot en passant a non-existent pawn.'); |
| 503 | 503 | } |
| 504 | 504 | $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] = null; |
| 505 | 505 | } |
| 506 | - } elseif($p->pieceID == ChessPiece::ROOK && ($x == 0 || $x == 7) && $y == ($p->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
| 506 | + } elseif ($p->pieceID == ChessPiece::ROOK && ($x == 0 || $x == 7) && $y == ($p->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
| 507 | 507 | //Rook moved? |
| 508 | - if($hasMoved[$p->colour][ChessPiece::ROOK][$x==0?'Queen':'King'] === false) { |
|
| 508 | + if ($hasMoved[$p->colour][ChessPiece::ROOK][$x == 0 ? 'Queen' : 'King'] === false) { |
|
| 509 | 509 | // We set rook moved in here as it's used for move info. |
| 510 | - $rookMoved = $x==0?'Queen':'King'; |
|
| 510 | + $rookMoved = $x == 0 ? 'Queen' : 'King'; |
|
| 511 | 511 | $hasMoved[$p->colour][ChessPiece::ROOK][$rookMoved] = true; |
| 512 | 512 | } |
| 513 | 513 | } |
| 514 | 514 | // Check if we've taken a rook and marked them as moved, if they've already moved this does nothing, but if they were taken before moving this stops an issue with trying to castle with a non-existent castle. |
| 515 | - if($pieceTaken != null && $pieceTaken->pieceID == ChessPiece::ROOK && ($toX == 0 || $toX == 7) && $toY == ($pieceTaken->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
| 516 | - if($hasMoved[$pieceTaken->colour][ChessPiece::ROOK][$toX==0?'Queen':'King'] === false) { |
|
| 517 | - $rookTaken = $toX==0?'Queen':'King'; |
|
| 515 | + if ($pieceTaken != null && $pieceTaken->pieceID == ChessPiece::ROOK && ($toX == 0 || $toX == 7) && $toY == ($pieceTaken->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
| 516 | + if ($hasMoved[$pieceTaken->colour][ChessPiece::ROOK][$toX == 0 ? 'Queen' : 'King'] === false) { |
|
| 517 | + $rookTaken = $toX == 0 ? 'Queen' : 'King'; |
|
| 518 | 518 | $hasMoved[$pieceTaken->colour][ChessPiece::ROOK][$rookTaken] = true; |
| 519 | 519 | } |
| 520 | 520 | } |
@@ -531,18 +531,18 @@ discard block |
||
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | public static function undoMovePiece(array &$board, array &$hasMoved, $x, $y, $toX, $toY, $moveInfo) { |
| 534 | - if(!self::isValidCoord($x, $y, $board)) { |
|
| 534 | + if (!self::isValidCoord($x, $y, $board)) { |
|
| 535 | 535 | throw new Exception('Invalid from coordinates, x=' . $x . ', y=' . $y); |
| 536 | 536 | } |
| 537 | - if(!self::isValidCoord($toX, $toY, $board)) { |
|
| 537 | + if (!self::isValidCoord($toX, $toY, $board)) { |
|
| 538 | 538 | throw new Exception('Invalid to coordinates, x=' . $toX . ', y=' . $toY); |
| 539 | 539 | } |
| 540 | - if($board[$y][$x] != null) { |
|
| 540 | + if ($board[$y][$x] != null) { |
|
| 541 | 541 | throw new Exception('Undoing move onto another piece? x=' . $x . ', y=' . $y); |
| 542 | 542 | } |
| 543 | 543 | $board[$y][$x] = $board[$toY][$toX]; |
| 544 | - $p =& $board[$y][$x]; |
|
| 545 | - if($p == null) { |
|
| 544 | + $p = & $board[$y][$x]; |
|
| 545 | + if ($p == null) { |
|
| 546 | 546 | throw new Exception('Trying to undo move of a non-existent piece: ' . var_export($board, true)); |
| 547 | 547 | } |
| 548 | 548 | $board[$toY][$toX] = $moveInfo['PieceTaken']; |
@@ -591,73 +591,73 @@ discard block |
||
| 591 | 591 | $toX = ord($move[2]) - $aVal; |
| 592 | 592 | $toY = 8 - $move[3]; |
| 593 | 593 | $pawnPromotionPiece = null; |
| 594 | - if(isset($move[4])) { |
|
| 594 | + if (isset($move[4])) { |
|
| 595 | 595 | $pawnPromotionPiece = ChessPiece::getPieceForLetter($move[4]); |
| 596 | 596 | } |
| 597 | 597 | return $this->tryMove($x, $y, $toX, $toY, $this->getCurrentTurnAccountID(), $pawnPromotionPiece); |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | public function tryMove($x, $y, $toX, $toY, $forAccountID, $pawnPromotionPiece) { |
| 601 | - if($this->hasEnded()) { |
|
| 601 | + if ($this->hasEnded()) { |
|
| 602 | 602 | return 5; |
| 603 | 603 | } |
| 604 | - if($this->getCurrentTurnAccountID() != $forAccountID) { |
|
| 604 | + if ($this->getCurrentTurnAccountID() != $forAccountID) { |
|
| 605 | 605 | return 4; |
| 606 | 606 | } |
| 607 | 607 | $lastTurnPlayer = $this->getCurrentTurnPlayer(); |
| 608 | 608 | $this->getBoard(); |
| 609 | 609 | $p = $this->board[$y][$x]; |
| 610 | - if($p == null || $p->colour != $this->getColourForAccountID($forAccountID)) { |
|
| 610 | + if ($p == null || $p->colour != $this->getColourForAccountID($forAccountID)) { |
|
| 611 | 611 | return 2; |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | $moves = $p->getPossibleMoves($this->board, $this->getHasMoved(), $forAccountID); |
| 615 | - foreach($moves as $move) { |
|
| 616 | - if($move[0]==$toX && $move[1]==$toY) { |
|
| 615 | + foreach ($moves as $move) { |
|
| 616 | + if ($move[0] == $toX && $move[1] == $toY) { |
|
| 617 | 617 | $chessType = $this->isNPCGame() ? 'Chess (NPC)' : 'Chess'; |
| 618 | 618 | $currentPlayer = $this->getCurrentTurnPlayer(); |
| 619 | 619 | |
| 620 | 620 | $moveInfo = ChessGame::movePiece($this->board, $this->getHasMoved(), $x, $y, $toX, $toY, $pawnPromotionPiece); |
| 621 | 621 | |
| 622 | 622 | //We have taken the move, we should refresh $p |
| 623 | - $p =& $this->board[$toY][$toX]; |
|
| 623 | + $p = & $this->board[$toY][$toX]; |
|
| 624 | 624 | |
| 625 | 625 | $pieceTakenID = null; |
| 626 | - if($moveInfo['PieceTaken'] != null) { |
|
| 626 | + if ($moveInfo['PieceTaken'] != null) { |
|
| 627 | 627 | $pieceTakenID = $moveInfo['PieceTaken']->pieceID; |
| 628 | - if($moveInfo['PieceTaken']->pieceID == ChessPiece::KING) { |
|
| 628 | + if ($moveInfo['PieceTaken']->pieceID == ChessPiece::KING) { |
|
| 629 | 629 | throw new Exception('King was taken.'); |
| 630 | 630 | } |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | $pieceID = $p->pieceID; |
| 634 | 634 | $pieceNo = $p->pieceNo; |
| 635 | - if($moveInfo['PawnPromotion'] !== false) { |
|
| 635 | + if ($moveInfo['PawnPromotion'] !== false) { |
|
| 636 | 636 | $p->pieceID = $moveInfo['PawnPromotion']['PieceID']; |
| 637 | 637 | $p->pieceNo = $moveInfo['PawnPromotion']['PieceNo']; |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | $checking = null; |
| 641 | - if($p->isAttacking($this->board, $this->getHasMoved(), true)) { |
|
| 641 | + if ($p->isAttacking($this->board, $this->getHasMoved(), true)) { |
|
| 642 | 642 | $checking = 'CHECK'; |
| 643 | 643 | } |
| 644 | - if($this->isCheckmated(self::getOtherColour($p->colour))) { |
|
| 644 | + if ($this->isCheckmated(self::getOtherColour($p->colour))) { |
|
| 645 | 645 | $checking = 'MATE'; |
| 646 | 646 | } |
| 647 | - if($this->moves!=null) { |
|
| 647 | + if ($this->moves != null) { |
|
| 648 | 648 | $this->moves[] = $this->createMove($pieceID, $x, $y, $toX, $toY, $pieceTakenID, $checking, $this->getCurrentTurnColour(), $moveInfo['Castling']['Type'], $moveInfo['EnPassant'], $moveInfo['PawnPromotion'] === false ? null : $moveInfo['PawnPromotion']['PieceID']); |
| 649 | 649 | } |
| 650 | - if(self::isPlayerChecked($this->board, $this->getHasMoved(), $p->colour)) { |
|
| 650 | + if (self::isPlayerChecked($this->board, $this->getHasMoved(), $p->colour)) { |
|
| 651 | 651 | return 3; |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | $otherPlayer = $this->getCurrentTurnPlayer(); |
| 655 | - if($moveInfo['PawnPromotion'] !== false) { |
|
| 655 | + if ($moveInfo['PawnPromotion'] !== false) { |
|
| 656 | 656 | $piecePromotedSymbol = $p->getPieceSymbol(); |
| 657 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Own Pawns Promoted','Total'), HOF_PUBLIC); |
|
| 658 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pawns Promoted','Total'), HOF_PUBLIC); |
|
| 659 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Own Pawns Promoted',$piecePromotedSymbol), HOF_PUBLIC); |
|
| 660 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pawns Promoted',$piecePromotedSymbol), HOF_PUBLIC); |
|
| 657 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pawns Promoted', 'Total'), HOF_PUBLIC); |
|
| 658 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pawns Promoted', 'Total'), HOF_PUBLIC); |
|
| 659 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pawns Promoted', $piecePromotedSymbol), HOF_PUBLIC); |
|
| 660 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pawns Promoted', $piecePromotedSymbol), HOF_PUBLIC); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | $castlingType = $moveInfo['Castling'] === false ? null : $moveInfo['Castling']['Type']; |