HeroProc.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. StlUtil::dictRemove(ctx()->heros->Dic, $heroId);
  60. UserProc::updateUserInfo();
  61. return Resp::ok(array(
  62. 'store' => ctx()->store,
  63. 'heros'=>ctx()->heros,
  64. ));
  65. }
  66. /**
  67. * 购买角色
  68. * @return type
  69. */
  70. private static function BuyHero(){
  71. list($heroId) = req()->paras; # 切换英雄id
  72. my_Assert(GameConfig::hero_getItem($heroId) != null, "找不到英雄配置数据!");
  73. ctx()->heros->Dic->$heroId->isUnlock = 1;
  74. return Resp::ok();
  75. }
  76. /**
  77. * 6602 解锁英雄
  78. * @return type
  79. */
  80. private static function UnlockHero() {
  81. list($heroId) = req()->paras;
  82. $mo = GameConfig::hero_getItem($heroId);
  83. my_Assert($mo != null, ErrCode::err_const_no);
  84. my_Assert(StlUtil::dictHasProperty(ctx()->heros->Dic, $heroId), "找不到英雄配置数据!");
  85. my_Assert(ctx()->heros->Dic->$heroId->isUnlock == 0, "英雄已经解锁!");
  86. //$heroDebris_need = $mo->heroDebris_need;
  87. $heroDebrisList = explode(',', $mo->heroDebris_need);
  88. $itemId = $heroDebrisList[0];
  89. $itemNum = $heroDebrisList[1];
  90. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $itemId) && ctx()->store->items->$itemId >= $itemNum, ErrCode::notenough_item);
  91. ctx()->store->removeItem($itemId, $itemNum);
  92. FightProc::skillUnlock_heroUnlock($heroId);//这个接口位置不能动
  93. ctx()->heros->Dic->$heroId->isUnlock = 1;//解锁
  94. ctx()->heros->Dic->$heroId->isNewHeadImgTip = 1;
  95. UserProc::updateUserInfo();
  96. return Resp::ok(array(
  97. 'store' => ctx()->store,
  98. 'heros'=>ctx()->heros,
  99. ));
  100. }
  101. /**
  102. * 6601 切换英雄
  103. */
  104. private static function SwithHero() {
  105. list($newHeroId) = req()->paras; # 切换英雄id
  106. my_Assert(CommUtil::isPropertyExists(ctx()->heros->Dic, $newHeroId), "尚未获得此英雄!");
  107. ctx()->heros->CurrentHeroId = $newHeroId;
  108. return Resp::ok();
  109. }
  110. }