HeroProc.php 41 KB

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