Beispiel #1
0
 /**
  * Updates soldier's AP if needed
  */
 public function updateAP()
 {
     $apGain = $this->_ruleset->get('soldier.apGain');
     $period = $this->_ruleset->get('game.period');
     $maxAp = $this->_ruleset->get('soldier.maxAp');
     $updatedAP = APHelpers::update($this->_ruleset->get('soldier.maxAp'), $this->_ruleset->get('game.period'), $this->_ruleset->get('soldier.apGain'), $this->AP, $this->time_from_last_regen);
     if ($updatedAP['ap'] != $this->AP) {
         $this->_db->executeRequest('updateSoldierAP', array(':id' => $this->ID, ':ap' => $updatedAP['ap'], ':toRemove' => $updatedAP['toRemove']));
         $this->AP = $updatedAP['ap'];
     }
 }
Beispiel #2
0
 /**
  * Loads a personna infos and update its AP if needed
  *
  * @param int $id ID of the personna to load
  */
 public function load($id)
 {
     $this->_db->beginTransaction();
     try {
         $personna = $this->_db->fetchFirstRequest('getPersonna', array(':id' => $id));
         if (empty($personna)) {
             throw new Exception('Personna not found');
         }
         // Update personna AP
         $updatedAP = APHelpers::update($this->_ruleset->get('personna.maxAp'), $this->_ruleset->get('game.period'), $this->_ruleset->get('personna.apGain'), $personna['AP'], $personna['time_from_last_regen']);
         if ($updatedAP['ap'] != $personna['AP']) {
             $this->_db->executeRequest('updatePersonna', array(':id' => $id, ':ap' => $updatedAP['ap'], ':toRemove' => $updatedAP['toRemove']));
             $personna['AP'] = $updatedAP['ap'];
         }
         // Get logs
         $personna['logs'] = array();
         $logs = $this->_db->fetchAllRequest('getPersonnaLogs', array(':userId' => $personna['user_id'], ':battlefieldId' => $personna['battlefield_id'], ':currentItemId' => $personna['current_item_id']));
         if (!empty($logs)) {
             foreach ($logs as $log) {
                 $actionLog = new ActionLog($this->_DI);
                 $actionLog->loadFromArray($log);
                 $personna['logs'][] = $actionLog;
             }
         }
         if ($personna['is_soldier']) {
             $personna['item'] = new Soldier($personna['current_item_id'], $this->_DI);
             $personna['item']->setRuleset($this->_ruleset);
             $personna['item']->updateAP();
         } else {
             $personna['item'] = new Headquarter($personna['current_item_id'], $this->_DI);
         }
         $this->_data = $personna;
     } catch (Exception $e) {
         $this->_db->rollBack();
         throw $e;
     }
     $this->_db->commit();
 }