HeroProc.php 55 KB

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