Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Events/Missions/EndMission.cs
2 using System.Collections.Generic;
3 using System.Collections.Immutable;
4 
5 namespace Barotrauma
6 {
7  partial class EndMission : Mission
8  {
9  public override bool DisplayAsCompleted => false;
10 
11  public override bool DisplayAsFailed => false;
12 
13  partial void OnStateChangedProjSpecific()
14  {
15  SoundPlayer.ForceMusicUpdate();
16  if (Phase == MissionPhase.NoItemsDestroyed)
17  {
18  CoroutineManager.Invoke(() =>
19  {
20  if (boss != null && !boss.Removed)
21  {
22  new CameraTransition(boss, GameMain.GameScreen.Cam, null, Alignment.Center, panDuration: 8, fadeOut: false, startZoom: 1.0f, endZoom: 0.3f * GUI.yScale)
23  {
24  RunWhilePaused = false,
25  EndWaitDuration = 3.0f
26  };
27  }
28  }, delay: 3.0f);
29  }
30  else if (Phase == MissionPhase.AllItemsDestroyed)
31  {
32  CoroutineManager.StartCoroutine(wakeUpCoroutine(), name: "EndMission.wakeUpCoroutine");
33  }
34  else if (Phase == MissionPhase.BossKilled)
35  {
36  if (!string.IsNullOrEmpty(endCinematicSound))
37  {
38  SoundPlayer.PlaySound(endCinematicSound);
39  }
40  CoroutineManager.Invoke(() =>
41  {
42  new CameraTransition(boss, GameMain.GameScreen.Cam, null, Alignment.Center, panDuration: 3, fadeOut: false, endZoom: 0.1f * GUI.yScale)
43  {
44  RunWhilePaused = false,
45  EndWaitDuration = float.PositiveInfinity
46  };
47  }, delay: 3.0f);
48  }
49 
50  IEnumerable<CoroutineStatus> wakeUpCoroutine()
51  {
52  yield return new WaitForSeconds(wakeUpCinematicDelay);
53  if (boss != null && !boss.Removed)
54  {
55  new CameraTransition(boss, GameMain.GameScreen.Cam, null, Alignment.Center, panDuration: 5.0f, fadeOut: false, losFadeIn: false, startZoom: 1.0f, endZoom: 0.4f * GUI.yScale)
56  {
57  RunWhilePaused = false,
58  EndWaitDuration = cameraWaitDuration
59  };
60  }
61  yield return new WaitForSeconds(bossWakeUpDelay);
62  if (boss != null && !boss.Removed)
63  {
64  foreach (var limb in boss.AnimController.Limbs)
65  {
66  if (!limb.FreezeBlinkState) { continue; }
67  limb.FreezeBlinkState = false;
68  if (limb.LightSource is Lights.LightSource light)
69  {
70  light.Enabled = true;
71  }
72  }
73  }
74  }
75  }
76 
77  partial void UpdateProjSpecific()
78  {
79  if (boss == null || boss.Removed) { return; }
80  if (Phase is MissionPhase.Initial or MissionPhase.NoItemsDestroyed or MissionPhase.SomeItemsDestroyed)
81  {
82  // Put asleep.
83  // Have to set the light every frame (or at least periodically), because light.Enabled is changed when Character.IsVisible changes (off/on screen). See GameScreen.Draw().
84  foreach (var limb in boss.AnimController.Limbs)
85  {
86  if (limb.Params.BlinkFrequency > 0)
87  {
88  limb.FreezeBlinkState = true;
89  limb.BlinkPhase = -limb.Params.BlinkHoldTime;
90  if (limb.LightSource is Lights.LightSource light)
91  {
92  light.Enabled = false;
93  }
94  }
95  }
96  }
97 
98 #if DEBUG
99  if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.O))
100  {
101  State = 0;
102  }
103  if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.Y))
104  {
105  destructibleItems.ForEach(it => it.Condition = 0.0f);
106  }
107  if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.U))
108  {
109  boss?.SetAllDamage(20000.0f, 0.0f, 0.0f);
110  }
111 #endif
112  }
113 
114  public override void ClientReadInitial(IReadMessage msg)
115  {
116  base.ClientReadInitial(msg);
117 
118  boss = Character.ReadSpawnData(msg);
119 
120  byte minionCount = msg.ReadByte();
121  List<Character> minionList = new List<Character>();
122  for (int i = 0; i < minionCount; i++)
123  {
124  var minion = Character.ReadSpawnData(msg);
125  if (minion == null)
126  {
127  throw new System.Exception($"Error in EndMission.ClientReadInitial: failed to create a minion (mission: {Prefab.Identifier}, index: {i})");
128  }
129  minionList.Add(minion);
130  }
131  minions = minionList.ToImmutableArray();
132  if (minions.Length != minionCount)
133  {
134  throw new System.Exception("Error in EndMission.ClientReadInitial: minion count does not match the server count (" + minionCount + " != " + minions.Length + "mission: " + Prefab.Identifier + ")");
135  }
136  }
137  }
138 }
readonly Identifier Identifier
Definition: Prefab.cs:34