Exemplo n.º 1
0
 /**
  * API:领取任务奖励
  *
  * @access public
  * @param 无
  * @return JsonView 响应json
  */
 public function exeGetTaskReward()
 {
     $requestParam = $this->getAllParameters();
     Logger::debug('requestParam:' . print_r($requestParam, true));
     $requestJsonParam = $this->getDecodedJsonRequest();
     Logger::debug('requestJsonParam:' . print_r($requestJsonParam, true));
     $user_id = $requestParam['user_id'];
     $task_id = $requestJsonParam['task_id'];
     $session_key = $requestParam['session_key'];
     $userTask = UserCache::getByKey($user_id, self::TASK_STRING);
     if (!$userTask) {
         $userTask = TaskAchieveModel::getUserInfoByCondition($user_id, self::TASK_STRING);
         UserCache::setByKey($user_id, self::TASK_STRING, $userTask);
     }
     $str = "task_id = " . $task_id . "_" . $userTask[0][$task_id];
     $file = IniFileManager::getRootDir() . "/files/csv/task.csv";
     $taskInfo = CharacterAction::readCsv($file, $str);
     //完成条件的判断
     if ($userTask[$task_id]['n_num'] < $taskInfo[0]['condition']) {
         $messageArr['error'] = "领取条件不足!";
         $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
         $view = new JsonView();
         return $this->getViewByJson($view, $messageArr, 0, "task_and_achieve/get_task_reward");
     }
     //是否领取的判断
     if ($userTask[$task_id]['n_reward'] != 0) {
         $messageArr['error'] = "已领取该奖励!";
         $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
         $view = new JsonView();
         return $this->getViewByJson($view, $messageArr, 0, "task_and_achieve/get_task_reward");
     }
     //更新任务状态,及金钱
     $price_type = $this->price_type;
     $type = $price_type[$taskInfo[0]['reward_type']];
     $money = UserCache::getByKey($user_id, $type);
     if (!$money) {
         $userInfo = TaskAchieveModel::getUserInfo($user_id);
         $money = $userInfo[$type];
     }
     $money = $money + $taskInfo[0]['reward_num'];
     //体力领取恢复时间更新
     if ($type == $price_type[4]) {
         $thewArr['n_thew'] = $money;
         $thewArr['n_refresh_time'] = UserCache::getBykey($user_id, 'n_refresh_time');
         if (!$thewArr['n_refresh_time']) {
             $userInfo = MailModel::getUserInfo($user_id);
             $thewArr['n_refresh_time'] = $userInfo['n_refresh_time'];
         }
         $getArr = UserAction::refreshThew($thewArr);
         if (!$getArr) {
             $res = CharacterModel::update($thewArr, array('n_id' => $user_id));
             UserCache::setByKey($user_id, 'n_thew', $thewArr['n_thew']);
             UserCache::setByKey($user_id, 'n_refresh_time', $thewArr['n_refresh_time']);
         } else {
             $res = CharacterModel::update($getArr, array('n_id' => $user_id));
             UserCache::setByKey($user_id, 'n_thew', $getArr['n_thew']);
             UserCache::setByKey($user_id, 'n_refresh_time', $getArr['n_refresh_time']);
         }
     } else {
         $res = CharacterModel::update(array($type => $money), array('n_id' => $user_id));
         UserCache::setByKey($user_id, $type, $money);
     }
     $userTask[$task_id]['n_reward'] = 1;
     $s_task_info = serialize($userTask);
     $res = TaskAchieveModel::update(array('s_task_info' => $s_task_info), array('n_id' => $user_id));
     if (!$res) {
         throw new Exception("update false");
     }
     UserCache::setByKey($user_id, self::TASK_STRING, $userTask);
     //任务成就统计
     if ($type == $price_type[1]) {
         TaskAndAchieveAction::taskStatistic($user_id, array('reward' => $taskInfo[0]['reward_num']));
     }
     if ($type == $price_type[3]) {
         //TaskAndAchieveAction::taskStatistic($user_id,array('soul'=>$taskInfo[0]['reward_num']));
         TaskAndAchieveAction::achieveStatistic($user_id, array('soul' => $taskInfo[0]['reward_num']));
     }
     //sessdion_key
     $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
     $messageArr['achieveInfo'] = self::getAchieveInfo($user_id);
     $messageArr['taskInfo'] = self::getTaskInfo($user_id);
     $view = new JsonView();
     return $this->getViewByJson($view, $messageArr, 1, "task_and_achieve/get_task_reward");
 }
