HeroProc.php 55 KB

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