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  UpdateTalentRefundPoints = 17,
33  ConfirmTalentRefund = 18,
34 
35  MinValue = 0,
36  MaxValue = 18
37  }
38 
39  private interface IEventData : NetEntityEvent.IData
40  {
41  public EventType EventType { get; }
42  }
43 
44  public readonly struct InventoryStateEventData : IEventData
45  {
46  public EventType EventType => EventType.InventoryState;
47  public readonly Range SlotRange;
48 
49  public InventoryStateEventData(Range slotRange)
50  {
51  SlotRange = slotRange;
52  }
53  }
54 
55  public readonly struct ControlEventData : IEventData
56  {
57  public EventType EventType => EventType.Control;
58  public readonly Client Owner;
59 
60  public ControlEventData(Client owner)
61  {
62  Owner = owner;
63  }
64  }
65 
66  public struct CharacterStatusEventData : IEventData
67  {
68  public EventType EventType => EventType.Status;
69 
70 #if SERVER
71  public bool ForceAfflictionData;
72 
73  public CharacterStatusEventData(bool forceAfflictionData)
74  {
75  ForceAfflictionData = forceAfflictionData;
76  }
77 #endif
78  }
79 
80  public struct TreatmentEventData : IEventData
81  {
82  public EventType EventType => EventType.Treatment;
83  }
84 
85  private interface IAttackEventData : IEventData
86  {
87  public Limb AttackLimb { get; }
88  public IDamageable TargetEntity { get; }
89  public Limb TargetLimb { get; }
90  public Vector2 TargetSimPos { get; }
91  }
92 
93  public struct SetAttackTargetEventData : IAttackEventData
94  {
95  public EventType EventType => EventType.SetAttackTarget;
96  public Limb AttackLimb { get; }
97  public IDamageable TargetEntity { get; }
98  public Limb TargetLimb { get; }
99  public Vector2 TargetSimPos { get; }
100 
101  public SetAttackTargetEventData(Limb attackLimb, IDamageable targetEntity, Limb targetLimb, Vector2 targetSimPos)
102  {
103  AttackLimb = attackLimb;
104  TargetEntity = targetEntity;
105  TargetLimb = targetLimb;
106  TargetSimPos = targetSimPos;
107  }
108  }
109 
110  public struct ExecuteAttackEventData : IAttackEventData
111  {
112  public EventType EventType => EventType.ExecuteAttack;
113  public Limb AttackLimb { get; }
114  public IDamageable TargetEntity { get; }
115  public Limb TargetLimb { get; }
116  public Vector2 TargetSimPos { get; }
117 
118  public ExecuteAttackEventData(Limb attackLimb, IDamageable targetEntity, Limb targetLimb, Vector2 targetSimPos)
119  {
120  AttackLimb = attackLimb;
121  TargetEntity = targetEntity;
122  TargetLimb = targetLimb;
123  TargetSimPos = targetSimPos;
124  }
125  }
126 
127  public struct AssignCampaignInteractionEventData : IEventData
128  {
129  public EventType EventType => EventType.AssignCampaignInteraction;
130  }
131 
132  public struct ObjectiveManagerStateEventData : IEventData
133  {
134  public EventType EventType => EventType.ObjectiveManagerState;
136 
138  {
139  ObjectiveType = objectiveType;
140  }
141  }
142 
143  public readonly struct LatchedOntoTargetEventData : IEventData
144  {
145  public EventType EventType => EventType.LatchOntoTarget;
146  public readonly bool IsLatched;
147  public readonly UInt16 TargetCharacterID = NullEntityID;
148  public readonly UInt16 TargetStructureID = NullEntityID;
149  public readonly int TargetLevelWallIndex = -1;
150 
151  public readonly Vector2 AttachSurfaceNormal = Vector2.Zero;
152  public readonly Vector2 AttachPos = Vector2.Zero;
153 
154  public readonly Vector2 CharacterSimPos;
155 
156  private LatchedOntoTargetEventData(Character character, Vector2 attachSurfaceNormal, Vector2 attachPos)
157  {
158  CharacterSimPos = character.SimPosition;
159  IsLatched = true;
160  AttachSurfaceNormal = attachSurfaceNormal;
161  AttachPos = attachPos;
162  }
163 
164  public LatchedOntoTargetEventData(Character character, Character targetCharacter, Vector2 attachSurfaceNormal, Vector2 attachPos)
165  : this(character, attachSurfaceNormal, attachPos)
166  {
167  TargetCharacterID = targetCharacter.ID;
168  }
169 
170  public LatchedOntoTargetEventData(Character character, Structure targetStructure, Vector2 attachSurfaceNormal, Vector2 attachPos)
171  : this(character, attachSurfaceNormal, attachPos)
172  {
173  TargetStructureID = targetStructure.ID;
174  }
175 
176  public LatchedOntoTargetEventData(Character character, VoronoiCell levelWall, Vector2 attachSurfaceNormal, Vector2 attachPos)
177  : this(character, attachSurfaceNormal, attachPos)
178  {
179  TargetLevelWallIndex = Level.Loaded.GetAllCells().IndexOf(levelWall);
180  }
181 
186  {
187  CharacterSimPos = Vector2.Zero;
188  IsLatched = false;
189  }
190  }
191 
192  private struct TeamChangeEventData : IEventData
193  {
194  public EventType EventType => EventType.TeamChange;
195  }
196 
197  [NetworkSerialize]
198  public readonly record struct ItemTeamChange(CharacterTeamType TeamId, ImmutableArray<UInt16> ItemIds) : INetSerializableStruct;
199 
200 
201  public struct AddToCrewEventData : IEventData
202  {
203  public EventType EventType => EventType.AddToCrew;
204  public readonly ItemTeamChange ItemTeamChange;
205 
206  public AddToCrewEventData(CharacterTeamType teamType, IEnumerable<Item> inventoryItems)
207  {
208  ItemTeamChange = new ItemTeamChange(teamType, inventoryItems.Select(it => it.ID).ToImmutableArray());
209  }
210  }
211 
212  public struct RemoveFromCrewEventData : IEventData
213  {
214  public EventType EventType => EventType.RemoveFromCrew;
216 
217  public RemoveFromCrewEventData(CharacterTeamType teamType, IEnumerable<Item> inventoryItems)
218  {
219  ItemTeamChange = new ItemTeamChange(teamType, inventoryItems.Select(it => it.ID).ToImmutableArray());
220  }
221  }
222 
223  public struct UpdateExperienceEventData : IEventData
224  {
225  public EventType EventType => EventType.UpdateExperience;
226  }
227 
228  public struct UpdateTalentsEventData : IEventData
229  {
230  public EventType EventType => EventType.UpdateTalents;
231  }
232 
233  public struct UpdateSkillsEventData : IEventData
234  {
235  public readonly EventType EventType => EventType.UpdateSkills;
236 
237  public readonly bool ForceNotification;
238  public readonly Identifier SkillIdentifier;
239 
240  public UpdateSkillsEventData(Identifier skillIdentifier, bool forceNotification)
241  {
242  SkillIdentifier = skillIdentifier;
243  ForceNotification = forceNotification;
244  }
245  }
246 
247  private struct UpdateMoneyEventData : IEventData
248  {
249  public EventType EventType => EventType.UpdateMoney;
250  }
251 
252  public struct UpdatePermanentStatsEventData : IEventData
253  {
254  public EventType EventType => EventType.UpdatePermanentStats;
255  public readonly StatTypes StatType;
256 
258  {
259  StatType = statType;
260  }
261  }
262 
263  public struct UpdateRefundPointsEventData : IEventData
264  {
265  public EventType EventType => EventType.UpdateTalentRefundPoints;
266  }
267 
268  public struct ConfirmRefundEventData : IEventData
269  {
270  public EventType EventType => EventType.ConfirmTalentRefund;
271  }
272  }
273 }
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:195
@ Character
Characters only
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)
UpdateSkillsEventData(Identifier skillIdentifier, bool forceNotification)