diff --git a/CyberneticHearingAid/CyberneticHeightenedHearingEffect.cs b/CyberneticHearingAid/CyberneticHeightenedHearingEffect.cs new file mode 100755 index 0000000..ece16ad --- /dev/null +++ b/CyberneticHearingAid/CyberneticHeightenedHearingEffect.cs @@ -0,0 +1,157 @@ +using System; +using XRL.UI; +using XRL.World.Capabilities; +using XRL.World.Parts; + +// 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 +namespace XRL.World.Effects +{ + [Serializable] + public class CyberneticHeightenedHearingEffect : Effect + { + public bool bIdentified; + public int Level = 1; + public GameObject Listener; + public GameObject Implant; + public CyberneticHeightenedHearingEffect() => Duration = 1; + + public CyberneticHeightenedHearingEffect(int Level, GameObject Listener) + : this() + { + this.Level = Level; + this.Listener = Listener; + } + + public CyberneticHeightenedHearingEffect(int Level, GameObject Listener, GameObject Implant) + : this() + { + this.Level = Level; + this.Listener = Listener; + this.Implant = Implant; + } + + public override int GetEffectType() => 2048; + + public override bool SameAs(Effect e) => false; + + public override string GetDescription() => (string)null; + + private bool BadListener() + { + Listener = null; + Object.RemoveEffect(this); + return true; + } + + public bool CheckListen() + { + if (!GameObject.validate(ref Listener) || !Listener.IsPlayer()) + { + 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; + } + + if (Object.CurrentCell == null) + { + return true; + } + + if (((int)((100 + (10 * Level)) / Math.Pow(num + 9, 2.0) * 100.0)).in100()) + { + bIdentified = true; + CheckInterruptAutoExplore(); + } + + 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) + { + if (Object.pBrain != null) + Object.pBrain.Hibernating = false; + CheckListen(); + return true; + } + + public override void Register(GameObject Object) + { + 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) + { + if (obj == null) + return false; + if (!obj.IsVisible()) + return true; + Cell currentCell = obj.CurrentCell; + return currentCell != null && (!currentCell.IsLit() || !currentCell.IsExplored()); + } + + public override bool FinalRender(RenderEvent E, bool bAlt) + { + 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); + } + } +} + diff --git a/CyberneticHearingAid/CyberneticsHearingAid.cs b/CyberneticHearingAid/CyberneticsHearingAid.cs new file mode 100755 index 0000000..1b76aec --- /dev/null +++ b/CyberneticHearingAid/CyberneticsHearingAid.cs @@ -0,0 +1,50 @@ +using System; + +using XRL.World.Effects; + +namespace XRL.World.Parts +{ + [Serializable] + public class CyberneticsHearingAid : IPart + { + public int Radius + { + get { return GetAvailableComputePowerEvent.GetFor(ParentObject.Implantee) + 20; } + } + public int Level + { + get { return GetAvailableComputePowerEvent.GetFor(ParentObject.Implantee) + 1; } + } + + public override bool SameAs(IPart p) => false; + + public override bool WantEvent(int ID, int cascade) => base.WantEvent(ID, cascade) || ID == EndTurnEvent.ID || ID == GetShortDescriptionEvent.ID; + + public override bool HandleEvent(EndTurnEvent E) + { + GameObject implantee = ParentObject.Implantee; + if (implantee?.IsPlayer() == true && !IsBroken() && !IsRusted() && !IsEMPed()) + { + Cell currentCell = implantee.CurrentCell; + if (currentCell?.OnWorldMap() == false) + { + foreach (var thing in currentCell.ParentZone.FastSquareSearch(currentCell.X, currentCell.Y, Radius, "Combat")) + { + if (implantee.DistanceTo(thing) <= Radius && !thing.HasEffect("CyberneticHeightenedHearingEffect")) + { + thing.ApplyEffect(new CyberneticHeightenedHearingEffect(Level, implantee, ParentObject)); + } + } + } + } + return base.HandleEvent(E); + } + + public override bool HandleEvent(GetShortDescriptionEvent E) + { + E.Postfix.AppendRules("Compute power on the local lattice increases this item's range."); + return base.HandleEvent(E); + } + public override bool AllowStaticRegistration() => false; + } +} diff --git a/CyberneticHearingAid/ObjectBlueprints.xml b/CyberneticHearingAid/ObjectBlueprints.xml new file mode 100755 index 0000000..77332b1 --- /dev/null +++ b/CyberneticHearingAid/ObjectBlueprints.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/CyberneticHearingAid/Textures/Items/hearingaid.png b/CyberneticHearingAid/Textures/Items/hearingaid.png new file mode 100755 index 0000000..f719443 Binary files /dev/null and b/CyberneticHearingAid/Textures/Items/hearingaid.png differ diff --git a/CyberneticHearingAid/manifest.json b/CyberneticHearingAid/manifest.json new file mode 100755 index 0000000..7749ee1 --- /dev/null +++ b/CyberneticHearingAid/manifest.json @@ -0,0 +1,8 @@ +{ + "id": "CyberneticHearingAid", + "title": "{{cybernetic hearing aid|Cybernetic Hearing Aid}}", + "description": "Enhanced hearing mutation but in cybernetics form.", + "version": "1.0.0", + "author": "{{paisley|Celediel}}", + "previewImage": "preview.png" +} diff --git a/CyberneticHearingAid/preview.png b/CyberneticHearingAid/preview.png new file mode 100755 index 0000000..82b674b Binary files /dev/null and b/CyberneticHearingAid/preview.png differ diff --git a/CyberneticHearingAid/workshop.json b/CyberneticHearingAid/workshop.json new file mode 100755 index 0000000..e1def31 --- /dev/null +++ b/CyberneticHearingAid/workshop.json @@ -0,0 +1,8 @@ +{ + "WorkshopId": 2721172552, + "Title": "Cybernetic Hearing Aid", + "Description": "Like the Enhanced Hearing mutation, but a cybernetic.", + "Tags": "Script,Cybernetic", + "Visibility": "0", + "ImagePath": "preview.png" +} \ No newline at end of file