HeroProc.php 45 KB

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