12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775 |
- <?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::HeroLevelUpCostExpItem($req);
- case CmdCode::cmd_hero_stageup: # 6304 英雄进阶 SABCD
- return HeroProc::HeroStageUp($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);
- }
- }
- /**
- * 6304 英雄 升阶(消耗碎片)
- * @param Req $req
- */
- static function HeroStageUp($req) {
- $g = glc();
- $user = $req->userInfo->game; # user引用
- $huid = $req->paras[0]; # 英雄的UID
- $nextGrade = $req->paras[1]; # 下一阶
- $collectHeros = $user->heros->collectHeros; # 角色容器
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- if (!CommUtil::isPropertyExists($collectHeros, $huid)) { # 1.检查是否存在要升级的英雄
- return Resp::err(ErrCode::hero_no);
- }
- isEditor() and $upHero = new UserHeroModel();
- $upHero = $collectHeros->$huid;
- if ($upHero->grade >= "S") { # 已经达到S级
- return Resp::err(ErrCode::hero_strength_maxstrengthlevel);
- }
- $heroUpgradeCostCfg = GameConfig::heroextra_level_getItem($upHero->typeId, $nextGrade);
- if (!$heroUpgradeCostCfg) { # 1.检查是否存在这个升阶数据的模板
- return Resp::err(ErrCode::hero_strength_cost_const_no);
- }
- $needSeg = $heroUpgradeCostCfg->segNum; # 2
- // if ($user->Consume_HeroSegment($user, # # 扣除碎片
- // $heroUpgradeCostCfg->segID, $heroUpgradeCostCfg->segNum)) {
- if (true) { # 扣除碎片直接成功
- $upHero->grade = $nextGrade; # 5.强化英雄进行成功升阶
- UserProc::updateUserInfo($req); //6.数据回存
- $resp = Resp::ok($upHero);
- SystemProc::insertHero_StageUp($req->zoneid, $req->uid, $user->name, #
- GameConfig::hero_getItem($upHero->typeId)->name, $upHero->grade);
- } else { # 碎片数量不足
- return Resp::err(ErrCode::hero_segment_not_enough);
- }
- return $resp;
- }
- /**
- * [6301] 英雄升级 - 消耗经验道具,获得经验(按照经验提升等级)
- * @param Req $req
- */
- static function HeroLevelUpCostExpItem($req) {
- $gcfg = glc();
- $user = $req->userInfo->game; # user引用
- $heroUID = $req->paras[0]; # 玩家英雄实例编号
- $costItemId = $req->paras[1]; # 消耗的道具ID
- $costNumber = $req->paras[2]; # 消耗的道具数量
- $collectHeros = $user->heros->collectHeros; // 1. 检查是否存在要升级的英雄
- if (!$collectHeros) {
- $collectHeros = ObjectInit();
- }
- if (!CommUtil::isPropertyExists($collectHeros, $heroUID)) {
- return Resp::err(ErrCode::hero_no);
- }
- isEditor() and $targetHero = new UserHeroModel;
- $targetHero = $collectHeros->$heroUID;
- $maxLevel = $gcfg->Hero_Upgrade_BasicMaxLevel;
- if ($targetHero->level >= $maxLevel) { // 2. 检查玩家等级是否达到当前等级上限
- return Resp::err(ErrCode::hero_upgrade_maxupgradelevel);
- }
- // 下面是检查道具的数量,在背包中是否充足
- $myPacketItems = $user->store->items; # 道具包裹
- if (!CommUtil::isPropertyExists($myPacketItems, $costItemId) || $myPacketItems->$costItemId < $costNumber) {
- return Resp::err(ErrCode::store_itemnotenough);
- }
- //4.计算消耗的道具一共给多少经验值以及 一共要消耗多少金币
- $totalEXP = 0;
- $costItemConst = GameConfig::item_stones_getItem($costItemId);
- if (!$costItemConst) {
- return Resp::err(ErrCode::err_const_no);
- } else {
- $totalEXP += $costItemConst->baseExp;
- }
- $heroConst = GameConfig::hero_getItem($targetHero->typeId); #
- if (null == $heroConst) {
- return \Resp::err(ErrCode::err_const_no, "英雄 模板数据");
- }
- if ($costItemConst->element != 0 # # 相同元素加成
- && $costItemConst->element == $heroConst->element) {
- $totalEXP += $costItemConst->extraExp;
- }
- self:: HeroAddEXP($heroUID, $totalEXP, $req); # 获得经验
- $myPacketItems->$costItemId -= $costNumber; # 消耗道具
- if ($myPacketItems->$costItemId < 0) {
- $myPacketItems->$costItemId = 0;
- }
- $req->userInfo->game->store->items = $myPacketItems;
- UserProc::updateUserInfo($req);
- return Resp::ok($targetHero);
- }
- // <editor-fold defaultstate="collapsed" desc="已过时代码">
- /**
- * 6323 解锁英雄
- * @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::err_const_no);
- }
- # 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); # 回写数据
- return Resp::ok(array('result' => "OK")); //返回OK
- } else {
- return Resp::err(ErrCode::hero_godblood_notengoughitem);
- }
- }
- /**
- * 购买英雄
- * @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->typeId == $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 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 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::err_method_notimplement);
- $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->typeId;
- $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::err_const_no);
- }
- $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::err_method_notimplement);
- $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->typeId;
- $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::err_const_no);
- }
- $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::err_method_notimplement);
- $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->typeId;
- $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::err_const_no);
- } 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;
- }
- // </editor-fold>
- /**
- * 6321 购买英雄 消耗碎片
- * @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->typeId == $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;
- }
- /**
- * [6315]保存队伍的战斗配置信息
- * @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
- * @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
- ));
- }
- /**
- * 获得英雄(测试已经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;
- }
- // <editor-fold defaultstate="collapsed" desc="辅助方法">
- /**
- * 尝试图鉴整合
- * @param CredisUtil $mem
- * @param HeroManualModel $manual
- * @param type $hero
- */
- static function tryNewManual($mem, &$manual, $hero) {
- $godpetId = $hero->typeId;
- $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->typeId = $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;
- }
- /**
- * 一个英雄卡牌获得一点经验值
- * @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;
- }
- }
- }
- // </editor-fold>
- // <editor-fold defaultstate="collapsed" desc="废弃代码">
- /**
- * [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;
- }
- // </editor-fold>
- /**
- * [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->typeId);
- $extra = GameConfig::heroextra_level_getItem(1);
- return (int) ($modle->$propertyname * (1 + $extra->$propertyname));
- }
- // </editor-fold>
- //
- }
|