HeroProc.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. UserProc::updateUserInfo();
  74. return Resp::ok(array(
  75. 'store' => ctx()->store,
  76. 'heros' => ctx()->heros,
  77. 'newHeroId' => $nextHeroId,
  78. ));
  79. }
  80. /**
  81. * 购买角色
  82. * @return type
  83. */
  84. private static function BuyHero() {
  85. list($heroId) = req()->paras; # 切换英雄id
  86. my_Assert(GameConfig::hero_getItem($heroId) != null, "找不到英雄配置数据!");
  87. ctx()->heros->Dic->$heroId->isUnlock = 1;
  88. return Resp::ok();
  89. }
  90. /**
  91. * 6602 解锁英雄
  92. * @return type
  93. */
  94. private static function UnlockHero() {
  95. list($heroId) = req()->paras;
  96. $mo = GameConfig::hero_getItem($heroId);
  97. my_Assert($mo != null, ErrCode::err_const_no);
  98. my_Assert(StlUtil::dictHasProperty(ctx()->heros->Dic, $heroId), "找不到英雄配置数据!");
  99. my_Assert(ctx()->heros->Dic->$heroId->isUnlock == 0, "英雄已经解锁!");
  100. //$heroDebris_need = $mo->heroDebris_need;
  101. $heroDebrisList = explode(',', $mo->heroDebris_need);
  102. $itemId = $heroDebrisList[0];
  103. $itemNum = $heroDebrisList[1];
  104. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $itemId) && ctx()->store->items->$itemId >= $itemNum, ErrCode::notenough_item);
  105. ctx()->store->removeItem($itemId, $itemNum);
  106. self::UnlockNewHero($heroId);
  107. UserProc::updateUserInfo();
  108. return Resp::ok(array(
  109. 'store' => ctx()->store,
  110. 'heros' => ctx()->heros,
  111. 'skillUnlockRecord' => ctx()->privateState->skillUnlockRecord,
  112. ));
  113. }
  114. public static function UnlockNewHero($heroId) {
  115. FightProc::skillUnlock_heroUnlock($heroId); //这个接口位置不能动
  116. ctx()->heros->Dic->$heroId->isUnlock = 1; //解锁
  117. ctx()->heros->Dic->$heroId->isNewHeadImgTip = 1;
  118. }
  119. public static function RoleCardUnlockHero($itemId, $num) {
  120. $heroDic = GameConfig::hero();
  121. $heroTypeId = 0;
  122. $tMo = null;
  123. foreach ($heroDic as $mo) {
  124. if ($itemId == $mo->roleCard) {
  125. $heroTypeId = $mo->typeID;
  126. $tMo = $mo;
  127. break;
  128. }
  129. }
  130. $tag = false;
  131. if ($heroTypeId != 0) {
  132. $dic = ctx()->heros->Dic;
  133. foreach ($dic as $heroItem) {
  134. $hero = GameConfig::hero_getItem($heroItem->Id);
  135. if ($hero->typeID == $heroTypeId && $heroItem->isUnlock == 1) {
  136. $tag = true;
  137. break;
  138. }
  139. }
  140. if ($tag) {//英雄已经解锁,则转为碎片
  141. for ($i = 0; $i < $num; $i++) {
  142. if ($tMo->heroDebris_need != null) {
  143. StoreProc::AddMultiItemInStore($tMo->heroDebris_need);
  144. }
  145. }
  146. } else {//解锁英雄
  147. for ($i = 0; $i < $num; $i++) {
  148. if ($i == 0) {
  149. HeroProc::UnlockNewHero($tMo->id);
  150. ctx()->heros->roleCardUnlockHeroList[] = $tMo->id;
  151. StoreProc::$reward[] = $itemId.',1';
  152. //StoreProc::$reward_hero[] = $tMo->id;
  153. } else {
  154. StoreProc::AddMultiItemInStore($tMo->heroDebris_need);
  155. }
  156. }
  157. }
  158. }
  159. UserProc::updateUserInfo();
  160. }
  161. /**
  162. * 6601 切换英雄
  163. */
  164. private static function SwithHero() {
  165. list($newHeroId) = req()->paras; # 切换英雄id
  166. my_Assert(CommUtil::isPropertyExists(ctx()->heros->Dic, $newHeroId), "尚未获得此英雄!");
  167. ctx()->heros->CurrentHeroId = $newHeroId;
  168. return Resp::ok();
  169. }
  170. }