HeroProc.php 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 英雄处理逻辑
  5. * @author gwang
  6. */
  7. class HeroProc {
  8. /**
  9. * 英雄处理逻辑分发
  10. * 所有的Proc中必须有这样一个方法
  11. */
  12. static function procMain() {
  13. switch (req()->cmd) {
  14. case CmdCode::cmd_hero_levelup: # [6301] 英雄升级
  15. return HeroProc::HeroLevelUpCostExpItem();
  16. case CmdCode::cmd_hero_tupo: # [6328] 英雄突破
  17. return HeroProc::tupo();
  18. // <editor-fold defaultstate="collapsed" desc="过时 接口">
  19. case CmdCode::cmd_hero_stageup: # [6304] 英雄进阶 SABCD
  20. return HeroProc::HeroStageUp();
  21. // case CmdCode::cmd_hero_upstar: # [6305] 英雄升星
  22. // return HeroProc::HeroUpStarByPieces();
  23. // case CmdCode::cmd_hero_changelockstate: # [6306] 英雄-修改锁定状态
  24. // return HeroProc::HeroChangelockstate();
  25. // case CmdCode::cmd_hero_buyCollectHeroLimtCount: # [6312] 扩展英雄数量上限
  26. // return HeroProc::BuyHeroMaxCountLimt();
  27. // <editor-fold defaultstate="collapsed" desc="---------------英雄评论----------------">
  28. // case CmdCode::cmd_hero_GetDiscuss: # [6316]拉取英雄评论
  29. // return HeroDiscussProc::GetDiscusses();
  30. // case CmdCode::cmd_hero_PostDiscuss: # [6317]对英雄发表评论
  31. // return HeroDiscussProc::Post();
  32. // case CmdCode::cmd_hero_PraiseDiscuss: # [6318]给某条评论点赞
  33. // return HeroDiscussProc::PriaseMsg();
  34. // case CmdCode::cmd_hero_DeleteDiscuss: # [6319]删除评论
  35. // return HeroDiscussProc::DeletePost();
  36. // case CmdCode::cmd_hero_scoreit: # [6320]给某个英雄评分
  37. // return HeroDiscussProc::Score();
  38. // </editor-fold>
  39. // <editor-fold defaultstate="collapsed" desc=" 英雄的解锁与购买 ">
  40. // case CmdCode::cmd_hero_buyHero: # [6321]购买英雄
  41. // return HeroProc::BuyHeroByCostPieces();
  42. // case CmdCode::cmd_hero_upGodBlood: # [6322] 神血升级
  43. // return HeroProc::UpGodBloodHeroByPieces();
  44. // case CmdCode::cmd_hero_unlockByPieces: # [6323] 解锁碎片
  45. // return HeroProc::UnLockHeroByPieces();
  46. // </editor-fold>
  47. // </editor-fold>
  48. # --------- 英雄技能 -----------
  49. case CmdCode::cmd_hero_upgradeSkillLevel: # [6314] 英雄的技能升级
  50. return HeroProc::UpgradeSkillLevel();
  51. case CmdCode::cmd_hero_unlockSkill: # [6324] 英雄技能 - 解锁技能
  52. return HeroProc::UnlockSkill();
  53. case CmdCode::cmd_hero_skillLevel_onekeyupgrade: # [6325] 英雄技能 - 一键升级
  54. return HeroProc::OnekeyUpgradeSkillLevel();
  55. case CmdCode::cmd_hero_saveHeroTeamConfig: # [6315] 保存玩家战队数据
  56. return HeroProc::SaveHeroTeamConfig();
  57. // <editor-fold defaultstate="collapsed" desc=" ------------- 英雄升级 cyzhao ">
  58. case CmdCode::cmd_hero_StrengthenStar: # [6326] 升星cmd_hero_YanlinUpLevel
  59. return HeroProc::StrengthenStar();
  60. case CmdCode::cmd_hero_YanlinUpLevel: # [6327] 言灵升级
  61. return HeroProc::YanlinUpLevel();
  62. case CmdCode::cmd_hero_YanLingReplace: # [6329] 言灵替换
  63. return HeroProc::YanLingReplace();
  64. // </editor-fold>
  65. default: # err: 未知的命令码
  66. return Resp::err(ErrCode::cmd_err);
  67. }
  68. }
  69. // <editor-fold defaultstate="collapsed" desc="技能升级与解锁">
  70. /**
  71. * [6324] 英雄技能解锁
  72. * @version 2020.1.13 至今未进行对接, 再次整理版
  73. * 2019.12.10 加班弄完第一版
  74. */
  75. static function UnlockSkill() {
  76. list($huid, $mainSkillId, $subSkillId) = req()->paras; # 提取参数: 英雄的UID, 主技能Id, 要升级的子技能ID
  77. $user = req()->userInfo->game; # user引用
  78. $cHeros = $user->heros->collectHeros;
  79. my_default_Obj($cHeros);
  80. my_Assert(CommUtil::isPropertyExists($cHeros, $huid), ErrCode::hero_no); # 1.检查是否存在要解锁的英雄
  81. # # 2.判断英雄的该技能能否升级....
  82. $targetHero = new Ins_UserHero($cHeros->$huid); # 直接类型识别
  83. $targteHeroSkills = $targetHero->subSkills; # 取出这个英雄的技能数据
  84. my_default_Arr($targteHeroSkills->$mainSkillId); # 保护子技能数组数据结构
  85. my_Assert(!CommUtil::isInArray($targteHeroSkills->$mainSkillId, $subSkillId), "子技能已解锁"); # 子技能已经解锁
  86. // if (!$targetHero->IsSkillUnlockAble($mainSkillId, $subSkillId)) { # 3.判断技能是否处于待解锁状态
  87. // return Resp::err(ErrCode::hero_upgradeSkill_maxLevel);
  88. // }
  89. $sm = GameConfig::subSkill_getItem($subSkillId); # 4.取出该技能升级消耗的常量数据
  90. my_Assert(null != $sm, ErrCode::err_const_no); # 找不到子技能配置数据
  91. // my_Assert(Data_UserGame::Consume_Gold($user->baseInfo, $sm->unlockCost), # # 5. 扣除金币消耗
  92. // ErrCode::notenough_gold_msg);
  93. my_Assert($user->base()->Consume_Gold($sm->unlockCost), # # 5. 扣除金币消耗
  94. ErrCode::notenough_gold_msg);
  95. array_push($targteHeroSkills->$mainSkillId, $subSkillId); # 添加技能
  96. $targetHero->subSkills = $targteHeroSkills;
  97. $cHeros->$huid = $targetHero; # 回存Hero对象
  98. UserProc::updateUserInfo(); # 回写数据
  99. TaskProc::OnHeroUnlocSkill($targetHero->typeId, $subSkillId);
  100. return Resp::ok($targetHero);
  101. }
  102. /**
  103. * [6325] 英雄技能一键升级
  104. */
  105. static function OnekeyUpgradeSkillLevel() {
  106. list($huid, $mainSkillId, $subSkillId, $targetSubSkillId, $costGold) = req()->paras; # 提取参数: 英雄的UID, 主技能ID, 要升级的子技能ID, 升级到的子技能ID, 升级要消耗的金币
  107. $user = req()->userInfo->game; # user引用#
  108. $collectHeros = $user->heros->collectHeros;
  109. my_default_Obj($collectHeros); # 防御变量为空
  110. my_Assert(CommUtil::isPropertyExists($collectHeros, $huid), ErrCode::hero_no); # 1.检查是否存在要升级的英雄
  111. # # 2.判断英雄的该技能能否升级....
  112. $targetHero = new Ins_UserHero($collectHeros->$huid); # 直接类型识别
  113. $targteHeroSkills = $targetHero->subSkills; # 取出这个英雄的技能数据
  114. my_default_Arr($targteHeroSkills->$mainSkillId); # 保护数据结构
  115. my_Assert(CommUtil::isInArray($targteHeroSkills->$mainSkillId, $subSkillId), "子技能id错误"); # 子技能id
  116. // if (!$targetHero->IsSkillUpdateAble($mainSkillId, $subSkillId)) { # 3.判断技能等级能否在继续升级了
  117. // return Resp::err(ErrCode::hero_upgradeSkill_maxLevel);
  118. // }
  119. // $sm = GameConfig::subSkill_getItem($subSkillId); # 4.取出该技能升级消耗的常量数据
  120. // if (null == $sm) {
  121. // return \Resp::err(ErrCode::err_const_no, '找不到子技能配置数据');
  122. // }
  123. my_Assert($user->base()->Consume_Gold($costGold), ErrCode::notenough_gold_msg); # 5. 扣除金币消耗
  124. unset($targteHeroSkills->$mainSkillId, $subSkillId); # 替换技能
  125. array_push($targteHeroSkills->$mainSkillId, $targetSubSkillId);
  126. $targetHero->subSkills = $targteHeroSkills;
  127. $collectHeros->$huid = $targetHero; # 更新Hero数据
  128. UserProc::updateUserInfo(); # 回写数据
  129. return Resp::ok($targetHero);
  130. }
  131. /**
  132. * [6314]英雄技能升级
  133. */
  134. static function UpgradeSkillLevel() {
  135. list($huid, $mainSkillId, $subSkillId) = req()->paras; # 提取参数: 英雄的UID, 主技能Id, 要升级的子技能Id
  136. $user = req()->userInfo->game; # user引用
  137. $collectHeros = $user->heros->collectHeros;
  138. my_default_Obj($collectHeros); # 防御变量为空
  139. my_Assert(CommUtil::isPropertyExists($collectHeros, $huid), ErrCode::hero_no); # 1.检查是否存在要升级的英雄
  140. $targetHero = new Ins_UserHero($collectHeros->$huid);
  141. $targteHeroSkills = $targetHero->subSkills; # 取出这个英雄的技能数据
  142. my_Assert(CommUtil::isPropertyExists($targteHeroSkills, $mainSkillId), "玩家数据结构有问题."); # 主技能Id.
  143. my_Assert(CommUtil::isInArray($targteHeroSkills->$mainSkillId, $subSkillId), "子技能id错误"); # 子技能id
  144. my_Assert($targetHero->IsSkillUpdateAble($mainSkillId, $subSkillId), ErrCode::hero_upgradeSkill_maxLevel); # 3.判断技能等级能否在继续升级了
  145. $sm = GameConfig::subSkill_getItem($subSkillId); # 4.取出该技能升级消耗的常量数据
  146. my_Assert(null != $sm, ErrCode::err_const_no); # 找不到子技能配置数据
  147. my_Assert($user->base()->Consume_Gold($sm->upgradeCost), ErrCode::notenough_gold_msg); # 5. 扣除金币消耗
  148. unset($targteHeroSkills->$mainSkillId, $subSkillId); # 替换技能
  149. array_push($targteHeroSkills->$mainSkillId, $sm->nextLevel_Id);
  150. $targetHero->subSkills = $targteHeroSkills;
  151. $collectHeros->$huid = $targetHero; # 更新hero数据
  152. UserProc::updateUserInfo(); # 回写数据
  153. return Resp::ok($targetHero);
  154. }
  155. // </editor-fold>
  156. //
  157. // <editor-fold defaultstate="collapsed" desc="英雄 强化">
  158. /**
  159. * 6304 英雄 升阶(消耗碎片)
  160. */
  161. static function HeroStageUp() {
  162. list($huid, $nextGrade) = req()->paras; # 提取参数: 英雄的UID,下一阶
  163. $user = req()->userInfo->game; # user引用
  164. $collectHeros = $user->heros->collectHeros; # 角色容器
  165. my_default_Obj($collectHeros); # 保证不为null
  166. my_Assert(CommUtil::isPropertyExists($collectHeros, $huid), ErrCode::hero_no); # 1.检查是否存在要升级的英雄
  167. $upHero = new Ins_UserHero($collectHeros->$huid); # 直接类型识别
  168. my_Assert($upHero->grade < "S", ErrCode::hero_strength_maxstrengthlevel); # 已经达到S级
  169. $heroUpgradeCostCfg = GameConfig::heroextra_level_getItem($upHero->typeId, $nextGrade);
  170. my_Assert($heroUpgradeCostCfg, ErrCode::hero_strength_cost_const_no); # 1.检查是否存在这个升阶数据的模板
  171. // my_Assert(Data_UserGame::Consume_HeroSegment($user, # # 扣除碎片
  172. // $heroUpgradeCostCfg->segID, $heroUpgradeCostCfg->segNum), ErrCode::hero_segment_not_enough);
  173. my_Assert($user->store()->Consume_HeroSegment($heroUpgradeCostCfg->segID, $heroUpgradeCostCfg->segNum), # 扣除碎片
  174. ErrCode::hero_segment_not_enough); # 碎片数量不足
  175. # 扣除碎片成功
  176. $upHero->grade = $nextGrade; # 5.强化英雄进行成功升阶
  177. $collectHeros->$huid = $upHero; # 更新Hero数据
  178. UserProc::updateUserInfo(); # 6.数据回存
  179. $resp = Resp::ok($upHero);
  180. SystemProc::insertHero_StageUp(req()->zoneid, req()->uid, $user->base()->name, # # 插入系统广播
  181. GameConfig::hero_getItem($upHero->typeId)->name, $upHero->grade);
  182. self::CalcUserFightPower(req()->zoneid, req()->uid, req()->userInfo->game); # 跟新战力统计
  183. TaskProc::OnHeroGradeUp($upHero->typeId, $upHero->grade);
  184. //StoreProc::addSegmentIntoStore($store, $segmentId, $num);
  185. // var_dump($user->task->taskListDaily);
  186. return $resp;
  187. }
  188. /**
  189. * [6301] 英雄升级 - 消耗经验道具,获得经验(按照经验提升等级)
  190. */
  191. static function HeroLevelUpCostExpItem() {
  192. list($huid, $costItemId, $costNumber) = req()->paras; # 提取参数: 玩家英雄实例编号, 消耗的道具ID, 消耗的道具数量
  193. $user = req()->userInfo->game; # user引用
  194. $collectHeros = $user->heros->collectHeros; # 1. 检查是否存在要升级的英雄
  195. my_default_Obj($collectHeros);
  196. my_Assert(is_int($costNumber) && $costNumber >= 1, ErrCode::paras_err); # 参数合法性判断
  197. my_Assert(CommUtil::isPropertyExists($collectHeros, $huid), ErrCode::hero_no); # 玩家拥有此英雄
  198. $targetHero = new Ins_UserHero($collectHeros->$huid); #
  199. //my_Assert($targetHero->HeroCanLevelUp(), "请提升指挥官等级."); # 2. 检查玩家等级是否可以继续升级, Ps. 全局限制 + 指挥官等级限制
  200. $myPacketItems = $user->store->items; # 检查道具的数量,在背包中是否充足
  201. my_Assert(CommUtil::isPropertyExists($myPacketItems, $costItemId), ErrCode::store_itemnotenough); #
  202. my_Assert($myPacketItems->$costItemId >= $costNumber, ErrCode::store_itemnotenough);
  203. $initLevel = $targetHero->level; # 初始等级
  204. $totalEXP = 0; # 4.计算消耗的道具一共给多少经验值以及 一共要消耗多少金币
  205. $costItemConst = GameConfig::item_stones_getItem($costItemId);
  206. my_Assert(null != $costItemConst, ErrCode::err_const_no);
  207. $totalGold = $costItemConst->costGold * $costNumber; #验证金币是否充足
  208. my_Assert($user->baseInfo->gold >= $totalGold, ErrCode::notenough_gold_msg);
  209. UserProc::CollectUserBaseParam(req()->cmd, 2, $user->baseInfo->gold, $totalGold, $user->baseInfo->gold-$totalGold,"");
  210. $user->baseInfo->gold -= $totalGold;
  211. $totalEXP += $costItemConst->baseExp;
  212. $heroConst = GameConfig::hero_getItem($targetHero->typeId); # 英雄模板数据
  213. my_Assert(null != $heroConst, ErrCode::err_const_no, "英雄 模板数据");
  214. // if ($costItemConst->element != 0 # # 相同元素加成
  215. // && $costItemConst->element == $heroConst->element) {
  216. // $totalEXP += $costItemConst->extraExp;
  217. // }
  218. $totalEXP *= $costNumber; # 消耗N个道具
  219. $targetHero = self:: HeroAddEXP($huid, $totalEXP); # 获得经验
  220. $myPacketItems->$costItemId -= $costNumber; # 消耗道具
  221. if ($myPacketItems->$costItemId < 0) {
  222. $myPacketItems->$costItemId = 0;
  223. }
  224. req()->userInfo->game->store->items = $myPacketItems; # 更新背包数据
  225. my_Assert($targetHero->xp >= 0, "英雄经验出错");
  226. UserProc::updateUserInfo(); # 回写玩家数据
  227. TaskProc::OnHeroImprove(); # 事件检测
  228. self::CalcUserFightPower(req()->zoneid, req()->uid, req()->userInfo->game); # 跟新战力统计
  229. $ret = array(
  230. 'hero' => $targetHero,
  231. 'store' => $user->store,
  232. 'gold' => $user->baseInfo->gold,
  233. );
  234. return Resp::ok($ret);
  235. }
  236. /**
  237. * 唤灵师突破
  238. */
  239. static function tupo() {
  240. list($uid) = req()->paras;
  241. $user = req()->userInfo->game;
  242. $collectHeros = $user->heros->collectHeros; # 1. 检查是否存在要升级的英雄
  243. my_default_Obj($collectHeros);
  244. my_Assert(StlUtil::dictHasProperty($collectHeros, $uid), ErrCode::hero_no); # 参数合法性判断
  245. $typeId = $collectHeros->$uid->typeId;
  246. $curStar = $collectHeros->$uid->curStar;
  247. my_Assert($curStar < 5, ErrCode::hero_yanling_canotTupo);
  248. $mo = GameConfig::heroextra_level_tupo_getItem($typeId, $curStar + 1);
  249. my_Assert($mo != null, ErrCode::err_const_no);
  250. my_Assert($collectHeros->$uid->level >= $mo->starlimitLv, ErrCode::hero_yanling_canotTupo);
  251. my_Assert($user->baseInfo->level >= $mo->userlvLimit, ErrCode::hero_yanling_canotTupo);
  252. my_Assert($user->baseInfo->gold >= $mo->gold, ErrCode::notenough_gold_msg);
  253. $segID = $mo->segID;
  254. my_Assert(StlUtil::dictHasProperty($user->store->items, $segID), ErrCode::store_itemnotenough);
  255. my_Assert($user->store->items->$segID >= $mo->segNum, ErrCode::store_itemnotenough);
  256. $costItemsList = explode(';', $mo->costItems);
  257. foreach ($costItemsList as $value) {
  258. $list = explode(',', $value);
  259. StoreProc::removeItemFromStore($user->store, $list[0], $list[1]);
  260. }
  261. $user->store->items->$segID -= $mo->segNum;
  262. UserProc::CollectUserBaseParam(req()->cmd, 2, $user->baseInfo->gold, $mo->gold, $user->baseInfo->gold - $mo->gold,"");
  263. $user->baseInfo->gold -= $mo->gold;
  264. $collectHeros->$uid->curStar += 1;
  265. NormalEventProc::OnHeroTuPo($uid, $collectHeros->$uid->curStar); # 广播英雄升级事件
  266. $user->heros->collectHeros = $collectHeros;
  267. req()->userInfo->game = $user;
  268. $targetHero = new Ins_UserHero($collectHeros->$uid);
  269. TaskProc::OnHeroGradeUp($targetHero->typeId, $targetHero->curStar); #唤灵师突破
  270. UserProc::updateUserInfo(); # 回写玩家数据
  271. $ret = array(
  272. 'hero' => $targetHero,
  273. 'store' => $user->store,
  274. 'gold' => req()->userInfo->game->baseInfo->gold,
  275. );
  276. return Resp::ok($ret);
  277. }
  278. /**
  279. * 武器替换
  280. * @return type
  281. */
  282. static function YanLingReplace() {
  283. list($heroId, $yanlingRank, $heroReplaceId, $yanlingReplaceRank) = req()->paras; # 参数 言灵uid(指定进阶的言灵实例id)
  284. $user = req()->userInfo->game;
  285. $collectHeros = $user->heros->collectHeros;
  286. my_Assert(StlUtil::dictHasProperty($collectHeros, $heroId) && StlUtil::dictHasProperty($collectHeros, $heroReplaceId), "找不到这个唤灵师");
  287. $yanling = $collectHeros->$heroId->yanling;
  288. $yanlingReplace = $collectHeros->$heroReplaceId->yanling;
  289. //my_Assert($yanling->$yanlingRank->itemuid != 0 && $yanlingReplace->$yanlingReplaceRank->itemuid != 0, "找不到这个言灵");
  290. $itemuid = $yanling->$yanlingRank->itemuid;
  291. $replaceItemuid = $yanlingReplace->$yanlingReplaceRank->itemuid;
  292. $yanling->$yanlingRank->itemuid = $replaceItemuid;
  293. $yanlingReplace->$yanlingReplaceRank->itemuid = $itemuid;
  294. if ($yanling->$yanlingRank->itemuid != 0) {
  295. $newItemuid = $yanling->$yanlingRank->itemuid;
  296. $user->store->yanling->$newItemuid->herouid = $heroId;
  297. }
  298. if ($yanlingReplace->$yanlingReplaceRank->itemuid != 0) {
  299. $newReplaceItemuid = $yanlingReplace->$yanlingReplaceRank->itemuid;
  300. $user->store->yanling->$newReplaceItemuid->herouid = $heroReplaceId;
  301. }
  302. $collectHeros->$heroId->yanling = $yanling;
  303. $collectHeros->$heroReplaceId->yanling = $yanlingReplace;
  304. $user->heros->collectHeros = $collectHeros;
  305. req()->userInfo->game = $user;
  306. UserProc::updateUserInfo(); # 回写玩家数据
  307. return Resp::ok(array(
  308. "store" => $user->store, # # 目前来看只涉及到items变化
  309. "hero" => $user->heros->collectHeros,
  310. "selfhero" => $user->heros->collectHeros->$heroId,
  311. ));
  312. }
  313. // </editor-fold>
  314. //
  315. // <editor-fold defaultstate="collapsed" desc="队伍配置">
  316. /**
  317. * [6315]保存队伍的战斗配置信息
  318. */
  319. static function SaveHeroTeamConfig() {
  320. $teamsetting = req()->paras[0]; # 配置信息json文件
  321. req()->userInfo->game->heroTeamConfig = $teamsetting; # 更新配置
  322. UserProc::updateUserInfo(); # 回写数据
  323. # # 添加到战斗力隐藏榜单中, for pvp back matchers, -wg 2017.07.13
  324. self::CalcTeamFightPower(req()->zoneid, req()->uid, req()->userInfo->game);
  325. return Resp::ok(array('result' => "succeed"));
  326. }
  327. // </editor-fold>
  328. //
  329. // <editor-fold defaultstate="collapsed" desc="已过时代码">
  330. /**
  331. * 6323 解锁英雄
  332. */
  333. static function UnLockHeroByPieces() {
  334. Err(ErrCode::err_method_obsoleted, "策划未设定解锁功能-2021.5.6");
  335. $user = req()->userInfo->game; # user引用
  336. $heroModelId = req()->paras[0];
  337. $piecesId = req()->paras[1]; # 英雄碎片的ID
  338. $piecesNum = req()->paras[2];
  339. my_default_Obj($user->heros->recordUnLockHeroDic); # 防御解锁列表未初始化,空对象
  340. $recordUnLockHeroDic = $user->heros->recordUnLockHeroDic; # 已解锁记录
  341. if (!CommUtil::isPropertyExists($recordUnLockHeroDic, $heroModelId)) { # 检查是不是已经解锁过了
  342. $recordUnLockHeroDic->$heroModelId = 0;
  343. }
  344. my_Assert(0 == $recordUnLockHeroDic->$heroModelId, ErrCode::hero_lockState); # 防御英雄已经解锁
  345. $heroCfg = GameConfig::hero_getItem($heroModelId);
  346. my_Assert(isset($heroCfg), ErrCode::hero_const_no_err); # 检查要解锁的英雄的常量配置是否存在
  347. $piecesCfg = GameConfig::segment_getItem($piecesId);
  348. my_Assert(isset($piecesCfg), ErrCode::err_const_no); # 检查需要消耗的碎片的常量配置是否存在
  349. $myPacketItems = $user->store->segement;
  350. $requirePiecesNum = $heroCfg->unlockConditionId;
  351. $enoughPieces = false; # 检查道具数量是否充足
  352. my_Assert($heroModelId == $piecesCfg->prototypeData && $requirePiecesNum == $piecesNum, ErrCode ::paras_err);
  353. if (!CommUtil::isPropertyExists($myPacketItems, $piecesId)) { # 检查碎片
  354. $enoughPieces = false;
  355. } else {
  356. if ($myPacketItems->$piecesId < $requirePiecesNum) { # 5.检查道具的数量是否充足
  357. $enoughPieces = false;
  358. } else {
  359. $enoughPieces = true;
  360. }
  361. }
  362. my_Assert($enoughPieces, ErrCode::hero_godblood_notengoughitem);
  363. $myPacketItems->$piecesId -= $requirePiecesNum;
  364. if ($myPacketItems->$piecesId < 0) { # 6.进行 # # 消耗道具
  365. $myPacketItems->$piecesId = 0;
  366. }
  367. $recordUnLockHeroDic->$heroModelId = 1;
  368. req()->userInfo->game->heros->recordUnLockHeroDic = $recordUnLockHeroDic;
  369. req()->userInfo->game->store->segement = $myPacketItems;
  370. UserProc::updateUserInfo(); # 回写数据
  371. return Resp::ok(array('result' => "OK")); # 返回OK
  372. }
  373. /**
  374. * [6322] 英雄神血
  375. */
  376. static function UpGodBloodHeroByPieces() {
  377. Err(ErrCode::err_method_obsoleted, "策划未设定神血功能-2021.5.6");
  378. }
  379. /**
  380. * 英雄消耗碎片道具来升星
  381. * @param req $req
  382. */
  383. static function HeroUpStarByPieces() {
  384. Err(ErrCode::err_method_obsoleted, "策划未设定碎片升级功能-2021.5.6");
  385. }
  386. /**
  387. * 英雄升星
  388. * @param Req $req
  389. */
  390. static function HeroUpStar() {
  391. Err(ErrCode::err_method_obsoleted, "策划未设定升星功能-2021.5.6");
  392. }
  393. // </editor-fold>
  394. /**
  395. * 6321 购买英雄 消耗碎片
  396. */
  397. static function BuyHeroByCostPieces() {
  398. Err(ErrCode::err_method_obsoleted, "策划未设定碎片功能-2021.5.6");
  399. list($heroModelId, $costType, $costMoneyNum, $piecesId, $piecesNum) = req()->paras; # 提取参数
  400. $user = req()->userInfo->game; # user引用
  401. $collectHeros = $user->heros->collectHeros;
  402. my_default_Obj($collectHeros);
  403. foreach ($collectHeros as $key => $value) { # 检查玩家是否已经拥有此类英雄
  404. my_Assert($value->typeId != $heroModelId, ErrCode::hero_existSameHero_err);
  405. }
  406. $heroCfg = GameConfig::hero_getItem($heroModelId); # 英雄模板数据
  407. my_Assert(null != $heroCfg, ErrCode::hero_const_no_err);
  408. my_Assert($heroCfg->isCanBuy != 0, ErrCode::paras_err); # 是否可以直接购买
  409. $piecesCfg = GameConfig::segment_getItem($piecesId); # 检查需要消耗的碎片的常量配置是否存在
  410. my_Assert(null != $piecesCfg, ErrCode::err_store_itemnoconst);
  411. $myPacketItems = $user->store->items;
  412. $requirePiecesNum = $piecesCfg->mergePrototypeNeedNum;
  413. my_Assert($heroModelId == $piecesCfg->prototypeData && $requirePiecesNum == $piecesNum, ErrCode::paras_err);
  414. my_Assert(CommUtil::isPropertyExists($myPacketItems, $piecesId), ErrCode::hero_godblood_notengoughitem);
  415. my_Assert($myPacketItems->$piecesId > $requirePiecesNum, ErrCode::hero_godblood_notengoughitem); # 检查碎片道具数量是否充足
  416. switch ($costType) {
  417. case "cash":
  418. $realPrice = $heroCfg->cashPrice;
  419. my_Assert($realPrice == $costMoneyNum, ErrCode::paras_err);
  420. my_Assert($costMoneyNum >= 0, ErrCode::paras_err);
  421. my_Assert($user->base()->Consume_Cash($costMoneyNum), ErrCode::err_msg_cashnotenough);
  422. break;
  423. case "gold":
  424. $realPrice = $heroCfg->goldPrice;
  425. my_Assert($realPrice == $costMoneyNum, ErrCode::paras_err);
  426. my_Assert($costMoneyNum >= 0, ErrCode::paras_err);
  427. my_Assert($user->base()->Consume_Gold($costMoneyNum), ErrCode::err_msg_goldnotenough);
  428. break;
  429. default :
  430. Err(ErrCode::paras_err, "参数错误: [costType] " . $costType);
  431. }
  432. # 4.消耗来获得英雄
  433. $myPacketItems->$piecesId -= $requirePiecesNum; # 消耗道具
  434. req()->userInfo->game->store->items = $myPacketItems; # 回存背包
  435. UserProc::updateUserInfo(); # 回写数据
  436. $resp = HeroProc::GetHero();
  437. SystemProc::GetHero(req()->zoneid, $user->base(), $heroModelId); # 插入系统广播消息
  438. return $resp;
  439. }
  440. /**
  441. * 购买玩家可以收集的英雄的数量上限
  442. * @return type
  443. */
  444. static function BuyHeroMaxCountLimt() {
  445. list($buyNum, $costCash) = req()->paras; # 提取参数: 数量, 花费钻石
  446. $g = glc();
  447. $user = req()->userInfo->game; # user引用
  448. if (!CommUtil::isPropertyExists($user->heros, "maxCollectCount")) {
  449. $user->heros->maxCollectCount = $g->Game_CollectHero_BasicMaxCount;
  450. }
  451. $index = ceil(($user->heros->maxCollectCount - $g->Game_CollectHero_BasicMaxCount) #
  452. / $g->Game_CollectHero_OneBuyLimtNum);
  453. $arr = explode(",", $g->Game_CollectHero_BasicMaxPrice);
  454. my_Assert($index < count($arr), "已达上限");
  455. $realCost = $arr[$index];
  456. my_Assert($realCost == $costCash, ErrCode::paras_err); # 参数错误
  457. my_Assert($costCash >= 0, ErrCode::paras_err);
  458. my_Assert($user->base()->Consume_Cash($costCash), ErrCode::err_msg_goldnotenough); # 扣除宝石
  459. $user->heros->maxCollectCount += $buyNum; # 修改上限
  460. UserProc::updateUserInfo();
  461. return Resp::ok(array(
  462. 'maxCollectCount' => $user->heros->maxCollectCount
  463. ));
  464. }
  465. /**
  466. * 获得英雄(测试已经OK)
  467. */
  468. static function GetHero() {
  469. $heroModelId = req()->paras[0]; # 英雄的模板ID
  470. $heroCfg = GameConfig::hero_getItem($heroModelId); # 1.检查是否存在这个英雄的模板
  471. my_Assert(null != $heroCfg, ErrCode::hero_const_no_err);
  472. $hero = self::AddHeroTFromStore($heroModelId); # 创建英雄
  473. UserProc::updateUserInfo();
  474. $result = array('result' => "succeed", 'heros' => $hero); # 4. 设置返回值
  475. return Resp::ok($result);
  476. }
  477. // <editor-fold defaultstate="collapsed" desc="辅助方法">
  478. /**
  479. * 获得一个英雄, 并且给他指定星级
  480. * @param int $heromodelId 原型数据id
  481. * @param int $star 星级
  482. * @return Ins_UserHero
  483. */
  484. static function AddHeroWithStar($heromodelId, $star) {
  485. my_Assert(null != ctx(), ErrCode::err_innerfault);
  486. $collectHeros = ctx()->heros()->collectHeros;
  487. $uid = self::CreateNewGameHeroUID($collectHeros, ctx()->heros()->recordMaxUID); # 先生成一个hero的UID
  488. ctx()->heros()->recordMaxUID = $uid;
  489. $hero = self::getGameHeroModelInstance($heromodelId, $uid);
  490. if ($star > 0) {
  491. $hero->curStar = $star; # 设定star
  492. }
  493. $collectHeros->$uid = $hero; # 回写
  494. ctx()->heros()->collectHeros = $collectHeros; # 回写
  495. return $hero; # 返回
  496. }
  497. /**
  498. * 获得一个英雄(实例)
  499. * @param req $req
  500. * @param int $heromodelId
  501. * @return type
  502. */
  503. static function AddHeroTFromStore($heromodelId) {
  504. $user = ctx(); # 玩家数据
  505. $collectHeros = ctx()->heros()->collectHeros; #
  506. my_default_Obj($collectHeros);
  507. $uid = self::CreateNewGameHeroUID($collectHeros, ctx()->heros()->recordMaxUID); # 先生成一个UID
  508. $user->heros->recordMaxUID = $uid; # 更新最大编号记录
  509. $hero = self::getGameHeroModelInstance($heromodelId, $uid); # 3.创建英雄实例
  510. $collectHeros->$uid = $hero;
  511. ctx()->heros()->collectHeros = $collectHeros;
  512. return $hero;
  513. }
  514. /**
  515. * 根据一个英雄的模板id,来获得一个英雄的实例数据
  516. * @param string $heroModelId 模板数据ID
  517. * @param string $uid 唯一ID
  518. * @return Ins_UserHero
  519. */
  520. static function getGameHeroModelInstance($heroModelId, $uid) {
  521. $heroCfg = GameConfig::hero_getItem($heroModelId);
  522. my_Assert(null != $heroCfg, ErrCode::err_const_no); # 检查是否存在这个英雄的模板
  523. $hero = new Ins_UserHero();
  524. // $hero->strengthLevel = $heroCfg->dengjie;
  525. $hero->curStar = $heroCfg->xingji;
  526. $hero->typeId = $heroCfg->heroId;
  527. $hero->uid = $uid;
  528. $hero->xp = 0;
  529. $lvs = GameConfig::hero_levelexp_getItem($hero->level + 1);
  530. $hero->maxXp = $lvs->requiredExp;
  531. // 取可用武器中第一个初始化 -- 策划要求初始英雄要带有武器 -- 王刚 2020年1月
  532. $wp = null;
  533. $arr = (array) GameConfig::item_weapon();
  534. uksort($arr, function ($a, $b) {
  535. return intval($a) < intval($b);
  536. }); // todo: 排序不正常
  537. foreach ($arr as $id => $mo) {
  538. // isEditor() and $mo = new \sm_item_weapon();
  539. $heroList = explode(',', $mo->hero_id);
  540. foreach ($heroList as $hero_id) {
  541. if ($hero_id == $hero->typeId) {
  542. $wp = $mo;
  543. break;
  544. }
  545. }
  546. // if ($mo->hero_id == $hero->typeId) {
  547. // $wp = $mo;
  548. // break;
  549. // }
  550. }
  551. if (null != $wp) {
  552. $wuid = StoreProc::PutEquipInStore($wp->typeId);
  553. req()->userInfo->game->store->equipment->$wuid->herouid = $uid;
  554. $hero->equip->weapon = array("itemuid" => $wuid);
  555. }
  556. return $hero;
  557. }
  558. /**
  559. * 查找下一个玩家获得英雄的UID
  560. * @param type $req
  561. * @return int
  562. */
  563. static function CreateNewGameHeroUID($collectHeros, $oldMaxUID) {
  564. $maxID = 10000;
  565. my_default_Obj($collectHeros);
  566. foreach ($collectHeros as $itemId => $hero) {
  567. if ($itemId > $maxID) {
  568. $maxID = $itemId;
  569. }
  570. }
  571. $max = max($maxID, $oldMaxUID);
  572. return $max + 1;
  573. }
  574. /**
  575. * 英雄卡牌增加经验值
  576. * @param string $heroUID
  577. * @param int $totalEXP
  578. */
  579. static function HeroAddEXP($heroUID, $totalEXP) {
  580. $req = req();
  581. $collectHeros = $req->userInfo->game->heros->collectHeros;
  582. my_default_Obj($collectHeros);
  583. my_Assert(CommUtil::isPropertyExists($collectHeros, $heroUID), ErrCode::hero_no); # 要升级的英雄不存在
  584. $targetHero = new Ins_UserHero($collectHeros->$heroUID); # 英雄对象
  585. // $playerLimit = GameConfig::playerlevel_getItem(ctx()->base()->level)->hero_max_level;
  586. // $maxLevel = min(glc()->Hero_Upgrade_BasicMaxLevel, $playerLimit); # 最大等级= max(英雄最高等级上限,玩家等级限制的上限)
  587. // if ($targetHero->level >= $maxLevel) {
  588. // return; # 已达顶级
  589. // }
  590. //$lvs = GameConfig::hero_levelexp_getItem($targetHero->level + 1);
  591. //var_dump("totototoxxxx---".$targetHero->xp);
  592. $targetHero->xp += $totalEXP;
  593. my_Assert($targetHero->xp >= 0, "[" . $req->uid . "] : HeroLevelUpgrade Exp is negative!");
  594. $initLevel = $targetHero->level;
  595. $curLv = 0;
  596. $heroLvDic = GameConfig::hero_levelexp();
  597. $f = (array) $heroLvDic;
  598. ksort($f);
  599. //var_dump($f);
  600. foreach ($f as $lv => $mo) {
  601. if ($targetHero->xp < $mo->requiredExp) {
  602. $curLv = $lv - 1;
  603. break;
  604. }
  605. if ($lv >= glc()->Hero_Upgrade_BasicMaxLevel) {
  606. $curLv = glc()->Hero_Upgrade_BasicMaxLevel;
  607. break;
  608. }
  609. }
  610. $targetHero->level = $curLv;
  611. $curStar = $targetHero->curStar; #当前星级
  612. if ($curStar < 5) {
  613. $starlimitLv = GameConfig::heroextra_level_tupo_getItem($targetHero->typeId, $curStar + 1)->starlimitLv;
  614. //var_dump("star--------".$starlimitLv);
  615. if ($starlimitLv < $curLv) {
  616. $targetHero->level = $starlimitLv;
  617. //var_dump("newlevelssttttt--------".GameConfig::hero_levelexp_getItem($starlimitLv)->requiredExp);
  618. $targetHero->xp = GameConfig::hero_levelexp_getItem($starlimitLv)->requiredExp;
  619. }
  620. }
  621. // while ($targetHero->xp >= $lvs->needExp) {
  622. // if ($targetHero->level < $maxLevel) { # 如果未到达最大等级
  623. // $targetHero->level += 1;
  624. // if ($targetHero->level >= $maxLevel) {
  625. // $targetHero->xp = $lvs->needExp;
  626. // } else {
  627. // $targetHero->xp -= $lvs->needExp;
  628. // }
  629. // $lvs = GameConfig::hero_levelexp_getItem($targetHero->level + 1);
  630. // } else { # 如果已到达最大等级则仅补齐缺失的经验即可
  631. // $targetHero->xp = $targetHero->maxXp; # 经验不能超过最大值
  632. // break;
  633. // }
  634. // } // end while
  635. my_Assert($targetHero->xp >= 0, "[" . $req->uid . "] : HeroLevelUpgrade Exp is negative!");
  636. $collectHeros->$heroUID = $targetHero; # 更新英雄的数据
  637. if ($targetHero->level != $initLevel) {
  638. NormalEventProc::OnHeroLvlUp($targetHero->uid, $initLevel); # 广播英雄升级事件
  639. StatisticsProc::TargetStatistics(Enum_TargetStatistics::HuanLingShiLevel_UserNum, $targetHero->typeId,$targetHero->level,$initLevel);
  640. }
  641. TaskProc::OnHeroLevelUp($targetHero->typeId, $targetHero->level);
  642. return $targetHero; # 将英雄对象返回
  643. }
  644. // </editor-fold>
  645. /**
  646. * [6306] 英雄-更改英雄的锁定状态
  647. * (测试已经OK)
  648. */
  649. static function HeroChangelockstate() {
  650. $gamedata = req()->userInfo->game;
  651. $heroUID = req()->paras[0]; # 玩家英雄实例编号
  652. $lockstate = req()->paras[1]; # 玩家英雄锁定状态
  653. $collectHeros = $gamedata->heros->collectHeros;
  654. my_default_Obj($collectHeros); # 默认值
  655. my_Assert(CommUtil::isPropertyExists($collectHeros, $heroUID), ErrCode::hero_no);
  656. // isEditor() and $hero = new UserHeroModel;
  657. $hero = $collectHeros->$heroUID; # 1. 获取这个英雄的实例数据是
  658. $hero->isLocked = $lockstate; # 2. 修改英雄状态
  659. UserProc::updateUserInfo(); # 3. 保存玩家数据
  660. return Resp::ok(ObjectInit()); # 4. 设置返回值
  661. }
  662. /** 6326
  663. * 言灵升星--改成突破【2021-6-8】 2021.4(cyzhao)
  664. * @return resp
  665. */
  666. static function StrengthenStar_old() {
  667. // list($yanlingUid, $uidList) = req()->paras;
  668. // $store = req()->userInfo->game->store;
  669. // my_Assert(StlUtil::dictHasProperty($store->yanling, $yanlingUid), ErrCode::hero_yanling_notfound);
  670. // my_Assert(!in_array($yanlingUid, $uidList), ErrCode::hero_yanling_repeat);
  671. // my_Assert($store->yanling->$yanlingUid->starLv < 5, ErrCode::hero_yanling_repeat);
  672. //
  673. // $tag = true;
  674. // foreach ($uidList as $costUid) {
  675. // if (StlUtil::dictHasProperty($store->yanling, $costUid)) { # 校验是否是同类型
  676. // $confDic = GameConfig::item_yanling_getItem($store->yanling->$costUid->typeId);
  677. // my_Assert(null != $confDic, ErrCode::hero_const_no_err);
  678. // if ($confDic->type != GameConfig::item_yanling_getItem($store->yanling->$yanlingUid->typeId)->type) {
  679. // $tag = false;
  680. // break;
  681. // }
  682. //
  683. // if ($store->yanling->$costUid->herouid != 0) {
  684. // $tag = false;
  685. // break;
  686. // }
  687. // } else {
  688. // $tag = false;
  689. // break;
  690. // }
  691. // }
  692. //
  693. // my_Assert($tag, ErrCode::hero_yanling_errorYanling);
  694. // $exp = 0;
  695. // foreach ($uidList as $costuid) {
  696. // $confDic = GameConfig::item_yanling_getItem($store->yanling->$costuid->typeId);
  697. // my_Assert(null != $confDic, ErrCode::hero_const_no_err);
  698. // $exp += $confDic->addStarExp;
  699. // StlUtil::dictRemove($store->yanling, $costuid);
  700. // }
  701. //
  702. // $store->yanling->$yanlingUid->curStarExp += $exp;
  703. // $dic = GameConfig::item_yanling_getItem($store->yanling->$yanlingUid->typeId);
  704. //
  705. // if ($store->yanling->$yanlingUid->curStarExp >= $dic->maxStarExp) {
  706. // $store->yanling->$yanlingUid->curStarExp = 0;
  707. // $store->yanling->$yanlingUid->starLv += 1;
  708. // $store->yanling->$yanlingUid->typeId = $dic->nextId;
  709. // }
  710. //
  711. // req()->userInfo->game->store = $store;
  712. // UserProc::updateUserInfo();
  713. // return Resp::ok(array('store' => req()->userInfo->game->store,));
  714. }
  715. /**
  716. * 新的突破
  717. * @return type
  718. */
  719. static function StrengthenStar() {
  720. list($uid) = req()->paras; # 参数 言灵uid(指定进阶的言灵实例id)
  721. $user = req()->userInfo->game;
  722. $yanling = $user->store->yanling;
  723. my_Assert(CommUtil::isPropertyExists($yanling, $uid), ErrCode::store_weapon_err); # 玩家拥有此英雄
  724. $typeId = $yanling->$uid->typeId;
  725. $curStar = $yanling->$uid->starLv;
  726. my_Assert($curStar < 5, ErrCode::hero_yanling_canotTupo);
  727. $mo = GameConfig::yanlingextra_level_getItem($typeId, $curStar + 1);
  728. my_Assert($mo != null, ErrCode::err_const_no);
  729. my_Assert($yanling->$uid->level >= $mo->starlimitLv, ErrCode::hero_yanling_canotTupo);
  730. my_Assert($user->baseInfo->level >= $mo->userlvLimit, ErrCode::hero_yanling_canotTupo);
  731. my_Assert($user->baseInfo->gold >= $mo->gold, ErrCode::notenough_gold_msg);
  732. $costItemsList = explode(';', $mo->costItems);
  733. foreach ($costItemsList as $value) {
  734. $list = explode(',', $value);
  735. StoreProc::removeItemFromStore($user->store, $list[0], $list[1]);
  736. }
  737. UserProc::CollectUserBaseParam(req()->cmd,2, $user->baseInfo->gold, $mo->gold, $user->baseInfo->gold - $mo->gold,"");
  738. $user->baseInfo->gold -= $mo->gold;
  739. $yanling->$uid->starLv += 1;
  740. NormalEventProc::OnYanLingLvTuPo($uid, $yanling->$uid->starLv); # 广播英雄升级事件
  741. TaskProc::OnYanlingStarUp($yanling->$uid->starLv); # 言灵突破 2021.7.30
  742. $user->store->yanling = $yanling;
  743. req()->userInfo->game = $user;
  744. UserProc::updateUserInfo(); # 回写玩家数据
  745. return Resp::ok(array(
  746. "store" => $user->store, # # 目前来看只涉及到items变化
  747. 'gold' => $user->baseInfo->gold,
  748. ));
  749. }
  750. /**
  751. * 言灵升级
  752. * @return type
  753. */
  754. static function YanlinUpLevel() {
  755. list($uid, $yanlingList, $items) = req()->paras; # 参数 言灵uid(指定进阶的言灵实例id)
  756. $user = req()->userInfo->game;
  757. $yanling = $user->store->yanling;
  758. my_Assert(CommUtil::isPropertyExists($yanling, $uid), ErrCode::store_weapon_err); # 玩家拥有此英雄
  759. $myPacketItems = $user->store->items;
  760. //消耗材料道具
  761. $total = 0;
  762. $totalGold = 0;
  763. foreach ($items as $costItemId => $costNumber) {
  764. my_Assert(CommUtil::isPropertyExists($myPacketItems, $costItemId), ErrCode::store_itemnotenough); #
  765. my_Assert($myPacketItems->$costItemId >= $costNumber, ErrCode::store_itemnotenough); # 检查道具的数量,在背包中是否充足
  766. $mo = GameConfig::item_stones_getItem($costItemId);
  767. my_Assert($mo != null, ErrCode::err_const_no);
  768. StoreProc::removeItemFromStore($user->store, $costItemId, $costNumber);
  769. $total += $mo->baseExp * $costNumber;
  770. $totalGold += $mo->costGold * $costNumber;
  771. }
  772. $yanlingExp = 0;
  773. //消耗言灵
  774. foreach ($yanlingList as $yanlingId) {
  775. my_Assert(CommUtil::isPropertyExists($yanling, $yanlingId), ErrCode::store_weapon_err); # 玩家拥有此英雄
  776. $mo = GameConfig::item_yanling_getItem($yanling->$yanlingId->typeId);
  777. $baseExp = $mo->baseExp;
  778. $yanlingExp += $baseExp + $yanling->$yanlingId->curStarExp * 0.75;
  779. $totalGold += $mo->costGold;
  780. StlUtil::dictRemove($user->store->yanling, $yanlingId);
  781. }
  782. my_Assert($user->baseInfo->gold >= $totalGold, ErrCode::notenough_gold_msg);
  783. $equipVo = new Ins_YanLin($yanling->$uid);
  784. //$equipVo = new Ins_Weapon($equipment->$uid);
  785. $initLevel = $equipVo->level;
  786. $equipVo->curStarExp += $total + (int) $yanlingExp;
  787. $curlevel = StoreProc::Upgrade($equipVo->curStarExp, GameConfig::item_base_getItem($equipVo->typeId)->quality, Enum_UpgradeType::YanLing);
  788. $curStar = $equipVo->starLv; #当前星级
  789. $equipVo->level = $curlevel;
  790. if ($curStar < 5) {
  791. $starlimitLv = GameConfig::yanlingextra_level_getItem($equipVo->typeId, $curStar + 1)->starlimitLv;
  792. if ($starlimitLv < $curlevel) {
  793. $equipVo->level = $starlimitLv;
  794. $equipVo->curStarExp = GameConfig::yanlingLevel_type_getItem(GameConfig::item_base_getItem($equipVo->typeId)->quality, $starlimitLv)->requiredExp;
  795. }
  796. }
  797. $user->store->yanling->$uid = $equipVo;
  798. UserProc::CollectUserBaseParam(req()->cmd, 2,$user->baseInfo->gold, $totalGold, $user->baseInfo->gold - $totalGold,"");
  799. $user->baseInfo->gold -= $totalGold;
  800. req()->userInfo->game = $user;
  801. req()->userInfo->game->store->items = $myPacketItems; # 更新背包数据
  802. if ($equipVo->level != $initLevel) {
  803. NormalEventProc::OnYanLingLvlUp($uid, $equipVo->level); # 广播英雄升级事件
  804. StatisticsProc::TargetStatistics(Enum_TargetStatistics::YanLingIdLevel_UserNum, $equipVo->typeId,"$equipVo->level",$initLevel);
  805. }
  806. UserProc::updateUserInfo(); # 回写玩家数据
  807. return Resp::ok(array(
  808. "store" => $user->store, # # 目前来看只涉及到items变化
  809. 'gold' => $user->baseInfo->gold,
  810. ));
  811. }
  812. /** 6327
  813. * 言灵升级 2021.4(cyzhao)
  814. */
  815. static function YanlinUpLevel_old() {
  816. // list($yanlingUid, $type) = req()->paras; # 参数: 言灵uid,升级类型:1/5级.
  817. // $store = ctx()->store();
  818. // my_Assert(StlUtil::dictHasProperty($store->yanling, $yanlingUid), ErrCode::hero_yanling_notfound);
  819. // $allDic = GameConfig::yanlingLeve();
  820. // $maxLevel = count((array) $allDic);
  821. // $curlv = $store->yanling->$yanlingUid->level;
  822. // my_Assert($curlv <= ctx()->base()->level, "请提升指挥官等级."); # 言灵等级不能超过指挥官等级.-gwang 2021.4.20
  823. // my_Assert($curlv < $maxLevel, ErrCode::hero_yanling_levelMax);
  824. //
  825. // $maxLv = $curlv + $type;
  826. // if ($maxLv > $maxLevel) {
  827. // $maxLv = $maxLevel;
  828. // }
  829. // $goldNum = 0;
  830. // $pointNum = 0;
  831. // for ($index = $curlv; $index < $maxLv; $index++) {
  832. // my_Assert(StlUtil::dictHasProperty($allDic, $index), ErrCode::hero_yanling_levelconst_no);
  833. // $mo = GameConfig::yanlingLeve_getItem($index);
  834. // $goldNum += $mo->goldCost;
  835. // $pointNum += $mo->pointCost;
  836. // }
  837. // my_Assert(req()->userInfo->game->base()->Consume_Gold($goldNum), ErrCode::notenough_gold_msg);
  838. //// my_Assert(Data_UserGame::Consume_ResPoint(req()->userInfo->game->baseInfo, $pointNum), ErrCode::notenough_resPoint);
  839. // my_Assert(req()->userInfo->game->base()->Consume_ResPoint($pointNum), ErrCode::notenough_resPoint);
  840. // $store->yanling->$yanlingUid->level += $type; # 增加等级
  841. // if ($store->yanling->$yanlingUid->level > $maxLevel) {
  842. // $store->yanling->$yanlingUid->level = $maxLevel;
  843. // }
  844. // TaskProc::OnYanlingLevelUp($store->yanling->$yanlingUid->typeId, $store->yanling->$yanlingUid->level); # 言灵升级
  845. //// req()->userInfo->game->store = $store;
  846. // UserProc::updateUserInfo(); # 回写玩家数据
  847. // return Resp::ok(array('store' => req()->userInfo->game->store, #
  848. // 'gold' => ctx()->base()->gold, #
  849. // 'resPoint' => ctx()->base()->resPoint));
  850. }
  851. //
  852. // <editor-fold defaultstate="collapsed" desc="计算战队战斗力, for pvp back matchers, -wg 2017.07.13">
  853. /**
  854. * 计算队伍战斗力, 添加到战斗力隐藏榜单中, for pvp back matchers, -wg 2017.07.13
  855. * @param type $zoneid
  856. * @param type $uid
  857. * @param Data_UserGame $user
  858. * @return type
  859. */
  860. static function CalcTeamFightPower($zoneid, $uid, $user) {
  861. $teamsetting = $user->heroTeamConfig; # 战队配置
  862. // var_dump($user);
  863. $heros = $user->heros;
  864. $teamCfg = JsonUtil::decode($teamsetting);
  865. $tid = $teamCfg->curUseTeamID;
  866. $team = $teamCfg->teamDic->$tid;
  867. $fp = 0; # 返回值
  868. if ($team) {
  869. foreach ($team->heros as $hid) {
  870. if ($hid) {
  871. $hero = $heros->collectHeros->$hid;
  872. if ($hero) {
  873. // $fp += self::calcHeroFightPower($hero);
  874. $h = new Ins_UserHero($hero);
  875. $fp += $h->GetPower($user);
  876. }
  877. }
  878. }
  879. //todo: 这里的战斗力榜被总战力榜征用了key, 重启PVP机制时再
  880. }
  881. return $fp;
  882. }
  883. /**
  884. * 计算玩家总战斗力, 添加到战斗力榜单中
  885. * @version 1.0.0 改造自原来的队伍战斗力统计方法 --gwang 2020.4.23
  886. * @param type $zoneid
  887. * @param type $uid
  888. * @param Data_UserGame $user
  889. * @return type
  890. */
  891. static function CalcUserFightPower($zoneid, $uid, $user) {
  892. $fp = 0; # 总战力:返回值
  893. foreach ($user->heros->collectHeros as $hid => $hero) {
  894. $h = new Ins_UserHero($hero);
  895. $fp += $h->GetPower($user);
  896. }
  897. $key_fp = MemKey_GameRun::Game_FightPowerRank_zset($zoneid); # 战力榜
  898. $key_log = MemKey_GameRun::Game_Rank_FPowerBreakLog_hash($zoneid); # 突破记录
  899. gMem()->zadd($key_fp, array($uid => $fp)); # 更新战力记录
  900. foreach (GameConfig::rankreward_fpower() as $condition => $reward) { # 遍历突破奖励数据
  901. if ($fp >= $condition && !gMem()->hexists($key_log, $condition)) { # 判断是否达成突破奖励标准
  902. gMem()->hset($key_log, $condition, $uid); # 添加突破记录
  903. CornerSignEventProc::OnRanking_PowerReward_new();
  904. }
  905. }
  906. TaskProc::OnUserFightPowerN($fp);
  907. return $fp;
  908. }
  909. /**
  910. * 计算hero战斗力, for pvp back matchers, -wg 2017.07.13
  911. * @param Ins_UserHero $hero
  912. * @return int
  913. */
  914. static private function calcHeroFightPower($hero) {
  915. $arr = explode(';', glc()->Battle_PowerFactor);
  916. $factor = ArrayInit();
  917. foreach ($arr as $s) {
  918. $kv = explode(',', $s);
  919. $k = $kv[0];
  920. $v = $kv[1];
  921. $factor[$k] = $v;
  922. }
  923. $a = (int) (self::calcHeroProperty($hero, 'hp') * $factor ["hp"] //// todo: 哈哈, 奇葩的命名方案, 多处使用的命名不一致, 坑!
  924. + $hero->level * 10);
  925. return $a;
  926. }
  927. /**
  928. * 计算hero的属性,, for pvp back matchers, -wg 2017.07.13
  929. * @param Ins_UserHero $hero
  930. * @param type $propertyname
  931. */
  932. private static function calcHeroProperty($hero, $propertyname) {
  933. $val = 0;
  934. if ($hero) {
  935. $modle = GameConfig::hero_getItem($hero->typeId);
  936. if ($modle) {
  937. $extra = GameConfig::heroextra_level_getItem($hero->typeId, $hero->grade);
  938. if ($extra) {
  939. $val = (int) ($modle->$propertyname * (1 + $extra->$propertyname));
  940. } else {
  941. $val = $modle->$propertyname;
  942. }
  943. }
  944. }
  945. return $val;
  946. }
  947. // </editor-fold>
  948. //
  949. }