/** * 初始化 PDO对象 * * @access public * @param array $configs PDO#__construct 使用数组来指定第一~第三个参数(默认值:生产环境的数据库) * @param array $driver_options PDO#__construct 第四个参数(默认:「SET CHARACTER SET `utf8`」) * @return PDO 对象 */ public static function initializeInstance($configs = array(), $driver_options = array()) { if (empty($configs)) { $configs = IniFileManager::getByFileName(self::FILE_NAME); } if (empty($configs)) { throw new Exception('Could not get configuration of "' . self::FILE_NAME . '".'); } if (empty($driver_options)) { $driver_options = Database::$DEFAULT_DRIVER_OPTIONS; } $pdo = new ExtPDO($configs[self::CONFIG_KEY_DSN], $configs[self::CONFIG_KEY_USER], $configs[self::CONFIG_KEY_PASSWORD], $driver_options); // 设置错误报告:抛出异常 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //$pdo->setAttribute( PDO::ATTR_EMULATE_PREPARES, false ); return $pdo; }
/** * 自动加载回调函数。 * * @access public * @param string $className 类名 * @return boolean 成功 / 失败 */ public function __autoload($className) { // 如果类或者接口已经定义, 直接返回 if (class_exists($className, false) || interface_exists($className, false)) { return true; } $root_dir = IniFileManager::getByFilesKey("environment_config.ini", "root_lib_dir"); foreach (self::$config as $dir) { $path = $root_dir . "/" . $dir . '/' . $className . '.class.php'; // 如果文件存在, 加载并返回 if (file_exists($path)) { require $path; return true; } } // 文件不存在 return false; }
/** * API:获取大事件信息 * * @access public * @param 无 * @return JsonView 响应json */ public function getBigMessage() { $requestParam = $this->getAllParameters(); Logger::debug('requestParam:' . print_r($requestParam, true)); $requestJsonParam = $this->getDecodedJsonRequest(); Logger::debug('requestJsonParam:' . print_r($requestJsonParam, true)); // 取缓存数据 $cache = MemcacheManager::instance(); $memcacheArr = $cache->get(self::BULLETIN_LIST); if ($memcacheArr) { $messageArr = $memcacheArr; } else { // 读取csv类 $csv = new Parsecsv(); $dir = IniFileManager::getRootDir() . "files/csv/" . self::BULLETIN_LIST . ".csv"; $csv->auto($dir); $messageArr = $csv->data; } return $messageArr; }
/** * 写入操作 * * @access private * @param string $msg 信息 * @return boolean 成功 / 失败 */ private static function write($name, $msg, $backtrace = null) { $file_path = IniFileManager::getByFilesKey(self::FILE_NAME, $name); if (!$file_path) { return false; } $f = fopen($file_path . '_' . date("Y-m-d"), 'a'); if (!$f) { return false; } if (!flock($f, LOCK_EX)) { return false; } $writer = isset($backtrace[0]['file']) ? $backtrace[0]['file'] . '-> ' : ""; $referer = isset($_SERVER['HTTP_REFERER']) ? ', referer: ' . $_SERVER['HTTP_REFERER'] : ""; $client = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ""; $logs = '[' . date('D M d H:i:s Y') . '] [' . str_replace('dir_', '', $name) . '] [client ' . $client . '] ' . $writer . $msg . $referer . "\n"; if (!fwrite($f, $logs)) { return false; } return fclose($f); }
/** * * 邮件通知处理函数 * * @access public * @param string $sub 邮件标题 * @param Exception $exception 捕捉到的异常 * @return boolean 处理结果:TRUE 发送成功 / FALSE 未发送成功 */ public static function sendExceptionMail($sub, $exception) { // 获取系统Email接收者 $reciever = IniFileManager::getByFilesKey("environment_config.ini", "system_mail_reciever"); if (!$reciever) { return false; } $host = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : php_uname('n'); // 发送 $sub = "[ylxx game] {$sub} / Host: {$host}"; $msg = "Date: " . date('Y-m-d H:i:s') . "\nName: " . get_class($exception) . "\nFile: " . $exception->getFile() . "\nLine: " . $exception->getLine() . "\nCode: " . $exception->getCode() . "\nMessage: " . $exception->getMessage(); $ret = mail($reciever, $sub, $msg); if ($ret !== true) { return false; } Logger::debug(__METHOD__ . " was success. \nsubject->" . $sub . "\nmessage->\n" . $msg); return true; }
/** * API:成就统计 * * @access public * @param int $user_id 用户ID * @return array */ public function achieveStatistic($user_id, $dataArr) { $pointArr = array(6 => 1, 12 => 2, 22 => 3, 30 => 4); $userAchieve = UserCache::getByKey($user_id, self::ACHIEVEMENT_STRING); if (!$userAchieve) { $userAchieve = TaskAchieveModel::getUserInfoByCondition($user_id, self::ACHIEVEMENT_STRING); UserCache::setByKey($user_id, self::ACHIEVEMENT_STRING, $userAchieve); } foreach ($userAchieve as $key => $value) { $str = "achievement_id = " . $key . "_" . ($userAchieve[$key]['n_level'] + 1); $file = IniFileManager::getRootDir() . "/files/csv/achievement.csv"; $achieveInfo = CharacterAction::readCsv($file, $str); if ($userAchieve[$key]['n_level'] < $userAchieve[$key]['max_level'] && $userAchieve[$key]['n_num'] < $achieveInfo[0]['condition']) { //1 if ($dataArr['friend_help'] == 1 && $key == 1) { $totalNum = $userAchieve[$key]['n_num'] + $dataArr['friend_help']; if ($totalNum >= $achieveInfo[0]['condition']) { $totalNum = $achieveInfo[0]['condition']; } $userAchieve[$key]['n_num'] = $totalNum; } //2 if ($dataArr['login_day'] == 1 && $key == 2) { $totalNum = $userAchieve[$key]['n_num'] + $dataArr['login_day']; if ($totalNum >= $achieveInfo[0]['condition']) { $totalNum = $achieveInfo[0]['condition']; } $userAchieve[$key]['n_num'] = $totalNum; } //3 if ($dataArr['monster'] && $key == 3) { $totalNum = $userAchieve[$key]['n_num'] + $dataArr['monster']; if ($totalNum >= $achieveInfo[0]['condition']) { $totalNum = $achieveInfo[0]['condition']; } $userAchieve[$key]['n_num'] = $totalNum; } //4 if ($dataArr['star_num'] && $key == 4) { $totalNum = $userAchieve[$key]['n_num'] + $dataArr['star_num']; if ($totalNum >= $achieveInfo[0]['condition']) { $totalNum = $achieveInfo[0]['condition']; } $userAchieve[$key]['n_num'] = $totalNum; } //5 if ($dataArr['pro_num'] && $key == 5) { $totalNum = $userAchieve[$key]['n_num'] + $dataArr['pro_num']; if ($totalNum >= $achieveInfo[0]['condition']) { $totalNum = $achieveInfo[0]['condition']; } $userAchieve[$key]['n_num'] = $totalNum; } //6 if (($dataArr['pass'] === 0 || $dataArr['pass'] === 1) && $key == 6) { $totalNum = $userAchieve[$key]['n_num'] + 1; if ($totalNum >= $achieveInfo[0]['condition']) { $totalNum = $achieveInfo[0]['condition']; } $userAchieve[$key]['n_num'] = $totalNum; } //7 if ($dataArr['away'] === 0 && $dataArr['attack'] === 0 && $key == 7) { $totalNum = $userAchieve[$key]['n_num'] + 1; if ($totalNum >= $achieveInfo[0]['condition']) { $totalNum = $achieveInfo[0]['condition']; } $userAchieve[$key]['n_num'] = $totalNum; } //8 if ($dataArr['skill_num'] && $key == 8) { $totalNum = $userAchieve[$key]['n_num'] + $dataArr['skill_num']; if ($totalNum >= $achieveInfo[0]['condition']) { $totalNum = $achieveInfo[0]['condition']; } $userAchieve[$key]['n_num'] = $totalNum; } //9 if ($dataArr['cost'] && $key == 9) { $totalNum = $userAchieve[$key]['n_num'] + $dataArr['cost']; if ($totalNum >= $achieveInfo[0]['condition']) { $totalNum = $achieveInfo[0]['condition']; } $userAchieve[$key]['n_num'] = $totalNum; } //11 if ($dataArr['pass'] === 0 && $key == 11) { $totalNum = $userAchieve[$key]['n_num'] + 1; if ($totalNum >= $achieveInfo[0]['condition']) { $totalNum = $achieveInfo[0]['condition']; } $userAchieve[$key]['n_num'] = $totalNum; } //12 if ($dataArr['soul'] && $key == 12) { $totalNum = $userAchieve[$key]['n_num'] + $dataArr['soul']; if ($totalNum >= $achieveInfo[0]['condition']) { $totalNum = $achieveInfo[0]['condition']; } $userAchieve[$key]['n_num'] = $totalNum; } //15 if ($dataArr['check_point_id'] == 1 && $dataArr['pass'] == 1 && $key == 15) { $totalNum = $userAchieve[$key]['n_num'] + 1; if ($totalNum >= $achieveInfo[0]['condition']) { $totalNum = $achieveInfo[0]['condition']; } $userAchieve[$key]['n_num'] = $totalNum; } } if ($userAchieve[$key]['n_level'] < $userAchieve[$key]['max_level']) { //10 if ($dataArr['pass'] == 1 && $pointArr[$dataArr['check_point_id']] > $userAchieve[$key]['n_num'] && $key == 10) { if ($value['n_level'] < Constants::CHAPTER_NUM) { $totalNum = $userAchieve[$key]['n_num'] + 1; // if ($totalNum>=$achieveInfo[0]['condition']) // { // $totalNum=$achieveInfo[0]['condition']; // } $userAchieve[$key]['n_num'] = $totalNum; } } //13 if ($dataArr['generl_full'] && $key == 13) { $totalNum = $userAchieve[$key]['n_num'] + $dataArr['generl_full']; // if ($totalNum>=$achieveInfo[0]['condition']) // { // $totalNum=$achieveInfo[0]['condition']; // } $userAchieve[$key]['n_num'] = $totalNum; } //14 if ($dataArr['update_times'] && $key == 14) { $totalNum = $userAchieve[$key]['n_num'] + $dataArr['update_times']; // if ($totalNum>=$achieveInfo[0]['condition']) // { // $totalNum=$achieveInfo[0]['condition']; // } $userAchieve[$key]['n_num'] = $totalNum; } } } $s_achievement_info = serialize($userAchieve); $res = TaskAchieveModel::update(array('s_achievement_info' => $s_achievement_info), array('n_id' => $user_id)); UserCache::setByKey($user_id, self::ACHIEVEMENT_STRING, $userAchieve); }
public static function checkEnviroment($env) { return IniFileManager::getByFilesKey("environment_config.ini", "env_mode") == strtolower($env); }
/** * 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"); }
/** * API:好友合体信息 * * @access public * @param 无 * @return JsonView 响应json */ public function exeGetFitInfo() { $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']; $idArr = FriendModel::fitFriend($user_id); $nowTime = time(); foreach ($idArr as $key => $value) { $condition .= $value['n_id'] . ","; $waitTime = $value['time'] - $nowTime; $idArr[$key]['time'] = $waitTime > 0 ? $waitTime : 0; } $condition = substr($condition, 0, -1); $friendInfo = array(); if ($condition) { $friendInfo = FriendModel::getFriendInfo($condition); } foreach ($friendInfo as $key1 => $value1) { foreach ($idArr as $key2 => $value2) { if ($value1['n_id'] == $value2['n_id']) { $friendInfo[$key1] = array_merge($value1, $value2); $num = $value2['num'] + 1; $costInfo = FriendAction::getFitCostInfo($value1['n_id'], $num); $friendInfo[$key1]['price_type'] = $costInfo['price_type']; $friendInfo[$key1]['price'] = $costInfo['price']; $battleInfo = CharacterAction::getFitBattleInfo($user_id, $value1['n_battle']); $friendInfo[$key1]['add_battle'] = $battleInfo['add_battle']; $friendInfo[$key1]['attack'] = $battleInfo['attack']; $friendInfo[$key1]['crit'] = $battleInfo['crit']; $friendInfo[$key1]['hp'] = $battleInfo['hp']; } } } //游戏中主角、武将信息获取 // $messageArr1=CharacterAction::GetAllCharacterInfo($user_id); // $messageArr2=GeneralAction::GetAllGeneralInfo($user_id); // $messageArr=array_merge($messageArr1,$messageArr2); // 关卡基本信息 $dir = IniFileManager::getRootDir() . "files/csv/" . self::CHECKPOINT_LIST . ".csv"; $str = "checkpoint_id = " . $requestJsonParam['checkpoint_id']; $checkpointArr = Util::readCsv($dir, $str); if (empty($checkpointArr)) { $view = new JsonView(); return $this->getViewByJson($view, $messageArr, 0, "game/start_game"); } $pointsNum = $checkpointArr[0]['reward_points']; $proArr = array('a' => $checkpointArr[0]['reward_pro_1'], 'b' => $checkpointArr[0]['reward_pro_2'], 'c' => $checkpointArr[0]['reward_pro_3']); $sequence = ""; for ($i = 0; $i < $pointsNum; $i++) { $sequence = $sequence . Util::extractRandomAnswer($proArr); } $messageArr['sequence'] = $sequence; $messageArr['score'] = $checkpointArr[0]['grade_score']; $messageArr['friendInfo'] = $friendInfo; $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key); $view = new JsonView(); return $this->getViewByJson($view, $messageArr, 1, "friend/get_fit_info"); }
/** * 获取根目录的路径 * * @access public * @param 无 * @return string 根目录绝对路径 */ public static function getRootDir() { $contents = IniFileManager::$ini_contents; if (empty($contents[self::ENV_CONFIG_FILE])) { $contents[self::ENV_CONFIG_FILE] = parse_ini_file(self::ENV_CONFIG_PATH); IniFileManager::$ini_contents = $contents; } if (!isset($contents[self::ENV_CONFIG_FILE][self::ROOT_DIR_KEY])) { return null; } return $contents[self::ENV_CONFIG_FILE][self::ROOT_DIR_KEY]; }
/** * 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"); }
/** * 新增一条memcache记录 * * @access public * @param string $key 要设置值的key * @param mixed $var 要存储的值,字符串和数值直接存储,其他类型序列化后存储 * @param int $flag 使用MEMCACHE_COMPRESSED指定对值进行压缩(使用zlib) * @param int $expire 当前写入缓存的数据的失效时间 / 0为永不过期 * @return boolean */ public function add($key, $var, $flag = null, $expire = null) { if (is_null($this->memcached)) { return false; } if (!isset($expire)) { $expire = IniFileManager::getByFilesKey(self::FILE_NAME, self::CONFIG_KEY_EXPIRE); } return $this->memcached->add($key, $var, $flag, $expire); }
/** * API:注册时主角初始化 * * @access public * @param int $user_id 用户ID $character_id主角ID * @return array */ public function registCharacter($user_id, $character_id) { $str = "character_id = " . $character_id; $file = IniFileManager::getRootDir() . "/files/csv/character.csv"; $characterArr = self::readCsv($file, $str); $userCharacter[$character_id] = array('n_level' => $characterArr[0]['level'], 'n_attack_level' => 0, 'n_crit_level' => 0, 'n_hp_level' => 0, 'wait_time' => 0); $userCharacter[0] = $character_id; $s_role_info = serialize($userCharacter); return $s_role_info; }
/** * 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; }
/** * API:获取签到信息 * * @access public * @param mixed $login_info 签到缓存信息 * @return $loginArr 返回签到信息数组 */ public function getUserLoginInfo($login_info = "") { // 无初始数据 if ($login_info == "") { $loginArr['con_day'] = 0; $loginArr['total_day'] = 0; // $loginArr['time'] = time(); $loginArr['type'] = 0; } else { // 非当天首次登陆 if ($login_info['time'] > strtotime(date('Y-m-d', time()))) { return false; } $loginArr['con_day'] = $login_info['con_day']; $loginArr['total_day'] = $login_info['total_day']; //$loginArr['time'] = time(); $loginArr['type'] = 0; // // 非连续签到 // if( strtotime( date( 'Y-m-d',time() ) ) - $login_info['check_time'] > 86400 ) // { // $loginArr['con_day'] = 1; // } } // 获取签到奖励内容 $cache = MemcacheManager::instance(); $memcacheArr = $cache->get(self::LOGIN_FILE); if ($memcacheArr) { $messageArr = $memcacheArr; } else { // 读取csv类 $dir = IniFileManager::getRootDir() . "files/csv/" . self::LOGIN_FILE . ".csv"; /*$str = "chest_id = " . 1; $messageArr = Util::readCsv( $dir, $str );*/ $csv = new Parsecsv(); $csv->auto($dir); $messageArr = $csv->data; /*echo "<pre>";var_dump($messageArr);exit; $loginArr['reward'] = $messageArr[0];*/ } /********************* 更新奖励列表 *****************/ // 统计箱子个数 $num = 1; foreach ($messageArr as $key => $value) { if ($value['chest_id'] == $messageArr[$key + 1]['chest_id']) { $rewardNumArr[$value['chest_id']] = ++$num; } else { $num = 1; } } // 随机箱子内容 $num = 0; foreach ($rewardNumArr as $key => $value) { $rewardArr[$key] = $messageArr[$num + rand(0, $value - 1)]; $probabilityArr[$key] = $rewardArr[$key]['probability']; $num = $num + $value; } $checkNum = Util::extractRandomAnswer($probabilityArr); $loginArr['rewardArr']['check'] = $checkNum; $loginArr['rewardArr']['box_info'] = $rewardArr; return $loginArr; }