paras[0]; $difficulty = $req->paras[1]; # 关卡难度 difficulty $star = $req->paras[2]; $TeamObj = $req->paras[3]; $bossId = $req->paras[4]; # 本关消灭的bossid (<=0代表本关卡未出现boss) $smGate = GameConfig::gate_getItem($gateId); if (!CommUtil::isPropertyExists($req->userInfo->game->gates, "newGateRecord")) { $req->userInfo->game->gates->newGateRecord = ObjectInit(); # 防御未初始化的变量 } $gatesRecord = $req->userInfo->game->gates->newGateRecord; if (!CommUtil::isPropertyExists($gatesRecord, "record")) { $gatesRecord->record = ObjectInit(); # 防御未初始化的变量 } ///按 三个难度取不同的值. $i = $difficulty + 1; $tili = self::getProperty_n($smGate, "tili", $i); $reward = self::getProperty_n($smGate, "reward", $i); $gold = self::getProperty_n($smGate, "gold", $i); $exp = self::getProperty_n($smGate, "exp", $i); #补充战斗记录 if (!CommUtil::isPropertyExists($gatesRecord->record, $gateId)) { $gatesRecord->record->$gateId = ObjectInit(); } if ($difficulty <= 0) { $gatesRecord->record->$gateId->normal = $star; if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "normalToday")) { $gatesRecord->record->$gateId->normalToday = 0; } } else if ($difficulty == 1) { $gatesRecord->record->$gateId->hard = $star; if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "hardToday")) { $gatesRecord->record->$gateId->hardToday = 0; } } else if ($difficulty == 2) { $gatesRecord->record->$gateId->elite = $star; if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "eliteToday")) { $gatesRecord->record->$gateId->eliteToday = 0; } } $canfighterr = SweepGatesProc::CanFight($req, $gateId, $difficulty); if ($canfighterr) {#不能符合战斗要求 return $canfighterr; } // $req->userInfo->game->gates->newGateRecord = $gatesRecord; # 回写数据 ActiveProc::ChangeTili(- $tili, $req); # 扣减体力 $req->userInfo->game->gates->TotalNum++; # 更新战斗次数统计 $req->userInfo->game->gates->Times++; ///增加英雄经验 组长去掉 // foreach ($TeamObj as $heroUID) { // HeroProc::HeroAddEXP($heroUID, $tili, $req); // } // 按照概率规则发放奖品 $rewardsArr = explode(";", $reward); $rwds = array(); foreach ($rewardsArr as $r) { $arr = explode(',', $r); $itemid = intval($arr[0]); $num = intval($arr[1]); $probability = floatval($arr[2]); # 掉落概率精度精确到±0.01% if (CommUtil::randomPercent($probability)) { # 投色子 $err = StoreProc::AddMultiItemInStore($req, "$itemid,$num"); if ($err) { return Resp::err($err); } $rwds[] = "$itemid,$num"; } } if ($bossId > 0) { # boss关处理 $req->userInfo->game->gates->killedBoss[] = $bossId; } UserGameModel::Add_Gold($req->mem, $req->userInfo->game, $gold); # 发放金币奖励 if ($err) { return Resp::err($err); } UserGameModel::Add_Exp($req, $exp); # 发放经验奖励 UserProc::updateUserInfo($req); # 在获取战利品哪里已经update了. $result = array( 'store' => $req->userInfo->game->store, 'heros' => $req->userInfo->game->heros, 'gates' => $req->userInfo->game->gates, 'tili' => $req->userInfo->game->tili, 'time' => $req->userInfo->game->privateState->TiliTime, 'gold' => $gold, 'exp' => $exp, 'rewardstr' => implode(';', $rwds) ); return Resp::ok($result); } /** * 提取某个对象的某个字段(利用后面2个参数组合为字段名) * @param type $obj * @param type $name * @param type $index * @return type */ private static function getProperty_n($obj, $name, $index) { if (is_object($obj)) { $ke = "$name$index"; if (property_exists($obj, $ke)) { return $obj->$ke; } } return null; } /** * [6818]更改地图所停留的城镇 * //需要消耗体力 * @param type $req */ public static function ChangeArenas_StayCity($req) { # 提取参数 # 0. 目标地址 # 1. 消耗体力 $cityId = $req->paras[0]; $costTili = $req->paras[1]; if (!CommUtil::isPropertyExists($req->userInfo->game->gates, "newGateRecord")) { $req->userInfo->game->gates->newGateRecord = ObjectInit(); } $gatesRecord = $req->userInfo->game->gates->newGateRecord; #在此补充检查消耗体力的数值是否正确 # $gatesRecord->lastStayCityId = $cityId; $req->userInfo->game->gates->newGateRecord = $gatesRecord; #体力变化 ActiveProc::ChangeTili(-$costTili, $req); UserProc::updateUserInfo($req); $result = array( 'gates' => $req->userInfo->game->gates, 'tili' => $req->userInfo->game->tili, 'time' => $req->userInfo->game->privateState->TiliTime, ); return Resp::ok($result); } /** * 关卡挑战1次 * @param Req $req * @deprecated since version 0 用新版 */ public static function Arenas_Fight($req) { # 提取参数 # 0. 挑战的关卡Id # 1. 挑战结果 和李宁商量了,挑战结果是没有用的,只有胜利以后才会发送服务器端.所以这里打算改为关卡难度(0,1,2) # 2. 挑战记录 // 验证之用.几星. #3.队伍信息 $gateId = $req->paras[0]; $difficulty = $req->paras[1]; ///这里将会改为关卡难度 difficulty $star = $req->paras[2]; $TeamObj = $req->paras[3]; $bossId = $req->paras[4]; // 本关消灭的bossid (<=0代表本关卡未出现boss) $isNewbieGuideGate = false; if ($gateId == 504001) { $isNewbieGuideGate = true; } $smGate = GameConfig::gate_getItem($gateId); ///按三个难度取不同的值. if ($difficulty == 0) { $gates = $req->userInfo->game->gates->normal; $tili = $smGate->tili1; $rwdstr = $smGate->reward1; $gold = $smGate->gold1; $exp = $smGate->exp1; } else if ($difficulty == 1) { $gates = $req->userInfo->game->gates->hard; $tili = $smGate->tili2; $rwdstr = $smGate->reward2; $gold = $smGate->gold2; $exp = $smGate->exp2; } else if ($difficulty == 2) { $gates = $req->userInfo->game->gates->elite; $tili = $smGate->tili3; $rwdstr = $smGate->reward3; $gold = $smGate->gold3; $exp = $smGate->exp3; } $typeId = substr($gates->highest, 0, 3); #分类 if ($typeId != '503') { $gates->highest = 503000; } if (!$isNewbieGuideGate) { if ($gateId > $gates->highest + 1) { # 不能跳关 return Resp::err(ErrCode::err_arenasgate_indexillegal); } else if ($gateId == $gates->highest + 1) { $gates->highest += 1; // 更新最高记录 } $gates->latest = $gateId; #记录数据 $uGate = new UGateModel(); if (isset($gates->gates->$gateId)) { $uGate = $gates->gates->$gateId; } $uGate->challengeTimes++; if ($uGate->star < $star) { $uGate->star = $star; } $uGate->cleared = 1; $gates->gates->$gateId = $uGate; ////体力变化 // UserGameModel::Add_Exp($req->mem, $req->userInfo->game, $tili);////老的增加玩家经验的去掉 ActiveProc::ChangeTili(-$tili, $req); ///增加英雄经验 这个功能组长取消掉了 // foreach ($TeamObj as $heroUID) { // HeroProc::HeroAddEXP($heroUID, $tili, $req); // } ////总战斗次数+1 $req->userInfo->game->gates->TotalNum++; $req->userInfo->game->gates->Times++; } /////检测如果当前物品格子大于物品总数,则可以获取战利品,否则不可以 ////战利品获取 $err = StoreProc::AddMultiItemInStore($req, $rwdstr); if ($err) { return Resp::err($err); } if ($bossId > 0) { $req->userInfo->game->gates->killedBoss[] = $bossId; } // 增加发经验和发金币 UserGameModel::Add_Gold($req->mem, $req->userInfo->game, $gold); UserGameModel::Add_Exp($req, $exp); UserProc::updateUserInfo($req); //在获取战利品哪里已经update了. $result = array( 'store' => $req->userInfo->game->store, 'heros' => $req->userInfo->game->heros, 'gates' => $req->userInfo->game->gates, 'tili' => $req->userInfo->game->tili, 'time' => $req->userInfo->game->privateState->TiliTime, 'gold' => $gold, 'exp' => $exp ); return Resp::ok($result); } // // // /** // * 关卡-扫荡 // * @param RequestVo $req // */ // public static function Arenas_SweepFight($req) // { // $resp = ResponseVo::err($req, ErrCode::msg_methodnotimplement); // # 提取参数 // # 0. 扫荡的关卡Id // # 1. 扫荡次数 // # 2. 挑战记录 // 验证之用. // $gateId = $req->paras[0]; // $iNum = $req->paras[1]; // $fightLog = $req->paras[2]; // $isNewbieGuideGate = false; // $gates = $req->userInfo->game->gates; // if ($gateId == 504001) { // $isNewbieGuideGate = true; // } // if ($iNum && !$fightLog) {# 检查挑战记录 // return ResponseVo::err($req, ErrCode::err_arenas_logillegal); // } // if (!$isNewbieGuideGate) { // if ($gateId > $gates->highest + 1) { # 不能跳关 // return ResponseVo::err($req, ErrCode::err_arenasgate_indexillegal); // } // } // #记录数据 // $uGate = new UGateModel(); // if (isset($gates->gates->$gateId)) { // $uGate = $gates->gates->$gateId; // } // $uGate->challengeTimes += $iNum; // $gates->gates->$gateId = $uGate; // UserProc::updateUserInfo($req); // $resp = ResponseVo::ok($req, array()); // 返回成功,以及奖励数据 // // return $resp; // } /* * 扫荡 */ public static function Arenas_NewSweepFight($req) { $gateId = $req->paras[0]; $difficulty = $req->paras[1]; # 关卡难度 difficulty $costItemId = $req->paras[2]; #扫荡券id $smGate = GameConfig::gate_getItem($gateId); if (!CommUtil::isPropertyExists($req->userInfo->game->gates, "newGateRecord")) { $req->userInfo->game->gates->newGateRecord = ObjectInit(); # 防御未初始化的变量 } $gatesRecord = $req->userInfo->game->gates->newGateRecord; if (!CommUtil::isPropertyExists($gatesRecord, "record")) { $gatesRecord->record = ObjectInit(); # 防御未初始化的变量 } ///按 三个难度取不同的值. $i = $difficulty + 1; $tili = self::getProperty_n($smGate, "tili", $i); $reward = self::getProperty_n($smGate, "reward", $i); $gold = self::getProperty_n($smGate, "gold", $i); $exp = self::getProperty_n($smGate, "exp", $i); $err = StoreProc::removeItemFromStore($req->userInfo->game->store, $costItemId, 1); if ($err) { # 扣除失败 return Resp::err($err); } #补充战斗记录 $canfighterr = SweepGatesProc::CanFight($req, $gateId, $difficulty); if ($canfighterr) {#不能符合战斗要求 return $canfighterr; } // $req->userInfo->game->gates->newGateRecord = $gatesRecord; # 回写数据 ActiveProc::ChangeTili(- $tili, $req); # 扣减体力 $req->userInfo->game->gates->TotalNum++; # 更新战斗次数统计 $req->userInfo->game->gates->Times++; // 按照概率规则发放奖品 $rewardsArr = explode(";", $reward); $rwds = array(); foreach ($rewardsArr as $r) { $arr = explode(',', $r); $itemid = intval($arr[0]); $num = intval($arr[1]); $probability = intval($arr[2]); if (CommUtil::randomPercent($probability)) { # 投色子 $err = StoreProc::AddMultiItemInStore($req, "$itemid,$num"); if ($err) { return Resp::err($err); } $rwds[] = "$itemid,$num"; } } UserGameModel::Add_Gold($req->mem, $req->userInfo->game, $gold); # 发放金币奖励 if ($err) { return Resp::err($err); } UserGameModel::Add_Exp($req, $exp); # 发放经验奖励 UserProc::updateUserInfo($req); # 在获取战利品哪里已经update了. $result = array( 'store' => $req->userInfo->game->store, 'heros' => $req->userInfo->game->heros, 'gates' => $req->userInfo->game->gates, 'tili' => $req->userInfo->game->tili, 'time' => $req->userInfo->game->privateState->TiliTime, 'gold' => $gold, 'exp' => $exp, 'rewardstr' => implode(';', $rwds) ); return Resp::ok($result); } /** * 是否可以战斗 * @param type $req * @param $gateId * @param $difficulty * @return type */ static function CanFight($req, $gateId, $difficulty) { $gatesRecord = $req->userInfo->game->gates->newGateRecord; $smGate = GameConfig::gate_getItem($gateId); if (!CommUtil::isPropertyExists($gatesRecord->record, $gateId)) { $gatesRecord->record->$gateId = ObjectInit(); } if ($difficulty > 2) { return Resp::err(ErrCode::err_arenasgate_indexillegal); } if ($difficulty == 0) { if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "normal")) { return Resp::err(ErrCode::err_arenas_normalgate_numno); } if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "normalToday")) { return Resp::err(ErrCode::err_arenas_normalgate_numno); } if ($smGate->cishu1 - $gatesRecord->record->$gateId->normalToday < 1) { return Resp::err(ErrCode::err_arenas_normalgate_numno); } $gatesRecord->record->$gateId->normalToday += 1; } else if ($difficulty == 1) { if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "hard")) { return Resp::err(ErrCode::err_arenas_normalgate_numno); } if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "hardToday")) { return Resp::err(ErrCode::err_arenas_normalgate_numno); } if ($smGate->cishu2 - $gatesRecord->record->$gateId->hardToday < 1) { return Resp::err(ErrCode::err_arenas_normalgate_numno); } $gatesRecord->record->$gateId->hardToday += 1; } else if ($difficulty == 2) { if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "elite")) { return Resp::err(ErrCode::err_arenas_normalgate_numno); } if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "eliteToday")) { return Resp::err(ErrCode::err_arenas_normalgate_numno); } if ($smGate->cishu3 - $gatesRecord->record->$gateId->eliteToday < 1) { return Resp::err(ErrCode::err_arenas_normalgate_numno); } $gatesRecord->record->$gateId->eliteToday += 1; } } // // /** * 关卡—————— 根据星星数量获得对应奖励 * @param type $req * @deprecated since version 0 用新版 */ public static function GetArenasStarReward($req) { $resp = Resp::err(ErrCode::err_method_notimplement); $gamedata = $req->userInfo->game; $rewardID = $req->paras[0]; //奖励的数据ID //1.检查奖励数据是否存在 $rewardCfg = GameConfig::gate_starreward_getItem($rewardID); // ConstProc::getArenasGate_StarReward($rewardID); if (!$rewardCfg) { return Resp::err(ErrCode::err_arenas_starreward_const_no); } //2.检查玩家是否已经领取了 $gates = $req->userInfo->game->gates; $getStarRewardRecord = ArrayInit(); if (CommUtil::isPropertyExists($gates, "starRewards")) { $getStarRewardRecord = $gates->starRewards; } if (CommUtil::isInArray($getStarRewardRecord, $rewardID)) { return Resp::err(ErrCode::err_arenas_hasgetstarreward); } //3.检查玩家的当前星星数是否满足数量要求 //"normal": { // "latest": 502001, // "highest": 502001, // "gates": { // "502001": { // "star": 3, // "cleared": 1, // "challengeTimes": 1 // } // } $totalStarNum = 0; $normalRecord = $gates->normal; foreach ($normalRecord->gates as $key => $gate) { $totalStarNum += $gate->star; } $hardRecord = $gates->hard; foreach ($hardRecord->gates as $key => $gate) { $totalStarNum += $gate->star; } $eliteRecord = $gates->elite; foreach ($eliteRecord->gates as $key => $gate) { $totalStarNum += $gate->star; } DebugHelper::var_dump($totalStarNum); if ($totalStarNum < $rewardCfg->star) { return Resp::err(ErrCode::err_arenas_starreward_starNotEnough); } $rewardStr = $rewardCfg->reward; $arr_reward = explode(",", $rewardStr); $itemId = $arr_reward[0]; $itemNum = $arr_reward[1]; $str1 = substr($itemId, 0, 3); switch ($str1) { ///怪物卡或者英雄卡牌获取 case "101": case "201": // HeroProc::AddHeroTFromStore($req, $itemId); break; ///装备物品的获取. case "301": case "302": case "303": StoreProc::PutEquipInStore($itemId, $req); break; ///宝石的获取 case "304": StoreProc:: PutOverlyingItemInStore($itemId, $itemNum, $req); break; //金币的获取 case "399": if ($itemId == "399002") { UserGameModel::Add_Gold($req->mem, $req->userInfo->game, $itemNum); } break; default: break; } //保存记录 $getStarRewardRecord[] = $rewardID; $req->userInfo->game->gates->starRewards = $getStarRewardRecord; // 更新数据库数据 UserProc::updateUserInfo($req); $result = ObjectInit(); $result->getreward = true; $resp = Resp::ok($result); return $resp; } /** * 扣除买buffer的费用 * @param type $req * @return type */ public static function ConsumeBufferGold($req) { $user = $req->userInfo->game; # user引用 $money = $req->paras[0]; //需要的手工费 // echo var_dump($money); $bDeal = UserGameModel::Consume_Gold($user, $money); if ($bDeal) { $result = array( 'resp' => "succeed!" ); // 更新数据库数据 $resp = Resp::ok($result); } else { // $user->gold=0; $result = array( 'resp' => "succeed!" ); // 更新数据库数据 $resp = Resp::ok($result); } UserProc::updateUserInfo($req); return $resp; } // // /** * 查询租借好友记录 * @param Req $req */ public static function GetBorrowedFriends($req) { // 查询好友借用记录中的数据 $rentedfriends = $req->userInfo->game->privateState->rentedFriends; if (!$rentedfriends || !is_array($rentedfriends)) { $rentedfriends = ArrayInit(); } return Resp::ok(array('ret' => $rentedfriends)); } /** * 清理战斗租借好友记录 * */ public static function ClearFightRentRecord($req) { $req->userInfo->game->privateState->rentedFriends = ArrayInit(); } /** * 扣除借用好友费用 * @param Req $req */ public static function ConsumeBorrowFriend($req) { // 提取参数:好友id $friend_uid = $req->paras[0]; // 验证好友关系 if (!FriendProc::isFriendship($req->zoneid, $req->uid, $friend_uid)) { return Resp::err(ErrCode::friend_no_err); } // 验证尚未租借过 $rentedfriends = $req->userInfo->game->privateState->rentedFriends; if (!$rentedfriends || !is_array($rentedfriends)) { $rentedfriends = ArrayInit(); } if (in_array($friend_uid, $rentedfriends)) { return Resp::err(array('err' => -1, 'msg' => 'has rented this player today!')); } // 验证好友出借英雄 $friend_info = UserProc::getUserInfo(gMem(), $req->zoneid, $friend_uid); if (!$friend_info) { return Resp::err(ErrCode::user_no_err, '找不到好友的游戏数据!'); } // todo:啦啦啦... 先不写了,管它用的是哪个英雄呢 // // 扣除费用,失败->金币不足 $arr = explode(',', glc()->User_Friends_HireFriendForBattle_Cost); if (count($arr) < 2) { return Resp::err(ErrCode::err_const_no); } $itemid = $arr[0]; # 道具id $amt = $arr[1]; # 数量 if ($itemid == META_GOLD_ITEMID) { $user = $req->userInfo->game; if ($user->gold < $amt) { return Resp::err(array('err' => -2, 'msg' => 'gold not enough!')); } UserGameModel::Consume_Gold($user, $amt); // todo: 给好友发送金币 邮件 EmailProc::SendHireCoinFromFight($req->zoneid, $friend_uid, # $req->userInfo->game->name, $req->uid, $amt); # 好友收益需要扣除系统税率. } else { return Resp::err(ErrCode::err_const_no); } // 添加借用记录 $rentedfriends[] = $friend_uid; $req->userInfo->game->privateState->rentedFriends = $rentedfriends; // 回写数据 UserProc::updateUserInfo($req); // 玩家数据 // UserProc::setUserInfo(global_mem(), $friend_info); // 好友数据 // 返回 return Resp::ok(array('err' => 0, 'curgold' => $user->gold)); } // // /** * 挑战黄金 无穷无尽战斗模式 * @param type $req */ public static function ChallengeEndlessFightMode_Gold($req) { $gateForeverId = $req->paras[0]; $difficuty = $req->paras[1]; $bociCount = $req->paras[2]; //判断是否已经达到挑战的次数上限 $gates = $req->userInfo->game->gates; if (!CommUtil::isPropertyExists($gates, "forever_Gold_FightTimes")) { $gates->forever_Gold_FightTimes = 0; } if ($gates->forever_Gold_FightTimes >= glc()->Battle_Forever_MaxCountEveryDay) { return Resp::err(ErrCode::err_gateForever_countIsFull, '挑战次数已经用尽!'); } //1.取出无尽模式的关卡常量数据 $gateForeverConst = GameConfig::gateforever_getItem($gateForeverId); // ConstProc::getGold_GateForeverGoldConst($gateForeverId); $gateBattleBociConst = GameConfig::gatecombat_getItem($gateForeverId); if (!$gateForeverConst) { return Resp::err(ErrCode::err_gateForever_const_no); } //判断次数是否合法 $bociArr = explode(",", $gateBattleBociConst->level); if ($bociCount > count($bociArr)) { return Resp::err(ErrCode::err_gateForever_countillegal); } //2.取出模式下的奖励数据 $rewardStr = $gateForeverConst->reward1; $arr_reward = explode(";", $rewardStr); foreach ($arr_reward as $value) { if (strlen($value) > 0) { $arr_RealReward = explode(",", $value); $itemId = $arr_RealReward[0]; $itemNum = $arr_RealReward[1]; $str1 = substr($itemId, 0, 3); //3.根据挑战的波次数据,重复累计获得奖励 for ($i = 0; $i < $bociCount; $i++) { switch ($str1) { ///怪物卡或者英雄卡牌获取 case "101": case "201": // HeroProc::AddHeroTFromStore($req, $itemId); break; ///装备物品的获取. case "301": case "302": case "303": StoreProc::PutEquipInStore($itemId, $req); break; ///宝石的获取 case "304": StoreProc:: PutOverlyingItemInStore($itemId, $itemNum, $req); break; //金币的获取 case "399": if ($itemId == "399002") { UserGameModel::Add_Gold($req->mem, $req->userInfo->game, $itemNum); } break; default: break; } } } } //4、存储玩家的挑战次数 $gates->forever_Gold_FightTimes = $gates->forever_Gold_FightTimes + 1; // 回写数据 UserProc::updateUserInfo($req); $result = ObjectInit(); $result->result = "succeed"; $result->forever_Gold_FightTimes = $gates->forever_Gold_FightTimes; $resp = Resp::ok($result); return $resp; } /** * 清理挑战无尽模式的 次数记录 * */ public static function ClearGateForeverGold_FightCountEveryDay($req) { $req->userInfo->game->gates->forever_Gold_FightTimes = 0; } /** * 清理每个难度副本的每日战斗次数 * @param type $req */ public static function ClearGateTimes($req) { if (!CommUtil::isPropertyExists($req->userInfo->game->gates, 'newGateRecord')) { $req->userInfo->game->gates->newGateRecord = ObjectInit(); } if (!CommUtil::isPropertyExists($req->userInfo->game->gates->newGateRecord, 'record')) { return; } $obj = $req->userInfo->game->gates->newGateRecord->record; //$result = empty($obj); // if ($result == true) { // return; //} foreach ($obj as $key => $value) { $value->normalToday = 0; $value->hardToday = 0; $value->eliteToday = 0; } UserProc::updateUserInfo($req); } // // // /** * 开启副本 * @param Req $req */ public static function OpenTheCarbon($req) { $gates = $req->userInfo->game->gates; $openedcarbons = $gates->carbons->openedCarbons; # 提取参数 $carbonId = $req->paras[0]; # 副本ID $difficulty = $req->paras[1]; # 难度等级 1,2,3 $key = "$carbonId-$difficulty"; # 键值 if (!($gates && $openedcarbons)) { return Resp::err(ErrCode::err_innerfault); } if ($difficulty > 3 || $difficulty < 1) { return Resp::err(ErrCode::carbon_wrongdifficult); } if (CommUtil::isPropertyExists($openedcarbons, $key)) { $carbon = $openedcarbons->$key; } else { $carbon = new CarbonModel(); } if ($carbon->closeTs > now()) { return Resp::err(ErrCode::carbon_opened); } $carbonModel = GameConfig::gate_carbon_getItem($carbonId); # 常量 # 扣除开启消耗的道具 $keyid = "keyId$difficulty"; $keynum = "keyNum$difficulty"; $costItemId = $carbonModel->$keyid; $costItemNum = $carbonModel->$keynum; $err = StoreProc::removeItemFromStore($req->userInfo->game->store, $costItemId, $costItemNum); if ($err) { # 扣除失败 return Resp::err($err); } $carbon->closeTs = now() + $carbonModel->duration; # 关闭倒计时 $carbon->curIndex = 0; # 索引重置为0 $openedcarbons->$key = $carbon; $req->userInfo->game->gates->carbons->openedCarbons = $openedcarbons; UserProc::updateUserInfo($req); return Resp::ok(array('err' => 0, 'carbons' => $openedcarbons)); } /** * 挑战副本关卡 * @param Req $req */ public static function ChallengeCarbon($req) { $gates = $req->userInfo->game->gates; $carbons = $gates->carbons->openedCarbons; # 提取参数 $carbonId = $req->paras[0]; # 副本ID $difficulty = $req->paras[1]; # 难度等级 1,2,3 $gateindex = $req->paras[2]; # 关卡索引 0,1,2,... $star = $req->paras[3]; # 战斗评价(几星) $TeamObj = $req->paras[4]; # 队伍信息 // $bossId = $req->paras[5]; # 本关消灭的bossid (<=0代表本关卡未出现boss) if ($difficulty > 3 || $difficulty < 1) { return Resp::err(ErrCode::carbon_wrongdifficult); } $key = "$carbonId-$difficulty"; # 键值 # 0 当前副本处于开启状态 # 1 当前关卡索引,不能跳着打, # 2 记录下战斗评价(几星), 也许以后用得着,比如最后通关后,给个啥奖励 # 3 决定掉落物品, 发给客户端 # 4 发放对应的经验之类的东西 # 5 检查是否最后一个关卡, 是, 关闭副本 # 6 回存数据,返回 isEditor() && $carbon = new CarbonModel; if (CommUtil::isPropertyExists($carbons, $key)) { $carbon = $carbons->$key; } else { $carbon = null; } if (!$carbon || $carbon->closeTs < now()) { return Resp::err(ErrCode::carbon_closed); } $carbonModel = GameConfig::gate_carbon_getItem($carbonId); # 副本常量数据 $gateIds = explode(',', $carbonModel->gateids); if ($gateindex < 0 || $gateindex >= count($gateIds)) { return Resp::err(ErrCode::carbon_gateIndex); } if ($carbon->curIndex == $gateindex || $gateindex == 0) { $carbon->curIndex += 1; # 更新进度 } else { # 不能跳关 return Resp::err(ErrCode::carbon_gateIndex); } $gateId = $gateIds[$gateindex]; # 通过索引获得关卡ID $tl = "tili$difficulty"; # 体力难度 $rwd = "reward$difficulty"; # 奖励难度 $arr = array("normal", 'hard', 'elite'); # 难度名称 $gt = $arr[$difficulty - 1]; # 关卡分类 $gateModel = GameConfig::gate_carbon_content_getItem($gateId); # 副本关卡常量数据 $tili = $gateModel->$tl; # 扣除体力 $reward = $gateModel->$rwd; # 获得奖励 # # 打副本呢也要扣除体力 ActiveProc::ChangeTili(-$tili, $req); # 扣除多少体力就给账号增加多少经验 -by 李宁, reconfirmed by wg 20170519144109 UserGameModel::Add_Exp($req, $tili); # 增加英雄经验(也是依据扣除的体力数) foreach ($TeamObj as $heroUID) { HeroProc::HeroAddEXP($heroUID, $tili, $req); } // $carbon->stars; 暂不记录了 # 掉落战利品->获取 $err = StoreProc::AddMultiItemInStore($req, $reward); if ($err) { return Resp::err($err); } if (count($gateIds) == $gateindex + 1) { # 最后一个关卡 unset($carbons->$key); # 关闭掉关卡,或者是直接删掉 } else { $carbons->$key = $carbon; # 回存数据 } $req->userInfo->game->gates->carbons->openedCarbons = $carbons; UserProc::updateUserInfo($req); //在获取战利品哪里已经update了. # Ps.备注,奖品是固定的,所以不必返回 $result = array( 'store' => $req->userInfo->game->store, 'heros' => $req->userInfo->game->heros, 'gates' => $req->userInfo->game->gates, 'tili' => $req->userInfo->game->tili, 'time' => $req->userInfo->game->privateState->TiliTime ); return Resp::ok($result); } /** 新版本的挑战 副本胜利 * * @param Req $req */ public static function NewChallengeCarbon($req) { $gates = $req->userInfo->game->gates; $carbons = $gates->carbons->openedCarbons; # 提取参数 $carbonId = $req->paras[0]; # 副本ID $gateId = $req->paras[1]; # 关卡ID $difficulty = $req->paras[2]; # 难度等级 1,2,3 $star = $req->paras[3]; # 战斗评价(几星) $TeamObj = $req->paras[4]; # 队伍信息 if ($difficulty > 3 || $difficulty < 1) { return Resp::err(ErrCode::carbon_wrongdifficult); } $key = "$carbonId-$difficulty"; # 键值 # 0 当前副本处于开启状态 # 1 战斗胜利之后,副本直接关闭 # 2 记录下战斗评价(几星), 也许以后用得着,比如最后通关后,给个啥奖励 # 3 决定掉落物品, 发给客户端 # 4 发放对应的经验之类的东西 # 5 检查是否最后一个关卡, 是, 关闭副本 # 6 回存数据,返回 isEditor() && $carbon = new CarbonModel; if (CommUtil::isPropertyExists($carbons, $key)) { $carbon = $carbons->$key; } else { $carbon = null; } if (!$carbon || $carbon->closeTs < now()) { return Resp::err(ErrCode::carbon_closed); } unset($carbons->$key); $tl = "tili$difficulty"; # 体力难度 $rwd = "reward$difficulty"; # 奖励难度 $gateModel = GameConfig::gate_carbon_content_getItem($gateId); # 副本关卡常量数据 $tili = $gateModel->$tl; # 扣除体力 $reward = $gateModel->$rwd; # 获得奖励 # # 打副本呢也要扣除体力 ActiveProc::ChangeTili(-$tili, $req); // 按照概率规则发放奖品 $rewardsArr = explode(";", $reward); $rwds = array(); foreach ($rewardsArr as $r) { $arr = explode(',', $r); $itemid = intval($arr[0]); $num = intval($arr[1]); $probability = floatval($arr[2]); # 掉落概率精度精确到±0.01% if (CommUtil::randomPercent($probability)) { # 投色子 $err = StoreProc::AddMultiItemInStore($req, "$itemid,$num"); if ($err) { return Resp::err($err); } $rwds[] = "$itemid,$num"; } } if ($err) { return Resp::err($err); } $req->userInfo->game->gates->carbons->openedCarbons = $carbons; UserProc::updateUserInfo($req); //在获取战利品哪里已经update了. # Ps.备注,奖品是固定的,所以不必返回 SystemProc::Carbon_Win($req->zoneid, $req->userInfo->game, $carbonId, $difficulty); # 插入通过副本消息 $result = array( 'store' => $req->userInfo->game->store, 'heros' => $req->userInfo->game->heros, 'gates' => $req->userInfo->game->gates, 'tili' => $req->userInfo->game->tili, 'time' => $req->userInfo->game->privateState->TiliTime, 'gold' => 0, 'exp' => 0, 'rewardstr' => implode(';', $rwds) ); return Resp::ok($result); } /** * 挑战剧情关卡 * @param type $req */ public static function ChallengeStoryGate($req) { $gates = $req->userInfo->game->gates; # 提取参数 $storyId = $req->paras[0]; # 剧情ID $difficulty = $req->paras[1]; # 难度等级 1,2,3 $star = $req->paras[2]; # 战斗评价(几星) $TeamObj = $req->paras[3]; # 队伍信息 $bossId = $req->paras[4]; # 本关消灭的bossid (<=0代表本关卡未出现boss) // #1. 判断是否有记录过剧情的战斗信息 if (!CommUtil::isPropertyExists($gates, "story")) { $gates->story = ObjectInit(); $gates->story->lastFinishedStoryGateId = 0; $gates->story->allFinishedStoryGateIdList = ArrayInit(); } $storrRecord = $gates->story; #2.取出模式下的奖励数据 $memStoryModel = GameConfig::gatestory_getItem($storyId); $tili = 0; $rewardStr = $memStoryModel->storyGateReward; #3 同步下剧情的推进进度数据 if ($storrRecord->lastFinishedStoryGateId == $storyId || in_array($storyId, $storrRecord->allFinishedStoryGateIdList)) { return Resp::err(ErrCode::story_repeatfight); #剧情关卡不能重复战斗 只能打一次 } else { $storrRecord->lastFinishedStoryGateId = $storyId; $storrRecord->allFinishedStoryGateIdList[] = $storyId; } # # 4 万一打剧情也扣除体力呢 if ($tili > 0) { ActiveProc::ChangeTili(-$tili, $req); # 扣除多少体力就给账号增加多少经验 -by 李宁, reconfirmed by wg 20170519144109 UserGameModel::Add_Exp($req, $tili); # 增加英雄经验(也是依据扣除的体力数) foreach ($TeamObj as $heroUID) { HeroProc::HeroAddEXP($heroUID, $tili, $req); } }# 5 玩家获得 剧情的战斗奖励 $err = StoreProc::AddMultiItemInStore($req, $rewardStr); if ($err) { return Resp::err($err); }# 6 回存玩家的战斗记录 $req->userInfo->game->gates->story = $storrRecord; UserProc::updateUserInfo($req); //在获取战利品哪里已经update了. # Ps.备注,奖品是固定的,所以不必返回 $result = array( 'store' => $req->userInfo->game->store, 'heros' => $req->userInfo->game->heros, 'gates' => $req->userInfo->game->gates, 'tili' => $req->userInfo->game->tili, 'time' => $req->userInfo->game->privateState->TiliTime ); return Resp::ok($result); } // // // }