void PlayerDidDamage(IPlayerPropertyMonitor <uint?> pm) { PlayerStatusesGrid.Dispatcher.InvokeAsync(() => { foreach (PlayerStatus status in BlueStatuses.Concat(RedStatuses)) { if (status.GUID != pm.Player.Info.GUID) { continue; } Debug.Assert(pm.Value.HasValue); uint damage = pm.Value.Value; if (damage == 0) { status.LastDamage = 0; status.DPM = 0; status.LastDPM = 0; } else { uint delta = damage - status.LastDamage; status.DPM += delta; status.LastDamage = damage; status.LastDPM = (uint)status.DPM; } break; } }); }
private void OriginXY_ValueChanged(IPlayerPropertyMonitor <Vector> xy) { var value = xy.Value; m_Value.X = value.X; m_Value.Y = value.Y; m_PositionChanged = true; }
private void OriginZ_ValueChanged(IPlayerPropertyMonitor <double> z) { m_Value.Z = z.Value; m_PositionChanged = true; }
public Player(UserInfo info, WorldState ws, uint entityIndex) { EntityIndex = entityIndex; Info = info; World = ws; #region Property Monitors Position = new PlayerPositionPropertyMonitor(this); Team = new MultiPlayerPropertyMonitor <Team?>(this, new IPropertyMonitor <Team?>[] { new PlayerResourcePropertyMonitor <Team?>("m_iTeam", this, o => (Team)Convert.ToInt32(o)), new PlayerPropertyMonitor <Team?>("DT_BaseEntity.m_iTeamNum", this, o => (Team)Convert.ToInt32(o)) }); IsDead = new MultiPlayerPropertyMonitor <bool?>(this, new IPropertyMonitor <bool?>[] { new PlayerResourcePropertyMonitor <bool?>("m_bAlive", this, o => Convert.ToInt32(o) == 0), new PlayerPropertyMonitor <bool?>("DT_BasePlayer.m_lifeState", this, o => (LifeState)Convert.ToInt32(o) != LifeState.Alive) }); Health = new MultiPlayerPropertyMonitor <int?>(this, new IPropertyMonitor <int?>[] { new PlayerResourcePropertyMonitor <int?>("m_iHealth", this, o => Convert.ToInt32(o)), new PlayerPropertyMonitor <int?>("DT_BasePlayer.m_iHealth", this, o => Convert.ToInt32(o)), }); Class = new MultiPlayerPropertyMonitor <Class?>(this, new IPropertyMonitor <Class?>[] { new PlayerResourcePropertyMonitor <Class?>("m_iPlayerClass", this, o => (Class)Convert.ToInt32(o)), new PlayerPropertyMonitor <Class?>("DT_TFPlayerClassShared.m_iClass", this, o => (Class)Convert.ToInt32(o)) }); PlayerState = new PlayerPropertyMonitor <PlayerState?>("DT_TFPlayerShared.m_nPlayerState", this, o => (PlayerState)(uint)(o)); MaxHealth = new PlayerResourcePropertyMonitor <uint?>("m_iMaxHealth", this, o => (uint)o); MaxBuffedHealth = new PlayerResourcePropertyMonitor <uint?>("m_iMaxBuffedHealth", this, o => (uint)o); Ping = new PlayerResourcePropertyMonitor <uint?>("m_iPing", this, o => (uint)o); Score = new PlayerResourcePropertyMonitor <int?>("m_iScore", this, o => (int)o); Deaths = new PlayerResourcePropertyMonitor <int?>("m_iDeaths", this, o => (int)o); Connected = new PlayerResourcePropertyMonitor <bool?>("m_bConnected", this, o => (uint)o != 0); Damage = new PlayerResourcePropertyMonitor <uint?>("m_iDamage", this, o => (uint)o); // weapons { IPlayerPropertyMonitor <EHandle>[] array = new IPlayerPropertyMonitor <EHandle> [48]; for (int i = 0; i < 48; i++) { array[i] = new PlayerPropertyMonitor <EHandle>(string.Format("m_hMyWeapons.{0:D3}", i), this, o => new EHandle(ws, (uint)o)); } Weapons = ImmutableArray.Create(array); } #endregion World.Listeners.EntityEnteredPVS.Add(Listeners_EntityEnteredPVS); World.Listeners.EntityLeftPVS.Add(Listeners_EntityLeftPVS); if (InPVS) { Listeners_EntityEnteredPVS(Entity); } }
void UpdatePlayerStatuses(WorldState ws) { foreach (Player p in ws.Players) { Team?t = p.Team.Value; Class?c = p.Class.Value; if (!c.HasValue) { c = Class.Undefined; } IPlayerPropertyMonitor <bool?> isDead = p.IsDead; if (!isDead.Value.HasValue) { continue; } int?health = p.Health.Value; if (!health.HasValue) { continue; } uint?maxHealth = p.MaxHealth.Value; if (!maxHealth.HasValue) { continue; } IPlayerPropertyMonitor <uint?> damage = p.Damage; if (!damage.Value.HasValue) { continue; } else { damage.ValueChanged.Add(PlayerDidDamage); } PlayerStatusesGrid.Dispatcher.InvokeAsync(() => { if (t != Team.Red && t != Team.Blue) { RedStatuses.Remove(RedStatuses.SingleOrDefault(s => s.GUID == p.Info.GUID)); BlueStatuses.Remove(BlueStatuses.SingleOrDefault(s => s.GUID == p.Info.GUID)); return; } PlayerStatus status = t == Team.Red ? RedStatuses.SingleOrDefault(s => s.GUID == p.Info.GUID) : BlueStatuses.SingleOrDefault(s => s.GUID == p.Info.GUID); bool added = false; if (status == null) { status = new PlayerStatus(); status.GUID = p.Info.GUID; added = true; } status.Nickname = p.Info.Name; status.IsDead = isDead.Value.Value; status.Team = t.Value; status.Health = health.Value; status.MaxHealth = maxHealth.Value; status.DPM = Math.Max(0, status.DPM - status.LastDPM * (1.0 / (66.0 * 20.0))); status.ClassPortrait = string.Format("{0} {1} {2} alpha", t.Value, c.Value, status.IsDead ? "grey" : ""); if (added) { status.LastDamage = damage.Value.Value; if (t == Team.Red) { RedStatuses.Add(status); } else { BlueStatuses.Add(status); } } }); } RedTeamHealth.Dispatcher.InvokeAsync(() => { int health = 0; uint maxHealth = 0; foreach (PlayerStatus status in RedStatuses) { maxHealth += status.MaxOverheal; if (status.IsDead) { continue; } health += status.Health; } { double delta = maxHealth - RedTeamHealth.Maximum; RedTeamHealth.Maximum = RedTeamHealth.Maximum + delta / 32; } { double delta = health - RedTeamHealth.Value; RedTeamHealth.Value = RedTeamHealth.Value + delta / 32; } }); BlueTeamHealth.Dispatcher.InvokeAsync(() => { int health = 0; uint maxHealth = 0; foreach (PlayerStatus status in BlueStatuses) { maxHealth += status.MaxOverheal; if (status.IsDead) { continue; } health += status.Health; } { double delta = maxHealth - BlueTeamHealth.Maximum; BlueTeamHealth.Maximum = BlueTeamHealth.Maximum + delta / 32; } { double delta = health - BlueTeamHealth.Value; BlueTeamHealth.Value = BlueTeamHealth.Value + delta / 32; } }); }