mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-30 08:07:28 +00:00
* added dynamic cost to Ratkings OnRaiseArmy ability * Update Content.Server/RatKing/RatKingSystem.cs Co-authored-by: Vanessa <908648+ShepardToTheStars@users.noreply.github.com> Signed-off-by: Carol <292806487+CarolCuchara@users.noreply.github.com> * switched summary to one line * added using directive for Linq --------- Signed-off-by: Carol <292806487+CarolCuchara@users.noreply.github.com> Co-authored-by: Vanessa <908648+ShepardToTheStars@users.noreply.github.com>
154 lines
6.1 KiB
C#
154 lines
6.1 KiB
C#
using System.Linq; // DeltaV
|
|
using System.Numerics;
|
|
using Content.Server.Atmos.EntitySystems;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.NPC;
|
|
using Content.Server.NPC.HTN;
|
|
using Content.Server.NPC.Systems;
|
|
using Content.Server.Popups;
|
|
using Content.Shared.Atmos;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Dataset;
|
|
using Content.Shared.Mobs; // DeltaV
|
|
using Content.Shared.Mobs.Components; // DeltaV
|
|
using Content.Shared.Nutrition.Components;
|
|
using Content.Shared.Nutrition.EntitySystems;
|
|
using Content.Shared.Pointing;
|
|
using Content.Shared.Random.Helpers;
|
|
using Content.Shared.RatKing;
|
|
using Robust.Shared.Map;
|
|
|
|
namespace Content.Server.RatKing
|
|
{
|
|
/// <inheritdoc/>
|
|
public sealed class RatKingSystem : SharedRatKingSystem
|
|
{
|
|
[Dependency] private readonly AtmosphereSystem _atmos = default!;
|
|
[Dependency] private readonly ChatSystem _chat = default!;
|
|
[Dependency] private readonly HTNSystem _htn = default!;
|
|
[Dependency] private readonly HungerSystem _hunger = default!;
|
|
[Dependency] private readonly NPCSystem _npc = default!;
|
|
[Dependency] private readonly PopupSystem _popup = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<RatKingComponent, RatKingRaiseArmyActionEvent>(OnRaiseArmy);
|
|
SubscribeLocalEvent<RatKingComponent, RatKingDomainActionEvent>(OnDomain);
|
|
SubscribeLocalEvent<RatKingComponent, AfterPointedAtEvent>(OnPointedAt);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Summons an allied rat servant at the King, costing a small amount of hunger
|
|
/// </summary>
|
|
private void OnRaiseArmy(EntityUid uid, RatKingComponent component, RatKingRaiseArmyActionEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
if (!TryComp<HungerComponent>(uid, out var hunger))
|
|
return;
|
|
|
|
// DeltaV - modify cost of Raise Army based on the amount of alive servants
|
|
// Check on how many servants are alive to calculate the cost of a new servant
|
|
var aliveServants = component.Servants.Count(servant
|
|
=> TryComp<MobStateComponent>(servant, out var mobState) && mobState.CurrentState == MobState.Alive);
|
|
|
|
// calculate the cost multiplier
|
|
var multiplier = aliveServants switch
|
|
{
|
|
< 5 => 1.0f, // 1-5 servants: 10 hunger
|
|
< 10 => 1.5f, // 6-10 servants: 15 hunger
|
|
< 15 => 2.5f, // 11-15 servants: 25 hunger
|
|
< 20 => 5.0f, // 16-20 servants: 50 hunger
|
|
< 25 => 10.0f, // 21-25 servants: 100 hunger
|
|
_ => 15.0f, // Above 25 servants: 150 hunger
|
|
};
|
|
var hungerPerArmyUseAdjusted = component.HungerPerArmyUse * multiplier;
|
|
|
|
//make sure the hunger doesn't go into the negatives
|
|
if (_hunger.GetHunger(hunger) < hungerPerArmyUseAdjusted)
|
|
{
|
|
_popup.PopupEntity(Loc.GetString("rat-king-too-hungry"), uid, uid);
|
|
return;
|
|
}
|
|
args.Handled = true;
|
|
_hunger.ModifyHunger(uid, - hungerPerArmyUseAdjusted, hunger);
|
|
// DeltaV - end to the modified cost of Raise Army
|
|
|
|
var servant = Spawn(component.ArmyMobSpawnId, Transform(uid).Coordinates);
|
|
var comp = EnsureComp<RatKingServantComponent>(servant);
|
|
comp.King = uid;
|
|
Dirty(servant, comp);
|
|
|
|
component.Servants.Add(servant);
|
|
_npc.SetBlackboard(servant, NPCBlackboard.FollowTarget, new EntityCoordinates(uid, Vector2.Zero));
|
|
UpdateServantNpc(servant, component.CurrentOrder);
|
|
}
|
|
|
|
/// <summary>
|
|
/// uses hunger to release a specific amount of ammonia into the air. This heals the rat king
|
|
/// and his servants through a specific metabolism.
|
|
/// </summary>
|
|
private void OnDomain(EntityUid uid, RatKingComponent component, RatKingDomainActionEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
if (!TryComp<HungerComponent>(uid, out var hunger))
|
|
return;
|
|
|
|
//make sure the hunger doesn't go into the negatives
|
|
if (_hunger.GetHunger(hunger) < component.HungerPerDomainUse)
|
|
{
|
|
_popup.PopupEntity(Loc.GetString("rat-king-too-hungry"), uid, uid);
|
|
return;
|
|
}
|
|
args.Handled = true;
|
|
_hunger.ModifyHunger(uid, -component.HungerPerDomainUse, hunger);
|
|
|
|
_popup.PopupEntity(Loc.GetString("deltav-rat-king-domain-popup"), uid); // DeltaV - Changed the loc string.
|
|
var tileMix = _atmos.GetTileMixture(uid, excite: true);
|
|
tileMix?.AdjustMoles(Gas.Ammonia, component.MolesAmmoniaPerDomain);
|
|
}
|
|
|
|
private void OnPointedAt(EntityUid uid, RatKingComponent component, ref AfterPointedAtEvent args)
|
|
{
|
|
if (component.CurrentOrder != RatKingOrderType.CheeseEm)
|
|
return;
|
|
|
|
foreach (var servant in component.Servants)
|
|
{
|
|
_npc.SetBlackboard(servant, NPCBlackboard.CurrentOrderedTarget, args.Pointed);
|
|
}
|
|
}
|
|
|
|
public override void UpdateServantNpc(EntityUid uid, RatKingOrderType orderType)
|
|
{
|
|
base.UpdateServantNpc(uid, orderType);
|
|
|
|
if (!TryComp<HTNComponent>(uid, out var htn))
|
|
return;
|
|
|
|
if (htn.Plan != null)
|
|
_htn.ShutdownPlan(htn);
|
|
|
|
_npc.SetBlackboard(uid, NPCBlackboard.CurrentOrders, orderType);
|
|
_htn.Replan(htn);
|
|
}
|
|
|
|
public override void DoCommandCallout(EntityUid uid, RatKingComponent component)
|
|
{
|
|
base.DoCommandCallout(uid, component);
|
|
|
|
if (!component.OrderCallouts.TryGetValue(component.CurrentOrder, out var datasetId) ||
|
|
!PrototypeManager.TryIndex<LocalizedDatasetPrototype>(datasetId, out var datasetPrototype))
|
|
return;
|
|
|
|
var msg = Random.Pick(datasetPrototype);
|
|
_chat.TrySendInGameICMessage(uid, msg, InGameICChatType.Speak, true);
|
|
}
|
|
}
|
|
}
|