HeroProc.php 64 KB

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