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.
93 lines
2.6 KiB
93 lines
2.6 KiB
namespace ET |
|
{ |
|
public class CabinDestroySystem : DestroySystem<Cabin> |
|
{ |
|
public override void Destroy(Cabin self) |
|
{ |
|
Unit unit = self.Parent.Parent.GetParent<Unit>(); |
|
unit.RemoveGrandChild(self.Id); |
|
|
|
// 需要清理所管理的农田的指向 |
|
foreach (long farmlandId in self.FarmlandIds) |
|
{ |
|
var farmland = unit.GetGrandChild<Farmland>(farmlandId); |
|
if (farmland != null) |
|
{ |
|
farmland.SetCabinId(0); |
|
} |
|
} |
|
|
|
// 农民变空闲 |
|
if (self.PeopleId > 0) |
|
{ |
|
var peopleComp = unit.GetComponent<PeopleComponent>(); |
|
var people = peopleComp.GetChild<People>(self.PeopleId); |
|
people.SetBehaveType(ConstBehaveType.BEHAVE_IDLE); |
|
self.PeopleId = 0; |
|
} |
|
} |
|
} |
|
|
|
[FriendClass(typeof(Cabin))] |
|
public static class CabinSystem |
|
{ |
|
public static void FromMessage(this Cabin self, CabinProto proto) |
|
{ |
|
self.Id = proto.Id; |
|
self.PeopleId = proto.PeopleId; |
|
self.FarmlandIds = proto.FarmlandIds; |
|
} |
|
|
|
public static CabinProto ToMessage(this Cabin self) |
|
{ |
|
var proto = new CabinProto(); |
|
proto.Id = self.Id; |
|
proto.PeopleId = self.PeopleId; |
|
proto.FarmlandIds = self.FarmlandIds; |
|
return proto; |
|
} |
|
|
|
public static void PeoplePrepare(this Cabin self,long peopleId) |
|
{ |
|
self.PeopleId = peopleId; |
|
} |
|
|
|
public static bool PeopleArrive(this Cabin self,long peopleId) |
|
{ |
|
if (self.PeopleId != peopleId) |
|
{ |
|
return false; |
|
} |
|
self.ResidentState = 1; |
|
return true; |
|
} |
|
public static void PeopleLeave(this Cabin self) |
|
{ |
|
self.ResidentState = 0; |
|
self.PeopleId = 0; |
|
} |
|
|
|
public static bool AddFarmland(this Cabin self,long farmlandId) |
|
{ |
|
if (self.FarmlandIds.Contains(farmlandId)) |
|
{ |
|
return false; |
|
} |
|
self.FarmlandIds.Add(farmlandId); |
|
return true; |
|
} |
|
|
|
public static void RemoveFarmland(this Cabin self, long farmlandId) |
|
{ |
|
if (self.FarmlandIds.Contains(farmlandId)) |
|
{ |
|
self.FarmlandIds.Remove(farmlandId); |
|
} |
|
} |
|
|
|
public static int GetRange(this Cabin self) |
|
{ |
|
return 20; |
|
} |
|
} |
|
} |