HeroProc.php 56 KB

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