Tavern map update (#516)

* recursive currency calculation

* map update

* fix
This commit is contained in:
Ed
2024-10-27 17:09:06 +03:00
committed by GitHub
parent c2404d6c0c
commit 2850665e33
10 changed files with 2966 additions and 4398 deletions

View File

@@ -236,7 +236,6 @@ namespace Content.IntegrationTests.Tests
// Test all availableJobs have spawnPoints
// This is done inside gamemap test because loading the map takes ages and we already have it.
/*
var comp = entManager.GetComponent<StationJobsComponent>(station);
var jobs = new HashSet<ProtoId<JobPrototype>>(comp.SetupAvailableJobs.Keys);
@@ -253,7 +252,6 @@ namespace Content.IntegrationTests.Tests
jobs.ExceptWith(spawnPoints);
Assert.That(jobs, Is.Empty, $"There is no spawnpoints for {string.Join(", ", jobs)} on {mapProto}.");
*/ //CP14 disable job spawners test
}
try

View File

@@ -0,0 +1,192 @@
using Content.Shared._CP14.Currency;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Stacks;
using Content.Shared.Verbs;
using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Server._CP14.Currency;
public sealed partial class CP14CurrencySystem
{
private void InitializeConverter()
{
SubscribeLocalEvent<CP14CurrencyConverterComponent, GetVerbsEvent<Verb>>(OnGetVerb);
SubscribeLocalEvent<CP14CurrencyConverterComponent, ExaminedEvent>(OnConverterExamine);
SubscribeLocalEvent<CP14CurrencyConverterComponent, InteractUsingEvent>(OnInteractUsing);
}
private void OnGetVerb(Entity<CP14CurrencyConverterComponent> ent, ref GetVerbsEvent<Verb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;
var transform = Transform(ent);
var coord = transform.Coordinates.Offset(transform.LocalRotation.RotateVec(ent.Comp.SpawnOffset));
Verb copperVerb = new()
{
Text = Loc.GetString("cp14-currency-converter-get-cp"),
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/_CP14/Objects/Economy/cp_coin.rsi/coin10.png")),
Category = VerbCategory.CP14CurrencyConvert,
Priority = 1,
CloseMenu = false,
Act = () =>
{
if (ent.Comp.Balance < CP.Value)
return;
ent.Comp.Balance -= CP.Value;
var newEnt = Spawn(CP.Key, coord);
_stack.TryMergeToContacts(newEnt);
_audio.PlayPvs(ent.Comp.InsertSound, ent, AudioParams.Default.WithMaxDistance(3).WithPitchScale(0.9f));
},
};
args.Verbs.Add(copperVerb);
Verb silverVerb = new()
{
Text = Loc.GetString("cp14-currency-converter-get-sp"),
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/_CP14/Objects/Economy/sp_coin.rsi/coin10.png")),
Category = VerbCategory.CP14CurrencyConvert,
Priority = 2,
CloseMenu = false,
Act = () =>
{
if (ent.Comp.Balance < SP.Value)
return;
ent.Comp.Balance -= SP.Value;
var newEnt = Spawn(SP.Key, coord);
_stack.TryMergeToContacts(newEnt);
_audio.PlayPvs(ent.Comp.InsertSound, ent, AudioParams.Default.WithMaxDistance(3).WithPitchScale(1.1f));
},
};
args.Verbs.Add(silverVerb);
Verb goldVerb = new()
{
Text = Loc.GetString("cp14-currency-converter-get-gp"),
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/_CP14/Objects/Economy/gp_coin.rsi/coin10.png")),
Category = VerbCategory.CP14CurrencyConvert,
Priority = 3,
CloseMenu = false,
Act = () =>
{
if (ent.Comp.Balance < GP.Value)
return;
ent.Comp.Balance -= GP.Value;
var newEnt = Spawn(GP.Key, coord);
_stack.TryMergeToContacts(newEnt);
_audio.PlayPvs(ent.Comp.InsertSound, ent, AudioParams.Default.WithMaxDistance(3).WithPitchScale(1.3f));
},
};
args.Verbs.Add(goldVerb);
Verb platinumVerb = new()
{
Text = Loc.GetString("cp14-currency-converter-get-pp"),
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/_CP14/Objects/Economy/pp_coin.rsi/coin10.png")),
Category = VerbCategory.CP14CurrencyConvert,
Priority = 4,
CloseMenu = false,
Act = () =>
{
if (ent.Comp.Balance < PP.Value)
return;
ent.Comp.Balance -= PP.Value;
var newEnt = Spawn(PP.Key, coord);
_stack.TryMergeToContacts(newEnt);
_audio.PlayPvs(ent.Comp.InsertSound, ent, AudioParams.Default.WithMaxDistance(3).WithPitchScale(1.5f));
},
};
args.Verbs.Add(platinumVerb);
}
private void OnConverterExamine(Entity<CP14CurrencyConverterComponent> ent, ref ExaminedEvent args)
{
var push = $"{Loc.GetString("cp14-currency-converter-examine-title")} {GetCurrencyPrettyString(ent.Comp.Balance)}";
args.PushMarkup(push);
}
private void OnInteractUsing(Entity<CP14CurrencyConverterComponent> ent, ref InteractUsingEvent args)
{
if (!TryComp<CP14CurrencyComponent>(args.Used, out var currency))
return;
if (ent.Comp.Whitelist is not null && !_whitelist.IsValid(ent.Comp.Whitelist, args.Used))
return;
var delta = GetTotalCurrency(args.Used);
ent.Comp.Balance += delta;
QueueDel(args.Used);
_popup.PopupEntity(Loc.GetString("cp14-currency-converter-insert", ("cash", delta)), ent, args.User);
_audio.PlayPvs(ent.Comp.InsertSound, ent, AudioParams.Default.WithMaxDistance(3));
}
public HashSet<EntityUid> GenerateMoney(EntProtoId currencyType, int target, EntityCoordinates coordinates, out int remainder)
{
remainder = target;
HashSet<EntityUid> spawns = new();
if (!_proto.TryIndex(currencyType, out var indexedCurrency))
return spawns;
var ent = Spawn(currencyType, coordinates);
if (ProcessEntity(ent, ref remainder, spawns))
return spawns;
while (remainder > 0)
{
var newEnt = Spawn(currencyType, coordinates);
if (ProcessEntity(newEnt, ref remainder, spawns))
break;
}
return spawns;
}
private bool ProcessEntity(EntityUid ent, ref int remainder, HashSet<EntityUid> spawns)
{
var singleCurrency = GetTotalCurrency(ent);
if (singleCurrency > remainder)
{
QueueDel(ent);
return true;
}
spawns.Add(ent);
remainder -= singleCurrency;
if (TryComp<StackComponent>(ent, out var stack) && _proto.TryIndex<StackPrototype>(stack.StackTypeId, out var indexedStack))
{
AdjustStack(ent, stack, indexedStack, singleCurrency, ref remainder);
}
return false;
}
private void AdjustStack(EntityUid ent, StackComponent stack, StackPrototype stackProto, float singleCurrency, ref int remainder)
{
var singleStackCurrency = singleCurrency / stack.Count;
var stackLeftSpace = stackProto.MaxCount - stack.Count;
if (stackLeftSpace is not null)
{
var addedStack = MathF.Min((float)stackLeftSpace, MathF.Floor(remainder / singleStackCurrency));
if (addedStack > 0)
{
_stack.SetCount(ent, stack.Count + (int)addedStack);
remainder -= (int)(addedStack * singleStackCurrency);
}
}
}
}

