protected function _exec() { $gameuid = $this->getParam('gameuid', 'int'); $characterId = $this->getParam('heroid', 'int'); $pieceItemId = $this->getParam('pieceItemId', 'int'); $pieceitemDef = get_xml_def($pieceItemId); if (empty($pieceitemDef)) { $this->throwException("itemId is not item {$pieceItemId}"); } $composeId = $pieceitemDef['boundItem']; $composeDef = get_xml_def($composeId); if (empty($composeDef)) { $this->throwException("composeitemId is not item {$composeId}"); } $itemMgr = new UserGameItemManager($characterId); $composeOwnItem = $itemMgr->getItem($composeId); $pieceOwnItem = $itemMgr->getItem($pieceItemId); $curLevel = 0; if (!empty($composeOwnItem)) { $curLevel = $composeOwnItem['count']; } $pieceArr = explode(",", $composeDef['upCount']); $needPiece = $pieceArr[$curLevel]; if ($pieceitemDef['type'] == "skill") { $needCoin = StaticFunction::getUpSkillCoin($curLevel); } else { if ($pieceitemDef['type'] == "soldier") { $needCoin = StaticFunction::getUpSoldierCoin($curLevel); } } if (empty($pieceOwnItem) || $pieceOwnItem['count'] < $needPiece) { $this->throwException("composeitemId piece is not enough {$pieceItemId}"); } $user_mgr = new UserAccountManager(); $user_account = $user_mgr->getUserAccount($gameuid); if ($user_account['coin'] < $needCoin) { $this->throwException("character {$gameuid} not enough coin {$needCoin} "); } $itemMgr->addItem($composeId, 1); $itemMgr->subItem($pieceItemId, $needPiece); $user_mgr->updateUserCoin($gameuid, -$needCoin); $itemMgr->commitToDB(); return array("state" => TRUE); }
protected function _exec() { $gameuid = $this->getParam('gameuid', 'int'); $name = $this->getParam('name', 'string'); $itemId = $this->getParam('itemId', 'int'); $characterId = $this->getParam('characterId', 'int'); $characterDef = get_xml_def($itemId); if (empty($characterDef) || intval($itemId / 10000) != 1) { $this->throwException("itemId is not character {$itemId}", GameStatusCode::DATA_ERROR); } $HeroCost = StaticFunction::$heroCost; $user_mgr = new UserAccountManager(); $user_account = $user_mgr->getUserAccount($gameuid); if ($characterId >= count($HeroCost)) { $this->throwException("character id not enough characterId: {$characterId} ", GameStatusCode::DATA_ERROR); } $costcoin = $HeroCost[$characterId]["coin"]; if ($costcoin > $user_account["coin"]) { $this->throwException("user not enough coin: {$costcoin} ", GameStatusCode::DATA_ERROR); } $change = array('coin' => -$costcoin); $costgem = $HeroCost[$characterId]["gem"]; if ($costgem > $user_account["gem"]) { $this->throwException("user not enough gem: {$costgem} ", GameStatusCode::DATA_ERROR); } $change['gem'] = -$costgem; $new_CharacterId = intval($gameuid * 10 + $characterId); $character_mgr = new CharacterAccountManager(); $character_info = $character_mgr->getCharacterAccount($new_CharacterId); if (!empty($character_info)) { $this->throwException("character id is exist characterId: {$new_CharacterId} ", GameStatusCode::DATA_ERROR); } $character_info = $character_mgr->createCharacterAccount($new_CharacterId, $name, $itemId); $itemMgr = new UserGameItemManager($new_CharacterId); $initItems = InitUser::$item_arr[$itemId]; foreach ($initItems as $v) { $itemMgr->addItem($v['item_id'], $v['count']); } $itemMgr->commitToDB(); $user_mgr->updateUserStatus($gameuid, $change); return array("character" => $character_info, "change" => $change); }
protected function _exec() { $gameuid = $this->getParam('gameuid', 'int'); $itemId = $this->getParam('itemId', 'int'); $count = $this->getParam('count', 'int'); $useGem = $this->getParam('useGem', 'bool'); $characterId = $this->getParam('heroid', 'int'); $itemDef = get_xml_def($itemId); if (empty($itemDef)) { $this->throwException("itemId is not item {$itemId}"); } $cost = 0; if ($useGem) { $cost = $itemDef['gem'] * $count; } else { $cost = $itemDef['coin'] * $count; } if ($cost <= 0) { $this->throwException("itemId is no cost useGem {$useGem} : {$cost}"); } $itemMgr = new UserGameItemManager($characterId); $itemMgr->addItem($itemId, $count); $user_mgr = new UserAccountManager(); $user_account = $user_mgr->getUserAccount($gameuid); if ($useGem) { if ($user_account['gem'] < $cost) { $this->throwException("character {$gameuid} not enough gem {$cost}"); } $user_mgr->updateUserMoney($gameuid, -$cost); } else { if ($user_account['coin'] < $cost) { $this->throwException("character {$gameuid} not enough coin {$cost}"); } $user_mgr->updateUserCoin($gameuid, -$cost); } $itemMgr->commitToDB(); return array("state" => TRUE); }
protected function _exec() { $gameuid = $this->getParam('gameuid', 'int'); $heroid = $this->getParam('heroid', 'int'); $name = $this->getParam('name', 'string'); $user_clan_mgr = new UserClanManager(); $clanInfo = $user_clan_mgr->getUserClanInfo($heroid); if (!empty($clanInfo)) { $this->throwException("user {$heroid} already have clan "); } $account_mgr = new UserAccountManager(); $account_info = $account_mgr->getUserAccount($gameuid); if ($account_info['gem'] < 20) { $this->throwException("user {$gameuid} not enough gem to buy Clan "); } $clan_mgr = new ClanManager(); $result = $clan_mgr->creatClan($heroid, $name); $user_clan_info = $user_clan_mgr->creatUserClan($heroid, $result['data_id']); $account_mgr->updateUserMoney($gameuid, 20); $hero_mgr = new CharacterAccountManager(); $result['admin'] = $hero_mgr->getCharacterAccount($heroid); $result['membersArr'] = array($user_clan_info); return array('clan' => $result); }
/** * @param $params */ public function execute($params = null) { try { if ($this->isServiceClosed($params['gameuid'])) { return $this->getReturnArray(GameStatusCode::SYSTEM_MAINTAIN, 'service closed.'); } // return $this->getReturnArray(0,'ok',"test"); if (isset($params['gameuid'])) { $gameuid = intval($params['gameuid']); if ($gameuid <= 0) { $this->throwException("user[{$gameuid}] not exists", GameStatusCode::USER_NOT_EXISTS); } if (isset($params['friend_gameuid'])) { if (empty($params['friend_gameuid']) || $params['friend_gameuid'] <= 0) { $this->throwException("friend user[" . $params['friend_gameuid'] . "] not exist", GameStatusCode::USER_NOT_EXISTS); } } $this->action_logger = new UserActionLogManager($gameuid); $this->user_account = $this->user_account_mgr->getUserAccount($gameuid); if (empty($this->user_account)) { $this->throwException("user[{$gameuid}] not exists", GameStatusCode::USER_NOT_EXISTS); } // //是否被禁用 // if($this->user_account['disabled'] == "1"){ // return $this->getReturnArray(GameStatusCode::USER_NOT_EXISTS,"user[$gameuid] is disbaled."); // } // $this->checkSession($gameuid); } // 对参数做处理 $this->params = $params; // if(!$this->isPerfTestMode($params['gameuid'])){ // if(!get_app_config()->getGlobalConfig("debug_mode")){ // $this->checkSignature($params); // } // $this->validate(); // } $now = time(); //调用游戏接口 $result = $this->_exec(); // // 根据动作的定义,获取用户的经验值和金币的修改值 // $modify = array_intersect_key($result,array('coin'=>0,'money'=>0,'coupon'=>0,'experience'=>0)); // if (isset($this->params['action_id'])) { // if (intval($this->action_def['coin']) != 0) $modify['coin'] += intval($this->action_def['coin']); // if (intval($this->action_def['experience']) != 0) $modify['experience'] += intval($this->action_def['experience']); // } // // //修改用户的经验值和金币数量 // if (count($modify) > 0) { // $this->user_account_mgr->updateUserStatus($gameuid, $modify); // $result = array_merge($result, $modify); // } // // //检查action是否要进行计数 // if (isset($this->params['action_id'])&&in_array($this->params['action_id'], $this->action_record_count)){ // UserActionCountManager::updateActionCount($this->params['gameuid'],$this->params['action_id']); // } // //判断是否要写actionlog日志 // if (!empty($modify) && isset($this->params['action_id'])){ // $action_log_params=array(); // $action_log_params=$modify; // if (isset($result['action_log_params'])){ // $action_log_params['content']=$result['action_log_params']['content']; // unset($result['action_log_params']); // } // $this->action_logger->writeLog($this->params['action_id'], $action_log_params); // } //如果有eventlog,则写log日志,同时将返回值中的相关信息删除 if (isset($result['event_log_params']) && is_array($result['event_log_params'])) { $event_log_params = $result['event_log_params']; $event_gameuid = $event_log_params['gameuid']; $event_action_id = $event_log_params['action_id']; $event_params = $event_log_params['params']; $event_logger = new UserEventLogManager($event_gameuid); $event_logger->writeLog($event_action_id, $event_params); unset($result['event_log_params']); } return $this->getReturnArray(0, 'ok', $result); } catch (DBException $e) { // 数据库类型的错误特殊处理 $this->logger->writeError("database exception happens while execute sql, error_msg:" . $e->getMessage()); $this->logger->writeError("and the stack trace is as below:\n" . $e->getTraceAsString()); if (get_app_config()->getGlobalConfig("debug_mode")) { return $this->getReturnArray(GameStatusCode::DATABASE_ERROR, $e->getMessage()); } else { return $this->getReturnArray(GameStatusCode::DATABASE_ERROR, 'database error'); } } catch (GameException $e) { $this->logger->writeError("game exception happens while execute action:" . $e); //log输出过多,关闭之 return $this->getReturnArray($e->getCode(), $e->getMessage()); } catch (Exception $e) { // 其他的错误 $this->logger->writeError("unknown exception happens while execute action." . $e->getTraceAsString()); return $this->getReturnArray(GameStatusCode::UNKNOWN_ERROR, $e->getMessage()); } return $this->getReturnArray(GameStatusCode::UNKNOWN_ERROR, ''); }
/** * * @return int */ private function initSeq() { $key = $this->getMemKey(); $seq = $this->cache->get($key); if ($seq === FALSE) { $sql = sprintf("select LAST_INSERT_ID() from %s", $this->table_name); $value = $this->dbhelper->resultFirst($sql); if (!empty($value)) { $seq = $value['gameuid']; } } if ($seq != FALSE && $seq >= 1) { $user_mgr = new UserAccountManager(); $account = $user_mgr->getUserAccount($seq); $nexAccount = $user_mgr->getUserAccount($seq); } if (empty($account) || !empty($nexAccount)) { $sql = sprintf("select ifnull(max(%s),0) max_value from %s", "gameuid", $this->table_name); $res = $this->dbhelper->getOne($sql); $seq = $res['max_value']; } return $seq; }