Skip to content

Instantly share code, notes, and snippets.

@NiclasOlofsson
Last active July 13, 2017 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NiclasOlofsson/61f0caf952447d6f33e4e0d01092d663 to your computer and use it in GitHub Desktop.
Save NiclasOlofsson/61f0caf952447d6f33e4e0d01092d663 to your computer and use it in GitHub Desktop.
public class ActionHealthManager : HealthManager
{
private readonly Action<Entity> _action;
public ActionHealthManager(Entity entity, Action<Entity> action) : base(entity)
{
_action = action;
}
public override void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
{
_action?.Invoke(source);
}
public override void TakeHit(Entity source, Item tool, int damage = 1, DamageCause cause = DamageCause.Unknown)
{
_action?.Invoke(source);
}
}
public class Npc : PlayerMob
{
private static readonly ILog Log = LogManager.GetLogger(typeof (Npc));
private readonly GameType _gameType;
public Npc(string name, Level level, GameManager gameManager, string gameType) : this(name, level, gameManager, (GameType) Enum.Parse(typeof (GameType), gameType, true))
{
}
public Npc(string name, Level level, GameManager gameManager, GameType gameType) : base(name, level)
{
_gameType = gameType;
Skin = new Skin {Slim = false, Texture = Encoding.Default.GetBytes(new string('Z', 8192))};
HealthManager = new ActionHealthManager(this, (source) =>
{
GamePlayer p = source as GamePlayer;
if (p == null) return;
p.SendMessage($"§eFinding you a game of §b{gameType}§e...");
Task.Run(() => { gameManager.TransferToGame(p, _gameType); });
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment