Beispiel #1
0
 /**
  * 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");
 }
Beispiel #2
0
 /**
  * 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;
 }