HeroProc.php 56 KB

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