|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
{
|
|
|
|
[FriendClass(typeof(Construct))]
|
|
|
|
[FriendClass(typeof(Building))]
|
|
|
|
public static class ConstructComponentSystem
|
|
|
|
{
|
|
|
|
public static Construct CreateConstruct( this ConstructComponent self,Unit unit,int configId, float x, float y,long id=0,long buildingId =0)
|
|
|
|
{
|
|
|
|
Construct construct ;
|
|
|
|
if (id == 0)
|
|
|
|
{
|
|
|
|
construct = self.AddChild<Construct>();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
construct = self.AddChildWithId<Construct>(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
construct.ConfigId = configId;
|
|
|
|
construct.X = x;
|
|
|
|
construct.Y = y;
|
|
|
|
construct.BuildingId = buildingId;
|
|
|
|
if (buildingId > 0)
|
|
|
|
{
|
|
|
|
var building = unit.GetComponent<BuildingComponent>().GetChild<Building>(buildingId);
|
|
|
|
if (building != null)
|
|
|
|
{
|
|
|
|
building.IsUpgrade = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return construct;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if SERVER
|
|
|
|
public static void Update(this ConstructComponent self,Unit unit, int tick)
|
|
|
|
{
|
|
|
|
if (self.Children.Count == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
List<Construct> finishConstructs = new List<Construct>();
|
|
|
|
foreach (var v in self.Children.Values)
|
|
|
|
{
|
|
|
|
var construct = ((Construct) v);
|
|
|
|
construct.Update(unit, tick);
|
|
|
|
if (construct.Progress >= construct.Config.BodyVolume)
|
|
|
|
{
|
|
|
|
finishConstructs.Add(construct);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstructHelper.NtfUpdateConstructProgress(unit, self);
|
|
|
|
foreach (var v in finishConstructs)
|
|
|
|
{
|
|
|
|
ConstructOperate.ConstructFinish(unit, v.Id);
|
|
|
|
ConstructHelper.NofityConstructFinish(unit,v.Id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (finishConstructs.Count > 0)
|
|
|
|
{
|
|
|
|
UnitOperate.InitProsperity(unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|