Files
OldThink/Content.Server/Revenant/EntitySystems/RevenantSystem.Abilities.cs
Remuchi e2b6002076 Merge remote-tracking branch 'origin/master' into upstream
# Conflicts:
#	Content.Server/Antag/AntagSelectionSystem.cs
#	Content.Server/Changeling/ChangelingRuleSystem.cs
#	Content.Server/Changeling/ChangelingSystem.Abilities.cs
#	Content.Server/Doors/Systems/DoorSystem.cs
#	Content.Server/GameTicking/Rules/NukeopsRuleSystem.cs
#	Content.Server/GameTicking/Rules/RevolutionaryRuleSystem.cs
#	Content.Server/GameTicking/Rules/TraitorRuleSystem.cs
#	Content.Server/GameTicking/Rules/ZombieRuleSystem.cs
#	Content.Server/Holosign/HolosignSystem.cs
#	Content.Server/Revenant/EntitySystems/RevenantSystem.Abilities.cs
#	Content.Server/_White/Cult/GameRule/CultRuleComponent.cs
#	Content.Server/_White/Cult/GameRule/CultRuleSystem.cs
#	Content.Server/_White/Cult/Runes/Systems/CultSystem.Rune.cs
#	Content.Server/_White/Keyhole/KeyholeSystem.cs
#	Content.Server/_White/MeatyOre/MeatyOreStoreSystem.cs
#	Content.Shared/Projectiles/SharedProjectileSystem.cs
#	Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs
#	Content.Shared/_White/Keyhole/Components/KeyBaseComponent.cs
#	Resources/Locale/ru-RU/White/stuff.ftl/runes-entities.ftl
#	Resources/Locale/ru-RU/_white/cult/blood-spear.ftl
#	Resources/Locale/ru-RU/_white/cult/bolt-barrage.ftl
#	Resources/Locale/ru-RU/_white/cult/cult.ftl
#	Resources/Locale/ru-RU/_white/cult/gui.ftl
#	Resources/Locale/ru-RU/cult/cult-structure.ftl
#	Resources/Locale/ru-RU/cult/pylon.ftl
#	Resources/Maps/White/Scoupidia.yml
#	Resources/Maps/White/Void.yml
#	Resources/Maps/White/WonderBox.yml
#	Resources/Prototypes/Actions/types.yml
#	Resources/Prototypes/Atmospherics/gases.yml
#	Resources/Prototypes/Catalog/Cargo/cargo_atmospherics.yml
#	Resources/Prototypes/Catalog/Cargo/cargo_vending.yml
#	Resources/Prototypes/Catalog/Fills/Lockers/dressers.yml
#	Resources/Prototypes/Catalog/Fills/Lockers/heads.yml
#	Resources/Prototypes/Catalog/Fills/Lockers/misc.yml
#	Resources/Prototypes/Catalog/uplink_catalog.yml
#	Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml
#	Resources/Prototypes/Entities/Objects/Misc/subdermal_implants.yml
#	Resources/Prototypes/Entities/Objects/Tools/jaws_of_life.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Melee/sledgehammer.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Melee/sword.yml
#	Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_assembly.yml
#	Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml
#	Resources/Prototypes/Entities/Structures/Doors/Firelocks/firelock.yml
#	Resources/Prototypes/Entities/Structures/Doors/Firelocks/frame.yml
#	Resources/Prototypes/Entities/Structures/Doors/SecretDoor/secret_door.yml
#	Resources/Prototypes/Entities/Structures/Doors/Windoors/assembly.yml
#	Resources/Prototypes/Entities/Structures/Doors/Windoors/base_structurewindoors.yml
#	Resources/Prototypes/Entities/Structures/Furniture/dresser.yml
#	Resources/Prototypes/Entities/Structures/Lighting/base_lighting.yml
#	Resources/Prototypes/Entities/Structures/Power/cable_terminal.yml
#	Resources/Prototypes/Entities/Structures/Walls/grille.yml
#	Resources/Prototypes/Entities/Structures/Walls/walls.yml
#	Resources/Prototypes/Entities/Structures/stairs.yml
#	Resources/Prototypes/_White/Entities/Objects/Misc/books.yml
2024-04-13 13:59:00 +07:00

374 lines
14 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.Bible.Components;
using Content.Server.Maps;
using Content.Server.Revenant.Components;
using Content.Shared._White.Cult.Components;
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.Physics;
using Content.Shared.Revenant.Components;
using Robust.Shared.Physics.Components;
using Robust.Shared.Utility;
using Robust.Shared.Map.Components;
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!;
private void InitializeAbilities()
{
SubscribeLocalEvent<RevenantComponent, InteractNoHandEvent>(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);
SubscribeLocalEvent<RevenantComponent, DoAfterAttemptEvent<HarvestEvent>>(OnHarvestAttempt); // WD
}
// WD START
private void OnHarvestAttempt(Entity<RevenantComponent> ent, ref DoAfterAttemptEvent<HarvestEvent> args)
{
var target = args.DoAfter.Args.Target;
if (target != null && _mobState.IsAlive(target.Value) && !HasComp<SleepingComponent>(target.Value))
args.Cancel();
}
// WD END
private void OnInteract(EntityUid uid, RevenantComponent component, InteractNoHandEvent args)
{
if (args.Target == args.User || args.Target == null)
return;
var target = args.Target.Value;
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);
}
}
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;
}
// WD START
var tileref = Transform(uid).Coordinates.GetTileRef();
if (tileref != null)
{
if(_physics.GetEntitiesIntersectingBody(uid, (int) CollisionGroup.Impassable).Count > 0)
{
_popup.PopupEntity(Loc.GetString("revenant-in-solid"), uid, uid);
return;
}
}
// WD END
var doAfter = new DoAfterArgs(EntityManager, uid, revenant.HarvestDebuffs.X, new HarvestEvent(), uid, target: target)
{
DistanceThreshold = 2,
BreakOnMove = true,
BreakOnDamage = true,
RequireCanInteract = false, // stuns itself
AttemptFrequency = AttemptFrequency.EveryTick // WD EDIT
};
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.HasAnyTag(ent, "Window"))
{
//hardcoded damage specifiers til i die.
var dspec = new DamageSpecifier();
dspec.DamageDict.Add("Structural", 15);
_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;
// WD START
var cultistQuery = GetEntityQuery<CultistComponent>();
var humanoidQuery = GetEntityQuery<HumanoidAppearanceComponent>();
foreach (var e in _lookup.GetEntitiesInRange(uid, component.BlightRadius))
{
if (!humanoidQuery.HasComponent(e) || !_mobState.IsAlive(e) || cultistQuery.HasComponent(e))
continue;
var blight = EnsureComp<BlightComponent>(e);
blight.Duration = 0f;
}
// WD END
// 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 (component.MalfunctionWhitelist?.IsValid(ent, EntityManager) == false)
continue;
if (component.MalfunctionBlacklist?.IsValid(ent, EntityManager) == true)
continue;
_emag.DoEmagEffect(uid, ent); //it does not emag itself. adorable.
}
}
}