mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* ready * oop forgot the HUD stuff * woooo examinable generalized tooooo * oop I forgot to rename the files * bungled the merge, I guess * this is called hubris * Verin's comments * PR comments how did I use `ProtoId<> Hunger` in more than a few spots but then just say "thirst can stay a literal :^)"? also changed a few spots to my beloved ``` functionInvocation( one param per line ) ``` ``` * Satiation effect condition now with ADDED FUNCTIONALITY?? :o * tfw you trust the markov chain recommendation because long generic type names are tough q-q * TFW YOU TRUST THE MARKOV CHAIN BUT IT DOESN'T UNDERSTAND THE DIFFERING SEMANTICS OF MAX AND MIN AHHHHH * tfw you think to yourself "i need to fix the effects", but then forget to and the code doesn't even compile. * centralize satiation constants * other small comments * The enum is dead. But at what cost? * oop * like 12 more ooperses * green checks are mine by right; I have performed the rites; I have done my part; you will not deny me this succor * oops I changed the semantics from `<=` to just `<` and didn't update the tests :) * serialization has bested me :agony: also PR comments * never trust the auto merge :agony: * literally just this * force engine back to master because idk why it's different * fix randomness and update master * submodule fuckery * fall before my might * okay I ran the linter, ARE YOU HAPPY?? * cursed ovis, trouble me no more * protoman stuff * inb4 linter bonks me * break non-critical stuff from the main satiation proto *  inb4 this breaks something somewhere lmao * my two greatest PRs COLLIDE I wonder why robust says it's changed :hmmclueless * sanity is at an all-time low * serialization, I guess * I don't believe you * field deltas on class \w*satiation\w*components * PR comments * 我做泥團子 😔 * doc + kill one property that's trivially accessible after the threshold caching changes * fixes --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com> Co-authored-by: AJCM-git <ajcm_mail@disroot.org>
133 lines
5.2 KiB
C#
133 lines
5.2 KiB
C#
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.Dataset;
|
|
using Content.Shared.Nutrition.Components;
|
|
using Content.Shared.Nutrition.EntitySystems;
|
|
using Content.Shared.Nutrition.Prototypes;
|
|
using Content.Shared.Pointing;
|
|
using Content.Shared.Random.Helpers;
|
|
using Content.Shared.RatKing;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Prototypes;
|
|
using Content.Shared.Chat;
|
|
|
|
namespace Content.Server.RatKing
|
|
{
|
|
/// <inheritdoc/>
|
|
public sealed partial class RatKingSystem : SharedRatKingSystem
|
|
{
|
|
[Dependency] private AtmosphereSystem _atmos = default!;
|
|
[Dependency] private ChatSystem _chat = default!;
|
|
[Dependency] private HTNSystem _htn = default!;
|
|
[Dependency] private SatiationSystem _satiation = default!;
|
|
[Dependency] private NPCSystem _npc = default!;
|
|
[Dependency] private 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<SatiationComponent>(uid, out var satiation))
|
|
return;
|
|
|
|
//make sure the hunger doesn't go into the negatives
|
|
if (_satiation.GetValueOrNull((uid, satiation), SatiationSystem.Hunger) < component.HungerPerArmyUse)
|
|
{
|
|
_popup.PopupEntity(Loc.GetString("rat-king-too-hungry"), uid, uid);
|
|
return;
|
|
}
|
|
args.Handled = true;
|
|
_satiation.ModifyValue((uid, satiation), SatiationSystem.Hunger, -component.HungerPerArmyUse);
|
|
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<SatiationComponent>(uid, out var satiation))
|
|
return;
|
|
|
|
//make sure the hunger doesn't go into the negatives
|
|
if (_satiation.GetValueOrNull((uid, satiation), SatiationSystem.Hunger) < component.HungerPerDomainUse)
|
|
{
|
|
_popup.PopupEntity(Loc.GetString("rat-king-too-hungry"), uid, uid);
|
|
return;
|
|
}
|
|
args.Handled = true;
|
|
_satiation.ModifyValue((uid, satiation), SatiationSystem.Hunger, -component.HungerPerDomainUse);
|
|
|
|
_popup.PopupEntity(Loc.GetString("rat-king-domain-popup"), uid);
|
|
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) ||
|
|
!ProtoMan.TryIndex<LocalizedDatasetPrototype>(datasetId, out var datasetPrototype))
|
|
return;
|
|
|
|
var msg = Random.Pick(datasetPrototype);
|
|
_chat.TrySendInGameICMessage(uid, msg, InGameICChatType.Speak, true);
|
|
}
|
|
}
|
|
}
|