Files
wwdpublic/Content.Server/Revenant/EntitySystems/RevenantSystem.Abilities.cs
sleepyyapril 885ee5a831 Wizmerge for Station AI (#1351)
<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

the adding AI is now up to y'all because i'm not touching loadout code
for name datasets, but it shouldn't be too bad from here

---------

Signed-off-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com>
Signed-off-by: SolStar <44028047+ewokswagger@users.noreply.github.com>
Signed-off-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
Co-authored-by: themias <89101928+themias@users.noreply.github.com>
Co-authored-by: Verm <32827189+Vermidia@users.noreply.github.com>
Co-authored-by: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Co-authored-by: Sphiral <145869023+SphiraI@users.noreply.github.com>
Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com>
Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Co-authored-by: Alzore <140123969+Blackern5000@users.noreply.github.com>
Co-authored-by: ravage <142820619+ravage123321@users.noreply.github.com>
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Co-authored-by: Intoxicating-Innocence <188202277+Intoxicating-Innocence@users.noreply.github.com>
Co-authored-by: Saphire <lattice@saphi.re>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: Errant <35878406+Errant-4@users.noreply.github.com>
Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
Co-authored-by: CaasGit <87243814+CaasGit@users.noreply.github.com>
Co-authored-by: BramvanZijp <56019239+BramvanZijp@users.noreply.github.com>
Co-authored-by: Boaz1111 <149967078+Boaz1111@users.noreply.github.com>
Co-authored-by: NakataRin <45946146+NakataRin@users.noreply.github.com>
Co-authored-by: Kara <lunarautomaton6@gmail.com>
Co-authored-by: Plykiya <58439124+Plykiya@users.noreply.github.com>
Co-authored-by: SlamBamActionman <slambamactionman@gmail.com>
Co-authored-by: Doomsdrayk <robotdoughnut@comcast.net>
Co-authored-by: Brandon Hu <103440971+Brandon-Huu@users.noreply.github.com>
Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
Co-authored-by: Julian Giebel <juliangiebel@live.de>
Co-authored-by: nikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com>
Co-authored-by: Repo <47093363+Titian3@users.noreply.github.com>
Co-authored-by: Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com>
Co-authored-by: icekot8 <93311212+icekot8@users.noreply.github.com>
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Co-authored-by: no <165581243+pissdemon@users.noreply.github.com>
Co-authored-by: Tornado Tech <54727692+Tornado-Technology@users.noreply.github.com>
Co-authored-by: osjarw <62134478+osjarw@users.noreply.github.com>
Co-authored-by: Simon <63975668+Simyon264@users.noreply.github.com>
Co-authored-by: TGRCDev <tgrc@tgrc.dev>
Co-authored-by: Milon <milonpl.git@proton.me>
Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Co-authored-by: Fildrance <fildrance@gmail.com>
Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
Co-authored-by: chavonadelal <156101927+chavonadelal@users.noreply.github.com>
Co-authored-by: SolStar <44028047+ewokswagger@users.noreply.github.com>
Co-authored-by: K-Dynamic <20566341+K-Dynamic@users.noreply.github.com>
Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com>
Co-authored-by: ArchRBX <5040911+ArchRBX@users.noreply.github.com>
Co-authored-by: archrbx <punk.gear5260@fastmail.com>
Co-authored-by: Radezolid <snappednexus@gmail.com>
Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
Co-authored-by: EmoGarbage404 <retron404@gmail.com>
Co-authored-by: MilenVolf <63782763+MilenVolf@users.noreply.github.com>
Co-authored-by: Velcroboy <107660393+IamVelcroboy@users.noreply.github.com>
Co-authored-by: Velcroboy <velcroboy333@hotmail.com>
Co-authored-by: neuPanda <chriseparton@gmail.com>
Co-authored-by: neuPanda <spainman0@yahoo.com>
Co-authored-by: Dvir <39403717+dvir001@users.noreply.github.com>
Co-authored-by: Whatstone <whatston3@gmail.com>
Co-authored-by: VideoKompany <135313844+VlaDOS1408@users.noreply.github.com>

(cherry picked from commit 93ed70acfeda357133a701f637d3faeec02749bb)
2025-01-14 00:13:42 +03:00

344 lines
12 KiB
C#

using Content.Shared.Popups;
using Content.Shared.Damage;
using Content.Shared.Revenant;
using Robust.Shared.Random;
using Content.Shared.Tag;
using Content.Server.Storage.Components;
using Content.Server.Light.Components;
using Content.Server.Ghost;
using Robust.Shared.Physics;
using Content.Shared.Throwing;
using Content.Server.Storage.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Item;
using Content.Shared.Bed.Sleep;
using System.Linq;
using System.Numerics;
using Content.Server.Revenant.Components;
using Content.Shared.Physics;
using Content.Shared.DoAfter;
using Content.Shared.Emag.Systems;
using Content.Shared.FixedPoint;
using Content.Shared.Humanoid;
using Content.Shared.Maps;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Revenant.Components;
using Robust.Shared.Physics.Components;
using Robust.Shared.Utility;
using Robust.Shared.Map.Components;
using Content.Shared.Whitelist;
namespace Content.Server.Revenant.EntitySystems;
public sealed partial class RevenantSystem
{
[Dependency] private readonly ThrowingSystem _throwing = default!;
[Dependency] private readonly EntityStorageSystem _entityStorage = default!;
[Dependency] private readonly EmagSystem _emag = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
[Dependency] private readonly GhostSystem _ghost = default!;
[Dependency] private readonly TileSystem _tile = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
private void InitializeAbilities()
{
SubscribeLocalEvent<RevenantComponent, UserActivateInWorldEvent>(OnInteract);
SubscribeLocalEvent<RevenantComponent, SoulEvent>(OnSoulSearch);
SubscribeLocalEvent<RevenantComponent, HarvestEvent>(OnHarvest);
SubscribeLocalEvent<RevenantComponent, RevenantDefileActionEvent>(OnDefileAction);
SubscribeLocalEvent<RevenantComponent, RevenantOverloadLightsActionEvent>(OnOverloadLightsAction);
SubscribeLocalEvent<RevenantComponent, RevenantBlightActionEvent>(OnBlightAction);
SubscribeLocalEvent<RevenantComponent, RevenantMalfunctionActionEvent>(OnMalfunctionAction);
}
private void OnInteract(EntityUid uid, RevenantComponent component, UserActivateInWorldEvent args)
{
if (args.Handled)
return;
if (args.Target == args.User)
return;
var target = args.Target;
if (HasComp<PoweredLightComponent>(target))
{
args.Handled = _ghost.DoGhostBooEvent(target);
return;
}
if (!HasComp<MobStateComponent>(target) || !HasComp<HumanoidAppearanceComponent>(target) || HasComp<RevenantComponent>(target))
return;
args.Handled = true;
if (!TryComp<EssenceComponent>(target, out var essence) || !essence.SearchComplete)
{
EnsureComp<EssenceComponent>(target);
BeginSoulSearchDoAfter(uid, target, component);
}
else
{
BeginHarvestDoAfter(uid, target, component, essence);
}
args.Handled = true;
}
private void BeginSoulSearchDoAfter(EntityUid uid, EntityUid target, RevenantComponent revenant)
{
var searchDoAfter = new DoAfterArgs(EntityManager, uid, revenant.SoulSearchDuration, new SoulEvent(), uid, target: target)
{
BreakOnMove = true,
BreakOnDamage = true,
DistanceThreshold = 2
};
if (!_doAfter.TryStartDoAfter(searchDoAfter))
return;
_popup.PopupEntity(Loc.GetString("revenant-soul-searching", ("target", target)), uid, uid, PopupType.Medium);
}
private void OnSoulSearch(EntityUid uid, RevenantComponent component, SoulEvent args)
{
if (args.Handled || args.Cancelled)
return;
if (!TryComp<EssenceComponent>(args.Args.Target, out var essence))
return;
essence.SearchComplete = true;
string message;
switch (essence.EssenceAmount)
{
case <= 45:
message = "revenant-soul-yield-low";
break;
case >= 90:
message = "revenant-soul-yield-high";
break;
default:
message = "revenant-soul-yield-average";
break;
}
_popup.PopupEntity(Loc.GetString(message, ("target", args.Args.Target)), args.Args.Target.Value, uid, PopupType.Medium);
args.Handled = true;
}
private void BeginHarvestDoAfter(EntityUid uid, EntityUid target, RevenantComponent revenant, EssenceComponent essence)
{
if (essence.Harvested)
{
_popup.PopupEntity(Loc.GetString("revenant-soul-harvested"), target, uid, PopupType.SmallCaution);
return;
}
if (TryComp<MobStateComponent>(target, out var mobstate) && mobstate.CurrentState == MobState.Alive && !HasComp<SleepingComponent>(target))
{
_popup.PopupEntity(Loc.GetString("revenant-soul-too-powerful"), target, uid);
return;
}
if(_physics.GetEntitiesIntersectingBody(uid, (int) CollisionGroup.Impassable).Count > 0)
{
_popup.PopupEntity(Loc.GetString("revenant-in-solid"), uid, uid);
return;
}
var doAfter = new DoAfterArgs(EntityManager, uid, revenant.HarvestDebuffs.X, new HarvestEvent(), uid, target: target)
{
DistanceThreshold = 2,
BreakOnMove = true,
BreakOnDamage = true,
RequireCanInteract = false, // stuns itself
};
if (!_doAfter.TryStartDoAfter(doAfter))
return;
_appearance.SetData(uid, RevenantVisuals.Harvesting, true);
_popup.PopupEntity(Loc.GetString("revenant-soul-begin-harvest", ("target", target)),
target, PopupType.Large);
TryUseAbility(uid, revenant, 0, revenant.HarvestDebuffs);
}
private void OnHarvest(EntityUid uid, RevenantComponent component, HarvestEvent args)
{
if (args.Cancelled)
{
_appearance.SetData(uid, RevenantVisuals.Harvesting, false);
return;
}
if (args.Handled || args.Args.Target == null)
return;
_appearance.SetData(uid, RevenantVisuals.Harvesting, false);
if (!TryComp<EssenceComponent>(args.Args.Target, out var essence))
return;
_popup.PopupEntity(Loc.GetString("revenant-soul-finish-harvest", ("target", args.Args.Target)),
args.Args.Target.Value, PopupType.LargeCaution);
essence.Harvested = true;
ChangeEssenceAmount(uid, essence.EssenceAmount, component);
_store.TryAddCurrency(new Dictionary<string, FixedPoint2>
{ {component.StolenEssenceCurrencyPrototype, essence.EssenceAmount} }, uid);
if (!HasComp<MobStateComponent>(args.Args.Target))
return;
if (_mobState.IsAlive(args.Args.Target.Value) || _mobState.IsCritical(args.Args.Target.Value))
{
_popup.PopupEntity(Loc.GetString("revenant-max-essence-increased"), uid, uid);
component.EssenceRegenCap += component.MaxEssenceUpgradeAmount;
}
//KILL THEMMMM
if (!_mobThresholdSystem.TryGetThresholdForState(args.Args.Target.Value, MobState.Dead, out var damage))
return;
DamageSpecifier dspec = new();
dspec.DamageDict.Add("Cold", damage.Value);
_damage.TryChangeDamage(args.Args.Target, dspec, true, origin: uid);
args.Handled = true;
}
private void OnDefileAction(EntityUid uid, RevenantComponent component, RevenantDefileActionEvent args)
{
if (args.Handled)
return;
if (!TryUseAbility(uid, component, component.DefileCost, component.DefileDebuffs))
return;
args.Handled = true;
//var coords = Transform(uid).Coordinates;
//var gridId = coords.GetGridUid(EntityManager);
var xform = Transform(uid);
if (!TryComp<MapGridComponent>(xform.GridUid, out var map))
return;
var tiles = map.GetTilesIntersecting(Box2.CenteredAround(xform.WorldPosition,
new Vector2(component.DefileRadius * 2, component.DefileRadius))).ToArray();
_random.Shuffle(tiles);
for (var i = 0; i < component.DefileTilePryAmount; i++)
{
if (!tiles.TryGetValue(i, out var value))
continue;
_tile.PryTile(value);
}
var lookup = _lookup.GetEntitiesInRange(uid, component.DefileRadius, LookupFlags.Approximate | LookupFlags.Static);
var tags = GetEntityQuery<TagComponent>();
var entityStorage = GetEntityQuery<EntityStorageComponent>();
var items = GetEntityQuery<ItemComponent>();
var lights = GetEntityQuery<PoweredLightComponent>();
foreach (var ent in lookup)
{
//break windows
if (tags.HasComponent(ent) && _tag.HasTag(ent, "Window"))
{
//hardcoded damage specifiers til i die.
var dspec = new DamageSpecifier();
dspec.DamageDict.Add("Structural", 60);
_damage.TryChangeDamage(ent, dspec, origin: uid);
}
if (!_random.Prob(component.DefileEffectChance))
continue;
//randomly opens some lockers and such.
if (entityStorage.TryGetComponent(ent, out var entstorecomp))
_entityStorage.OpenStorage(ent, entstorecomp);
//chucks shit
if (items.HasComponent(ent) &&
TryComp<PhysicsComponent>(ent, out var phys) && phys.BodyType != BodyType.Static)
_throwing.TryThrow(ent, _random.NextAngle().ToWorldVec());
//flicker lights
if (lights.HasComponent(ent))
_ghost.DoGhostBooEvent(ent);
}
}
private void OnOverloadLightsAction(EntityUid uid, RevenantComponent component, RevenantOverloadLightsActionEvent args)
{
if (args.Handled)
return;
if (!TryUseAbility(uid, component, component.OverloadCost, component.OverloadDebuffs))
return;
args.Handled = true;
var xform = Transform(uid);
var poweredLights = GetEntityQuery<PoweredLightComponent>();
var mobState = GetEntityQuery<MobStateComponent>();
var lookup = _lookup.GetEntitiesInRange(uid, component.OverloadRadius);
//TODO: feels like this might be a sin and a half
foreach (var ent in lookup)
{
if (!mobState.HasComponent(ent) || !_mobState.IsAlive(ent))
continue;
var nearbyLights = _lookup.GetEntitiesInRange(ent, component.OverloadZapRadius)
.Where(e => poweredLights.HasComponent(e) && !HasComp<RevenantOverloadedLightsComponent>(e) &&
_interact.InRangeUnobstructed(e, uid, -1)).ToArray();
if (!nearbyLights.Any())
continue;
//get the closest light
var allLight = nearbyLights.OrderBy(e =>
Transform(e).Coordinates.TryDistance(EntityManager, xform.Coordinates, out var dist) ? component.OverloadZapRadius : dist);
var comp = EnsureComp<RevenantOverloadedLightsComponent>(allLight.First());
comp.Target = ent; //who they gon fire at?
}
}
private void OnBlightAction(EntityUid uid, RevenantComponent component, RevenantBlightActionEvent args)
{
if (args.Handled)
return;
if (!TryUseAbility(uid, component, component.BlightCost, component.BlightDebuffs))
return;
args.Handled = true;
// TODO: When disease refactor is in.
}
private void OnMalfunctionAction(EntityUid uid, RevenantComponent component, RevenantMalfunctionActionEvent args)
{
if (args.Handled)
return;
if (!TryUseAbility(uid, component, component.MalfunctionCost, component.MalfunctionDebuffs))
return;
args.Handled = true;
foreach (var ent in _lookup.GetEntitiesInRange(uid, component.MalfunctionRadius))
{
if (_whitelistSystem.IsWhitelistFail(component.MalfunctionWhitelist, ent) ||
_whitelistSystem.IsBlacklistPass(component.MalfunctionBlacklist, ent))
continue;
_emag.DoEmagEffect(uid, ent); //it does not emag itself. adorable.
}
}
}