-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateBoardStructure.cs
More file actions
136 lines (124 loc) · 4.57 KB
/
CreateBoardStructure.cs
File metadata and controls
136 lines (124 loc) · 4.57 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
using System.Collections.Generic;
using Assets.Scripts.GridSystem;
using Assets.Scripts.Networking;
using Assets.Scripts.Objects;
using LaunchPadBooster.Networking;
using UnityEngine;
namespace LibConstruct
{
public class CreateBoardStructureInstance
{
public MultiConstructor Constructor;
public PlacementBoard Board;
public IPlacementBoardStructure StructurePrefab;
public Grid3 Position;
public int Rotation;
public int CustomColor = -1;
public ulong OwnerClientId;
public bool AuthoringMode;
public CreateBoardStructureInstance(
MultiConstructor constructor,
IPlacementBoardStructure prefabToCreate,
PlacementBoard board,
Grid3 position,
int rotation,
ulong ownerClientId,
bool authoringMode,
int colorIndex = -1
)
{
this.Constructor = constructor;
this.Board = board;
this.StructurePrefab = prefabToCreate;
this.Position = position;
this.Rotation = rotation;
this.OwnerClientId = ownerClientId;
this.CustomColor = colorIndex;
this.AuthoringMode = authoringMode;
}
public CreateBoardStructureInstance(CreateBoardStructureMessage message)
{
this.Constructor = message.AuthoringMode ?
Prefab.Find<MultiConstructor>((int)message.ConstructorId) :
Thing.Find<MultiConstructor>(message.ConstructorId);
this.Board = PlacementBoard.FindExisting(message.BoardID, message.BoardHostID);
this.StructurePrefab = (IPlacementBoardStructure)Prefab.Find<Structure>(message.PrefabHash);
this.Position = message.Position;
this.Rotation = message.Rotation;
this.OwnerClientId = message.OwnerClientId;
this.CustomColor = message.CustomColor;
this.AuthoringMode = message.AuthoringMode;
}
public Vector3 WorldPosition => this.Board.GridToWorld(this.Position);
public Quaternion WorldRotation => this.Board.IndexToRotation(this.Rotation);
}
public class CreateBoardStructureMessage : ModNetworkMessage<CreateBoardStructureMessage>
{
public long ConstructorId;
public long BoardID;
public long BoardHostID;
public int PrefabHash;
public Grid3 Position;
public int Rotation;
public int CustomColor;
public ulong OwnerClientId;
public bool AuthoringMode;
public CreateBoardStructureMessage() { }
public CreateBoardStructureMessage(CreateBoardStructureInstance create)
{
var prefabStructure = (Structure)create.StructurePrefab;
this.ConstructorId = create.AuthoringMode ? create.Constructor.PrefabHash : create.Constructor.ReferenceId;
this.BoardID = create.Board.ID;
this.BoardHostID = create.Board.PrimaryHost.ReferenceId;
this.PrefabHash = prefabStructure.PrefabHash;
this.Position = create.Position;
this.Rotation = create.Rotation;
this.CustomColor = create.CustomColor;
this.OwnerClientId = create.OwnerClientId;
this.AuthoringMode = create.AuthoringMode;
}
public override void Deserialize(RocketBinaryReader reader)
{
this.ConstructorId = reader.ReadInt64();
this.BoardID = reader.ReadInt64();
this.BoardHostID = reader.ReadInt64();
this.PrefabHash = reader.ReadInt32();
this.Position = reader.ReadGrid3();
this.Rotation = reader.ReadSByte();
this.CustomColor = reader.ReadInt32();
this.OwnerClientId = reader.ReadUInt64();
this.AuthoringMode = reader.ReadBoolean();
}
public override void Serialize(RocketBinaryWriter writer)
{
writer.WriteInt64(this.ConstructorId);
writer.WriteInt64(this.BoardID);
writer.WriteInt64(this.BoardHostID);
writer.WriteInt32(this.PrefabHash);
writer.WriteGrid3(this.Position);
writer.WriteSByte((sbyte)this.Rotation);
writer.WriteInt32(this.CustomColor);
writer.WriteUInt64(this.OwnerClientId);
writer.WriteBoolean(this.AuthoringMode);
}
public override void Process(long hostId)
{
base.Process(hostId);
var constructor = this.AuthoringMode ?
Prefab.Find<MultiConstructor>((int)this.ConstructorId) :
Thing.Find<MultiConstructor>(this.ConstructorId);
var host = Thing.Find<IPlacementBoardHost>(this.BoardHostID);
if (constructor == null || host == null)
{
var ids = new List<long> { this.BoardHostID };
if (!this.AuthoringMode)
ids.Add(this.ConstructorId);
this.WaitUntilFound(hostId, this.Process, this.Process, ids, 3f, "CreateBoardStructure", true);
}
else
{
PlacementBoard.CreateBoardStructure(new CreateBoardStructureInstance(this));
}
}
}
}