public void Update(float dt) { if (_waitingForWood) { TryTakeWood(); } else if(_waitingForWorkingPlace) { TryAddWorker(); } else if ((Creature.ResoursesStorage.Overload(Resourses.Board) && Creature.CreatureState == CreatureState.Working) || Creature.ResoursesStorage.IsAbscent(Resourses.Wood) && Creature.CreatureState != CreatureState.Moving) { _targetCastle = (Castle) BuildingManager.GetNearest<Castle>(Creature.Cell); if (_targetCastle != null) { Creature.MoveTo(_targetCastle.Cell); Creature.PathFinished += OnPathFinishedInCastle; } } else if (Creature.CreatureState == CreatureState.Idle) { _targetSawmill = (Sawmill) BuildingManager.GetNearest<Sawmill>(Creature.Cell); Creature.MoveTo(_targetSawmill.Cell); Creature.PathFinished += OnPathFinishedInSawmill; } else if (Creature.ResoursesStorage.IsAbscent(Resourses.Wood)) { } }
private void OnPathFinishedInCastle() { Creature.PathFinished -= OnPathFinishedInCastle; Creature.CreatureState = CreatureState.Idle; _targetCastle.ResoursesStorage.AddResourses(Creature.ResoursesStorage, true); _targetCastle = null; }
public void Update(float dt) { if(Creature.ResoursesStorage.Overload(Resourses.Wood) && Creature.CreatureState == CreatureState.GatheringResourses) { _targetCastle = (Castle)BuildingManager.GetNearest<Castle>(Creature.Cell); if (_targetCastle != null) { Creature.MoveTo(_targetCastle.Cell); Creature.PathFinished += OnPathFinishedInCastle; } } else if(Creature.CreatureState == CreatureState.Idle) { Creature.MoveTo(GameField.GetNearest(Chunk.ChunkType.Forest, Creature.Cell, true)); Creature.PathFinished += OnPathFinishedInForest; } }
public StrategyManager() { Camera = new Camera2D(new Vector2(450, 450), Settings.ScreenResolution.X, Settings.ScreenResolution.Y); CreatureManager = new CreatureManager(); GameField = new GameField(100, 100); BuildingManager = new BuildingManager(); _guiManager = new GUIManager(); ConstructionMenu constructionMenu = new ConstructionMenu(1,new Size(64,64)); constructionMenu.ButtonSize = new Size(64, 64); constructionMenu.Position = new Vector2(0, Settings.ScreenResolution.Y - 64); constructionMenu.AddElement(SpriteType.SawmillMenuElement, "Sawmill", typeof(Sawmill)); _guiManager.Add(constructionMenu); Castle castle = new Castle(new Point(3, 3)); castle.ResoursesStorage.AddResourse(Resourses.Wood, 50); BuildingManager.Add(castle); Sawmill sawmill = new Sawmill(new Point(10, 10)); BuildingManager.Add(sawmill); for (int i = 0; i < 6; i++) { Creature creature = CreatureFabric.CreateHuman(this, CreatureRelation.Friendly); creature.Position = new Vector2(RandomTool.RandInt(0, 200), RandomTool.RandInt(0, 100)); creature.SetBehaviour(new CarpenterBehaviour()); CreatureManager.Add(creature); } for (int i = 0; i < 40; i++) { Creature creature = CreatureFabric.CreateHuman(this, CreatureRelation.Friendly); creature.Position = new Vector2(RandomTool.RandInt(0, 2000), RandomTool.RandInt(0, 2000)); creature.SetBehaviour(new WoodcutterBehavior()); CreatureManager.Add(creature); } }