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.
74 lines
2.1 KiB
74 lines
2.1 KiB
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) |
|
{ |
|
var building = ConstructOperate.ConstructFinish(unit, v.Id); |
|
ConstructHelper.NotifyConstructFinish(unit,v.Id, building.Id); |
|
} |
|
|
|
if (finishConstructs.Count > 0) |
|
{ |
|
UnitOperate.InitProsperity(unit); |
|
} |
|
|
|
} |
|
#endif |
|
|
|
|
|
} |
|
} |