fix CyberneticHearingAid being broken after game update

This commit is contained in:
Lilian Jónsdóttir 2024-06-16 17:57:37 -07:00
parent 4d6351f7a8
commit 7f92ebb169
2 changed files with 130 additions and 158 deletions

View file

@ -2,6 +2,7 @@ using System;
using XRL.UI; using XRL.UI;
using XRL.World.Capabilities; using XRL.World.Capabilities;
using XRL.World.Parts; using XRL.World.Parts;
using XRL.World.Parts.Mutation;
// this is 95% copy/pasted from decompiled vanilla HeightenedHearingEffect // this is 95% copy/pasted from decompiled vanilla HeightenedHearingEffect
// only thing added was a reference to the implant because it has the part rather than the implantee // only thing added was a reference to the implant because it has the part rather than the implantee
@ -10,18 +11,12 @@ namespace XRL.World.Effects
[Serializable] [Serializable]
public class CyberneticHeightenedHearingEffect : Effect public class CyberneticHeightenedHearingEffect : Effect
{ {
public bool bIdentified; public bool Identified;
public int Level = 1; public int Level = 1;
public GameObject Listener; public GameObject Listener;
public GameObject Implant; public GameObject Implant;
public CyberneticHeightenedHearingEffect() => Duration = 1;
public CyberneticHeightenedHearingEffect(int Level, GameObject Listener) public CyberneticHeightenedHearingEffect() => this.Duration = 1;
: this()
{
this.Level = Level;
this.Listener = Listener;
}
public CyberneticHeightenedHearingEffect(int Level, GameObject Listener, GameObject Implant) public CyberneticHeightenedHearingEffect(int Level, GameObject Listener, GameObject Implant)
: this() : this()
@ -37,78 +32,65 @@ namespace XRL.World.Effects
public override string GetDescription() => (string)null; public override string GetDescription() => (string)null;
public override bool WantEvent(int ID, int cascade) => base.WantEvent(ID, cascade) || ID == SingletonEvent<EndTurnEvent>.ID || ID == EnteringCellEvent.ID;
public override bool HandleEvent(AfterPlayerBodyChangeEvent E)
{
this.CheckListen();
return base.HandleEvent(E);
}
public override bool HandleEvent(EndTurnEvent E)
{
this.CheckListen();
return base.HandleEvent(E);
}
public override bool HandleEvent(EnteringCellEvent E)
{
this.CheckListen();
return base.HandleEvent(E);
}
private bool BadListener() private bool BadListener()
{ {
Listener = null; this.Listener = (GameObject)null;
Object.RemoveEffect(this); this.Object?.RemoveEffect((Effect)this);
return true; return true;
} }
public bool CheckListen() public bool CheckListen()
{ {
if (!GameObject.validate(ref Listener) || !Listener.IsPlayer()) if (!GameObject.Validate(this.Object))
{
return BadListener();
}
if (!(Implant.GetPart("CyberneticsHearingAid") is CyberneticsHearingAid part))
{
return BadListener();
}
int num = Object.DistanceTo(Listener);
if (num > part.Radius)
{
return BadListener();
}
if (bIdentified)
{
CheckInterruptAutoExplore();
return true; return true;
} if (!GameObject.Validate(ref this.Listener) || !this.Listener.IsPlayer())
return this.BadListener();
if (Object.CurrentCell == null) CyberneticsHearingAid part = this.Listener.GetPart<CyberneticsHearingAid>();
{ if (part == null || part.Level <= 0)
return this.BadListener();
if (!(Implant.GetPart("CyberneticsHearingAid") is CyberneticsHearingAid otherpart))
return this.BadListener();
int num = this.Object.DistanceTo(this.Listener);
if (num > part.GetRadius())
return this.BadListener();
if (this.Identified || this.Object.CurrentCell == null)
return true; return true;
} if (((int)((double)(100 + 10 * this.Level) / Math.Pow((double)(num + 9), 2.0) * 100.0)).in100())
if (((int)((100 + (10 * Level)) / Math.Pow(num + 9, 2.0) * 100.0)).in100())
{ {
bIdentified = true; this.Identified = true;
CheckInterruptAutoExplore(); if (this.Listener.IsPlayer())
AutoAct.CheckHostileInterrupt();
} }
return false; return false;
} }
public void CheckInterruptAutoExplore()
{
if (!bIdentified || !GameObject.validate(ref Listener) || !Listener.IsPlayer() || !AutoAct.IsInterruptable() || AutoAct.IsGathering() || !Listener.IsRelevantHostile(Object))
return;
AddPlayerMessage(Listener.GenerateSpotMessage(Object, verb: "hear"));
AutoAct.Interrupt(null, null, Object);
}
public override bool Apply(GameObject Object) public override bool Apply(GameObject Object)
{ {
if (Object.pBrain != null) this.CheckListen();
Object.pBrain.Hibernating = false;
CheckListen();
return true; return true;
} }
public override void Register(GameObject Object) public override void RegisterActive(GameObject Object, IEventRegistrar Registrar) => Registrar.Register((IEventSource)The.Game, (IEventHandler)this, PooledEvent<AfterPlayerBodyChangeEvent>.ID);
{
Object.RegisterEffectEvent(this, "EndTurn");
base.Register(Object);
}
public override void Unregister(GameObject Object)
{
Object.UnregisterEffectEvent(this, "EndTurn");
base.Unregister(Object);
}
public bool HeardAndNotSeen(GameObject obj) public bool HeardAndNotSeen(GameObject obj)
{ {
@ -122,36 +104,24 @@ namespace XRL.World.Effects
public override bool FinalRender(RenderEvent E, bool bAlt) public override bool FinalRender(RenderEvent E, bool bAlt)
{ {
if (!HeardAndNotSeen(Object) || !Object.CanHypersensesDetect()) if (!this.HeardAndNotSeen(this.Object) || !this.Object.CanHypersensesDetect())
{
return true; return true;
} E.Tile = (string)null;
if (this.Identified)
if (bIdentified)
{ {
E.HighestLayer = 0; E.HighestLayer = 0;
Object.Render(E); E.NoWake = true;
E.ColorString = "&K"; this.Object.ComponentRender(E);
E.DetailColor = "K"; E.RenderString = this.Object.Render.RenderString;
E.RenderString = Object.pRender.RenderString; if (Options.UseTiles)
E.Tile = !Options.UseTiles ? null : Object.pRender.Tile; E.Tile = this.Object.Render.Tile;
E.CustomDraw = true;
} }
else else
{ E.RenderString = "?";
E.RenderString = "&K?"; E.ColorString = "&K";
E.Tile = null; E.DetailColor = "K";
E.CustomDraw = true; E.CustomDraw = true;
}
return false; return false;
} }
public override bool FireEvent(Event E)
{
if (E.ID == "EndTurn" && Object != null)
CheckListen();
return base.FireEvent(E);
}
} }
} }

View file

@ -16,7 +16,9 @@ namespace XRL.World.Parts
get { return GetAvailableComputePowerEvent.GetFor(ParentObject.Implantee) + 1; } get { return GetAvailableComputePowerEvent.GetFor(ParentObject.Implantee) + 1; }
} }
public override bool SameAs(IPart p) => false; public static int GetRadius(int Level) => Level < 10 ? 3 + Level * 2 : 40;
public int GetRadius() => CyberneticsHearingAid.GetRadius(this.Level);
public override bool WantEvent(int ID, int cascade) => base.WantEvent(ID, cascade) || ID == EndTurnEvent.ID || ID == GetShortDescriptionEvent.ID; public override bool WantEvent(int ID, int cascade) => base.WantEvent(ID, cascade) || ID == EndTurnEvent.ID || ID == GetShortDescriptionEvent.ID;