HeroProc.php 67 KB

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