/** * * @param stdClass $input * @param stdClass $parentInput * @param GameAction $oGameAction * @return GameAction */ public static function mapGameActionFromAPI($input, $parentInput, GameAction $oOutput = null) { $oGameActionType = NefubTypeMapper::mapTypeFromAPI($input->Type, 'GameActionType'); $time = date('H:i:s', '00:' . strtotime($input->Time)); if (!$oOutput) { $where = array('game_nefub_id' => $parentInput->ID, 'team_nefub_id' => $input->Team->ID, 'game_action_type_id' => $oGameActionType->getId(), 'period' => $input->Period, 'time' => $time); $oOutput = GameAction::getSingle($where); if (!$oOutput) { $oOutput = new GameAction(); } } // Mapping $oOutput->time = $time; $oOutput->period = $input->Period; $oOutput->game_nefub_id = $parentInput->ID; $oOutput->team_nefub_id = $input->Team->ID; $oOutput->game_action_type_id = $oGameActionType->getId(); $oOutput->code = $input->Code; $oOutput->description = $input->Description; if ($input->Person) { $oOutput->person_nefub_id = $input->Person->ID; } if ($input->Assist) { $oOutput->assist_person_nefub_id = $input->Assist->ID; } $oOutput->save(); self::log('GameAction toegevoegd aan Game ' . $oOutput->game_nefub_id); return $oOutput; }
public function getGameActionSummery() { $aGameActions = $this->getGameActions(); $return = array('goals', 'assists', 'penalty_minutes'); foreach ($aGameActions as $oGameAction) { $oGameAction = new GameAction($oGameAction->getId()); $oGameActionType = $oGameAction->getGameActionType(); if ($oGameActionType->use) { if ($oGameActionType->is_goal) { $return['goals']++; } $return['penalty_minutes'] += $oGameActionType->minutes; } } $oGameActionAssists = $this->getAssists(); $return['assists'] = count($oGameActionAssists); return $return; }
/** * * @return array */ public function getGameActions($period = null) { $where = array('game_nefub_id' => $this->nefub_id); if ($period) { $where['period'] = $period; } return GameAction::getAll($where); }
/** * * @param stdClass $gameAction * @param Team $oTeam * @param Game $oGame */ private function convertGameAction(stdClass $gameAction, Game $oGame, $team1_score, $team2_score) { $oGameAction = new GameAction(); $oGameAction->period = $gameAction->Period; $oGameAction->time = '00:' . str_pad(str_replace('.', ':', $gameAction->Time), 5, '0', STR_PAD_LEFT); $oGameAction->game_nefub_id = $oGame->nefub_id; $oGameAction->team_nefub_id = $gameAction->Team->ID; $oGameAction->person_nefub_id = $gameAction->Person->ID; if ($gameAction->Assist) { $oGameAction->assist_person_nefub_id = $gameAction->Assist->ID; } // add new unkown type $oType = GameActionType::getByNefubName($gameAction->Type); if (!$oType) { self::put('Wedstrijdactietype ' . $gameAction->Type . ' toegevoegd'); $oType = new GameActionType(); $oType->name = $gameAction->Type; $oType->nefub_name = $gameAction->Type; $oType->use = true; $oType->save(); $this->addedNefubObject($oType); } $oGameAction->game_action_type_id = $oType->getId(); if ($gameAction->Code) { $oGameAction->code = $gameAction->Code; $oGameAction->description = $gameAction->Description; } // add a point to the assigned team is needed if ($oType->is_goal) { if ($oGameAction->team_nefub_id == $oGame->team1_nefub_id) { $team1_score++; } else { $team2_score++; } } $oGameAction->team1_score = $team1_score; $oGameAction->team2_score = $team2_score; $oGameAction->save(); $this->addedNefubObject($oGameAction); return $oGameAction; }
/** * API:武将解锁直接拥有 * * @access public * @param int $user_id 用户ID $general_id主角ID * @return array */ public function isUnlock($user_id) { $starNum = GameAction::getUserStar($user_id); $userGeneral = UserCache::getByKey($user_id, 's_general_info'); if (!$userGeneral) { $userGeneral = GeneralModel::getUserGeneralInfo($user_id); UserCache::setByKey($user_id, 's_general_info', $userGeneral); } //读取系统武将,属性列表 $file = IniFileManager::getRootDir() . "/files/csv/general.csv"; $generalArr = CharacterAction::readCsv($file); foreach ($generalArr as $key => $value) { if (!$userGeneral[$value['general_id']]) { if ($starNum >= $value['unlock_star']) { //添加新武将到武将信息字段、更新用户金钱 $userGeneral[$value['general_id']] = array('n_continue_level' => 0, 'n_cool_level' => 0); $unlockInfo = $value['general_id']; } } } $s_general_info = serialize($userGeneral); $ret = GeneralModel::update(array('s_general_info' => $s_general_info), array('n_id' => $user_id)); UserCache::setByKey($user_id, 's_general_info', $userGeneral); //更新战斗力 $battle = UserAction::getUserBattle($user_id); GeneralModel::update(array('n_battle' => $battle), array('n_id' => $user_id)); UserCache::setByKey($user_id, 'n_battle', $battle); return $unlockInfo ? $unlockInfo : 0; }