HeroProc.php 52 KB

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