|
|
|
using ET.EventType;
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
{
|
|
|
|
|
|
|
|
public class FarmlandDestroySystem : DestroySystem<Farmland>
|
|
|
|
{
|
|
|
|
public override void Destroy(Farmland self)
|
|
|
|
{
|
|
|
|
Unit unit = self.Parent.Parent.GetParent<Unit>();
|
|
|
|
unit.RemoveGrandChild(self.Id);
|
|
|
|
|
|
|
|
// 如果农田受小屋管理,需要从中移除
|
|
|
|
if (self.CabinId > 0)
|
|
|
|
{
|
|
|
|
var cabin = unit.GetGrandChild<Cabin>(self.CabinId);
|
|
|
|
if (cabin != null)
|
|
|
|
{
|
|
|
|
cabin.RemoveFarmland(self.Id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class FarmlandAwakeSystem : AwakeSystem<Farmland>
|
|
|
|
{
|
|
|
|
public override void Awake(Farmland self)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class FarmlandUpdateSystem: UpdateSystem<Farmland>
|
|
|
|
{
|
|
|
|
public override void Update(Farmland self)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[FriendClass(typeof(Farmland))]
|
|
|
|
public static class FarmlandSystem
|
|
|
|
{
|
|
|
|
public static void FromMessage(this Farmland self, FarmlandProto farmlandProto)
|
|
|
|
{
|
|
|
|
self.Id = farmlandProto.Id;
|
|
|
|
self.CropCfgId = farmlandProto.CropCfgId;
|
|
|
|
self.Duration = farmlandProto.Duration;
|
|
|
|
self.ExProduct = farmlandProto.ExProduct;
|
|
|
|
self.PlanCropCfgId = farmlandProto.PlantCfgId;
|
|
|
|
self.FarmlandState = farmlandProto.FarmlandState;
|
|
|
|
self.PeopleId = farmlandProto.PeopleId;
|
|
|
|
self.CabinId = farmlandProto.CabinId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static FarmlandProto ToMessage(this Farmland self)
|
|
|
|
{
|
|
|
|
FarmlandProto proto = new FarmlandProto();
|
|
|
|
proto.Id = self.Id;
|
|
|
|
proto.CropCfgId = self.CropCfgId;
|
|
|
|
proto.Duration = self.Duration;
|
|
|
|
proto.ExProduct = self.ExProduct;
|
|
|
|
proto.PlantCfgId = self.PlanCropCfgId;
|
|
|
|
proto.FarmlandState = self.FarmlandState;
|
|
|
|
proto.PeopleId = self.PeopleId;
|
|
|
|
proto.CabinId = self.CabinId;
|
|
|
|
|
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Plant(this Farmland self)
|
|
|
|
{
|
|
|
|
self.Duration = 0;
|
|
|
|
self.SetFarmlandState(FarmlandState.FARMLAND_STATE_GROW);
|
|
|
|
self.ExProduct = 0;
|
|
|
|
self.PeopleId = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Update(this Farmland self,Unit unit)
|
|
|
|
{
|
|
|
|
|
|
|
|
self.Duration += 1;
|
|
|
|
if (self.Duration >= self.Config.GrowthCycle*60)
|
|
|
|
{
|
|
|
|
self.SetFarmlandState(FarmlandState.FARMLAND_STATE_RIPE);
|
|
|
|
|
|
|
|
#if SERVER
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Harvest(this Farmland self)
|
|
|
|
{
|
|
|
|
self.Duration = 0;
|
|
|
|
self.CropCfgId = 0;
|
|
|
|
self.ExProduct = 0;
|
|
|
|
self.SetFarmlandState(FarmlandState.FARMLAND_STATE_FREE);
|
|
|
|
self.PeopleId = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Seed(this Farmland self,int cropCfgId)
|
|
|
|
{
|
|
|
|
self.CropCfgId = cropCfgId;
|
|
|
|
self.SetFarmlandState(FarmlandState.FARMLAND_STATE_SEED);
|
|
|
|
self.PlanCropCfgId = cropCfgId;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void SetFarmlandState(this Farmland self, int state)
|
|
|
|
{
|
|
|
|
self.FarmlandState = state;
|
|
|
|
|
|
|
|
#if !SERVER
|
|
|
|
Game.EventSystem.Publish(new FarmlandStateChanged(){Farmland = self});
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void SetCabinId(this Farmland self, long cabinId)
|
|
|
|
{
|
|
|
|
self.CabinId = cabinId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|