BossBattleField.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using UnityEngine;
  2. using System.Collections;
  3. public class BossBattleField : BattleField
  4. {
  5. private BossBattle mBattle;
  6. private SpawnPointCfg mBossSpawnCfg;
  7. private BossBattleFieldState mState;
  8. private ReadyPoint mActorReadyPoint;
  9. private bool ignoreBossCheck;
  10. public bool Pause
  11. {
  12. get;private set;
  13. }
  14. public override string Name
  15. {
  16. get { return "BossBattleField"; }
  17. }
  18. public BossBattle Battle
  19. {
  20. get { return mBattle; }
  21. }
  22. public BossBattleFieldStateType CurrentState
  23. {
  24. get { return mState != null ? mState.State : BossBattleFieldStateType.None; }
  25. set
  26. {
  27. if (CurrentState == value) return;
  28. int oldState = (int)CurrentState;
  29. if (mState != null)
  30. mState.OnLeave();
  31. mState = BossBattleFieldState.Create(this, value);
  32. mCurrentStateFrame = 0;
  33. if (mState != null)
  34. mState.OnEnter();
  35. }
  36. }
  37. public override bool IsIdleState
  38. {
  39. get { return CurrentState == BossBattleFieldStateType.None; }
  40. }
  41. public override bool IsFightingState
  42. {
  43. get { return CurrentState == BossBattleFieldStateType.Fighting && !Pause; }
  44. }
  45. public override float FloorY
  46. {
  47. get { return mBossSpawnCfg != null ? mBossSpawnCfg.Pos.y : 0; }
  48. }
  49. public override Vector3 FieldCenter
  50. {
  51. get
  52. {
  53. return mBossSpawnCfg != null ? mBossSpawnCfg.PointList[1].pos : Vector3.zero;
  54. }
  55. }
  56. public override Vector3 FieldFocus
  57. {
  58. get
  59. {
  60. if (Fighters.Count == 0)
  61. return mBossSpawnCfg.Pos;
  62. Vector3 min = Vector3.zero;
  63. Vector3 max = Vector3.zero;
  64. bool hasSet = false;
  65. for (int idx = 0; idx < Fighters.Count; idx++)
  66. {
  67. Fighter f = Fighters[idx];
  68. if (!hasSet)
  69. {
  70. min = f.Position;
  71. max = f.Position;
  72. hasSet = true;
  73. }
  74. else
  75. {
  76. min = Vector3.Min(f.Position, min);
  77. max = Vector3.Max(f.Position, max);
  78. }
  79. }
  80. return 0.5f * (min + max) + Vector3.up * 1.0f;
  81. }
  82. }
  83. public BossBattleField(BossBattle battle,SpawnPointCfg cfg):
  84. base(battle,cfg.Pos,new Vector3(20,20,20),Vector3.forward)
  85. {
  86. mBattle = battle;
  87. mBossSpawnCfg = cfg;
  88. FightingTime = 0;
  89. }
  90. public void Start()
  91. {
  92. Result = FightingResult.None;
  93. FightingTime = 0;
  94. CurrentState = BossBattleFieldStateType.Start;
  95. }
  96. public void Fight()
  97. {
  98. Result = FightingResult.None;
  99. FightingTime = 0;
  100. CurrentState = BossBattleFieldStateType.Fighting;
  101. }
  102. public override void AddFighter(Fighter fighter)
  103. {
  104. base.AddFighter(fighter);
  105. if (mBattle != null)
  106. mBattle.FighterMgr.AddFighterToBattleField(fighter);
  107. }
  108. public override void RemoveFighter(Fighter fighter)
  109. {
  110. base.RemoveFighter(fighter);
  111. if (mBattle != null)
  112. mBattle.FighterMgr.RemoveFighterFromBattleField(fighter);
  113. }
  114. public override void Update(float deltaTime)
  115. {
  116. base.Update(deltaTime);
  117. if (mState != null)
  118. {
  119. #if PROFILE
  120. UnityEngine.Profiling.Profiler.BeginSample("BossBattleField update:" + mState.State);
  121. #endif
  122. mState.Update(deltaTime);
  123. #if PROFILE
  124. UnityEngine.Profiling.Profiler.EndSample();
  125. #endif
  126. }
  127. }
  128. public override void DoPauseFight(bool pause)
  129. {
  130. Pause = pause;
  131. if (Pause)
  132. {
  133. EffectManager.Instance.PauseAllEffects();
  134. }
  135. else
  136. {
  137. EffectManager.Instance.ResumeAllEffects();
  138. }
  139. }
  140. public override void GetFieldSummonPos(int posVal, out Vector3 pos, out Vector3 rot)
  141. {
  142. if (mBattle.SpawnCfg == null)
  143. {
  144. pos = Vector3.zero;
  145. rot = Vector3.zero;
  146. return;
  147. }
  148. MonsterSpawnLoc loc = mBattle.SpawnCfg.PointList[posVal - 1];
  149. pos = loc.pos;
  150. rot = loc.rot;
  151. }
  152. }