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