HeroProc.php 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 英雄处理逻辑
  5. * @author gwang
  6. */
  7. class HeroProc {
  8. //put your code here
  9. /**
  10. * 英雄处理逻辑分发
  11. * 所有的Proc中必须有这样一个方法
  12. * @param Req $req
  13. */
  14. static function procMain($req) {
  15. switch ($req->cmd) {
  16. case CmdCode::cmd_hero_levelup: # [6301] 英雄升级
  17. return HeroProc::HeroLevelUpCostExpItem($req);
  18. case CmdCode::cmd_hero_stageup: # 6304 英雄进阶 SABCD
  19. return HeroProc::HeroStageUp($req);
  20. // case CmdCode::cmd_hero_changelockstate: # [6306] 英雄-修改锁定状态
  21. // return HeroProc::HeroChangelockstate($req);
  22. // case CmdCode::cmd_hero_gethero: # [6308] 分解英雄
  23. // return HeroProc::GetHero($req);
  24. // case CmdCode::cmd_hero_strength: # [6309] 英雄升阶
  25. // return HeroProc::HeroStrength($req);
  26. // case CmdCode::cmd_hero_upstar: # [6305] 英雄升星
  27. // return HeroProc::HeroUpStarByPieces($req);
  28. // case CmdCode::cmd_hero_openFavor: # [6310] 英雄好感度解锁
  29. // return HeroProc::HeroOpenFavor($req);
  30. // case CmdCode::cmd_hero_separate: # [6311] 分解英雄
  31. // return HeroProc::HeroSeparate($req);
  32. // case CmdCode::cmd_hero_buyCollectHeroLimtCount: # [6312] 扩展英雄数量上限
  33. // return HeroProc::BuyHeroMaxCountLimt($req);
  34. // case CmdCode::cmd_hero_changefriendsupport: # [6313] 更换支援好友
  35. // return HeroProc::ChangeFriendSupport($req);
  36. case CmdCode::cmd_hero_upgradeSkillLevel: # [6314] 英雄的技能升级
  37. return HeroProc::UpgradeSkillLevel($req);
  38. case CmdCode::cmd_hero_saveHeroTeamConfig: # [6315] 保存玩家战队数据
  39. return HeroProc::SaveHeroTeamConfig($req);
  40. case CmdCode::cmd_hero_upGodBlood: # [6322] 神血升级
  41. return HeroProc::UpGodBloodHeroByPieces($req);
  42. // case CmdCode::cmd_hero_unlockByPieces: # [6323] 解锁碎片
  43. // return HeroProc::UnLockHeroByPieces($req);
  44. # --------- 英雄评论 -----------
  45. case CmdCode::cmd_hero_GetDiscuss: # [6316]拉取英雄评论
  46. return HeroDiscussProc::GetDiscusses($req);
  47. case CmdCode::cmd_hero_PostDiscuss: # [6317]对英雄发表评论
  48. return HeroDiscussProc::Post($req);
  49. case CmdCode::cmd_hero_DeleteDiscuss: # [6319]删除评论
  50. return HeroDiscussProc::DeletePost($req);
  51. case CmdCode::cmd_hero_PraiseDiscuss: # [6318]给某条评论点赞
  52. return HeroDiscussProc::PriaseMsg($req);
  53. case CmdCode::cmd_hero_scoreit: # [6320]给某个英雄评分
  54. return HeroDiscussProc::Score($req);
  55. #----------------------------------------------
  56. case CmdCode::cmd_hero_buyHero: # [6321]购买英雄
  57. return HeroProc::BuyHeroByCostPieces($req);
  58. default: # err: 未知的命令码
  59. return Resp::err(ErrCode::cmd_err);
  60. }
  61. }
  62. /**
  63. * 6304 英雄 升阶(消耗碎片)
  64. * @param Req $req
  65. */
  66. static function HeroStageUp($req) {
  67. $g = glc();
  68. $user = $req->userInfo->game; # user引用
  69. $huid = $req->paras[0]; # 英雄的UID
  70. $nextGrade = $req->paras[1]; # 下一阶
  71. $collectHeros = $user->heros->collectHeros; # 角色容器
  72. if (!$collectHeros) {
  73. $collectHeros = ObjectInit();
  74. }
  75. if (!CommUtil::isPropertyExists($collectHeros, $huid)) { # 1.检查是否存在要升级的英雄
  76. return Resp::err(ErrCode::hero_no);
  77. }
  78. isEditor() and $upHero = new UserHeroModel();
  79. $upHero = $collectHeros->$huid;
  80. if ($upHero->grade >= "S") { # 已经达到S级
  81. return Resp::err(ErrCode::hero_strength_maxstrengthlevel);
  82. }
  83. $heroUpgradeCostCfg = GameConfig::heroextra_level_getItem($upHero->typeId, $nextGrade);
  84. if (!$heroUpgradeCostCfg) { # 1.检查是否存在这个升阶数据的模板
  85. return Resp::err(ErrCode::hero_strength_cost_const_no);
  86. }
  87. $needSeg = $heroUpgradeCostCfg->segNum; # 2
  88. // if ($user->Consume_HeroSegment($user, # # 扣除碎片
  89. // $heroUpgradeCostCfg->segID, $heroUpgradeCostCfg->segNum)) {
  90. if (true) { # 扣除碎片直接成功
  91. $upHero->grade = $nextGrade; # 5.强化英雄进行成功升阶
  92. UserProc::updateUserInfo($req); //6.数据回存
  93. $resp = Resp::ok($upHero);
  94. SystemProc::insertHero_StageUp($req->zoneid, $req->uid, $user->name, #
  95. GameConfig::hero_getItem($upHero->typeId)->name, $upHero->grade);
  96. } else { # 碎片数量不足
  97. return Resp::err(ErrCode::hero_segment_not_enough);
  98. }
  99. return $resp;
  100. }
  101. /**
  102. * [6301] 英雄升级 - 消耗经验道具,获得经验(按照经验提升等级)
  103. * @param Req $req
  104. */
  105. static function HeroLevelUpCostExpItem($req) {
  106. $gcfg = glc();
  107. $user = $req->userInfo->game; # user引用
  108. $heroUID = $req->paras[0]; # 玩家英雄实例编号
  109. $costItemId = $req->paras[1]; # 消耗的道具ID
  110. $costNumber = $req->paras[2]; # 消耗的道具数量
  111. $collectHeros = $user->heros->collectHeros; // 1. 检查是否存在要升级的英雄
  112. if (!$collectHeros) {
  113. $collectHeros = ObjectInit();
  114. }
  115. if (!CommUtil::isPropertyExists($collectHeros, $heroUID)) {
  116. return Resp::err(ErrCode::hero_no);
  117. }
  118. isEditor() and $targetHero = new UserHeroModel;
  119. $targetHero = $collectHeros->$heroUID;
  120. $maxLevel = $gcfg->Hero_Upgrade_BasicMaxLevel;
  121. if ($targetHero->level >= $maxLevel) { // 2. 检查玩家等级是否达到当前等级上限
  122. return Resp::err(ErrCode::hero_upgrade_maxupgradelevel);
  123. }
  124. // 下面是检查道具的数量,在背包中是否充足
  125. $myPacketItems = $user->store->items; # 道具包裹
  126. if (!CommUtil::isPropertyExists($myPacketItems, $costItemId) || $myPacketItems->$costItemId < $costNumber) {
  127. return Resp::err(ErrCode::store_itemnotenough);
  128. }
  129. //4.计算消耗的道具一共给多少经验值以及 一共要消耗多少金币
  130. $totalEXP = 0;
  131. $costItemConst = GameConfig::item_stones_getItem($costItemId);
  132. if (!$costItemConst) {
  133. return Resp::err(ErrCode::err_const_no);
  134. } else {
  135. $totalEXP += $costItemConst->baseExp;
  136. }
  137. $heroConst = GameConfig::hero_getItem($targetHero->typeId); #
  138. if (null == $heroConst) {
  139. return \Resp::err(ErrCode::err_const_no, "英雄 模板数据");
  140. }
  141. if ($costItemConst->element != 0 # # 相同元素加成
  142. && $costItemConst->element == $heroConst->element) {
  143. $totalEXP += $costItemConst->extraExp;
  144. }
  145. self:: HeroAddEXP($heroUID, $totalEXP, $req); # 获得经验
  146. $myPacketItems->$costItemId -= $costNumber; # 消耗道具
  147. if ($myPacketItems->$costItemId < 0) {
  148. $myPacketItems->$costItemId = 0;
  149. }
  150. $req->userInfo->game->store->items = $myPacketItems;
  151. UserProc::updateUserInfo($req);
  152. return Resp::ok($targetHero);
  153. }
  154. // <editor-fold defaultstate="collapsed" desc="已过时代码">
  155. /**
  156. * 6323 解锁英雄
  157. * @param type $req
  158. */
  159. static function UnLockHeroByPieces($req) {
  160. $user = $req->userInfo->game; # user引用
  161. $heroModelId = $req->paras[0];
  162. $piecesId = $req->paras[1]; # 英雄碎片的ID
  163. $piecesNum = $req->paras[2];
  164. if (!CommUtil::isPropertyExists($user->heros, "recordUnLockHeroDic")) {
  165. $user->heros->recordUnLockHeroDic = ObjectInit();
  166. }
  167. $recordUnLockHeroDic = $user->heros->recordUnLockHeroDic;
  168. #检查是不是已经解锁过了
  169. $flag = 0;
  170. if (!CommUtil::isPropertyExists($recordUnLockHeroDic, $heroModelId)) {
  171. $recordUnLockHeroDic->$heroModelId = 0;
  172. }
  173. $flag = $recordUnLockHeroDic->$heroModelId;
  174. if ($flag == 1) {
  175. return Resp::err(ErrCode::hero_lockState);
  176. }
  177. #检查要解锁的英雄的常量配置是否存在
  178. $heroCfg = GameConfig::hero_getItem($heroModelId);
  179. if (!$heroCfg) {
  180. return Resp::err(ErrCode::hero_const_no_err);
  181. }
  182. #检查需要消耗的碎片的常量配置是否存在
  183. $piecesCfg = GameConfig::segment_getItem($piecesId);
  184. if (!$piecesCfg) {
  185. return Resp::err(ErrCode::err_const_no);
  186. }
  187. # 5.检查道具的数量是否充足
  188. $myPacketItems = $user->store->segement;
  189. $requirePiecesNum = $heroCfg->unlockConditionId;
  190. # 检查道具数量是否充足
  191. $enoughPieces = false;
  192. if ($heroModelId == $piecesCfg->prototypeData && $requirePiecesNum == $piecesNum) {
  193. if (!CommUtil::isPropertyExists($myPacketItems, $piecesId)) { # 检查碎片
  194. $enoughPieces = false;
  195. } else {
  196. if ($myPacketItems->$piecesId < $requirePiecesNum) {
  197. $enoughPieces = false;
  198. } else {
  199. $enoughPieces = true;
  200. }
  201. }
  202. } else {
  203. return Resp::err(ErrCode ::paras_err, "error pieces para" . "req" . $piecesId . "_" . $requirePiecesNum . "/" . $piecesId . "_" . $piecesNum);
  204. }
  205. if ($enoughPieces === true) {
  206. # 6.进行 # # 消耗道具
  207. $myPacketItems->$piecesId -= $requirePiecesNum;
  208. if ($myPacketItems->$piecesId < 0) {
  209. $myPacketItems->$piecesId = 0;
  210. }
  211. $recordUnLockHeroDic->$heroModelId = 1;
  212. $req->user->heros->recordUnLockHeroDic = $recordUnLockHeroDic;
  213. $req->userInfo->game->store->segement = $myPacketItems;
  214. UserProc::updateUserInfo($req); # 回写数据
  215. return Resp::ok(array('result' => "OK")); //返回OK
  216. } else {
  217. return Resp::err(ErrCode::hero_godblood_notengoughitem);
  218. }
  219. }
  220. /**
  221. * 购买英雄
  222. * @param type $req
  223. */
  224. static function BuyHero($req) {
  225. $user = $req->userInfo->game; # user引用
  226. $heroModelId = $req->paras[0];
  227. $costType = $req->paras[1];
  228. $costMoneyNum = $req->paras[2];
  229. #1 检查玩家是否已经拥有此类英雄
  230. $collectHeros = $user->heros->collectHeros;
  231. if (!$collectHeros) {
  232. $collectHeros = ObjectInit();
  233. }
  234. foreach ($collectHeros as $key => $value) {
  235. isEditor() and $value = new UserHeroModel();
  236. if ($value->typeId == $heroModelId) {
  237. return Resp::err(ErrCode::hero_existSameHero_err);
  238. }
  239. }
  240. $recordUnLockHeroDic = $user->heros->recordUnLockHeroDic;
  241. if (!$recordUnLockHeroDic) {
  242. $recordUnLockHeroDic = ObjectInit();
  243. }
  244. #检查是不是已经解锁过了
  245. $flag = 0;
  246. if (!CommUtil::isPropertyExists($recordUnLockHeroDic, $heroModelId)) {
  247. $recordUnLockHeroDic->$heroModelId = 0;
  248. }
  249. $flag = $recordUnLockHeroDic->$heroModelId;
  250. if ($flag == 0) {
  251. return Resp::err(ErrCode::hero_lockState);
  252. }
  253. #2 检查账户余额是否充足
  254. $heroCfg = GameConfig::hero_getItem($heroModelId);
  255. if (!$heroCfg) {
  256. return Resp::err(ErrCode::hero_const_no_err);
  257. }
  258. if ($heroCfg->isCanBuy == 0) {
  259. return Resp::err(ErrCode::paras_err);
  260. }
  261. $bDeal = false; # 成交
  262. if ($costType == "cash") {
  263. $realPrice = $heroCfg->cashPrice;
  264. if ($realPrice != $costMoneyNum) {
  265. return Resp::err(ErrCode::paras_err, "costCASH error! server need:" . $realPrice);
  266. } else {
  267. if ($costMoneyNum > 0) {
  268. if ($user->cash < $costMoneyNum) {
  269. return Resp::err(ErrCode::notenough_cash_msg);
  270. } else {
  271. $bDeal = UserGameModel::Consume_Cash($user, $costMoneyNum);
  272. }
  273. } else if ($costMoneyNum == 0) {
  274. $bDeal = true;
  275. } else {
  276. return Resp::err(ErrCode::paras_err);
  277. }
  278. }
  279. } else if ($costType == "gold") {
  280. $realPrice = $heroCfg->goldPrice;
  281. if ($realPrice != $costMoneyNum) {
  282. return Resp::err(ErrCode::paras_err, "costGold error! server need:" . $realPrice);
  283. } else {
  284. if ($costMoneyNum > 0) {
  285. if ($user->gold < $costMoneyNum) {
  286. return Resp::err(ErrCode::notenough_gold_msg);
  287. } else {
  288. $bDeal = UserGameModel::Consume_Gold($user, $costMoneyNum);
  289. }
  290. } else if ($costMoneyNum == 0) {
  291. $bDeal = true;
  292. } else {
  293. return Resp::err(ErrCode::paras_err);
  294. }
  295. }
  296. }
  297. # 4.消耗来获得英雄
  298. if ($bDeal) {
  299. $resp = HeroProc::GetHero($req);
  300. }
  301. return $resp;
  302. }
  303. /**
  304. * 英雄技能升级
  305. * @param type $req
  306. */
  307. static function UpgradeSkillLevel($req) {
  308. # $resp = ResponseVo::ErrResponse($req, ErrCode::msg_methodnotimplement);
  309. $user = $req->userInfo->game; # user引用
  310. $huid = $req->paras[0]; # 英雄的UID
  311. $skillId = $req->paras[1]; # 要升级的技能
  312. $skillType = $req->paras[2]; # 要升级的技能
  313. $costGold = $req->paras[3]; # 要升级的消耗金币
  314. # # 1.检查是否存在要升级的英雄
  315. $collectHeros = $user->heros->collectHeros;
  316. if (!$collectHeros) {
  317. $collectHeros = ObjectInit();
  318. }
  319. if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
  320. return Resp::err(ErrCode::hero_no);
  321. }
  322. # # 2.判断英雄的该技能能否升级....
  323. isEditor() and $strengthHero = new UserHeroModel();
  324. $strengthHero = $collectHeros->$huid;
  325. # # 取出这个英雄的技能数据
  326. $targteHeroSkills = ObjectInit();
  327. if (CommUtil::isPropertyExists($strengthHero, "skills")) {
  328. $targteHeroSkills = $strengthHero->skills;
  329. }
  330. # 如果不存在这个类型的技能,则 初始化一个.
  331. if (!CommUtil::isPropertyExists($targteHeroSkills, $skillType)) {
  332. $targteHeroSkills->$skillType = JsonUtil::decode('{"level":1}');
  333. }
  334. $curSkillInfo = $targteHeroSkills->$skillType;
  335. $curSkillLevel = $curSkillInfo->level;
  336. # 3.判断技能等级能否在继续升级了
  337. if ($curSkillLevel >= $strengthHero->level) {
  338. return Resp::err(ErrCode::hero_upgradeSkill_maxLevel);
  339. }
  340. # 4.取出该技能升级消耗的常量数据
  341. # 检查是否存在当前技能的消耗常量数据
  342. // $lvs = GameConfig::skill_shengji_getItem($skillId);
  343. $lvs = GameConfig::skill_upgrade_cost_getItem($skillId);
  344. if (!$lvs) {
  345. return Resp::err(ErrCode::hero_upgradeSkill_cost_const_no);
  346. }
  347. $realGold = $lvs->basic + ($curSkillLevel - 1) * $lvs->xishu;
  348. $arr_extracost = explode(";", $lvs->extra);
  349. foreach ($arr_extracost as $value) {
  350. $arr = explode(",", $value);
  351. if (count($arr) == 2) {
  352. $extraLevel = $arr[0];
  353. $extraGold = $arr[1];
  354. if ($extraLevel == $curSkillLevel + 1) {
  355. $realGold += $extraGold;
  356. break;
  357. }
  358. }
  359. }
  360. # 判断金币是否充足
  361. $bDeal = false; # 成交
  362. if ($realGold != $costGold) {
  363. return Resp::err(ErrCode::paras_err, "costGold error! server need:" . $realGold);
  364. } else {
  365. if ($costGold > 0) {
  366. if ($user->gold < $costGold) {
  367. return Resp::err(ErrCode::notenough_gold_msg);
  368. } else {
  369. $bDeal = UserGameModel::Consume_Gold($user, $costGold);
  370. }
  371. } else if ($costGold == 0) {
  372. $bDeal = true;
  373. } else {
  374. return Resp::err(ErrCode::paras_err);
  375. }
  376. }
  377. # 4.消耗金币和英雄
  378. if ($bDeal) {
  379. $targteHeroSkills->$skillType->level += 1;
  380. $strengthHero->skills = $targteHeroSkills;
  381. ActiveProc::ChangeTaskCount($req);
  382. # 回写数据
  383. UserProc::updateUserInfo($req);
  384. $resp = Resp::ok($strengthHero);
  385. }
  386. return $resp;
  387. }
  388. /**
  389. * 更改好友支援
  390. * @param type $req
  391. */
  392. static function ChangeFriendSupport($req) {
  393. $user = $req->userInfo->game; # user引用
  394. if (!CommUtil::isPropertyExists($user->heros, "firendSupportHeroUID")) {
  395. $user->heros->firendSupportHeroUID = "";
  396. }
  397. $friendSupportHeroUids = $req->paras[0]; # 设置支援好友的英雄UID
  398. $collectHeros = $user->heros->collectHeros;
  399. if (!$collectHeros) {
  400. $collectHeros = ObjectInit();
  401. } # 1.检查玩家存在指定的英雄
  402. if (!CommUtil::isPropertyExists($collectHeros, $friendSupportHeroUids)) {
  403. return Resp::err(ErrCode::hero_separate_cost_hero);
  404. }
  405. $user->heros->firendSupportHeroUID = $friendSupportHeroUids;
  406. UserProc::updateUserInfo($req); # 回存数据
  407. return Resp::ok(array('firendSupportHeroUID' => $friendSupportHeroUids));
  408. }
  409. /**
  410. * 英雄的分解获得晶石
  411. * @param type $req
  412. * @return type
  413. */
  414. static function HeroSeparate($req) {
  415. $g = glc();
  416. $user = $req->userInfo->game; # user引用
  417. $costHeroUids = $req->paras[0]; # 消耗掉的英雄UID
  418. # 1.检查是玩家的英雄数据
  419. $collectHeros = $user->heros->collectHeros;
  420. if (!$collectHeros) {
  421. $collectHeros = ObjectInit();
  422. }
  423. # 3.检查消耗的英雄数量,以及玩家是否都存在这些英雄UID.
  424. $arr_costUID = explode(",", $costHeroUids);
  425. $isAllExist = true;
  426. foreach ($arr_costUID as $value) {
  427. if ($value == "") {
  428. continue;
  429. }
  430. if (!CommUtil::isPropertyExists($collectHeros, $value)) {
  431. $isAllExist = false;
  432. break;
  433. }
  434. }
  435. if (!$isAllExist) {
  436. return Resp::err(ErrCode::hero_separate_cost_hero);
  437. }
  438. # 4.统计下这些个英雄都能获得多少晶石
  439. # 消耗卡牌
  440. $spar = 0;
  441. $starToSparCfgArr = explode(",", $g->Hero_Star_SeparateToSpar);
  442. foreach ($arr_costUID as $huid) {
  443. if ($huid == "") {
  444. continue;
  445. }
  446. isEditor() and $strengthHero = new UserHeroModel();
  447. $strengthHero = $collectHeros->$huid;
  448. $index = $strengthHero->curStar - 1;
  449. if ($index >= 0 && $index < count($starToSparCfgArr)) {
  450. $spar += $starToSparCfgArr[$index];
  451. }
  452. unset($collectHeros->$huid);
  453. }
  454. # 发物品到玩家包裹
  455. $req->userInfo->game->spar += $spar; # 入账能量块
  456. # 回存数据
  457. UserProc::updateUserInfo($req);
  458. return Resp::ok(array('num' => $spar));
  459. }
  460. /**
  461. * 英雄好感度解锁
  462. * @param type $req
  463. */
  464. static function HeroOpenFavor($req) {
  465. $user = $req->userInfo->game; # user引用
  466. $huid = $req->paras[0]; # 英雄的UID
  467. $targetFavorId = $req->paras[1]; # 目标好感度 索引id
  468. # 1.检查是否存在要升级的英雄
  469. $collectHeros = $user->heros->collectHeros;
  470. if (!$collectHeros) {
  471. $collectHeros = ObjectInit();
  472. }
  473. if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
  474. return Resp::err(ErrCode::hero_no);
  475. }
  476. # 2.检查目标好感度的常量数据是否存在
  477. $favorCfg = GameConfig::heroextra_favor_getItem($targetFavorId);
  478. if (!$favorCfg) {
  479. return Resp::err(ErrCode::hero_favor_cost_const_no);
  480. }
  481. # 3.检查英雄是否已经解锁了目标好感度
  482. $strengthHero = $collectHeros->$huid;
  483. if (!$strengthHero->curMainFavor) {
  484. $strengthHero->curMainFavor = 'E';
  485. }
  486. if (!$strengthHero->favors) {
  487. $strengthHero->favors = ArrayInit();
  488. $strengthHero->favors[] = 'E';
  489. }
  490. if (CommUtil::isInArray($strengthHero->favors, $favorCfg->name)) {
  491. return Resp::err(ErrCode::hero_favor_targetfavor_para);
  492. }
  493. # 4.检查消耗道具是否充足
  494. $costSpar = $favorCfg->cost;
  495. $bDeal = false; # 成交
  496. if ($costSpar > 0) {
  497. if ($user->spar < $costSpar) {
  498. return Resp::err(ErrCode::notenough_spar);
  499. } else {
  500. $bDeal = UserGameModel::Consume_Spar($user, $costSpar);
  501. }
  502. } else {
  503. return Resp::err(ErrCode::paras_err);
  504. }
  505. # 6.进行消耗升星
  506. if ($bDeal) {
  507. if ($favorCfg->isMain) {
  508. $strengthHero->curMainFavor = $favorCfg->name;
  509. }
  510. $strengthHero->favors[] = $favorCfg->name;
  511. UserProc::updateUserInfo($req);
  512. $resp = Resp::ok($strengthHero);
  513. }
  514. return $resp;
  515. }
  516. /**
  517. * 英雄神血
  518. * @param Req $req
  519. */
  520. static function UpGodBloodHeroByPieces($req) {
  521. $resp = Resp::err(ErrCode::err_method_notimplement);
  522. $g = glc();
  523. $user = $req->userInfo->game; # user引用
  524. $huid = $req->paras[0]; # 英雄的UID
  525. $piecesId = $req->paras[1]; # 英雄碎片的ID
  526. $piecesNum = $req->paras[2];
  527. $moneyType = $req->paras[3]; # 升星消耗金钱的类型
  528. $moneyNum = $req->paras[4];
  529. # 1.检查是否存在要升级的英雄
  530. $collectHeros = $user->heros->collectHeros;
  531. if (!$collectHeros) {
  532. $collectHeros = ObjectInit();
  533. }
  534. if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
  535. return Resp::err(ErrCode::hero_no);
  536. }
  537. # 2.检查是否存在要升级的英雄的神血的血脉值 是否达到100%
  538. isEditor() and $strengthHero = new UserHeroModel();
  539. $strengthHero = $collectHeros->$huid;
  540. # 检查是否存在当前 神血的的消耗常量数据 以及血脉值 是否达到100%
  541. if (!CommUtil::isPropertyExists($strengthHero, "curBloodId")) {
  542. $strengthHero->curBloodId = 0;
  543. }
  544. $lvs = GameConfig::heroextra_godblood_getItem($strengthHero->curBloodId);
  545. if (!$lvs) {
  546. return Resp::err(ErrCode::hero_godblood_level_const_no);
  547. } else {
  548. if ($lvs->targetGodPercent >= 100) {
  549. return Resp::err(ErrCode::hero_godblood_maxlevel);
  550. }
  551. }
  552. # 3. 检查是否存在这个英雄的模板
  553. $heroModelId = $strengthHero->typeId;
  554. $heroCfg = GameConfig::hero_getItem($heroModelId);
  555. if (!$heroCfg) {
  556. return Resp::err(ErrCode::hero_const_no_err);
  557. }
  558. # 4 .检查碎片是否正确
  559. $requirePieceId = $piecesId;
  560. $requirePiecesNum = 0;
  561. $arr_costPieces = explode(";", $lvs->pieces);
  562. foreach ($arr_costPieces as $value) {
  563. $strArr = explode(",", $value);
  564. if (count($strArr) == 2) {
  565. $zhenxidu = $strArr[0];
  566. $num = $strArr[1];
  567. if ((int) $zhenxidu == $heroCfg->zhenxidu) {
  568. $requirePiecesNum = (int) $num;
  569. break;
  570. }
  571. }
  572. }
  573. $piecesCfg = GameConfig::segment_getItem($piecesId);
  574. if (!$piecesCfg) {
  575. return Resp::err(ErrCode::err_const_no);
  576. }
  577. $pos = strpos($piecesCfg->icon, strval($heroModelId));
  578. if ($pos === false) {
  579. return Resp::err(ErrCode::paras_err, $piecesCfg->icon . "?" . $heroModelId);
  580. }
  581. # 5.检查道具的数量是否充足
  582. $myPacketItems = $user->store->segement;
  583. # 检查道具数量是否充足
  584. $enoughPieces = false;
  585. if ($requirePieceId == $piecesId && $requirePiecesNum == $piecesNum) {
  586. #检查碎片
  587. if (!CommUtil::isPropertyExists($myPacketItems, $requirePieceId)) {
  588. $enoughPieces = false;
  589. } else {
  590. if ($myPacketItems->$requirePieceId < $requirePiecesNum) {
  591. $enoughPieces = false;
  592. } else {
  593. $enoughPieces = true;
  594. }
  595. }
  596. } else {
  597. return Resp::err(ErrCode ::paras_err, "error pieces para" . "req" . $requirePieceId . "_" . $requirePiecesNum . "/" . $piecesId . "_" . $piecesNum);
  598. }
  599. if ($enoughPieces === true) {
  600. } else {
  601. return Resp::err(ErrCode::hero_godblood_notengoughitem);
  602. }
  603. # 6.检查账户余额是否充足
  604. #检查消耗是否正确
  605. $enoughMoney = false;
  606. $requireMoneyType = "";
  607. $requireMoneyNum = 0;
  608. $arr_costMoney = explode(";", $lvs->cost);
  609. foreach ($arr_costMoney as $value) {
  610. $strArr = explode(",", $value);
  611. if (count($strArr) == 3) {
  612. $zhenxidu = $strArr[0];
  613. $type = $strArr[1];
  614. $num = $strArr[2];
  615. if ((int) $zhenxidu == $heroCfg->zhenxidu) {
  616. $requireMoneyType = $type;
  617. $requireMoneyNum = (int) $num;
  618. break;
  619. }
  620. }
  621. }
  622. echoline($requireMoneyNum + " " + $moneyNum + " " + $requireMoneyType + " " + $moneyType);
  623. if ($requireMoneyType == $moneyType && $requireMoneyNum == $moneyNum) {
  624. if ($requireMoneyType === "gold") {
  625. if ($user->gold >= $requireMoneyNum) {
  626. $enoughMoney = true;
  627. } else {
  628. return Resp::err(ErrCode::notenough_gold_msg);
  629. }
  630. } else if ($requireMoneyType === "cash") {
  631. if ($user->cash >= $requireMoneyNum) {
  632. $enoughMoney = true;
  633. } else {
  634. return Resp::err(ErrCode::notenough_cash_msg);
  635. }
  636. } else {
  637. return Resp::err(ErrCode ::paras_err, $moneyType);
  638. }
  639. } else {
  640. return Resp::err(ErrCode ::paras_err, "error money para");
  641. }
  642. $bDeal = false;
  643. if ($enoughMoney === true) {
  644. if ($requireMoneyType === "gold") {
  645. $bDeal = UserGameModel:: Consume_Gold($user, $requireMoneyNum);
  646. } else if ($requireMoneyType === "cash") {
  647. $bDeal = UserGameModel:: Consume_Cash($user, $requireMoneyNum);
  648. }
  649. }
  650. # 6.进行消耗升星
  651. if ($bDeal) {
  652. $strengthHero->curBloodId += 1;
  653. # # 消耗道具
  654. $myPacketItems->$requirePieceId -= $requirePiecesNum;
  655. if ($myPacketItems->$requirePieceId < 0) {
  656. $myPacketItems->$requirePieceId = 0;
  657. }
  658. $req->userInfo->game->store->segement = $myPacketItems;
  659. # 回写数据
  660. UserProc::updateUserInfo($req);
  661. $resp = Resp::ok($strengthHero);
  662. # 推送系统消息
  663. SystemProc::Hero_purification($req->zoneid, $user, $heroModelId);
  664. }
  665. ActiveProc::ChangeTaskCount($req);
  666. return $resp;
  667. }
  668. /**
  669. * 英雄消耗碎片道具来升星
  670. * @param type $req
  671. */
  672. static function HeroUpStarByPieces($req) {
  673. $resp = Resp::err(ErrCode::err_method_notimplement);
  674. $g = glc();
  675. $user = $req->userInfo->game; # user引用
  676. $huid = $req->paras[0]; # 英雄的UID
  677. $piecesId = $req->paras[1]; # 英雄碎片的ID
  678. $piecesNum = $req->paras[2];
  679. $diamondId = $req->paras[3]; # 升星石道具的ID
  680. $diamondNum = $req->paras[4];
  681. $moneyType = $req->paras[5]; # 升星消耗金钱的类型
  682. $moneyNum = $req->paras[6];
  683. # 1.检查是否存在要升级的英雄
  684. $collectHeros = $user->heros->collectHeros;
  685. if (!$collectHeros) {
  686. $collectHeros = ObjectInit();
  687. }
  688. if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
  689. return Resp::err(ErrCode::hero_no);
  690. }
  691. # 2.检查是否已经达到最大星级
  692. isEditor() and $strengthHero = new UserHeroModel();
  693. $strengthHero = $collectHeros->$huid;
  694. if ($strengthHero->curStar >= $g->Hero_Star_MaxStarLevel) {
  695. return Resp::err(ErrCode::hero_star_maxstarlevel);
  696. }
  697. # 检查是否存在当前星级的升星消耗常量数据
  698. $lvs = GameConfig::heroextra_star_getItem($strengthHero->curStar);
  699. if (!$lvs) {
  700. return Resp::err(ErrCode::hero_star_level_const_no_err);
  701. }
  702. # 3检查是否存在这个英雄的模板
  703. $heroModelId = $strengthHero->typeId;
  704. $heroCfg = GameConfig::hero_getItem($heroModelId);
  705. if (!$heroCfg) {
  706. return Resp::err(ErrCode::hero_const_no_err);
  707. }
  708. # 4.检查道具的数量是否充足以及消耗数量是否一致
  709. $requireDiamondId = $lvs->itemid;
  710. $requireDiamondNum = 0;
  711. $arr_costDiamond = explode(";", $lvs->itemNum);
  712. foreach ($arr_costDiamond as $value) {
  713. $strArr = explode(",", $value);
  714. if (count($strArr) == 2) {
  715. $zhenxidu = $strArr[0];
  716. $num = $strArr[1];
  717. if ((int) $zhenxidu == $heroCfg->zhenxidu) {
  718. $requireDiamondNum = (int) $num;
  719. break;
  720. }
  721. }
  722. }
  723. #检查碎片是否正确
  724. $requirePieceId = $piecesId;
  725. $requirePiecesNum = 0;
  726. $arr_costPieces = explode(";", $lvs->pieces);
  727. foreach ($arr_costPieces as $value) {
  728. $strArr = explode(",", $value);
  729. if (count($strArr) == 2) {
  730. $zhenxidu = $strArr[0];
  731. $num = $strArr[1];
  732. if ((int) $zhenxidu == $heroCfg->zhenxidu) {
  733. $requirePiecesNum = (int) $num;
  734. break;
  735. }
  736. }
  737. }
  738. $piecesCfg = GameConfig::item_getItem($piecesId);
  739. if (!$piecesCfg) {
  740. return Resp::err(ErrCode::err_const_no);
  741. }
  742. $pos = strpos($piecesCfg->icon, strval($heroModelId));
  743. if ($pos === false) {
  744. return Resp::err(ErrCode::paras_err, $piecesCfg->icon . "?" . $heroModelId);
  745. }
  746. # 4.检查道具的数量是否充足
  747. $myPacketItems = $user->store->items;
  748. #检查道具数量是否充足
  749. $enoughDiamond = false;
  750. $enoughPieces = false;
  751. if ($requirePieceId == $piecesId && $requirePiecesNum == $piecesNum) {
  752. #检查碎片
  753. if (!CommUtil::isPropertyExists($myPacketItems, $requirePieceId)) {
  754. $enoughPieces = false;
  755. } else {
  756. if ($myPacketItems->$requirePieceId < $requirePiecesNum) {
  757. $enoughPieces = false;
  758. } else {
  759. $enoughPieces = true;
  760. }
  761. }
  762. } else {
  763. return Resp::err(ErrCode ::paras_err, #
  764. "error pieces para" . "req" . $requirePieceId . "_" . $requirePiecesNum . "/" . $piecesId . "_" . $piecesNum);
  765. }
  766. if ($requireDiamondId == $diamondId && $requireDiamondNum == $diamondNum) {
  767. #检查升星石
  768. if (!CommUtil::isPropertyExists($myPacketItems, $requireDiamondId)) {
  769. $enoughDiamond = false;
  770. } else {
  771. if ($myPacketItems->$requireDiamondId < $requireDiamondNum) {
  772. $enoughDiamond = false;
  773. } else {
  774. $enoughDiamond = true;
  775. }
  776. }
  777. } else {
  778. return Resp::err(ErrCode ::paras_err, #
  779. "error diamond para" . "req" . $requireDiamondId . "_" . $requireDiamondNum . "/" . $diamondId . "_" . $diamondNum);
  780. }
  781. if ($enoughDiamond === true && $enoughPieces === true) {
  782. } else {
  783. return Resp::err(ErrCode::hero_star_notengoughitem);
  784. }
  785. # 5.检查账户余额是否充足
  786. #检查消耗是否正确
  787. $enoughMoney = false;
  788. $requireMoneyType = "";
  789. $requireMoneyNum = 0;
  790. $arr_costMoney = explode(";", $lvs->cost);
  791. foreach ($arr_costMoney as $value) {
  792. $strArr = explode(",", $value);
  793. if (count($strArr) == 3) {
  794. $zhenxidu = $strArr[0];
  795. $type = $strArr[1];
  796. $num = $strArr[2];
  797. if ((int) $zhenxidu == $heroCfg->zhenxidu) {
  798. $requireMoneyType = $type;
  799. $requireMoneyNum = (int) $num;
  800. break;
  801. }
  802. }
  803. }
  804. if ($requireMoneyType == $moneyType && $requireMoneyNum == $moneyNum) {
  805. if ($requireMoneyType === "gold") {
  806. if ($user->gold >= $requireMoneyNum) {
  807. $enoughMoney = true;
  808. } else {
  809. return Resp::err(ErrCode::notenough_gold_msg);
  810. }
  811. } else if ($requireMoneyType === "cash") {
  812. if ($user->cash >= $requireMoneyNum) {
  813. $enoughMoney = true;
  814. } else {
  815. return Resp::err(ErrCode::notenough_cash_msg);
  816. }
  817. } else {
  818. return Resp::err(ErrCode ::paras_err, $moneyType);
  819. }
  820. } else {
  821. return Resp::err(ErrCode ::paras_err, "error money para");
  822. }
  823. $bDeal = false;
  824. if ($enoughMoney === true) {
  825. if ($requireMoneyType === "gold") {
  826. $bDeal = UserGameModel:: Consume_Gold($user, $requireMoneyNum);
  827. } else if ($requireMoneyType === "cash") {
  828. $bDeal = UserGameModel:: Consume_Cash($user, $requireMoneyNum);
  829. }
  830. }
  831. # 6.进行消耗升星
  832. if ($bDeal) {
  833. $strengthHero->curStar += 1;
  834. # # 消耗道具
  835. $myPacketItems->$requireDiamondId -= $requireDiamondNum;
  836. if ($myPacketItems->$requireDiamondId < 0) {
  837. $myPacketItems->$requireDiamondId = 0;
  838. }
  839. $myPacketItems->$requirePieceId -= $requirePiecesNum;
  840. if ($myPacketItems->$requirePieceId < 0) {
  841. $myPacketItems->$requirePieceId = 0;
  842. }
  843. $req->userInfo->game->store->items = $myPacketItems;
  844. # 回写数据
  845. UserProc::updateUserInfo($req);
  846. $resp = Resp::ok($strengthHero);
  847. # 推送系统消息
  848. // SystemProc::insertHero_Star($req->zoneid, $req->uid, $user->name, $heroCfg->name, $strengthHero->curStar);
  849. }
  850. ActiveProc::ChangeTaskCount($req);
  851. return $resp;
  852. }
  853. /**
  854. * 英雄升星
  855. * @param Req $req
  856. */
  857. static function HeroUpStar($req) {
  858. $resp = Resp::err(ErrCode::err_method_notimplement);
  859. $g = glc();
  860. $user = $req->userInfo->game; # user引用
  861. $huid = $req->paras[0]; # 英雄的UID
  862. $costHeroUids = $req->paras[1]; # 消耗掉的英雄UID
  863. $costGold = $req->paras[2];
  864. # 1.检查是否存在要升级的英雄
  865. $collectHeros = $user->heros->collectHeros;
  866. if (!$collectHeros) {
  867. $collectHeros = ObjectInit();
  868. }
  869. if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
  870. return Resp::err(ErrCode::hero_no);
  871. }
  872. # 2.检查是否已经达到最大星级
  873. isEditor() and $strengthHero = new UserHeroModel();
  874. $strengthHero = $collectHeros->$huid;
  875. if ($strengthHero->curStar >= $g->Hero_Star_MaxStarLevel) {
  876. return Resp::err(ErrCode::hero_star_maxstarlevel);
  877. }
  878. # 检查是否存在当前星级的升星消耗常量数据
  879. $lvs = GameConfig::heroextra_star_getItem($strengthHero->curStar);
  880. if (!$lvs) {
  881. return Resp::err(ErrCode::hero_star_level_const_no_err);
  882. }
  883. # 3.检查消耗的英雄数量,以及玩家是否都存在这些英雄UID.
  884. $arr_costUID = explode(",", $costHeroUids);
  885. $checkCostHeroAllRight = true;
  886. if (count($arr_costUID) != $g->Hero_Star_MaxCostHeroCardNum) {
  887. $checkCostHeroAllRight = false;
  888. } else {
  889. foreach ($arr_costUID as $value) {
  890. if ($value == "" || !CommUtil::isPropertyExists($collectHeros, $value)) {
  891. $checkCostHeroAllRight = false;
  892. break;
  893. }
  894. }
  895. }
  896. if (!$checkCostHeroAllRight) {
  897. return Resp::err(ErrCode::hero_star_costhero);
  898. }
  899. # 获得升星英雄的模板数据,取得它的元素类型
  900. # 检查是否存在这个英雄的模板
  901. $heroModelId = $strengthHero->typeId;
  902. $heroCfg = GameConfig::hero_getItem($heroModelId);
  903. if (!$heroCfg) {
  904. return Resp::err(ErrCode::hero_const_no_err);
  905. }
  906. $queryCostGold = $lvs->costGold;
  907. $costItemNum = $lvs->costItemNum;
  908. # 4.检查道具的数量是否充足
  909. $myPacketItems = $user->store->items;
  910. $checkHasEnoughItem = true;
  911. $costItemId = "";
  912. $record = ObjectInit();
  913. $keyxxx = "Hero_Star_CostItem_" . $heroCfg->yuansu;
  914. if (!CommUtil::isPropertyExists($g, $keyxxx)) {
  915. return Resp::err(ErrCode::hero_star_noglobal_costitem);
  916. } else {
  917. $costItemId = $g->$keyxxx;
  918. }
  919. # 检查道具种类与消耗数量是否匹配
  920. $arr_costitemids = explode(",", $costItemId);
  921. $arr_costnums = explode(",", $costItemNum);
  922. if (count($arr_costitemids) != count($arr_costnums)) {
  923. return Resp::err(ErrCode::hero_star_conststr_itemnotmathnum);
  924. }
  925. $index = 0;
  926. foreach ($arr_costitemids as $requireiItemId) {
  927. $requireCount = 0;
  928. if ($index < count($arr_costnums)) {
  929. $requireCount = $arr_costnums[$index];
  930. }
  931. $index += 1;
  932. # --判断对应的item是否存在相应的常量
  933. # 检查是否存在当前星级的升星消耗常量数据
  934. $itemcfg = GameConfig::item_getItem($requireiItemId);
  935. if (!$itemcfg) {
  936. return Resp::err(ErrCode::err_const_no);
  937. } else {
  938. if (!CommUtil::isPropertyExists($record, $requireiItemId)) {
  939. $record->$requireiItemId = intval($requireCount);
  940. } else {
  941. $count = intval($record->$requireiItemId) + intval($requireCount);
  942. $record->$requireiItemId = $count;
  943. }
  944. }
  945. } foreach ($record as $key => $value) {
  946. if ($value > 0) {
  947. if (!CommUtil::isPropertyExists($myPacketItems, $key)) {
  948. $checkHasEnoughItem = false;
  949. break;
  950. } else {
  951. if ($myPacketItems->$key < $value) {
  952. $checkHasEnoughItem = false;
  953. break;
  954. }
  955. }
  956. }
  957. }
  958. if (!$checkHasEnoughItem) {
  959. return Resp::err(ErrCode::hero_star_notengoughitem);
  960. }
  961. # 5.检查金币是否充足
  962. $bDeal = false; # 成交
  963. if ($queryCostGold != $costGold) {
  964. return Resp::err(ErrCode::paras_err);
  965. } else {
  966. if ($costGold > 0) {
  967. if ($user->gold < $costGold) {
  968. return Resp::err(ErrCode::notenough_gold_msg);
  969. } else {
  970. $bDeal = UserGameModel:: Consume_Gold($user, $costGold);
  971. }
  972. } else if ($costGold == 0) {
  973. $bDeal = true;
  974. } else {
  975. return Resp::err(ErrCode::paras_err);
  976. }
  977. }
  978. # 6.进行消耗升星
  979. if ($bDeal) {
  980. $strengthHero->curStar += 1;
  981. # 消耗卡牌
  982. foreach ($arr_costUID as $value) {
  983. if ($value == "") {
  984. continue;
  985. }
  986. unset($collectHeros->$value);
  987. }
  988. # # 消耗道具
  989. foreach ($record as $key => $value) {
  990. $myPacketItems->$key -= $value;
  991. if ($myPacketItems->$key < 0) {
  992. $myPacketItems->$key = 0;
  993. }
  994. }
  995. $req->userInfo->game->store->items = $myPacketItems;
  996. # 回写数据
  997. UserProc::updateUserInfo($req);
  998. $resp = Resp::ok($strengthHero);
  999. # 推送系统消息
  1000. // SystemProc::insertHero_Star($req->zoneid, $req->uid, $user->name, $heroCfg->name, $strengthHero->curStar);
  1001. }
  1002. ActiveProc::ChangeTaskCount($req);
  1003. return $resp;
  1004. }
  1005. // </editor-fold>
  1006. /**
  1007. * 6321 购买英雄 消耗碎片
  1008. * @param type $req
  1009. */
  1010. static function BuyHeroByCostPieces($req) {
  1011. $user = $req->userInfo->game; # user引用
  1012. $heroModelId = $req->paras[0];
  1013. $costType = $req->paras[1];
  1014. $costMoneyNum = $req->paras[2];
  1015. $piecesId = $req->paras[3];
  1016. $piecesNum = $req->paras[4];
  1017. #1 检查玩家是否已经拥有此类英雄
  1018. $collectHeros = $user->heros->collectHeros;
  1019. if (!$collectHeros) {
  1020. $collectHeros = ObjectInit();
  1021. }
  1022. foreach ($collectHeros as $key => $value) {
  1023. isEditor() and $value = new UserHeroModel();
  1024. if ($value->typeId == $heroModelId) {
  1025. return Resp::err(ErrCode::hero_existSameHero_err);
  1026. }
  1027. }
  1028. #2 检查账户余额是否充足
  1029. $heroCfg = GameConfig::hero_getItem($heroModelId);
  1030. if (!$heroCfg) {
  1031. return Resp::err(ErrCode::hero_const_no_err);
  1032. }
  1033. if ($heroCfg->isCanBuy == 0) {
  1034. return Resp::err(ErrCode::paras_err);
  1035. }
  1036. #3检查碎片是否对不对
  1037. $piecesCfg = GameConfig::segment_getItem($piecesId); # 检查需要消耗的碎片的常量配置是否存在
  1038. if (!$piecesCfg) {
  1039. return Resp::err(ErrCode::err_store_itemnoconst);
  1040. }
  1041. # 5.检查道具的数量是否充足
  1042. $myPacketItems = $user->store->segement;
  1043. $requirePiecesNum = $piecesCfg->mergePrototypeNeedNum;
  1044. # 检查道具数量是否充足
  1045. $enoughPieces = false;
  1046. if ($heroModelId == $piecesCfg->prototypeData && $requirePiecesNum == $piecesNum) {
  1047. if (!CommUtil::isPropertyExists($myPacketItems, $piecesId)) { # 检查碎片
  1048. $enoughPieces = false;
  1049. } else {
  1050. if ($myPacketItems->$piecesId < $requirePiecesNum) {
  1051. $enoughPieces = false;
  1052. } else {
  1053. $enoughPieces = true;
  1054. }
  1055. }
  1056. } else {
  1057. return Resp::err(ErrCode ::paras_err, "error pieces para" . "req" . $piecesId . "_" . $requirePiecesNum . "/" . $piecesId . "_" . $piecesNum);
  1058. }
  1059. if ($enoughPieces == true) {
  1060. } else {
  1061. return Resp::err(ErrCode::hero_godblood_notengoughitem);
  1062. }
  1063. $bDeal = false; # 成交
  1064. if ($costType == "cash") {
  1065. $realPrice = $heroCfg->cashPrice;
  1066. if ($realPrice != $costMoneyNum) {
  1067. return Resp::err(ErrCode::paras_err, "costCASH error! server need:" . $realPrice);
  1068. } else {
  1069. if ($costMoneyNum > 0) {
  1070. if ($user->cash < $costMoneyNum) {
  1071. return Resp::err(ErrCode::err_msg_cashnotenough);
  1072. } else {
  1073. $bDeal = UserGameModel::Consume_Cash($user, $costMoneyNum);
  1074. }
  1075. } else if ($costMoneyNum == 0) {
  1076. $bDeal = true;
  1077. } else {
  1078. return Resp::err(ErrCode::paras_err);
  1079. }
  1080. }
  1081. } else if ($costType == "gold") {
  1082. $realPrice = $heroCfg->goldPrice;
  1083. if ($realPrice != $costMoneyNum) {
  1084. return Resp::err(ErrCode::paras_err, "costGold error! server need:" . $realPrice);
  1085. } else {
  1086. if ($costMoneyNum > 0) {
  1087. if ($user->gold < $costMoneyNum) {
  1088. return Resp::err(ErrCode::err_msg_goldnotenough);
  1089. } else {
  1090. $bDeal = UserGameModel::Consume_Gold($user, $costMoneyNum);
  1091. }
  1092. } else if ($costMoneyNum == 0) {
  1093. $bDeal = true;
  1094. } else {
  1095. return Resp::err(ErrCode::paras_err);
  1096. }
  1097. }
  1098. }
  1099. # 4.消耗来获得英雄
  1100. if ($bDeal) {
  1101. # 6.进行
  1102. # # 消耗道具
  1103. $myPacketItems->$piecesId -= $requirePiecesNum;
  1104. if ($myPacketItems->$piecesId < 0) {
  1105. $myPacketItems->$piecesId = 0;
  1106. }
  1107. $req->userInfo->game->store->segement = $myPacketItems;
  1108. # 回写数据
  1109. UserProc::updateUserInfo($req);
  1110. $resp = HeroProc::GetHero($req);
  1111. SystemProc::GetHero($req->zoneid, $user, $heroModelId);
  1112. }
  1113. return $resp;
  1114. }
  1115. /**
  1116. * [6315]保存队伍的战斗配置信息
  1117. * @param Req $req
  1118. */
  1119. static function SaveHeroTeamConfig($req) {
  1120. $teamsetting = $req->paras[0]; # 配置信息json文件
  1121. $req->userInfo->game->heroTeamConfig = $teamsetting; # 更新配置
  1122. UserProc::updateUserInfo($req); # 回写数据
  1123. # # 添加到战斗力隐藏榜单中, for pvp back matchers, -wg 2017.07.13
  1124. self::CalcTeamFightPower($req->zoneid, $req->uid, $req->userInfo->game);
  1125. return Resp::ok(array('result' => "succeed"));
  1126. }
  1127. /**
  1128. * 购买玩家可以收集的英雄的数量上限
  1129. * @param type $req
  1130. * @return type
  1131. */
  1132. static function BuyHeroMaxCountLimt($req) {
  1133. $g = glc();
  1134. $user = $req->userInfo->game; # user引用
  1135. if (!CommUtil::isPropertyExists($user->heros, "maxCollectCount")) {
  1136. $user->heros->maxCollectCount = $g->Game_CollectHero_BasicMaxCount;
  1137. }
  1138. $buyNum = $req->paras[0];
  1139. $costCash = $req->paras[1];
  1140. $index = ceil(($user->heros->maxCollectCount - $g->Game_CollectHero_BasicMaxCount) #
  1141. / $g->Game_CollectHero_OneBuyLimtNum);
  1142. $arr = explode(",", $g->Game_CollectHero_BasicMaxPrice);
  1143. if ($index >= count($arr)) {
  1144. return Resp::err(ErrCode::paras_err, "yi da shang xian");
  1145. }
  1146. $realCost = $arr[$index];
  1147. if ($realCost != $costCash) {
  1148. return Resp::err(ErrCode::paras_err, "costCash error! server need:" . $realCost);
  1149. }
  1150. if ($costCash <= 0) {
  1151. return Resp::err(ErrCode::paras_err);
  1152. }
  1153. if ($user->cash < $costCash) {
  1154. return Resp::err(ErrCode::notenough_spar);
  1155. }
  1156. UserGameModel::Consume_Cash($user, $costCash); # 扣除宝石
  1157. $user->heros->maxCollectCount += $buyNum; # 修改上限
  1158. UserProc::updateUserInfo($req);
  1159. return Resp::ok(array(
  1160. 'maxCollectCount' => $user->heros->maxCollectCount
  1161. ));
  1162. }
  1163. /**
  1164. * 获得英雄(测试已经OK)
  1165. * @param type $req
  1166. */
  1167. static function GetHero($req) {
  1168. $heroModelId = $req->paras[0]; //英雄的模板ID
  1169. //1.检查是否存在这个英雄的模板
  1170. $heroCfg = GameConfig::hero_getItem($heroModelId);
  1171. if (!$heroCfg) {
  1172. return Resp::err(ErrCode::hero_const_no_err);
  1173. }
  1174. $hero = self::AddHeroTFromStore($req, $heroModelId);
  1175. UserProc::updateUserInfo($req);
  1176. # 4. 设置返回值
  1177. $result = array('result' => "succeed",
  1178. 'heros' => $hero);
  1179. return Resp::ok($result);
  1180. # return $resp;
  1181. }
  1182. // <editor-fold defaultstate="collapsed" desc="辅助方法">
  1183. /**
  1184. * 尝试图鉴整合
  1185. * @param CredisUtil $mem
  1186. * @param HeroManualModel $manual
  1187. * @param type $hero
  1188. */
  1189. static function tryNewManual($mem, &$manual, $hero) {
  1190. $godpetId = $hero->typeId;
  1191. $level = 0;
  1192. self:: changeManual($manual, $godpetId, $level);
  1193. }
  1194. /**
  1195. * 更改图鉴数据
  1196. * @global int $AchievementIsManualExpAddedGlobal
  1197. * @param type $manual
  1198. * @param type $heroModelId
  1199. * @param type $level
  1200. */
  1201. static function changeManual(&$manual, $heroModelId, $level) {
  1202. if (!property_exists($manual, "godpetDic")) {
  1203. $manual->godpetDic = ObjectInit();
  1204. }
  1205. $godpetDic = $manual->godpetDic;
  1206. if (!CommUtil::isPropertyExists($godpetDic, $heroModelId)) {
  1207. $godpetDic->$heroModelId = array(0);
  1208. } else {
  1209. }
  1210. }
  1211. /**
  1212. * 获得一个英雄, 并且给他指定星级
  1213. * @param Req $req
  1214. * @param int $heromodelId 原型数据id
  1215. * @param int $star 星级
  1216. * @return UserHeroModel
  1217. */
  1218. static function AddHeroWithStar(&$req, $heromodelId, $star) {
  1219. $user = $req->userInfo->game;
  1220. if (!$user) {
  1221. return null;
  1222. }
  1223. $heroCfg = GameConfig::hero_getItem($heromodelId); # 检查是否存在这个英雄的模板
  1224. if (!$heroCfg) { # 这里能不能附加错误信息给外面
  1225. return null;
  1226. }
  1227. # 先生成一个hero的UID
  1228. $collectHeros = $user->heros->collectHeros;
  1229. $uid = self::CreateNewGameHeroUID($collectHeros, $user->heros->recordMaxUID);
  1230. $user->heros->recordMaxUID = $uid;
  1231. $hero = self::getGameHeroModelInstance($heroCfg, $heromodelId, $uid);
  1232. $hero->curStar = $star; # 设定star
  1233. $collectHeros->$uid = $hero; # 回写
  1234. $user->heros->collectHeros = $collectHeros; # 回写
  1235. # 更新 图鉴
  1236. if (!CommUtil::isPropertyExists($user, "heroManual")) {
  1237. $user->heroManual = new HeroManualModel();
  1238. $user->heroManual->initInstance();
  1239. }
  1240. $manual = $user->heroManual;
  1241. self:: tryNewManual($req->mem, $manual, $hero);
  1242. return $hero; # 返回
  1243. }
  1244. /**
  1245. * 获得一个英雄
  1246. * @param type $req
  1247. * @param type $heromodelId
  1248. * @return type
  1249. */
  1250. static function AddHeroTFromStore(&$req, $heromodelId) {
  1251. $gamedata = $req->userInfo->game;
  1252. if (!CommUtil::isPropertyExists($gamedata, "heroManual")) {
  1253. $gamedata->heroManual = new HeroManualModel();
  1254. $gamedata->heroManual->initInstance();
  1255. }
  1256. $manual = $gamedata->heroManual;
  1257. //1.检查是否存在这个英雄的模板
  1258. $heroCfg = GameConfig::hero_getItem($heromodelId);
  1259. if (!$heroCfg) {
  1260. return Resp::err(ErrCode::hero_const_no_err);
  1261. }
  1262. //2.存在的话,先生成一个UID
  1263. $collectHeros = $gamedata->heros->collectHeros;
  1264. $uid = self::CreateNewGameHeroUID($collectHeros, $gamedata->heros->recordMaxUID);
  1265. $gamedata->heros->recordMaxUID = $uid;
  1266. $hero = self::getGameHeroModelInstance($heroCfg, $heromodelId, $uid);
  1267. $collectHeros->$uid = $hero;
  1268. $gamedata->heros->collectHeros = $collectHeros;
  1269. self:: tryNewManual($req->mem, $manual, $hero);
  1270. return $hero;
  1271. }
  1272. /**
  1273. * 根据一个英雄的模板id,来获得一个英雄的实例数据
  1274. * @param HeroModel $heroCfg 模板数据
  1275. * @param string $heroModelId 模板数据ID
  1276. * @param string $uid 唯一ID
  1277. * @return UserHeroModel
  1278. */
  1279. static function getGameHeroModelInstance($heroCfg, $heroModelId, $uid) {
  1280. $hero = new UserHeroModel();
  1281. ////取常量数据理的默认的等阶和星级
  1282. $sour = $heroCfg; //GameConfig::hero_getItem($heroModelId);
  1283. $hero->strengthLevel = $sour->dengjie;
  1284. $hero->curStar = $sour->xingji;
  1285. //查找mem中此英雄的模板数据
  1286. $hero->typeId = $heroModelId;
  1287. $hero->uid = $uid;
  1288. $hero->xp = 0;
  1289. $lvs = GameConfig::hero_levelexp_getItem($hero->level + 1);
  1290. $hero->maxXp = $lvs->requiredExp;
  1291. return $hero;
  1292. }
  1293. /**
  1294. * 查找下一个玩家获得英雄的UID
  1295. * @param type $req
  1296. * @return int
  1297. */
  1298. static function CreateNewGameHeroUID($collectHeros, $oldMaxUID) {
  1299. $maxID = 10000;
  1300. if ($collectHeros == null) {
  1301. $collectHeros = ObjectInit();
  1302. }
  1303. foreach ($collectHeros as $itemId => $hero) {
  1304. if ($itemId > $maxID) {
  1305. $maxID = $itemId;
  1306. }
  1307. }
  1308. $max = $maxID;
  1309. if ($oldMaxUID < $maxID) {
  1310. $max = $maxID;
  1311. } else {
  1312. $max = $oldMaxUID;
  1313. }
  1314. return $max + 1;
  1315. }
  1316. /**
  1317. * 一个英雄卡牌获得一点经验值
  1318. * @param string $heroUID
  1319. * @param int $totalEXP
  1320. * @param Req $req
  1321. */
  1322. static function HeroAddEXP($heroUID, $totalEXP, $req) {
  1323. $g = glc();
  1324. $collectHeros = $req->userInfo->game->heros->collectHeros;
  1325. if (!$collectHeros) {
  1326. $collectHeros = ObjectInit();
  1327. }
  1328. if (!CommUtil::isPropertyExists($collectHeros, $heroUID)) {
  1329. return; # 要升级的英雄不存在
  1330. }
  1331. isEditor() and $targetHero = new UserHeroModel;
  1332. $targetHero = $collectHeros->$heroUID;
  1333. //$strengthconst = GameConfig::heroextra_dengjie_getItem($targetHero->strengthLevel);
  1334. $maxLevel = $g->Hero_Upgrade_BasicMaxLevel; //$strengthconst->maxLevel;
  1335. if ($targetHero->level >= $maxLevel) {
  1336. return; # 已达顶级
  1337. }
  1338. $lvs = GameConfig::hero_levelexp_getItem($targetHero->level);
  1339. $targetHero->xp += $totalEXP;
  1340. CLog:: Assert("HeroProc", $targetHero->xp >= 0, #
  1341. "[" . $req->uid . "] : HeroLevelUpgrade Exp is negative!");
  1342. while ($targetHero->xp >= $targetHero->maxXp) {
  1343. if ($targetHero->level < $maxLevel) { # 如果未到达最大等级
  1344. $nowlv = $targetHero->level + 1;
  1345. $nextlv = $nowlv + 1;
  1346. $targetHero->level = $nowlv;
  1347. $lvs = GameConfig::hero_levelexp_getItem($nextlv);
  1348. if ($nowlv >= $maxLevel) {
  1349. $targetHero->xp = $targetHero->maxXp;
  1350. }
  1351. $targetHero->maxXp = $lvs->requiredExp;
  1352. } else { # 如果已到达最大等级则仅补齐缺失的经验即可
  1353. $targetHero->xp = $targetHero->maxXp; # 经验不能超过最大值
  1354. break;
  1355. }
  1356. }
  1357. }
  1358. // </editor-fold>
  1359. // <editor-fold defaultstate="collapsed" desc="废弃代码">
  1360. /**
  1361. * [6301] 英雄升级 - 消耗经验道具书,获得经验
  1362. * @param type $req
  1363. */
  1364. static function HeroLevelUpCostItem($req) {
  1365. $gcfg = glc();
  1366. $user = $req->userInfo->game; # user引用
  1367. $heroUID = $req->paras[0]; # 玩家英雄实例编号
  1368. $costItemIds = $req->paras[1]; # 消耗的道具ID
  1369. $costGold = $req->paras[2];
  1370. //1.检查是否存在要升级的英雄
  1371. $collectHeros = $user->heros->collectHeros;
  1372. if (!$collectHeros) {
  1373. $collectHeros = ObjectInit();
  1374. }
  1375. if (!CommUtil::isPropertyExists($collectHeros, $heroUID)) {
  1376. return Resp::err(ErrCode::hero_no);
  1377. }
  1378. isEditor() and $targetHero = new UserHeroModel;
  1379. $targetHero = $collectHeros->$heroUID;
  1380. //2.检查玩家等级是否达到当前等级上限
  1381. //$strengthconst = GameConfig::heroextra_dengjie_getItem($targetHero->strengthLevel);
  1382. $maxLevel = $gcfg->Hero_Upgrade_BasicMaxLevel; // $strengthconst->maxLevel;
  1383. if ($targetHero->level >= $maxLevel) {
  1384. return Resp::err(ErrCode::hero_upgrade_maxupgradelevel);
  1385. }
  1386. //3.检查消耗的道具是否是都存在的
  1387. $arr_costUID = explode(",", $costItemIds);
  1388. $isAllExist = true;
  1389. $itemObj = ObjectInit();
  1390. foreach ($arr_costUID as $value) {
  1391. if ($value == "") {
  1392. continue;
  1393. }
  1394. if (!CommUtil::isPropertyExists($itemObj, $value)) {
  1395. $itemObj->$value = 1;
  1396. } else {
  1397. $itemObj->$value += 1;
  1398. }
  1399. }
  1400. //以上是统计各种道具的消耗数量
  1401. //下面是检查道具的数量,在背包中是否充足
  1402. $myPacketItems = $user->store->items;
  1403. foreach ($itemObj as $key => $value) {
  1404. if ($value > 0) {
  1405. if (!CommUtil::isPropertyExists($myPacketItems, $key)) {
  1406. $isAllExist = false;
  1407. break;
  1408. } else {
  1409. if ($myPacketItems->$key < $value) {
  1410. $isAllExist = false;
  1411. break;
  1412. }
  1413. }
  1414. }
  1415. }
  1416. if (!$isAllExist) {
  1417. return Resp::err(ErrCode::hero_upgrade_cost);
  1418. }
  1419. //4.计算消耗的道具一共给多少经验值以及 一共要消耗多少金币
  1420. $totalEXP = 0;
  1421. $realCostGold = 0;
  1422. foreach ($arr_costUID as $value) {
  1423. if ($value == "") {
  1424. continue;
  1425. }
  1426. isEditor() and $costItemConst = new sm_hero_levelexp_costitem;
  1427. $costItemConst = GameConfig::hero_levelexp_costitem_getItem($value);
  1428. if (!$costItemConst) {
  1429. return Resp::err(ErrCode::hero_upgrade_cost_const_no);
  1430. } else {
  1431. $totalEXP += $costItemConst->dogExp;
  1432. $realCostGold += $costItemConst->costGold;
  1433. }
  1434. }
  1435. //5.取升级消耗数据,提取消耗的金币数量,判断金币是否充足
  1436. $bDeal = false; # 成交标志
  1437. if ($costGold != $realCostGold) {
  1438. return Resp::err(ErrCode ::paras_err, $errMsg);
  1439. } else {
  1440. if ($costGold > 0) {
  1441. if ($user->gold < $costGold) {
  1442. return Resp::err(ErrCode::notenough_gold_msg);
  1443. } else {
  1444. $bDeal = UserGameModel:: Consume_Gold($user, $costGold);
  1445. }
  1446. } else if ($costGold == 0) {
  1447. $bDeal = true;
  1448. } else {
  1449. return Resp::err(ErrCode::paras_err);
  1450. }
  1451. }
  1452. if ($bDeal) {
  1453. self:: HeroAddEXP($heroUID, $totalEXP, $req); # 获得经验
  1454. #消耗道具
  1455. foreach ($itemObj as $key => $value) {
  1456. $myPacketItems->$key -= $value;
  1457. if ($myPacketItems->$key < 0) {
  1458. $myPacketItems->$key = 0;
  1459. }
  1460. }
  1461. $req->userInfo->game->store->items = $myPacketItems;
  1462. UserProc::updateUserInfo($req);
  1463. $resp = Resp::ok($targetHero);
  1464. }
  1465. ActiveProc::ChangeTaskCount($req);
  1466. return $resp;
  1467. }
  1468. /**
  1469. * [6301] 英雄升级 - 吞噬其他英雄的卡牌,获得经验
  1470. * @param Req $req
  1471. */
  1472. static function HeroLevelUp($req) {
  1473. $g = glc(); # 全局变量
  1474. $user = $req->userInfo->game; # user引用
  1475. $heroUID = $req->paras[0]; # 玩家英雄实例编号
  1476. $costHeroUids = $req->paras[1]; # 消耗的玩家英雄实例编号
  1477. $costGold = $req->paras[2];
  1478. //1.检查是否存在要升级的英雄
  1479. $collectHeros = $user->heros->collectHeros;
  1480. if (!$collectHeros) {
  1481. $collectHeros = ObjectInit();
  1482. }
  1483. if (!CommUtil::isPropertyExists($collectHeros, $heroUID)) {
  1484. return Resp::err(ErrCode::hero_no);
  1485. }
  1486. isEditor() and $targetHero = new UserHeroModel;
  1487. $targetHero = $collectHeros->$heroUID;
  1488. //2.检查玩家等级是否达到当前等级上限
  1489. ////$maxLevel = $gcfg->Hero_Upgrade_BasicMaxLevel + 10 * $targetHero->strengthLevel;
  1490. $strengthconst = GameConfig::heroextra_dengjie_getItem($targetHero->strengthLevel);
  1491. $maxLevel = $strengthconst->maxLevel;
  1492. if ($targetHero->level >= $maxLevel) {
  1493. return Resp::err(ErrCode::hero_upgrade_maxupgradelevel);
  1494. }
  1495. //3.检查消耗的英雄是否是都存在的
  1496. $arr_costUID = explode(",", $costHeroUids);
  1497. $isAllExist = true;
  1498. foreach ($arr_costUID as $value) {
  1499. if ($value == "") {
  1500. continue;
  1501. }
  1502. if (!CommUtil::isPropertyExists($collectHeros, $value)) {
  1503. $isAllExist = false;
  1504. break;
  1505. }
  1506. }
  1507. if (!$isAllExist) {
  1508. return Resp::err(ErrCode::hero_upgrade_cost);
  1509. }
  1510. //4.计算消耗的英雄一共给多少经验值
  1511. $totalEXP = 0;
  1512. $errMsg = "";
  1513. foreach ($arr_costUID as $value) {
  1514. if ($value == "") {
  1515. continue;
  1516. }
  1517. isEditor() and $curHero = new UserHeroModel;
  1518. $errMsg = $errMsg . " uid::" . $value;
  1519. $curHero = $collectHeros->$value;
  1520. $tempLv = $curHero->level;
  1521. $tempLevelConst = GameConfig::hero_levelexp_getItem($tempLv);
  1522. $totalEXP += (int) $tempLevelConst->dogExp;
  1523. $errMsg = $errMsg . " add xp::" . $tempLevelConst->dogExp;
  1524. // $totalEXP += (int) ( $curHero->xp * $gcfg->Hero_Upgrade_EXP_XiShu);
  1525. // $errMsg = $errMsg . " xp::" . $curHero->xp;
  1526. // $totalEXP += $gcfg->Hero_Upgrade_BasicEXP;
  1527. // $errMsg = $errMsg . " basic::" . $gcfg->Hero_Upgrade_BasicEXP;
  1528. $errMsg = $errMsg . " end.";
  1529. }
  1530. //然后算一算获得这么多经验值之后,最新的英雄等级是多少
  1531. $realCostGold = $totalEXP * $g->Hero_Upgrade_ExpConverGold;
  1532. $errMsg = $errMsg . " totalEXP:" . $totalEXP;
  1533. //5.取升级消耗数据,提取消耗的金币数量,判断金币是否充足
  1534. $bDeal = false; # 成交标志
  1535. if ($costGold != $realCostGold) {
  1536. return Resp::err(ErrCode ::paras_err, $errMsg);
  1537. } else {
  1538. if ($costGold > 0) {
  1539. if ($user->gold < $costGold) {
  1540. return Resp::err(ErrCode::notenough_gold_msg);
  1541. } else {
  1542. $bDeal = UserGameModel:: Consume_Gold($user, $costGold);
  1543. }
  1544. } else if ($costGold == 0) {
  1545. $bDeal = true;
  1546. } else {
  1547. return Resp::err(ErrCode::paras_err);
  1548. }
  1549. }
  1550. if ($bDeal) {
  1551. self:: HeroAddEXP($heroUID, $totalEXP, $req); # 获得经验
  1552. foreach ($arr_costUID as $value) {
  1553. if ($value == "") {
  1554. continue;
  1555. }
  1556. unset($collectHeros->$value); # 消耗卡牌
  1557. }
  1558. UserProc::updateUserInfo($req);
  1559. $resp = Resp::ok($targetHero);
  1560. }
  1561. ActiveProc::ChangeTaskCount($req);
  1562. return $resp;
  1563. }
  1564. // </editor-fold>
  1565. /**
  1566. * [6306] 英雄-更改英雄的锁定状态
  1567. * (测试已经OK)
  1568. * @param type $req
  1569. */
  1570. static function HeroChangelockstate($req) {
  1571. $gamedata = $req->userInfo->game;
  1572. $heroUID = $req->paras[0]; # 玩家英雄实例编号
  1573. $lockstate = $req->paras[1]; # 玩家英雄锁定状态
  1574. $collectHeros = $gamedata->heros->collectHeros;
  1575. if (!$collectHeros) {
  1576. $collectHeros = ObjectInit();
  1577. }
  1578. if (!CommUtil::isPropertyExists($collectHeros, $heroUID)) {
  1579. return Resp::err(ErrCode::hero_no);
  1580. }
  1581. isEditor() and $hero = new UserHeroModel;
  1582. $hero = $collectHeros->$heroUID; # 1. 获取这个英雄的实例数据是
  1583. $hero->isLocked = $lockstate; # 2. 修改英雄状态
  1584. UserProc::updateUserInfo($req); # 3. 保存玩家数据
  1585. return Resp::ok(ObjectInit()); # 4. 设置返回值
  1586. }
  1587. //
  1588. // <editor-fold defaultstate="collapsed" desc="计算战队战斗力, for pvp back matchers, -wg 2017.07.13">
  1589. /**
  1590. * 计算队伍战斗力, 添加到战斗力隐藏榜单中, for pvp back matchers, -wg 2017.07.13
  1591. * @param type $zoneid
  1592. * @param type $uid
  1593. * @param UserGameModel $user
  1594. * @return type
  1595. */
  1596. static function CalcTeamFightPower($zoneid, $uid, $user) {
  1597. $mem = gMem();
  1598. $teamsetting = $user->heroTeamConfig; # 更新配置
  1599. // var_dump($user);
  1600. $heros = $user->heros;
  1601. $teamCfg = JsonUtil::decode($teamsetting);
  1602. $tid = $teamCfg->curUseTeamID;
  1603. $team = $teamCfg->teamDic->$tid;
  1604. $fp = 0; # 返回值
  1605. if ($team) {
  1606. foreach ($team->heros as $hid) {
  1607. // isEditor() and $hero = new GameHeroModel();
  1608. if ($hid) {
  1609. $hero = $heros->collectHeros->$hid;
  1610. if ($hero) {
  1611. $fp += self::calcHeroFightPower($hero);
  1612. }
  1613. }
  1614. }
  1615. $mem->zadd(MemKey_GameRun::Game_FightPowerRank_zset($zoneid), array($uid => $fp));
  1616. }
  1617. return $fp;
  1618. }
  1619. /**
  1620. * 计算hero战斗力, for pvp back matchers, -wg 2017.07.13
  1621. * @param UserHeroModel $hero
  1622. * @return int
  1623. */
  1624. static private function calcHeroFightPower($hero) {
  1625. $arr = explode(';', glc()->Battle_PowerFactor);
  1626. $factor = ArrayInit();
  1627. foreach ($arr as $s) {
  1628. $kv = explode(',', $s);
  1629. $k = $kv[0];
  1630. $v = $kv[1];
  1631. $factor[$k] = $v;
  1632. }
  1633. // todo: 哈哈, 奇葩的命名方案, 多处使用的命名不一致, 坑!
  1634. $a = (int) (self::calcHeroProperty($hero, 'hp') * $factor ["hp"] //
  1635. + $hero->level * 10);
  1636. return $a;
  1637. }
  1638. /**
  1639. * 计算hero的属性,, for pvp back matchers, -wg 2017.07.13
  1640. * @param UserHeroModel $hero
  1641. * @param type $propertyname
  1642. */
  1643. private static function calcHeroProperty($hero, $propertyname) {
  1644. $level = $hero->level;
  1645. $modle = GameConfig::hero_getItem($hero->typeId);
  1646. $extra = GameConfig::heroextra_level_getItem(1);
  1647. return (int) ($modle->$propertyname * (1 + $extra->$propertyname));
  1648. }
  1649. // </editor-fold>
  1650. //
  1651. }