1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729 |
- <?php
- namespace loyalsoft;
- /**
- * 英雄处理逻辑
- * @author gwang
- */
- class HeroProc {
- //put your code here
- /**
- * 英雄处理逻辑分发
- * 所有的Proc中必须有这样一个方法
- * @param Req $req
- */
- static function procMain($req) {
- switch ($req->cmd) {
- case CmdCode::cmd_hero_levelup: # [6301] 英雄升级
- return HeroProc::HeroLevelUpCostItem($req);
- // case CmdCode::cmd_hero_changelockstate: # [6306] 英雄-修改锁定状态
- // return HeroProc::HeroChangelockstate($req);
- // case CmdCode::cmd_hero_gethero: # [6308] 分解英雄
- // return HeroProc::GetHero($req);
- // case CmdCode::cmd_hero_strength: # [6309] 英雄升阶
- // return HeroProc::HeroStrength($req);
- // case CmdCode::cmd_hero_upstar: # [6305] 英雄升星
- // return HeroProc::HeroUpStarByPieces($req);
- // case CmdCode::cmd_hero_openFavor: # [6310] 英雄好感度解锁
- // return HeroProc::HeroOpenFavor($req);
- // case CmdCode::cmd_hero_separate: # [6311] 分解英雄
- // return HeroProc::HeroSeparate($req);
- // case CmdCode::cmd_hero_buyCollectHeroLimtCount: # [6312] 扩展英雄数量上限
- // return HeroProc::BuyHeroMaxCountLimt($req);
- // case CmdCode::cmd_hero_changefriendsupport: # [6313] 更换支援好友
- // return HeroProc::ChangeFriendSupport($req);
- case CmdCode::cmd_hero_upgradeSkillLevel: # [6314] 英雄的技能升级
- return HeroProc::UpgradeSkillLevel($req);
- case CmdCode::cmd_hero_saveHeroTeamConfig: # [6315] 保存玩家战队数据
- return HeroProc::SaveHeroTeamConfig($req);
- case CmdCode::cmd_hero_upGodBlood: # [6322] 神血升级
- return HeroProc::UpGodBloodHeroByPieces($req);
- // case CmdCode::cmd_hero_unlockByPieces: # [6323] 解锁碎片
- // return HeroProc::UnLockHeroByPieces($req);
- # --------- 英雄评论 -----------
- case CmdCode::cmd_hero_GetDiscuss: # [6316]拉取英雄评论
- return HeroDiscussProc::GetDiscusses($req);
- case CmdCode::cmd_hero_PostDiscuss: # [6317]对英雄发表评论
- return HeroDiscussProc::Post($req);
- case CmdCode::cmd_hero_DeleteDiscuss: # [6319]删除评论
- return HeroDiscussProc::DeletePost($req);
- case CmdCode::cmd_hero_PraiseDiscuss: # [6318]给某条评论点赞
- return HeroDiscussProc::PriaseMsg($req);
- case CmdCode::cmd_hero_scoreit: # [6320]给某个英雄评分
- return HeroDiscussProc::Score($req);
- #----------------------------------------------
- case CmdCode::cmd_hero_buyHero: # [6321]购买英雄
- return HeroProc::BuyHeroByCostPieces($req);
- default: # err: 未知的命令码
- return Resp::err(ErrCode::cmd_err);
- }
- }
- /**
- * 解锁英雄
- * @param type $req
- */
- static function UnLockHeroByPieces($req) {
- $user = $req->userInfo->game; # user引用
- $heroModelId = $req->paras[0];
- $piecesId = $req->paras[1]; # 英雄碎片的ID
- $piecesNum = $req->paras[2];
- if (!CommUtil::isPropertyExists($user->heros, "recordUnLockHeroDic")) {
- $user->heros->recordUnLockHeroDic = ObjectInit();
- }
- $recordUnLockHeroDic = $user->heros->recordUnLockHeroDic;
- #检查是不是已经解锁过了
- $flag = 0;
- if (!CommUtil::isPropertyExists($recordUnLockHeroDic, $heroModelId)) {
- $recordUnLockHeroDic->$heroModelId = 0;
- }
- $flag = $recordUnLockHeroDic->$heroModelId;
- if ($flag == 1) {
- return Resp::err(ErrCode::hero_lockState);
- }
- #检查要解锁的英雄的常量配置是否存在
- $heroCfg = GameConfig::hero_getItem($heroModelId);
- if (!$heroCfg) {
- return Resp::err(ErrCode::hero_const_no_err);
- }
- #检查需要消耗的碎片的常量配置是否存在
- $piecesCfg = GameConfig::segment_getItem($piecesId);
- if (!$piecesCfg) {
- return Resp::err(ErrCode::const_no_err);
- }
- # 5.检查道具的数量是否充足
- $myPacketItems = $user->store->segement;
- $requirePiecesNum = $heroCfg->unlockConditionId;
- # 检查道具数量是否充足
- $enoughPieces = false;
- if ($heroModelId == $piecesCfg->prototypeData && $requirePiecesNum == $piecesNum) {
- #检查碎片
- if (!CommUtil::isPropertyExists($myPacketItems, $piecesId)) {
- $enoughPieces = false;
- } else {
- if ($myPacketItems->$piecesId < $requirePiecesNum) {
- $enoughPieces = false;
- } else {
- $enoughPieces = true;
- }
- }
- } else {
- return Resp::err(ErrCode ::paras_err, "error pieces para" . "req" . $piecesId . "_" . $requirePiecesNum . "/" . $piecesId . "_" . $piecesNum);
- }
- if ($enoughPieces === true) {
- # 6.进行
- # # 消耗道具
- $myPacketItems->$piecesId -= $requirePiecesNum;
- if ($myPacketItems->$piecesId < 0) {
- $myPacketItems->$piecesId = 0;
- }
- $recordUnLockHeroDic->$heroModelId = 1;
- $req->user->heros->recordUnLockHeroDic = $recordUnLockHeroDic;
- $req->userInfo->game->store->segement = $myPacketItems;
- # 回写数据
- UserProc::updateUserInfo($req);
- //返回OK
- return Resp::ok(array('result' => "OK"));
- } else {
- return Resp::err(ErrCode::hero_godblood_notengoughitem);
- }
- }
- /**
- * 购买英雄 消耗碎片
- * @param type $req
- */
- static function BuyHeroByCostPieces($req) {
- $user = $req->userInfo->game; # user引用
- $heroModelId = $req->paras[0];
- $costType = $req->paras[1];
- $costMoneyNum = $req->paras[2];
- $piecesId = $req->paras[3];
- $piecesNum = $req->paras[4];
- #1 检查玩家是否已经拥有此类英雄
- $collectHeros = $user->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- foreach ($collectHeros as $key => $value) {
- isEditor() and $value = new UserHeroModel();
- if ($value->modelId == $heroModelId) {
- return Resp::err(ErrCode::hero_existSameHero_err);
- }
- }
- #2 检查账户余额是否充足
- $heroCfg = GameConfig::hero_getItem($heroModelId);
- if (!$heroCfg) {
- return Resp::err(ErrCode::hero_const_no_err);
- }
- if ($heroCfg->isCanBuy == 0) {
- return Resp::err(ErrCode::paras_err);
- }
- #3检查碎片是否对不对
- #检查需要消耗的碎片的常量配置是否存在
- $piecesCfg = GameConfig::segment_getItem($piecesId);
- if (!$piecesCfg) {
- return Resp::err(ErrCode::err_store_itemnoconst);
- }
- # 5.检查道具的数量是否充足
- $myPacketItems = $user->store->segement;
- $requirePiecesNum = $piecesCfg->mergePrototypeNeedNum;
- # 检查道具数量是否充足
- $enoughPieces = false;
- if ($heroModelId == $piecesCfg->prototypeData && $requirePiecesNum == $piecesNum) {
- #检查碎片
- if (!CommUtil::isPropertyExists($myPacketItems, $piecesId)) {
- $enoughPieces = false;
- } else {
- if ($myPacketItems->$piecesId < $requirePiecesNum) {
- $enoughPieces = false;
- } else {
- $enoughPieces = true;
- }
- }
- } else {
- return Resp::err(ErrCode ::paras_err, "error pieces para" . "req" . $piecesId . "_" . $requirePiecesNum . "/" . $piecesId . "_" . $piecesNum);
- }
- if ($enoughPieces == true) {
-
- } else {
- return Resp::err(ErrCode::hero_godblood_notengoughitem);
- }
- $bDeal = false; # 成交
- if ($costType == "cash") {
- $realPrice = $heroCfg->cashPrice;
- if ($realPrice != $costMoneyNum) {
- return Resp::err(ErrCode::paras_err, "costCASH error! server need:" . $realPrice);
- } else {
- if ($costMoneyNum > 0) {
- if ($user->cash < $costMoneyNum) {
- return Resp::err(ErrCode::err_msg_cashnotenough);
- } else {
- $bDeal = UserGameModel::Consume_Cash($user, $costMoneyNum);
- }
- } else if ($costMoneyNum == 0) {
- $bDeal = true;
- } else {
- return Resp::err(ErrCode::paras_err);
- }
- }
- } else if ($costType == "gold") {
- $realPrice = $heroCfg->goldPrice;
- if ($realPrice != $costMoneyNum) {
- return Resp::err(ErrCode::paras_err, "costGold error! server need:" . $realPrice);
- } else {
- if ($costMoneyNum > 0) {
- if ($user->gold < $costMoneyNum) {
- return Resp::err(ErrCode::err_msg_goldnotenough);
- } else {
- $bDeal = UserGameModel::Consume_Gold($user, $costMoneyNum);
- }
- } else if ($costMoneyNum == 0) {
- $bDeal = true;
- } else {
- return Resp::err(ErrCode::paras_err);
- }
- }
- }
- # 4.消耗来获得英雄
- if ($bDeal) {
- # 6.进行
- # # 消耗道具
- $myPacketItems->$piecesId -= $requirePiecesNum;
- if ($myPacketItems->$piecesId < 0) {
- $myPacketItems->$piecesId = 0;
- }
- $req->userInfo->game->store->segement = $myPacketItems;
- # 回写数据
- UserProc::updateUserInfo($req);
- $resp = HeroProc::GetHero($req);
- SystemProc::GetHero($req->zoneid, $user, $heroModelId);
- }
- return $resp;
- }
- /**
- * 购买英雄
- * @param type $req
- */
- static function BuyHero($req) {
- $user = $req->userInfo->game; # user引用
- $heroModelId = $req->paras[0];
- $costType = $req->paras[1];
- $costMoneyNum = $req->paras[2];
- #1 检查玩家是否已经拥有此类英雄
- $collectHeros = $user->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- foreach ($collectHeros as $key => $value) {
- isEditor() and $value = new UserHeroModel();
- if ($value->modelId == $heroModelId) {
- return Resp::err(ErrCode::hero_existSameHero_err);
- }
- }
- $recordUnLockHeroDic = $user->heros->recordUnLockHeroDic;
- if (!$recordUnLockHeroDic) {
- $recordUnLockHeroDic = ObjectInit();
- }
- #检查是不是已经解锁过了
- $flag = 0;
- if (!CommUtil::isPropertyExists($recordUnLockHeroDic, $heroModelId)) {
- $recordUnLockHeroDic->$heroModelId = 0;
- }
- $flag = $recordUnLockHeroDic->$heroModelId;
- if ($flag == 0) {
- return Resp::err(ErrCode::hero_lockState);
- }
- #2 检查账户余额是否充足
- $heroCfg = GameConfig::hero_getItem($heroModelId);
- if (!$heroCfg) {
- return Resp::err(ErrCode::hero_const_no_err);
- }
- if ($heroCfg->isCanBuy == 0) {
- return Resp::err(ErrCode::paras_err);
- }
- $bDeal = false; # 成交
- if ($costType == "cash") {
- $realPrice = $heroCfg->cashPrice;
- if ($realPrice != $costMoneyNum) {
- return Resp::err(ErrCode::paras_err, "costCASH error! server need:" . $realPrice);
- } else {
- if ($costMoneyNum > 0) {
- if ($user->cash < $costMoneyNum) {
- return Resp::err(ErrCode::notenough_cash_msg);
- } else {
- $bDeal = UserGameModel::Consume_Cash($user, $costMoneyNum);
- }
- } else if ($costMoneyNum == 0) {
- $bDeal = true;
- } else {
- return Resp::err(ErrCode::paras_err);
- }
- }
- } else if ($costType == "gold") {
- $realPrice = $heroCfg->goldPrice;
- if ($realPrice != $costMoneyNum) {
- return Resp::err(ErrCode::paras_err, "costGold error! server need:" . $realPrice);
- } else {
- if ($costMoneyNum > 0) {
- if ($user->gold < $costMoneyNum) {
- return Resp::err(ErrCode::notenough_gold_msg);
- } else {
- $bDeal = UserGameModel::Consume_Gold($user, $costMoneyNum);
- }
- } else if ($costMoneyNum == 0) {
- $bDeal = true;
- } else {
- return Resp::err(ErrCode::paras_err);
- }
- }
- }
- # 4.消耗来获得英雄
- if ($bDeal) {
- $resp = HeroProc::GetHero($req);
- }
- return $resp;
- }
- /**
- * 保持队伍的战斗配置信息
- * @param Req $req
- */
- static function SaveHeroTeamConfig($req) {
- $teamsetting = $req->paras[0]; # 配置信息json文件
- $req->userInfo->game->heroTeamConfig = $teamsetting; # 更新配置
- UserProc::updateUserInfo($req); # 回写数据
- # # 添加到战斗力隐藏榜单中, for pvp back matchers, -wg 2017.07.13
- self::CalcTeamFightPower($req->zoneid, $req->uid, $req->userInfo->game);
- return Resp::ok(array('result' => "succeed"));
- }
- /**
- * 英雄技能升级
- * @param type $req
- */
- static function UpgradeSkillLevel($req) {
- # $resp = ResponseVo::ErrResponse($req, ErrCode::msg_methodnotimplement);
- $user = $req->userInfo->game; # user引用
- $huid = $req->paras[0]; # 英雄的UID
- $skillId = $req->paras[1]; # 要升级的技能
- $skillType = $req->paras[2]; # 要升级的技能
- $costGold = $req->paras[3]; # 要升级的消耗金币
- # # 1.检查是否存在要升级的英雄
- $collectHeros = $user->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
- return Resp::err(ErrCode::hero_no);
- }
- # # 2.判断英雄的该技能能否升级....
- isEditor() and $strengthHero = new UserHeroModel();
- $strengthHero = $collectHeros->$huid;
- # # 取出这个英雄的技能数据
- $targteHeroSkills = ObjectInit();
- if (CommUtil::isPropertyExists($strengthHero, "skills")) {
- $targteHeroSkills = $strengthHero->skills;
- }
- # 如果不存在这个类型的技能,则 初始化一个.
- if (!CommUtil::isPropertyExists($targteHeroSkills, $skillType)) {
- $targteHeroSkills->$skillType = JsonUtil::decode('{"level":1}');
- }
- $curSkillInfo = $targteHeroSkills->$skillType;
- $curSkillLevel = $curSkillInfo->level;
- # 3.判断技能等级能否在继续升级了
- if ($curSkillLevel >= $strengthHero->level) {
- return Resp::err(ErrCode::hero_upgradeSkill_maxLevel);
- }
- # 4.取出该技能升级消耗的常量数据
- # 检查是否存在当前技能的消耗常量数据
- // $lvs = GameConfig::skill_shengji_getItem($skillId);
- $lvs = \GameConfig::skill_upgrade_cost_getItem($skillId);
- if (!$lvs) {
- return Resp::err(ErrCode::hero_upgradeSkill_cost_const_no);
- }
- $realGold = $lvs->basic + ($curSkillLevel - 1) * $lvs->xishu;
- $arr_extracost = explode(";", $lvs->extra);
- foreach ($arr_extracost as $value) {
- $arr = explode(",", $value);
- if (count($arr) == 2) {
- $extraLevel = $arr[0];
- $extraGold = $arr[1];
- if ($extraLevel == $curSkillLevel + 1) {
- $realGold += $extraGold;
- break;
- }
- }
- }
- # 判断金币是否充足
- $bDeal = false; # 成交
- if ($realGold != $costGold) {
- return Resp::err(ErrCode::paras_err, "costGold error! server need:" . $realGold);
- } else {
- if ($costGold > 0) {
- if ($user->gold < $costGold) {
- return Resp::err(ErrCode::notenough_gold_msg);
- } else {
- $bDeal = UserGameModel::Consume_Gold($user, $costGold);
- }
- } else if ($costGold == 0) {
- $bDeal = true;
- } else {
- return Resp::err(ErrCode::paras_err);
- }
- }
- # 4.消耗金币和英雄
- if ($bDeal) {
- $targteHeroSkills->$skillType->level += 1;
- $strengthHero->skills = $targteHeroSkills;
- ActiveProc::ChangeTaskCount($req);
- # 回写数据
- UserProc::updateUserInfo($req);
- $resp = Resp::ok($strengthHero);
- }
- return $resp;
- }
- /**
- * 更改好友支援
- * @param type $req
- */
- static function ChangeFriendSupport($req) {
- $user = $req->userInfo->game; # user引用
- if (!CommUtil::isPropertyExists($user->heros, "firendSupportHeroUID")) {
- $user->heros->firendSupportHeroUID = "";
- }
- $friendSupportHeroUids = $req->paras[0]; # 设置支援好友的英雄UID
- $collectHeros = $user->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- } # 1.检查玩家存在指定的英雄
- if (!CommUtil::isPropertyExists($collectHeros, $friendSupportHeroUids)) {
- return Resp::err(ErrCode::hero_separate_cost_hero);
- }
- $user->heros->firendSupportHeroUID = $friendSupportHeroUids;
- UserProc::updateUserInfo($req); # 回存数据
- return Resp::ok(array('firendSupportHeroUID' => $friendSupportHeroUids));
- }
- /**
- * 购买玩家可以收集的英雄的数量上限
- * @param type $req
- * @return type
- */
- static function BuyHeroMaxCountLimt($req) {
- $g = glc();
- $user = $req->userInfo->game; # user引用
- if (!CommUtil::isPropertyExists($user->heros, "maxCollectCount")) {
- $user->heros->maxCollectCount = $g->Game_CollectHero_BasicMaxCount;
- }
- $buyNum = $req->paras[0];
- $costCash = $req->paras[1];
- $index = ceil(($user->heros->maxCollectCount - $g->Game_CollectHero_BasicMaxCount) #
- / $g->Game_CollectHero_OneBuyLimtNum);
- $arr = explode(",", $g->Game_CollectHero_BasicMaxPrice);
- if ($index >= count($arr)) {
- return Resp::err(ErrCode::paras_err, "yi da shang xian");
- }
- $realCost = $arr[$index];
- if ($realCost != $costCash) {
- return Resp::err(ErrCode::paras_err, "costCash error! server need:" . $realCost);
- }
- if ($costCash <= 0) {
- return Resp::err(ErrCode::paras_err);
- }
- if ($user->cash < $costCash) {
- return Resp::err(ErrCode::notenough_spar);
- }
- UserGameModel::Consume_Cash($user, $costCash); # 扣除宝石
- $user->heros->maxCollectCount += $buyNum; # 修改上限
- UserProc::updateUserInfo($req);
- return Resp::ok(array(
- 'maxCollectCount' => $user->heros->maxCollectCount
- ));
- }
- /**
- * 英雄的分解获得晶石
- * @param type $req
- * @return type
- */
- static function HeroSeparate($req) {
- $g = glc();
- $user = $req->userInfo->game; # user引用
- $costHeroUids = $req->paras[0]; # 消耗掉的英雄UID
- # 1.检查是玩家的英雄数据
- $collectHeros = $user->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- # 3.检查消耗的英雄数量,以及玩家是否都存在这些英雄UID.
- $arr_costUID = explode(",", $costHeroUids);
- $isAllExist = true;
- foreach ($arr_costUID as $value) {
- if ($value == "") {
- continue;
- }
- if (!CommUtil::isPropertyExists($collectHeros, $value)) {
- $isAllExist = false;
- break;
- }
- }
- if (!$isAllExist) {
- return Resp::err(ErrCode::hero_separate_cost_hero);
- }
- # 4.统计下这些个英雄都能获得多少晶石
- # 消耗卡牌
- $spar = 0;
- $starToSparCfgArr = explode(",", $g->Hero_Star_SeparateToSpar);
- foreach ($arr_costUID as $huid) {
- if ($huid == "") {
- continue;
- }
- isEditor() and $strengthHero = new UserHeroModel();
- $strengthHero = $collectHeros->$huid;
- $index = $strengthHero->curStar - 1;
- if ($index >= 0 && $index < count($starToSparCfgArr)) {
- $spar += $starToSparCfgArr[$index];
- }
- unset($collectHeros->$huid);
- }
- # 发物品到玩家包裹
- $req->userInfo->game->spar += $spar; # 入账能量块
- # 回存数据
- UserProc::updateUserInfo($req);
- return Resp::ok(array('num' => $spar));
- }
- /**
- * 英雄好感度解锁
- * @param type $req
- */
- static function HeroOpenFavor($req) {
- $user = $req->userInfo->game; # user引用
- $huid = $req->paras[0]; # 英雄的UID
- $targetFavorId = $req->paras[1]; # 目标好感度 索引id
- # 1.检查是否存在要升级的英雄
- $collectHeros = $user->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
- return Resp::err(ErrCode::hero_no);
- }
- # 2.检查目标好感度的常量数据是否存在
- $favorCfg = GameConfig::heroextra_favor_getItem($targetFavorId);
- if (!$favorCfg) {
- return Resp::err(ErrCode::hero_favor_cost_const_no);
- }
- # 3.检查英雄是否已经解锁了目标好感度
- $strengthHero = $collectHeros->$huid;
- if (!$strengthHero->curMainFavor) {
- $strengthHero->curMainFavor = 'E';
- }
- if (!$strengthHero->favors) {
- $strengthHero->favors = ArrayInit();
- $strengthHero->favors[] = 'E';
- }
- if (CommUtil::isInArray($strengthHero->favors, $favorCfg->name)) {
- return Resp::err(ErrCode::hero_favor_targetfavor_para);
- }
- # 4.检查消耗道具是否充足
- $costSpar = $favorCfg->cost;
- $bDeal = false; # 成交
- if ($costSpar > 0) {
- if ($user->spar < $costSpar) {
- return Resp::err(ErrCode::notenough_spar);
- } else {
- $bDeal = UserGameModel::Consume_Spar($user, $costSpar);
- }
- } else {
- return Resp::err(ErrCode::paras_err);
- }
- # 6.进行消耗升星
- if ($bDeal) {
- if ($favorCfg->isMain) {
- $strengthHero->curMainFavor = $favorCfg->name;
- }
- $strengthHero->favors[] = $favorCfg->name;
- UserProc::updateUserInfo($req);
- $resp = Resp::ok($strengthHero);
- }
- return $resp;
- }
- /**
- * 英雄神血
- * @param Req $req
- */
- static function UpGodBloodHeroByPieces($req) {
- $resp = Resp::err(ErrCode::method_notimplement_err);
- $g = glc();
- $user = $req->userInfo->game; # user引用
- $huid = $req->paras[0]; # 英雄的UID
- $piecesId = $req->paras[1]; # 英雄碎片的ID
- $piecesNum = $req->paras[2];
- $moneyType = $req->paras[3]; # 升星消耗金钱的类型
- $moneyNum = $req->paras[4];
- # 1.检查是否存在要升级的英雄
- $collectHeros = $user->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
- return Resp::err(ErrCode::hero_no);
- }
- # 2.检查是否存在要升级的英雄的神血的血脉值 是否达到100%
- isEditor() and $strengthHero = new UserHeroModel();
- $strengthHero = $collectHeros->$huid;
- # 检查是否存在当前 神血的的消耗常量数据 以及血脉值 是否达到100%
- if (!CommUtil::isPropertyExists($strengthHero, "curBloodId")) {
- $strengthHero->curBloodId = 0;
- }
- $lvs = GameConfig::heroextra_godblood_getItem($strengthHero->curBloodId);
- if (!$lvs) {
- return Resp::err(ErrCode::hero_godblood_level_const_no);
- } else {
- if ($lvs->targetGodPercent >= 100) {
- return Resp::err(ErrCode::hero_godblood_maxlevel);
- }
- }
- # 3. 检查是否存在这个英雄的模板
- $heroModelId = $strengthHero->modelId;
- $heroCfg = GameConfig::hero_getItem($heroModelId);
- if (!$heroCfg) {
- return Resp::err(ErrCode::hero_const_no_err);
- }
- # 4 .检查碎片是否正确
- $requirePieceId = $piecesId;
- $requirePiecesNum = 0;
- $arr_costPieces = explode(";", $lvs->pieces);
- foreach ($arr_costPieces as $value) {
- $strArr = explode(",", $value);
- if (count($strArr) == 2) {
- $zhenxidu = $strArr[0];
- $num = $strArr[1];
- if ((int) $zhenxidu == $heroCfg->zhenxidu) {
- $requirePiecesNum = (int) $num;
- break;
- }
- }
- }
- $piecesCfg = GameConfig::segment_getItem($piecesId);
- if (!$piecesCfg) {
- return Resp::err(ErrCode::const_no_err);
- }
- $pos = strpos($piecesCfg->icon, strval($heroModelId));
- if ($pos === false) {
- return Resp::err(ErrCode::paras_err, $piecesCfg->icon . "?" . $heroModelId);
- }
- # 5.检查道具的数量是否充足
- $myPacketItems = $user->store->segement;
- # 检查道具数量是否充足
- $enoughPieces = false;
- if ($requirePieceId == $piecesId && $requirePiecesNum == $piecesNum) {
- #检查碎片
- if (!CommUtil::isPropertyExists($myPacketItems, $requirePieceId)) {
- $enoughPieces = false;
- } else {
- if ($myPacketItems->$requirePieceId < $requirePiecesNum) {
- $enoughPieces = false;
- } else {
- $enoughPieces = true;
- }
- }
- } else {
- return Resp::err(ErrCode ::paras_err, "error pieces para" . "req" . $requirePieceId . "_" . $requirePiecesNum . "/" . $piecesId . "_" . $piecesNum);
- }
- if ($enoughPieces === true) {
-
- } else {
- return Resp::err(ErrCode::hero_godblood_notengoughitem);
- }
- # 6.检查账户余额是否充足
- #检查消耗是否正确
- $enoughMoney = false;
- $requireMoneyType = "";
- $requireMoneyNum = 0;
- $arr_costMoney = explode(";", $lvs->cost);
- foreach ($arr_costMoney as $value) {
- $strArr = explode(",", $value);
- if (count($strArr) == 3) {
- $zhenxidu = $strArr[0];
- $type = $strArr[1];
- $num = $strArr[2];
- if ((int) $zhenxidu == $heroCfg->zhenxidu) {
- $requireMoneyType = $type;
- $requireMoneyNum = (int) $num;
- break;
- }
- }
- }
- echoline($requireMoneyNum + " " + $moneyNum + " " + $requireMoneyType + " " + $moneyType);
- if ($requireMoneyType == $moneyType && $requireMoneyNum == $moneyNum) {
- if ($requireMoneyType === "gold") {
- if ($user->gold >= $requireMoneyNum) {
- $enoughMoney = true;
- } else {
- return Resp::err(ErrCode::notenough_gold_msg);
- }
- } else if ($requireMoneyType === "cash") {
- if ($user->cash >= $requireMoneyNum) {
- $enoughMoney = true;
- } else {
- return Resp::err(ErrCode::notenough_cash_msg);
- }
- } else {
- return Resp::err(ErrCode ::paras_err, $moneyType);
- }
- } else {
- return Resp::err(ErrCode ::paras_err, "error money para");
- }
- $bDeal = false;
- if ($enoughMoney === true) {
- if ($requireMoneyType === "gold") {
- $bDeal = UserGameModel:: Consume_Gold($user, $requireMoneyNum);
- } else if ($requireMoneyType === "cash") {
- $bDeal = UserGameModel:: Consume_Cash($user, $requireMoneyNum);
- }
- }
- # 6.进行消耗升星
- if ($bDeal) {
- $strengthHero->curBloodId += 1;
- # # 消耗道具
- $myPacketItems->$requirePieceId -= $requirePiecesNum;
- if ($myPacketItems->$requirePieceId < 0) {
- $myPacketItems->$requirePieceId = 0;
- }
- $req->userInfo->game->store->segement = $myPacketItems;
- # 回写数据
- UserProc::updateUserInfo($req);
- $resp = Resp::ok($strengthHero);
- # 推送系统消息
- SystemProc::Hero_purification($req->zoneid, $user, $heroModelId);
- }
- ActiveProc::ChangeTaskCount($req);
- return $resp;
- }
- /**
- * 英雄消耗碎片道具来升星
- * @param type $req
- */
- static function HeroUpStarByPieces($req) {
- $resp = Resp::err(ErrCode::method_notimplement_err);
- $g = glc();
- $user = $req->userInfo->game; # user引用
- $huid = $req->paras[0]; # 英雄的UID
- $piecesId = $req->paras[1]; # 英雄碎片的ID
- $piecesNum = $req->paras[2];
- $diamondId = $req->paras[3]; # 升星石道具的ID
- $diamondNum = $req->paras[4];
- $moneyType = $req->paras[5]; # 升星消耗金钱的类型
- $moneyNum = $req->paras[6];
- # 1.检查是否存在要升级的英雄
- $collectHeros = $user->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
- return Resp::err(ErrCode::hero_no);
- }
- # 2.检查是否已经达到最大星级
- isEditor() and $strengthHero = new UserHeroModel();
- $strengthHero = $collectHeros->$huid;
- if ($strengthHero->curStar >= $g->Hero_Star_MaxStarLevel) {
- return Resp::err(ErrCode::hero_star_maxstarlevel);
- }
- # 检查是否存在当前星级的升星消耗常量数据
- $lvs = GameConfig::heroextra_star_getItem($strengthHero->curStar);
- if (!$lvs) {
- return Resp::err(ErrCode::hero_star_level_const_no_err);
- }
- # 3检查是否存在这个英雄的模板
- $heroModelId = $strengthHero->modelId;
- $heroCfg = GameConfig::hero_getItem($heroModelId);
- if (!$heroCfg) {
- return Resp::err(ErrCode::hero_const_no_err);
- }
- # 4.检查道具的数量是否充足以及消耗数量是否一致
- $requireDiamondId = $lvs->itemid;
- $requireDiamondNum = 0;
- $arr_costDiamond = explode(";", $lvs->itemNum);
- foreach ($arr_costDiamond as $value) {
- $strArr = explode(",", $value);
- if (count($strArr) == 2) {
- $zhenxidu = $strArr[0];
- $num = $strArr[1];
- if ((int) $zhenxidu == $heroCfg->zhenxidu) {
- $requireDiamondNum = (int) $num;
- break;
- }
- }
- }
- #检查碎片是否正确
- $requirePieceId = $piecesId;
- $requirePiecesNum = 0;
- $arr_costPieces = explode(";", $lvs->pieces);
- foreach ($arr_costPieces as $value) {
- $strArr = explode(",", $value);
- if (count($strArr) == 2) {
- $zhenxidu = $strArr[0];
- $num = $strArr[1];
- if ((int) $zhenxidu == $heroCfg->zhenxidu) {
- $requirePiecesNum = (int) $num;
- break;
- }
- }
- }
- $piecesCfg = GameConfig::item_getItem($piecesId);
- if (!$piecesCfg) {
- return Resp::err(ErrCode::const_no_err);
- }
- $pos = strpos($piecesCfg->icon, strval($heroModelId));
- if ($pos === false) {
- return Resp::err(ErrCode::paras_err, $piecesCfg->icon . "?" . $heroModelId);
- }
- # 4.检查道具的数量是否充足
- $myPacketItems = $user->store->items;
- #检查道具数量是否充足
- $enoughDiamond = false;
- $enoughPieces = false;
- if ($requirePieceId == $piecesId && $requirePiecesNum == $piecesNum) {
- #检查碎片
- if (!CommUtil::isPropertyExists($myPacketItems, $requirePieceId)) {
- $enoughPieces = false;
- } else {
- if ($myPacketItems->$requirePieceId < $requirePiecesNum) {
- $enoughPieces = false;
- } else {
- $enoughPieces = true;
- }
- }
- } else {
- return Resp::err(ErrCode ::paras_err, #
- "error pieces para" . "req" . $requirePieceId . "_" . $requirePiecesNum . "/" . $piecesId . "_" . $piecesNum);
- }
- if ($requireDiamondId == $diamondId && $requireDiamondNum == $diamondNum) {
- #检查升星石
- if (!CommUtil::isPropertyExists($myPacketItems, $requireDiamondId)) {
- $enoughDiamond = false;
- } else {
- if ($myPacketItems->$requireDiamondId < $requireDiamondNum) {
- $enoughDiamond = false;
- } else {
- $enoughDiamond = true;
- }
- }
- } else {
- return Resp::err(ErrCode ::paras_err, #
- "error diamond para" . "req" . $requireDiamondId . "_" . $requireDiamondNum . "/" . $diamondId . "_" . $diamondNum);
- }
- if ($enoughDiamond === true && $enoughPieces === true) {
-
- } else {
- return Resp::err(ErrCode::hero_star_notengoughitem);
- }
- # 5.检查账户余额是否充足
- #检查消耗是否正确
- $enoughMoney = false;
- $requireMoneyType = "";
- $requireMoneyNum = 0;
- $arr_costMoney = explode(";", $lvs->cost);
- foreach ($arr_costMoney as $value) {
- $strArr = explode(",", $value);
- if (count($strArr) == 3) {
- $zhenxidu = $strArr[0];
- $type = $strArr[1];
- $num = $strArr[2];
- if ((int) $zhenxidu == $heroCfg->zhenxidu) {
- $requireMoneyType = $type;
- $requireMoneyNum = (int) $num;
- break;
- }
- }
- }
- if ($requireMoneyType == $moneyType && $requireMoneyNum == $moneyNum) {
- if ($requireMoneyType === "gold") {
- if ($user->gold >= $requireMoneyNum) {
- $enoughMoney = true;
- } else {
- return Resp::err(ErrCode::notenough_gold_msg);
- }
- } else if ($requireMoneyType === "cash") {
- if ($user->cash >= $requireMoneyNum) {
- $enoughMoney = true;
- } else {
- return Resp::err(ErrCode::notenough_cash_msg);
- }
- } else {
- return Resp::err(ErrCode ::paras_err, $moneyType);
- }
- } else {
- return Resp::err(ErrCode ::paras_err, "error money para");
- }
- $bDeal = false;
- if ($enoughMoney === true) {
- if ($requireMoneyType === "gold") {
- $bDeal = UserGameModel:: Consume_Gold($user, $requireMoneyNum);
- } else if ($requireMoneyType === "cash") {
- $bDeal = UserGameModel:: Consume_Cash($user, $requireMoneyNum);
- }
- }
- # 6.进行消耗升星
- if ($bDeal) {
- $strengthHero->curStar += 1;
- # # 消耗道具
- $myPacketItems->$requireDiamondId -= $requireDiamondNum;
- if ($myPacketItems->$requireDiamondId < 0) {
- $myPacketItems->$requireDiamondId = 0;
- }
- $myPacketItems->$requirePieceId -= $requirePiecesNum;
- if ($myPacketItems->$requirePieceId < 0) {
- $myPacketItems->$requirePieceId = 0;
- }
- $req->userInfo->game->store->items = $myPacketItems;
- # 回写数据
- UserProc::updateUserInfo($req);
- $resp = Resp::ok($strengthHero);
- # 推送系统消息
- // SystemProc::insertHero_Star($req->zoneid, $req->uid, $user->name, $heroCfg->name, $strengthHero->curStar);
- }
- ActiveProc::ChangeTaskCount($req);
- return $resp;
- }
- /**
- * 英雄升星
- * @param Req $req
- */
- static function HeroUpStar($req) {
- $resp = Resp::err(ErrCode::method_notimplement_err);
- $g = glc();
- $user = $req->userInfo->game; # user引用
- $huid = $req->paras[0]; # 英雄的UID
- $costHeroUids = $req->paras[1]; # 消耗掉的英雄UID
- $costGold = $req->paras[2];
- # 1.检查是否存在要升级的英雄
- $collectHeros = $user->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
- return Resp::err(ErrCode::hero_no);
- }
- # 2.检查是否已经达到最大星级
- isEditor() and $strengthHero = new UserHeroModel();
- $strengthHero = $collectHeros->$huid;
- if ($strengthHero->curStar >= $g->Hero_Star_MaxStarLevel) {
- return Resp::err(ErrCode::hero_star_maxstarlevel);
- }
- # 检查是否存在当前星级的升星消耗常量数据
- $lvs = GameConfig::heroextra_star_getItem($strengthHero->curStar);
- if (!$lvs) {
- return Resp::err(ErrCode::hero_star_level_const_no_err);
- }
- # 3.检查消耗的英雄数量,以及玩家是否都存在这些英雄UID.
- $arr_costUID = explode(",", $costHeroUids);
- $checkCostHeroAllRight = true;
- if (count($arr_costUID) != $g->Hero_Star_MaxCostHeroCardNum) {
- $checkCostHeroAllRight = false;
- } else {
- foreach ($arr_costUID as $value) {
- if ($value == "" || !CommUtil::isPropertyExists($collectHeros, $value)) {
- $checkCostHeroAllRight = false;
- break;
- }
- }
- }
- if (!$checkCostHeroAllRight) {
- return Resp::err(ErrCode::hero_star_costhero);
- }
- # 获得升星英雄的模板数据,取得它的元素类型
- # 检查是否存在这个英雄的模板
- $heroModelId = $strengthHero->modelId;
- $heroCfg = GameConfig::hero_getItem($heroModelId);
- if (!$heroCfg) {
- return Resp::err(ErrCode::hero_const_no_err);
- }
- $queryCostGold = $lvs->costGold;
- $costItemNum = $lvs->costItemNum;
- # 4.检查道具的数量是否充足
- $myPacketItems = $user->store->items;
- $checkHasEnoughItem = true;
- $costItemId = "";
- $record = ObjectInit();
- $keyxxx = "Hero_Star_CostItem_" . $heroCfg->yuansu;
- if (!CommUtil::isPropertyExists($g, $keyxxx)) {
- return Resp::err(ErrCode::hero_star_noglobal_costitem);
- } else {
- $costItemId = $g->$keyxxx;
- }
- # 检查道具种类与消耗数量是否匹配
- $arr_costitemids = explode(",", $costItemId);
- $arr_costnums = explode(",", $costItemNum);
- if (count($arr_costitemids) != count($arr_costnums)) {
- return Resp::err(ErrCode::hero_star_conststr_itemnotmathnum);
- }
- $index = 0;
- foreach ($arr_costitemids as $requireiItemId) {
- $requireCount = 0;
- if ($index < count($arr_costnums)) {
- $requireCount = $arr_costnums[$index];
- }
- $index += 1;
- # --判断对应的item是否存在相应的常量
- # 检查是否存在当前星级的升星消耗常量数据
- $itemcfg = GameConfig::item_getItem($requireiItemId);
- if (!$itemcfg) {
- return Resp::err(ErrCode::const_no_err);
- } else {
- if (!CommUtil::isPropertyExists($record, $requireiItemId)) {
- $record->$requireiItemId = intval($requireCount);
- } else {
- $count = intval($record->$requireiItemId) + intval($requireCount);
- $record->$requireiItemId = $count;
- }
- }
- } foreach ($record as $key => $value) {
- if ($value > 0) {
- if (!CommUtil::isPropertyExists($myPacketItems, $key)) {
- $checkHasEnoughItem = false;
- break;
- } else {
- if ($myPacketItems->$key < $value) {
- $checkHasEnoughItem = false;
- break;
- }
- }
- }
- }
- if (!$checkHasEnoughItem) {
- return Resp::err(ErrCode::hero_star_notengoughitem);
- }
- # 5.检查金币是否充足
- $bDeal = false; # 成交
- if ($queryCostGold != $costGold) {
- return Resp::err(ErrCode::paras_err);
- } else {
- if ($costGold > 0) {
- if ($user->gold < $costGold) {
- return Resp::err(ErrCode::notenough_gold_msg);
- } else {
- $bDeal = UserGameModel:: Consume_Gold($user, $costGold);
- }
- } else if ($costGold == 0) {
- $bDeal = true;
- } else {
- return Resp::err(ErrCode::paras_err);
- }
- }
- # 6.进行消耗升星
- if ($bDeal) {
- $strengthHero->curStar += 1;
- # 消耗卡牌
- foreach ($arr_costUID as $value) {
- if ($value == "") {
- continue;
- }
- unset($collectHeros->$value);
- }
- # # 消耗道具
- foreach ($record as $key => $value) {
- $myPacketItems->$key -= $value;
- if ($myPacketItems->$key < 0) {
- $myPacketItems->$key = 0;
- }
- }
- $req->userInfo->game->store->items = $myPacketItems;
- # 回写数据
- UserProc::updateUserInfo($req);
- $resp = Resp::ok($strengthHero);
- # 推送系统消息
- // SystemProc::insertHero_Star($req->zoneid, $req->uid, $user->name, $heroCfg->name, $strengthHero->curStar);
- }
- ActiveProc::ChangeTaskCount($req);
- return $resp;
- }
- /**
- * 英雄 强化 突破升阶
- * @param Req $req
- */
- static function HeroStrength($req) {
- $g = glc();
- # $resp = ResponseVo::ErrResponse($req, ErrCode::msg_methodnotimplement);
- $user = $req->userInfo->game; # user引用
- $huid = $req->paras[0]; # 英雄的UID
- $costUID = $req->paras[1]; # 消耗掉的英雄UID
- $costGold = $req->paras[2];
- # 1.检查是否存在要升级的英雄
- $collectHeros = $user->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
- return Resp::err(ErrCode::hero_no);
- }
- isEditor() and $strengthHero = new UserHeroModel();
- $strengthHero = $collectHeros->$huid;
- if ($strengthHero->strengthLevel >= $g->Hero_Stength_MaxStrengthLevel) {
- return Resp::err(ErrCode::hero_strength_maxstrengthlevel);
- }
- # 1.检查是否存在这个升阶数据的模板
- $heroStrengthCostCfg = GameConfig::heroextra_dengjie_getItem($strengthHero->strengthLevel);
- if (!$heroStrengthCostCfg) {
- return Resp::err(ErrCode::hero_strength_cost_const_no);
- }
- # 2.检查要消耗的英雄是否存在
- if (!CommUtil::isPropertyExists($collectHeros, $costUID)) {
- return Resp::err(ErrCode::hero_no);
- }
- # 3.检查金币是否正确,以及玩家账户金币是否充足
- $queryCostGold = $heroStrengthCostCfg->cost;
- $bDeal = false; # 成交
- if ($queryCostGold != $costGold) {
- return Resp::err(ErrCode::paras_err);
- } else {
- if ($costGold > 0) {
- if ($user->gold < $costGold) {
- return Resp::err(ErrCode::notenough_gold_msg);
- } else {
- $bDeal = UserGameModel:: Consume_Gold($user, $costGold);
- }
- } else if ($costGold == 0) {
- $bDeal = true;
- } else {
- return Resp::err(ErrCode::paras_err);
- }
- }
- # 4.消耗金币和英雄
- if ($bDeal) {
- unset($collectHeros->$costUID);
- # 5.强化英雄进行成功升阶 //6.数据回存
- $strengthHero->strengthLevel += 1;
- UserProc::updateUserInfo($req);
- $resp = Resp::ok($strengthHero);
- SystemProc::insertHero_StageUp($req->zoneid, $req->uid, $user->name, #
- GameConfig::hero_getItem($strengthHero->modelId)->name, $strengthHero->strengthLevel);
- }
- ActiveProc::ChangeTaskCount($req);
- return $resp;
- }
- /**
- * 获得英雄(测试已经OK)
- * @param type $req
- */
- static function GetHero($req) {
- $heroModelId = $req->paras[0]; //英雄的模板ID
- //1.检查是否存在这个英雄的模板
- $heroCfg = GameConfig::hero_getItem($heroModelId);
- if (!$heroCfg) {
- return Resp::err(ErrCode::hero_const_no_err);
- }
- $hero = self::AddHeroTFromStore($req, $heroModelId);
- UserProc::updateUserInfo($req);
- # 4. 设置返回值
- $result = array('result' => "succeed",
- 'heros' => $hero);
- return Resp::ok($result);
- # return $resp;
- }
- /**
- * 尝试图鉴整合
- * @param CredisUtil $mem
- * @param HeroManualModel $manual
- * @param type $hero
- */
- static function tryNewManual($mem, &$manual, $hero) {
- $godpetId = $hero->modelId;
- $level = 0;
- self:: changeManual($manual, $godpetId, $level);
- }
- /**
- * 更改图鉴数据
- * @global int $AchievementIsManualExpAddedGlobal
- * @param type $manual
- * @param type $heroModelId
- * @param type $level
- */
- static function changeManual(&$manual, $heroModelId, $level) {
- if (!property_exists($manual, "godpetDic")) {
- $manual->godpetDic = ObjectInit();
- }
- $godpetDic = $manual->godpetDic;
- if (!CommUtil::isPropertyExists($godpetDic, $heroModelId)) {
- $godpetDic->$heroModelId = array(0);
- } else {
-
- }
- }
- /**
- * 获得一个英雄, 并且给他指定星级
- * @param Req $req
- * @param int $heromodelId 原型数据id
- * @param int $star 星级
- * @return UserHeroModel
- */
- static function AddHeroWithStar(&$req, $heromodelId, $star) {
- $user = $req->userInfo->game;
- if (!$user) {
- return null;
- }
- $heroCfg = GameConfig::hero_getItem($heromodelId); # 检查是否存在这个英雄的模板
- if (!$heroCfg) { # 这里能不能附加错误信息给外面
- return null;
- }
- # 先生成一个hero的UID
- $collectHeros = $user->heros->collectHeros;
- $uid = self::CreateNewGameHeroUID($collectHeros, $user->heros->recordMaxUID);
- $user->heros->recordMaxUID = $uid;
- $hero = self::getGameHeroModelInstance($heroCfg, $heromodelId, $uid);
- $hero->curStar = $star; # 设定star
- $collectHeros->$uid = $hero; # 回写
- $user->heros->collectHeros = $collectHeros; # 回写
- # 更新 图鉴
- if (!CommUtil::isPropertyExists($user, "heroManual")) {
- $user->heroManual = new HeroManualModel();
- $user->heroManual->initInstance();
- }
- $manual = $user->heroManual;
- self:: tryNewManual($req->mem, $manual, $hero);
- return $hero; # 返回
- }
- /**
- * 获得一个英雄
- * @param type $req
- * @param type $heromodelId
- * @return type
- */
- static function AddHeroTFromStore(&$req, $heromodelId) {
- $gamedata = $req->userInfo->game;
- if (!CommUtil::isPropertyExists($gamedata, "heroManual")) {
- $gamedata->heroManual = new HeroManualModel();
- $gamedata->heroManual->initInstance();
- }
- $manual = $gamedata->heroManual;
- //1.检查是否存在这个英雄的模板
- $heroCfg = GameConfig::hero_getItem($heromodelId);
- if (!$heroCfg) {
- return Resp::err(ErrCode::hero_const_no_err);
- }
- //2.存在的话,先生成一个UID
- $collectHeros = $gamedata->heros->collectHeros;
- $uid = self::CreateNewGameHeroUID($collectHeros, $gamedata->heros->recordMaxUID);
- $gamedata->heros->recordMaxUID = $uid;
- $hero = self::getGameHeroModelInstance($heroCfg, $heromodelId, $uid);
- $collectHeros->$uid = $hero;
- $gamedata->heros->collectHeros = $collectHeros;
- self:: tryNewManual($req->mem, $manual, $hero);
- return $hero;
- }
- /**
- * 根据一个英雄的模板id,来获得一个英雄的实例数据
- * @param HeroModel $heroCfg 模板数据
- * @param string $heroModelId 模板数据ID
- * @param string $uid 唯一ID
- * @return UserHeroModel
- */
- static function getGameHeroModelInstance($heroCfg, $heroModelId, $uid) {
- $hero = new UserHeroModel();
- ////取常量数据理的默认的等阶和星级
- $sour = $heroCfg; //GameConfig::hero_getItem($heroModelId);
- $hero->strengthLevel = $sour->dengjie;
- $hero->curStar = $sour->xingji;
- //查找mem中此英雄的模板数据
- $hero->modelId = $heroModelId;
- $hero->uid = $uid;
- $hero->xp = 0;
- $lvs = GameConfig::hero_levelexp_getItem($hero->level + 1);
- $hero->maxXp = $lvs->requiredExp;
- return $hero;
- }
- /**
- * 查找下一个玩家获得英雄的UID
- * @param type $req
- * @return int
- */
- static function CreateNewGameHeroUID($collectHeros, $oldMaxUID) {
- $maxID = 10000;
- if ($collectHeros == null) {
- $collectHeros = ObjectInit();
- }
- foreach ($collectHeros as $itemId => $hero) {
- if ($itemId > $maxID) {
- $maxID = $itemId;
- }
- }
- $max = $maxID;
- if ($oldMaxUID < $maxID) {
- $max = $maxID;
- } else {
- $max = $oldMaxUID;
- }
- return $max + 1;
- }
- /**
- * [6301] 英雄升级 - 消耗经验道具书,获得经验
- * @param type $req
- */
- static function HeroLevelUpCostItem($req) {
- $gcfg = glc();
- $user = $req->userInfo->game; # user引用
- $heroUID = $req->paras[0]; # 玩家英雄实例编号
- $costItemIds = $req->paras[1]; # 消耗的道具ID
- $costGold = $req->paras[2];
- //1.检查是否存在要升级的英雄
- $collectHeros = $user->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- if (!CommUtil::isPropertyExists($collectHeros, $heroUID)) {
- return Resp::err(ErrCode::hero_no);
- }
- isEditor() and $targetHero = new UserHeroModel;
- $targetHero = $collectHeros->$heroUID;
- //2.检查玩家等级是否达到当前等级上限
- //$strengthconst = GameConfig::heroextra_dengjie_getItem($targetHero->strengthLevel);
- $maxLevel = $gcfg->Hero_Upgrade_BasicMaxLevel; // $strengthconst->maxLevel;
- if ($targetHero->level >= $maxLevel) {
- return Resp::err(ErrCode::hero_upgrade_maxupgradelevel);
- }
- //3.检查消耗的道具是否是都存在的
- $arr_costUID = explode(",", $costItemIds);
- $isAllExist = true;
- $itemObj = ObjectInit();
- foreach ($arr_costUID as $value) {
- if ($value == "") {
- continue;
- }
- if (!CommUtil::isPropertyExists($itemObj, $value)) {
- $itemObj->$value = 1;
- } else {
- $itemObj->$value += 1;
- }
- }
- //以上是统计各种道具的消耗数量
- //下面是检查道具的数量,在背包中是否充足
- $myPacketItems = $user->store->items;
- foreach ($itemObj as $key => $value) {
- if ($value > 0) {
- if (!CommUtil::isPropertyExists($myPacketItems, $key)) {
- $isAllExist = false;
- break;
- } else {
- if ($myPacketItems->$key < $value) {
- $isAllExist = false;
- break;
- }
- }
- }
- }
- if (!$isAllExist) {
- return Resp::err(ErrCode::hero_upgrade_cost);
- }
- //4.计算消耗的道具一共给多少经验值以及 一共要消耗多少金币
- $totalEXP = 0;
- $realCostGold = 0;
- foreach ($arr_costUID as $value) {
- if ($value == "") {
- continue;
- }
- isEditor() and $costItemConst = new sm_hero_levelexp_costitem;
- $costItemConst = GameConfig::hero_levelexp_costitem_getItem($value);
- if (!$costItemConst) {
- return Resp::err(ErrCode::hero_upgrade_cost_const_no);
- } else {
- $totalEXP += $costItemConst->dogExp;
- $realCostGold += $costItemConst->costGold;
- }
- }
- //5.取升级消耗数据,提取消耗的金币数量,判断金币是否充足
- $bDeal = false; # 成交标志
- if ($costGold != $realCostGold) {
- return Resp::err(ErrCode ::paras_err, $errMsg);
- } else {
- if ($costGold > 0) {
- if ($user->gold < $costGold) {
- return Resp::err(ErrCode::notenough_gold_msg);
- } else {
- $bDeal = UserGameModel:: Consume_Gold($user, $costGold);
- }
- } else if ($costGold == 0) {
- $bDeal = true;
- } else {
- return Resp::err(ErrCode::paras_err);
- }
- }
- if ($bDeal) {
- self:: HeroAddEXP($heroUID, $totalEXP, $req); # 获得经验
- #消耗道具
- foreach ($itemObj as $key => $value) {
- $myPacketItems->$key -= $value;
- if ($myPacketItems->$key < 0) {
- $myPacketItems->$key = 0;
- }
- }
- $req->userInfo->game->store->items = $myPacketItems;
- UserProc::updateUserInfo($req);
- $resp = Resp::ok($targetHero);
- }
- ActiveProc::ChangeTaskCount($req);
- return $resp;
- }
- /**
- * [6301] 英雄升级 - 吞噬其他英雄的卡牌,获得经验
- * @param Req $req
- */
- static function HeroLevelUp($req) {
- $g = glc(); # 全局变量
- $user = $req->userInfo->game; # user引用
- $heroUID = $req->paras[0]; # 玩家英雄实例编号
- $costHeroUids = $req->paras[1]; # 消耗的玩家英雄实例编号
- $costGold = $req->paras[2];
- //1.检查是否存在要升级的英雄
- $collectHeros = $user->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- if (!CommUtil::isPropertyExists($collectHeros, $heroUID)) {
- return Resp::err(ErrCode::hero_no);
- }
- isEditor() and $targetHero = new UserHeroModel;
- $targetHero = $collectHeros->$heroUID;
- //2.检查玩家等级是否达到当前等级上限
- ////$maxLevel = $gcfg->Hero_Upgrade_BasicMaxLevel + 10 * $targetHero->strengthLevel;
- $strengthconst = GameConfig::heroextra_dengjie_getItem($targetHero->strengthLevel);
- $maxLevel = $strengthconst->maxLevel;
- if ($targetHero->level >= $maxLevel) {
- return Resp::err(ErrCode::hero_upgrade_maxupgradelevel);
- }
- //3.检查消耗的英雄是否是都存在的
- $arr_costUID = explode(",", $costHeroUids);
- $isAllExist = true;
- foreach ($arr_costUID as $value) {
- if ($value == "") {
- continue;
- }
- if (!CommUtil::isPropertyExists($collectHeros, $value)) {
- $isAllExist = false;
- break;
- }
- }
- if (!$isAllExist) {
- return Resp::err(ErrCode::hero_upgrade_cost);
- }
- //4.计算消耗的英雄一共给多少经验值
- $totalEXP = 0;
- $errMsg = "";
- foreach ($arr_costUID as $value) {
- if ($value == "") {
- continue;
- }
- isEditor() and $curHero = new UserHeroModel;
- $errMsg = $errMsg . " uid::" . $value;
- $curHero = $collectHeros->$value;
- $tempLv = $curHero->level;
- $tempLevelConst = GameConfig::hero_levelexp_getItem($tempLv);
- $totalEXP += (int) $tempLevelConst->dogExp;
- $errMsg = $errMsg . " add xp::" . $tempLevelConst->dogExp;
- // $totalEXP += (int) ( $curHero->xp * $gcfg->Hero_Upgrade_EXP_XiShu);
- // $errMsg = $errMsg . " xp::" . $curHero->xp;
- // $totalEXP += $gcfg->Hero_Upgrade_BasicEXP;
- // $errMsg = $errMsg . " basic::" . $gcfg->Hero_Upgrade_BasicEXP;
- $errMsg = $errMsg . " end.";
- }
- //然后算一算获得这么多经验值之后,最新的英雄等级是多少
- $realCostGold = $totalEXP * $g->Hero_Upgrade_ExpConverGold;
- $errMsg = $errMsg . " totalEXP:" . $totalEXP;
- //5.取升级消耗数据,提取消耗的金币数量,判断金币是否充足
- $bDeal = false; # 成交标志
- if ($costGold != $realCostGold) {
- return Resp::err(ErrCode ::paras_err, $errMsg);
- } else {
- if ($costGold > 0) {
- if ($user->gold < $costGold) {
- return Resp::err(ErrCode::notenough_gold_msg);
- } else {
- $bDeal = UserGameModel:: Consume_Gold($user, $costGold);
- }
- } else if ($costGold == 0) {
- $bDeal = true;
- } else {
- return Resp::err(ErrCode::paras_err);
- }
- }
- if ($bDeal) {
- self:: HeroAddEXP($heroUID, $totalEXP, $req); # 获得经验
- foreach ($arr_costUID as $value) {
- if ($value == "") {
- continue;
- }
- unset($collectHeros->$value); # 消耗卡牌
- }
- UserProc::updateUserInfo($req);
- $resp = Resp::ok($targetHero);
- }
- ActiveProc::ChangeTaskCount($req);
- return $resp;
- }
- /**
- * 一个英雄卡牌获得一点经验值
- * @param string $heroUID
- * @param int $totalEXP
- * @param Req $req
- */
- static function HeroAddEXP($heroUID, $totalEXP, $req) {
- $g = glc();
- $collectHeros = $req->userInfo->game->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- if (!CommUtil::isPropertyExists($collectHeros, $heroUID)) {
- return; # 要升级的英雄不存在
- }
- isEditor() and $targetHero = new UserHeroModel;
- $targetHero = $collectHeros->$heroUID;
- //$strengthconst = GameConfig::heroextra_dengjie_getItem($targetHero->strengthLevel);
- $maxLevel = $g->Hero_Upgrade_BasicMaxLevel; //$strengthconst->maxLevel;
- if ($targetHero->level >= $maxLevel) {
- return; # 已达顶级
- }
- $lvs = GameConfig::hero_levelexp_getItem($targetHero->level);
- $targetHero->xp += $totalEXP;
- CLog:: Assert("HeroProc", $targetHero->xp >= 0, #
- "[" . $req->uid . "] : HeroLevelUpgrade Exp is negative!");
- while ($targetHero->xp >= $targetHero->maxXp) {
- if ($targetHero->level < $maxLevel) { # 如果未到达最大等级
- $nowlv = $targetHero->level + 1;
- $nextlv = $nowlv + 1;
- $targetHero->level = $nowlv;
- $lvs = GameConfig::hero_levelexp_getItem($nextlv);
- if ($nowlv >= $maxLevel) {
- $targetHero->xp = $targetHero->maxXp;
- }
- $targetHero->maxXp = $lvs->requiredExp;
- } else { # 如果已到达最大等级则仅补齐缺失的经验即可
- $targetHero->xp = $targetHero->maxXp; # 经验不能超过最大值
- break;
- }
- }
- }
- /**
- * [6306] 英雄-更改英雄的锁定状态
- * (测试已经OK)
- * @param type $req
- */
- static function HeroChangelockstate($req) {
- $gamedata = $req->userInfo->game;
- $heroUID = $req->paras[0]; # 玩家英雄实例编号
- $lockstate = $req->paras[1]; # 玩家英雄锁定状态
- $collectHeros = $gamedata->heros->collectHeros;
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- if (!CommUtil::isPropertyExists($collectHeros, $heroUID)) {
- return Resp::err(ErrCode::hero_no);
- }
- isEditor() and $hero = new UserHeroModel;
- $hero = $collectHeros->$heroUID; # 1. 获取这个英雄的实例数据是
- $hero->isLocked = $lockstate; # 2. 修改英雄状态
- UserProc::updateUserInfo($req); # 3. 保存玩家数据
- return Resp::ok(ObjectInit()); # 4. 设置返回值
- }
- //
- // <editor-fold defaultstate="collapsed" desc="计算战队战斗力, for pvp back matchers, -wg 2017.07.13">
- /**
- * 计算队伍战斗力, 添加到战斗力隐藏榜单中, for pvp back matchers, -wg 2017.07.13
- * @param type $zoneid
- * @param type $uid
- * @param UserGameModel $user
- * @return type
- */
- static function CalcTeamFightPower($zoneid, $uid, $user) {
- $mem = gMem();
- $teamsetting = $user->heroTeamConfig; # 更新配置
- // var_dump($user);
- $heros = $user->heros;
- $teamCfg = JsonUtil::decode($teamsetting);
- $tid = $teamCfg->curUseTeamID;
- $team = $teamCfg->teamDic->$tid;
- $fp = 0; # 返回值
- if ($team) {
- foreach ($team->heros as $hid) {
- // isEditor() and $hero = new GameHeroModel();
- if ($hid) {
- $hero = $heros->collectHeros->$hid;
- if ($hero) {
- $fp += self::calcHeroFightPower($hero);
- }
- }
- }
- $mem->zadd(MemKey_GameRun::Game_FightPowerRank_zset($zoneid), array($uid => $fp));
- }
- return $fp;
- }
- /**
- * 计算hero战斗力, for pvp back matchers, -wg 2017.07.13
- * @param UserHeroModel $hero
- * @return int
- */
- static private function calcHeroFightPower($hero) {
- $arr = explode(';', glc()->Battle_PowerFactor);
- $factor = ArrayInit();
- foreach ($arr as $s) {
- $kv = explode(',', $s);
- $k = $kv[0];
- $v = $kv[1];
- $factor[$k] = $v;
- }
- // todo: 哈哈, 奇葩的命名方案, 多处使用的命名不一致, 坑!
- $a = (int) (self::calcHeroProperty($hero, 'hp') * $factor ["hp"] //
- + $hero->level * 10);
- return $a;
- }
- /**
- * 计算hero的属性,, for pvp back matchers, -wg 2017.07.13
- * @param UserHeroModel $hero
- * @param type $propertyname
- */
- private static function calcHeroProperty($hero, $propertyname) {
- $level = $hero->level;
- $modle = GameConfig::hero_getItem($hero->modelId);
- $extra = GameConfig::heroextra_level_getItem(1);
- return (int) ($modle->$propertyname * (1 + $extra->$propertyname));
- }
- // </editor-fold>
- //
- }
|