public static void Init(HexGrid.HexGrid hexGrid) { initialized = true; grid = hexGrid; buildings = new List <Building>(); ressources = new List <Ressource>(); carts = new List <Cart>(); foreach (HexCell cell in grid.cells) { if (cell.Structure != null) { AddStructureToList(cell.Structure); } } ComputeConnectedStorages(); foreach (Building building in buildings) { if (building is Headquarter) { AddTribe(building.Tribe, (Headquarter)building); } } foreach (Building building in buildings) { Tribe tribe = GetTribe(building.Tribe); tribe.AddBuilding(building.GetType()); } }
public static Player AddPlayer(string name, Tribe tribe) { Player newPlayer = new Player(name, tribe); Players.Add(newPlayer); return(newPlayer); }
public static HexCell ApplyBuild(HexCoordinates coords, Type buildingType, Tribe tribe) { Building building = (Building)Activator.CreateInstance(buildingType); HexCell cell = grid.GetCell(coords); if (cell.Structure != null) { DestroyStructure(coords); } cell.Structure = building; building.Cell = cell; building.Tribe = tribe.Id; tribe.HQ.Inventory.ApplyRecipe(building.Recipes[0]); AddStructureToList(building); tribe.AddBuilding(building.GetType()); if (building is ICartHandler) { ComputeConnectedStorages(); } return(cell); }
public static Tribe AddTribe(byte tribeID, Headquarter hq) { Tribe newTribe = new Tribe(tribeID, hq); Tribes.Add(newTribe); return(newTribe); }
public Player ( string name, Tribe tribe, TroopInventory TroopInventory ) { this.Name = name; this.Tribe = tribe; this.TroopInventory = TroopInventory; }
public static void ApplyUpgrade(HexCoordinates coords, Tribe tribe) { HexCell cell = grid.GetCell(coords); if (cell.Structure is Building) { Building building = (Building)cell.Structure; if (!building.IsUpgradable()) { return; } tribe.HQ.Inventory.ApplyRecipe(building.Recipes[building.Level]); ((Building)cell.Structure).Upgrade(); } }
public static bool DestroyStructure(HexCoordinates coords) { Console.WriteLine("structure has been destroyed"); HexCell cell = grid.GetCell(coords); if (cell == null) { return(false); } Structure structure = cell.Structure; if (structure != null) { cell.Structure = null; if (typeof(Building).IsAssignableFrom(structure.GetType())) { Building building = (Building)structure; buildings.RemoveAll(elem => elem == building); carts.RemoveAll(elem => elem.Origin == building); foreach (Building b in buildings) { if (b is ICartHandler) { ((ICartHandler)b).Carts.RemoveAll(elem => elem.Origin == building); if (b is InventoryBuilding) { if (building is InventoryBuilding) { ((InventoryBuilding)b).AllowedRessources.Remove((InventoryBuilding)building); } } } } if (structure is ICartHandler) { ComputeConnectedStorages(); } Tribe tribe = GetTribe(building.Tribe); tribe.RemoveBuilding(building.GetType()); } else if (typeof(Ressource).IsAssignableFrom(structure.GetType())) { ressources.RemoveAll(elem => elem == structure); } } return(true); }
public static void AddPlayer(string playerName, int tribeId, HexCoordinates coordinates, TroopInventory troopInventory) { Tribe tribe = GameLogic.GetTribe(tribeId); Player player = GameLogic.GetPlayer(playerName); if (player == null) { player = AddPlayer(playerName, tribe); player.Position = coordinates; player.TroopInventory = troopInventory; } else { player.Tribe = tribe; player.Position = coordinates; player.TroopInventory = troopInventory; } }
public static bool Harvest(byte tribeID, HexCoordinates coords) { HexCell cell = grid.GetCell(coords); Tribe tribe = GetTribe(tribeID); if (cell != null) { if (cell.Structure is Ressource) { Ressource ressource = (Ressource)cell.Structure; if (ressource.ManuallyHarvestable()) { int gain = ressource.HarvestManually(); tribe.HQ.Inventory.AddRessource(ressource.ressourceType, gain); return(true); } } } return(false); }
public static Tribe ApplyBuildHQ(HexCoordinates coords, Headquarter hq) { HexCell cell = grid.GetCell(coords); if (cell.Structure != null) { DestroyStructure(coords); } cell.Structure = hq; hq.Cell = cell; Tribe tribe = AddTribe((byte)Tribes.Count, hq); hq.Tribe = tribe.Id; AddStructureToList(hq); ComputeConnectedStorages(); return(tribe); }
public Player(string name, Tribe tribe) { this.Name = name; this.Tribe = tribe; this.TroopInventory = new TroopInventory(); }
public Player(string name) { this.Tribe = null; this.TroopInventory = new TroopInventory(); }