-
Notifications
You must be signed in to change notification settings - Fork 11
/
Components.cs
198 lines (166 loc) · 5.88 KB
/
Components.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using Swihoni.Components;
using Swihoni.Sessions;
using Swihoni.Sessions.Components;
using Swihoni.Sessions.Player.Components;
using UnityEngine;
using Voxels;
using Voxels.Map;
namespace Voxelfield.Session
{
/* Session */
[Serializable]
public class VoxelMapNameProperty : StringProperty
{
public VoxelMapNameProperty(string @string) : base(@string, 16) { }
public VoxelMapNameProperty() : base(16) { }
}
public class CurePackagesArray : ArrayElement<CurePackageComponent>
{
public CurePackagesArray() : base(9) { }
}
[Serializable, ModeElement]
public class ShowdownSessionComponent : ComponentBase
{
public ByteProperty number;
public TimeUsProperty remainingUs;
public CurePackagesArray curePackages = new();
}
[Serializable, ModeElement]
public class DualScoresArray : ArrayElement<ByteProperty>
{
public DualScoresArray() : base(2) { }
public void Swap()
{
byte first = this[0];
this[0].Value = this[1];
this[1].Value = first;
}
}
[Serializable]
public class MapGenerationProperty : UIntProperty
{
public void Reload() => Value++;
}
/* Capture the flag */
[Serializable, ModeElement]
public class FlagComponent : ComponentBase
{
public ByteProperty capturingPlayerId;
public ElapsedUsProperty captureElapsedTimeUs;
}
[Serializable, ModeElement]
public class TeamFlagArray : ArrayElement<FlagArray>
{
public const int Count = 2;
public TeamFlagArray() : base(Count) { }
}
[Serializable, ModeElement]
public class FlagArray : ArrayElement<FlagComponent>
{
public const int Count = 2;
public FlagArray() : base(Count) { }
}
[Serializable, ModeElement]
public class CtfComponent : ComponentBase
{
public TeamFlagArray teamFlags;
public UIntProperty pickupFlags;
[NoSerialization] public ArrayElement<TimeUsProperty> pickupCoolDowns = new(sizeof(uint) * 8);
}
/* Secure area */
[Serializable, ModeElement]
public class SiteComponent : ComponentBase
{
public TimeUsProperty timeUs;
public BoolProperty isRedInside, isBlueInside;
}
[Serializable, ModeElement]
public class SiteArray : ArrayElement<SiteComponent>
{
public SiteArray() : base(2) { }
}
[Serializable, ModeElement]
public class SecureAreaComponent : ComponentBase
{
public SiteArray sites = new();
public TimeUsProperty roundTime;
[NoSerialization] public ByteProperty lastWinningTeam;
public bool RedInside(out SiteComponent element)
{
foreach (SiteComponent site in sites)
{
if (site.isRedInside)
{
element = site;
return true;
}
}
element = default;
return false;
}
}
[Serializable, ModeElement]
public class CurePackageComponent : ComponentBase
{
public BoolProperty isActive;
}
/* Player */
[Serializable, OnlyServerTrusted, ModeElement]
public class ShowdownPlayerComponent : ComponentBase
{
public ByteProperty stagesCuredFlags;
public ElapsedUsProperty elapsedSecuringUs;
public bool IsCured(ShowdownSessionComponent showdown) => (stagesCuredFlags & (byte) (1 << showdown.number)) != 0;
}
[Serializable, ClientTrusted, ModeElement]
public class DesignerPlayerComponent : ComponentBase
{
public Position3IntProperty positionOne, positionTwo;
public VoxelChangeProperty selectedVoxel;
public UShortProperty selectedModelId;
public FloatProperty editRadius;
}
[Serializable, ModeElement]
public class MoneyComponent : ComponentBase
{
[OnlyServerTrusted] public UShortProperty count;
}
[Serializable, SingleTick]
public class WantedItemComponent : ComponentBase
{
public ByteProperty id;
}
[Serializable]
public class WantedItemIdArray : ArrayElement<ByteProperty>
{
public WantedItemIdArray() : base(ItemsArray.ItemsCount) { }
}
[Serializable, OnlyServerTrusted, ModeElement]
public class BrokeVoxelTickProperty : ByteProperty
{
}
[Serializable]
public class ExtentsProperty : VectorProperty
{
public ExtentsProperty() { }
public ExtentsProperty(float x, float y, float z) : base(x, y, z) { }
}
public static class VoxelfieldComponents
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void Initialize()
=> SerializationRegistrar.RegisterAll(typeof(ModelIdProperty), typeof(ByteIdProperty), typeof(TeamProperty),
typeof(VectorProperty), typeof(ModeIdProperty), typeof(ExtentsProperty));
public static readonly SessionElements SessionElements;
static VoxelfieldComponents()
{
SessionElements = SessionElements.NewStandardSessionElements();
SessionElements.playerElements.AppendAll(typeof(ShowdownPlayerComponent), typeof(DesignerPlayerComponent), typeof(SecureAreaComponent), typeof(MoneyComponent),
typeof(BrokeVoxelTickProperty), typeof(SteamIdProperty), typeof(FlashProperty));
SessionElements.commandElements.AppendAll(typeof(WantedItemComponent), typeof(WantedItemIdArray));
SessionElements.elements.AppendAll(typeof(VoxelMapNameProperty), typeof(OrderedVoxelChangesProperty), typeof(MapGenerationProperty),
typeof(CtfComponent), typeof(ShowdownSessionComponent), typeof(SecureAreaComponent), typeof(DualScoresArray));
}
}
}