qud-mods/CyberneticHearingAid/CyberneticsHearingAid.cs

53 lines
1.6 KiB
C#

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 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 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;
}
}