Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced the Buildings mechanics for holdings #17

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
12dfb69
buildings: Created buildings.xml
hmlendea Apr 3, 2024
4bd4d1b
buildings: Added some building icons
hmlendea Apr 3, 2024
6c63d27
buildings: Started with the code
hmlendea Apr 3, 2024
8bb609c
Merge branch 'master' into buildings
hmlendea Apr 4, 2024
e718bf5
buildings: More implementation
hmlendea Apr 4, 2024
8e1ae9c
buildings: Renamed building panel
hmlendea Apr 4, 2024
dc252c1
buildings: Holding panel skeleton
hmlendea Apr 4, 2024
d3cca96
buildings: Province indicator on the Holding panel
hmlendea Apr 4, 2024
047c680
buildings: Build building panel
hmlendea Apr 4, 2024
bccbb32
buildings: Fixes
hmlendea Apr 4, 2024
278b250
buildings: Added more building icons
hmlendea Apr 4, 2024
571b760
buildings: Added more building icons
hmlendea Apr 5, 2024
61ceed6
buildings: Optimised some textures' sizes
hmlendea Apr 5, 2024
fbf5809
buildings: Added more icons
hmlendea Apr 5, 2024
83ba027
buildings: Do not display card tooltip if name empty
hmlendea Apr 5, 2024
c62d8d4
buildings: Removed some building types
hmlendea Apr 5, 2024
007172e
buildings: Added more building icons
hmlendea Apr 5, 2024
c155832
buildings: Changed some building IDs
hmlendea Apr 5, 2024
7418587
buildings: Display building descriptions when on the build panel
hmlendea Apr 5, 2024
aef20d0
buildings: Larger building cards
hmlendea Apr 5, 2024
5154d3d
buildings: Added more building icons
hmlendea Apr 5, 2024
c791178
buildings: Renamed some buildings
hmlendea Apr 5, 2024
33bdd59
buildings: New descriptions for buildings
hmlendea Apr 5, 2024
66ec7cf
buildings: Added icons for the rest of the letian buildings
hmlendea Apr 8, 2024
472889d
buildings: Fixed file name
hmlendea Apr 8, 2024
a69e97e
Merge branch 'master' into buildings
hmlendea Apr 8, 2024
2dbfc41
buildings: Properly close panels
hmlendea Apr 8, 2024
1b1ad6a
buildings: Fixes
hmlendea Apr 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,308 changes: 1,308 additions & 0 deletions Content/Content.mgcb

Large diffs are not rendered by default.