View File

@@ -1,17 +1,13 @@
using Content.Server.Popups;
using Content.Server.Stack;
using Content.Server.Storage.Components;
using Content.Shared._CP14.Currency;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Stacks;
using Content.Shared.Verbs;
using Content.Shared.Storage;
using Content.Shared.Whitelist;
using Robust.Server.Audio;
using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Server._CP14.Currency;
public sealed partial class CP14CurrencySystem : CP14SharedCurrencySystem
@@ -25,19 +21,18 @@ public sealed partial class CP14CurrencySystem : CP14SharedCurrencySystem
{
base.Initialize();
SubscribeLocalEvent<CP14CurrencyComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<CP14CurrencyConverterComponent, ExaminedEvent>(OnConverterExamine);
InitializeConverter();
SubscribeLocalEvent<CP14CurrencyConverterComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<CP14CurrencyConverterComponent, GetVerbsEvent<Verb>>(OnGetVerb);
SubscribeLocalEvent<CP14CurrencyExaminableComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<CP14CurrencyComponent, CP14GetCurrencyEvent>(OnGetCurrency);
SubscribeLocalEvent<EntityStorageComponent, CP14GetCurrencyEvent>(OnEntityStorageGetCurrency);
SubscribeLocalEvent<StorageComponent, CP14GetCurrencyEvent>(OnStorageGetCurrency);
}
private void OnGetCurrency(Entity<CP14CurrencyComponent> ent, ref CP14GetCurrencyEvent args)
{
var total = ent.Comp.Currency;
if (TryComp<StackComponent>(ent, out var stack))
{
total *= stack.Count;
@@ -46,7 +41,29 @@ public sealed partial class CP14CurrencySystem : CP14SharedCurrencySystem
args.Currency += total;
}
private void OnExamine(Entity<CP14CurrencyComponent> currency, ref ExaminedEvent args)
private void OnEntityStorageGetCurrency(Entity<EntityStorageComponent> ent, ref CP14GetCurrencyEvent args)
{
var total = 0;
foreach (var entity in ent.Comp.Contents.ContainedEntities)
{
total += GetTotalCurrency(entity);
}
args.Currency += total;
}
private void OnStorageGetCurrency(Entity<StorageComponent> ent, ref CP14GetCurrencyEvent args)
{
var total = 0;
foreach (var entity in ent.Comp.StoredItems)
{
total += GetTotalCurrency(entity.Key);
}
args.Currency += total;
}
private void OnExamine(Entity<CP14CurrencyExaminableComponent> currency, ref ExaminedEvent args)
{
var total = GetTotalCurrency(currency);
@@ -54,172 +71,4 @@ public sealed partial class CP14CurrencySystem : CP14SharedCurrencySystem
push += GetCurrencyPrettyString(total);
args.PushMarkup(push);
}
private void OnConverterExamine(Entity<CP14CurrencyConverterComponent> ent, ref ExaminedEvent args)
{
var push = $"{Loc.GetString("cp14-currency-converter-examine-title")} {GetCurrencyPrettyString(ent.Comp.Balance)}";
args.PushMarkup(push);
}
private void OnInteractUsing(Entity<CP14CurrencyConverterComponent> ent, ref InteractUsingEvent args)
{
if (!TryComp<CP14CurrencyComponent>(args.Used, out var currency))
return;
if (ent.Comp.Whitelist is not null && !_whitelist.IsValid(ent.Comp.Whitelist, args.Used))
return;
var delta = GetTotalCurrency(args.Used);
ent.Comp.Balance += delta;
QueueDel(args.Used);
_popup.PopupEntity(Loc.GetString("cp14-currency-converter-insert", ("cash", delta)), ent, args.User);
_audio.PlayPvs(ent.Comp.InsertSound, ent, AudioParams.Default.WithMaxDistance(3));
}
private void OnGetVerb(Entity<CP14CurrencyConverterComponent> ent, ref GetVerbsEvent<Verb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;
var transform = Transform(ent);
var coord = transform.Coordinates.Offset(transform.LocalRotation.RotateVec(ent.Comp.SpawnOffset));
Verb copperVerb = new()
{
Text = Loc.GetString("cp14-currency-converter-get-cp"),
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/_CP14/Objects/Economy/cp_coin.rsi/coin10.png")),
Category = VerbCategory.CP14CurrencyConvert,
Priority = 1,
CloseMenu = false,
Act = () =>
{
if (ent.Comp.Balance < CP.Value)
return;
ent.Comp.Balance -= CP.Value;
var newEnt = Spawn(CP.Key, coord);
_stack.TryMergeToContacts(newEnt);
_audio.PlayPvs(ent.Comp.InsertSound, ent, AudioParams.Default.WithMaxDistance(3).WithPitchScale(0.9f));
},
};
args.Verbs.Add(copperVerb);
Verb silverVerb = new()
{
Text = Loc.GetString("cp14-currency-converter-get-sp"),
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/_CP14/Objects/Economy/sp_coin.rsi/coin10.png")),
Category = VerbCategory.CP14CurrencyConvert,
Priority = 2,
CloseMenu = false,
Act = () =>
{
if (ent.Comp.Balance < SP.Value)
return;
ent.Comp.Balance -= SP.Value;
var newEnt = Spawn(SP.Key, coord);
_stack.TryMergeToContacts(newEnt);
_audio.PlayPvs(ent.Comp.InsertSound, ent, AudioParams.Default.WithMaxDistance(3).WithPitchScale(1.1f));
},
};
args.Verbs.Add(silverVerb);
Verb goldVerb = new()
{
Text = Loc.GetString("cp14-currency-converter-get-gp"),
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/_CP14/Objects/Economy/gp_coin.rsi/coin10.png")),
Category = VerbCategory.CP14CurrencyConvert,
Priority = 3,
CloseMenu = false,
Act = () =>
{
if (ent.Comp.Balance < GP.Value)
return;
ent.Comp.Balance -= GP.Value;
var newEnt = Spawn(GP.Key, coord);
_stack.TryMergeToContacts(newEnt);
_audio.PlayPvs(ent.Comp.InsertSound, ent, AudioParams.Default.WithMaxDistance(3).WithPitchScale(1.3f));
},
};
args.Verbs.Add(goldVerb);
Verb platinumVerb = new()
{
Text = Loc.GetString("cp14-currency-converter-get-pp"),
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/_CP14/Objects/Economy/pp_coin.rsi/coin10.png")),
Category = VerbCategory.CP14CurrencyConvert,
Priority = 4,
CloseMenu = false,
Act = () =>
{
if (ent.Comp.Balance < PP.Value)
return;
ent.Comp.Balance -= PP.Value;
var newEnt = Spawn(PP.Key, coord);
_stack.TryMergeToContacts(newEnt);
_audio.PlayPvs(ent.Comp.InsertSound, ent, AudioParams.Default.WithMaxDistance(3).WithPitchScale(1.5f));
},
};
args.Verbs.Add(platinumVerb);
}
public HashSet<EntityUid> GenerateMoney(EntProtoId currencyType, int target, EntityCoordinates coordinates, out int remainder)
{
remainder = target;
HashSet<EntityUid> spawns = new();
if (!_proto.TryIndex(currencyType, out var indexedCurrency))
return spawns;
var ent = Spawn(currencyType, coordinates);
if (ProcessEntity(ent, ref remainder, spawns))
return spawns;
while (remainder > 0)
{
var newEnt = Spawn(currencyType, coordinates);
if (ProcessEntity(newEnt, ref remainder, spawns))
break;
}
return spawns;
}
private bool ProcessEntity(EntityUid ent, ref int remainder, HashSet<EntityUid> spawns)
{
var singleCurrency = GetTotalCurrency(ent);
if (singleCurrency > remainder)
{
QueueDel(ent);
return true;
}
spawns.Add(ent);
remainder -= singleCurrency;
if (TryComp<StackComponent>(ent, out var stack) && _proto.TryIndex<StackPrototype>(stack.StackTypeId, out var indexedStack))
{
AdjustStack(ent, stack, indexedStack, singleCurrency, ref remainder);
}
return false;
}
private void AdjustStack(EntityUid ent, StackComponent stack, StackPrototype stackProto, float singleCurrency, ref int remainder)
{
var singleStackCurrency = singleCurrency / stack.Count;
var stackLeftSpace = stackProto.MaxCount - stack.Count;
if (stackLeftSpace is not null)
{
var addedStack = MathF.Min((float)stackLeftSpace, MathF.Floor(remainder / singleStackCurrency));
if (addedStack > 0)
{
_stack.SetCount(ent, stack.Count + (int)addedStack);
remainder -= (int)(addedStack * singleStackCurrency);
}
}
}
}

