blob: 0e400ad476f24cf373b52deaf3cefdee8b3581e9 (
plain)
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
|
using System;
using Hazel;
public class SwitchSystem : ISystemType, IActivatable
{
public float Level
{
get
{
return (float)this.Value / 255f;
}
}
public bool IsActive
{
get
{
return this.ExpectedSwitches != this.ActualSwitches;
}
}
public const byte MaxValue = 255;
public const int NumSwitches = 5;
public const byte DamageSystem = 128;
public const byte SwitchesMask = 31;
public float DetoriorationTime = 0.03f;
public byte Value = byte.MaxValue;
private float timer;
public byte ExpectedSwitches;
public byte ActualSwitches;
public SwitchSystem()
{
Random random = new Random();
this.ExpectedSwitches = (byte)(random.Next() & 31);
this.ActualSwitches = this.ExpectedSwitches;
}
public bool Detoriorate(float deltaTime)
{
this.timer += deltaTime;
if (this.timer >= this.DetoriorationTime)
{
this.timer = 0f;
if (this.ExpectedSwitches != this.ActualSwitches)
{
if (this.Value > 0)
{
this.Value = (byte)Math.Max((int)(this.Value - 3), 0);
}
if (!SwitchSystem.HasTask<ElectricTask>())
{
PlayerControl.LocalPlayer.AddSystemTask(SystemTypes.Electrical);
}
}
else if (this.Value < 255)
{
this.Value = (byte)Math.Min((int)(this.Value + 3), 255);
}
}
return false;
}
public void RepairDamage(PlayerControl player, byte amount)
{
if (amount.HasBit(128))
{
this.ActualSwitches ^= (amount & 31);
return;
}
this.ActualSwitches ^= (byte)(1 << (int)amount);
}
public void Serialize(MessageWriter writer, bool initialState)
{
writer.Write(this.ExpectedSwitches);
writer.Write(this.ActualSwitches);
writer.Write(this.Value);
}
public void Deserialize(MessageReader reader, bool initialState)
{
this.ExpectedSwitches = reader.ReadByte();
this.ActualSwitches = reader.ReadByte();
this.Value = reader.ReadByte();
}
protected static bool HasTask<T>()
{
for (int i = PlayerControl.LocalPlayer.myTasks.Count - 1; i > 0; i--)
{
if (PlayerControl.LocalPlayer.myTasks[i] is T)
{
return true;
}
}
return false;
}
}
|