Binary file added Content/Icons/Buildings/amionic/statue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/ayakan/statue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/barbarian/fishery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/barbarian/mine_gold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/barbarian/mine_silver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/barbarian/statue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/barbarian/tannery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/barbarian/windmill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/blumiac/statue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/chowo/statue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/generic/watchtower.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/arena.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/barracks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/blacksmith.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/caravanserai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/carpentry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/farms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/farms_grape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/farms_wheat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/fishery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/foundry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/hunting_lodge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/market_slave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/marketplace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Icons/Buildings/letian/mine_gold.png
Binary file added Content/Icons/Buildings/letian/mine_iron.png
Binary file added Content/Icons/Buildings/letian/mine_silver.png
Binary file added Content/Icons/Buildings/letian/paved_roads.png
Binary file added Content/Icons/Buildings/letian/public_baths.png
Binary file added Content/Icons/Buildings/letian/siege_workshop.png
Binary file added Content/Icons/Buildings/letian/stables.png
Binary file added Content/Icons/Buildings/letian/statue.png
Binary file added Content/Icons/Buildings/letian/tannery.png
Binary file added Content/Icons/Buildings/letian/tavern.png
Binary file added Content/Icons/Buildings/letian/temple.png
Binary file added Content/Icons/Buildings/letian/timber_camp.png
Binary file added Content/Icons/Buildings/letian/walls.png
Binary file added Content/Icons/Buildings/letian/watchtower.png
Binary file added Content/Icons/Buildings/letian/whalery.png
Binary file added Content/Icons/Buildings/letian/windmill.png
Binary file added Content/Icons/Buildings/nordic/arena.png
Binary file added Content/Icons/Buildings/nordic/barracks.png
Binary file added Content/Icons/Buildings/nordic/blacksmith.png
Binary file added Content/Icons/Buildings/nordic/caravanserai.png
Binary file added Content/Icons/Buildings/nordic/carpentry.png
Binary file added Content/Icons/Buildings/nordic/farms.png
Binary file added Content/Icons/Buildings/nordic/farms_grape.png
Binary file added Content/Icons/Buildings/nordic/farms_wheat.png
Binary file added Content/Icons/Buildings/nordic/fishery.png
Binary file added Content/Icons/Buildings/nordic/foundry.png
Binary file added Content/Icons/Buildings/nordic/hunting_lodge.png
Binary file added Content/Icons/Buildings/nordic/market_slave.png
Binary file added Content/Icons/Buildings/nordic/marketplace.png
Binary file added Content/Icons/Buildings/nordic/mine_gold.png
Binary file added Content/Icons/Buildings/nordic/mine_iron.png
Binary file added Content/Icons/Buildings/nordic/mine_silver.png
Binary file added Content/Icons/Buildings/nordic/paved_roads.png
Binary file added Content/Icons/Buildings/nordic/public_baths.png
Binary file added Content/Icons/Buildings/nordic/siege_workshop.png
Binary file added Content/Icons/Buildings/nordic/stables.png
Binary file added Content/Icons/Buildings/nordic/statue.png
Binary file added Content/Icons/Buildings/nordic/tannery.png
Binary file added Content/Icons/Buildings/nordic/tavern.png
Binary file added Content/Icons/Buildings/nordic/temple.png
Binary file added Content/Icons/Buildings/nordic/timber_camp.png
Binary file added Content/Icons/Buildings/nordic/walls.png
Binary file added Content/Icons/Buildings/nordic/watchtower.png
Binary file added Content/Icons/Buildings/nordic/whalery.png
Binary file added Content/Icons/Buildings/nordic/windmill.png
Binary file added Content/Icons/Buildings/rennan/statue.png
Binary file added Content/Icons/Buildings/rodah/mine_gold.png
Binary file added Content/Icons/Buildings/rodah/mine_silver.png
Binary file added Content/Icons/Buildings/rodah/statue.png
Binary file added Content/Icons/Buildings/rural/arena.png
Binary file added Content/Icons/Buildings/rural/barracks.png
Binary file added Content/Icons/Buildings/rural/blacksmith.png
Binary file added Content/Icons/Buildings/rural/caravanserai.png
Binary file added Content/Icons/Buildings/rural/carpentry.png
Binary file added Content/Icons/Buildings/rural/farms.png
Binary file added Content/Icons/Buildings/rural/farms_grape.png
Binary file added Content/Icons/Buildings/rural/farms_wheat.png
Binary file added Content/Icons/Buildings/rural/fishery.png
Binary file added Content/Icons/Buildings/rural/foundry.png
Binary file added Content/Icons/Buildings/rural/hunting_lodge.png
Binary file added Content/Icons/Buildings/rural/market_slave.png
Binary file added Content/Icons/Buildings/rural/marketplace.png
Binary file added Content/Icons/Buildings/rural/mine_gold.png
Binary file added Content/Icons/Buildings/rural/mine_iron.png
Binary file added Content/Icons/Buildings/rural/mine_silver.png
Binary file added Content/Icons/Buildings/rural/paved_roads.png
Binary file added Content/Icons/Buildings/rural/public_baths.png
Binary file added Content/Icons/Buildings/rural/siege_workshop.png
Binary file added Content/Icons/Buildings/rural/stables.png
Binary file added Content/Icons/Buildings/rural/statue.png
Binary file added Content/Icons/Buildings/rural/tannery.png
Binary file added Content/Icons/Buildings/rural/tavern.png
Binary file added Content/Icons/Buildings/rural/temple.png
Binary file added Content/Icons/Buildings/rural/timber_camp.png
Binary file added Content/Icons/Buildings/rural/walls.png
Binary file added Content/Icons/Buildings/rural/watchtower.png
Binary file added Content/Icons/Buildings/rural/whaling_station.png
Binary file added Content/Icons/Buildings/rural/windmill.png
Binary file added Content/Icons/Buildings/sudic/statue.png
Binary file added Content/Interface/Icons/province.png
Binary file added Content/Interface/Icons/wealth.png
Binary file modified Content/Interface/ProvincePanel/holding-frame.png
27 changes: 27 additions & 0 deletions DataAccess/DataObjects/BuildingTypeEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NuciDAL.DataObjects;

namespace Narivia.DataAccess.DataObjects
{
public class BuildingTypeEntity : EntityBase
{
public string Name { get; set; }

public string Description { get; set; }

public string RequiredResourceId { get; set; }

public int Price { get; set; }

public int MaintenanceCost { get; set; }

public int Income { get; set; }

public int AttackBonus { get; set; }

public int DefenceBonus { get; set; }

public int RecruitmentBonus { get; set; }

public int ReligionInfluence { get; set; }
}
}
90 changes: 90 additions & 0 deletions GameLogic/GameManagers/BuildingManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Narivia.DataAccess.DataObjects;
using Narivia.GameLogic.Mapping;
using Narivia.Models;
using Narivia.Settings;
using NuciDAL.Repositories;

