Added a component to eat bodies for health #8922 (#16345)

This commit is contained in:
PilgrimViis
2023-05-16 00:44:35 +02:00
committed by GitHub
parent 4d66f817b8
commit 832ba7b6f3
8 changed files with 248 additions and 161 deletions

View File

@@ -59,12 +59,9 @@ namespace Content.Server.Dragon
SubscribeLocalEvent<DragonComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<DragonComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<DragonComponent, DragonDevourActionEvent>(OnDevourAction);
SubscribeLocalEvent<DragonComponent, DragonSpawnRiftActionEvent>(OnDragonRift);
SubscribeLocalEvent<DragonComponent, RefreshMovementSpeedModifiersEvent>(OnDragonMove);
SubscribeLocalEvent<DragonComponent, DragonDevourDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<DragonComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<DragonRiftComponent, ComponentShutdown>(OnRiftShutdown);
@@ -75,29 +72,6 @@ namespace Content.Server.Dragon
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRiftRoundEnd);
}
private void OnDoAfter(EntityUid uid, DragonComponent component, DragonDevourDoAfterEvent args)
{
if (args.Handled || args.Cancelled)
return;
var ichorInjection = new Solution(component.DevourChem, component.DevourHealRate);
//Humanoid devours allow dragon to get eggs, corpses included
if (HasComp<HumanoidAppearanceComponent>(args.Args.Target))
{
ichorInjection.ScaleSolution(0.5f);
component.DragonStomach.Insert(args.Args.Target.Value);
_bloodstreamSystem.TryAddToChemicals(uid, ichorInjection);
}
//TODO: Figure out a better way of removing structures via devour that still entails standing still and waiting for a DoAfter. Somehow.
//If it's not human, it must be a structure
else if (args.Args.Target != null)
EntityManager.QueueDeleteEntity(args.Args.Target.Value);
_audioSystem.PlayPvs(component.SoundDevour, uid);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
@@ -303,8 +277,6 @@ namespace Content.Server.Dragon
if (component.SoundDeath != null)
_audioSystem.PlayPvs(component.SoundDeath, uid, component.SoundDeath.Params);
component.DragonStomach.EmptyContainer();
foreach (var rift in component.Rifts)
{
QueueDel(rift);
@@ -322,62 +294,10 @@ namespace Content.Server.Dragon
private void OnStartup(EntityUid uid, DragonComponent component, ComponentStartup args)
{
//Dragon doesn't actually chew, since he sends targets right into his stomach.
//I did it mom, I added ERP content into upstream. Legally!
component.DragonStomach = _containerSystem.EnsureContainer<Container>(uid, "dragon_stomach");
if (component.DevourAction != null)
_actionsSystem.AddAction(uid, component.DevourAction, null);
if (component.SpawnRiftAction != null)
_actionsSystem.AddAction(uid, component.SpawnRiftAction, null);
Roar(component);
}
/// <summary>
/// The devour action
/// </summary>
private void OnDevourAction(EntityUid uid, DragonComponent component, DragonDevourActionEvent args)
{
if (args.Handled || component.DevourWhitelist?.IsValid(args.Target, EntityManager) != true)
return;
args.Handled = true;
var target = args.Target;
// Structure and mob devours handled differently.
if (EntityManager.TryGetComponent(target, out MobStateComponent? targetState))
{
switch (targetState.CurrentState)
{
case MobState.Critical:
case MobState.Dead:
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(uid, component.DevourTime, new DragonDevourDoAfterEvent(), uid, target: target, used: uid)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
});
break;
default:
_popupSystem.PopupEntity(Loc.GetString("devour-action-popup-message-fail-target-alive"), uid, uid);
break;
}
return;
}
_popupSystem.PopupEntity(Loc.GetString("devour-action-popup-message-structure"), uid, uid);
if (component.SoundStructureDevour != null)
_audioSystem.PlayPvs(component.SoundStructureDevour, uid, component.SoundStructureDevour.Params);
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(uid, component.StructureDevourTime, new DragonDevourDoAfterEvent(), uid, target: target, used: uid)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
});
}
}
}