HeroProc.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_buy:
  26. return self::BuyHero();
  27. default:
  28. Err(ErrCode::cmd_err);
  29. }
  30. }
  31. /**
  32. * 购买角色
  33. * @return type
  34. */
  35. private static function BuyHero(){
  36. list($heroId) = req()->paras; # 切换英雄id
  37. my_Assert(GameConfig::hero_getItem($heroId) != null, "找不到英雄配置数据!");
  38. ctx()->heros->Dic->$heroId->isUnlock = 1;
  39. return Resp::ok();
  40. }
  41. /**
  42. * 6602 解锁英雄
  43. * @return type
  44. */
  45. private static function UnlockHero() {
  46. list($newHeroId) = req()->paras; # 切换英雄id
  47. my_Assert(GameConfig::hero_getItem($newHeroId) != null, "找不到英雄配置数据!");
  48. // 解锁消耗,
  49. // 解锁成功.
  50. ctx()->heros->Dic->$newHeroId = new Ins_Hero();
  51. return Resp::ok();
  52. }
  53. /**
  54. * 6601 切换英雄
  55. */
  56. private static function SwithHero() {
  57. list($newHeroId) = req()->paras; # 切换英雄id
  58. my_Assert(CommUtil::isPropertyExists(ctx()->heros->Dic, $newHeroId), "尚未获得此英雄!");
  59. ctx()->heros->CurrentHeroId = $newHeroId;
  60. return Resp::ok();
  61. }
  62. }