forked from PerpetuumOnline/PerpetuumServer
-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathEntityDefaultOptions.cs
More file actions
180 lines (136 loc) · 5.12 KB
/
EntityDefaultOptions.cs
File metadata and controls
180 lines (136 loc) · 5.12 KB
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
using Perpetuum.ExportedTypes;
using Perpetuum.GenXY;
using Perpetuum.Zones.NpcSystem;
using Perpetuum.Zones.RemoteControl;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace Perpetuum.EntityFramework
{
public sealed class EntityDefaultOptions
{
private readonly IDictionary<string, object> _dictionary = new Dictionary<string, object>();
public EntityDefaultOptions() { }
public EntityDefaultOptions(IDictionary<string, object> dictionary)
{
_dictionary = dictionary;
}
public TReturnType GetOption<TReturnType>(string keyName)
{
return _dictionary.GetOrDefault<TReturnType>(keyName);
}
public int AlarmPeriod => _dictionary.GetOrDefault<int>(k.alarmPeriod);
public bool PublicBeam => _dictionary.GetOrDefault<int>(k.publicBeam) == 1;
public int Points => _dictionary.GetOrDefault<int>(k.points);
public int ProductionTime => _dictionary.GetOrDefault<int>(k.productionTime);
public int Level => _dictionary.GetOrDefault<int>(k.level);
public double PerSecondPrice => _dictionary.GetOrDefault<double>(k.perSecondPrice);
public double BulletTime => _dictionary.GetOrDefault<double>(k.bulletTime);
public string MineralLayer => _dictionary.GetOrDefault<string>(k.mineral);
public double Capacity => _dictionary.GetOrDefault<double>(k.capacity);
public int AmmoCapacity => _dictionary.GetOrDefault<int>(k.ammoCapacity);
public int ModuleFlag => _dictionary.GetOrDefault<int>(k.moduleFlag);
[NotNull]
public int[] SlotFlags => _dictionary.GetOrDefault<int[]>(k.slotFlags) ?? new int[0];
public Position SpawnPosition
{
get
{
int x = _dictionary.GetOrDefault<int>(k.spawnPositionX);
int y = _dictionary.GetOrDefault<int>(k.spawnPositionY);
return new Position(x, y);
}
}
public int SpawnRange => _dictionary.GetOrDefault<int>(k.spawnRange);
public int Size => _dictionary.GetOrDefault<int>(k.size);
public int DockingRange => _dictionary.GetOrDefault<int>(k.dockRange);
public int Max => _dictionary.GetOrDefault<int>(k.max);
public int Increase => _dictionary.GetOrDefault<int>(k.increase);
public double Height => _dictionary.GetOrDefault(k.height, 1.0);
public int Item => _dictionary.GetOrDefault<int>(k.item);
[NotNull]
public EffectType[] Effects => _dictionary.GetOrDefault<int[]>(k.effect).Select(e => (EffectType)e).ToArray();
public int Type => _dictionary.GetOrDefault<int>(k.type);
public string Tier => _dictionary.GetOrDefault<string>("tier");
public TechTreePointType KernelPointType => _dictionary.GetOrDefault<TechTreePointType>("pointType");
public string ToGenxyString()
{
return GenxyConverter.Serialize(_dictionary);
}
public int ExtensionPoints
{
get
{
int ep = _dictionary.GetOrDefault("ep", 0);
Debug.Assert(ep > 0);
return ep;
}
}
public int Credit
{
get
{
int credit = _dictionary.GetOrDefault("credit", 0);
Debug.Assert(credit > 0);
return credit;
}
}
public int SparkID
{
get
{
int id = _dictionary.GetOrDefault("sparkId", 0);
Debug.Assert(id > 0);
return id;
}
}
public int TurretId
{
get
{
int id = _dictionary.GetOrDefault(k.TurretId, 0);
Debug.Assert(id > 0);
return id;
}
}
public int PackedTurretId
{
get
{
int id = _dictionary.GetOrDefault(k.PackedTurretId, 0);
Debug.Assert(id > 0);
return id;
}
}
public TurretType TurretType
{
get
{
string typeString = _dictionary.GetOrDefault<string>("turretType");
return (TurretType)Enum.Parse(typeof(TurretType), typeString);
}
}
public Faction Faction
{
get
{
string typeString = _dictionary.GetOrDefault<string>("faction");
return typeString != null ?
(Faction)Enum.Parse(typeof(Faction), typeString)
: Faction.Niani;
}
}
public int[] AllowedBots
{
get
{
int[] ids = _dictionary.GetOrDefault(k.AllowedBots, Array.Empty<int>());
Debug.Assert(ids.Length > 0);
return ids;
}
}
public int PlasmaDefinition => _dictionary.GetOrDefault<int>(k.PlasmaDefinition);
public int PlasmaConsumption => _dictionary.GetOrDefault<int>(k.PlasmaConsumption);
}
}