/** * 判断是否主角全满级 * * @access public * @param int $user_id 用户ID * @return array */ public function isRoleMax($user_id) { $file = IniFileManager::getRootDir() . "/files/csv/character.csv"; $characterArr = CharacterAction::readCsv($file); $userCharacter = UserCache::getByKey($user_id, CharacterAction::CHARACTER_STRING); if (!$userCharacter) { $userCharacter = CharacterModel::getUserCharacterInfo($user_id); UserCache::setByKey($user_id, CharacterAction::CHARACTER_STRING, $userCharacter); } $attribute = array(1 => 'n_attack_level', 2 => 'n_crit_level', 3 => 'n_hp_level'); $CharacterNum = 0; foreach ($characterArr as $key => $value) { if ($userCharacter[$value['character_id']] && $userCharacter[$value['character_id']]['n_level'] == $value['bigest_level']) { foreach ($attribute as $key2 => $value2) { $CharacterNum += Constants::MAX_ATTRIBUTE - $userCharacter[$value['character_id']][$value2]; } } else { $CharacterNum += 15; } } // if (count($userCharacter)>count($characterArr)) // { // foreach ($userCharacter as $key => $value) // { // if ($value['n_level']==Constants::CHARACTER_MAX_LEVEL) // { // foreach ($attribute as $key2 => $value2) // { // $CharacterNum+=Constants::MAX_ATTRIBUTE-$value[$value2]; // } // } // else // { // $generalNum=5; // } // } // } // else { // $generalNum=10; // } return $CharacterNum; }
/** * 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"); }
/** * 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 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 */ 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"); }
/** * API:复活 * * @access public * @param 无 * @return JsonView 响应json * */ public function exeResurrect() { $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']; $type = self::$price_type[Constants::RESURE_TYPE]; $money = UserCache::getByKey($user_id, $type); if (!$money) { $userInfo = FriendModel::getUserInfo($user_id); $money = $userInfo[$type]; } $money = $money - Constants::RESURE_COST; if ($money < 0) { $messageArr['error'] = "人生果/钻石不足!"; $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key); $view = new JsonView(); return $this->getViewByJson($view, $messageArr, 0, "game/resurrect"); } $ret = CharacterModel::update(array($type => $money), array('n_id' => $user_id)); UserCache::setByKey($user_id, $type, $money); $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key); $view = new JsonView(); return $this->getViewByJson($view, $messageArr, 1, "game/resurrect"); }
/** * API:获取当前上阵主角信息 * * @access public * @param $integer $user_id $general_id 用户ID,武将ID * @return array */ public function nowCharacterInfo($user_id) { $userCharacter = UserCache::getByKey($user_id, self::CHARACTER_STRING); if (!$userCharacter) { $userCharacter = CharacterModel::getUserCharacterInfo($user_id); UserCache::setByKey($user_id, self::CHARACTER_STRING, $userCharacter); } return self::GetCharacterAttribute($user_id, $userCharacter[0]); }
/** * API:获取武将属性 * * @access public * @param $integer $user_id 用户ID * @return array */ public function GetAllGeneralInfo($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']]) { $generalArr[$key]['n_get'] = 1; //$generalArr[$key]['battle']=self::GetGeneralBattle($user_id,$value['general_id']); $generalArr[$key]['attributeInfo'] = self::GetGeneralAttribute($user_id, $value['general_id']); } else { $generalArr[$key]['n_get'] = 0; // $generalArr[$key]['battle']=self::GetGeneralBattle($user_id,$value['general_id']); $generalArr[$key]['attributeInfo'] = self::GetGeneralAttribute($user_id, $value['general_id']); } } foreach (self::$price_type as $key => $value) { $moneyArr[$value] = UserCache::getByKey($user_id, $value); if (!$moneyArr[$value]) { $userInfo = CharacterModel::getUserInfo($user_id); $moneyArr[$value] = $userInfo[$value]; } } $messageArr['moneyInfo'] = $moneyArr; $messageArr['generalInfo'] = $generalArr; return $messageArr; }
<?php class CharacterModel extends ImplicitWOGAPModel { public $table = 'wog_character'; } CharacterModel::setParams(array('ch_id' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'ch_name' => array('filter' => FILTER_SANITIZE_STRING), 'ch_str' => array('filter' => FILTER_SANITIZE_STRING), 'ch_agi' => array('filter' => FILTER_SANITIZE_STRING), 'ch_life' => array('filter' => FILTER_SANITIZE_STRING), 'ch_vit' => array('filter' => FILTER_SANITIZE_STRING), 'ch_smart' => array('filter' => FILTER_SANITIZE_STRING), 'ch_mlv' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'ch_map' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'ch_au' => array('filter' => FILTER_SANITIZE_STRING), 'ch_be' => array('filter' => FILTER_SANITIZE_STRING), 'ch_main' => array('filter' => FILTER_SANITIZE_NUMBER_INT)));