HeroProc.php 51 KB

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