HeroProc.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  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_buyCollectHeroLimtCount: # [6312] 扩展英雄数量上限
  25. // return HeroProc::BuyHeroMaxCountLimt($req);
  26. // </editor-fold>
  27. # --------- 英雄技能 -----------
  28. case CmdCode::cmd_hero_upgradeSkillLevel: # [6314] 英雄的技能升级
  29. return HeroProc::UpgradeSkillLevel($req);
  30. case CmdCode::cmd_hero_unlockSkill: # [6324] 英雄技能 - 解锁技能
  31. return HeroProc::UnlockSkill($req);
  32. case CmdCode::cmd_hero_skillLevel_onekeyupgrade: # [6325] 英雄技能 - 一键升级
  33. return HeroProc::OnekeyUpgradeSkillLevel($req);
  34. case CmdCode::cmd_hero_saveHeroTeamConfig: # [6315] 保存玩家战队数据
  35. return HeroProc::SaveHeroTeamConfig($req);
  36. // <editor-fold defaultstate="collapsed" desc="---------------英雄评论----------------">
  37. case CmdCode::cmd_hero_GetDiscuss: # [6316]拉取英雄评论
  38. return HeroDiscussProc::GetDiscusses($req);
  39. case CmdCode::cmd_hero_PostDiscuss: # [6317]对英雄发表评论
  40. return HeroDiscussProc::Post($req);
  41. case CmdCode::cmd_hero_PraiseDiscuss: # [6318]给某条评论点赞
  42. return HeroDiscussProc::PriaseMsg($req);
  43. case CmdCode::cmd_hero_DeleteDiscuss: # [6319]删除评论
  44. return HeroDiscussProc::DeletePost($req);
  45. case CmdCode::cmd_hero_scoreit: # [6320]给某个英雄评分
  46. return HeroDiscussProc::Score($req);
  47. // </editor-fold>
  48. #----------- 英雄的解锁与购买 --------------
  49. case CmdCode::cmd_hero_buyHero: # [6321]购买英雄
  50. return HeroProc::BuyHeroByCostPieces($req);
  51. case CmdCode::cmd_hero_upGodBlood: # [6322] 神血升级
  52. return HeroProc::UpGodBloodHeroByPieces($req);
  53. case CmdCode::cmd_hero_StrengthenStar: # [6326] 升星cmd_hero_YanlinUpLevel
  54. return HeroProc::StrengthenStar($req);
  55. case CmdCode::cmd_hero_YanlinUpLevel: # [6327] 升级
  56. return HeroProc::YanlinUpLevel($req);
  57. // case CmdCode::cmd_hero_unlockByPieces: # [6323] 解锁碎片
  58. // return HeroProc::UnLockHeroByPieces($req);
  59. default: # err: 未知的命令码
  60. return Resp::err(ErrCode::cmd_err);
  61. }
  62. }
  63. // <editor-fold defaultstate="collapsed" desc="技能升级与解锁">
  64. /**
  65. * [6324] 英雄技能解锁
  66. * @version 2020.1.13 至今未进行对接, 再次整理版
  67. * 2019.12.10 加班弄完第一版
  68. * @param req $req
  69. */
  70. static function UnlockSkill($req) {
  71. list($huid, $mainSkillId, $subSkillId) = $req->paras; # 提取参数: 英雄的UID, 主技能Id, 要升级的子技能ID
  72. $user = $req->userInfo->game; # user引用
  73. $cHeros = $user->heros->collectHeros;
  74. my_default_Obj($cHeros);
  75. my_Assert(CommUtil::isPropertyExists($cHeros, $huid), ErrCode::hero_no); # 1.检查是否存在要解锁的英雄
  76. # # 2.判断英雄的该技能能否升级....
  77. $targetHero = new Ins_UserHero($cHeros->$huid); # 直接类型识别
  78. $targteHeroSkills = $targetHero->subSkills; # 取出这个英雄的技能数据
  79. my_default_Arr($targteHeroSkills->$mainSkillId); # 保护子技能数组数据结构
  80. my_Assert(!CommUtil::isInArray($targteHeroSkills->$mainSkillId, $subSkillId), "子技能已解锁"); # 子技能已经解锁
  81. // if (!$targetHero->IsSkillUnlockAble($mainSkillId, $subSkillId)) { # 3.判断技能是否处于待解锁状态
  82. // return Resp::err(ErrCode::hero_upgradeSkill_maxLevel);
  83. // }
  84. $sm = GameConfig::subSkill_getItem($subSkillId); # 4.取出该技能升级消耗的常量数据
  85. my_Assert(null != $sm, ErrCode::err_const_no); # 找不到子技能配置数据
  86. my_Assert(Data_UserGame::Consume_Gold($user->baseInfo, $sm->unlockCost), # # 5. 扣除金币消耗
  87. ErrCode::notenough_gold_msg);
  88. array_push($targteHeroSkills->$mainSkillId, $subSkillId); # 添加技能
  89. $targetHero->subSkills = $targteHeroSkills;
  90. $cHeros->$huid = $targetHero; # 回存Hero对象
  91. UserProc::updateUserInfo(); # 回写数据
  92. TaskProc::OnHeroUnlocSkill($targetHero->typeId, $subSkillId);
  93. return Resp::ok($targetHero);
  94. }
  95. /**
  96. * [6325] 英雄技能一键升级
  97. * @param req $req
  98. */
  99. static function OnekeyUpgradeSkillLevel($req) {
  100. list($huid, $mainSkillId, $subSkillId, $targetSubSkillId, $costGold) = $req->paras; # 提取参数: 英雄的UID, 主技能ID, 要升级的子技能ID, 升级到的子技能ID, 升级要消耗的金币
  101. $user = $req->userInfo->game; # user引用#
  102. $collectHeros = $user->heros->collectHeros;
  103. my_default_Obj($collectHeros); # 防御变量为空
  104. my_Assert(CommUtil::isPropertyExists($collectHeros, $huid), ErrCode::hero_no); # 1.检查是否存在要升级的英雄
  105. # # 2.判断英雄的该技能能否升级....
  106. $targetHero = new Ins_UserHero($cHeros->$huid); # 直接类型识别
  107. $targteHeroSkills = $targetHero->subSkills; # 取出这个英雄的技能数据
  108. my_default_Arr($targteHeroSkills->$mainSkillId); # 保护数据结构
  109. my_Assert(CommUtil::isInArray($targteHeroSkills->$mainSkillId, $subSkillId), "子技能id错误"); # 子技能id
  110. // if (!$targetHero->IsSkillUpdateAble($mainSkillId, $subSkillId)) { # 3.判断技能等级能否在继续升级了
  111. // return Resp::err(ErrCode::hero_upgradeSkill_maxLevel);
  112. // }
  113. // $sm = GameConfig::subSkill_getItem($subSkillId); # 4.取出该技能升级消耗的常量数据
  114. // if (null == $sm) {
  115. // return \Resp::err(ErrCode::err_const_no, '找不到子技能配置数据');
  116. // }
  117. my_Assert(Data_UserGame::Consume_Gold($user->baseInfo, $costGold), ErrCode::notenough_gold_msg); # 5. 扣除金币消耗
  118. unset($targteHeroSkills->$mainSkillId, $subSkillId); # 替换技能
  119. array_push($targteHeroSkills->$mainSkillId, $targetSubSkillId);
  120. $targetHero->subSkills = $targteHeroSkills;
  121. $collectHeros->$huid = $targetHero; # 更新Hero数据
  122. UserProc::updateUserInfo(); # 回写数据
  123. return Resp::ok($targetHero);
  124. }
  125. /**
  126. * [6314]英雄技能升级
  127. * @param req $req
  128. */
  129. static function UpgradeSkillLevel($req) {
  130. list($huid, $mainSkillId, $subSkillId) = $req->paras; # 提取参数: 英雄的UID, 主技能Id, 要升级的子技能Id
  131. $user = $req->userInfo->game; # user引用
  132. $collectHeros = $user->heros->collectHeros;
  133. my_default_Obj($collectHeros); # 防御变量为空
  134. my_Assert(CommUtil::isPropertyExists($collectHeros, $huid), ErrCode::hero_no); # 1.检查是否存在要升级的英雄
  135. $targetHero = new Ins_UserHero($collectHeros->$huid);
  136. $targteHeroSkills = $targetHero->subSkills; # 取出这个英雄的技能数据
  137. my_Assert(CommUtil::isPropertyExists($targteHeroSkills, $mainSkillId), "玩家数据结构有问题."); # 主技能Id.
  138. my_Assert(CommUtil::isInArray($targteHeroSkills->$mainSkillId, $subSkillId), "子技能id错误"); # 子技能id
  139. my_Assert($targetHero->IsSkillUpdateAble($mainSkillId, $subSkillId), ErrCode::hero_upgradeSkill_maxLevel); # 3.判断技能等级能否在继续升级了
  140. $sm = GameConfig::subSkill_getItem($subSkillId); # 4.取出该技能升级消耗的常量数据
  141. my_Assert(null != $sm, ErrCode::err_const_no); # 找不到子技能配置数据
  142. my_Assert(Data_UserGame::Consume_Gold($user->baseInfo, $sm->upgradeCost), ErrCode::notenough_gold_msg); # 5. 扣除金币消耗
  143. unset($targteHeroSkills->$mainSkillId, $subSkillId); # 替换技能
  144. array_push($targteHeroSkills->$mainSkillId, $sm->nextLevel_Id);
  145. $targetHero->subSkills = $targteHeroSkills;
  146. $collectHeros->$huid = $targetHero; # 更新hero数据
  147. UserProc::updateUserInfo(); # 回写数据
  148. return Resp::ok($targetHero);
  149. }
  150. // </editor-fold>
  151. //
  152. // <editor-fold defaultstate="collapsed" desc="英雄 强化">
  153. /**
  154. * 6304 英雄 升阶(消耗碎片)
  155. * @param Req $req
  156. */
  157. static function HeroStageUp($req) {
  158. list($huid, $nextGrade) = $req->paras; # 提取参数: 英雄的UID,下一阶
  159. $user = $req->userInfo->game; # user引用
  160. $collectHeros = $user->heros->collectHeros; # 角色容器
  161. my_default_Obj($collectHeros); # 保证不为null
  162. my_Assert(CommUtil::isPropertyExists($collectHeros, $huid), ErrCode::hero_no); # 1.检查是否存在要升级的英雄
  163. $upHero = new Ins_UserHero($collectHeros->$huid); # 直接类型识别
  164. my_Assert($upHero->grade < "S", ErrCode::hero_strength_maxstrengthlevel); # 已经达到S级
  165. $heroUpgradeCostCfg = GameConfig::heroextra_level_getItem($upHero->typeId, $nextGrade);
  166. my_Assert($heroUpgradeCostCfg, ErrCode::hero_strength_cost_const_no); # 1.检查是否存在这个升阶数据的模板
  167. my_Assert(Data_UserGame::Consume_HeroSegment($user, # # 扣除碎片
  168. $heroUpgradeCostCfg->segID, $heroUpgradeCostCfg->segNum), ErrCode::hero_segment_not_enough); # 碎片数量不足
  169. # 扣除碎片成功
  170. $upHero->grade = $nextGrade; # 5.强化英雄进行成功升阶
  171. $collectHeros->$huid = $upHero; # 更新Hero数据
  172. UserProc::updateUserInfo(); # 6.数据回存
  173. $resp = Resp::ok($upHero);
  174. SystemProc::insertHero_StageUp($req->zoneid, $req->uid, $user->baseInfo->name, # # 插入系统广播
  175. GameConfig::hero_getItem($upHero->typeId)->name, $upHero->grade);
  176. self::CalcUserFightPower($req->zoneid, $req->uid, $req->userInfo->game); # 跟新战力统计
  177. TaskProc::OnHeroGradeUp($upHero->typeId, $upHero->grade);
  178. // var_dump($user->task->taskListDaily);
  179. return $resp;
  180. }
  181. /**
  182. * [6301] 英雄升级 - 消耗经验道具,获得经验(按照经验提升等级)
  183. * @param Req $req
  184. */
  185. static function HeroLevelUpCostExpItem($req) {
  186. list($huid, $costItemId, $costNumber) = $req->paras; # 提取参数: 玩家英雄实例编号, 消耗的道具ID, 消耗的道具数量
  187. $user = $req->userInfo->game; # user引用
  188. $collectHeros = $user->heros->collectHeros; # 1. 检查是否存在要升级的英雄
  189. my_default_Obj($collectHeros);
  190. my_Assert(is_int($costNumber) && $costNumber >= 1, ErrCode::paras_err); # 参数合法性判断
  191. my_Assert(CommUtil::isPropertyExists($collectHeros, $huid), ErrCode::hero_no); # 玩家拥有此英雄
  192. $targetHero = new Ins_UserHero($collectHeros->$huid); # 智能感知辅助
  193. my_Assert($targetHero->HeroCanLevelUp(), "英雄不可升级"); # 2. 检查玩家等级是否可以继续升级, Ps. 全局限制 + 指挥官等级限制
  194. $myPacketItems = $user->store->items; # 检查道具的数量,在背包中是否充足
  195. my_Assert(CommUtil::isPropertyExists($myPacketItems, $costItemId), ErrCode::store_itemnotenough); #
  196. my_Assert($myPacketItems->$costItemId >= $costNumber, ErrCode::store_itemnotenough);
  197. $totalEXP = 0; # 4.计算消耗的道具一共给多少经验值以及 一共要消耗多少金币
  198. $costItemConst = GameConfig::item_stones_getItem($costItemId);
  199. my_Assert(null != $costItemConst, ErrCode::err_const_no);
  200. $totalEXP += $costItemConst->baseExp;
  201. $heroConst = GameConfig::hero_getItem($targetHero->typeId); # 英雄模板数据
  202. my_Assert(null != $heroConst, ErrCode::err_const_no, "英雄 模板数据");
  203. if ($costItemConst->element != 0 # # 相同元素加成
  204. && $costItemConst->element == $heroConst->element) {
  205. $totalEXP += $costItemConst->extraExp;
  206. }
  207. $totalEXP *= $costNumber; # 消耗N个道具
  208. $targetHero = self:: HeroAddEXP($huid, $totalEXP); # 获得经验
  209. $myPacketItems->$costItemId -= $costNumber; # 消耗道具
  210. if ($myPacketItems->$costItemId < 0) {
  211. $myPacketItems->$costItemId = 0;
  212. }
  213. $req->userInfo->game->store->items = $myPacketItems; # 更新背包数据
  214. if ($targetHero->xp < 0) {
  215. Err(ErrCode::err_innerfault, "英雄经验出错");
  216. } else {
  217. UserProc::updateUserInfo(); # 回写玩家数据
  218. TaskProc::OnHeroImprove();
  219. }
  220. // var_dump($user->task->taskListDaily);
  221. self::CalcUserFightPower($req->zoneid, $req->uid, $req->userInfo->game); # 跟新战力统计
  222. $ret = array(
  223. 'hero' => $targetHero,
  224. 'store' => $user->store
  225. );
  226. return Resp::ok($ret);
  227. }
  228. // </editor-fold>
  229. //
  230. // <editor-fold defaultstate="collapsed" desc="队伍配置">
  231. /**
  232. * [6315]保存队伍的战斗配置信息
  233. * @param Req $req
  234. */
  235. static function SaveHeroTeamConfig($req) {
  236. $teamsetting = $req->paras[0]; # 配置信息json文件
  237. $req->userInfo->game->heroTeamConfig = $teamsetting; # 更新配置
  238. UserProc::updateUserInfo(); # 回写数据
  239. # # 添加到战斗力隐藏榜单中, for pvp back matchers, -wg 2017.07.13
  240. self::CalcTeamFightPower($req->zoneid, $req->uid, $req->userInfo->game);
  241. return Resp::ok(array('result' => "succeed"));
  242. }
  243. // </editor-fold>
  244. //
  245. // <editor-fold defaultstate="collapsed" desc="已过时代码">
  246. /**
  247. * 6323 解锁英雄
  248. * @param type $req
  249. */
  250. static function UnLockHeroByPieces($req) {
  251. $user = $req->userInfo->game; # user引用
  252. $heroModelId = $req->paras[0];
  253. $piecesId = $req->paras[1]; # 英雄碎片的ID
  254. $piecesNum = $req->paras[2];
  255. if (!CommUtil::isPropertyExists($user->heros, "recordUnLockHeroDic")) {
  256. $user->heros->recordUnLockHeroDic = ObjectInit();
  257. }
  258. $recordUnLockHeroDic = $user->heros->recordUnLockHeroDic;
  259. #检查是不是已经解锁过了
  260. $flag = 0;
  261. if (!CommUtil::isPropertyExists($recordUnLockHeroDic, $heroModelId)) {
  262. $recordUnLockHeroDic->$heroModelId = 0;
  263. }
  264. $flag = $recordUnLockHeroDic->$heroModelId;
  265. if ($flag == 1) {
  266. return Resp::err(ErrCode::hero_lockState);
  267. }
  268. #检查要解锁的英雄的常量配置是否存在
  269. $heroCfg = GameConfig::hero_getItem($heroModelId);
  270. if (!$heroCfg) {
  271. return Resp::err(ErrCode::hero_const_no_err);
  272. }
  273. #检查需要消耗的碎片的常量配置是否存在
  274. $piecesCfg = GameConfig::segment_getItem($piecesId);
  275. if (!$piecesCfg) {
  276. return Resp::err(ErrCode::err_const_no);
  277. }
  278. # 5.检查道具的数量是否充足
  279. $myPacketItems = $user->store->segement;
  280. $requirePiecesNum = $heroCfg->unlockConditionId;
  281. # 检查道具数量是否充足
  282. $enoughPieces = false;
  283. if ($heroModelId == $piecesCfg->prototypeData && $requirePiecesNum == $piecesNum) {
  284. if (!CommUtil::isPropertyExists($myPacketItems, $piecesId)) { # 检查碎片
  285. $enoughPieces = false;
  286. } else {
  287. if ($myPacketItems->$piecesId < $requirePiecesNum) {
  288. $enoughPieces = false;
  289. } else {
  290. $enoughPieces = true;
  291. }
  292. }
  293. } else {
  294. return Resp::err(ErrCode ::paras_err, "error pieces para" . "req" . $piecesId . "_" . $requirePiecesNum . "/" . $piecesId . "_" . $piecesNum);
  295. }
  296. if ($enoughPieces === true) {
  297. # 6.进行 # # 消耗道具
  298. $myPacketItems->$piecesId -= $requirePiecesNum;
  299. if ($myPacketItems->$piecesId < 0) {
  300. $myPacketItems->$piecesId = 0;
  301. }
  302. $recordUnLockHeroDic->$heroModelId = 1;
  303. $req->user->heros->recordUnLockHeroDic = $recordUnLockHeroDic;
  304. $req->userInfo->game->store->segement = $myPacketItems;
  305. UserProc::updateUserInfo(); # 回写数据
  306. return Resp::ok(array('result' => "OK")); //返回OK
  307. } else {
  308. return Resp::err(ErrCode::hero_godblood_notengoughitem);
  309. }
  310. }
  311. /**
  312. * [6322] 英雄神血
  313. * @param Req $req
  314. */
  315. static function UpGodBloodHeroByPieces($req) {
  316. return Resp::err(ErrCode::err_method_obsoleted);
  317. }
  318. /**
  319. * 英雄消耗碎片道具来升星
  320. * @param req $req
  321. */
  322. static function HeroUpStarByPieces($req) {
  323. $resp = Resp::err(ErrCode::err_method_notimplement);
  324. $g = glc();
  325. $user = $req->userInfo->game; # user引用
  326. $huid = $req->paras[0]; # 英雄的UID
  327. $piecesId = $req->paras[1]; # 英雄碎片的ID
  328. $piecesNum = $req->paras[2];
  329. $diamondId = $req->paras[3]; # 升星石道具的ID
  330. $diamondNum = $req->paras[4];
  331. $moneyType = $req->paras[5]; # 升星消耗金钱的类型
  332. $moneyNum = $req->paras[6];
  333. # 1.检查是否存在要升级的英雄
  334. $collectHeros = $user->heros->collectHeros;
  335. if (!$collectHeros) {
  336. $collectHeros = ObjectInit();
  337. }
  338. if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
  339. return Resp::err(ErrCode::hero_no);
  340. }
  341. # 2.检查是否已经达到最大星级
  342. isEditor() and $strengthHero = new Ins_UserHero();
  343. $strengthHero = $collectHeros->$huid;
  344. if ($strengthHero->curStar >= $g->Hero_Star_MaxStarLevel) {
  345. return Resp::err(ErrCode::hero_star_maxstarlevel);
  346. }
  347. # 检查是否存在当前星级的升星消耗常量数据
  348. $lvs = GameConfig::heroextra_star_getItem($strengthHero->curStar);
  349. if (!$lvs) {
  350. return Resp::err(ErrCode::hero_star_level_const_no_err);
  351. }
  352. # 3检查是否存在这个英雄的模板
  353. $heroModelId = $strengthHero->typeId;
  354. $heroCfg = GameConfig::hero_getItem($heroModelId);
  355. if (!$heroCfg) {
  356. return Resp::err(ErrCode::hero_const_no_err);
  357. }
  358. # 4.检查道具的数量是否充足以及消耗数量是否一致
  359. $requireDiamondId = $lvs->itemid;
  360. $requireDiamondNum = 0;
  361. $arr_costDiamond = explode(";", $lvs->itemNum);
  362. foreach ($arr_costDiamond as $value) {
  363. $strArr = explode(",", $value);
  364. if (count($strArr) == 2) {
  365. $zhenxidu = $strArr[0];
  366. $num = $strArr[1];
  367. if ((int) $zhenxidu == $heroCfg->zhenxidu) {
  368. $requireDiamondNum = (int) $num;
  369. break;
  370. }
  371. }
  372. }
  373. #检查碎片是否正确
  374. $requirePieceId = $piecesId;
  375. $requirePiecesNum = 0;
  376. $arr_costPieces = explode(";", $lvs->pieces);
  377. foreach ($arr_costPieces as $value) {
  378. $strArr = explode(",", $value);
  379. if (count($strArr) == 2) {
  380. $zhenxidu = $strArr[0];
  381. $num = $strArr[1];
  382. if ((int) $zhenxidu == $heroCfg->zhenxidu) {
  383. $requirePiecesNum = (int) $num;
  384. break;
  385. }
  386. }
  387. }
  388. $piecesCfg = GameConfig::item_getItem($piecesId);
  389. if (!$piecesCfg) {
  390. return Resp::err(ErrCode::err_const_no);
  391. }
  392. $pos = strpos($piecesCfg->icon, strval($heroModelId));
  393. if ($pos === false) {
  394. return Resp::err(ErrCode::paras_err, $piecesCfg->icon . "?" . $heroModelId);
  395. }
  396. # 4.检查道具的数量是否充足
  397. $myPacketItems = $user->store->items;
  398. #检查道具数量是否充足
  399. $enoughDiamond = false;
  400. $enoughPieces = false;
  401. if ($requirePieceId == $piecesId && $requirePiecesNum == $piecesNum) {
  402. #检查碎片
  403. if (!CommUtil::isPropertyExists($myPacketItems, $requirePieceId)) {
  404. $enoughPieces = false;
  405. } else {
  406. if ($myPacketItems->$requirePieceId < $requirePiecesNum) {
  407. $enoughPieces = false;
  408. } else {
  409. $enoughPieces = true;
  410. }
  411. }
  412. } else {
  413. return Resp::err(ErrCode ::paras_err, #
  414. "error pieces para" . "req" . $requirePieceId . "_" . $requirePiecesNum . "/" . $piecesId . "_" . $piecesNum);
  415. }
  416. if ($requireDiamondId == $diamondId && $requireDiamondNum == $diamondNum) {
  417. #检查升星石
  418. if (!CommUtil::isPropertyExists($myPacketItems, $requireDiamondId)) {
  419. $enoughDiamond = false;
  420. } else {
  421. if ($myPacketItems->$requireDiamondId < $requireDiamondNum) {
  422. $enoughDiamond = false;
  423. } else {
  424. $enoughDiamond = true;
  425. }
  426. }
  427. } else {
  428. return Resp::err(ErrCode ::paras_err, #
  429. "error diamond para" . "req" . $requireDiamondId . "_" . $requireDiamondNum . "/" . $diamondId . "_" . $diamondNum);
  430. }
  431. if ($enoughDiamond === true && $enoughPieces === true) {
  432. } else {
  433. return Resp::err(ErrCode::hero_star_notengoughitem);
  434. }
  435. # 5.检查账户余额是否充足
  436. #检查消耗是否正确
  437. $enoughMoney = false;
  438. $requireMoneyType = "";
  439. $requireMoneyNum = 0;
  440. $arr_costMoney = explode(";", $lvs->cost);
  441. foreach ($arr_costMoney as $value) {
  442. $strArr = explode(",", $value);
  443. if (count($strArr) == 3) {
  444. $zhenxidu = $strArr[0];
  445. $type = $strArr[1];
  446. $num = $strArr[2];
  447. if ((int) $zhenxidu == $heroCfg->zhenxidu) {
  448. $requireMoneyType = $type;
  449. $requireMoneyNum = (int) $num;
  450. break;
  451. }
  452. }
  453. }
  454. if ($requireMoneyType == $moneyType && $requireMoneyNum == $moneyNum) {
  455. if ($requireMoneyType === "gold") {
  456. if ($user->baseInfo->gold >= $requireMoneyNum) {
  457. $enoughMoney = true;
  458. } else {
  459. return Resp::err(ErrCode::notenough_gold_msg);
  460. }
  461. } else if ($requireMoneyType === "cash") {
  462. if ($user->baseInfo->cash >= $requireMoneyNum) {
  463. $enoughMoney = true;
  464. } else {
  465. return Resp::err(ErrCode::notenough_cash_msg);
  466. }
  467. } else {
  468. return Resp::err(ErrCode ::paras_err, $moneyType);
  469. }
  470. } else {
  471. return Resp::err(ErrCode ::paras_err, "error money para");
  472. }
  473. $bDeal = false;
  474. if ($enoughMoney === true) {
  475. if ($requireMoneyType === "gold") {
  476. $bDeal = Data_UserGame:: Consume_Gold($user->baseInfo, $requireMoneyNum);
  477. } else if ($requireMoneyType === "cash") {
  478. $bDeal = Data_UserGame:: Consume_Cash($user->baseInfo, $requireMoneyNum);
  479. }
  480. }
  481. # 6.进行消耗升星
  482. if ($bDeal) {
  483. $strengthHero->curStar += 1;
  484. # # 消耗道具
  485. $myPacketItems->$requireDiamondId -= $requireDiamondNum;
  486. if ($myPacketItems->$requireDiamondId < 0) {
  487. $myPacketItems->$requireDiamondId = 0;
  488. }
  489. $myPacketItems->$requirePieceId -= $requirePiecesNum;
  490. if ($myPacketItems->$requirePieceId < 0) {
  491. $myPacketItems->$requirePieceId = 0;
  492. }
  493. $req->userInfo->game->store->items = $myPacketItems;
  494. # 回写数据
  495. UserProc::updateUserInfo();
  496. $resp = Resp::ok($strengthHero);
  497. # 推送系统消息
  498. // SystemProc::insertHero_Star($req->zoneid, $req->uid, $user->name, $heroCfg->name, $strengthHero->curStar);
  499. }
  500. ActiveProc::ChangeTaskCount($req);
  501. return $resp;
  502. }
  503. /**
  504. * 英雄升星
  505. * @param Req $req
  506. */
  507. static function HeroUpStar($req) {
  508. $resp = Resp::err(ErrCode::err_method_notimplement);
  509. $g = glc();
  510. $user = $req->userInfo->game; # user引用
  511. $huid = $req->paras[0]; # 英雄的UID
  512. $costHeroUids = $req->paras[1]; # 消耗掉的英雄UID
  513. $costGold = $req->paras[2];
  514. # 1.检查是否存在要升级的英雄
  515. $collectHeros = $user->heros->collectHeros;
  516. if (!$collectHeros) {
  517. $collectHeros = ObjectInit();
  518. }
  519. if (!CommUtil::isPropertyExists($collectHeros, $huid)) {
  520. return Resp::err(ErrCode::hero_no);
  521. }
  522. # 2.检查是否已经达到最大星级
  523. isEditor() and $strengthHero = new Ins_UserHero();
  524. $strengthHero = $collectHeros->$huid;
  525. if ($strengthHero->curStar >= $g->Hero_Star_MaxStarLevel) {
  526. return Resp::err(ErrCode::hero_star_maxstarlevel);
  527. }
  528. # 检查是否存在当前星级的升星消耗常量数据
  529. $lvs = GameConfig::heroextra_star_getItem($strengthHero->curStar);
  530. if (!$lvs) {
  531. return Resp::err(ErrCode::hero_star_level_const_no_err);
  532. }
  533. # 3.检查消耗的英雄数量,以及玩家是否都存在这些英雄UID.
  534. $arr_costUID = explode(",", $costHeroUids);
  535. $checkCostHeroAllRight = true;
  536. if (count($arr_costUID) != $g->Hero_Star_MaxCostHeroCardNum) {
  537. $checkCostHeroAllRight = false;
  538. } else {
  539. foreach ($arr_costUID as $value) {
  540. if ($value == "" || !CommUtil::isPropertyExists($collectHeros, $value)) {
  541. $checkCostHeroAllRight = false;
  542. break;
  543. }
  544. }
  545. }
  546. if (!$checkCostHeroAllRight) {
  547. return Resp::err(ErrCode::hero_star_costhero);
  548. }
  549. # 获得升星英雄的模板数据,取得它的元素类型
  550. # 检查是否存在这个英雄的模板
  551. $heroModelId = $strengthHero->typeId;
  552. $heroCfg = GameConfig::hero_getItem($heroModelId);
  553. if (!$heroCfg) {
  554. return Resp::err(ErrCode::hero_const_no_err);
  555. }
  556. $queryCostGold = $lvs->costGold;
  557. $costItemNum = $lvs->costItemNum;
  558. # 4.检查道具的数量是否充足
  559. $myPacketItems = $user->store->items;
  560. $checkHasEnoughItem = true;
  561. $costItemId = "";
  562. $record = ObjectInit();
  563. $keyxxx = "Hero_Star_CostItem_" . $heroCfg->yuansu;
  564. if (!CommUtil::isPropertyExists($g, $keyxxx)) {
  565. return Resp::err(ErrCode::hero_star_noglobal_costitem);
  566. } else {
  567. $costItemId = $g->$keyxxx;
  568. }
  569. # 检查道具种类与消耗数量是否匹配
  570. $arr_costitemids = explode(",", $costItemId);
  571. $arr_costnums = explode(",", $costItemNum);
  572. if (count($arr_costitemids) != count($arr_costnums)) {
  573. return Resp::err(ErrCode::hero_star_conststr_itemnotmathnum);
  574. }
  575. $index = 0;
  576. foreach ($arr_costitemids as $requireiItemId) {
  577. $requireCount = 0;
  578. if ($index < count($arr_costnums)) {
  579. $requireCount = $arr_costnums[$index];
  580. }
  581. $index += 1;
  582. # --判断对应的item是否存在相应的常量
  583. # 检查是否存在当前星级的升星消耗常量数据
  584. $itemcfg = GameConfig::item_getItem($requireiItemId);
  585. if (!$itemcfg) {
  586. return Resp::err(ErrCode::err_const_no);
  587. } else {
  588. if (!CommUtil::isPropertyExists($record, $requireiItemId)) {
  589. $record->$requireiItemId = intval($requireCount);
  590. } else {
  591. $count = intval($record->$requireiItemId) + intval($requireCount);
  592. $record->$requireiItemId = $count;
  593. }
  594. }
  595. } foreach ($record as $key => $value) {
  596. if ($value > 0) {
  597. if (!CommUtil::isPropertyExists($myPacketItems, $key)) {
  598. $checkHasEnoughItem = false;
  599. break;
  600. } else {
  601. if ($myPacketItems->$key < $value) {
  602. $checkHasEnoughItem = false;
  603. break;
  604. }
  605. }
  606. }
  607. }
  608. if (!$checkHasEnoughItem) {
  609. return Resp::err(ErrCode::hero_star_notengoughitem);
  610. }
  611. # 5.检查金币是否充足
  612. $bDeal = false; # 成交
  613. if ($queryCostGold != $costGold) {
  614. return Resp::err(ErrCode::paras_err);
  615. } else {
  616. if ($costGold > 0) {
  617. if ($user->baseInfo->gold < $costGold) {
  618. return Resp::err(ErrCode::notenough_gold_msg);
  619. } else {
  620. $bDeal = Data_UserGame:: Consume_Gold($user->baseInfo, $costGold);
  621. }
  622. } else if ($costGold == 0) {
  623. $bDeal = true;
  624. } else {
  625. return Resp::err(ErrCode::paras_err);
  626. }
  627. }
  628. # 6.进行消耗升星
  629. if ($bDeal) {
  630. $strengthHero->curStar += 1;
  631. # 消耗卡牌
  632. foreach ($arr_costUID as $value) {
  633. if ($value == "") {
  634. continue;
  635. }
  636. unset($collectHeros->$value);
  637. }
  638. # # 消耗道具
  639. foreach ($record as $key => $value) {
  640. $myPacketItems->$key -= $value;
  641. if ($myPacketItems->$key < 0) {
  642. $myPacketItems->$key = 0;
  643. }
  644. }
  645. $req->userInfo->game->store->items = $myPacketItems;
  646. # 回写数据
  647. UserProc::updateUserInfo();
  648. $resp = Resp::ok($strengthHero);
  649. # 推送系统消息
  650. // SystemProc::insertHero_Star($req->zoneid, $req->uid, $user->name, $heroCfg->name, $strengthHero->curStar);
  651. }
  652. ActiveProc::ChangeTaskCount($req);
  653. return $resp;
  654. }
  655. // </editor-fold>
  656. /**
  657. * 6321 购买英雄 消耗碎片
  658. * @param req $req
  659. */
  660. static function BuyHeroByCostPieces($req) {
  661. list($heroModelId, $costType, $costMoneyNum, $piecesId, $piecesNum) = $req->paras; # 提取参数
  662. $user = $req->userInfo->game; # user引用
  663. $collectHeros = $user->heros->collectHeros;
  664. my_default_Obj($collectHeros);
  665. foreach ($collectHeros as $key => $value) { # 检查玩家是否已经拥有此类英雄
  666. my_Assert($value->typeId != $heroModelId, ErrCode::hero_existSameHero_err);
  667. }
  668. $heroCfg = GameConfig::hero_getItem($heroModelId); # 英雄模板数据
  669. my_Assert(null != $heroCfg, ErrCode::hero_const_no_err);
  670. my_Assert($heroCfg->isCanBuy != 0, ErrCode::paras_err); # 是否可以直接购买
  671. $piecesCfg = GameConfig::segment_getItem($piecesId); # 检查需要消耗的碎片的常量配置是否存在
  672. my_Assert(null != $piecesCfg, ErrCode::err_store_itemnoconst);
  673. $myPacketItems = $user->store->items;
  674. $requirePiecesNum = $piecesCfg->mergePrototypeNeedNum;
  675. my_Assert($heroModelId == $piecesCfg->prototypeData && $requirePiecesNum == $piecesNum, ErrCode::paras_err);
  676. my_Assert(CommUtil::isPropertyExists($myPacketItems, $piecesId), ErrCode::hero_godblood_notengoughitem);
  677. my_Assert($myPacketItems->$piecesId > $requirePiecesNum, ErrCode::hero_godblood_notengoughitem); # 检查碎片道具数量是否充足
  678. switch ($costType) {
  679. case "cash":
  680. $realPrice = $heroCfg->cashPrice;
  681. my_Assert($realPrice == $costMoneyNum, ErrCode::paras_err);
  682. my_Assert($costMoneyNum >= 0, ErrCode::paras_err);
  683. my_Assert(Data_UserGame::Consume_Cash($user->baseInfo, $costMoneyNum), ErrCode::err_msg_cashnotenough);
  684. break;
  685. case "gold":
  686. $realPrice = $heroCfg->goldPrice;
  687. my_Assert($realPrice == $costMoneyNum, ErrCode::paras_err);
  688. my_Assert($costMoneyNum >= 0, ErrCode::paras_err);
  689. my_Assert(Data_UserGame::Consume_Gold($user->baseInfo, $costMoneyNum), ErrCode::err_msg_goldnotenough);
  690. break;
  691. default :
  692. Err(ErrCode::paras_err, "参数错误: [costType] " . $costType);
  693. }
  694. # 4.消耗来获得英雄
  695. $myPacketItems->$piecesId -= $requirePiecesNum; # 消耗道具
  696. $req->userInfo->game->store->items = $myPacketItems; # 回存背包
  697. UserProc::updateUserInfo(); # 回写数据
  698. $resp = HeroProc::GetHero($req);
  699. SystemProc::GetHero($req->zoneid, $user->baseInfo, $heroModelId); # 插入系统广播消息
  700. return $resp;
  701. }
  702. /**
  703. * 购买玩家可以收集的英雄的数量上限
  704. * @param req $req
  705. * @return type
  706. */
  707. static function BuyHeroMaxCountLimt($req) {
  708. list($buyNum, $costCash) = $req->paras; # 提取参数: 数量, 花费钻石
  709. $g = glc();
  710. $user = $req->userInfo->game; # user引用
  711. if (!CommUtil::isPropertyExists($user->heros, "maxCollectCount")) {
  712. $user->heros->maxCollectCount = $g->Game_CollectHero_BasicMaxCount;
  713. }
  714. $index = ceil(($user->heros->maxCollectCount - $g->Game_CollectHero_BasicMaxCount) #
  715. / $g->Game_CollectHero_OneBuyLimtNum);
  716. $arr = explode(",", $g->Game_CollectHero_BasicMaxPrice);
  717. my_Assert($index < count($arr), "已达上限");
  718. $realCost = $arr[$index];
  719. my_Assert($realCost == $costCash, ErrCode::paras_err); # 参数错误
  720. my_Assert($costCash >= 0, ErrCode::paras_err);
  721. my_Assert(Data_UserGame::Consume_Cash($user->baseInfo, $costCash), ErrCode::err_msg_goldnotenough); # 扣除宝石
  722. $user->heros->maxCollectCount += $buyNum; # 修改上限
  723. UserProc::updateUserInfo();
  724. return Resp::ok(array(
  725. 'maxCollectCount' => $user->heros->maxCollectCount
  726. ));
  727. }
  728. /**
  729. * 获得英雄(测试已经OK)
  730. * @param req $req
  731. */
  732. static function GetHero($req) {
  733. $heroModelId = $req->paras[0]; # 英雄的模板ID
  734. $heroCfg = GameConfig::hero_getItem($heroModelId); # 1.检查是否存在这个英雄的模板
  735. my_Assert(null != $heroCfg, ErrCode::hero_const_no_err);
  736. $hero = self::AddHeroTFromStore($req, $heroModelId); # 创建英雄
  737. UserProc::updateUserInfo();
  738. $result = array('result' => "succeed", 'heros' => $hero); # 4. 设置返回值
  739. return Resp::ok($result);
  740. }
  741. // <editor-fold defaultstate="collapsed" desc="辅助方法">
  742. /**
  743. * 获得一个英雄, 并且给他指定星级
  744. * @param Req $req
  745. * @param int $heromodelId 原型数据id
  746. * @param int $star 星级
  747. * @return Ins_UserHero
  748. */
  749. static function AddHeroWithStar(&$req, $heromodelId, $star) {
  750. $user = $req->userInfo->game;
  751. my_Assert(null != $user, ErrCode::err_innerfault);
  752. $collectHeros = $user->heros->collectHeros;
  753. $uid = self::CreateNewGameHeroUID($collectHeros, $user->heros->recordMaxUID); # 先生成一个hero的UID
  754. $user->heros->recordMaxUID = $uid;
  755. $hero = self::getGameHeroModelInstance($heromodelId, $uid);
  756. if ($star > 0) {
  757. $hero->curStar = $star; # 设定star
  758. }
  759. $collectHeros->$uid = $hero; # 回写
  760. $user->heros->collectHeros = $collectHeros; # 回写
  761. return $hero; # 返回
  762. }
  763. /**
  764. * 获得一个英雄(实例)
  765. * @param req $req
  766. * @param int $heromodelId
  767. * @return type
  768. */
  769. static function AddHeroTFromStore(&$req, $heromodelId) {
  770. $user = $req->userInfo->game; # 玩家数据
  771. $collectHeros = $user->heros->collectHeros; #
  772. my_default_Obj($collectHeros);
  773. $uid = self::CreateNewGameHeroUID($collectHeros, $user->heros->recordMaxUID); # 先生成一个UID
  774. $user->heros->recordMaxUID = $uid; # 更新最大编号记录
  775. $hero = self::getGameHeroModelInstance($heromodelId, $uid); # 3.创建英雄实例
  776. $collectHeros->$uid = $hero;
  777. $user->heros->collectHeros = $collectHeros;
  778. return $hero;
  779. }
  780. /**
  781. * 根据一个英雄的模板id,来获得一个英雄的实例数据
  782. * @param string $heroModelId 模板数据ID
  783. * @param string $uid 唯一ID
  784. * @return Ins_UserHero
  785. */
  786. static function getGameHeroModelInstance($heroModelId, $uid) {
  787. $heroCfg = GameConfig::hero_getItem($heroModelId);
  788. my_Assert(null != $heroCfg, ErrCode::err_const_no); # 检查是否存在这个英雄的模板
  789. $hero = new Ins_UserHero();
  790. // $hero->strengthLevel = $heroCfg->dengjie;
  791. $hero->curStar = $heroCfg->xingji;
  792. $hero->typeId = $heroCfg->heroId;
  793. $hero->uid = $uid;
  794. $hero->xp = 0;
  795. $lvs = GameConfig::hero_levelexp_getItem($hero->level + 1);
  796. $hero->maxXp = $lvs->requiredExp;
  797. // 取可用武器中第一个初始化 -- 策划要求初始英雄要带有武器 -- 王刚 2020年1月
  798. $wp = null;
  799. $arr = (array) GameConfig::item_weapon();
  800. ksort($arr); // todo: 排序不正常
  801. foreach ($arr as $id => $mo) {
  802. // isEditor() and $mo = new \sm_item_weapon();
  803. if ($mo->hero_id == $hero->typeId) {
  804. $wp = $mo;
  805. break;
  806. }
  807. }
  808. if (null != $wp) {
  809. $req = req();
  810. $wuid = StoreProc::PutEquipInStore($wp->typeId, $req);
  811. $req->userInfo->game->store->equipment->$wuid->herouid = $uid;
  812. $hero->equip->weapon = array("itemuid" => $wuid);
  813. }
  814. return $hero;
  815. }
  816. /**
  817. * 查找下一个玩家获得英雄的UID
  818. * @param type $req
  819. * @return int
  820. */
  821. static function CreateNewGameHeroUID($collectHeros, $oldMaxUID) {
  822. $maxID = 10000;
  823. my_default_Obj($collectHeros);
  824. foreach ($collectHeros as $itemId => $hero) {
  825. if ($itemId > $maxID) {
  826. $maxID = $itemId;
  827. }
  828. }
  829. $max = max($maxID, $oldMaxUID);
  830. return $max + 1;
  831. }
  832. /**
  833. * 英雄卡牌增加经验值
  834. * @param string $heroUID
  835. * @param int $totalEXP
  836. */
  837. static function HeroAddEXP($heroUID, $totalEXP) {
  838. $req = req();
  839. $collectHeros = $req->userInfo->game->heros->collectHeros;
  840. my_default_Obj($collectHeros);
  841. my_Assert(CommUtil::isPropertyExists($collectHeros, $heroUID), ErrCode::hero_no); # 要升级的英雄不存在
  842. $targetHero = new Ins_UserHero($collectHeros->$heroUID); # 英雄对象
  843. $playerLimit = GameConfig::playerlevel_getItem($req->userInfo->game->baseInfo->level)->hero_max_level;
  844. $maxLevel = min(glc()->Hero_Upgrade_BasicMaxLevel, $playerLimit); # 最大等级= max(英雄最高等级上限,玩家等级限制的上限)
  845. if ($targetHero->level >= $maxLevel) {
  846. return; # 已达顶级
  847. }
  848. $lvs = GameConfig::hero_levelexp_getItem($targetHero->level + 1);
  849. $targetHero->xp += $totalEXP;
  850. my_Assert($targetHero->xp >= 0, "[" . $req->uid . "] : HeroLevelUpgrade Exp is negative!");
  851. $initLevel = $targetHero->level;
  852. while ($targetHero->xp >= $lvs->needExp) {
  853. if ($targetHero->level < $maxLevel) { # 如果未到达最大等级
  854. $targetHero->level += 1;
  855. if ($targetHero->level >= $maxLevel) {
  856. $targetHero->xp = $lvs->needExp;
  857. } else {
  858. $targetHero->xp -= $lvs->needExp;
  859. }
  860. $lvs = GameConfig::hero_levelexp_getItem($targetHero->level + 1);
  861. } else { # 如果已到达最大等级则仅补齐缺失的经验即可
  862. $targetHero->xp = $targetHero->maxXp; # 经验不能超过最大值
  863. break;
  864. }
  865. } // end while
  866. my_Assert($targetHero->xp >= 0, "[" . $req->uid . "] : HeroLevelUpgrade Exp is negative!");
  867. $collectHeros->$heroUID = $targetHero; # 更新英雄的数据
  868. // if ($targetHero->level != $initLevel) {
  869. TaskProc::OnHeroLevelUp($targetHero->typeId, $targetHero->level);
  870. // }
  871. return $targetHero; # 将英雄对象返回
  872. }
  873. // </editor-fold>
  874. /**
  875. * [6306] 英雄-更改英雄的锁定状态
  876. * (测试已经OK)
  877. * @param type $req
  878. */
  879. static function HeroChangelockstate($req) {
  880. $gamedata = $req->userInfo->game;
  881. $heroUID = $req->paras[0]; # 玩家英雄实例编号
  882. $lockstate = $req->paras[1]; # 玩家英雄锁定状态
  883. $collectHeros = $gamedata->heros->collectHeros;
  884. my_default_Obj($collectHeros); # 默认值
  885. my_Assert(CommUtil::isPropertyExists($collectHeros, $heroUID), ErrCode::hero_no);
  886. // isEditor() and $hero = new UserHeroModel;
  887. $hero = $collectHeros->$heroUID; # 1. 获取这个英雄的实例数据是
  888. $hero->isLocked = $lockstate; # 2. 修改英雄状态
  889. UserProc::updateUserInfo(); # 3. 保存玩家数据
  890. return Resp::ok(ObjectInit()); # 4. 设置返回值
  891. }
  892. /**6326
  893. * 言灵升星
  894. * @param req $req
  895. * @return type
  896. */
  897. static function StrengthenStar($req) {
  898. list($yanlingUid, $uidList) = $req->paras;
  899. $store = $req->userInfo->game->store;
  900. if (!StlUtil::dictHasProperty($store->yanling, $yanlingUid)) {
  901. return Resp::err(ErrCode::hero_yanling_notfound);
  902. }
  903. if(in_array($yanlingUid, $uidList)){
  904. return Resp::err(ErrCode::hero_yanling_repeat);
  905. }
  906. if($store->yanling->$yanlingUid->starLv >= 5){
  907. return Resp::err(ErrCode::hero_yanling_repeat);
  908. }
  909. $tag = true;
  910. foreach ($uidList as $costUid) {
  911. if (StlUtil::dictHasProperty($store->yanling, $costUid)) {//校验是否是同类型
  912. $confDic = GameConfig::item_yanling_getItem($store->yanling->$costUid->typeId);
  913. my_Assert(null != $confDic, ErrCode::hero_const_no_err);
  914. if ($confDic->type != GameConfig::item_yanling_getItem($store->yanling->$yanlingUid->typeId)->type) {
  915. $tag = false;
  916. break;
  917. }
  918. } else {
  919. $tag = false;
  920. break;
  921. }
  922. }
  923. if (!$tag) {
  924. return Resp::err(ErrCode::hero_yanling_notfound);
  925. }
  926. $exp = 0;
  927. foreach ($uidList as $costuid) {
  928. $confDic = GameConfig::item_yanling_getItem($store->yanling->$costUid->typeId);
  929. my_Assert(null != $confDic, ErrCode::hero_const_no_err);
  930. $exp += $confDic->addStarExp;
  931. StlUtil::dictRemove($store->yanling, $costuid);
  932. }
  933. $store->yanling->$yanlingUid->curStarExp += $exp;
  934. $dic = GameConfig::item_yanling_getItem($store->yanling->$yanlingUid->typeId);
  935. if ($store->yanling->$yanlingUid->curStarExp >= $dic->maxStarExp) {
  936. $store->yanling->$yanlingUid->curStarExp = 0;
  937. $store->yanling->$yanlingUid->starLv += 1;
  938. $store->yanling->$yanlingUid->typeId = $dic->nextId;
  939. }
  940. $req->userInfo->game->store = $store;
  941. UserProc::updateUserInfo();
  942. return Resp::ok(array('store' => $req->userInfo->game->store,));
  943. }
  944. /** 6327
  945. * 言灵升级
  946. * @param req $req
  947. */
  948. static function YanlinUpLevel($req) {
  949. list($yanlingUid, $type) = $req->paras;
  950. $store = $req->userInfo->game->store;
  951. if (!StlUtil::dictHasProperty($store->yanling, $yanlingUid)) {
  952. return Resp::err(ErrCode::hero_yanling_notfound);
  953. }
  954. $allDic = GameConfig::yanlingLeve();
  955. $maxLevel = count((array)$allDic);
  956. $curlv = $store->yanling->$yanlingUid->level;
  957. if($curlv >= $maxLevel){
  958. return Resp::err(ErrCode::hero_yanling_levelMax);
  959. }
  960. $maxLv = $curlv + $type;
  961. if($maxLv > $maxLevel ){
  962. $maxLv = $maxLevel;
  963. }
  964. $goldNum = 0;
  965. $pointNum = 0;
  966. for ($index = $curlv; $index < $maxLv; $index++) {
  967. if(!StlUtil::dictHasProperty($allDic,$index)){
  968. return Resp::err(ErrCode::hero_yanling_levelconst_no);
  969. }
  970. $mo = GameConfig::yanlingLeve_getItem($index);
  971. //$cost = '1,'.$mo->goldCost.';'. '8,'.$mo->pointCost;
  972. $goldNum += $mo->goldCost;
  973. $pointNum += $mo->pointCost;
  974. // $costList = explode(';',$cost);
  975. // foreach ($costList as $item) {
  976. // $list = explode(',', $item);
  977. // if($list[0] == META_GOLD_ITEMID){//扣金币
  978. // $goldNum += $list[1];
  979. // } elseif ($list[0] == META_RESPOINT_ITEMID) {//扣除资源点
  980. // $pointNum += $list[1];
  981. // }
  982. // }
  983. }
  984. if($req->userInfo->game->baseInfo->gold < $goldNum){
  985. return Resp::err(ErrCode::notenough_gold_msg);
  986. }
  987. if($req->userInfo->game->baseInfo->resPoint < $pointNum){
  988. return Resp::err(ErrCode::notenough_resPoint);
  989. }
  990. Data_UserGame::Consume_Gold($req->userInfo->game->baseInfo, $goldNum);
  991. Data_UserGame::Consume_ResPoint($req->userInfo->game->baseInfo, $pointNum);
  992. $store->yanling->$yanlingUid->level += $type;
  993. if($store->yanling->$yanlingUid->level > $maxLevel){
  994. $store->yanling->$yanlingUid->level = $maxLevel;
  995. }
  996. $req->userInfo->game->store = $store;
  997. UserProc::updateUserInfo();
  998. return Resp::ok(array('store' => $req->userInfo->game->store, 'gold' => $req->userInfo->game->baseInfo->gold, 'resPoint' => $req->userInfo->game->baseInfo->resPoint));
  999. }
  1000. //
  1001. // <editor-fold defaultstate="collapsed" desc="计算战队战斗力, for pvp back matchers, -wg 2017.07.13">
  1002. /**
  1003. * 计算队伍战斗力, 添加到战斗力隐藏榜单中, for pvp back matchers, -wg 2017.07.13
  1004. * @param type $zoneid
  1005. * @param type $uid
  1006. * @param Data_UserGame $user
  1007. * @return type
  1008. */
  1009. static function CalcTeamFightPower($zoneid, $uid, $user) {
  1010. $teamsetting = $user->heroTeamConfig; # 战队配置
  1011. // var_dump($user);
  1012. $heros = $user->heros;
  1013. $teamCfg = JsonUtil::decode($teamsetting);
  1014. $tid = $teamCfg->curUseTeamID;
  1015. $team = $teamCfg->teamDic->$tid;
  1016. $fp = 0; # 返回值
  1017. if ($team) {
  1018. foreach ($team->heros as $hid) {
  1019. if ($hid) {
  1020. $hero = $heros->collectHeros->$hid;
  1021. if ($hero) {
  1022. // $fp += self::calcHeroFightPower($hero);
  1023. $h = new Ins_UserHero($hero);
  1024. $fp += $h->GetPower();
  1025. }
  1026. }
  1027. }
  1028. //todo: 这里的战斗力榜被总战力榜征用了key, 重启PVP机制时再
  1029. // gMem()->zadd(MemKey_GameRun::Game_FightPowerRank_zset($zoneid), array($uid => $fp));
  1030. }
  1031. return $fp;
  1032. }
  1033. /**
  1034. * 计算玩家总战斗力, 添加到战斗力榜单中
  1035. * @version 1.0.0 改造自原来的队伍战斗力统计方法 --gwang 2020.4.23
  1036. * @param type $zoneid
  1037. * @param type $uid
  1038. * @param Data_UserGame $user
  1039. * @return type
  1040. */
  1041. static function CalcUserFightPower($zoneid, $uid, $user) {
  1042. $fp = 0; # 总战力:返回值
  1043. foreach ($user->heros->collectHeros as $hid => $hero) {
  1044. $h = new Ins_UserHero($hero);
  1045. $fp += $h->GetPower();
  1046. }
  1047. $key_fp = MemKey_GameRun::Game_FightPowerRank_zset($zoneid); # 战力榜
  1048. $key_log = MemKey_GameRun::Game_Rank_FPowerBreakLog_hash($zoneid); # 突破记录
  1049. gMem()->zadd($key_fp, array($uid => $fp)); # 更新战力记录
  1050. foreach (GameConfig::rankreward_fpower() as $condition => $reward) { # 遍历突破奖励数据
  1051. if ($fp >= $condition && !gMem()->hexists($key_log, $condition)) { # 判断是否达成突破奖励标准
  1052. gMem()->hset($key_log, $condition, $uid); # 添加突破记录
  1053. CornerSignEventProc::OnRanking_PowerReward_new(req());
  1054. }
  1055. }
  1056. TaskProc::OnUserFightPowerN($fp);
  1057. return $fp;
  1058. }
  1059. /**
  1060. * 计算hero战斗力, for pvp back matchers, -wg 2017.07.13
  1061. * @param Ins_UserHero $hero
  1062. * @return int
  1063. */
  1064. static private function calcHeroFightPower($hero) {
  1065. $arr = explode(';', glc()->Battle_PowerFactor);
  1066. $factor = ArrayInit();
  1067. foreach ($arr as $s) {
  1068. $kv = explode(',', $s);
  1069. $k = $kv[0];
  1070. $v = $kv[1];
  1071. $factor[$k] = $v;
  1072. }
  1073. // todo: 哈哈, 奇葩的命名方案, 多处使用的命名不一致, 坑!
  1074. $a = (int) (self::calcHeroProperty($hero, 'hp') * $factor ["hp"] //
  1075. + $hero->level * 10);
  1076. return $a;
  1077. }
  1078. /**
  1079. * 计算hero的属性,, for pvp back matchers, -wg 2017.07.13
  1080. * @param Ins_UserHero $hero
  1081. * @param type $propertyname
  1082. */
  1083. private static function calcHeroProperty($hero, $propertyname) {
  1084. $val = 0;
  1085. if ($hero) {
  1086. $modle = GameConfig::hero_getItem($hero->typeId);
  1087. if ($modle) {
  1088. $extra = GameConfig::heroextra_level_getItem($hero->typeId, $hero->grade);
  1089. if ($extra) {
  1090. $val = (int) ($modle->$propertyname * (1 + $extra->$propertyname));
  1091. } else {
  1092. $val = $modle->$propertyname;
  1093. }
  1094. }
  1095. }
  1096. return $val;
  1097. }
  1098. // </editor-fold>
  1099. //
  1100. }