HeroProc.php 65 KB

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