HeroProc.php 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  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. $user->baseInfo->gold -= $totalGold;
  210. $totalEXP += $costItemConst->baseExp;
  211. $heroConst = GameConfig::hero_getItem($targetHero->typeId); # 英雄模板数据
  212. my_Assert(null != $heroConst, ErrCode::err_const_no, "英雄 模板数据");
  213. // if ($costItemConst->element != 0 # # 相同元素加成
  214. // && $costItemConst->element == $heroConst->element) {
  215. // $totalEXP += $costItemConst->extraExp;
  216. // }
  217. $totalEXP *= $costNumber; # 消耗N个道具
  218. $targetHero = self:: HeroAddEXP($huid, $totalEXP); # 获得经验
  219. $myPacketItems->$costItemId -= $costNumber; # 消耗道具
  220. if ($myPacketItems->$costItemId < 0) {
  221. $myPacketItems->$costItemId = 0;
  222. }
  223. req()->userInfo->game->store->items = $myPacketItems; # 更新背包数据
  224. my_Assert($targetHero->xp >= 0, "英雄经验出错");
  225. UserProc::updateUserInfo(); # 回写玩家数据
  226. TaskProc::OnHeroImprove(); # 事件检测
  227. self::CalcUserFightPower(req()->zoneid, req()->uid, req()->userInfo->game); # 跟新战力统计
  228. $ret = array(
  229. 'hero' => $targetHero,
  230. 'store' => $user->store,
  231. 'gold' => $user->baseInfo->gold,
  232. );
  233. return Resp::ok($ret);
  234. }
  235. /**
  236. * 唤灵师突破
  237. */
  238. static function tupo() {
  239. list($uid) = req()->paras;
  240. $user = req()->userInfo->game;
  241. $collectHeros = $user->heros->collectHeros; # 1. 检查是否存在要升级的英雄
  242. my_default_Obj($collectHeros);
  243. my_Assert(StlUtil::dictHasProperty($collectHeros, $uid), ErrCode::hero_no); # 参数合法性判断
  244. $typeId = $collectHeros->$uid->typeId;
  245. $curStar = $collectHeros->$uid->curStar;
  246. my_Assert($curStar < 5, ErrCode::hero_yanling_canotTupo);
  247. $mo = GameConfig::heroextra_level_tupo_getItem($typeId, $curStar + 1);
  248. my_Assert($mo != null, ErrCode::err_const_no);
  249. my_Assert($collectHeros->$uid->level >= $mo->starlimitLv, ErrCode::hero_yanling_canotTupo);
  250. my_Assert($user->baseInfo->level >= $mo->userlvLimit, ErrCode::hero_yanling_canotTupo);
  251. my_Assert($user->baseInfo->gold >= $mo->gold, ErrCode::notenough_gold_msg);
  252. $segID = $mo->segID;
  253. my_Assert(StlUtil::dictHasProperty($user->store->items, $segID), ErrCode::store_itemnotenough);
  254. my_Assert($user->store->items->$segID >= $mo->segNum, ErrCode::store_itemnotenough);
  255. $costItemsList = explode(';', $mo->costItems);
  256. foreach ($costItemsList as $value) {
  257. $list = explode(',', $value);
  258. StoreProc::removeItemFromStore($user->store, $list[0], $list[1]);
  259. }
  260. $user->store->items->$segID -= $mo->segNum;
  261. $user->baseInfo->gold -= $mo->gold;
  262. $collectHeros->$uid->curStar += 1;
  263. NormalEventProc::OnHeroTuPo($uid, $collectHeros->$uid->curStar); # 广播英雄升级事件
  264. $user->heros->collectHeros = $collectHeros;
  265. req()->userInfo->game = $user;
  266. $targetHero = new Ins_UserHero($collectHeros->$uid);
  267. TaskProc::OnHeroGradeUp($targetHero->typeId, $targetHero->curStar); #唤灵师突破
  268. UserProc::updateUserInfo(); # 回写玩家数据
  269. $ret = array(
  270. 'hero' => $targetHero,
  271. 'store' => $user->store,
  272. 'gold' => req()->userInfo->game->baseInfo->gold,
  273. );
  274. return Resp::ok($ret);
  275. }
  276. /**
  277. * 武器替换
  278. * @return type
  279. */
  280. static function YanLingReplace() {
  281. list($heroId, $yanlingRank, $heroReplaceId, $yanlingReplaceRank) = req()->paras; # 参数 言灵uid(指定进阶的言灵实例id)
  282. $user = req()->userInfo->game;
  283. $collectHeros = $user->heros->collectHeros;
  284. my_Assert(StlUtil::dictHasProperty($collectHeros, $heroId) && StlUtil::dictHasProperty($collectHeros, $heroReplaceId), "找不到这个唤灵师");
  285. $yanling = $collectHeros->$heroId->yanling;
  286. $yanlingReplace = $collectHeros->$heroReplaceId->yanling;
  287. //my_Assert($yanling->$yanlingRank->itemuid != 0 && $yanlingReplace->$yanlingReplaceRank->itemuid != 0, "找不到这个言灵");
  288. $itemuid = $yanling->$yanlingRank->itemuid;
  289. $replaceItemuid = $yanlingReplace->$yanlingReplaceRank->itemuid;
  290. $yanling->$yanlingRank->itemuid = $replaceItemuid;
  291. $yanlingReplace->$yanlingReplaceRank->itemuid = $itemuid;
  292. if ($yanling->$yanlingRank->itemuid != 0) {
  293. $newItemuid = $yanling->$yanlingRank->itemuid;
  294. $user->store->yanling->$newItemuid->herouid = $heroId;
  295. }
  296. if ($yanlingReplace->$yanlingReplaceRank->itemuid != 0) {
  297. $newReplaceItemuid = $yanlingReplace->$yanlingReplaceRank->itemuid;
  298. $user->store->yanling->$newReplaceItemuid->herouid = $heroReplaceId;
  299. }
  300. $collectHeros->$heroId->yanling = $yanling;
  301. $collectHeros->$heroReplaceId->yanling = $yanlingReplace;
  302. $user->heros->collectHeros = $collectHeros;
  303. req()->userInfo->game = $user;
  304. UserProc::updateUserInfo(); # 回写玩家数据
  305. return Resp::ok(array(
  306. "store" => $user->store, # # 目前来看只涉及到items变化
  307. "hero" => $user->heros->collectHeros,
  308. "selfhero" => $user->heros->collectHeros->$heroId,
  309. ));
  310. }
  311. // </editor-fold>
  312. //
  313. // <editor-fold defaultstate="collapsed" desc="队伍配置">
  314. /**
  315. * [6315]保存队伍的战斗配置信息
  316. */
  317. static function SaveHeroTeamConfig() {
  318. $teamsetting = req()->paras[0]; # 配置信息json文件
  319. req()->userInfo->game->heroTeamConfig = $teamsetting; # 更新配置
  320. UserProc::updateUserInfo(); # 回写数据
  321. # # 添加到战斗力隐藏榜单中, for pvp back matchers, -wg 2017.07.13
  322. self::CalcTeamFightPower(req()->zoneid, req()->uid, req()->userInfo->game);
  323. return Resp::ok(array('result' => "succeed"));
  324. }
  325. // </editor-fold>
  326. //
  327. // <editor-fold defaultstate="collapsed" desc="已过时代码">
  328. /**
  329. * 6323 解锁英雄
  330. */
  331. static function UnLockHeroByPieces() {
  332. Err(ErrCode::err_method_obsoleted, "策划未设定解锁功能-2021.5.6");
  333. $user = req()->userInfo->game; # user引用
  334. $heroModelId = req()->paras[0];
  335. $piecesId = req()->paras[1]; # 英雄碎片的ID
  336. $piecesNum = req()->paras[2];
  337. my_default_Obj($user->heros->recordUnLockHeroDic); # 防御解锁列表未初始化,空对象
  338. $recordUnLockHeroDic = $user->heros->recordUnLockHeroDic; # 已解锁记录
  339. if (!CommUtil::isPropertyExists($recordUnLockHeroDic, $heroModelId)) { # 检查是不是已经解锁过了
  340. $recordUnLockHeroDic->$heroModelId = 0;
  341. }
  342. my_Assert(0 == $recordUnLockHeroDic->$heroModelId, ErrCode::hero_lockState); # 防御英雄已经解锁
  343. $heroCfg = GameConfig::hero_getItem($heroModelId);
  344. my_Assert(isset($heroCfg), ErrCode::hero_const_no_err); # 检查要解锁的英雄的常量配置是否存在
  345. $piecesCfg = GameConfig::segment_getItem($piecesId);
  346. my_Assert(isset($piecesCfg), ErrCode::err_const_no); # 检查需要消耗的碎片的常量配置是否存在
  347. $myPacketItems = $user->store->segement;
  348. $requirePiecesNum = $heroCfg->unlockConditionId;
  349. $enoughPieces = false; # 检查道具数量是否充足
  350. my_Assert($heroModelId == $piecesCfg->prototypeData && $requirePiecesNum == $piecesNum, ErrCode ::paras_err);
  351. if (!CommUtil::isPropertyExists($myPacketItems, $piecesId)) { # 检查碎片
  352. $enoughPieces = false;
  353. } else {
  354. if ($myPacketItems->$piecesId < $requirePiecesNum) { # 5.检查道具的数量是否充足
  355. $enoughPieces = false;
  356. } else {
  357. $enoughPieces = true;
  358. }
  359. }
  360. my_Assert($enoughPieces, ErrCode::hero_godblood_notengoughitem);
  361. $myPacketItems->$piecesId -= $requirePiecesNum;
  362. if ($myPacketItems->$piecesId < 0) { # 6.进行 # # 消耗道具
  363. $myPacketItems->$piecesId = 0;
  364. }
  365. $recordUnLockHeroDic->$heroModelId = 1;
  366. req()->userInfo->game->heros->recordUnLockHeroDic = $recordUnLockHeroDic;
  367. req()->userInfo->game->store->segement = $myPacketItems;
  368. UserProc::updateUserInfo(); # 回写数据
  369. return Resp::ok(array('result' => "OK")); # 返回OK
  370. }
  371. /**
  372. * [6322] 英雄神血
  373. */
  374. static function UpGodBloodHeroByPieces() {
  375. Err(ErrCode::err_method_obsoleted, "策划未设定神血功能-2021.5.6");
  376. }
  377. /**
  378. * 英雄消耗碎片道具来升星
  379. * @param req $req
  380. */
  381. static function HeroUpStarByPieces() {
  382. Err(ErrCode::err_method_obsoleted, "策划未设定碎片升级功能-2021.5.6");
  383. }
  384. /**
  385. * 英雄升星
  386. * @param Req $req
  387. */
  388. static function HeroUpStar() {
  389. Err(ErrCode::err_method_obsoleted, "策划未设定升星功能-2021.5.6");
  390. }
  391. // </editor-fold>
  392. /**
  393. * 6321 购买英雄 消耗碎片
  394. */
  395. static function BuyHeroByCostPieces() {
  396. Err(ErrCode::err_method_obsoleted, "策划未设定碎片功能-2021.5.6");
  397. list($heroModelId, $costType, $costMoneyNum, $piecesId, $piecesNum) = req()->paras; # 提取参数
  398. $user = req()->userInfo->game; # user引用
  399. $collectHeros = $user->heros->collectHeros;
  400. my_default_Obj($collectHeros);
  401. foreach ($collectHeros as $key => $value) { # 检查玩家是否已经拥有此类英雄
  402. my_Assert($value->typeId != $heroModelId, ErrCode::hero_existSameHero_err);
  403. }
  404. $heroCfg = GameConfig::hero_getItem($heroModelId); # 英雄模板数据
  405. my_Assert(null != $heroCfg, ErrCode::hero_const_no_err);
  406. my_Assert($heroCfg->isCanBuy != 0, ErrCode::paras_err); # 是否可以直接购买
  407. $piecesCfg = GameConfig::segment_getItem($piecesId); # 检查需要消耗的碎片的常量配置是否存在
  408. my_Assert(null != $piecesCfg, ErrCode::err_store_itemnoconst);
  409. $myPacketItems = $user->store->items;
  410. $requirePiecesNum = $piecesCfg->mergePrototypeNeedNum;
  411. my_Assert($heroModelId == $piecesCfg->prototypeData && $requirePiecesNum == $piecesNum, ErrCode::paras_err);
  412. my_Assert(CommUtil::isPropertyExists($myPacketItems, $piecesId), ErrCode::hero_godblood_notengoughitem);
  413. my_Assert($myPacketItems->$piecesId > $requirePiecesNum, ErrCode::hero_godblood_notengoughitem); # 检查碎片道具数量是否充足
  414. switch ($costType) {
  415. case "cash":
  416. $realPrice = $heroCfg->cashPrice;
  417. my_Assert($realPrice == $costMoneyNum, ErrCode::paras_err);
  418. my_Assert($costMoneyNum >= 0, ErrCode::paras_err);
  419. my_Assert($user->base()->Consume_Cash($costMoneyNum), ErrCode::err_msg_cashnotenough);
  420. break;
  421. case "gold":
  422. $realPrice = $heroCfg->goldPrice;
  423. my_Assert($realPrice == $costMoneyNum, ErrCode::paras_err);
  424. my_Assert($costMoneyNum >= 0, ErrCode::paras_err);
  425. my_Assert($user->base()->Consume_Gold($costMoneyNum), ErrCode::err_msg_goldnotenough);
  426. break;
  427. default :
  428. Err(ErrCode::paras_err, "参数错误: [costType] " . $costType);
  429. }
  430. # 4.消耗来获得英雄
  431. $myPacketItems->$piecesId -= $requirePiecesNum; # 消耗道具
  432. req()->userInfo->game->store->items = $myPacketItems; # 回存背包
  433. UserProc::updateUserInfo(); # 回写数据
  434. $resp = HeroProc::GetHero();
  435. SystemProc::GetHero(req()->zoneid, $user->base(), $heroModelId); # 插入系统广播消息
  436. return $resp;
  437. }
  438. /**
  439. * 购买玩家可以收集的英雄的数量上限
  440. * @return type
  441. */
  442. static function BuyHeroMaxCountLimt() {
  443. list($buyNum, $costCash) = req()->paras; # 提取参数: 数量, 花费钻石
  444. $g = glc();
  445. $user = req()->userInfo->game; # user引用
  446. if (!CommUtil::isPropertyExists($user->heros, "maxCollectCount")) {
  447. $user->heros->maxCollectCount = $g->Game_CollectHero_BasicMaxCount;
  448. }
  449. $index = ceil(($user->heros->maxCollectCount - $g->Game_CollectHero_BasicMaxCount) #
  450. / $g->Game_CollectHero_OneBuyLimtNum);
  451. $arr = explode(",", $g->Game_CollectHero_BasicMaxPrice);
  452. my_Assert($index < count($arr), "已达上限");
  453. $realCost = $arr[$index];
  454. my_Assert($realCost == $costCash, ErrCode::paras_err); # 参数错误
  455. my_Assert($costCash >= 0, ErrCode::paras_err);
  456. my_Assert($user->base()->Consume_Cash($costCash), ErrCode::err_msg_goldnotenough); # 扣除宝石
  457. $user->heros->maxCollectCount += $buyNum; # 修改上限
  458. UserProc::updateUserInfo();
  459. return Resp::ok(array(
  460. 'maxCollectCount' => $user->heros->maxCollectCount
  461. ));
  462. }
  463. /**
  464. * 获得英雄(测试已经OK)
  465. */
  466. static function GetHero() {
  467. $heroModelId = req()->paras[0]; # 英雄的模板ID
  468. $heroCfg = GameConfig::hero_getItem($heroModelId); # 1.检查是否存在这个英雄的模板
  469. my_Assert(null != $heroCfg, ErrCode::hero_const_no_err);
  470. $hero = self::AddHeroTFromStore($heroModelId); # 创建英雄
  471. UserProc::updateUserInfo();
  472. $result = array('result' => "succeed", 'heros' => $hero); # 4. 设置返回值
  473. return Resp::ok($result);
  474. }
  475. // <editor-fold defaultstate="collapsed" desc="辅助方法">
  476. /**
  477. * 获得一个英雄, 并且给他指定星级
  478. * @param int $heromodelId 原型数据id
  479. * @param int $star 星级
  480. * @return Ins_UserHero
  481. */
  482. static function AddHeroWithStar($heromodelId, $star) {
  483. my_Assert(null != ctx(), ErrCode::err_innerfault);
  484. $collectHeros = ctx()->heros()->collectHeros;
  485. $uid = self::CreateNewGameHeroUID($collectHeros, ctx()->heros()->recordMaxUID); # 先生成一个hero的UID
  486. ctx()->heros()->recordMaxUID = $uid;
  487. $hero = self::getGameHeroModelInstance($heromodelId, $uid);
  488. if ($star > 0) {
  489. $hero->curStar = $star; # 设定star
  490. }
  491. $collectHeros->$uid = $hero; # 回写
  492. ctx()->heros()->collectHeros = $collectHeros; # 回写
  493. return $hero; # 返回
  494. }
  495. /**
  496. * 获得一个英雄(实例)
  497. * @param req $req
  498. * @param int $heromodelId
  499. * @return type
  500. */
  501. static function AddHeroTFromStore($heromodelId) {
  502. $user = ctx(); # 玩家数据
  503. $collectHeros = ctx()->heros()->collectHeros; #
  504. my_default_Obj($collectHeros);
  505. $uid = self::CreateNewGameHeroUID($collectHeros, ctx()->heros()->recordMaxUID); # 先生成一个UID
  506. $user->heros->recordMaxUID = $uid; # 更新最大编号记录
  507. $hero = self::getGameHeroModelInstance($heromodelId, $uid); # 3.创建英雄实例
  508. $collectHeros->$uid = $hero;
  509. ctx()->heros()->collectHeros = $collectHeros;
  510. return $hero;
  511. }
  512. /**
  513. * 根据一个英雄的模板id,来获得一个英雄的实例数据
  514. * @param string $heroModelId 模板数据ID
  515. * @param string $uid 唯一ID
  516. * @return Ins_UserHero
  517. */
  518. static function getGameHeroModelInstance($heroModelId, $uid) {
  519. $heroCfg = GameConfig::hero_getItem($heroModelId);
  520. my_Assert(null != $heroCfg, ErrCode::err_const_no); # 检查是否存在这个英雄的模板
  521. $hero = new Ins_UserHero();
  522. // $hero->strengthLevel = $heroCfg->dengjie;
  523. $hero->curStar = $heroCfg->xingji;
  524. $hero->typeId = $heroCfg->heroId;
  525. $hero->uid = $uid;
  526. $hero->xp = 0;
  527. $lvs = GameConfig::hero_levelexp_getItem($hero->level + 1);
  528. $hero->maxXp = $lvs->requiredExp;
  529. // 取可用武器中第一个初始化 -- 策划要求初始英雄要带有武器 -- 王刚 2020年1月
  530. $wp = null;
  531. $arr = (array) GameConfig::item_weapon();
  532. uksort($arr, function ($a, $b) {
  533. return intval($a) < intval($b);
  534. }); // todo: 排序不正常
  535. foreach ($arr as $id => $mo) {
  536. // isEditor() and $mo = new \sm_item_weapon();
  537. $heroList = explode(',', $mo->hero_id);
  538. foreach ($heroList as $hero_id) {
  539. if ($hero_id == $hero->typeId) {
  540. $wp = $mo;
  541. break;
  542. }
  543. }
  544. // if ($mo->hero_id == $hero->typeId) {
  545. // $wp = $mo;
  546. // break;
  547. // }
  548. }
  549. if (null != $wp) {
  550. $wuid = StoreProc::PutEquipInStore($wp->typeId);
  551. req()->userInfo->game->store->equipment->$wuid->herouid = $uid;
  552. $hero->equip->weapon = array("itemuid" => $wuid);
  553. }
  554. return $hero;
  555. }
  556. /**
  557. * 查找下一个玩家获得英雄的UID
  558. * @param type $req
  559. * @return int
  560. */
  561. static function CreateNewGameHeroUID($collectHeros, $oldMaxUID) {
  562. $maxID = 10000;
  563. my_default_Obj($collectHeros);
  564. foreach ($collectHeros as $itemId => $hero) {
  565. if ($itemId > $maxID) {
  566. $maxID = $itemId;
  567. }
  568. }
  569. $max = max($maxID, $oldMaxUID);
  570. return $max + 1;
  571. }
  572. /**
  573. * 英雄卡牌增加经验值
  574. * @param string $heroUID
  575. * @param int $totalEXP
  576. */
  577. static function HeroAddEXP($heroUID, $totalEXP) {
  578. $req = req();
  579. $collectHeros = $req->userInfo->game->heros->collectHeros;
  580. my_default_Obj($collectHeros);
  581. my_Assert(CommUtil::isPropertyExists($collectHeros, $heroUID), ErrCode::hero_no); # 要升级的英雄不存在
  582. $targetHero = new Ins_UserHero($collectHeros->$heroUID); # 英雄对象
  583. // $playerLimit = GameConfig::playerlevel_getItem(ctx()->base()->level)->hero_max_level;
  584. // $maxLevel = min(glc()->Hero_Upgrade_BasicMaxLevel, $playerLimit); # 最大等级= max(英雄最高等级上限,玩家等级限制的上限)
  585. // if ($targetHero->level >= $maxLevel) {
  586. // return; # 已达顶级
  587. // }
  588. //$lvs = GameConfig::hero_levelexp_getItem($targetHero->level + 1);
  589. $targetHero->xp += $totalEXP;
  590. my_Assert($targetHero->xp >= 0, "[" . $req->uid . "] : HeroLevelUpgrade Exp is negative!");
  591. $initLevel = $targetHero->level;
  592. $curLv = 0;
  593. $heroLvDic = GameConfig::hero_levelexp();
  594. $f = (array) $heroLvDic;
  595. ksort($f);
  596. foreach ($f as $lv => $mo) {
  597. if ($targetHero->xp < $mo->requiredExp) {
  598. $curLv = $lv - 1;
  599. break;
  600. }
  601. if ($lv >= glc()->Hero_Upgrade_BasicMaxLevel) {
  602. $curLv = glc()->Hero_Upgrade_BasicMaxLevel;
  603. break;
  604. }
  605. }
  606. $targetHero->level = $curLv;
  607. $curStar = $targetHero->curStar; #当前星级
  608. if ($curStar < 5) {
  609. $starlimitLv = GameConfig::heroextra_level_tupo_getItem($targetHero->typeId, $curStar + 1)->starlimitLv;
  610. if ($starlimitLv < $curLv) {
  611. $targetHero->level = $starlimitLv;
  612. $targetHero->xp = GameConfig::hero_levelexp_getItem($starlimitLv)->needExp;
  613. }
  614. }
  615. // while ($targetHero->xp >= $lvs->needExp) {
  616. // if ($targetHero->level < $maxLevel) { # 如果未到达最大等级
  617. // $targetHero->level += 1;
  618. // if ($targetHero->level >= $maxLevel) {
  619. // $targetHero->xp = $lvs->needExp;
  620. // } else {
  621. // $targetHero->xp -= $lvs->needExp;
  622. // }
  623. // $lvs = GameConfig::hero_levelexp_getItem($targetHero->level + 1);
  624. // } else { # 如果已到达最大等级则仅补齐缺失的经验即可
  625. // $targetHero->xp = $targetHero->maxXp; # 经验不能超过最大值
  626. // break;
  627. // }
  628. // } // end while
  629. my_Assert($targetHero->xp >= 0, "[" . $req->uid . "] : HeroLevelUpgrade Exp is negative!");
  630. $collectHeros->$heroUID = $targetHero; # 更新英雄的数据
  631. if ($targetHero->level != $initLevel) {
  632. NormalEventProc::OnHeroLvlUp($targetHero->uid, $initLevel); # 广播英雄升级事件
  633. }
  634. TaskProc::OnHeroLevelUp($targetHero->typeId, $targetHero->level);
  635. return $targetHero; # 将英雄对象返回
  636. }
  637. // </editor-fold>
  638. /**
  639. * [6306] 英雄-更改英雄的锁定状态
  640. * (测试已经OK)
  641. */
  642. static function HeroChangelockstate() {
  643. $gamedata = req()->userInfo->game;
  644. $heroUID = req()->paras[0]; # 玩家英雄实例编号
  645. $lockstate = req()->paras[1]; # 玩家英雄锁定状态
  646. $collectHeros = $gamedata->heros->collectHeros;
  647. my_default_Obj($collectHeros); # 默认值
  648. my_Assert(CommUtil::isPropertyExists($collectHeros, $heroUID), ErrCode::hero_no);
  649. // isEditor() and $hero = new UserHeroModel;
  650. $hero = $collectHeros->$heroUID; # 1. 获取这个英雄的实例数据是
  651. $hero->isLocked = $lockstate; # 2. 修改英雄状态
  652. UserProc::updateUserInfo(); # 3. 保存玩家数据
  653. return Resp::ok(ObjectInit()); # 4. 设置返回值
  654. }
  655. /** 6326
  656. * 言灵升星--改成突破【2021-6-8】 2021.4(cyzhao)
  657. * @return resp
  658. */
  659. static function StrengthenStar_old() {
  660. list($yanlingUid, $uidList) = req()->paras;
  661. $store = req()->userInfo->game->store;
  662. my_Assert(StlUtil::dictHasProperty($store->yanling, $yanlingUid), ErrCode::hero_yanling_notfound);
  663. my_Assert(!in_array($yanlingUid, $uidList), ErrCode::hero_yanling_repeat);
  664. my_Assert($store->yanling->$yanlingUid->starLv < 5, ErrCode::hero_yanling_repeat);
  665. $tag = true;
  666. foreach ($uidList as $costUid) {
  667. if (StlUtil::dictHasProperty($store->yanling, $costUid)) { # 校验是否是同类型
  668. $confDic = GameConfig::item_yanling_getItem($store->yanling->$costUid->typeId);
  669. my_Assert(null != $confDic, ErrCode::hero_const_no_err);
  670. if ($confDic->type != GameConfig::item_yanling_getItem($store->yanling->$yanlingUid->typeId)->type) {
  671. $tag = false;
  672. break;
  673. }
  674. if ($store->yanling->$costUid->herouid != 0) {
  675. $tag = false;
  676. break;
  677. }
  678. } else {
  679. $tag = false;
  680. break;
  681. }
  682. }
  683. my_Assert($tag, ErrCode::hero_yanling_errorYanling);
  684. $exp = 0;
  685. foreach ($uidList as $costuid) {
  686. $confDic = GameConfig::item_yanling_getItem($store->yanling->$costuid->typeId);
  687. my_Assert(null != $confDic, ErrCode::hero_const_no_err);
  688. $exp += $confDic->addStarExp;
  689. StlUtil::dictRemove($store->yanling, $costuid);
  690. }
  691. $store->yanling->$yanlingUid->curStarExp += $exp;
  692. $dic = GameConfig::item_yanling_getItem($store->yanling->$yanlingUid->typeId);
  693. if ($store->yanling->$yanlingUid->curStarExp >= $dic->maxStarExp) {
  694. $store->yanling->$yanlingUid->curStarExp = 0;
  695. $store->yanling->$yanlingUid->starLv += 1;
  696. $store->yanling->$yanlingUid->typeId = $dic->nextId;
  697. }
  698. req()->userInfo->game->store = $store;
  699. UserProc::updateUserInfo();
  700. return Resp::ok(array('store' => req()->userInfo->game->store,));
  701. }
  702. /**
  703. * 新的突破
  704. * @return type
  705. */
  706. static function StrengthenStar() {
  707. list($uid) = req()->paras; # 参数 言灵uid(指定进阶的言灵实例id)
  708. $user = req()->userInfo->game;
  709. $yanling = $user->store->yanling;
  710. my_Assert(CommUtil::isPropertyExists($yanling, $uid), ErrCode::store_weapon_err); # 玩家拥有此英雄
  711. $typeId = $yanling->$uid->typeId;
  712. $curStar = $yanling->$uid->starLv;
  713. my_Assert($curStar < 5, ErrCode::hero_yanling_canotTupo);
  714. $mo = GameConfig::yanlingextra_level_getItem($typeId, $curStar + 1);
  715. my_Assert($mo != null, ErrCode::err_const_no);
  716. my_Assert($yanling->$uid->level >= $mo->starlimitLv, ErrCode::hero_yanling_canotTupo);
  717. my_Assert($user->baseInfo->level >= $mo->userlvLimit, ErrCode::hero_yanling_canotTupo);
  718. my_Assert($user->baseInfo->gold >= $mo->gold, ErrCode::notenough_gold_msg);
  719. $costItemsList = explode(';', $mo->costItems);
  720. foreach ($costItemsList as $value) {
  721. $list = explode(',', $value);
  722. StoreProc::removeItemFromStore($user->store, $list[0], $list[1]);
  723. }
  724. $user->baseInfo->gold -= $mo->gold;
  725. $yanling->$uid->starLv += 1;
  726. NormalEventProc::OnYanLingLvTuPo($uid, $yanling->$uid->starLv); # 广播英雄升级事件
  727. TaskProc::OnYanlingStarUp($yanling->$uid->starLv); # 言灵突破 2021.7.30
  728. $user->store->yanling = $yanling;
  729. req()->userInfo->game = $user;
  730. UserProc::updateUserInfo(); # 回写玩家数据
  731. return Resp::ok(array(
  732. "store" => $user->store, # # 目前来看只涉及到items变化
  733. 'gold' => $user->baseInfo->gold,
  734. ));
  735. }
  736. /**
  737. * 言灵升级
  738. * @return type
  739. */
  740. static function YanlinUpLevel() {
  741. list($uid, $yanlingList, $items) = req()->paras; # 参数 言灵uid(指定进阶的言灵实例id)
  742. $user = req()->userInfo->game;
  743. $yanling = $user->store->yanling;
  744. my_Assert(CommUtil::isPropertyExists($yanling, $uid), ErrCode::store_weapon_err); # 玩家拥有此英雄
  745. $myPacketItems = $user->store->items;
  746. //消耗材料道具
  747. $total = 0;
  748. $totalGold = 0;
  749. foreach ($items as $costItemId => $costNumber) {
  750. my_Assert(CommUtil::isPropertyExists($myPacketItems, $costItemId), ErrCode::store_itemnotenough); #
  751. my_Assert($myPacketItems->$costItemId >= $costNumber, ErrCode::store_itemnotenough); # 检查道具的数量,在背包中是否充足
  752. $mo = GameConfig::item_stones_getItem($costItemId);
  753. my_Assert($mo != null, ErrCode::err_const_no);
  754. StoreProc::removeItemFromStore($user->store, $costItemId, $costNumber);
  755. $total += $mo->baseExp * $costNumber;
  756. $totalGold += $mo->costGold * $costNumber;
  757. }
  758. $yanlingExp = 0;
  759. //消耗言灵
  760. foreach ($yanlingList as $yanlingId) {
  761. my_Assert(CommUtil::isPropertyExists($yanling, $yanlingId), ErrCode::store_weapon_err); # 玩家拥有此英雄
  762. $mo = GameConfig::item_yanling_getItem($yanling->$yanlingId->typeId);
  763. $baseExp = $mo->baseExp;
  764. $yanlingExp += $baseExp + $yanling->$yanlingId->curStarExp * 0.75;
  765. $totalGold += $mo->costGold;
  766. StlUtil::dictRemove($user->store->yanling, $yanlingId);
  767. }
  768. my_Assert($user->baseInfo->gold >= $totalGold, ErrCode::notenough_gold_msg);
  769. $equipVo = new Ins_YanLin($yanling->$uid);
  770. //$equipVo = new Ins_Weapon($equipment->$uid);
  771. $initLevel = $equipVo->level;
  772. $equipVo->curStarExp += $total + (int) $yanlingExp;
  773. $curlevel = StoreProc::Upgrade($equipVo->curStarExp, GameConfig::item_base_getItem($equipVo->typeId)->quality, Enum_UpgradeType::YanLing);
  774. $curStar = $equipVo->starLv; #当前星级
  775. $equipVo->level = $curlevel;
  776. if ($curStar < 5) {
  777. $starlimitLv = GameConfig::yanlingextra_level_getItem($equipVo->typeId, $curStar + 1)->starlimitLv;
  778. if ($starlimitLv < $curlevel) {
  779. $equipVo->level = $starlimitLv;
  780. $equipVo->curStarExp = GameConfig::yanlingLevel_type_getItem(GameConfig::item_base_getItem($equipVo->typeId)->quality, $starlimitLv)->requiredExp;
  781. }
  782. }
  783. $user->store->yanling->$uid = $equipVo;
  784. $user->baseInfo->gold -= $totalGold;
  785. req()->userInfo->game = $user;
  786. req()->userInfo->game->store->items = $myPacketItems; # 更新背包数据
  787. if ($equipVo->level != $initLevel) {
  788. NormalEventProc::OnYanLingLvlUp($uid, $equipVo->level); # 广播英雄升级事件
  789. }
  790. UserProc::updateUserInfo(); # 回写玩家数据
  791. return Resp::ok(array(
  792. "store" => $user->store, # # 目前来看只涉及到items变化
  793. 'gold' => $user->baseInfo->gold,
  794. ));
  795. }
  796. /** 6327
  797. * 言灵升级 2021.4(cyzhao)
  798. */
  799. static function YanlinUpLevel_old() {
  800. list($yanlingUid, $type) = req()->paras; # 参数: 言灵uid,升级类型:1/5级.
  801. $store = ctx()->store();
  802. my_Assert(StlUtil::dictHasProperty($store->yanling, $yanlingUid), ErrCode::hero_yanling_notfound);
  803. $allDic = GameConfig::yanlingLeve();
  804. $maxLevel = count((array) $allDic);
  805. $curlv = $store->yanling->$yanlingUid->level;
  806. my_Assert($curlv <= ctx()->base()->level, "请提升指挥官等级."); # 言灵等级不能超过指挥官等级.-gwang 2021.4.20
  807. my_Assert($curlv < $maxLevel, ErrCode::hero_yanling_levelMax);
  808. $maxLv = $curlv + $type;
  809. if ($maxLv > $maxLevel) {
  810. $maxLv = $maxLevel;
  811. }
  812. $goldNum = 0;
  813. $pointNum = 0;
  814. for ($index = $curlv; $index < $maxLv; $index++) {
  815. my_Assert(StlUtil::dictHasProperty($allDic, $index), ErrCode::hero_yanling_levelconst_no);
  816. $mo = GameConfig::yanlingLeve_getItem($index);
  817. $goldNum += $mo->goldCost;
  818. $pointNum += $mo->pointCost;
  819. }
  820. my_Assert(req()->userInfo->game->base()->Consume_Gold($goldNum), ErrCode::notenough_gold_msg);
  821. // my_Assert(Data_UserGame::Consume_ResPoint(req()->userInfo->game->baseInfo, $pointNum), ErrCode::notenough_resPoint);
  822. my_Assert(req()->userInfo->game->base()->Consume_ResPoint($pointNum), ErrCode::notenough_resPoint);
  823. $store->yanling->$yanlingUid->level += $type; # 增加等级
  824. if ($store->yanling->$yanlingUid->level > $maxLevel) {
  825. $store->yanling->$yanlingUid->level = $maxLevel;
  826. }
  827. TaskProc::OnYanlingLevelUp($store->yanling->$yanlingUid->typeId, $store->yanling->$yanlingUid->level); # 言灵升级
  828. // req()->userInfo->game->store = $store;
  829. UserProc::updateUserInfo(); # 回写玩家数据
  830. return Resp::ok(array('store' => req()->userInfo->game->store, #
  831. 'gold' => ctx()->base()->gold, #
  832. 'resPoint' => ctx()->base()->resPoint));
  833. }
  834. //
  835. // <editor-fold defaultstate="collapsed" desc="计算战队战斗力, for pvp back matchers, -wg 2017.07.13">
  836. /**
  837. * 计算队伍战斗力, 添加到战斗力隐藏榜单中, for pvp back matchers, -wg 2017.07.13
  838. * @param type $zoneid
  839. * @param type $uid
  840. * @param Data_UserGame $user
  841. * @return type
  842. */
  843. static function CalcTeamFightPower($zoneid, $uid, $user) {
  844. $teamsetting = $user->heroTeamConfig; # 战队配置
  845. // var_dump($user);
  846. $heros = $user->heros;
  847. $teamCfg = JsonUtil::decode($teamsetting);
  848. $tid = $teamCfg->curUseTeamID;
  849. $team = $teamCfg->teamDic->$tid;
  850. $fp = 0; # 返回值
  851. if ($team) {
  852. foreach ($team->heros as $hid) {
  853. if ($hid) {
  854. $hero = $heros->collectHeros->$hid;
  855. if ($hero) {
  856. // $fp += self::calcHeroFightPower($hero);
  857. $h = new Ins_UserHero($hero);
  858. $fp += $h->GetPower($user);
  859. }
  860. }
  861. }
  862. //todo: 这里的战斗力榜被总战力榜征用了key, 重启PVP机制时再
  863. }
  864. return $fp;
  865. }
  866. /**
  867. * 计算玩家总战斗力, 添加到战斗力榜单中
  868. * @version 1.0.0 改造自原来的队伍战斗力统计方法 --gwang 2020.4.23
  869. * @param type $zoneid
  870. * @param type $uid
  871. * @param Data_UserGame $user
  872. * @return type
  873. */
  874. static function CalcUserFightPower($zoneid, $uid, $user) {
  875. $fp = 0; # 总战力:返回值
  876. foreach ($user->heros->collectHeros as $hid => $hero) {
  877. $h = new Ins_UserHero($hero);
  878. $fp += $h->GetPower($user);
  879. }
  880. $key_fp = MemKey_GameRun::Game_FightPowerRank_zset($zoneid); # 战力榜
  881. $key_log = MemKey_GameRun::Game_Rank_FPowerBreakLog_hash($zoneid); # 突破记录
  882. gMem()->zadd($key_fp, array($uid => $fp)); # 更新战力记录
  883. foreach (GameConfig::rankreward_fpower() as $condition => $reward) { # 遍历突破奖励数据
  884. if ($fp >= $condition && !gMem()->hexists($key_log, $condition)) { # 判断是否达成突破奖励标准
  885. gMem()->hset($key_log, $condition, $uid); # 添加突破记录
  886. CornerSignEventProc::OnRanking_PowerReward_new();
  887. }
  888. }
  889. TaskProc::OnUserFightPowerN($fp);
  890. return $fp;
  891. }
  892. /**
  893. * 计算hero战斗力, for pvp back matchers, -wg 2017.07.13
  894. * @param Ins_UserHero $hero
  895. * @return int
  896. */
  897. static private function calcHeroFightPower($hero) {
  898. $arr = explode(';', glc()->Battle_PowerFactor);
  899. $factor = ArrayInit();
  900. foreach ($arr as $s) {
  901. $kv = explode(',', $s);
  902. $k = $kv[0];
  903. $v = $kv[1];
  904. $factor[$k] = $v;
  905. }
  906. $a = (int) (self::calcHeroProperty($hero, 'hp') * $factor ["hp"] //// todo: 哈哈, 奇葩的命名方案, 多处使用的命名不一致, 坑!
  907. + $hero->level * 10);
  908. return $a;
  909. }
  910. /**
  911. * 计算hero的属性,, for pvp back matchers, -wg 2017.07.13
  912. * @param Ins_UserHero $hero
  913. * @param type $propertyname
  914. */
  915. private static function calcHeroProperty($hero, $propertyname) {
  916. $val = 0;
  917. if ($hero) {
  918. $modle = GameConfig::hero_getItem($hero->typeId);
  919. if ($modle) {
  920. $extra = GameConfig::heroextra_level_getItem($hero->typeId, $hero->grade);
  921. if ($extra) {
  922. $val = (int) ($modle->$propertyname * (1 + $extra->$propertyname));
  923. } else {
  924. $val = $modle->$propertyname;
  925. }
  926. }
  927. }
  928. return $val;
  929. }
  930. // </editor-fold>
  931. //
  932. }