View File

@@ -0,0 +1,10 @@
namespace Content.Shared._CP14.Currency;
/// <summary>
/// Allows you to estimate the value of an item with a simple glance.
/// </summary>
[RegisterComponent]
public sealed partial class CP14CurrencyExaminableComponent : Component
{
}

View File

@@ -349,13 +349,6 @@ entities:
- type: Transform
pos: -0.5,-0.5
parent: 2
- proto: CP14SpawnPointCaptain
entities:
- uid: 241
components:
- type: Transform
pos: -1.5,-0.5
parent: 2
- proto: FenceMetalBroken
entities:
- uid: 217

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,7 @@
mapNameTemplate: "Meteor Arena"
- type: StationJobs
availableJobs:
CP14Captain: [ -1, -1 ]
CP14Adventurer: [ -1, -1 ]
- type: gameMap
id: AlchemyTest
@@ -35,7 +35,7 @@
availableJobs:
CP14Adventurer: [ -1, -1 ]
CP14Alchemist: [ -1, -1 ]
CP14Captain: [1, 1]
#CP14Captain: [1, 1]
- type: gameMap
id: BattleRoyale
@@ -54,7 +54,7 @@
availableJobs:
CP14Adventurer: [ -1, -1 ]
CP14Alchemist: [ -1, -1 ]
CP14Captain: [1, 1]
#CP14Captain: [1, 1]
- type: StationBiome
biome: CP14GrassFill
@@ -76,7 +76,7 @@
CP14Adventurer: [ -1, -1 ]
CP14Alchemist: [ 2, 3 ]
CP14Innkeeper: [ 3, 4 ]
CP14Captain: [1, 1]
#CP14Captain: [1, 1]
CP14Commandant: [1, 1]
CP14Banker: [3, 4]
#CP14GuardCommander: [1, 1]

View File

@@ -12,7 +12,7 @@
- type: StationJobs
availableJobs:
CP14Adventurer: [ -1, -1 ]
CP14Captain: [ -1, -1 ]
#CP14Captain: [ -1, -1 ]
- type: gameMap
id: Dev

View File

@@ -10,6 +10,7 @@
canBeAntag: false
supervisors: cp14-job-supervisors-command
weight: 10
setPreference: false #TEMP
- type: startingGear
id: CP14CaptainGear

View File

@@ -10,6 +10,7 @@
canBeAntag: false
supervisors: cp14-job-supervisors-command
weight: 2
setPreference: false #TEMP
- type: startingGear
id: CP14GuardCommanderGear