You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.6 KiB
82 lines
2.6 KiB
using System.Collections.Generic; |
|
|
|
namespace ET |
|
{ |
|
[FriendClass(typeof(Construct))] |
|
public static class ConstructSystem |
|
{ |
|
public static void FromMessage(this Construct self, ConstructProto constructProto) |
|
{ |
|
self.Id = constructProto.Id; |
|
self.X = constructProto.X; |
|
self.Y = constructProto.Y; |
|
self.UpdateTime = constructProto.UpdateTime; |
|
self.ConstructSpeed = constructProto.ConStructSpeed; |
|
self.ConfigId = constructProto.ConfigId; |
|
self.PeopleIdList = constructProto.PeopleIdList; |
|
self.PreparePeopleIdList = constructProto.PreparePeopleIdList; |
|
self.BuildingId = constructProto.BuildingId; |
|
} |
|
|
|
public static ConstructProto ToMessage(this Construct self) |
|
{ |
|
ConstructProto proto = new ConstructProto(); |
|
proto.Id = self.Id; |
|
proto.X = self.X; |
|
proto.Y = self.Y; |
|
proto.UpdateTime = self.UpdateTime; |
|
proto.ConStructSpeed = self.ConstructSpeed; |
|
proto.ConfigId = self.ConfigId; |
|
proto.PeopleIdList = self.PeopleIdList; |
|
proto.PreparePeopleIdList = self.PreparePeopleIdList; |
|
proto.BuildingId = self.BuildingId; |
|
return proto; |
|
} |
|
|
|
|
|
|
|
public static void SetConstructState(this Construct self,int state) |
|
{ |
|
self.IsConstructed = state; |
|
} |
|
|
|
public static void Update(this Construct self,Unit unit,int tick) |
|
{ |
|
self.Progress += tick * self.GetLaborSpeed() * (1 + self.AddEfficiency / 100); |
|
} |
|
|
|
public static int GetLaborSpeed(this Construct self) |
|
{ |
|
var labor = 0; |
|
Unit unit = (Unit) self.Parent.Parent; |
|
foreach (var peopleId in self.PeopleIdList) |
|
{ |
|
labor += unit.GetComponent<PeopleComponent>().GetChild<People>(peopleId).GetLaborWithCoefficient(); |
|
} |
|
|
|
return labor; |
|
|
|
} |
|
|
|
public static void GoConstruct(this Construct self, long peopleId) |
|
{ |
|
self.PreparePeopleIdList.Add(peopleId); |
|
} |
|
|
|
public static void StartConstruct(this Construct self, long peopleId) |
|
{ |
|
if (self.PreparePeopleIdList.Contains(peopleId)) |
|
{ |
|
self.PreparePeopleIdList.Remove(peopleId); |
|
self.PeopleIdList.Add(peopleId); |
|
} |
|
} |
|
|
|
public static void StopConstruct(this Construct self, long peopleId) |
|
{ |
|
self.PreparePeopleIdList.Remove(peopleId); |
|
self.PeopleIdList.Remove(peopleId); |
|
} |
|
|
|
} |
|
} |