I'm not quite sure why this wasn't added yet, but I need it for thessal's corral bombs, so I put it together quickly.
This behavior lets a monster toss an enemy at a player instead of only at the angle and distance specified.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using wServer.realm;
using wServer.realm.entities;
using wServer.svrPackets;
namespace wServer.logic.attack
{
class TossEnemyAtPlayer : Behavior
{
float range;
short objType;
private TossEnemyAtPlayer(float range, short objType)
{
this.range = range;
this.objType = objType;
}
static readonly Dictionary<Tuple<float, short>, TossEnemyAtPlayer> instances = new Dictionary<Tuple<float, short>, TossEnemyAtPlayer>();
public static TossEnemyAtPlayer Instance(float range, short objType)
{
var key = new Tuple<float, short>(range, objType);
TossEnemyAtPlayer ret;
if (!instances.TryGetValue(key, out ret))
ret = instances[key] = new TossEnemyAtPlayer(range, objType);
return ret;
}
Random rand = new Random();
protected override bool TickCore(RealmTime time)
{
float dist = range;
Entity player = GetNearestEntity(ref dist, null);
if (player != null)
{
var chr = Host as Character;
Position target = new Position()
{
X = player.X,
Y = player.Y
};
chr.Owner.BroadcastPacket(new ShowEffectPacket()
{
EffectType = EffectType.Throw,
Color = new ARGB(0xffffbf00),
TargetId = Host.Self.Id,
PosA = target
}, null);
chr.Owner.Timers.Add(new WorldTimer(1500, (world, t) =>
{
Entity entity = Entity.Resolve(objType);
entity.Move(target.X, target.Y);
(entity as Enemy).Terrain = (chr as Enemy).Terrain;
world.EnterWorld(entity);
}));
} return true;
}
}
}
To add this, open up your solution, and navigate to wserver > logic > Attack in the solution explorer.
Right click on the attack folder > add > new item
Name it TossEnemyAtPlayer.cs, then click add
Then, just replace the entire contents of your newly created TossEnemyAtPlayer.cs with the once I posted up there.
Usage:
Code:
TossEnemyAtPlayer.Instance(RANGE, MONSTERID)
For example:
Code:
TossEnemyAtPlayer.Instance(10, 0x1702)
If the player is within the specified range (first number) it will toss the enemy. Otherwise it will do nothing. The MONSTERID is the id of the monster you want it to toss.