-
Notifications
You must be signed in to change notification settings - Fork 0
/
NPlayer.cs
42 lines (37 loc) · 1.26 KB
/
NPlayer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Text;
using static War3Api.Common;
namespace NoxRaven
{
/// <summary>
/// Class for player data, might add some neat stuff here later on.
/// Extend to your needs for players in map.
/// </summary>
public class NPlayer
{
public static Dictionary<int, NPlayer> players = new Dictionary<int, NPlayer>();
/// <summary>
/// Throw-away value for <see cref="wc3agent"/>.
/// </summary>
public int id;
/// <summary>
/// Real reference to player.
/// </summary>
public player wc3agent;
public NPlayer(int id)
{
this.id = id;
wc3agent = Player(id);
players.Add(id, this);
}
public static NPlayer FromId(int id) => players[id];
public void SendMessage(string msg, float timeout, RecipientType whoGets)
{
timer msgt = CreateTimer();
TimerStart(msgt, timeout, false, () => { BlzDisplayChatMessage(wc3agent, (int)whoGets, msg); DestroyTimer(msgt); });
}
public static implicit operator player(NPlayer p) => p.wc3agent;
public static implicit operator NPlayer(player p) => FromId(GetPlayerId(p));
}
}