public void changeStructure(shared.Vector2Int location, Structure.StructureType newType) { if (ownedOutposts.ContainsKey(location)) { Structure str = NewStructure(location, newType); ownedOutposts[location] = str; GameServer.Instance.Structures.SetStructure(str); } }
public static Dictionary <Resource.ResourceType, int> GetStructureCostByType(Structure.StructureType structureType) { Dictionary <Resource.ResourceType, int> cost = new Dictionary <Resource.ResourceType, int>(); switch (structureType) { case StructureType.House: { cost.Add(Resource.ResourceType.Wood, 50); cost.Add(Resource.ResourceType.Stone, 20); cost.Add(Resource.ResourceType.Metal, 5); break; } case StructureType.Warehouse: { cost.Add(Resource.ResourceType.Wood, 200); cost.Add(Resource.ResourceType.Stone, 100); break; } case StructureType.Lumbermill: { cost.Add(Resource.ResourceType.Wood, 150); cost.Add(Resource.ResourceType.Stone, 50); cost.Add(Resource.ResourceType.Metal, 10); break; } case StructureType.Capitol: { cost.Add(Resource.ResourceType.Wood, 500); cost.Add(Resource.ResourceType.Stone, 500); cost.Add(Resource.ResourceType.Metal, 250); break; } case StructureType.Forge: { cost.Add(Resource.ResourceType.Stone, 300); break; } case StructureType.Mine: { cost.Add(Resource.ResourceType.Wood, 500); break; } default: { break; } } return(cost); }
public void AddCard(Structure.StructureType type) { if (cardTexture == null) { cardTexture = content.Load <Texture2D>(ControlConstants.STRUCTURE_CARD_TEXTURE); } StructureCard newCard = new StructureCard(cardTexture); newCard.Initialize(this.town, type, NextCardPosition(), titleFont, resourceFont); structureCards.Add(newCard); //this.Add(newCard); }
public void Initialize(Town town, Structure.StructureType type, Vector2 position, SpriteFont titleFont, SpriteFont resourceFont) { this.StructureType = type; this.Position = position; this.Size = ControlConstants.STRUCTURE_CARD_SIZE; this.town = town; _hoverColor = ControlConstants.STRUCTURE_CARD_HOVER_COLOR; TextBox title = new TextBox(titleFont); title.Text = type.ToString(); title.Position = this.Position + ControlConstants.STRUCTURE_CARD_TITLE_POSITION; title.Size = ControlConstants.STRUCTURE_CARD_TITLE_SIZE; title.Color = ControlConstants.STRUCTURE_CARD_TITLE_COLOR; title.TextAlignment = TextBox.TextAlign.Left; Dictionary <Resource.ResourceType, int> structureCost = Structure.GetStructureCostByType(type); Vector2 nextCountPos = this.Position + ControlConstants.STRUCTURE_CARD_RESOURCE_COUNT_POSITION; Vector2 nextLabelPos = this.Position + ControlConstants.STRUCTURE_CARD_RESOURCE_LABEL_POSITION; foreach (Resource.ResourceType resource in structureCost.Keys) { TextBox resourceCost = new TextBox(resourceFont); TextBox resourceLabel = new TextBox(resourceFont); resourceCost.Text = structureCost[resource].ToString(); resourceLabel.Text = resource.ToString(); resourceCost.Position = nextCountPos; resourceLabel.Position = nextLabelPos; nextCountPos += ControlConstants.STRUCTURE_CARD_RESOURCE_LABEL_OFFSET; nextLabelPos += ControlConstants.STRUCTURE_CARD_RESOURCE_LABEL_OFFSET; resourceCost.Size = ControlConstants.STRUCTURE_CARD_RESOURCE_COUNT_SIZE; resourceLabel.Size = ControlConstants.STRUCTURE_CARD_RESOURCE_LABEL_SIZE; resourceCost.Color = ControlConstants.STRUCTURE_CARD_RESOURCE_COUNT_COLOR; resourceLabel.Color = ControlConstants.STRUCTURE_CARD_RESOURCE_LABEL_COLOR; resourceCost.TextAlignment = TextBox.TextAlign.Right; resourceLabel.TextAlignment = TextBox.TextAlign.Left; this.Add(resourceCost); this.Add(resourceLabel); } this.Add(title); this.Click += StructureCard_Click; }
public Structure CreateStructure(shared.Vector2Int location, Structure.StructureType type, bool updateImmediately) { Structure str = NewStructure(location, type); if (str != null) { if (!ownedOutposts.ContainsKey(str.Location)) { ownedOutposts.Add(str.Location, str); } GameServer.Instance.Structures.AddStructure(str, updateImmediately); } return(str); }
public Structure NewStructure(shared.Vector2Int location, Structure.StructureType type) { Structure str = null; switch (type) { case Structure.StructureType.None: str = new None(location, this); break; case Structure.StructureType.City: str = new City(location, this); break; case Structure.StructureType.Outpost: str = new Outpost(location, this); break; case Structure.StructureType.Radar: str = new Radar(location, this, AppSettings.BaseRadarRadius); break; } return(str); }
public bool CanUpgradeStructure(shared.Vector2Int location, Structure.StructureType newType, out shared.MessageTypes reason) { if (!ownedOutposts.ContainsKey(location)) { reason = shared.MessageTypes.No_OP; return(false); } Structure structure = ownedOutposts[location]; if (structure.Type != Structure.StructureType.Outpost) { reason = shared.MessageTypes.Op_Not_Upgradable; return(false); } //check resources bool hasResources = true; if (!hasResources) { reason = shared.MessageTypes.Not_Enough_Resources; return(false); } //check age bool validAge = true; if (!validAge) { reason = shared.MessageTypes.Invalid_Op_Age; return(false); } reason = shared.MessageTypes.Success; return(true); }
public static bool PurchaseBuilding(int currencyRequired, int populationNeeded, Structure.StructureType strucureType) { IronTowerDBContext db = new IronTowerDBContext(); Game game = db.Games.FirstOrDefault(); if (game.TotalBalance < currencyRequired) { return(false); } if (game.TotalPopulation(game) - game.ConsumedPopulation(game) < populationNeeded) { return(false); } game.TotalBalance -= currencyRequired; Structure structure = new Structure(strucureType, game.TotalFloors(game) + 1); game.Structures.Add(structure); game.PeriodicRevenue += structure.Income; db.SaveChanges(); return(true); }