Skip to content

Commit

Permalink
QoL Deposit/Withdraw
Browse files Browse the repository at this point in the history
- when depositing or withdrawing a single item, banker will not prompt for an amount
- depositing or selling a damaged item will no longer work
- updated ChaosTool to have "NoTrade" for items
- added an integrity check for items that are Equippable, but have no SellValue
  • Loading branch information
Sichii committed May 1, 2024
1 parent 60850a7 commit 450c2db
Show file tree
Hide file tree
Showing 16 changed files with 333 additions and 55 deletions.
6 changes: 4 additions & 2 deletions Chaos/Models/World/Abstractions/Creature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ public virtual void ShowPublicMessage(PublicMessageType publicMessageType, strin
switch (publicMessageType)
{
case PublicMessageType.Normal:
creaturesWithinRange = MapInstance.GetEntitiesWithinRange<Creature>(this);
creaturesWithinRange = MapInstance.GetEntitiesWithinRange<Creature>(this)
.ThatCanObserve(this);
sendMessage = $"{Name}: {message}";

break;
Expand All @@ -364,7 +365,8 @@ public virtual void ShowPublicMessage(PublicMessageType publicMessageType, strin

break;
case PublicMessageType.Chant:
creaturesWithinRange = MapInstance.GetEntities<Creature>();
creaturesWithinRange = MapInstance.GetEntities<Creature>()
.ThatCanObserve(this);

break;
default:
Expand Down
20 changes: 20 additions & 0 deletions Chaos/Scripting/DialogScripts/BankScripts/DepositItemScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ private void OnDisplayingInitial(Aisling source)
/// <inheritdoc />
public override void OnNext(Aisling source, byte? optionIndex = null)
{
if (!TryFetchArgs<byte>(out var slot) || !source.Inventory.TryGetObject(slot, out var item))
{
Subject.ReplyToUnknownInput(source);

return;
}

//if the inventory only has 1 of the specified item, skip the amount request
if (source.Inventory.CountOf(item.DisplayName) == 1)
{
Subject.MenuArgs.Add("1");
OnNextAmountRequest(source);

return;
}

switch (Subject.Template.TemplateKey.ToLower())
{
case "generic_deposititem_amountrequest":
Expand Down Expand Up @@ -103,6 +119,10 @@ private void OnNextAmountRequest(Aisling source)
//Subject.Reply(source, $"You don't have enough gold, you need {}");
//this script doesnt currently take into account deposit fees

return;
case ComplexActionHelper.DepositItemResult.ItemDamaged:
Subject.Reply(source, "That item is damaged, I don't want to be responsible for it.", "generic_deposititem_initial");

return;
case ComplexActionHelper.DepositItemResult.BadInput:
Subject.ReplyToUnknownInput(source);
Expand Down
16 changes: 16 additions & 0 deletions Chaos/Scripting/DialogScripts/BankScripts/WithdrawItemScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ private void OnDisplayingAmountRequest(Aisling source)
/// <inheritdoc />
public override void OnNext(Aisling source, byte? optionIndex = null)
{
if (!TryFetchArgs<string>(out var itemName) || !TryGetItem(source, itemName, out var item))
{
Subject.ReplyToUnknownInput(source);

return;
}

//if the bank only has 1 of the specified item, skip the amount request
if (item.Count == 1)
{
Subject.MenuArgs.Add("1");
OnNextAmountRequest(source);

return;
}

switch (Subject.Template.TemplateKey.ToLower())
{
case "generic_withdrawitem_amountrequest":
Expand Down
4 changes: 4 additions & 0 deletions Chaos/Scripting/DialogScripts/ShopScripts/SellShopScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ private void OnDisplayingAccepted(Aisling source)
case ComplexActionHelper.SellItemResult.TooMuchGold:
Subject.Reply(source, "You are carrying too much gold.", "generic_sellshop_initial");

return;
case ComplexActionHelper.SellItemResult.ItemDamaged:
Subject.Reply(source, "I don't want your junk, ask a smith to fix it.", "generic_sellshop_initial");

return;
case ComplexActionHelper.SellItemResult.BadInput:
Subject.ReplyToUnknownInput(source);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Chaos.Common.Utilities;
using Chaos.Extensions;
using Chaos.Extensions.Common;
using Chaos.Extensions.Geometry;
using Chaos.Models.World;
using Chaos.Scripting.MerchantScripts.Abstractions;
using Chaos.Utilities;
using Humanizer;

namespace Chaos.Scripting.MerchantScripts.BankScripts.Abstractions;

Expand Down Expand Up @@ -39,7 +42,7 @@ public abstract class VerbalBankerScriptBase : MerchantScriptBase

protected static ICollection<string> DontHaveThatManyWithdrawPhrases { get; } = new List<string>
{
"{Name}, it appears you don't have {AmountOfThing} in your account.",
"{Name}, it appears you don't have {AmountOfThing} in your account.".Humanize(),
"{Name}, {AmountOfThing} seems to exceed your balance.",
"{Name}, you don't have {AmountOfThing} to withdraw.",
"{Name}, you're missing {AmountOfThing} for withdrawal.",
Expand All @@ -56,6 +59,15 @@ public abstract class VerbalBankerScriptBase : MerchantScriptBase
"How much gold I got"
};

protected static ICollection<string> ItemDamagedDepositPhrases { get; } = new List<string>
{
"{Name}, I can't be made responsible for your damaged {AmountOfThing}.",
"{Name}, your {AmountOfThing} is damaged. Deposit denied.",
"{Name}, your {AmountOfThing} isn't in depositable condition.",
"{Name}, fix your {AmountOfThing} before depositing it.",
"{Name}, I can't take your {AmountOfThing}. Ask a smith to fix it."
};

protected ILogger Logger { get; }

protected static ICollection<string> MoneyTerms { get; } = new List<string>
Expand Down Expand Up @@ -85,6 +97,20 @@ protected VerbalBankerScriptBase(Merchant subject, ILogger logger)
: base(subject)
=> Logger = logger;

protected virtual string Humanize(
string template,
string name,
int amount,
string thing)
{
if (amount > 1)
template.ReplaceI("{AmountOfThing} is", "{AmountOfThing} are");
else
template.ReplaceI("{AmountOfThing} are", "{AmountOfThing} is");

return template.Inject(name, thing.ToQuantity(amount));
}

protected virtual bool IsClosestVerbalBankerTo(Aisling aisling)
{
//if we're checking, it means we're in range... it should be impossible to get no results
Expand All @@ -101,5 +127,27 @@ protected virtual bool IsClosestVerbalBankerTo(Aisling aisling)
return false;
}

protected virtual void RandomizedReply(
Merchant source,
ICollection<string> phrases,
string name,
int amount,
string thing,
int? goldAmount = null)
{
var phrase = phrases.PickRandom();

phrase = Humanize(
phrase,
name,
amount,
thing);

if (goldAmount.HasValue)
phrase = phrase.Inject(goldAmount.Value);

source.Say(phrase);
}

protected virtual void ReplyToUnknownInput(Aisling aisling) => Subject.Say(DialogString.UnknownInput);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Chaos.Common.Utilities;
using Chaos.Definitions;
using Chaos.Extensions.Common;
using Chaos.Models.World;
using Chaos.Models.World.Abstractions;
using Chaos.NLog.Logging.Definitions;
Expand All @@ -24,8 +22,12 @@ protected virtual void DepositGold(Aisling source, int amount)
{
case ComplexActionHelper.DepositGoldResult.Success:
{
var phrase = DepositPhrases.PickRandom();
Subject.Say(phrase.Inject(source.Name, $"{amount} gold"));
RandomizedReply(
Subject,
DepositPhrases,
source.Name,
amount,
"gold");

Logger.WithTopics(Topics.Entities.Aisling, Topics.Entities.Gold, Topics.Actions.Deposit)
.WithProperty(source)
Expand All @@ -36,8 +38,12 @@ protected virtual void DepositGold(Aisling source, int amount)
}
case ComplexActionHelper.DepositGoldResult.DontHaveThatMany:
{
var phrase = DontHaveThatManyDepositPhrases.PickRandom();
Subject.Say(phrase.Inject(source.Name, $"{amount} gold"));
RandomizedReply(
Subject,
DontHaveThatManyDepositPhrases,
source.Name,
amount,
"gold");

break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Chaos.Common.Utilities;
using Chaos.Definitions;
using Chaos.Extensions.Common;
using Chaos.Models.World;
Expand All @@ -7,7 +6,6 @@
using Chaos.NLog.Logging.Extensions;
using Chaos.Scripting.MerchantScripts.BankScripts.Abstractions;
using Chaos.Utilities;
using Humanizer;

namespace Chaos.Scripting.MerchantScripts.BankScripts;

Expand All @@ -25,8 +23,12 @@ protected virtual void DepositItem(Aisling source, int amount, string itemName)
{
case ComplexActionHelper.DepositItemResult.Success:
{
var phrase = DepositPhrases.PickRandom();
Subject.Say(phrase.Inject(source.Name, itemName.ToQuantity(amount)));
RandomizedReply(
Subject,
DepositPhrases,
source.Name,
amount,
itemName);

Logger.WithTopics(Topics.Entities.Aisling, Topics.Entities.Item, Topics.Actions.Deposit)
.WithProperty(source)
Expand All @@ -41,14 +43,23 @@ protected virtual void DepositItem(Aisling source, int amount, string itemName)
}
case ComplexActionHelper.DepositItemResult.DontHaveThatMany:
{
var phrase = DontHaveThatManyDepositPhrases.PickRandom();
Subject.Say(phrase.Inject(source.Name, itemName.ToQuantity(amount)));
RandomizedReply(
Subject,
DontHaveThatManyDepositPhrases,
source.Name,
amount,
itemName);

break;
}
case ComplexActionHelper.DepositItemResult.NotEnoughGold:
{
//TODO: gold fees not used in these samples
RandomizedReply(
Subject,
ItemDamagedDepositPhrases,
source.Name,
amount,
itemName);

break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Chaos.Common.Utilities;
using Chaos.Definitions;
using Chaos.Extensions.Common;
using Chaos.Models.World;
using Chaos.Models.World.Abstractions;
using Chaos.NLog.Logging.Definitions;
Expand Down Expand Up @@ -64,8 +62,12 @@ protected virtual void WithdrawGold(Aisling source, int amount)
{
case ComplexActionHelper.WithdrawGoldResult.Success:
{
var phrase = WithdrawPhrases.PickRandom();
Subject.Say(phrase.Inject(source.Name, $"{amount} gold"));
RandomizedReply(
Subject,
WithdrawPhrases,
source.Name,
amount,
"gold");

Logger.WithTopics(Topics.Entities.Aisling, Topics.Entities.Gold, Topics.Actions.Withdraw)
.WithProperty(source)
Expand All @@ -82,8 +84,12 @@ protected virtual void WithdrawGold(Aisling source, int amount)
}
case ComplexActionHelper.WithdrawGoldResult.DontHaveThatMany:
{
var phrase = DontHaveThatManyWithdrawPhrases.PickRandom();
Subject.Say(phrase.Inject(source.Name, $"{amount} gold"));
RandomizedReply(
Subject,
DontHaveThatManyWithdrawPhrases,
source.Name,
amount,
"gold");

break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Chaos.Common.Utilities;
using Chaos.Definitions;
using Chaos.Extensions.Common;
using Chaos.Models.World;
Expand All @@ -7,7 +6,6 @@
using Chaos.NLog.Logging.Extensions;
using Chaos.Scripting.MerchantScripts.BankScripts.Abstractions;
using Chaos.Utilities;
using Humanizer;

namespace Chaos.Scripting.MerchantScripts.BankScripts;

Expand Down Expand Up @@ -78,8 +76,12 @@ public virtual void WithdrawItem(Aisling source, int amount, string itemName)
{
case ComplexActionHelper.WithdrawItemResult.Success:
{
var phrase = WithdrawPhrases.PickRandom();
Subject.Say(phrase.Inject(source.Name, itemName.ToQuantity(amount)));
RandomizedReply(
Subject,
WithdrawPhrases,
source.Name,
amount,
itemName);

Logger.WithTopics(Topics.Entities.Aisling, Topics.Entities.Item, Topics.Actions.Withdraw)
.WithProperty(source)
Expand All @@ -100,8 +102,12 @@ public virtual void WithdrawItem(Aisling source, int amount, string itemName)
}
case ComplexActionHelper.WithdrawItemResult.DontHaveThatMany:
{
var phrase = DontHaveThatManyWithdrawPhrases.PickRandom();
Subject.Say(phrase.Inject(source.Name, itemName.ToQuantity(amount)));
RandomizedReply(
Subject,
DontHaveThatManyWithdrawPhrases,
source.Name,
amount,
itemName);

break;
}
Expand Down
Loading

0 comments on commit 450c2db

Please sign in to comment.