HeroProc.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /*
  3. * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  4. * Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
  5. */
  6. namespace loyalsoft;
  7. /**
  8. * Description of HeroProc
  9. *
  10. * @author gwang
  11. */
  12. class HeroProc {
  13. //put your code here
  14. /**
  15. * 逻辑分发
  16. * 所有的Proc中必须有这样一个方法
  17. * @param Req $req
  18. */
  19. public static function procMain($req) {
  20. switch ($req->cmd) {
  21. case CmdCode::hero_swith: # 6601 切换英雄
  22. return HeroProc::SwithHero();
  23. case CmdCode::hero_unlock: # 6602 解锁英雄
  24. return self::UnlockHero();
  25. case CmdCode::hero_strengthenStar: # 6603 角色升星
  26. return self::HeroStrengthenStar();
  27. case CmdCode::hero_resetUnlockHero: # 6604 角色卡解锁英雄
  28. return self::ResetUnlockHero();
  29. default:
  30. Err(ErrCode::cmd_err);
  31. }
  32. }
  33. private static function ResetUnlockHero() {
  34. list($heroId) = req()->paras;
  35. if(in_array($heroId, ctx()->heros->roleCardUnlockHeroList)){
  36. StlUtil::arrayRemove(ctx()->heros->roleCardUnlockHeroList, $heroId);
  37. }
  38. UserProc::updateUserInfo();
  39. return Resp::ok(array());
  40. }
  41. /**
  42. * 6603 角色升星
  43. * @return type
  44. */
  45. private static function HeroStrengthenStar() {
  46. list($heroId) = req()->paras;
  47. $mo = GameConfig::hero_getItem($heroId);
  48. my_Assert($mo != null, ErrCode::err_const_no);
  49. my_Assert(StlUtil::dictHasProperty(ctx()->heros->Dic, $heroId), "找不到英雄配置数据!");
  50. my_Assert(ctx()->heros->Dic->$heroId->isUnlock == 1, "英雄未解锁!");
  51. $nextMo = null;
  52. $typeList = GameConfig::heroType_typeId_getItemArray($mo->typeID);
  53. foreach ($typeList as $item) {
  54. if ($item->starLv == $mo->starLv + 1) {
  55. $nextMo = $item;
  56. break;
  57. }
  58. }
  59. my_Assert($nextMo != null, "没有下一星级配置信息");
  60. $heroDebrisList = explode(',', $nextMo->heroDebris_need);
  61. $itemId = $heroDebrisList[0];
  62. $itemNum = $heroDebrisList[1];
  63. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $itemId) && ctx()->store->items->$itemId >= $itemNum, ErrCode::notenough_item);
  64. ctx()->store->removeItem($itemId, $itemNum);
  65. $nextHeroId = $nextMo->id;
  66. $ins_hero = new Ins_Hero(ctx()->heros->Dic->$heroId);
  67. $ins_hero->Id = $nextHeroId;
  68. ctx()->heros->Dic->$nextHeroId = $ins_hero;
  69. if (ctx()->heros->CurrentHeroId == $heroId) {
  70. ctx()->heros->CurrentHeroId = $nextHeroId;
  71. }
  72. StlUtil::dictRemove(ctx()->heros->Dic, $heroId);
  73. FightProc::Ranking_FightPower();
  74. UserProc::updateUserInfo();
  75. return Resp::ok(array(
  76. 'store' => ctx()->store,
  77. 'heros' => ctx()->heros,
  78. 'newHeroId' => $nextHeroId,
  79. ));
  80. }
  81. /**
  82. * 购买角色
  83. * @return type
  84. */
  85. private static function BuyHero() {
  86. list($heroId) = req()->paras; # 切换英雄id
  87. my_Assert(GameConfig::hero_getItem($heroId) != null, "找不到英雄配置数据!");
  88. ctx()->heros->Dic->$heroId->isUnlock = 1;
  89. return Resp::ok();
  90. }
  91. /**
  92. * 6602 解锁英雄
  93. * @return type
  94. */
  95. private static function UnlockHero() {
  96. list($heroId) = req()->paras;
  97. $mo = GameConfig::hero_getItem($heroId);
  98. my_Assert($mo != null, ErrCode::err_const_no);
  99. my_Assert(StlUtil::dictHasProperty(ctx()->heros->Dic, $heroId), "找不到英雄配置数据!");
  100. my_Assert(ctx()->heros->Dic->$heroId->isUnlock == 0, "英雄已经解锁!");
  101. //$heroDebris_need = $mo->heroDebris_need;
  102. $heroDebrisList = explode(',', $mo->heroDebris_need);
  103. $itemId = $heroDebrisList[0];
  104. $itemNum = $heroDebrisList[1];
  105. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $itemId) && ctx()->store->items->$itemId >= $itemNum, ErrCode::notenough_item);
  106. ctx()->store->removeItem($itemId, $itemNum);
  107. self::UnlockNewHero($heroId);
  108. UserProc::updateUserInfo();
  109. return Resp::ok(array(
  110. 'store' => ctx()->store,
  111. 'heros' => ctx()->heros,
  112. 'skillUnlockRecord' => ctx()->privateState->skillUnlockRecord,
  113. ));
  114. }
  115. public static function UnlockNewHero($heroId) {
  116. FightProc::skillUnlock_heroUnlock($heroId); //这个接口位置不能动
  117. ctx()->heros->Dic->$heroId->isUnlock = 1; //解锁
  118. ctx()->heros->Dic->$heroId->isNewHeadImgTip = 1;
  119. }
  120. public static function RoleCardUnlockHero($itemId, $num) {
  121. $heroDic = GameConfig::hero();
  122. $heroTypeId = 0;
  123. $tMo = null;
  124. foreach ($heroDic as $mo) {
  125. if ($itemId == $mo->roleCard) {
  126. $heroTypeId = $mo->typeID;
  127. $tMo = $mo;
  128. break;
  129. }
  130. }
  131. $tag = false;
  132. if ($heroTypeId != 0) {
  133. $dic = ctx()->heros->Dic;
  134. foreach ($dic as $heroItem) {
  135. $hero = GameConfig::hero_getItem($heroItem->Id);
  136. if ($hero->typeID == $heroTypeId && $heroItem->isUnlock == 1) {
  137. $tag = true;
  138. break;
  139. }
  140. }
  141. if ($tag) {//英雄已经解锁,则转为碎片
  142. for ($i = 0; $i < $num; $i++) {
  143. if ($tMo->heroDebris_need != null) {
  144. StoreProc::AddMultiItemInStore($tMo->heroDebris_need);
  145. }
  146. }
  147. } else {//解锁英雄
  148. for ($i = 0; $i < $num; $i++) {
  149. if ($i == 0) {
  150. HeroProc::UnlockNewHero($tMo->id);
  151. ctx()->heros->roleCardUnlockHeroList[] = $tMo->id;
  152. StoreProc::$reward[] = $itemId.',1';
  153. //StoreProc::$reward_hero[] = $tMo->id;
  154. } else {
  155. StoreProc::AddMultiItemInStore($tMo->heroDebris_need);
  156. }
  157. }
  158. }
  159. }
  160. UserProc::updateUserInfo();
  161. }
  162. /**
  163. * 6601 切换英雄
  164. */
  165. private static function SwithHero() {
  166. list($newHeroId) = req()->paras; # 切换英雄id
  167. my_Assert(CommUtil::isPropertyExists(ctx()->heros->Dic, $newHeroId), "尚未获得此英雄!");
  168. ctx()->heros->CurrentHeroId = $newHeroId;
  169. FightProc::Ranking_FightPower();
  170. return Resp::ok();
  171. }
  172. }