This is a modification from the GivePlayerEffect class that gives the nearest player a status effect. I simply took its original point, and made it apply to all players within the given distance. I also removed the immune checks, since players are normally not immune to status effects.
All credits go towards The First Sin for the original code. Click here to look at the original, and to thank him.
GivePlayersEffect.cs
Code:
#region
using System.Linq;
using wServer.realm;
using wServer.networking.svrPackets;
using wServer.realm.entities;
using wServer.realm.entities.player;
#endregion
namespace wServer.logic.behaviors
{
public class GivePlayersEffect : Behavior
{
private readonly int dist;
private readonly int duration;
private readonly ConditionEffectIndex effect;
public GivePlayersEffect(ConditionEffectIndex effect, int duration, int dist)
{
this.dist = dist;
this.effect = effect;
this.duration = duration;
}
protected override void TickCore(Entity host, RealmTime time, ref object state) { }
protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
{
if (host.GetNearestEntities(dist, null) == null) return;
foreach (Entity player in host.GetNearestEntities(dist, null))
{
string effectname = effect.ToString();
if (player.HasConditionEffect(ConditionEffectIndex.Invincible)) return;
player.ApplyConditionEffect(new ConditionEffect
{
Effect = effect,
DurationMS = duration
});
player.Owner.BroadcastPacket(new ShowEffectPacket
{
EffectType = EffectType.Trail,
TargetId = host.Id,
PosA = new Position { X = player.X, Y = player.Y },
Color = new ARGB(0xffff0000)
}, null);
player.Owner.BroadcastPacket(new ShowEffectPacket
{
EffectType = EffectType.Potion,
TargetId = player.Id,
Color = new ARGB(0xffff0000)
}, null);
player.Owner.BroadcastPacket(new NotificationPacket
{
ObjectId = player.Id,
Color = new ARGB(0xffff0000),
Text = "{"key":"blank","tokens":{"data":"" + effectname + ""}}"
}, null);
}
}
}
}