HeroProc.php 52 KB

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