qud-mods/CyberneticHearingAid/CyberneticsHearingAid.cs

51 lines
1.5 KiB
C#
Raw Normal View History

2023-12-19 01:26:05 -05:00
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;
}
}