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

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