GamePendingState.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.playerId = _gameCore.localPlayer.playerId;
  54. antiCockActionComp.playerId = _gameCore.antiPlayer.playerId;
  55. _gameCore.cockActionComps.Add(_gameCore.localPlayer.playerId, localCockActionComp);
  56. _gameCore.cockActionComps.Add(_gameCore.antiPlayer.playerId, antiCockActionComp);
  57. // 处理声音组件
  58. localCock.GetComponent<SoundCtrl>().Tag = "player-" + _gameCore.localPlayer.playerId;
  59. antiCock.GetComponent<SoundCtrl>().Tag = "player-" + _gameCore.antiPlayer.playerId;
  60. // 处理方向位置
  61. localCock.transform.eulerAngles = new Vector3(0, 90, 0);
  62. antiCock.transform.eulerAngles = new Vector3(0, -90, 0);
  63. localCock.transform.position = new Vector3(-CockInitialX - StaticOffset, localCock.transform.position.y,
  64. localCock.transform.position.z);
  65. antiCock.transform.position =
  66. new Vector3(CockInitialX - StaticOffset, antiCock.transform.position.y, antiCock.transform.position.z);
  67. localCock.transform.parent = _gameCore.parent.transform;
  68. antiCock.transform.parent = _gameCore.parent.transform;
  69. // 处理主人模型
  70. var masterPrefab = Resources.Load<GameObject>("Human/prefab_master");
  71. var localMaster = Object.Instantiate(masterPrefab);
  72. var antiMaster = Object.Instantiate(masterPrefab);
  73. localMaster.transform.position = new Vector3(-MastInitialX - StaticOffset, localMaster.transform.position.y,
  74. localMaster.transform.position.z);
  75. antiMaster.transform.position =
  76. new Vector3(MastInitialX - StaticOffset, antiMaster.transform.position.y,
  77. antiMaster.transform.position.z);
  78. antiMaster.transform.eulerAngles = new Vector3(0, -90f, 0);
  79. localMaster.transform.parent = _gameCore.parent.transform;
  80. antiMaster.transform.parent = _gameCore.parent.transform;
  81. var localMasterActionComp = localMaster.GetComponent<MasterActionComp>();
  82. localMasterActionComp.playerId = _gameCore.localPlayer.playerId;
  83. var antiMasterActionComp = antiMaster.GetComponent<MasterActionComp>();
  84. antiMasterActionComp.playerId = _gameCore.antiPlayer.playerId;
  85. _gameCore.masterDict.Add(_gameCore.localPlayer.playerId, localMasterActionComp);
  86. _gameCore.masterDict.Add(_gameCore.antiPlayer.playerId, antiMasterActionComp);
  87. SoundCore.Instance.PlaySound(SoundType.BattleBgmStart, SoundCtrl.BattleEnvPlayer);
  88. Debug.Log("enter pending state finish");
  89. }
  90. public override void ExitState()
  91. {
  92. // 啥都不做
  93. }
  94. public GamePendingState(GameCore gameCore) : base(gameCore)
  95. {
  96. }
  97. }
  98. }