HeroProc.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. default:
  28. Err(ErrCode::cmd_err);
  29. }
  30. }
  31. /**
  32. * 6603 角色升星
  33. * @return type
  34. */
  35. private static function HeroStrengthenStar(){
  36. list($heroId) = req()->paras;
  37. $mo = GameConfig::hero_getItem($heroId);
  38. my_Assert($mo != null, ErrCode::err_const_no);
  39. my_Assert(StlUtil::dictHasProperty(ctx()->heros->Dic, $heroId), "找不到英雄配置数据!");
  40. my_Assert(ctx()->heros->Dic->$heroId->isUnlock == 1, "英雄未解锁!");
  41. $nextMo = null;
  42. $typeList = GameConfig::heroType_typeId_getItemArray($mo->typeID);
  43. foreach ($typeList as $item) {
  44. if($item->starLv == $mo->starLv +1){
  45. $nextMo = $item;
  46. break;
  47. }
  48. }
  49. my_Assert($nextMo != null, "没有下一星级配置信息");
  50. $heroDebrisList = explode(',', $nextMo->heroDebris_need);
  51. $itemId = $heroDebrisList[0];
  52. $itemNum = $heroDebrisList[1];
  53. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $itemId) && ctx()->store->items->$itemId >= $itemNum, ErrCode::notenough_item);
  54. ctx()->store->removeItem($itemId, $itemNum);
  55. $nextHeroId = $nextMo->id;
  56. $ins_hero = new Ins_Hero(ctx()->heros->Dic->$heroId);
  57. $ins_hero->Id = $nextHeroId;
  58. ctx()->heros->Dic->$nextHeroId = $ins_hero;
  59. if(ctx()->heros->CurrentHeroId == $heroId){
  60. ctx()->heros->CurrentHeroId = $nextHeroId;
  61. }
  62. StlUtil::dictRemove(ctx()->heros->Dic, $heroId);
  63. UserProc::updateUserInfo();
  64. return Resp::ok(array(
  65. 'store' => ctx()->store,
  66. 'heros'=>ctx()->heros,
  67. ));
  68. }
  69. /**
  70. * 购买角色
  71. * @return type
  72. */
  73. private static function BuyHero(){
  74. list($heroId) = req()->paras; # 切换英雄id
  75. my_Assert(GameConfig::hero_getItem($heroId) != null, "找不到英雄配置数据!");
  76. ctx()->heros->Dic->$heroId->isUnlock = 1;
  77. return Resp::ok();
  78. }
  79. /**
  80. * 6602 解锁英雄
  81. * @return type
  82. */
  83. private static function UnlockHero() {
  84. list($heroId) = req()->paras;
  85. $mo = GameConfig::hero_getItem($heroId);
  86. my_Assert($mo != null, ErrCode::err_const_no);
  87. my_Assert(StlUtil::dictHasProperty(ctx()->heros->Dic, $heroId), "找不到英雄配置数据!");
  88. my_Assert(ctx()->heros->Dic->$heroId->isUnlock == 0, "英雄已经解锁!");
  89. //$heroDebris_need = $mo->heroDebris_need;
  90. $heroDebrisList = explode(',', $mo->heroDebris_need);
  91. $itemId = $heroDebrisList[0];
  92. $itemNum = $heroDebrisList[1];
  93. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $itemId) && ctx()->store->items->$itemId >= $itemNum, ErrCode::notenough_item);
  94. ctx()->store->removeItem($itemId, $itemNum);
  95. FightProc::skillUnlock_heroUnlock($heroId);//这个接口位置不能动
  96. ctx()->heros->Dic->$heroId->isUnlock = 1;//解锁
  97. ctx()->heros->Dic->$heroId->isNewHeadImgTip = 1;
  98. UserProc::updateUserInfo();
  99. return Resp::ok(array(
  100. 'store' => ctx()->store,
  101. 'heros'=>ctx()->heros,
  102. 'skillUnlockRecord' => ctx()->privateState->skillUnlockRecord,
  103. ));
  104. }
  105. /**
  106. * 6601 切换英雄
  107. */
  108. private static function SwithHero() {
  109. list($newHeroId) = req()->paras; # 切换英雄id
  110. my_Assert(CommUtil::isPropertyExists(ctx()->heros->Dic, $newHeroId), "尚未获得此英雄!");
  111. ctx()->heros->CurrentHeroId = $newHeroId;
  112. return Resp::ok();
  113. }
  114. }