HeroProc.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 英雄处理逻辑
  5. * @author gwang
  6. */
  7. class HeroProc {
  8. /**
  9. * 英雄处理逻辑分发
  10. * 所有的Proc中必须有这样一个方法
  11. * @param Req $req
  12. */
  13. static function procMain($req) {
  14. switch ($req->cmd) {
  15. case CmdCode::cmd_hero_levelup: # [6301] 英雄升级
  16. return HeroProc::HeroLevelUpCostExpItem($req);
  17. case CmdCode::cmd_hero_stageup: # [6304] 英雄进阶 SABCD
  18. return HeroProc::HeroStageUp($req);
  19. // <editor-fold defaultstate="collapsed" desc="过时 接口">
  20. // case CmdCode::cmd_hero_upstar: # [6305] 英雄升星
  21. // return HeroProc::HeroUpStarByPieces($req);
  22. // case CmdCode::cmd_hero_changelockstate: # [6306] 英雄-修改锁定状态
  23. // return HeroProc::HeroChangelockstate($req);
  24. // case CmdCode::cmd_hero_buyCollectHeroLimtCount: # [6312] 扩展英雄数量上限
  25. // return HeroProc::BuyHeroMaxCountLimt($req);
  26. // </editor-fold>
  27. # --------- 英雄技能 -----------
  28. case CmdCode::cmd_hero_upgradeSkillLevel: # [6314] 英雄的技能升级
  29. return HeroProc::UpgradeSkillLevel($req);
  30. case CmdCode::cmd_hero_unlockSkill: # [6324] 英雄技能 - 解锁技能
  31. return HeroProc::UnlockSkill($req);
  32. case CmdCode::cmd_hero_skillLevel_onekeyupgrade: # [6325] 英雄技能 - 一键升级
  33. return HeroProc::OnekeyUpgradeSkillLevel($req);
  34. case CmdCode::cmd_hero_saveHeroTeamConfig: # [6315] 保存玩家战队数据
  35. return HeroProc::SaveHeroTeamConfig($req);
  36. // <editor-fold defaultstate="collapsed" desc="---------------英雄评论----------------">
  37. case CmdCode::cmd_hero_GetDiscuss: # [6316]拉取英雄评论
  38. return HeroDiscussProc::GetDiscusses($req);
  39. case CmdCode::cmd_hero_PostDiscuss: # [6317]对英雄发表评论
  40. return HeroDiscussProc::Post($req);
  41. case CmdCode::cmd_hero_PraiseDiscuss: # [6318]给某条评论点赞
  42. return HeroDiscussProc::PriaseMsg($req);
  43. case CmdCode::cmd_hero_DeleteDiscuss: # [6319]删除评论
  44. return HeroDiscussProc::DeletePost($req);
  45. case CmdCode::cmd_hero_scoreit: # [6320]给某个英雄评分
  46. return HeroDiscussProc::Score($req);
  47. // </editor-fold>
  48. #----------- 英雄的解锁与购买 --------------
  49. case CmdCode::cmd_hero_buyHero: # [6321]购买英雄
  50. return HeroProc::BuyHeroByCostPieces($req);
  51. case CmdCode::cmd_hero_upGodBlood: # [6322] 神血升级
  52. return HeroProc::UpGodBloodHeroByPieces($req);
  53. case CmdCode::cmd_hero_StrengthenStar: # [6326] 升星cmd_hero_YanlinUpLevel
  54. return HeroProc::StrengthenStar($req);
  55. case CmdCode::cmd_hero_YanlinUpLevel: # [6327] 升级
  56. return HeroProc::YanlinUpLevel($req);
  57. // case CmdCode::cmd_hero_unlockByPieces: # [6323] 解锁碎片
  58. // return HeroProc::UnLockHeroByPieces($req);
  59. default: # err: 未知的命令码
  60. return Resp::err(ErrCode::cmd_err);
  61. }
  62. }
  63. // <editor-fold defaultstate="collapsed" desc="技能升级与解锁">
  64. /**
  65. * [6324] 英雄技能解锁
  66. * @version 2020.1.13 至今未进行对接, 再次整理版
  67. * 2019.12.10 加班弄完第一版
  68. * @param req $req
  69. */
  70. static function UnlockSkill($req) {
  71. list($huid, $mainSkillId, $subSkillId) = $req->paras; # 提取参数: 英雄的UID, 主技能Id, 要升级的子技能ID
  72. $user = $req->userInfo->game; # user引用
  73. $cHeros = $user->heros->collectHeros;
  74. my_default_Obj($cHeros);
  75. my_Assert(CommUtil::isPropertyExists($cHeros, $huid), ErrCode::hero_no); # 1.检查是否存在要解锁的英雄
  76. # # 2.判断英雄的该技能能否升级....
  77. $targetHero = new Ins_UserHero($cHeros->$huid); # 直接类型识别
  78. $targteHeroSkills = $targetHero->subSkills; # 取出这个英雄的技能数据
  79. my_default_Arr($targteHeroSkills->$mainSkillId); # 保护子技能数组数据结构
  80. my_Assert(!CommUtil::isInArray($targteHeroSkills->$mainSkillId, $subSkillId), "子技能已解锁"); # 子技能已经解锁
  81. // if (!$targetHero->IsSkillUnlockAble($mainSkillId, $subSkillId)) { # 3.判断技能是否处于待解锁状态
  82. // return Resp::err(ErrCode::hero_upgradeSkill_maxLevel);
  83. // }
  84. $sm = GameConfig::subSkill_getItem($subSkillId); # 4.取出该技能升级消耗的常量数据
  85. my_Assert(null != $sm, ErrCode::err_const_no); # 找不到子技能配置数据
  86. my_Assert(Data_UserGame::Consume_Gold($user->baseInfo, $sm->unlockCost), # # 5. 扣除金币消耗
  87. ErrCode::notenough_gold_msg);
  88. array_push($targteHeroSkills->$mainSkillId, $subSkillId); # 添加技能
  89. $targetHero->subSkills = $targteHeroSkills;
  90. $cHeros->$huid = $targetHero; # 回存Hero对象
  91. UserProc::updateUserInfo(); # 回写数据
  92. TaskProc::OnHeroUnlocSkill($targetHero->typeId, $subSkillId);
  93. return Resp::ok($targetHero);
  94. }
  95. /**
  96. * [6325] 英雄技能一键升级
  97. * @param req $req
  98. */
  99. static function OnekeyUpgradeSkillLevel($req) {
  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($cHeros->$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. * @param req $req
  128. */
  129. static function UpgradeSkillLevel($req) {
  130. list($huid, $mainSkillId, $subSkillId) = $req->paras; # 提取参数: 英雄的UID, 主技能Id, 要升级的子技能Id
  131. $user = $req->userInfo->game; # user引用
  132. $collectHeros = $user->heros->collectHeros;
  133. my_default_Obj($collectHeros); # 防御变量为空
  134. my_Assert(CommUtil::isPropertyExists($collectHeros, $huid), ErrCode::hero_no); # 1.检查是否存在要升级的英雄
  135. $targetHero = new Ins_UserHero($collectHeros->$huid);
  136. $targteHeroSkills = $targetHero->subSkills; # 取出这个英雄的技能数据
  137. my_Assert(CommUtil::isPropertyExists($targteHeroSkills, $mainSkillId), "玩家数据结构有问题."); # 主技能Id.
  138. my_Assert(CommUtil::isInArray($targteHeroSkills->$mainSkillId, $subSkillId), "子技能id错误"); # 子技能id
  139. my_Assert($targetHero->IsSkillUpdateAble($mainSkillId, $subSkillId), ErrCode::hero_upgradeSkill_maxLevel); # 3.判断技能等级能否在继续升级了
  140. $sm = GameConfig::subSkill_getItem($subSkillId); # 4.取出该技能升级消耗的常量数据
  141. my_Assert(null != $sm, ErrCode::err_const_no); # 找不到子技能配置数据
  142. my_Assert(Data_UserGame::Consume_Gold($user->baseInfo, $sm->upgradeCost), ErrCode::notenough_gold_msg); # 5. 扣除金币消耗
  143. unset($targteHeroSkills->$mainSkillId, $subSkillId); # 替换技能
  144. array_push($targteHeroSkills->$mainSkillId, $sm->nextLevel_Id);
  145. $targetHero->subSkills = $targteHeroSkills;
  146. $collectHeros->$huid = $targetHero; # 更新hero数据
  147. UserProc::updateUserInfo(); # 回写数据
  148. return Resp::ok($targetHero);
  149. }
  150. // </editor-fold>
  151. //
  152. // <editor-fold defaultstate="collapsed" desc="英雄 强化">
  153. /**
  154. * 6304 英雄 升阶(消耗碎片)
  155. * @param Req $req
  156. */
  157. static function HeroStageUp($req) {
  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. # 扣除碎片成功
  170. $upHero->grade = $nextGrade; # 5.强化英雄进行成功升阶
  171. $collectHeros->$huid = $upHero; # 更新Hero数据
  172. UserProc::updateUserInfo(); # 6.数据回存
  173. $resp = Resp::ok($upHero);
  174. SystemProc::insertHero_StageUp($req->zoneid, $req->uid, $user->baseInfo->name, # # 插入系统广播
  175. GameConfig::hero_getItem($upHero->typeId)->name, $upHero->grade);
  176. self::CalcUserFightPower($req->zoneid, $req->uid, $req->userInfo->game); # 跟新战力统计
  177. TaskProc::OnHeroGradeUp($upHero->typeId, $upHero->grade);
  178. // var_dump($user->task->taskListDaily);
  179. return $resp;
  180. }
  181. /**
  182. * [6301] 英雄升级 - 消耗经验道具,获得经验(按照经验提升等级)
  183. * @param Req $req
  184. */
  185. static function HeroLevelUpCostExpItem($req) {
  186. list($huid, $costItemId, $costNumber) = $req->paras; # 提取参数: 玩家英雄实例编号, 消耗的道具ID, 消耗的道具数量
  187. $user = $req->userInfo->game; # user引用
  188. $collectHeros = $user->heros->collectHeros; # 1. 检查是否存在要升级的英雄
  189. my_default_Obj($collectHeros);
  190. my_Assert(is_int($costNumber) && $costNumber >= 1, ErrCode::paras_err); # 参数合法性判断
  191. my_Assert(CommUtil::isPropertyExists($collectHeros, $huid), ErrCode::hero_no); # 玩家拥有此英雄
  192. $targetHero = new Ins_UserHero($collectHeros->$huid); #
  193. my_Assert($targetHero->HeroCanLevelUp(), "请提升指挥官等级."); # 2. 检查玩家等级是否可以继续升级, Ps. 全局限制 + 指挥官等级限制
  194. $myPacketItems = $user->store->items; # 检查道具的数量,在背包中是否充足
  195. my_Assert(CommUtil::isPropertyExists($myPacketItems, $costItemId), ErrCode::store_itemnotenough); #
  196. my_Assert($myPacketItems->$costItemId >= $costNumber, ErrCode::store_itemnotenough);
  197. $initLevel = $targetHero->level; # 初始等级
  198. $totalEXP = 0; # 4.计算消耗的道具一共给多少经验值以及 一共要消耗多少金币
  199. $costItemConst = GameConfig::item_stones_getItem($costItemId);
  200. my_Assert(null != $costItemConst, ErrCode::err_const_no);
  201. $totalEXP += $costItemConst->baseExp;
  202. $heroConst = GameConfig::hero_getItem($targetHero->typeId); # 英雄模板数据
  203. my_Assert(null != $heroConst, ErrCode::err_const_no, "英雄 模板数据");
  204. if ($costItemConst->element != 0 # # 相同元素加成
  205. && $costItemConst->element == $heroConst->element) {
  206. $totalEXP += $costItemConst->extraExp;
  207. }
  208. $totalEXP *= $costNumber; # 消耗N个道具
  209. $targetHero = self:: HeroAddEXP($huid, $totalEXP); # 获得经验
  210. $myPacketItems->$costItemId -= $costNumber; # 消耗道具
  211. if ($myPacketItems->$costItemId < 0) {
  212. $myPacketItems->$costItemId = 0;
  213. }
  214. $req->userInfo->game->store->items = $myPacketItems; # 更新背包数据
  215. my_Assert($targetHero->xp >= 0, "英雄经验出错");
  216. UserProc::updateUserInfo(); # 回写玩家数据
  217. TaskProc::OnHeroImprove();
  218. self::CalcUserFightPower($req->zoneid, $req->uid, $req->userInfo->game); # 跟新战力统计
  219. $ret = array(
  220. 'hero' => $targetHero,
  221. 'store' => $user->store
  222. );
  223. return Resp::ok($ret);
  224. }
  225. // </editor-fold>
  226. //
  227. // <editor-fold defaultstate="collapsed" desc="队伍配置">
  228. /**
  229. * [6315]保存队伍的战斗配置信息
  230. * @param Req $req
  231. */
  232. static function SaveHeroTeamConfig($req) {
  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. * @param type $req
  246. */
  247. static function UnLockHeroByPieces($req) {
  248. $user = $req->userInfo->game; # user引用
  249. $heroModelId = $req->paras[0];
  250. $piecesId = $req->paras[1]; # 英雄碎片的ID
  251. $piecesNum = $req->paras[2];
  252. if (!CommUtil::isPropertyExists($user->heros, "recordUnLockHeroDic")) {
  253. $user->heros->recordUnLockHeroDic = ObjectInit();
  254. }
  255. $recordUnLockHeroDic = $user->heros->recordUnLockHeroDic;
  256. #检查是不是已经解锁过了
  257. $flag = 0;
  258. if (!CommUtil::isPropertyExists($recordUnLockHeroDic, $heroModelId)) {
  259. $recordUnLockHeroDic->$heroModelId = 0;
  260. }
  261. $flag = $recordUnLockHeroDic->$heroModelId;
  262. if ($flag == 1) {
  263. return Resp::err(ErrCode::hero_lockState);
  264. }
  265. #检查要解锁的英雄的常量配置是否存在
  266. $heroCfg = GameConfig::hero_getItem($heroModelId);
  267. if (!$heroCfg) {
  268. return Resp::err(ErrCode::hero_const_no_err);
  269. }
  270. #检查需要消耗的碎片的常量配置是否存在
  271. $piecesCfg = GameConfig::segment_getItem($piecesId);
  272. if (!$piecesCfg) {
  273. return Resp::err(ErrCode::err_const_no);
  274. }
  275. # 5.检查道具的数量是否充足
  276. $myPacketItems = $user->store->segement;
  277. $requirePiecesNum = $heroCfg->unlockConditionId;
  278. # 检查道具数量是否充足
  279. $enoughPieces = false;
  280. if ($heroModelId == $piecesCfg->prototypeData && $requirePiecesNum == $piecesNum) {
  281. if (!CommUtil::isPropertyExists($myPacketItems, $piecesId)) { # 检查碎片
  282. $enoughPieces = false;
  283. } else {
  284. if ($myPacketItems->$piecesId < $requirePiecesNum) {
  285. $enoughPieces = false;
  286. } else {
  287. $enoughPieces = true;
  288. }
  289. }
  290. } else {
  291. return Resp::err(ErrCode ::paras_err, "error pieces para" . "req" . $piecesId . "_" . $requirePiecesNum . "/" . $piecesId . "_" . $piecesNum);
  292. }
  293. if ($enoughPieces === true) {
  294. # 6.进行 # # 消耗道具
  295. $myPacketItems->$piecesId -= $requirePiecesNum;
  296. if ($myPacketItems->$piecesId < 0) {
  297. $myPacketItems->$piecesId = 0;
  298. }
  299. $recordUnLockHeroDic->$heroModelId = 1;
  300. $req->user->heros->recordUnLockHeroDic = $recordUnLockHeroDic;
  301. $req->userInfo->game->store->segement = $myPacketItems;
  302. UserProc::updateUserInfo(); # 回写数据
  303. return Resp::ok(array('result' => "OK")); //返回OK
  304. } else {
  305. return Resp::err(ErrCode::hero_godblood_notengoughitem);
  306. }
  307. }
  308. /**
  309. * [6322] 英雄神血
  310. * @param Req $req
  311. */
  312. static function UpGodBloodHeroByPieces($req) {
  313. return Resp::err(ErrCode::err_method_obsoleted);
  314. }
  315. /**
  316. * 英雄消耗碎片道具来升星
  317. * @param req $req
  318. */
  319. static function HeroUpStarByPieces($req) {
  320. $resp = Resp::err(ErrCode::err_method_notimplement);
  321. $g = glc();
  322. $user = $req->userInfo->game; # user引用
  323. $huid = $req->paras[0]; # 英雄的UID
  324. $piecesId = $req->paras[1]; # 英雄碎片的ID
  325. $piecesNum = $req->paras[2];
  326. $diamondId = $req->paras[3]; # 升星石道具的ID
  327. $diamondNum = $req->paras[4];
  328. $moneyType = $req->paras[5]; # 升星消耗金钱的类型
  329. $moneyNum = $req->paras[6];
  330. # 1.检查是否存在要升级的英雄
  331. $collectHeros = $user->heros->collectHeros;
  332. if (!$collectHeros) {
  333. $collectHeros = ObjectInit();
  334. }
  335. if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
  336. return Resp::err(ErrCode::hero_no);
  337. }
  338. # 2.检查是否已经达到最大星级
  339. isEditor() and $strengthHero = new Ins_UserHero();
  340. $strengthHero = $collectHeros->$huid;
  341. if ($strengthHero->curStar >= $g->Hero_Star_MaxStarLevel) {
  342. return Resp::err(ErrCode::hero_star_maxstarlevel);
  343. }
  344. # 检查是否存在当前星级的升星消耗常量数据
  345. $lvs = GameConfig::heroextra_star_getItem($strengthHero->curStar);
  346. if (!$lvs) {
  347. return Resp::err(ErrCode::hero_star_level_const_no_err);
  348. }
  349. # 3检查是否存在这个英雄的模板
  350. $heroModelId = $strengthHero->typeId;
  351. $heroCfg = GameConfig::hero_getItem($heroModelId);
  352. if (!$heroCfg) {
  353. return Resp::err(ErrCode::hero_const_no_err);
  354. }
  355. # 4.检查道具的数量是否充足以及消耗数量是否一致
  356. $requireDiamondId = $lvs->itemid;
  357. $requireDiamondNum = 0;
  358. $arr_costDiamond = explode(";", $lvs->itemNum);
  359. foreach ($arr_costDiamond as $value) {
  360. $strArr = explode(",", $value);
  361. if (count($strArr) == 2) {
  362. $zhenxidu = $strArr[0];
  363. $num = $strArr[1];
  364. if ((int) $zhenxidu == $heroCfg->zhenxidu) {
  365. $requireDiamondNum = (int) $num;
  366. break;
  367. }
  368. }
  369. }
  370. #检查碎片是否正确
  371. $requirePieceId = $piecesId;
  372. $requirePiecesNum = 0;
  373. $arr_costPieces = explode(";", $lvs->pieces);
  374. foreach ($arr_costPieces as $value) {
  375. $strArr = explode(",", $value);
  376. if (count($strArr) == 2) {
  377. $zhenxidu = $strArr[0];
  378. $num = $strArr[1];
  379. if ((int) $zhenxidu == $heroCfg->zhenxidu) {
  380. $requirePiecesNum = (int) $num;
  381. break;
  382. }
  383. }
  384. }
  385. $piecesCfg = GameConfig::item_getItem($piecesId);
  386. if (!$piecesCfg) {
  387. return Resp::err(ErrCode::err_const_no);
  388. }
  389. $pos = strpos($piecesCfg->icon, strval($heroModelId));
  390. if ($pos === false) {
  391. return Resp::err(ErrCode::paras_err, $piecesCfg->icon . "?" . $heroModelId);
  392. }
  393. # 4.检查道具的数量是否充足
  394. $myPacketItems = $user->store->items;
  395. #检查道具数量是否充足
  396. $enoughDiamond = false;
  397. $enoughPieces = false;
  398. if ($requirePieceId == $piecesId && $requirePiecesNum == $piecesNum) {
  399. #检查碎片
  400. if (!CommUtil::isPropertyExists($myPacketItems, $requirePieceId)) {
  401. $enoughPieces = false;
  402. } else {
  403. if ($myPacketItems->$requirePieceId < $requirePiecesNum) {
  404. $enoughPieces = false;
  405. } else {
  406. $enoughPieces = true;
  407. }
  408. }
  409. } else {
  410. return Resp::err(ErrCode ::paras_err, #
  411. "error pieces para" . "req" . $requirePieceId . "_" . $requirePiecesNum . "/" . $piecesId . "_" . $piecesNum);
  412. }
  413. if ($requireDiamondId == $diamondId && $requireDiamondNum == $diamondNum) {
  414. #检查升星石
  415. if (!CommUtil::isPropertyExists($myPacketItems, $requireDiamondId)) {
  416. $enoughDiamond = false;
  417. } else {
  418. if ($myPacketItems->$requireDiamondId < $requireDiamondNum) {
  419. $enoughDiamond = false;
  420. } else {
  421. $enoughDiamond = true;
  422. }
  423. }
  424. } else {
  425. return Resp::err(ErrCode ::paras_err, #
  426. "error diamond para" . "req" . $requireDiamondId . "_" . $requireDiamondNum . "/" . $diamondId . "_" . $diamondNum);
  427. }
  428. if ($enoughDiamond === true && $enoughPieces === true) {
  429. } else {
  430. return Resp::err(ErrCode::hero_star_notengoughitem);
  431. }
  432. # 5.检查账户余额是否充足
  433. #检查消耗是否正确
  434. $enoughMoney = false;
  435. $requireMoneyType = "";
  436. $requireMoneyNum = 0;
  437. $arr_costMoney = explode(";", $lvs->cost);
  438. foreach ($arr_costMoney as $value) {
  439. $strArr = explode(",", $value);
  440. if (count($strArr) == 3) {
  441. $zhenxidu = $strArr[0];
  442. $type = $strArr[1];
  443. $num = $strArr[2];
  444. if ((int) $zhenxidu == $heroCfg->zhenxidu) {
  445. $requireMoneyType = $type;
  446. $requireMoneyNum = (int) $num;
  447. break;
  448. }
  449. }
  450. }
  451. if ($requireMoneyType == $moneyType && $requireMoneyNum == $moneyNum) {
  452. if ($requireMoneyType === "gold") {
  453. if ($user->baseInfo->gold >= $requireMoneyNum) {
  454. $enoughMoney = true;
  455. } else {
  456. return Resp::err(ErrCode::notenough_gold_msg);
  457. }
  458. } else if ($requireMoneyType === "cash") {
  459. if ($user->baseInfo->cash >= $requireMoneyNum) {
  460. $enoughMoney = true;
  461. } else {
  462. return Resp::err(ErrCode::notenough_cash_msg);
  463. }
  464. } else {
  465. return Resp::err(ErrCode ::paras_err, $moneyType);
  466. }
  467. } else {
  468. return Resp::err(ErrCode ::paras_err, "error money para");
  469. }
  470. $bDeal = false;
  471. if ($enoughMoney === true) {
  472. if ($requireMoneyType === "gold") {
  473. $bDeal = Data_UserGame:: Consume_Gold($user->baseInfo, $requireMoneyNum);
  474. } else if ($requireMoneyType === "cash") {
  475. $bDeal = Data_UserGame:: Consume_Cash($user->baseInfo, $requireMoneyNum);
  476. }
  477. }
  478. # 6.进行消耗升星
  479. if ($bDeal) {
  480. $strengthHero->curStar += 1;
  481. # # 消耗道具
  482. $myPacketItems->$requireDiamondId -= $requireDiamondNum;
  483. if ($myPacketItems->$requireDiamondId < 0) {
  484. $myPacketItems->$requireDiamondId = 0;
  485. }
  486. $myPacketItems->$requirePieceId -= $requirePiecesNum;
  487. if ($myPacketItems->$requirePieceId < 0) {
  488. $myPacketItems->$requirePieceId = 0;
  489. }
  490. $req->userInfo->game->store->items = $myPacketItems;
  491. # 回写数据
  492. UserProc::updateUserInfo();
  493. $resp = Resp::ok($strengthHero);
  494. # 推送系统消息
  495. // SystemProc::insertHero_Star($req->zoneid, $req->uid, $user->name, $heroCfg->name, $strengthHero->curStar);
  496. }
  497. ActiveProc::ChangeTaskCount($req);
  498. return $resp;
  499. }
  500. /**
  501. * 英雄升星
  502. * @param Req $req
  503. */
  504. static function HeroUpStar($req) {
  505. $resp = Resp::err(ErrCode::err_method_notimplement);
  506. $g = glc();
  507. $user = $req->userInfo->game; # user引用
  508. $huid = $req->paras[0]; # 英雄的UID
  509. $costHeroUids = $req->paras[1]; # 消耗掉的英雄UID
  510. $costGold = $req->paras[2];
  511. # 1.检查是否存在要升级的英雄
  512. $collectHeros = $user->heros->collectHeros;
  513. if (!$collectHeros) {
  514. $collectHeros = ObjectInit();
  515. }
  516. if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
  517. return Resp::err(ErrCode::hero_no);
  518. }
  519. # 2.检查是否已经达到最大星级
  520. isEditor() and $strengthHero = new Ins_UserHero();
  521. $strengthHero = $collectHeros->$huid;
  522. if ($strengthHero->curStar >= $g->Hero_Star_MaxStarLevel) {
  523. return Resp::err(ErrCode::hero_star_maxstarlevel);
  524. }
  525. # 检查是否存在当前星级的升星消耗常量数据
  526. $lvs = GameConfig::heroextra_star_getItem($strengthHero->curStar);
  527. if (!$lvs) {
  528. return Resp::err(ErrCode::hero_star_level_const_no_err);
  529. }
  530. # 3.检查消耗的英雄数量,以及玩家是否都存在这些英雄UID.
  531. $arr_costUID = explode(",", $costHeroUids);
  532. $checkCostHeroAllRight = true;
  533. if (count($arr_costUID) != $g->Hero_Star_MaxCostHeroCardNum) {
  534. $checkCostHeroAllRight = false;
  535. } else {
  536. foreach ($arr_costUID as $value) {
  537. if ($value == "" || !CommUtil::isPropertyExists($collectHeros, $value)) {
  538. $checkCostHeroAllRight = false;
  539. break;
  540. }
  541. }
  542. }
  543. if (!$checkCostHeroAllRight) {
  544. return Resp::err(ErrCode::hero_star_costhero);
  545. }
  546. # 获得升星英雄的模板数据,取得它的元素类型
  547. # 检查是否存在这个英雄的模板
  548. $heroModelId = $strengthHero->typeId;
  549. $heroCfg = GameConfig::hero_getItem($heroModelId);
  550. if (!$heroCfg) {
  551. return Resp::err(ErrCode::hero_const_no_err);
  552. }
  553. $queryCostGold = $lvs->costGold;
  554. $costItemNum = $lvs->costItemNum;
  555. # 4.检查道具的数量是否充足
  556. $myPacketItems = $user->store->items;
  557. $checkHasEnoughItem = true;
  558. $costItemId = "";
  559. $record = ObjectInit();
  560. $keyxxx = "Hero_Star_CostItem_" . $heroCfg->yuansu;
  561. if (!CommUtil::isPropertyExists($g, $keyxxx)) {
  562. return Resp::err(ErrCode::hero_star_noglobal_costitem);
  563. } else {
  564. $costItemId = $g->$keyxxx;
  565. }
  566. # 检查道具种类与消耗数量是否匹配
  567. $arr_costitemids = explode(",", $costItemId);
  568. $arr_costnums = explode(",", $costItemNum);
  569. if (count($arr_costitemids) != count($arr_costnums)) {
  570. return Resp::err(ErrCode::hero_star_conststr_itemnotmathnum);
  571. }
  572. $index = 0;
  573. foreach ($arr_costitemids as $requireiItemId) {
  574. $requireCount = 0;
  575. if ($index < count($arr_costnums)) {
  576. $requireCount = $arr_costnums[$index];
  577. }
  578. $index += 1;
  579. # --判断对应的item是否存在相应的常量
  580. # 检查是否存在当前星级的升星消耗常量数据
  581. $itemcfg = GameConfig::item_getItem($requireiItemId);
  582. if (!$itemcfg) {
  583. return Resp::err(ErrCode::err_const_no);
  584. } else {
  585. if (!CommUtil::isPropertyExists($record, $requireiItemId)) {
  586. $record->$requireiItemId = intval($requireCount);
  587. } else {
  588. $count = intval($record->$requireiItemId) + intval($requireCount);
  589. $record->$requireiItemId = $count;
  590. }
  591. }
  592. } foreach ($record as $key => $value) {
  593. if ($value > 0) {
  594. if (!CommUtil::isPropertyExists($myPacketItems, $key)) {
  595. $checkHasEnoughItem = false;
  596. break;
  597. } else {
  598. if ($myPacketItems->$key < $value) {
  599. $checkHasEnoughItem = false;
  600. break;
  601. }
  602. }
  603. }
  604. }
  605. if (!$checkHasEnoughItem) {
  606. return Resp::err(ErrCode::hero_star_notengoughitem);
  607. }
  608. # 5.检查金币是否充足
  609. $bDeal = false; # 成交
  610. if ($queryCostGold != $costGold) {
  611. return Resp::err(ErrCode::paras_err);
  612. } else {
  613. if ($costGold > 0) {
  614. if ($user->baseInfo->gold < $costGold) {
  615. return Resp::err(ErrCode::notenough_gold_msg);
  616. } else {
  617. $bDeal = Data_UserGame:: Consume_Gold($user->baseInfo, $costGold);
  618. }
  619. } else if ($costGold == 0) {
  620. $bDeal = true;
  621. } else {
  622. return Resp::err(ErrCode::paras_err);
  623. }
  624. }
  625. # 6.进行消耗升星
  626. if ($bDeal) {
  627. $strengthHero->curStar += 1;
  628. # 消耗卡牌
  629. foreach ($arr_costUID as $value) {
  630. if ($value == "") {
  631. continue;
  632. }
  633. unset($collectHeros->$value);
  634. }
  635. # # 消耗道具
  636. foreach ($record as $key => $value) {
  637. $myPacketItems->$key -= $value;
  638. if ($myPacketItems->$key < 0) {
  639. $myPacketItems->$key = 0;
  640. }
  641. }
  642. $req->userInfo->game->store->items = $myPacketItems;
  643. # 回写数据
  644. UserProc::updateUserInfo();
  645. $resp = Resp::ok($strengthHero);
  646. # 推送系统消息
  647. // SystemProc::insertHero_Star($req->zoneid, $req->uid, $user->name, $heroCfg->name, $strengthHero->curStar);
  648. }
  649. ActiveProc::ChangeTaskCount($req);
  650. return $resp;
  651. }
  652. // </editor-fold>
  653. /**
  654. * 6321 购买英雄 消耗碎片
  655. * @param req $req
  656. */
  657. static function BuyHeroByCostPieces($req) {
  658. list($heroModelId, $costType, $costMoneyNum, $piecesId, $piecesNum) = $req->paras; # 提取参数
  659. $user = $req->userInfo->game; # user引用
  660. $collectHeros = $user->heros->collectHeros;
  661. my_default_Obj($collectHeros);
  662. foreach ($collectHeros as $key => $value) { # 检查玩家是否已经拥有此类英雄
  663. my_Assert($value->typeId != $heroModelId, ErrCode::hero_existSameHero_err);
  664. }
  665. $heroCfg = GameConfig::hero_getItem($heroModelId); # 英雄模板数据
  666. my_Assert(null != $heroCfg, ErrCode::hero_const_no_err);
  667. my_Assert($heroCfg->isCanBuy != 0, ErrCode::paras_err); # 是否可以直接购买
  668. $piecesCfg = GameConfig::segment_getItem($piecesId); # 检查需要消耗的碎片的常量配置是否存在
  669. my_Assert(null != $piecesCfg, ErrCode::err_store_itemnoconst);
  670. $myPacketItems = $user->store->items;
  671. $requirePiecesNum = $piecesCfg->mergePrototypeNeedNum;
  672. my_Assert($heroModelId == $piecesCfg->prototypeData && $requirePiecesNum == $piecesNum, ErrCode::paras_err);
  673. my_Assert(CommUtil::isPropertyExists($myPacketItems, $piecesId), ErrCode::hero_godblood_notengoughitem);
  674. my_Assert($myPacketItems->$piecesId > $requirePiecesNum, ErrCode::hero_godblood_notengoughitem); # 检查碎片道具数量是否充足
  675. switch ($costType) {
  676. case "cash":
  677. $realPrice = $heroCfg->cashPrice;
  678. my_Assert($realPrice == $costMoneyNum, ErrCode::paras_err);
  679. my_Assert($costMoneyNum >= 0, ErrCode::paras_err);
  680. my_Assert(Data_UserGame::Consume_Cash($user->baseInfo, $costMoneyNum), ErrCode::err_msg_cashnotenough);
  681. break;
  682. case "gold":
  683. $realPrice = $heroCfg->goldPrice;
  684. my_Assert($realPrice == $costMoneyNum, ErrCode::paras_err);
  685. my_Assert($costMoneyNum >= 0, ErrCode::paras_err);
  686. my_Assert(Data_UserGame::Consume_Gold($user->baseInfo, $costMoneyNum), ErrCode::err_msg_goldnotenough);
  687. break;
  688. default :
  689. Err(ErrCode::paras_err, "参数错误: [costType] " . $costType);
  690. }
  691. # 4.消耗来获得英雄
  692. $myPacketItems->$piecesId -= $requirePiecesNum; # 消耗道具
  693. $req->userInfo->game->store->items = $myPacketItems; # 回存背包
  694. UserProc::updateUserInfo(); # 回写数据
  695. $resp = HeroProc::GetHero($req);
  696. SystemProc::GetHero($req->zoneid, $user->baseInfo, $heroModelId); # 插入系统广播消息
  697. return $resp;
  698. }
  699. /**
  700. * 购买玩家可以收集的英雄的数量上限
  701. * @param req $req
  702. * @return type
  703. */
  704. static function BuyHeroMaxCountLimt($req) {
  705. list($buyNum, $costCash) = $req->paras; # 提取参数: 数量, 花费钻石
  706. $g = glc();
  707. $user = $req->userInfo->game; # user引用
  708. if (!CommUtil::isPropertyExists($user->heros, "maxCollectCount")) {
  709. $user->heros->maxCollectCount = $g->Game_CollectHero_BasicMaxCount;
  710. }
  711. $index = ceil(($user->heros->maxCollectCount - $g->Game_CollectHero_BasicMaxCount) #
  712. / $g->Game_CollectHero_OneBuyLimtNum);
  713. $arr = explode(",", $g->Game_CollectHero_BasicMaxPrice);
  714. my_Assert($index < count($arr), "已达上限");
  715. $realCost = $arr[$index];
  716. my_Assert($realCost == $costCash, ErrCode::paras_err); # 参数错误
  717. my_Assert($costCash >= 0, ErrCode::paras_err);
  718. my_Assert(Data_UserGame::Consume_Cash($user->baseInfo, $costCash), ErrCode::err_msg_goldnotenough); # 扣除宝石
  719. $user->heros->maxCollectCount += $buyNum; # 修改上限
  720. UserProc::updateUserInfo();
  721. return Resp::ok(array(
  722. 'maxCollectCount' => $user->heros->maxCollectCount
  723. ));
  724. }
  725. /**
  726. * 获得英雄(测试已经OK)
  727. * @param req $req
  728. */
  729. static function GetHero($req) {
  730. $heroModelId = $req->paras[0]; # 英雄的模板ID
  731. $heroCfg = GameConfig::hero_getItem($heroModelId); # 1.检查是否存在这个英雄的模板
  732. my_Assert(null != $heroCfg, ErrCode::hero_const_no_err);
  733. $hero = self::AddHeroTFromStore($req, $heroModelId); # 创建英雄
  734. UserProc::updateUserInfo();
  735. $result = array('result' => "succeed", 'heros' => $hero); # 4. 设置返回值
  736. return Resp::ok($result);
  737. }
  738. // <editor-fold defaultstate="collapsed" desc="辅助方法">
  739. /**
  740. * 获得一个英雄, 并且给他指定星级
  741. * @param Req $req
  742. * @param int $heromodelId 原型数据id
  743. * @param int $star 星级
  744. * @return Ins_UserHero
  745. */
  746. static function AddHeroWithStar(&$req, $heromodelId, $star) {
  747. $user = $req->userInfo->game;
  748. my_Assert(null != $user, ErrCode::err_innerfault);
  749. $collectHeros = $user->heros->collectHeros;
  750. $uid = self::CreateNewGameHeroUID($collectHeros, $user->heros->recordMaxUID); # 先生成一个hero的UID
  751. $user->heros->recordMaxUID = $uid;
  752. $hero = self::getGameHeroModelInstance($heromodelId, $uid);
  753. if ($star > 0) {
  754. $hero->curStar = $star; # 设定star
  755. }
  756. $collectHeros->$uid = $hero; # 回写
  757. $user->heros->collectHeros = $collectHeros; # 回写
  758. return $hero; # 返回
  759. }
  760. /**
  761. * 获得一个英雄(实例)
  762. * @param req $req
  763. * @param int $heromodelId
  764. * @return type
  765. */
  766. static function AddHeroTFromStore(&$req, $heromodelId) {
  767. $user = $req->userInfo->game; # 玩家数据
  768. $collectHeros = $user->heros->collectHeros; #
  769. my_default_Obj($collectHeros);
  770. $uid = self::CreateNewGameHeroUID($collectHeros, $user->heros->recordMaxUID); # 先生成一个UID
  771. $user->heros->recordMaxUID = $uid; # 更新最大编号记录
  772. $hero = self::getGameHeroModelInstance($heromodelId, $uid); # 3.创建英雄实例
  773. $collectHeros->$uid = $hero;
  774. $user->heros->collectHeros = $collectHeros;
  775. return $hero;
  776. }
  777. /**
  778. * 根据一个英雄的模板id,来获得一个英雄的实例数据
  779. * @param string $heroModelId 模板数据ID
  780. * @param string $uid 唯一ID
  781. * @return Ins_UserHero
  782. */
  783. static function getGameHeroModelInstance($heroModelId, $uid) {
  784. $heroCfg = GameConfig::hero_getItem($heroModelId);
  785. my_Assert(null != $heroCfg, ErrCode::err_const_no); # 检查是否存在这个英雄的模板
  786. $hero = new Ins_UserHero();
  787. // $hero->strengthLevel = $heroCfg->dengjie;
  788. $hero->curStar = $heroCfg->xingji;
  789. $hero->typeId = $heroCfg->heroId;
  790. $hero->uid = $uid;
  791. $hero->xp = 0;
  792. $lvs = GameConfig::hero_levelexp_getItem($hero->level + 1);
  793. $hero->maxXp = $lvs->requiredExp;
  794. // 取可用武器中第一个初始化 -- 策划要求初始英雄要带有武器 -- 王刚 2020年1月
  795. $wp = null;
  796. $arr = (array) GameConfig::item_weapon();
  797. ksort($arr); // todo: 排序不正常
  798. foreach ($arr as $id => $mo) {
  799. // isEditor() and $mo = new \sm_item_weapon();
  800. if ($mo->hero_id == $hero->typeId) {
  801. $wp = $mo;
  802. break;
  803. }
  804. }
  805. if (null != $wp) {
  806. $req = req();
  807. $wuid = StoreProc::PutEquipInStore($wp->typeId, $req);
  808. $req->userInfo->game->store->equipment->$wuid->herouid = $uid;
  809. $hero->equip->weapon = array("itemuid" => $wuid);
  810. }
  811. return $hero;
  812. }
  813. /**
  814. * 查找下一个玩家获得英雄的UID
  815. * @param type $req
  816. * @return int
  817. */
  818. static function CreateNewGameHeroUID($collectHeros, $oldMaxUID) {
  819. $maxID = 10000;
  820. my_default_Obj($collectHeros);
  821. foreach ($collectHeros as $itemId => $hero) {
  822. if ($itemId > $maxID) {
  823. $maxID = $itemId;
  824. }
  825. }
  826. $max = max($maxID, $oldMaxUID);
  827. return $max + 1;
  828. }
  829. /**
  830. * 英雄卡牌增加经验值
  831. * @param string $heroUID
  832. * @param int $totalEXP
  833. */
  834. static function HeroAddEXP($heroUID, $totalEXP) {
  835. $req = req();
  836. $collectHeros = $req->userInfo->game->heros->collectHeros;
  837. my_default_Obj($collectHeros);
  838. my_Assert(CommUtil::isPropertyExists($collectHeros, $heroUID), ErrCode::hero_no); # 要升级的英雄不存在
  839. $targetHero = new Ins_UserHero($collectHeros->$heroUID); # 英雄对象
  840. $playerLimit = GameConfig::playerlevel_getItem($req->userInfo->game->baseInfo->level)->hero_max_level;
  841. $maxLevel = min(glc()->Hero_Upgrade_BasicMaxLevel, $playerLimit); # 最大等级= max(英雄最高等级上限,玩家等级限制的上限)
  842. if ($targetHero->level >= $maxLevel) {
  843. return; # 已达顶级
  844. }
  845. $lvs = GameConfig::hero_levelexp_getItem($targetHero->level + 1);
  846. $targetHero->xp += $totalEXP;
  847. my_Assert($targetHero->xp >= 0, "[" . $req->uid . "] : HeroLevelUpgrade Exp is negative!");
  848. $initLevel = $targetHero->level;
  849. while ($targetHero->xp >= $lvs->needExp) {
  850. if ($targetHero->level < $maxLevel) { # 如果未到达最大等级
  851. $targetHero->level += 1;
  852. if ($targetHero->level >= $maxLevel) {
  853. $targetHero->xp = $lvs->needExp;
  854. } else {
  855. $targetHero->xp -= $lvs->needExp;
  856. }
  857. $lvs = GameConfig::hero_levelexp_getItem($targetHero->level + 1);
  858. } else { # 如果已到达最大等级则仅补齐缺失的经验即可
  859. $targetHero->xp = $targetHero->maxXp; # 经验不能超过最大值
  860. break;
  861. }
  862. } // end while
  863. my_Assert($targetHero->xp >= 0, "[" . $req->uid . "] : HeroLevelUpgrade Exp is negative!");
  864. $collectHeros->$heroUID = $targetHero; # 更新英雄的数据
  865. if ($targetHero->level != $initLevel) {
  866. NormalEventProc::OnHeroLvlUp($targetHero->uid, $initLevel); # 广播英雄升级事件
  867. }
  868. TaskProc::OnHeroLevelUp($targetHero->typeId, $targetHero->level);
  869. return $targetHero; # 将英雄对象返回
  870. }
  871. // </editor-fold>
  872. /**
  873. * [6306] 英雄-更改英雄的锁定状态
  874. * (测试已经OK)
  875. * @param type $req
  876. */
  877. static function HeroChangelockstate($req) {
  878. $gamedata = $req->userInfo->game;
  879. $heroUID = $req->paras[0]; # 玩家英雄实例编号
  880. $lockstate = $req->paras[1]; # 玩家英雄锁定状态
  881. $collectHeros = $gamedata->heros->collectHeros;
  882. my_default_Obj($collectHeros); # 默认值
  883. my_Assert(CommUtil::isPropertyExists($collectHeros, $heroUID), ErrCode::hero_no);
  884. // isEditor() and $hero = new UserHeroModel;
  885. $hero = $collectHeros->$heroUID; # 1. 获取这个英雄的实例数据是
  886. $hero->isLocked = $lockstate; # 2. 修改英雄状态
  887. UserProc::updateUserInfo(); # 3. 保存玩家数据
  888. return Resp::ok(ObjectInit()); # 4. 设置返回值
  889. }
  890. /* * 6326
  891. * 言灵升星
  892. * @param req $req
  893. * @return type
  894. */
  895. static function StrengthenStar($req) {
  896. list($yanlingUid, $uidList) = $req->paras;
  897. $store = $req->userInfo->game->store;
  898. my_Assert(StlUtil::dictHasProperty($store->yanling, $yanlingUid), ErrCode::hero_yanling_notfound);
  899. my_Assert(!in_array($yanlingUid, $uidList), ErrCode::hero_yanling_repeat);
  900. my_Assert($store->yanling->$yanlingUid->starLv < 5, ErrCode::hero_yanling_repeat);
  901. $tag = true;
  902. foreach ($uidList as $costUid) {
  903. if (StlUtil::dictHasProperty($store->yanling, $costUid)) { // 校验是否是同类型
  904. $confDic = GameConfig::item_yanling_getItem($store->yanling->$costUid->typeId);
  905. my_Assert(null != $confDic, ErrCode::hero_const_no_err);
  906. if ($confDic->type != GameConfig::item_yanling_getItem($store->yanling->$yanlingUid->typeId)->type) {
  907. $tag = false;
  908. break;
  909. }
  910. } else {
  911. $tag = false;
  912. break;
  913. }
  914. }
  915. my_Assert($tag, ErrCode::hero_yanling_notfound);
  916. $exp = 0;
  917. foreach ($uidList as $costuid) {
  918. $confDic = GameConfig::item_yanling_getItem($store->yanling->$costUid->typeId);
  919. my_Assert(null != $confDic, ErrCode::hero_const_no_err);
  920. $exp += $confDic->addStarExp;
  921. StlUtil::dictRemove($store->yanling, $costuid);
  922. }
  923. $store->yanling->$yanlingUid->curStarExp += $exp;
  924. $dic = GameConfig::item_yanling_getItem($store->yanling->$yanlingUid->typeId);
  925. if ($store->yanling->$yanlingUid->curStarExp >= $dic->maxStarExp) {
  926. $store->yanling->$yanlingUid->curStarExp = 0;
  927. $store->yanling->$yanlingUid->starLv += 1;
  928. $store->yanling->$yanlingUid->typeId = $dic->nextId;
  929. }
  930. $req->userInfo->game->store = $store;
  931. UserProc::updateUserInfo();
  932. return Resp::ok(array('store' => $req->userInfo->game->store,));
  933. }
  934. /** 6327
  935. * 言灵升级
  936. * @param req $req
  937. */
  938. static function YanlinUpLevel($req) {
  939. list($yanlingUid, $type) = $req->paras; # 参数: 言灵uid,升级类型:1/5级.
  940. $store = $req->userInfo->game->store;
  941. my_Assert(StlUtil::dictHasProperty($store->yanling, $yanlingUid), ErrCode::hero_yanling_notfound);
  942. $allDic = GameConfig::yanlingLeve();
  943. $maxLevel = count((array) $allDic);
  944. $curlv = $store->yanling->$yanlingUid->level;
  945. my_Assert($curlv <= $req->userInfo->game->baseInfo->level, "请提升指挥官等级."); # 言灵等级不能超过指挥官等级.-gwang 2021.4.20
  946. my_Assert($curlv < $maxLevel, ErrCode::hero_yanling_levelMax);
  947. $maxLv = $curlv + $type;
  948. if ($maxLv > $maxLevel) {
  949. $maxLv = $maxLevel;
  950. }
  951. $goldNum = 0;
  952. $pointNum = 0;
  953. for ($index = $curlv; $index < $maxLv; $index++) {
  954. my_Assert(StlUtil::dictHasProperty($allDic, $index), ErrCode::hero_yanling_levelconst_no);
  955. $mo = GameConfig::yanlingLeve_getItem($index);
  956. $goldNum += $mo->goldCost;
  957. $pointNum += $mo->pointCost;
  958. }
  959. my_Assert(Data_UserGame::Consume_Gold($req->userInfo->game->baseInfo, $goldNum), ErrCode::notenough_gold_msg);
  960. my_Assert(Data_UserGame::Consume_ResPoint($req->userInfo->game->baseInfo, $pointNum), ErrCode::notenough_resPoint);
  961. $store->yanling->$yanlingUid->level += $type; # 增加等级
  962. if ($store->yanling->$yanlingUid->level > $maxLevel) {
  963. $store->yanling->$yanlingUid->level = $maxLevel;
  964. }
  965. TaskProc::OnYanlingLevelUp($store->yanling->$yanlingUid->typeId, $store->yanling->$yanlingUid->level); # 言灵升级
  966. $req->userInfo->game->store = $store;
  967. UserProc::updateUserInfo(); # 回写玩家数据
  968. return Resp::ok(array('store' => $req->userInfo->game->store, #
  969. 'gold' => $req->userInfo->game->baseInfo->gold, #
  970. 'resPoint' => $req->userInfo->game->baseInfo->resPoint));
  971. }
  972. //
  973. // <editor-fold defaultstate="collapsed" desc="计算战队战斗力, for pvp back matchers, -wg 2017.07.13">
  974. /**
  975. * 计算队伍战斗力, 添加到战斗力隐藏榜单中, for pvp back matchers, -wg 2017.07.13
  976. * @param type $zoneid
  977. * @param type $uid
  978. * @param Data_UserGame $user
  979. * @return type
  980. */
  981. static function CalcTeamFightPower($zoneid, $uid, $user) {
  982. $teamsetting = $user->heroTeamConfig; # 战队配置
  983. // var_dump($user);
  984. $heros = $user->heros;
  985. $teamCfg = JsonUtil::decode($teamsetting);
  986. $tid = $teamCfg->curUseTeamID;
  987. $team = $teamCfg->teamDic->$tid;
  988. $fp = 0; # 返回值
  989. if ($team) {
  990. foreach ($team->heros as $hid) {
  991. if ($hid) {
  992. $hero = $heros->collectHeros->$hid;
  993. if ($hero) {
  994. // $fp += self::calcHeroFightPower($hero);
  995. $h = new Ins_UserHero($hero);
  996. $fp += $h->GetPower();
  997. }
  998. }
  999. }
  1000. //todo: 这里的战斗力榜被总战力榜征用了key, 重启PVP机制时再
  1001. // gMem()->zadd(MemKey_GameRun::Game_FightPowerRank_zset($zoneid), array($uid => $fp));
  1002. }
  1003. return $fp;
  1004. }
  1005. /**
  1006. * 计算玩家总战斗力, 添加到战斗力榜单中
  1007. * @version 1.0.0 改造自原来的队伍战斗力统计方法 --gwang 2020.4.23
  1008. * @param type $zoneid
  1009. * @param type $uid
  1010. * @param Data_UserGame $user
  1011. * @return type
  1012. */
  1013. static function CalcUserFightPower($zoneid, $uid, $user) {
  1014. $fp = 0; # 总战力:返回值
  1015. foreach ($user->heros->collectHeros as $hid => $hero) {
  1016. $h = new Ins_UserHero($hero);
  1017. $fp += $h->GetPower();
  1018. }
  1019. $key_fp = MemKey_GameRun::Game_FightPowerRank_zset($zoneid); # 战力榜
  1020. $key_log = MemKey_GameRun::Game_Rank_FPowerBreakLog_hash($zoneid); # 突破记录
  1021. gMem()->zadd($key_fp, array($uid => $fp)); # 更新战力记录
  1022. foreach (GameConfig::rankreward_fpower() as $condition => $reward) { # 遍历突破奖励数据
  1023. if ($fp >= $condition && !gMem()->hexists($key_log, $condition)) { # 判断是否达成突破奖励标准
  1024. gMem()->hset($key_log, $condition, $uid); # 添加突破记录
  1025. CornerSignEventProc::OnRanking_PowerReward_new();
  1026. }
  1027. }
  1028. TaskProc::OnUserFightPowerN($fp);
  1029. return $fp;
  1030. }
  1031. /**
  1032. * 计算hero战斗力, for pvp back matchers, -wg 2017.07.13
  1033. * @param Ins_UserHero $hero
  1034. * @return int
  1035. */
  1036. static private function calcHeroFightPower($hero) {
  1037. $arr = explode(';', glc()->Battle_PowerFactor);
  1038. $factor = ArrayInit();
  1039. foreach ($arr as $s) {
  1040. $kv = explode(',', $s);
  1041. $k = $kv[0];
  1042. $v = $kv[1];
  1043. $factor[$k] = $v;
  1044. }
  1045. // todo: 哈哈, 奇葩的命名方案, 多处使用的命名不一致, 坑!
  1046. $a = (int) (self::calcHeroProperty($hero, 'hp') * $factor ["hp"] //
  1047. + $hero->level * 10);
  1048. return $a;
  1049. }
  1050. /**
  1051. * 计算hero的属性,, for pvp back matchers, -wg 2017.07.13
  1052. * @param Ins_UserHero $hero
  1053. * @param type $propertyname
  1054. */
  1055. private static function calcHeroProperty($hero, $propertyname) {
  1056. $val = 0;
  1057. if ($hero) {
  1058. $modle = GameConfig::hero_getItem($hero->typeId);
  1059. if ($modle) {
  1060. $extra = GameConfig::heroextra_level_getItem($hero->typeId, $hero->grade);
  1061. if ($extra) {
  1062. $val = (int) ($modle->$propertyname * (1 + $extra->$propertyname));
  1063. } else {
  1064. $val = $modle->$propertyname;
  1065. }
  1066. }
  1067. }
  1068. return $val;
  1069. }
  1070. // </editor-fold>
  1071. //
  1072. }