Exemplo n.º 2
0
 /**
  * API:接受所有邮件
  *
  * @access public
  * @param 无
  * @return JsonView 响应json
  */
 public function exeUpdateAllMail()
 {
     $requestParam = $this->getAllParameters();
     Logger::debug('requestParam:' . print_r($requestParam, true));
     $requestJsonParam = $this->getDecodedJsonRequest();
     Logger::debug('requestJsonParam:' . print_r($requestJsonParam, true));
     $user_id = $requestParam['user_id'];
     $session_key = $requestParam['session_key'];
     $mailInfo = MailModel::getSystemMail($user_id);
     $userInfo = UserCache::getAllUserCache($user_id);
     if (!$userInfo) {
         $userInfo = UserAction::iniUserInfo($user_id);
     }
     if (!$mailInfo) {
         $messageArr['error'] = "没有系统邮件";
         $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
         $view = new JsonView();
         return $this->getViewByJson($view, $messageArr, 0, "mail/update_all_mail");
     }
     $price_type = $this->price_type;
     foreach ($mailInfo as $key => $value) {
         foreach ($price_type as $key2 => $value2) {
             if ($key2 == $value['n_item_type']) {
                 $userInfo[$value2] = $userInfo[$value2] + $value['n_item_num'];
                 if ($key2 == 4) {
                     $n_thew = $userInfo[$value2];
                 } else {
                     $newInfo[$value2] = $userInfo[$value2];
                 }
                 if ($key2 == 1) {
                     $n_coin = $n_coin + $value['n_item_num'];
                 }
                 if ($key2 == 3) {
                     $n_soul = $n_soul + $value['n_item_num'];
                 }
             }
         }
     }
     if ($n_thew) {
         $thewArr['n_thew'] = $n_thew;
         $thewArr['n_refresh_time'] = UserCache::getBykey($user_id, 'n_refresh_time');
         if (!$thewArr['n_refresh_time']) {
             $userInfo = MailModel::getUserInfo($user_id);
             $thewArr['n_refresh_time'] = $userInfo['n_refresh_time'];
         }
         $getArr = UserAction::refreshThew($thewArr);
         if (!$getArr) {
             $res = CharacterModel::update($thewArr, array('n_id' => $user_id));
             UserCache::setByKey($user_id, 'n_thew', $thewArr['n_thew']);
             UserCache::setByKey($user_id, 'n_refresh_time', $thewArr['n_refresh_time']);
         } else {
             $res = CharacterModel::update($getArr, array('n_id' => $user_id));
             UserCache::setByKey($user_id, 'n_thew', $getArr['n_thew']);
             UserCache::setByKey($user_id, 'n_refresh_time', $getArr['n_refresh_time']);
         }
     }
     //任务成就统计
     TaskAndAchieveAction::taskStatistic($user_id, array('reward' => $n_coin));
     //TaskAndAchieveAction::taskStatistic($user_id,array('soul'=>$n_soul));
     TaskAndAchieveAction::achieveStatistic($user_id, array('soul' => $n_soul));
     $res = MailModel::update(array('n_type' => 0), array('n_receive_id' => $user_id));
     $res = CharacterModel::update($newInfo, array('n_id' => $user_id));
     foreach ($newInfo as $key => $value) {
         UserCache::setByKey($user_id, $key, $value);
     }
     foreach ($price_type as $key => $value) {
         $moneyArr[$value] = UserCache::getByKey($user_id, $value);
         if (!$moneyArr[$value]) {
             $userInfo = MailModel::getUserInfo($user_id);
             $moneyArr[$value] = $userInfo[$value];
         }
     }
     $messageArr['moneyInfo'] = $moneyArr;
     //任务成就界面
     $messageArr['achieveInfo'] = TaskAndAchieveAction::getAchieveInfo($user_id);
     $messageArr['taskInfo'] = TaskAndAchieveAction::getTaskInfo($user_id);
     $messageArr['friend_mail'] = MailModel::getFriendMail($user_id);
     $messageArr['system_mail'] = MailModel::getSystemMail($user_id);
     $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
     $view = new JsonView();
     return $this->getViewByJson($view, $messageArr, 1, "mail/update_all_mail");
 }
