GamePendingState.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using Comp;
  2. using Sound;
  3. using UnityEngine;
  4. namespace Game
  5. {
  6. public class GamePendingState : GameState
  7. {
  8. private const float CockInitialX = 2f;
  9. private const float StaticOffset = -2.534481f;
  10. private const float MastInitialX = 6f;
  11. public override void PlayBattle()
  12. {
  13. Debug.Log("play battle");
  14. _gameCore.GetController(_gameCore.localPlayer).Run();
  15. _gameCore.GetController(_gameCore.antiPlayer).Run();
  16. }
  17. public override void BattleStart()
  18. {
  19. _gameCore.TransitionToState(_gameCore.battleState);
  20. _gameCore.GetCurState().BattleStart();
  21. }
  22. public override void LiftCock()
  23. {
  24. // 啥都不做
  25. }
  26. public override void ExitBattle()
  27. {
  28. }
  29. public override void EndBattle()
  30. {
  31. // 啥都不做
  32. }
  33. public override void EnterState()
  34. {
  35. Debug.Log("enter pending state");
  36. // 处理鸡模型
  37. var localCockPrefab = CockFactory.Instance.GenerateCockPrefab(_gameCore.localPlayer.cockId);
  38. var antiCockPrefab = CockFactory.Instance.GenerateCockPrefab(_gameCore.antiPlayer.cockId);
  39. var localCock = Object.Instantiate(localCockPrefab);
  40. var antiCock = Object.Instantiate(antiCockPrefab);
  41. // 处理鸡Hp组件
  42. var localCockHpComp = localCock.GetComponent<CockHpComp>();
  43. var antiCockHpComp = antiCock.GetComponent<CockHpComp>();
  44. localCockHpComp.MaxHp = _gameCore.localPlayer.hp;
  45. antiCockHpComp.MaxHp = _gameCore.antiPlayer.hp;
  46. _gameCore.cockHpComps.Add(_gameCore.localPlayer.playerId, localCockHpComp);
  47. _gameCore.cockHpComps.Add(_gameCore.antiPlayer.playerId, antiCockHpComp);
  48. // 处理鸡动作组件
  49. var localCockActionComp = localCock.GetComponent<CockActionComp>();
  50. var antiCockActionComp = antiCock.GetComponent<CockActionComp>();
  51. localCockActionComp.cockId = _gameCore.localPlayer.cockId;
  52. antiCockActionComp.cockId = _gameCore.antiPlayer.cockId;
  53. localCockActionComp.gameObject.GetComponent<CockMoveComp>().cockId = _gameCore.localPlayer.cockId;
  54. antiCockActionComp.gameObject.GetComponent<CockMoveComp>().cockId = _gameCore.antiPlayer.cockId;
  55. localCockActionComp.playerId = _gameCore.localPlayer.playerId;
  56. antiCockActionComp.playerId = _gameCore.antiPlayer.playerId;
  57. _gameCore.cockActionComps.Add(_gameCore.localPlayer.playerId, localCockActionComp);
  58. _gameCore.cockActionComps.Add(_gameCore.antiPlayer.playerId, antiCockActionComp);
  59. // 处理声音组件
  60. localCock.GetComponent<SoundCtrl>().Tag = "player-" + _gameCore.localPlayer.playerId;
  61. antiCock.GetComponent<SoundCtrl>().Tag = "player-" + _gameCore.antiPlayer.playerId;
  62. // 处理方向位置
  63. localCock.transform.eulerAngles = new Vector3(0, 90, 0);
  64. antiCock.transform.eulerAngles = new Vector3(0, -90, 0);
  65. localCock.transform.position = new Vector3(-CockInitialX - StaticOffset, localCock.transform.position.y,
  66. localCock.transform.position.z);
  67. antiCock.transform.position =
  68. new Vector3(CockInitialX - StaticOffset, antiCock.transform.position.y, antiCock.transform.position.z);
  69. localCock.transform.parent = _gameCore.parent.transform;
  70. antiCock.transform.parent = _gameCore.parent.transform;
  71. // 处理主人模型
  72. var masterPrefab = Resources.Load<GameObject>("Human/prefab_master");
  73. var localMaster = Object.Instantiate(masterPrefab);
  74. var antiMaster = Object.Instantiate(masterPrefab);
  75. localMaster.transform.position = new Vector3(-MastInitialX - StaticOffset, localMaster.transform.position.y,
  76. localMaster.transform.position.z);
  77. antiMaster.transform.position =
  78. new Vector3(MastInitialX - StaticOffset, antiMaster.transform.position.y,
  79. antiMaster.transform.position.z);
  80. antiMaster.transform.eulerAngles = new Vector3(0, -90f, 0);
  81. localMaster.transform.parent = _gameCore.parent.transform;
  82. antiMaster.transform.parent = _gameCore.parent.transform;
  83. var localMasterActionComp = localMaster.GetComponent<MasterActionComp>();
  84. localMasterActionComp.playerId = _gameCore.localPlayer.playerId;
  85. var antiMasterActionComp = antiMaster.GetComponent<MasterActionComp>();
  86. antiMasterActionComp.playerId = _gameCore.antiPlayer.playerId;
  87. _gameCore.masterDict.Add(_gameCore.localPlayer.playerId, localMasterActionComp);
  88. _gameCore.masterDict.Add(_gameCore.antiPlayer.playerId, antiMasterActionComp);
  89. SoundCore.Instance.PlaySound(SoundType.BattleBgmStart, SoundCtrl.BattleEnvPlayer);
  90. Debug.Log("enter pending state finish");
  91. }
  92. public override void ExitState()
  93. {
  94. // 啥都不做
  95. }
  96. public GamePendingState(GameCore gameCore) : base(gameCore)
  97. {
  98. }
  99. }
  100. }