|
|
|
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;
|
|
|
|
self.IsUpgrade = buildingProto.IsUpgrade;
|
|
|
|
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,
|
|
|
|
IsUpgrade = self.IsUpgrade
|
|
|
|
};
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|