HeroProc.php 61 KB

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