public static TreeCutter CreateNew(ILevelManager level, IBuilding building, TreeCutterType type) { TreeCutter newCutter = null; try { newCutter = new TreeCutter(level, building, type); newCutter.healthBar = new HealthBarControl(level, building, 100, new Vector3(0, 3, 0), new Vector2(0.5f, 0.1f), false); StaticRangeTarget.CreateNew(newCutter, level, building.Center); using (var spawnPoints = building.Tiles[0].GetNeighbours().GetEnumerator()) { for (int i = 0; i < numberOfWorkers; i++) { IUnit workerUnit1 = level.EditorMode ? null : newCutter.SpawnWorkerUnit(spawnPoints); newCutter.workers[i] = new Worker(newCutter, workerUnit1, workerRespawnTime) { DoRespawn = !level.EditorMode }; } } return(newCutter); } catch (Exception e) { newCutter?.Dispose(); throw; } }
public static Worker Load(SequentialPluginDataReader reader, TreeCutter cutter, bool doRespawn) { reader.GetNext(out int ID); reader.GetNext(out double duration); reader.GetNext(out double remaining); IUnit unit = ID != 0 ? cutter.Level.GetUnit(ID) : null; return(new Worker(cutter, unit, duration, remaining) { DoRespawn = doRespawn }); }
Worker(TreeCutter cutter, IUnit unit, double respawnTime, double remainingTime) { this.DoRespawn = true; this.Unit = unit; if (unit != null) { ((Dog)unit.UnitPlugin).Cutter = cutter; unit.OnRemoval += OnWorkerDeath; } this.cutter = cutter; timeout = new Timeout(respawnTime, remainingTime); }
public override BuildingInstancePlugin GetInstanceForLoading(ILevelManager level, IBuilding building) { return(TreeCutter.CreateForLoading(level, building, this)); }
public override BuildingInstancePlugin CreateNewInstance(ILevelManager level, IBuilding building) { return(TreeCutter.CreateNew(level, building, this)); }
public Worker(TreeCutter cutter, IUnit unit, double respawnTime) : this(cutter, unit, respawnTime, respawnTime) { }