예제 #1
0
 /**
  * Checks whether an attack is legal or not.
  *
  * @return boolean
  **/
 public function check($update_timer = true)
 {
     $attacker = $this->attacker;
     $target = $this->target;
     $possible = array('required_turns', 'ignores_stealth', 'self_use', 'clan_forbidden');
     // *** Initializes all the possible param indexes. ***
     foreach ($possible as $loop_index) {
         ${$loop_index} = isset($this->params[$loop_index]) ? $this->params[$loop_index] : NULL;
     }
     if (!is_object($this->attacker)) {
         $this->error = 'Only Ninja can get close enough to attack.';
         return FALSE;
     } elseif (!is_object($this->target)) {
         $this->error = 'No valid target was found.';
         return FALSE;
     } elseif (!isset($this->params['required_turns'])) {
         $this->error = 'The required number of turns was not specified.';
         return FALSE;
     }
     $second_interval_limiter_on_attacks = '.25';
     // Originally .2
     $sel_last_started_attack = "SELECT player_id FROM players\n\t\t\tWHERE player_id = :char_id\n\t\t\tAND ((now() - :interval::interval) >= last_started_attack) LIMIT 1";
     // *** Returns a player id if the enough time has passed, or else or false/null. ***
     $attack_later_than_limit = query_item($sel_last_started_attack, array(':char_id' => intval($this->attacker->id()), ':interval' => $second_interval_limiter_on_attacks . ' second'));
     if ($attack_later_than_limit && $update_timer) {
         // *** If not too soon, update the attack limit. ***
         update_last_attack_time($attacker->id());
         // updates the timestamp of the last_attacked column to slow excessive attacks.
     }
     //  *** START OF ILLEGAL ATTACK ERROR LIST  ***
     if (!$attack_later_than_limit) {
         $this->error = 'Even the fastest ninja cannot act more than four times a second.';
     } else {
         if (empty($target->vo->uname)) {
             $this->error = 'Your target does not exist.';
         } else {
             if ($target->id() == $attacker->id() && !$self_use) {
                 $this->error = 'Commiting suicide is a tactic reserved for samurai.';
             } else {
                 if ($attacker->vo->turns < $required_turns) {
                     $this->error = 'You don\'t have enough turns for that, wait for the half hour or use amanita mushrooms to gain more turns.';
                 } else {
                     if (!$self_use && $this->sameDomain($target, $attacker)) {
                         $this->error = 'You can not attack a ninja from the same domain.';
                     } else {
                         if ($target->vo->active == 0) {
                             $this->error = 'You can not attack an inactive ninja.';
                         } else {
                             if ($attacker->vo->active == 0) {
                                 $this->error = 'You cannot attack when your ninja is retired/inactive.';
                             } else {
                                 if ($target->health() < 1) {
                                     $this->error = "They're already dead.";
                                 } else {
                                     if ($target->hasStatus(STEALTH) && !$ignores_stealth) {
                                         // Attacks that ignore stealth will skip this.
                                         $this->error = 'Your target is stealthed. You can only hit this ninja using certain techniques.';
                                     } else {
                                         if ($clan_forbidden && $target->getClan()->getID() == $attacker->getClan()->getID() && $attacker->getClan() == null && !$self_use) {
                                             $this->error = 'Your clan would outcast you if you attacked one of your own.';
                                         } else {
                                             if ($target->health() > 0) {
                                                 $this->error = null;
                                                 return true;
                                                 //  ***  ATTACK IS LEGAL ***
                                             } else {
                                                 //  *** CATCHALL ERROR MESSAGE ***
                                                 $this->error = 'There was a problem with your attack.';
                                                 error_log('The problem catch-all for attackLegal object was triggered, which should not occur.');
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return empty($this->error);
 }
예제 #2
0
 /**
  * Checks whether an attack is legal or not.
  *
  * @return boolean
  **/
 function check()
 {
     $sql = new DBAccess();
     $attacker = $this->attacker;
     $target = $this->target;
     $possible = array('required_turns', 'ignores_stealth', 'self_use', 'clan_forbidden');
     //Initializes all the possible param indexes.
     foreach ($possible as $loop_index) {
         ${$loop_index} = isset($this->params[$loop_index]) ? $this->params[$loop_index] : NULL;
     }
     if (!is_object($this->attacker)) {
         $this->error = 'Only Ninja can get close enough to attack.';
         return FALSE;
     } elseif (!is_object($this->target)) {
         $this->error = 'No valid target was found.';
         return FALSE;
     } elseif (!isset($this->params['required_turns'])) {
         $this->error = 'The required number of turns was not specified.';
         return FALSE;
     }
     $target_status = $target->getStatus();
     $second_interval_limiter_on_attacks = '.25';
     // Originally .2
     $sel_last_started_attack = "select player_id from players\n\t\t\twhere player_id = '" . intval($this->attacker->player_id) . "'\n\t\t\tand ((now() - interval '" . $second_interval_limiter_on_attacks . " second') >= last_started_attack) limit 1";
     $attack_later_than_limit = $sql->QueryItem($sel_last_started_attack);
     // Returns a player id if the enough time has passed, or else or false/null.
     if ($attack_later_than_limit) {
         // If not too soon, update the attack limit.
         update_last_attack_time($attacker->vo->player_id, $sql);
     }
     // updates the timestamp of the last_attacked column to slow excessive attacks.
     switch (true) {
         //  *** START OF ILLEGAL ATTACK ERROR LIST  ***
         case !$attack_later_than_limit:
             $this->error = "Even the fastest ninja cannot act more than four times a second.";
             return false;
             break;
         case $target->vo->uname == "":
             $this->error = "Your target does not exist.";
             return false;
             break;
         case $target->player_id == $attacker->player_id && !$self_use:
             $this->error = "Commiting suicide is a tactic reserved for samurai.";
             return false;
             break;
         case $attacker->vo->turns < $required_turns:
             $this->error = "You do not have enough turns to perform this action in this way.";
             return false;
             break;
         case isset($_SESSION) && $target->vo->ip == $_SESSION['ip'] && $_SESSION['ip'] != '127.0.0.1' && !$self_use:
             $this->error = "You can not attack a ninja from the same domain.";
             return false;
             break;
         case $target->vo->confirmed == 0:
             $this->error = "You can not attack an inactive ninja.";
             return false;
             break;
         case $target->vo->health < 1:
             $this->error = "Your target is a ghost.";
             return false;
             break;
         case $target_status['Stealth'] && !$ignores_stealth:
             // Attacks that ignore stealth will skip this.
             $this->error = "Your target is stealthed. You can only hit this ninja using certain techniques.";
             return false;
             break;
         case $clan_forbidden && ($target->vo->clan == $attacker->vo->clan && $attacker->vo->clan != "" && !$self_use):
             $this->error = "Your clan would outcast you if you attacked one of your own.";
             return false;
             break;
         case $target->vo->health > 0:
             return true;
             //  ***  ATTACK IS LEGAL ***
             break;
         default:
             //  *** CATCHALL ERROR MESSAGE ***
             $this->error = "There was a problem with your attack.";
             error_log('The problem catch-all for attackLegal object was triggered, which should not occur.');
             return false;
             break;
     }
 }