HeroProc.php 41 KB

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