Currency collect goal (#352)

* simple currency comp

* stack support + weapon cost dnd port

* add collect currency objective conditions

* clean up
This commit is contained in:
Ed
2024-07-24 13:28:27 +03:00
committed by GitHub
parent bf93349b73
commit 9c84ce9be0
26 changed files with 332 additions and 24 deletions

View File

@@ -142,8 +142,8 @@ public sealed class CharacterUIController : UIController, IOnStateEntered<Gamepl
conditionControl.ProgressTexture.Progress = condition.Progress;
var titleMessage = new FormattedMessage();
var descriptionMessage = new FormattedMessage();
titleMessage.AddText(condition.Title);
descriptionMessage.AddText(condition.Description);
titleMessage.TryAddMarkup(condition.Title, out _); //CP14 colored objective text support
descriptionMessage.TryAddMarkup(condition.Description, out _); //CP14 colored objective text support
conditionControl.Title.SetMessage(titleMessage);
conditionControl.Description.SetMessage(descriptionMessage);

View File

@@ -0,0 +1,26 @@
using Content.Server._CP14.Objectives.Systems;
using Robust.Shared.Utility;
namespace Content.Server._CP14.Objectives.Components;
[RegisterComponent, Access(typeof(CP14CurrencyCollectConditionSystem))]
public sealed partial class CP14CurrencyCollectConditionComponent : Component
{
[DataField]
public int Currency = 1000;
/// <summary>
/// Limits the goal to collecting values from a specific category.
/// </summary>
[DataField]
public string? Category;
[DataField(required: true)]
public LocId ObjectiveText;
[DataField(required: true)]
public LocId ObjectiveDescription;
[DataField(required: true)]
public SpriteSpecifier ObjectiveSprite;
}

View File

@@ -0,0 +1,113 @@
using Content.Server._CP14.Objectives.Components;
using Content.Shared._CP14.Currency;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Objectives.Components;
using Content.Shared.Objectives.Systems;
using Robust.Shared.Containers;
namespace Content.Server._CP14.Objectives.Systems;
public sealed class CP14CurrencyCollectConditionSystem : EntitySystem
{
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly SharedObjectivesSystem _objectives = default!;
[Dependency] private readonly CP14CurrencySystem _currency = default!;
private EntityQuery<ContainerManagerComponent> _containerQuery;
public override void Initialize()
{
base.Initialize();
_containerQuery = GetEntityQuery<ContainerManagerComponent>();
SubscribeLocalEvent<CP14CurrencyCollectConditionComponent, ObjectiveAssignedEvent>(OnAssigned);
SubscribeLocalEvent<CP14CurrencyCollectConditionComponent, ObjectiveAfterAssignEvent>(OnAfterAssign);
SubscribeLocalEvent<CP14CurrencyCollectConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
}
private void OnAssigned(Entity<CP14CurrencyCollectConditionComponent> condition, ref ObjectiveAssignedEvent args)
{
}
private void OnAfterAssign(Entity<CP14CurrencyCollectConditionComponent> condition, ref ObjectiveAfterAssignEvent args)
{
_metaData.SetEntityName(condition.Owner, Loc.GetString(condition.Comp.ObjectiveText), args.Meta);
_metaData.SetEntityDescription(condition.Owner, Loc.GetString(condition.Comp.ObjectiveDescription, ("coins", _currency.GetPrettyCurrency(condition.Comp.Currency))), args.Meta);
_objectives.SetIcon(condition.Owner, condition.Comp.ObjectiveSprite);
}
private void OnGetProgress(Entity<CP14CurrencyCollectConditionComponent> condition, ref ObjectiveGetProgressEvent args)
{
args.Progress = GetProgress(args.Mind, condition);
}
private float GetProgress(MindComponent mind, CP14CurrencyCollectConditionComponent condition)
{
if (!_containerQuery.TryGetComponent(mind.OwnedEntity, out var currentManager))
return 0;
var containerStack = new Stack<ContainerManagerComponent>();
var count = 0;
//check pulling object
if (TryComp<PullerComponent>(mind.OwnedEntity, out var pull)) //TO DO: to make the code prettier? don't like the repetition
{
var pulledEntity = pull.Pulling;
if (pulledEntity != null)
{
CheckEntity(pulledEntity.Value, condition, ref containerStack, ref count);
}
}
// recursively check each container for the item
// checks inventory, bag, implants, etc.
do
{
foreach (var container in currentManager.Containers.Values)
{
foreach (var entity in container.ContainedEntities)
{
// check if this is the item
count += CheckCurrency(entity, condition);
// if it is a container check its contents
if (_containerQuery.TryGetComponent(entity, out var containerManager))
containerStack.Push(containerManager);
}
}
} while (containerStack.TryPop(out currentManager));
var result = count / (float) condition.Currency;
result = Math.Clamp(result, 0, 1);
return result;
}
private void CheckEntity(EntityUid entity, CP14CurrencyCollectConditionComponent condition, ref Stack<ContainerManagerComponent> containerStack, ref int counter)
{
// check if this is the item
counter += CheckCurrency(entity, condition);
//we don't check the inventories of sentient entity
if (!TryComp<MindContainerComponent>(entity, out _))
{
// if it is a container check its contents
if (_containerQuery.TryGetComponent(entity, out var containerManager))
containerStack.Push(containerManager);
}
}
private int CheckCurrency(EntityUid entity, CP14CurrencyCollectConditionComponent condition)
{
// check if this is the target
if (!TryComp<CP14CurrencyComponent>(entity, out var target))
return 0;
if (target.Category != condition.Category)
return 0;
return _currency.GetTotalCurrency(entity);
}
}

View File

@@ -0,0 +1,18 @@
namespace Content.Shared._CP14.Currency;
/// <summary>
/// Reflects the market value of an item, to guide players through the economy.
/// </summary>
[RegisterComponent, Access(typeof(CP14CurrencySystem))]
public sealed partial class CP14CurrencyComponent : Component
{
[DataField]
public int Currency = 1;
/// <summary>
/// allows you to categorize different valuable items in order to, for example, give goals for buying weapons, or earning money specifically.
/// </summary>
[DataField]
public string? Category;
}

View File

@@ -0,0 +1,62 @@
using Content.Shared.Examine;
using Content.Shared.Stacks;
namespace Content.Shared._CP14.Currency;
public sealed partial class CP14CurrencySystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CP14CurrencyComponent, ExaminedEvent>(OnExamine);
}
private void OnExamine(Entity<CP14CurrencyComponent> currency, ref ExaminedEvent args)
{
var total = GetTotalCurrency(currency, currency.Comp);
var push = Loc.GetString("cp14-currency-examine-title");
push += GetPrettyCurrency(total);
args.PushMarkup(push);
}
public string GetPrettyCurrency(int currency)
{
var total = currency;
if (total <= 0)
return string.Empty;
var gp = total / 100;
total %= 100;
var sp = total / 10;
total %= 10;
var cp = total;
var push = string.Empty;
if (gp > 0) push += " " + Loc.GetString("cp14-currency-examine-gp", ("coin", gp));
if (sp > 0) push += " " + Loc.GetString("cp14-currency-examine-sp", ("coin", sp));
if (cp > 0) push += " " + Loc.GetString("cp14-currency-examine-cp", ("coin", cp));
return push;
}
public int GetTotalCurrency(EntityUid uid, CP14CurrencyComponent? currency = null)
{
if (!Resolve(uid, ref currency))
return 0;
var total = currency.Currency;
if (TryComp<StackComponent>(uid, out var stack))
{
total *= stack.Count;
}
return total;
}
}

