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.
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
{
|
|
|
|
[FriendClass(typeof(Building))]
|
|
|
|
public static class BuildingSystem
|
|
|
|
{
|
|
|
|
public static void FromMessage(this Building self, BuildingProto buildingProto)
|
|
|
|
{
|
|
|
|
self.Id = buildingProto.Id;
|
|
|
|
self.Position = new Vector2(buildingProto.X, buildingProto.Y);
|
|
|
|
self.ConfigId = buildingProto.ConfigId;
|
|
|
|
self.Durable = buildingProto.Durable;
|
|
|
|
if (buildingProto.Farmland != null)
|
|
|
|
{
|
|
|
|
var farmland = self.AddChildWithId<Farmland>(buildingProto.Farmland.id);
|
|
|
|
farmland.FromMessage(buildingProto.Farmland);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static BuildingProto ToMessage(this Building self)
|
|
|
|
{
|
|
|
|
var proto= new BuildingProto() { Id = self.Id,
|
|
|
|
ConfigId = self.ConfigId,
|
|
|
|
X = self.Position.x,
|
|
|
|
Y = self.Position.y,
|
|
|
|
Durable = self.Durable};
|
|
|
|
if (self.Config.Special == (int) StructureSpecialEnum.FARMLAND)
|
|
|
|
{
|
|
|
|
foreach (var v in self.Children.Values)
|
|
|
|
{
|
|
|
|
if (v.GetType() == typeof (Farmland))
|
|
|
|
{
|
|
|
|
proto.Farmland = ((Farmland) v).ToMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void DurableReduce(this Building self)
|
|
|
|
{
|
|
|
|
if (self.Durable == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.Durable -= self.Config.DurableCoefficient;
|
|
|
|
if (self.Durable < 0)
|
|
|
|
{
|
|
|
|
self.Durable = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Repair(this Building self)
|
|
|
|
{
|
|
|
|
self.Durable = self.Config.Durable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|