Exemplo n.º 3
0
 /**
  * API:购买商城物品
  *
  * @access public
  * @param 无
  * @return JsonView 响应json
  */
 public function exeBuyMall()
 {
     $requestParam = $this->getAllParameters();
     Logger::debug('requestParam:' . print_r($requestParam, true));
     $requestJsonParam = $this->getDecodedJsonRequest();
     Logger::debug('requestJsonParam:' . print_r($requestJsonParam, true));
     $user_id = $requestParam['user_id'];
     $mall_id = $requestJsonParam['mall_id'];
     $session_key = $requestParam['session_key'];
     $str = "mall_id = " . $mall_id;
     $file = IniFileManager::getRootDir() . "/files/csv/mall.csv";
     $itemInfo = CharacterAction::readCsv($file, $str);
     $price_type = self::$price_type;
     //余额判断
     $type1 = $price_type[$itemInfo[0]['price_type']];
     $type2 = $price_type[$itemInfo[0]['buy_type']];
     $money1 = UserCache::getByKey($user_id, $type1);
     $money2 = UserCache::getByKey($user_id, $type2);
     if (!$money1) {
         $userInfo = BuyPropModel::getUserInfo($user_id);
         $money1 = $userInfo[$type1];
     }
     if (!$money2) {
         $userInfo = BuyPropModel::getUserInfo($user_id);
         $money2 = $userInfo[$type2];
     }
     $money1 = $money1 - $itemInfo[0]['price_num'];
     $money2 = $money2 + $itemInfo[0]['buy_num'];
     if ($money1 < 0) {
         $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
         $messageArr['error'] = "人生果/钻石不足!";
         $view = new JsonView();
         return $this->getViewByJson($view, $messageArr, 0, "buy_prop/buy_mall");
     }
     //任务成就统计
     if ($type2 == $price_type[1]) {
         TaskAndAchieveAction::taskStatistic($user_id, array('reward' => $itemInfo[0]['buy_num']));
     }
     if ($type1 == $price_type[1]) {
         TaskAndAchieveAction::achieveStatistic($user_id, array('cost' => $itemInfo[0]['price_num']));
     }
     //购买体力是更新体力时间
     if ($type2 == $price_type[3]) {
         $thewArr['n_thew'] = $money2;
         $thewArr['n_refresh_time'] = UserCache::getBykey($user_id, 'n_refresh_time');
         if (!$thewArr['n_refresh_time']) {
             $userInfo = MailModel::getUserInfo($user_id);
             $thewArr['n_refresh_time'] = $userInfo['n_refresh_time'];
         }
         $getArr = UserAction::refreshThew($thewArr);
         if (!$getArr) {
             $res = CharacterModel::update($thewArr, array('n_id' => $user_id));
             UserCache::setByKey($user_id, 'n_thew', $thewArr['n_thew']);
             UserCache::setByKey($user_id, 'n_refresh_time', $thewArr['n_refresh_time']);
         } else {
             $res = CharacterModel::update($getArr, array('n_id' => $user_id));
             UserCache::setByKey($user_id, 'n_thew', $getArr['n_thew']);
             UserCache::setByKey($user_id, 'n_refresh_time', $getArr['n_refresh_time']);
         }
         $res = BuyPropModel::update(array($type1 => $money1), array('n_id' => $user_id));
         UserCache::setByKey($user_id, $type1, $money1);
     } else {
         $res = BuyPropModel::update(array($type1 => $money1, $type2 => $money2), array('n_id' => $user_id));
         UserCache::setByKey($user_id, $type1, $money1);
         UserCache::setByKey($user_id, $type2, $money2);
     }
     $messageArr['moneyInfo'] = BuyPropModel::getUserInfo($user_id);
     $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
     //任务成就界面
     $messageArr['achieveInfo'] = TaskAndAchieveAction::getAchieveInfo($user_id);
     $messageArr['taskInfo'] = TaskAndAchieveAction::getTaskInfo($user_id);
     $view = new JsonView();
     return $this->getViewByJson($view, $messageArr, 1, "buy_prop/buy_mall");
 }
