/** * API:用户注册 * * @access public * @param 无 * @return JsonView 响应json */ public function exeUserRegister() { $requestParam = $this->getAllParameters(); Logger::debug('requestParam:' . print_r($requestParam, true)); $requestJsonParam = $this->getDecodedJsonRequest(); Logger::debug('requestJsonParam:' . print_r($requestJsonParam, true)); // 检测账号是否重复 $ret = AuthModel::checkUserAccount($requestJsonParam['account']); if (!$ret) { $view = new JsonView(); $messageArr['error'] = "该账号已存在"; return $this->getViewByJson($view, $messageArr, 0, "auth/user_register"); } // 检测账号是否重复 $ret = AuthModel::checkUserName($requestJsonParam['user_name']); if (!$ret) { $view = new JsonView(); $messageArr['error'] = "该昵称已存在"; return $this->getViewByJson($view, $messageArr, 0, "auth/user_register"); } // 插入新用户 $ret = AuthModel::insert(array('s_account' => $requestJsonParam['account'], 's_password' => $requestJsonParam['password'], 't_create_time' => date("Y-m-d H:i:s")), $pdo); if (is_null($ret)) { throw new ModelException('insert false pa_user_master'); } //---------------------------- 初始用户表 ---------------------------- $user_id = AuthModel::getUserID($requestJsonParam['account'], $requestJsonParam['password'], $pdo); $messageArr['n_id'] = $user_id; self::$userBasicIni['s_name'] = $requestJsonParam['user_name']; self::$userBasicIni['n_sex'] = $requestJsonParam['sex']; self::$userBasicIni['t_create_time'] = date("Y-m-d H:i:s"); // 初始化关卡信息 $checkPointIni = array(1 => array('score' => 0, 'scr_length' => 0, 'reward' => 0, 'kill_num' => 0, 'star_num' => 0)); //self::$userBasicIni['s_checkpoint_info'] = serialize( $checkPointIni ); // 初始化角色信息 self::$userBasicIni['s_role_info '] = CharacterAction::registCharacter($user_id, Constants::INI_CHARACTER_ID); // 初始化武将信息 self::$userBasicIni['s_general_info'] = GeneralAction::registGeneral($user_id, Constants::INI_GENERAL_ID); // 初始化任务信息 self::$userBasicIni['s_task_info'] = serialize(TaskAndAchieveAction::randTask($user_id)); // 初始化成就信息 self::$userBasicIni['s_achievement_info'] = TaskAndAchieveAction::registAchieveCsv($user_id); // 初始化签到信息 $loginInfo = UserAction::getUserLoginInfo(); self::$userBasicIni['s_login_info'] = serialize($loginInfo); $userInfo = array_merge($messageArr, self::$userBasicIni); $ret = UserModel::insert($userInfo, $pdo); FriendModel::insert(array('n_user_id' => $user_id, 'n_friend_id' => Constants::ROBERT, 't_create_time' => date("Y-m-d H:i:s"))); $battle = UserAction::getUserbattle($user_id); UserModel::update(array('n_battle' => $battle), array('n_id' => $user_id)); MailAction::sendSystemMail($user_id); if (is_null($ret)) { throw new ModelException('insert false pa_user_master'); } // // 成就 // $statisticArr['login_day'] = 1; // TaskAndAchieveAction::achieveStatistic( $user_id, $statisticArr ); $userInfo = array_merge($messageArr, self::$userBasicIni); $session_key = CharacterModel::setSessionKey($user_id, $session_key); $messageArr['total_day'] = $loginInfo['total_day']; $messageArr['session_key'] = $session_key; $view = new JsonView(); return $this->getViewByJson($view, $messageArr, 1, "auth/user_register"); }
/** * API:游戏结算 * * @access public * @param 无 * @return JsonView 响应json * {"scoreInfo":{"combo":[5,3,4],"award":10,"deduction":[3,2],"kill":{"monster":5,"boss":2}},"checkpoint_id":3,"scr_length":5,"star_num":5,"diamond":2,"pass":1} */ public function exeEndGame() { $requestParam = $this->getAllParameters(); Logger::debug('requestParam:' . print_r($requestParam, true)); $requestJsonParam = $this->getDecodedJsonRequest(); Logger::debug('requestJsonParam:' . print_r($requestJsonParam, true)); //------------------------------------统计分数--------------------------------------- $checkPointId = $requestJsonParam['checkpoint_id']; // 评级总分 $dir = IniFileManager::getRootDir() . "files/csv/" . self::CHECKPOINT_LIST . ".csv"; $str = "checkpoint_id = " . $checkPointId; $checkpointArr = Util::readCsv($dir, $str); if (empty($checkpointArr)) { $view = new JsonView(); $messageArr['error'] = "关卡不存在"; return $this->getViewByJson($view, $messageArr, 0, "game/end_game"); } $gradeScore = $checkpointArr[0]['grade_score']; $scoreInfo = $requestJsonParam['scoreInfo']; // 连击奖励分总和 if (count($scoreInfo['combo']) > 0) { foreach ($scoreInfo['combo'] as $key => $value) { $comboNum = $value; } } $comboTotal = $comboNum * 3; // 得人参果分总和 $rewardTotal = $scoreInfo['award']; // 杀怪总分 $killTotal = $scoreInfo['kill']['monster'] + $scoreInfo['kill']['boss'] * 3; // 被击扣分总和 $deduction = $scoreInfo['deduction'][0] * 5 + $scoreInfo['deduction'][1] * 5; // 通关分 $passScore = $gradeScore * 0.1; // 技巧评分 $skillScore = ($comboTotal + $rewardTotal + $killTotal + $passScore - $deduction) / $gradeScore * 100; //------------------------------------最优关卡信息--------------------------------------- // 获取原有最优信息 $userInfo = UserCache::getAllUserCache($requestParam['user_id']); if (!$userInfo) { $userInfo = UserAction::iniUserInfo($requestParam['user_id']); } $checkPointInfo = $userInfo['s_checkpoint_info']; // 此次游戏需对比信息 $newInfo['score'] = $skillScore; $newInfo['scr_length'] = $requestJsonParam['scr_length']; $newInfo['reward'] = $scoreInfo['award']; $newInfo['kill_num'] = $scoreInfo['kill']['monster'] + $scoreInfo['kill']['boss']; $newInfo['star_num'] = $requestJsonParam['star_num']; $addStarNum = 0; if ($checkPointInfo[$checkPointId]) { // 分数判断 if ($newInfo['score'] > $checkPointInfo[$checkPointId]['score']) { $checkPointInfo[$checkPointId]['score'] = $newInfo['score']; $updateType = 1; } // 最短划痕 if ($newInfo['scr_length'] < $checkPointInfo[$checkPointId]['scr_length']) { $checkPointInfo[$checkPointId]['scr_length'] = $newInfo['scr_length']; $updateType = 1; } // 单局最多人生果 if ($newInfo['reward'] > $checkPointInfo[$checkPointId]['reward']) { $checkPointInfo[$checkPointId]['reward'] = $newInfo['reward']; $updateType = 1; } // 单局杀死最多怪物数 if ($newInfo['kill_num'] > $checkPointInfo[$checkPointId]['kill_num']) { $checkPointInfo[$checkPointId]['kill_num'] = $newInfo['kill_num']; $updateType = 1; } // 该关卡获得星星数 if ($newInfo['star_num'] > $checkPointInfo[$checkPointId]['star_num']) { $checkPointInfo[$checkPointId]['star_num'] = $newInfo['star_num']; $updateType = 1; $addStarNum = $newInfo['star_num'] - $checkPointInfo[$checkPointId]['star_num']; } } else { $updateType = 1; $checkPointInfo[$checkPointId] = $newInfo; // 预留激活下一关 } // 增加钻石 if ($requestJsonParam['diamond']) { $newUserInfo['n_diamond'] = $userInfo['n_diamond'] + $requestJsonParam['diamond']; $updateType = 1; } // 增加魂石数 if ($requestJsonParam['soul']) { $newUserInfo['n_soul'] = $userInfo['n_soul'] + $requestJsonParam['soul']; $updateType = 1; } // 增加人生果数 if ($newInfo['reward']) { $newUserInfo['n_coin'] = $userInfo['n_coin'] + $newInfo['reward']; $updateType = 1; } if ($requestJsonParam['pass'] == 1 && $checkPointId >= $userInfo['n_max_checkpoint']) { $updateType = 1; // 更新排行榜 $newRank['id'] = $user_id; $newRank['max_checkpoint'] = $checkPointId; $newRank['battle'] = $userInfo['n_battle']; $cache = UserCache::setByKey(Constants::WORLD_RANK, $user_id, $newRank); $newUserInfo['n_max_checkpoint'] = $checkPointId; UserCache::setByKey($requestParam['user_id'], 'n_max_checkpoint', $checkPointId); } if ($updateType == 1) { //成功才存关卡信息 if ($requestJsonParam['lose_type'] == 0) { $newUserInfo['s_checkpoint_info'] = serialize($checkPointInfo); UserCache::setByKey($requestParam['user_id'], 's_checkpoint_info', $checkPointInfo); } if ($newUserInfo) { UserModel::update($newUserInfo, $user = array('n_id' => $requestParam['user_id']), $pdo); } if ($newUserInfo['n_diamond']) { UserCache::setByKey($requestParam['user_id'], 'n_diamond', $newUserInfo['n_diamond']); } if ($newUserInfo['n_soul']) { UserCache::setByKey($requestParam['user_id'], 'n_soul', $newUserInfo['n_soul']); } if ($newUserInfo['n_coin']) { UserCache::setByKey($requestParam['user_id'], 'n_coin', $newUserInfo['n_coin']); } } // 任务成就信息 $statisticArr['check_point_id'] = $checkPointId; $statisticArr['pass'] = $requestJsonParam['pass']; $statisticArr['lose_type'] = $requestJsonParam['lose_type']; $statisticArr['reward'] = $scoreInfo['award']; $statisticArr['monster'] = $scoreInfo['kill']['monster']; $statisticArr['boss'] = $scoreInfo['kill']['boss']; $statisticArr['all_star'] = $requestJsonParam['star_num'] == 3 ? 1 : 0; $statisticArr['soul'] = $requestJsonParam['soul']; $statisticArr['away'] = $scoreInfo['deduction'][0]; $statisticArr['attack'] = $scoreInfo['deduction'][1]; $statisticArr['star_num'] = $newInfo['star_num']; $statisticArr['skill_num'] = $requestJsonParam['skill_num']; $beforGame = TaskAndAchieveAction::endNotice($requestParam['user_id']); TaskAndAchieveAction::taskStatistic($requestParam['user_id'], $statisticArr); $finishInfo = TaskAndAchieveAction::achieveStatistic($requestParam['user_id'], $statisticArr); /*------------------------------扣除用户体力、购买一次性道具道具----------------------*/ // 获取体力 $userThew = $userInfo['n_thew']; // 更新用户体力 $nowThew = $userThew - 1; if ($nowThew < 0) { $view = new JsonView(); $messageArr['error'] = "体力不足"; return $this->getViewByJson($view, $messageArr, 0, "game/end_game"); } else { if ($userThew == Constants::USER_MAX_THEW) { $recordArr['n_refresh_time'] = $userInfo['n_refresh_time'] = time(); } } // 购买一次性道具 if ($requestJsonParam['propArr'] && count($requestJsonParam['propArr'])) { foreach ($requestJsonParam['propArr'] as $key => $item_id) { $result = BuyPropAction::buyProp($requestParam['user_id'], $item_id); if ($result == false) { $view = new JsonView(); $messageArr['error'] = "人生果不足"; return $this->getViewByJson($view, $messageArr, 0, "game/end_game"); } } } $recordArr['n_thew'] = $nowThew; $wheresArr['n_id'] = $requestParam['user_id']; UserCache::setByKey($requestParam['user_id'], 'n_thew', $nowThew); UserCache::setByKey($requestParam['user_id'], 'n_refresh_time', $userInfo['n_refresh_time']); UserModel::update($recordArr, $wheresArr); // 生成缓存 $newSessionKey = Util::generateSessionKey($requestParam['user_id']); $oldSessionKey = $requestParam['session_key']; Logger::debug('SessionKey1:' . $oldSessionKey); Logger::debug('SessionKey2:' . $newSessionKey); UserCache::setByKey($requestParam['user_id'], Constants::PREVIOUS_SESSION_KEY, $oldSessionKey); UserCache::setByKey($requestParam['user_id'], Constants::CURRENT_SESSION_KEY, $newSessionKey); $messageArr = RankAction::getFriendRank($requestParam['user_id']); $afterGame = TaskAndAchieveAction::endNotice($requestParam['user_id']); $messageArr['unlockInfo'] = GeneralAction::isUnlock($requestParam['user_id']); //获取解锁武将 $general = GeneralAction::GetAllGeneralInfo($requestParam['user_id']); $messageArr['generalInfo'] = $general['generalInfo']; $messageArr['achieveInfo'] = array_values(array_diff($afterGame['achieveInfo'], $beforGame['achieveInfo'])); $messageArr['finish_num'] = $afterGame['finish_num'] > $beforGame['finish_num'] ? $afterGame['finish_num'] : 0; $messageArr['n_thew'] = $nowThew; $messageArr['n_refresh_time'] = $userInfo['n_refresh_time']; $messageArr['server_time'] = time(); $messageArr['time_num'] = Constants::REFRESH_THEW_TIME; $messageArr['session_key'] = $newSessionKey; $view = new JsonView(); return $this->getViewByJson($view, $messageArr, 1, "game/end_game"); }
/** * API:获取武将战斗力 * * @access public * @param $integer $user_id $general_id 用户ID,武将ID * @return array */ public function GetGeneralBattle($user_id, $general_id = null) { $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 = Util::readCsv($file); foreach ($generalArr as $key => $value) { $attributeArr = GeneralAction::GetGeneralAttribute($user_id, $value['general_id']); if ($userGeneral[$value['general_id']]) { $battle += $attributeArr[0]['battle'] + $attributeArr[1]['battle']; } } return $battle; }
/** * API:注册登陆时获取所有界面信息 * * @access public * @param int $user_id 用户ID $character_id主角ID * @return array */ public function getAllMessage($user_id) { //主角界面 $characterInfo = CharacterAction::GetAllCharacterInfo($user_id); //武将界面 $generalInfo = GeneralAction::GetAllGeneralInfo($user_id); $messageArr = array_merge($characterInfo, $generalInfo); //任务成就界面 $messageArr['achieveInfo'] = TaskAndAchieveAction::getAchieveInfo($user_id); $messageArr['taskInfo'] = TaskAndAchieveAction::getTaskInfo($user_id); //商城数据 $messageArr['mallInfo'] = BuyPropAction::exeGetMallInfo($user_id); //道具数据 $messageArr['itemInfo'] = BuyPropAction::exeGetPropInfo($user_id); //好友界面 $messageArr['friendInfo'] = FriendAction::exeGetFriendMenu($user_id); $messageArr['mail_num'] = MailAction::getMailNum($user_id); $messageArr['achieve_type'] = TaskAndAchieveAction::isFinish($user_id); //复活信息 $messageArr['resurrextInfo']['price_type'] = Constants::RESURE_TYPE; $messageArr['resurrextInfo']['price'] = Constants::RESURE_COST; $messageArr['resurrextInfo']['hp'] = Constants::RESURE_HP; $messageArr['resurrextInfo']['time'] = Constants::RESURE_TIME; //BOSS关卡评分 $messageArr['bossPoint']['time'] = Constants::BOSS_TIME; $messageArr['bossPoint']['less_time'] = Constants::LESS_TIME; $messageArr['bossPoint']['more_time'] = Constants::MORE_TIME; return $messageArr; }
/** * API:获取用户战斗力 * * @access public * @param mixed * @return $loginArr */ public function getUserBattle($user_id) { $generalBattle = GeneralAction::GetGeneralBattle($user_id); $CharacterBattle = CharacterAction::getCharacterBattle($user_id); $battle = $CharacterBattle + $generalBattle; return $battle; }