Skip to content

Commit

Permalink
feat: add possibility to define custom workshop level for technology
Browse files Browse the repository at this point in the history
resolve #327
  • Loading branch information
PavelZinchenko committed Jun 7, 2024
1 parent 32d46ed commit c993d96
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions Assets/Modules/Database/.Schema/v1/Objects/Technology.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
<member name="Hidden" type="bool" />
<member name="Special" type="bool" />
<member name="Dependencies" type="object_list" typeid="Technology" />
<member name="CustomCraftingLevel" type="int" minvalue="0" />
</data>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected Technology(TechnologySerializable serializable, Database.Loader loader
Hidden = serializable.Hidden;
Special = serializable.Special;
Dependencies = new ImmutableCollection<Technology>(serializable.Dependencies?.Select(item => loader.GetTechnology(new ItemId<Technology>(item), true)));
CustomCraftingLevel = UnityEngine.Mathf.Clamp(serializable.CustomCraftingLevel, 0, 2147483647);

OnDataDeserialized(serializable, loader);
}
Expand All @@ -61,6 +62,7 @@ protected Technology(TechnologySerializable serializable, Database.Loader loader
public bool Hidden { get; private set; }
public bool Special { get; private set; }
public ImmutableCollection<Technology> Dependencies { get; private set; }
public int CustomCraftingLevel { get; private set; }

public static Technology DefaultValue { get; private set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public class TechnologySerializable : SerializableItem
public bool Hidden;
public bool Special;
public int[] Dependencies;
public int CustomCraftingLevel;
}
}
2 changes: 1 addition & 1 deletion Assets/Scripts/Domain/Economy/ItemType/BlueprintItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public BlueprintItem(ITechnology technology, Research research, ILocalization lo
_research = research;
}

public string Id { get { return "blueprint_" + _technology.Id; } }
public string Id { get { return "blueprint_" + _technology.Data.Id; } }
public string Name { get { return _localization.GetString("$Blueprint", _technology.GetName(_localization)); } }
public string Description { get { return string.Empty; } }
public SpriteId Icon => new("Textures/Icons/icon_blueprint", SpriteId.Type.Default);
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/Domain/Research/Research.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void ResearchTechForFree(ITechnology technology)
_availableTech.Add(technology);
var faction = technology.Faction;
_session.Research.SetResearchPoints(faction, _session.Research.GetResearchPoints(faction) + technology.Price);
_session.Research.AddTechnology(technology.Id);
_session.Research.AddTechnology(technology.Data.Id);

CheckConsistency();
_messenger.Broadcast(EventType.TechResearched);
Expand All @@ -56,7 +56,7 @@ public void ForgetTech(ITechnology technology)
return;

_availableTech.Remove(technology);
_session.Research.RemoveTechnology(technology.Id);
_session.Research.RemoveTechnology(technology.Data.Id);

CheckConsistency();
_messenger.Broadcast(EventType.TechResearched);
Expand All @@ -77,7 +77,7 @@ public bool ResearchTech(ITechnology technology)

_researchPoints [faction.Id.Value] = points;
_availableTech.Add(technology);
_session.Research.AddTechnology(technology.Id);
_session.Research.AddTechnology(technology.Data.Id);

CheckConsistency();
_messenger.Broadcast(EventType.TechResearched);
Expand Down
5 changes: 4 additions & 1 deletion Assets/Scripts/Domain/Technologies/ITechnology.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public CraftingPrice(Money credits, Money stars, int techs = 0)

public interface ITechnology
{
ItemId<GameDatabase.DataModel.Technology> Id { get; }
GameDatabase.DataModel.Technology Data { get; }
string GetName(ILocalization localization);
Sprite GetImage(IResourceLocator resourceLocator);
string GetDescription(ILocalization localization);
Expand All @@ -97,6 +97,9 @@ public static class TechnologyExtension
{
public static int GetWorkshopLevel(this ITechnology technology)
{
if (technology.Data.CustomCraftingLevel > 0)
return technology.Data.CustomCraftingLevel;

return technology.Price + technology.Requirements.Sum(item => GetWorkshopLevel(item));
}
}
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/Domain/Technologies/Technology.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public abstract class TechnologyBase : ITechnology
{
protected TechnologyBase(ITechnologies technologies, GameDatabase.DataModel.Technology data)
{
Id = data.Id;
Data = data;
_technologies = technologies;
_requirements = data.Dependencies.Select(item => item.Id);
Price = data.Price;
Hidden = data.Hidden;
Special = data.Special;
}

public ItemId<GameDatabase.DataModel.Technology> Id { get; private set; }
public GameDatabase.DataModel.Technology Data { get; }

public IEnumerable<ITechnology> Requirements
public IEnumerable<ITechnology> Requirements
{
get
{
Expand Down

0 comments on commit c993d96

Please sign in to comment.