Exemplo n.º 4
0
 /**
  * API:用户登陆
  *
  * @access public
  * @param 无
  * @return JsonView 响应json
  */
 public function exeUserLogin()
 {
     $requestParam = $this->getAllParameters();
     Logger::debug('requestParam:' . print_r($requestParam, true));
     $requestJsonParam = $this->getDecodedJsonRequest();
     Logger::debug('requestJsonParam:' . print_r($requestJsonParam, true));
     // 获取用户id
     $user_id = AuthModel::getUserID($requestJsonParam['account'], $requestJsonParam['password'], $pdo);
     if (!$user_id) {
         $view = new JsonView();
         $messageArr['error'] = "密码不正确,请重新输入";
         return $this->getViewByJson($view, $messageArr, 0, "auth/user_login");
     }
     // 初始化缓存
     $userInfo = UserAction::iniUserInfo($user_id);
     $loginInfo = UserAction::getUserLoginInfo($userInfo['s_login_info']);
     if ($loginInfo != false) {
         $taskInfo = TaskAndAchieveAction::randTask($user_id);
         $updateArr['s_login_info'] = serialize($loginInfo);
         $updateArr['s_task_info'] = serialize($taskInfo);
         UserCache::setByKey($user_id, 's_login_info', $loginInfo);
         UserCache::setByKey($user_id, 's_task_info', $taskInfo);
         $userInfo['s_login_info'] = $loginInfo;
         $userInfo['s_task_info'] = $taskInfo;
         UserModel::update($updateArr, $user = array('n_id' => $user_id), $pdo);
         //清零合体次数
         FriendModel::clearFitNum($user_id);
         // // 成就
         // $statisticArr['login_day'] = 1;
         // TaskAndAchieveAction::achieveStatistic( $user_id, $statisticArr );
     }
     //$user_id = $requestParam['user_id'];
     //$userInfo = AuthModel::getUserInfo( $user_id, $pdo );
     // 生成缓存
     $newSessionKey = Util::generateSessionKey($user_id);
     $oldSessionKey = $requestParam['session_key'];
     Logger::debug('SessionKey1:' . $oldSessionKey);
     Logger::debug('SessionKey2:' . $newSessionKey);
     UserCache::setByKey($user_id, Constants::PREVIOUS_SESSION_KEY, $oldSessionKey);
     UserCache::setByKey($user_id, Constants::CURRENT_SESSION_KEY, $newSessionKey);
     //UserCache::setByKey($user_id, 'userInfo', $userInfo);
     //$messageArr['user'] = $userInfo;
     $messageArr['n_id'] = $user_id;
     $messageArr['total_day'] = $userInfo['s_login_info']['total_day'];
     $messageArr['session_key'] = $newSessionKey;
     $view = new JsonView();
     return $this->getViewByJson($view, $messageArr, 1, "auth/user_login");
 }
Exemplo n.º 5
0
 /**
  * API:更新合体时间
  *
  * @access public
  * @param 无
  * @return JsonView 响应json
  */
 public function exeUpdateFitTime()
 {
     $requestParam = $this->getAllParameters();
     Logger::debug('requestParam:' . print_r($requestParam, true));
     $requestJsonParam = $this->getDecodedJsonRequest();
     Logger::debug('requestJsonParam:' . print_r($requestJsonParam, true));
     $user_id = $requestParam['user_id'];
     $friend_id = $requestJsonParam['friend_id'];
     $session_key = $requestParam['session_key'];
     //判断是否已为好友关系
     $ret = FriendModel::isFriend($user_id, $friend_id);
     if (!$ret) {
         $messageArr['error'] = "非好友关系!";
         $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
         $view = new JsonView();
         return $this->getViewByJson($view, $messageArr, 0, "friend/update_fit_time");
     }
     $fitTime = FriendModel::fitFriend($user_id);
     foreach ($fitTime as $key => $value) {
         if ($value['n_id'] == $friend_id) {
             $time = $value['time'];
             $fit_num = $value['num'] + 1;
         }
     }
     $nowTime = time();
     //冷却时间未到,扣除金钱
     if ($time > $nowTime) {
         $price_type = array(1 => 'n_coin', 2 => 'n_diamond');
         $costInfo = FriendAction::getFitCostInfo($friend_id, $fit_num);
         $type = $price_type[$costInfo['price_type']];
         $price = $costInfo['price'];
         $money = UserCache::getByKey($user_id, $type);
         if (!$money) {
             $userInfo = FriendModel::getUserInfo($user_id);
             $money = $userInfo[$type];
         }
         $money = $money - $price;
         if ($money < 0) {
             $messageArr['error'] = "人生果/钻石不足!";
             $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
             $view = new JsonView();
             return $this->getViewByJson($view, $messageArr, 0, "friend/update_fit_time");
         }
         $ret = CharacterModel::update(array($type => $money), array('n_id' => $user_id));
         FriendModel::updateFitNum($user_id, $friend_id);
         UserCache::setByKey($user_id, $type, $money);
     } else {
         $ret = FriendModel::fitTime($user_id, $friend_id);
     }
     //任务成就统计
     TaskAndAchieveAction::taskStatistic($user_id, array('friend_help' => 1));
     TaskAndAchieveAction::achieveStatistic($user_id, array('friend_help' => 1));
     $friendInfo = FriendModel::getUserInfo($friend_id);
     $messageArr = CharacterAction::getFitBattleInfo($user_id, $friendInfo['n_battle']);
     $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
     $view = new JsonView();
     return $this->getViewByJson($view, $messageArr, 1, "friend/update_fit_time");
 }
