* vampire returns + transformstions redo * carcat fangs fix + greetings music update * vampire skill trees * Blood essence gathering Introduces the vampire blood essence mechanic, including the CP14SpellVampireGatherEssence spell, new skill point consumable component, and related UI/localization updates. Adds clientside effects for spell casting, new vampire skill and action, and refines skill point gain/loss popups. Also restructures vampire components, updates spell logic for client/server prediction, and removes unused parallax files. * perma damage * Add skill point cost to magic system and vampire essence spell Introduced CP14MagicEffectSkillPointCostComponent to allow magic effects to consume skill points. Updated the shared magic system to handle skill point checks and consumption. Added a new vampire spell for creating blood essence, including new icons and localization. Adjusted vampire component to grant and remove skill points, and updated related skill tree and spell prototypes. Minor fixes and refactoring in spell logic and descriptions. * blood step + blood vision skills * vampire clans icons * 50 players limit + vampire objectives * fixes * devourers altar transmutation * Remove StealTarget component from animal, dino, and mole NPCs The StealTarget component and associated stealGroup were removed from boar, dinosaur, and mole NPC definitions. This likely disables these entities from being targeted for stealing, possibly to adjust gameplay balance or fix unintended behavior. * fix * essence creation improve * altars * voice masks * transmutation fix * teleportation glyph * crimson candles * candle crafting * fix pointer predictions * Add Vampire Clan Battle gamemode and update vampire roles Introduces the 'Vampire Clan Battle' gamemode with new localization in English and Russian, updated game preset definitions, and secret weights. Refactors vampire antagonist briefings and objectives for multiple clans, adjusts vampire role preferences and team settings, and reduces the damage of the Vampire Gather Essence spell. Also includes minor improvements to spell and game mode descriptions, and corrects file naming for game preset locales. * powerful kicks in * time gates + vampire tree * vampire proto faction * fix * fixes * tree progression * search enemy * Update CP14SharedVampireSystem.cs * blood essence gathering redo * essence gathering refactor 2 * blood healing * Update secret_weights.yml * tree planting * boodgrass * tree upgrade announcement * construction graph integration * delete transmutation system * workbench crafting returns * cloaks crafting + cloak invisibility * make vampire tree is generic red tree (sad) * clan heart sprite * Refactor vampire tree to clan heart system Replaces the CP14VampireTreeComponent with CP14VampireClanHeartComponent, updating all related logic, appearance, and localization. Adjusts skill requirements, examination, and level progression to use the new clan heart system. Updates entity prototypes, visuals, and adds new orb sprites for clan heart levels. Localization strings and logic are updated to reflect the new terminology and mechanics. * Update SpeciesBlacklist.cs * Refactor vampire clan heart and remove tree spell Refactored the vampire clan heart to support essence regeneration over time and adjusted level thresholds. Removed the vampire tree planting spell and related prototype fields, as well as unused tree system code. Updated localization, entity prototypes, and faction definitions to reflect these changes. * Add clan heart construction for vampire clans Introduces construction graphs, entities, and conditions for building unique clan hearts for each vampire clan (Unnameable, Devourers, NightChildrens). Adds new construction conditions (all clan vampires required, singleton enforcement), updates skill tree to unlock constructions, and removes the now-obsolete CP14MagicEffectAllVampireClanRequiredComponent. Also adds new frame sprites and updates localization and prototype files accordingly. * level up vfx * VFX + lobby track * orb resprite * sprites * Add vampire altar mechanics and improve clan heart behavior Introduces the CP14VampireAltarComponent and altar entity, which doubles blood essence extraction when victims are strapped to the altar. Adds a custom explosion behavior for vampire clan hearts upon destruction, updates construction graphs and recipes for altars, and improves localization. Also refines skill description handling and adjusts vampire bite action text. * essence get when heart destruction * Add clan heart damage and destruction announcements Introduces announcements for when a vampire clan heart is damaged or destroyed, with cooldown to prevent spam. Refactors examination logic and updates localization files for both English and Russian to support new messages and sender formatting. * glyph adaptation * resurrection * Add round end summary for Vampire Clan Battles Implemented detailed round end text for the Vampire Clan Battles game mode, displaying victory, defeat, or draw outcomes based on surviving factions and population percentage. Refactored alive player percentage logic into a shared method and updated localization files with new outcome messages in English and Russian. Also removed an unused field from the defence condition component. * Update vampire_cloak.yml * fix * fix * Update portal_glyph.yml
279 lines
10 KiB
C#
279 lines
10 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using Content.Shared.Alert;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Content.Shared.Movement.Systems;
|
|
using Content.Shared.Nutrition.Components;
|
|
using Content.Shared.Rejuvenate;
|
|
using Content.Shared.StatusIcon;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Shared.Nutrition.EntitySystems;
|
|
|
|
public sealed class HungerSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly AlertsSystem _alerts = default!;
|
|
[Dependency] private readonly DamageableSystem _damageable = default!;
|
|
[Dependency] private readonly MobStateSystem _mobState = default!;
|
|
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;
|
|
[Dependency] private readonly SharedJetpackSystem _jetpack = default!;
|
|
|
|
private static readonly ProtoId<SatiationIconPrototype> HungerIconOverfedId = "HungerIconOverfed";
|
|
private static readonly ProtoId<SatiationIconPrototype> HungerIconPeckishId = "HungerIconPeckish";
|
|
private static readonly ProtoId<SatiationIconPrototype> HungerIconStarvingId = "HungerIconStarving";
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<HungerComponent, MapInitEvent>(OnMapInit);
|
|
SubscribeLocalEvent<HungerComponent, ComponentShutdown>(OnShutdown);
|
|
SubscribeLocalEvent<HungerComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
|
SubscribeLocalEvent<HungerComponent, RejuvenateEvent>(OnRejuvenate);
|
|
}
|
|
|
|
private void OnMapInit(EntityUid uid, HungerComponent component, MapInitEvent args)
|
|
{
|
|
var amount = _random.Next(
|
|
(int) component.Thresholds[HungerThreshold.Peckish] + 10,
|
|
(int) component.Thresholds[HungerThreshold.Okay]);
|
|
SetHunger(uid, amount, component);
|
|
}
|
|
|
|
private void OnShutdown(EntityUid uid, HungerComponent component, ComponentShutdown args)
|
|
{
|
|
_alerts.ClearAlertCategory(uid, component.HungerAlertCategory);
|
|
}
|
|
|
|
private void OnRefreshMovespeed(EntityUid uid, HungerComponent component, RefreshMovementSpeedModifiersEvent args)
|
|
{
|
|
if (component.CurrentThreshold > HungerThreshold.Starving)
|
|
return;
|
|
|
|
if (_jetpack.IsUserFlying(uid))
|
|
return;
|
|
|
|
args.ModifySpeed(component.StarvingSlowdownModifier, component.StarvingSlowdownModifier);
|
|
}
|
|
|
|
private void OnRejuvenate(EntityUid uid, HungerComponent component, RejuvenateEvent args)
|
|
{
|
|
SetHunger(uid, component.Thresholds[HungerThreshold.Okay], component);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the current hunger value of the given <see cref="HungerComponent"/>.
|
|
/// </summary>
|
|
public float GetHunger(HungerComponent component)
|
|
{
|
|
var dt = _timing.CurTime - component.LastAuthoritativeHungerChangeTime;
|
|
var value = component.LastAuthoritativeHungerValue - (float)dt.TotalSeconds * component.ActualDecayRate;
|
|
return ClampHungerWithinThresholds(component, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds to the current hunger of an entity by the specified value
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="amount"></param>
|
|
/// <param name="component"></param>
|
|
public void ModifyHunger(EntityUid uid, float amount, HungerComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
SetHunger(uid, GetHunger(component) + amount, component);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the current hunger of an entity to the specified value
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="amount"></param>
|
|
/// <param name="component"></param>
|
|
public void SetHunger(EntityUid uid, float amount, HungerComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
SetAuthoritativeHungerValue((uid, component), amount);
|
|
UpdateCurrentThreshold(uid, component);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets <see cref="HungerComponent.LastAuthoritativeHungerValue"/> and
|
|
/// <see cref="HungerComponent.LastAuthoritativeHungerChangeTime"/>, and dirties this entity. This "resets" the
|
|
/// starting point for <see cref="GetHunger"/>'s calculation.
|
|
/// </summary>
|
|
/// <param name="entity">The entity whose hunger will be set.</param>
|
|
/// <param name="value">The value to set the entity's hunger to.</param>
|
|
private void SetAuthoritativeHungerValue(Entity<HungerComponent> entity, float value)
|
|
{
|
|
entity.Comp.LastAuthoritativeHungerChangeTime = _timing.CurTime;
|
|
entity.Comp.LastAuthoritativeHungerValue = ClampHungerWithinThresholds(entity.Comp, value);
|
|
DirtyField(entity.Owner, entity.Comp, nameof(HungerComponent.LastAuthoritativeHungerChangeTime));
|
|
DirtyField(entity.Owner, entity.Comp, nameof(HungerComponent.LastAuthoritativeHungerValue));
|
|
}
|
|
|
|
private void UpdateCurrentThreshold(EntityUid uid, HungerComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
var calculatedHungerThreshold = GetHungerThreshold(component);
|
|
if (calculatedHungerThreshold == component.CurrentThreshold)
|
|
return;
|
|
|
|
component.CurrentThreshold = calculatedHungerThreshold;
|
|
DirtyField(uid, component, nameof(HungerComponent.CurrentThreshold));
|
|
DoHungerThresholdEffects(uid, component);
|
|
}
|
|
|
|
private void DoHungerThresholdEffects(EntityUid uid, HungerComponent? component = null, bool force = false)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
if (component.CurrentThreshold == component.LastThreshold && !force)
|
|
return;
|
|
|
|
if (GetMovementThreshold(component.CurrentThreshold) != GetMovementThreshold(component.LastThreshold))
|
|
{
|
|
_movementSpeedModifier.RefreshMovementSpeedModifiers(uid);
|
|
}
|
|
|
|
if (component.HungerThresholdAlerts.TryGetValue(component.CurrentThreshold, out var alertId))
|
|
{
|
|
_alerts.ShowAlert(uid, alertId);
|
|
}
|
|
else
|
|
{
|
|
_alerts.ClearAlertCategory(uid, component.HungerAlertCategory);
|
|
}
|
|
|
|
if (component.HungerThresholdDecayModifiers.TryGetValue(component.CurrentThreshold, out var modifier))
|
|
{
|
|
component.ActualDecayRate = component.BaseDecayRate * modifier;
|
|
DirtyField(uid, component, nameof(HungerComponent.ActualDecayRate));
|
|
SetAuthoritativeHungerValue((uid, component), GetHunger(component));
|
|
}
|
|
|
|
component.LastThreshold = component.CurrentThreshold;
|
|
DirtyField(uid, component, nameof(HungerComponent.LastThreshold));
|
|
}
|
|
|
|
private void DoContinuousHungerEffects(EntityUid uid, HungerComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
if (component.CurrentThreshold <= HungerThreshold.Starving &&
|
|
component.StarvationDamage is { } damage &&
|
|
!_mobState.IsDead(uid))
|
|
{
|
|
_damageable.TryChangeDamage(uid, damage, true, false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the hunger threshold for an entity based on the amount of food specified.
|
|
/// If a specific amount isn't specified, just uses the current hunger of the entity
|
|
/// </summary>
|
|
/// <param name="component"></param>
|
|
/// <param name="food"></param>
|
|
/// <returns></returns>
|
|
public HungerThreshold GetHungerThreshold(HungerComponent component, float? food = null)
|
|
{
|
|
food ??= GetHunger(component);
|
|
var result = HungerThreshold.Dead;
|
|
var value = component.Thresholds[HungerThreshold.Overfed];
|
|
foreach (var threshold in component.Thresholds)
|
|
{
|
|
if (threshold.Value <= value && threshold.Value >= food)
|
|
{
|
|
result = threshold.Key;
|
|
value = threshold.Value;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// A check that returns if the entity is below a hunger threshold.
|
|
/// </summary>
|
|
public bool IsHungerBelowState(EntityUid uid, HungerThreshold threshold, float? food = null, HungerComponent? comp = null)
|
|
{
|
|
if (!Resolve(uid, ref comp))
|
|
return false; // It's never going to go hungry, so it's probably fine to assume that it's not... you know, hungry.
|
|
|
|
return GetHungerThreshold(comp, food) < threshold;
|
|
}
|
|
|
|
private bool GetMovementThreshold(HungerThreshold threshold)
|
|
{
|
|
switch (threshold)
|
|
{
|
|
case HungerThreshold.Overfed:
|
|
case HungerThreshold.Okay:
|
|
return true;
|
|
case HungerThreshold.Peckish:
|
|
case HungerThreshold.Starving:
|
|
case HungerThreshold.Dead:
|
|
return false;
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(threshold), threshold, null);
|
|
}
|
|
}
|
|
|
|
public bool TryGetStatusIconPrototype(HungerComponent component, [NotNullWhen(true)] out SatiationIconPrototype? prototype)
|
|
{
|
|
switch (component.CurrentThreshold)
|
|
{
|
|
case HungerThreshold.Overfed:
|
|
_prototype.TryIndex(HungerIconOverfedId, out prototype);
|
|
break;
|
|
case HungerThreshold.Peckish:
|
|
_prototype.TryIndex(HungerIconPeckishId, out prototype);
|
|
break;
|
|
case HungerThreshold.Starving:
|
|
_prototype.TryIndex(HungerIconStarvingId, out prototype);
|
|
break;
|
|
default:
|
|
prototype = null;
|
|
break;
|
|
}
|
|
|
|
return prototype != null;
|
|
}
|
|
|
|
private static float ClampHungerWithinThresholds(HungerComponent component, float hungerValue)
|
|
{
|
|
return Math.Clamp(hungerValue,
|
|
component.Thresholds[HungerThreshold.Dead],
|
|
component.Thresholds[HungerThreshold.Overfed]);
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
var query = EntityQueryEnumerator<HungerComponent>();
|
|
while (query.MoveNext(out var uid, out var hunger))
|
|
{
|
|
if (_timing.CurTime < hunger.NextThresholdUpdateTime)
|
|
continue;
|
|
hunger.NextThresholdUpdateTime = _timing.CurTime + hunger.ThresholdUpdateRate;
|
|
|
|
UpdateCurrentThreshold(uid, hunger);
|
|
DoContinuousHungerEffects(uid, hunger);
|
|
}
|
|
}
|
|
}
|