Client LuaCsForBarotrauma
CharacterEventData.cs
2 using Microsoft.Xna.Framework;
3 using System;
4 using System.Collections.Generic;
5 using System.Collections.Immutable;
6 using System.Linq;
7 using Voronoi2;
8 
9 namespace Barotrauma
10 {
11  partial class Character
12  {
13  public enum EventType
14  {
15  InventoryState = 0,
16  Control = 1,
17  Status = 2,
18  Treatment = 3,
19  SetAttackTarget = 4,
20  ExecuteAttack = 5,
21  AssignCampaignInteraction = 6,
22  ObjectiveManagerState = 7,
23  TeamChange = 8,
24  AddToCrew = 9,
25  UpdateExperience = 10,
26  UpdateTalents = 11,
27  UpdateSkills = 12,
28  UpdateMoney = 13,
29  UpdatePermanentStats = 14,
30  RemoveFromCrew = 15,
31  LatchOntoTarget = 16,
32 
33  MinValue = 0,
34  MaxValue = 16
35  }
36 
37  private interface IEventData : NetEntityEvent.IData
38  {
39  public EventType EventType { get; }
40  }
41 
42  public readonly struct InventoryStateEventData : IEventData
43  {
44  public EventType EventType => EventType.InventoryState;
45  public readonly Range SlotRange;
46 
47  public InventoryStateEventData(Range slotRange)
48  {
49  SlotRange = slotRange;
50  }
51  }
52 
53  public readonly struct ControlEventData : IEventData
54  {
55  public EventType EventType => EventType.Control;
56  public readonly Client Owner;
57 
58  public ControlEventData(Client owner)
59  {
60  Owner = owner;
61  }
62  }
63 
64  public struct CharacterStatusEventData : IEventData
65  {
66  public EventType EventType => EventType.Status;
67 
68 #if SERVER
69  public bool ForceAfflictionData;
70 
71  public CharacterStatusEventData(bool forceAfflictionData)
72  {
73  ForceAfflictionData = forceAfflictionData;
74  }
75 #endif
76  }
77 
78  public struct TreatmentEventData : IEventData
79  {
80  public EventType EventType => EventType.Treatment;
81  }
82 
83  private interface IAttackEventData : IEventData
84  {
85  public Limb AttackLimb { get; }
86  public IDamageable TargetEntity { get; }
87  public Limb TargetLimb { get; }
88  public Vector2 TargetSimPos { get; }
89  }
90 
91  public struct SetAttackTargetEventData : IAttackEventData
92  {
93  public EventType EventType => EventType.SetAttackTarget;
94  public Limb AttackLimb { get; }
95  public IDamageable TargetEntity { get; }
96  public Limb TargetLimb { get; }
97  public Vector2 TargetSimPos { get; }
98 
99  public SetAttackTargetEventData(Limb attackLimb, IDamageable targetEntity, Limb targetLimb, Vector2 targetSimPos)
100  {
101  AttackLimb = attackLimb;
102  TargetEntity = targetEntity;
103  TargetLimb = targetLimb;
104  TargetSimPos = targetSimPos;
105  }
106  }
107 
108  public struct ExecuteAttackEventData : IAttackEventData
109  {
110  public EventType EventType => EventType.ExecuteAttack;
111  public Limb AttackLimb { get; }
112  public IDamageable TargetEntity { get; }
113  public Limb TargetLimb { get; }
114  public Vector2 TargetSimPos { get; }
115 
116  public ExecuteAttackEventData(Limb attackLimb, IDamageable targetEntity, Limb targetLimb, Vector2 targetSimPos)
117  {
118  AttackLimb = attackLimb;
119  TargetEntity = targetEntity;
120  TargetLimb = targetLimb;
121  TargetSimPos = targetSimPos;
122  }
123  }
124 
125  public struct AssignCampaignInteractionEventData : IEventData
126  {
127  public EventType EventType => EventType.AssignCampaignInteraction;
128  }
129 
130  public struct ObjectiveManagerStateEventData : IEventData
131  {
132  public EventType EventType => EventType.ObjectiveManagerState;
134 
136  {
137  ObjectiveType = objectiveType;
138  }
139  }
140 
141  public readonly struct LatchedOntoTargetEventData : IEventData
142  {
143  public EventType EventType => EventType.LatchOntoTarget;
144  public readonly bool IsLatched;
145  public readonly UInt16 TargetCharacterID = NullEntityID;
146  public readonly UInt16 TargetStructureID = NullEntityID;
147  public readonly int TargetLevelWallIndex = -1;
148 
149  public readonly Vector2 AttachSurfaceNormal = Vector2.Zero;
150  public readonly Vector2 AttachPos = Vector2.Zero;
151 
152  public readonly Vector2 CharacterSimPos;
153 
154  private LatchedOntoTargetEventData(Character character, Vector2 attachSurfaceNormal, Vector2 attachPos)
155  {
156  CharacterSimPos = character.SimPosition;
157  IsLatched = true;
158  AttachSurfaceNormal = attachSurfaceNormal;
159  AttachPos = attachPos;
160  }
161 
162  public LatchedOntoTargetEventData(Character character, Character targetCharacter, Vector2 attachSurfaceNormal, Vector2 attachPos)
163  : this(character, attachSurfaceNormal, attachPos)
164  {
165  TargetCharacterID = targetCharacter.ID;
166  }
167 
168  public LatchedOntoTargetEventData(Character character, Structure targetStructure, Vector2 attachSurfaceNormal, Vector2 attachPos)
169  : this(character, attachSurfaceNormal, attachPos)
170  {
171  TargetStructureID = targetStructure.ID;
172  }
173 
174  public LatchedOntoTargetEventData(Character character, VoronoiCell levelWall, Vector2 attachSurfaceNormal, Vector2 attachPos)
175  : this(character, attachSurfaceNormal, attachPos)
176  {
177  TargetLevelWallIndex = Level.Loaded.GetAllCells().IndexOf(levelWall);
178  }
179 
184  {
185  CharacterSimPos = Vector2.Zero;
186  IsLatched = false;
187  }
188  }
189 
190  private struct TeamChangeEventData : IEventData
191  {
192  public EventType EventType => EventType.TeamChange;
193  }
194 
195  [NetworkSerialize]
196  public readonly record struct ItemTeamChange(CharacterTeamType TeamId, ImmutableArray<UInt16> ItemIds) : INetSerializableStruct;
197 
198 
199  public struct AddToCrewEventData : IEventData
200  {
201  public EventType EventType => EventType.AddToCrew;
202  public readonly ItemTeamChange ItemTeamChange;
203 
204  public AddToCrewEventData(CharacterTeamType teamType, IEnumerable<Item> inventoryItems)
205  {
206  ItemTeamChange = new ItemTeamChange(teamType, inventoryItems.Select(it => it.ID).ToImmutableArray());
207  }
208  }
209 
210  public struct RemoveFromCrewEventData : IEventData
211  {
212  public EventType EventType => EventType.RemoveFromCrew;
214 
215  public RemoveFromCrewEventData(CharacterTeamType teamType, IEnumerable<Item> inventoryItems)
216  {
217  ItemTeamChange = new ItemTeamChange(teamType, inventoryItems.Select(it => it.ID).ToImmutableArray());
218  }
219  }
220 
221  public struct UpdateExperienceEventData : IEventData
222  {
223  public EventType EventType => EventType.UpdateExperience;
224  }
225 
226  public struct UpdateTalentsEventData : IEventData
227  {
228  public EventType EventType => EventType.UpdateTalents;
229  }
230 
231  public struct UpdateSkillsEventData : IEventData
232  {
233  public EventType EventType => EventType.UpdateSkills;
234  }
235 
236  private struct UpdateMoneyEventData : IEventData
237  {
238  public EventType EventType => EventType.UpdateMoney;
239  }
240 
241  public struct UpdatePermanentStatsEventData : IEventData
242  {
243  public EventType EventType => EventType.UpdatePermanentStats;
244  public readonly StatTypes StatType;
245 
247  {
248  StatType = statType;
249  }
250  }
251  }
252 }
void SetAttackTarget(Limb attackLimb, IDamageable damageTarget, Vector2 attackPos)
const ushort NullEntityID
Definition: Entity.cs:14
readonly ushort ID
Unique, but non-persistent identifier. Stays the same if the entities are created in the exactly same...
Definition: Entity.cs:43
StatTypes
StatTypes are used to alter several traits of a character. They are mostly used by talents.
Definition: Enums.cs:180
AddToCrewEventData(CharacterTeamType teamType, IEnumerable< Item > inventoryItems)
ExecuteAttackEventData(Limb attackLimb, IDamageable targetEntity, Limb targetLimb, Vector2 targetSimPos)
LatchedOntoTargetEventData()
Signifies detaching (not attached to any target)
LatchedOntoTargetEventData(Character character, Structure targetStructure, Vector2 attachSurfaceNormal, Vector2 attachPos)
LatchedOntoTargetEventData(Character character, Character targetCharacter, Vector2 attachSurfaceNormal, Vector2 attachPos)
LatchedOntoTargetEventData(Character character, VoronoiCell levelWall, Vector2 attachSurfaceNormal, Vector2 attachPos)
ObjectiveManagerStateEventData(AIObjectiveManager.ObjectiveType objectiveType)
readonly AIObjectiveManager.ObjectiveType ObjectiveType
RemoveFromCrewEventData(CharacterTeamType teamType, IEnumerable< Item > inventoryItems)
SetAttackTargetEventData(Limb attackLimb, IDamageable targetEntity, Limb targetLimb, Vector2 targetSimPos)