Client LuaCsForBarotrauma
BarotraumaShared/SharedSource/Items/ItemEventData.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Collections.Immutable;
4 using System.Linq;
7 using Microsoft.Xna.Framework;
8 
9 namespace Barotrauma
10 {
11  partial class Item
12  {
13  public enum EventType
14  {
15  ComponentState = 0,
16  InventoryState = 1,
17  Treatment = 2,
18  ChangeProperty = 3,
19  Combine = 4,
20  Status = 5,
21  AssignCampaignInteraction = 6,
23  Upgrade = 8,
24  ItemStat = 9,
25  DroppedStack = 10,
26  SetHighlight = 11,
27 
28  MinValue = 0,
29  MaxValue = 11
30  }
31 
32  public interface IEventData : NetEntityEvent.IData
33  {
34  public EventType EventType { get; }
35  }
36 
37  public readonly struct ComponentStateEventData : IEventData
38  {
39  public EventType EventType => EventType.ComponentState;
40  public readonly ItemComponent Component;
42 
44  {
45  Component = component;
46  ComponentData = componentData;
47  }
48  }
49 
50  public readonly struct InventoryStateEventData : IEventData
51  {
52  public EventType EventType => EventType.InventoryState;
53  public readonly ItemContainer Component;
54  public readonly Range SlotRange;
55 
56  public InventoryStateEventData(ItemContainer component, Range slotRange)
57  {
58  Component = component;
59  SlotRange = slotRange;
60  }
61  }
62 
63  public readonly struct ChangePropertyEventData : IEventData
64  {
65  public EventType EventType => EventType.ChangeProperty;
67  public readonly ISerializableEntity Entity;
68 
70  {
71  if (serializableProperty.GetAttribute<Editable>() == null)
72  {
73  DebugConsole.ThrowError($"Attempted to create {nameof(ChangePropertyEventData)} for the non-editable property {serializableProperty.Name}.");
74  }
75  SerializableProperty = serializableProperty;
76  Entity = entity;
77  }
78  }
79 
80  public readonly struct SetItemStatEventData : IEventData
81  {
82  public EventType EventType => EventType.ItemStat;
83 
84  public readonly Dictionary<TalentStatIdentifier, float> Stats;
85 
86  public SetItemStatEventData(Dictionary<TalentStatIdentifier, float> stats)
87  {
88  Stats = stats;
89  }
90  }
91 
92  private readonly struct ItemStatusEventData : IEventData
93  {
94  public EventType EventType => EventType.Status;
95 
96  public readonly bool LoadingRound;
97 
98  public ItemStatusEventData(bool loadingRound)
99  {
100  LoadingRound = loadingRound;
101  }
102  }
103 
104  private readonly struct AssignCampaignInteractionEventData : IEventData
105  {
106  public EventType EventType => EventType.AssignCampaignInteraction;
107 
108  public readonly ImmutableArray<Client> TargetClients;
109 
110  public AssignCampaignInteractionEventData(IEnumerable<Client> targetClients)
111  {
112  TargetClients = (targetClients ?? Enumerable.Empty<Client>()).ToImmutableArray();
113  }
114  }
115 
116  public readonly struct ApplyStatusEffectEventData : IEventData
117  {
118  public EventType EventType => EventType.ApplyStatusEffect;
119  public readonly ActionType ActionType;
121  public readonly Character TargetCharacter;
122  public readonly Limb TargetLimb;
123  public readonly Entity UseTarget;
124  public readonly Vector2? WorldPosition;
125 
127  ActionType actionType,
128  ItemComponent targetItemComponent = null,
129  Character targetCharacter = null,
130  Limb targetLimb = null,
131  Entity useTarget = null,
132  Vector2? worldPosition = null)
133  {
134  ActionType = actionType;
135  TargetItemComponent = targetItemComponent;
136  TargetCharacter = targetCharacter;
137  TargetLimb = targetLimb;
138  UseTarget = useTarget;
139  WorldPosition = worldPosition;
140  }
141  }
142 
143  private readonly struct UpgradeEventData : IEventData
144  {
145  public EventType EventType => EventType.Upgrade;
146  public readonly Upgrade Upgrade;
147 
148  public UpgradeEventData(Upgrade upgrade)
149  {
150  Upgrade = upgrade;
151  }
152  }
153  }
154 }
void ApplyStatusEffect(StatusEffect effect, ActionType type, float deltaTime, Character character=null, Limb limb=null, Entity useTarget=null, bool isNetworkEvent=false, bool checkCondition=true, Vector2? worldPosition=null)
bool Combine(Item item, Character user)
The base class for components holding the different functionalities of the item
ActionType
ActionTypes define when a StatusEffect is executed.
Definition: Enums.cs:19
ApplyStatusEffectEventData(ActionType actionType, ItemComponent targetItemComponent=null, Character targetCharacter=null, Limb targetLimb=null, Entity useTarget=null, Vector2? worldPosition=null)
ChangePropertyEventData(SerializableProperty serializableProperty, ISerializableEntity entity)
ComponentStateEventData(ItemComponent component, ItemComponent.IEventData componentData)
readonly Dictionary< TalentStatIdentifier, float > Stats
SetItemStatEventData(Dictionary< TalentStatIdentifier, float > stats)