Exemplo n.º 6
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");
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
0
 /**
  * API:升级武将属性
  *
  * @access public
  * @param 无
  * @return JsonView 响应json
  */
 public function exeUpdateGeneral()
 {
     $requestParam = $this->getAllParameters();
     Logger::debug('requestParam:' . print_r($requestParam, true));
     $requestJsonParam = $this->getDecodedJsonRequest();
     Logger::debug('requestJsonParam:' . print_r($requestJsonParam, true));
     $user_id = $requestParam['user_id'];
     $general_id = $requestJsonParam['general_id'];
     $attribute_id = $requestJsonParam['attribute_id'];
     $session_key = $requestParam['session_key'];
     $userGeneral = UserCache::getByKey($user_id, 's_general_info');
     if (!$userGeneral) {
         $userGeneral = GeneralModel::getUserGeneralInfo($user_id);
         UserCache::setByKey($user_id, 's_general_info', $userGeneral);
     }
     $attribute = self::$attribute;
     $price_type = self::$price_type;
     // 读取csv类  ,读取目标文件
     $file = IniFileManager::getRootDir() . "/files/csv/general" . $general_id . "_update_value.csv";
     $str = "update_id = " . $attribute_id . '_' . $userGeneral[$general_id][$attribute[$attribute_id]];
     $nowArr = CharacterAction::readCsv($file, $str);
     $type = $price_type[$nowArr[0]['price_type']];
     $money = UserCache::getByKey($user_id, $type);
     if (!$money) {
         $userInfo = GeneralModel::getUserInfo($user_id);
         $money = $userInfo[$type];
     }
     $money = $money - $nowArr[0]['price'];
     if ($money < 0) {
         $messageArr['error'] = "人生果/钻石不足!";
         $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
         $view = new JsonView();
         return $this->getViewByJson($view, $messageArr, 0, "general/update_general");
     }
     if ($userGeneral[$general_id][$attribute[$attribute_id]] >= Constants::MAX_LEVEL) {
         $messageArr['error'] = "等级已达最大!";
         $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
         $view = new JsonView();
         return $this->getViewByJson($view, $messageArr, 0, "general/update_general");
     }
     $userGeneral[$general_id][$attribute[$attribute_id]] = $userGeneral[$general_id][$attribute[$attribute_id]] + 1;
     $s_general_info = serialize($userGeneral);
     $res = GeneralModel::update(array($type => $money, 's_general_info' => $s_general_info), array('n_id' => $user_id));
     if (!$res) {
         throw new Exception(" update false pa_user_master ");
     }
     //任务成就统计
     $num = 0;
     TaskAndAchieveAction::taskStatistic($user_id, array('generl_up' => 1));
     if ($type == $price_type[1]) {
         TaskAndAchieveAction::achieveStatistic($user_id, array('cost' => $nowArr[0]['price']));
     }
     foreach ($attribute as $key => $value) {
         if ($userGeneral[$general_id][$value] >= Constants::MAX_LEVEL) {
             $num++;
         }
     }
     if ($num == 2) {
         TaskAndAchieveAction::achieveStatistic($user_id, array('generl_full' => 1));
     }
     //session_key
     UserCache::setByKey($user_id, 's_general_info', $userGeneral);
     UserCache::setByKey($user_id, $type, $money);
     //更新战斗力
     $battle = UserAction::getUserBattle($user_id);
     GeneralModel::update(array('n_battle' => $battle), array('n_id' => $user_id));
     UserCache::setByKey($user_id, 'n_battle', $battle);
     $messageArr = self::GetAllGeneralInfo($user_id);
     $messageArr['battle'] = $battle;
     //任务成就界面
     $messageArr['achieveInfo'] = TaskAndAchieveAction::getAchieveInfo($user_id);
     $messageArr['taskInfo'] = TaskAndAchieveAction::getTaskInfo($user_id);
     $messageArr['mail_num'] = MailAction::getMailNum($user_id);
     $messageArr['achieve_type'] = TaskAndAchieveAction::isFinish($user_id);
     $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
     $view = new JsonView();
     return $this->getViewByJson($view, $messageArr, 1, "general/update_general");
 }
