HeroProc.php 69 KB

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