HeroProc.php 70 KB

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