View File

@@ -0,0 +1,4 @@
cp14-currency-examine-title = Market price:
cp14-currency-examine-gp = [color=#ebad3b]{$coin}gp[/color]
cp14-currency-examine-sp = [color=#bad1d6]{$coin}sp[/color]
cp14-currency-examine-cp = [color=#824e27]{$coin}cp[/color]

View File

@@ -1,4 +1,4 @@
cp14-objective-issuer-expedition = [color=#fcae38]Expedition oobjective[/color]
cp14-objective-issuer-expedition = [color=#fcae38]Expedition objective[/color]
cp14-objective-expedition-collect-title = Collect { $itemName }
cp14-objective-expedition-collect-desc = Your objective is to collect and deliver { $itemName } to the Elemental Ship.

View File

@@ -1 +0,0 @@
objective-issuer-ExpeditionObjective = [color=#d6853a]Expedition Objective[/color]

View File

@@ -0,0 +1,4 @@
cp14-objective-issuer-personal = [color="#95a6c2"]Personal objectives[/color]
cp14-objective-personal-currency-collect-title = Make money
cp14-objective-personal-currency-collect-desc = I need this expedition primarily as a way to make money. At the very least I plan on making{$coins}

View File

@@ -0,0 +1,4 @@
cp14-currency-examine-title = Рыночная цена:
cp14-currency-examine-gp = [color=#ebad3b]{$coin}зм[/color]
cp14-currency-examine-sp = [color=#bad1d6]{$coin}см[/color]
cp14-currency-examine-cp = [color=#824e27]{$coin}мм[/color]

View File

@@ -1 +0,0 @@
objective-issuer-ExpeditionObjective = [color=#d6853a]Цель экспедиции[/color]

View File

@@ -0,0 +1,4 @@
cp14-objective-issuer-personal = [color="#95a6c2"]Личные цели[/color]
cp14-objective-personal-currency-collect-title = Заработать денег
cp14-objective-personal-currency-collect-desc = Эта экспедиция нужна мне в первую очередь как способ заработка денег. Как минимум я планирую заработать{$coins}

View File

@@ -46195,7 +46195,6 @@ entities:
- CP14Crossbolt
- CP14BaseSharpeningStone
- CP14BaseSharpeningStone
- CP14Shovel
- CP14OldLantern
- CP14CopperCoin1
- CP14CopperCoin1
@@ -46226,7 +46225,6 @@ entities:
- CP14Crossbolt
- CP14BaseSharpeningStone
- CP14BaseSharpeningStone
- CP14Shovel
- CP14OldLantern
- CP14CopperCoin1
- CP14CopperCoin1
@@ -46257,7 +46255,6 @@ entities:
- CP14Crossbolt
- CP14BaseSharpeningStone
- CP14BaseSharpeningStone
- CP14Shovel
- CP14OldLantern
- CP14CopperCoin1
- CP14CopperCoin1
@@ -46288,7 +46285,6 @@ entities:
- CP14Crossbolt
- CP14BaseSharpeningStone
- CP14BaseSharpeningStone
- CP14Shovel
- CP14OldLantern
- CP14CopperCoin1
- CP14CopperCoin1
@@ -46319,7 +46315,6 @@ entities:
- CP14Crossbolt
- CP14BaseSharpeningStone
- CP14BaseSharpeningStone
- CP14Shovel
- CP14OldLantern
- CP14CopperCoin1
- CP14CopperCoin1
@@ -46350,7 +46345,6 @@ entities:
- CP14Crossbolt
- CP14BaseSharpeningStone
- CP14BaseSharpeningStone
- CP14Shovel
- CP14OldLantern
- CP14CopperCoin1
- CP14CopperCoin1
@@ -46449,7 +46443,6 @@ entities:
- CP14Crossbolt
- CP14BaseSharpeningStone
- CP14BaseSharpeningStone
- CP14Shovel
- CP14OldLantern
- CP14CopperCoin1
- CP14CopperCoin1
@@ -46480,7 +46473,6 @@ entities:
- CP14Crossbolt
- CP14BaseSharpeningStone
- CP14BaseSharpeningStone
- CP14Shovel
- CP14OldLantern
- CP14CopperCoin1
- CP14CopperCoin1
@@ -46512,7 +46504,6 @@ entities:
- CP14Crossbolt
- CP14BaseSharpeningStone
- CP14BaseSharpeningStone
- CP14Shovel
- CP14OldLantern
- CP14CopperCoin1
- CP14CopperCoin1
@@ -46543,7 +46534,6 @@ entities:
- CP14Crossbolt
- CP14BaseSharpeningStone
- CP14BaseSharpeningStone
- CP14Shovel
- CP14OldLantern
- CP14CopperCoin1
- CP14CopperCoin1
@@ -46640,7 +46630,6 @@ entities:
- CP14Crossbolt
- CP14BaseSharpeningStone
- CP14BaseSharpeningStone
- CP14Shovel
- CP14OldLantern
- CP14CopperCoin1
- CP14CopperCoin1
@@ -46672,7 +46661,6 @@ entities:
- CP14Crossbolt
- CP14BaseSharpeningStone
- CP14BaseSharpeningStone
- CP14Shovel
- CP14OldLantern
- CP14CopperCoin1
- CP14CopperCoin1

View File

@@ -23,6 +23,9 @@
- coin9
- coin10
- type: Appearance
- type: CP14Currency
currency: 1
category: Currency
# Copper
@@ -41,6 +44,8 @@
- type: Stack
stackType: CP14CopperCoin
count: 10
- type: CP14Currency
currency: 1
- type: entity
id: CP14CopperCoin5
@@ -79,6 +84,8 @@
- type: Stack
stackType: CP14SilverCoin
count: 10
- type: CP14Currency
currency: 10
- type: entity
id: CP14SilverCoin5
@@ -117,6 +124,8 @@
- type: Stack
stackType: CP14GoldCoin
count: 10
- type: CP14Currency
currency: 100
- type: entity
id: CP14GoldCoin5
@@ -155,6 +164,8 @@
- type: Stack
stackType: CP14PlatinumCoin
count: 10
- type: CP14Currency
currency: 1000
- type: entity
id: CP14PlatinumCoin5

View File

@@ -57,3 +57,5 @@
params:
variation: 0.03
volume: 2
- type: CP14Currency
currency: 1500

View File

@@ -35,4 +35,6 @@
soundHit:
collection: MetalThud
cPAnimationLength: 0.3
cPAnimationOffset: -1.3
cPAnimationOffset: -1.3
- type: CP14Currency
currency: 20

View File

@@ -41,4 +41,6 @@
offset: 0.15,0.15
removalTime: 1
- type: ThrowingAngle
angle: 225
angle: 225
- type: CP14Currency
currency: 200

View File

@@ -40,4 +40,6 @@
damage:
types:
Slash: 5
Piercing: 5
Piercing: 5
- type: CP14Currency
currency: 500

View File

@@ -42,3 +42,5 @@
params:
variation: 0.03
volume: 2
- type: CP14Currency
currency: 200

View File

@@ -34,3 +34,5 @@
damage:
types:
Blunt: 10
- type: CP14Currency
currency: 500

View File

@@ -38,4 +38,6 @@
collection: MetalThud
- type: Tag
tags:
- CP14HerbalGathering
- CP14HerbalGathering
- type: CP14Currency
currency: 100

View File

@@ -33,4 +33,10 @@
types:
Slash: 12
soundHit:
collection: MetalThud
collection: MetalThud
- type: CP14SkillRequirement
fuckupChance: 0.5
requiredSkills:
- Warcraft
- type: CP14Currency
currency: 1200

View File

@@ -48,6 +48,8 @@
fuckupChance: 0.5
requiredSkills:
- Warcraft
- type: CP14Currency
currency: 5000
- type: entity
id: CP14TwoHandedSwordScythe

View File

@@ -51,4 +51,6 @@
unwielded-arrow:
whitelist:
tags:
- CP14CrossbowBolt
- CP14CrossbowBolt
- type: CP14Currency
currency: 2500

View File

@@ -13,7 +13,8 @@
components:
- type: CP14ExpeditionObjectivesRule
objectives:
- CP14ExpeditionCollectGoldObjective
#- CP14ExpeditionCollectGoldObjective
- CP14PersonalCurrencyCollectObjectiveMedium
# Expedition random objectives
# main objective + sub objective?
# motivations

View File

@@ -0,0 +1,51 @@
- type: entity
abstract: true
parent: BaseObjective
id: CP14BasePersonalObjective
components:
- type: Objective
issuer: cp14-objective-issuer-personal
difficulty: 1
- type: entity
parent: CP14BasePersonalObjective
abstract: true
id: CP14BasePersonalCurrencyCollectObjective
components:
- type: Objective
difficulty: 0
- type: CP14CurrencyCollectCondition
currency: 10
category: Currency
objectiveText: cp14-objective-personal-currency-collect-title
objectiveDescription: cp14-objective-personal-currency-collect-desc
objectiveSprite:
sprite: /Textures/_CP14/Objects/Economy/gp_coin.rsi
state: coin10
- type: entity
parent: CP14BasePersonalCurrencyCollectObjective
id: CP14PersonalCurrencyCollectObjectiveSmall
components:
- type: Objective
difficulty: 0.5
- type: CP14CurrencyCollectCondition
currency: 500
- type: entity
parent: CP14BasePersonalCurrencyCollectObjective
id: CP14PersonalCurrencyCollectObjectiveMedium
components:
- type: Objective
difficulty: 1
- type: CP14CurrencyCollectCondition
currency: 1000
- type: entity
parent: CP14BasePersonalCurrencyCollectObjective
id: CP14PersonalCurrencyCollectObjectiveBig
components:
- type: Objective
difficulty: 3
- type: CP14CurrencyCollectCondition
currency: 3000