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(); } else { construct = self.AddChildWithId(id); } construct.ConfigId = configId; construct.X = x; construct.Y = y; construct.BuildingId = buildingId; if (buildingId > 0) { var building = unit.GetComponent().GetChild(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 finishConstructs = new List(); 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,childId) = ConstructOperate.ConstructFinish(unit, v.Id); ConstructHelper.NotifyConstructFinish(unit,v.Id, building.Id,childId); } if (finishConstructs.Count > 0) { UnitOperate.InitProsperity(unit); } } #endif } }