summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/MedScanSystem.cs
blob: 8a5f6721cd368bf5c7e734166a21e69d2b744656 (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
using System;
using System.Collections.Generic;
using Hazel;
using UnityEngine;

public class MedScanSystem : ISystemType
{
	public byte CurrentUser { get; private set; } = byte.MaxValue;

	public const byte Request = 128;

	public const byte Release = 64;

	public const byte NumMask = 31;

	public const byte NoPlayer = 255;

	public List<byte> UsersList = new List<byte>();

	public bool Detoriorate(float deltaTime)
	{
		if (this.UsersList.Count > 0)
		{
			if (this.CurrentUser != this.UsersList[0])
			{
				if (this.CurrentUser != 255)
				{
					Debug.Log("Released scanner from: " + this.CurrentUser);
				}
				this.CurrentUser = this.UsersList[0];
				Debug.Log("Acquired scanner for: " + this.CurrentUser);
				return true;
			}
		}
		else if (this.CurrentUser != 255)
		{
			Debug.Log("Released scanner from: " + this.CurrentUser);
			this.CurrentUser = byte.MaxValue;
			return true;
		}
		return false;
	}

	public void RepairDamage(PlayerControl player, byte data)
	{
		byte playerId = data & 31;
		if ((data & 128) != 0)
		{
			if (!this.UsersList.Contains(playerId))
			{
				Debug.Log("Added to queue: " + playerId);
				this.UsersList.Add(playerId);
				return;
			}
		}
		else if ((data & 64) != 0)
		{
			Debug.Log("Removed from queue: " + playerId);
			this.UsersList.RemoveAll((byte v) => v == playerId);
		}
	}

	public void Serialize(MessageWriter writer, bool initialState)
	{
		writer.WritePacked(this.UsersList.Count);
		for (int i = 0; i < this.UsersList.Count; i++)
		{
			writer.Write(this.UsersList[i]);
		}
	}

	public void Deserialize(MessageReader reader, bool initialState)
	{
		this.UsersList.Clear();
		int num = reader.ReadPackedInt32();
		for (int i = 0; i < num; i++)
		{
			this.UsersList.Add(reader.ReadByte());
		}
	}
}