namespace Narivia.GameLogic.GameManagers
{
public sealed class BuildingManager : IBuildingManager
{
readonly Random random;
readonly IHoldingManager holdingManager;
readonly IWorldManager worldManager;

string worldId;
Dictionary<string, Building> buildings;
Dictionary<string, BuildingType> buildingTypes;

public BuildingManager(
string worldId,
IHoldingManager holdingManager,
IWorldManager worldManager)
{
random = new Random();

this.worldId = worldId;
this.holdingManager = holdingManager;
this.worldManager = worldManager;
}

public void LoadContent()
{
string buildingsPath = Path.Combine(ApplicationPaths.WorldsDirectory, worldId, "building_types.xml");

IRepository<BuildingTypeEntity> repository = new XmlRepository<BuildingTypeEntity>(buildingsPath);

buildings = new Dictionary<string, Building>();
buildingTypes = repository.GetAll().ToDictionary(x => x.Id, x => x.ToDomainModel());
}

public void UnloadContent()
{
buildings.Clear();
}

public Building GetBuilding(string buildingId)
=> buildings[buildingId];

public IEnumerable<Building> GetBuildings()
=> buildings.Values;

public IEnumerable<Building> GetHoldingBuildings(string holdingId)
=> buildings.Values.Where(building => building.HoldingId == holdingId);

public IEnumerable<BuildingType> GetBuildingTypes()
=> buildingTypes.Values;

public void BuildBuilding(string holdingId, string buildingTypeId)
{
BuildingType buildingType = buildingTypes[buildingTypeId];
Holding holding = holdingManager.GetHolding(holdingId);
Province province = worldManager.GetProvince(holding.ProvinceId);
Faction faction = worldManager.GetFaction(province.FactionId);

AddBuilding(holding.Id, buildingType.Id, faction.CultureId);
faction.Wealth -= buildingType.Price;
}

public void AddBuilding(string holdingId, string buildingTypeId, string cultureId)
{
// TODO: Don't pass cultureId as a parameter

Building building = new()
{
Id = $"{holdingId}_{buildingTypeId}",
Name = buildingTypes[buildingTypeId].Name,
Description = buildingTypes[buildingTypeId].Description,
TypeId = buildingTypeId,
HoldingId = holdingId,
CultureId = cultureId
};

buildings.Add(building.Id, building);
}
}
}
24 changes: 24 additions & 0 deletions GameLogic/GameManagers/IBuildingManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using Narivia.Models;

namespace Narivia.GameLogic.GameManagers
{
public interface IBuildingManager
{
void LoadContent();

void UnloadContent();

Building GetBuilding(string buildingId);

IEnumerable<Building> GetBuildings();

IEnumerable<Building> GetHoldingBuildings(string holdingId);

IEnumerable<BuildingType> GetBuildingTypes();

void BuildBuilding(string holdingId, string buildingTypeId);

void AddBuilding(string holdingId, string buildingTypeId, string cultureId);
}
}
49 changes: 49 additions & 0 deletions GameLogic/Mapping/BuildingTypeMappingExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.Linq;

using Narivia.DataAccess.DataObjects;
using Narivia.Models;

namespace Narivia.GameLogic.Mapping
{
static class BuildingTypeMappingExtensions
{
internal static BuildingType ToDomainModel(this BuildingTypeEntity entity)
=> new()
{
Id = entity.Id,
Name = entity.Name,
Description = entity.Description,
RequiredResourceId = entity.RequiredResourceId,
Price = entity.Price,
MaintenanceCost = entity.MaintenanceCost,
Income = entity.Income,
AttackBonus = entity.AttackBonus,
DefenceBonus = entity.DefenceBonus,
RecruitmentBonus = entity.RecruitmentBonus,
ReligionInfluence = entity.ReligionInfluence
};

internal static BuildingTypeEntity ToEntity(this BuildingType domainModel)
=> new()
{
Id = domainModel.Id,
Name = domainModel.Name,
Description = domainModel.Description,
RequiredResourceId = domainModel.RequiredResourceId,
Price = domainModel.Price,
MaintenanceCost = domainModel.MaintenanceCost,
Income = domainModel.Income,
AttackBonus = domainModel.AttackBonus,
DefenceBonus = domainModel.DefenceBonus,
RecruitmentBonus = domainModel.RecruitmentBonus,
ReligionInfluence = domainModel.ReligionInfluence
};

internal static IEnumerable<BuildingType> ToDomainModels(this IEnumerable<BuildingTypeEntity> entities)
=> entities.Select(entity => entity.ToDomainModel());

internal static IEnumerable<BuildingTypeEntity> ToEntities(this IEnumerable<BuildingType> domainModels)
=> domainModels.Select(domainModel => domainModel.ToEntity());
}
}
Loading
Loading