Exemplo n.º 9
0
 /**
  * API:用户签到
  *
  * @access public
  * @param 无
  * @return JsonView 响应json
  */
 public function exeLogin()
 {
     $requestParam = $this->getAllParameters();
     Logger::debug('requestParam:' . print_r($requestParam, true));
     $requestJsonParam = $this->getDecodedJsonRequest();
     Logger::debug('requestJsonParam:' . print_r($requestJsonParam, true));
     // 获取用户表信息
     $userInfo = UserCache::getAllUserCache($requestParam['user_id']);
     if (!$userInfo) {
         $userInfo = self::iniUserInfo($requestParam['user_id']);
     }
     if ($userInfo['s_login_info']['type'] == 0) {
         $rewardTypeArr = array(1 => 'n_coin', 2 => 'n_diamond', 3 => 'n_thew', 4 => 'n_soul');
         /*$reward = $userInfo['s_login_info']['reward'];
           $updateArr[$rewardTypeArr[$reward['type']]] = $userInfo[$rewardTypeArr[$reward['type']]] = $userInfo[$rewardTypeArr[$reward['type']]] + $reward['num'];
           $userInfo['s_login_info']['type'] = 1;
           $updateArr['s_login_info'] = serialize( $userInfo['s_login_info'] );*/
         $userInfo['s_login_info']['con_day'] = $userInfo['s_login_info']['con_day'] + 1;
         $userInfo['s_login_info']['total_day'] = $userInfo['s_login_info']['total_day'] + 1;
         // 非连续签到
         if (strtotime(date('Y-m-d', time())) - $userInfo['s_login_info']['time'] > 86400) {
             $userInfo['s_login_info']['con_day'] = 1;
         }
         $userInfo['s_login_info']['time'] = time();
         $rewardNum = $userInfo['s_login_info']['rewardArr']['check'];
         $reward = $userInfo['s_login_info']['rewardArr']['box_info'][$rewardNum];
         $updateArr[$rewardTypeArr[$reward['type']]] = $userInfo[$rewardTypeArr[$reward['type']]] = $userInfo[$rewardTypeArr[$reward['type']]] + $reward['num'];
         $userInfo['s_login_info']['type'] = 1;
         $updateArr['s_login_info'] = serialize($userInfo['s_login_info']);
         // 成就
         if ($reward['type'] == 1) {
             $statisticArr['reward'] = $reward['num'];
             TaskAndAchieveAction::taskStatistic($requestParam['user_id'], $statisticArr);
         } elseif ($reward['type'] == 4) {
             $statisticArr['soul'] = $reward['num'];
         }
         $statisticArr['login_day'] = 1;
         TaskAndAchieveAction::achieveStatistic($requestParam['user_id'], $statisticArr);
         UserModel::update($updateArr, array('n_id' => $requestParam['user_id']));
         UserCache::setByKey($requestParam['user_id'], $rewardTypeArr[$reward['type']], $userInfo[$rewardTypeArr[$reward['type']]]);
         UserCache::setByKey($requestParam['user_id'], 's_login_info', $userInfo['s_login_info']);
     } else {
         $messageArr['error'] = "今天已签到";
         $view = new JsonView();
         return $this->getViewByJson($view, $messageArr, 0, "user/login");
     }
     // 生成缓存
     $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);
     //UserCache::setByKey($user_id, 'userInfo', $userInfo);
     $messageArr['n_id'] = $requestParam['user_id'];
     //$messageArr = $userInfo;
     $messageArr['n_coin'] = $userInfo['n_coin'];
     $messageArr['n_diamond'] = $userInfo['n_diamond'];
     $messageArr['n_soul'] = $userInfo['n_soul'];
     $messageArr['n_thew'] = $userInfo['n_thew'];
     //$messageArr['n_reward'] = $userInfo['n_reward'];
     //任务成就界面
     $messageArr['achieveInfo'] = TaskAndAchieveAction::getAchieveInfo($requestParam['user_id']);
     $messageArr['taskInfo'] = TaskAndAchieveAction::getTaskInfo($requestParam['user_id']);
     $messageArr['session_key'] = $newSessionKey;
     $view = new JsonView();
     return $this->getViewByJson($view, $messageArr, 1, "user/login");
 }