HeroProc.php 69 KB

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