2018-04-08 17:50:58 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Objects;
|
|
|
|
|
using SharedLibraryCore.Services;
|
|
|
|
|
using IW4MAdmin.Plugins.Stats.Models;
|
2018-02-10 01:26:38 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2018-04-08 17:50:58 -04:00
|
|
|
|
namespace IW4MAdmin.Plugins.Stats.Commands
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
|
|
|
|
public class CViewStats : Command
|
|
|
|
|
{
|
|
|
|
|
public CViewStats() : base("stats", "view your stats", "xlrstats", Player.Permission.User, false, new CommandArgument[]
|
|
|
|
|
{
|
|
|
|
|
new CommandArgument()
|
|
|
|
|
{
|
|
|
|
|
Name = "player",
|
|
|
|
|
Required = false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
public override async Task ExecuteAsync(Event E)
|
|
|
|
|
{
|
2018-02-24 00:56:03 -05:00
|
|
|
|
if (E.Target?.ClientNumber < 0)
|
|
|
|
|
{
|
|
|
|
|
await E.Origin.Tell("The specified player must be ingame");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
2018-02-24 00:56:03 -05:00
|
|
|
|
if (E.Origin.ClientNumber < 0 && E.Target == null)
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
|
|
|
|
await E.Origin.Tell("You must be ingame to view your stats");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String statLine;
|
|
|
|
|
EFClientStatistics pStats;
|
|
|
|
|
|
|
|
|
|
if (E.Data.Length > 0 && E.Target == null)
|
|
|
|
|
{
|
|
|
|
|
await E.Origin.Tell("Cannot find the player you specified");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var clientStats = new GenericRepository<EFClientStatistics>();
|
2018-02-15 23:01:28 -05:00
|
|
|
|
int serverId = E.Owner.GetHashCode();
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
|
|
|
|
if (E.Target != null)
|
|
|
|
|
{
|
2018-02-24 00:56:03 -05:00
|
|
|
|
pStats = clientStats.Find(c => c.ServerId == serverId && c.ClientId == E.Target.ClientId).First();
|
2018-02-10 01:26:38 -05:00
|
|
|
|
statLine = String.Format("^5{0} ^7KILLS | ^5{1} ^7DEATHS | ^5{2} ^7KDR | ^5{3} ^7SKILL", pStats.Kills, pStats.Deaths, pStats.KDR, pStats.Skill);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-02-15 23:01:28 -05:00
|
|
|
|
pStats = pStats = clientStats.Find(c => c.ServerId == serverId && c.ClientId == E.Origin.ClientId).First();
|
2018-02-10 01:26:38 -05:00
|
|
|
|
statLine = String.Format("^5{0} ^7KILLS | ^5{1} ^7DEATHS | ^5{2} ^7KDR | ^5{3} ^7SKILL", pStats.Kills, pStats.Deaths, pStats.KDR, pStats.Skill);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Message.IsBroadcastCommand())
|
|
|
|
|
{
|
|
|
|
|
string name = E.Target == null ? E.Origin.Name : E.Target.Name;
|
|
|
|
|
await E.Owner.Broadcast($"Stats for ^5{name}^7");
|
|
|
|
|
await E.Owner.Broadcast(statLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (E.Target != null)
|
|
|
|
|
await E.Origin.Tell($"Stats for ^5{E.Target.Name}^7");
|
|
|
|
|
await E.Origin.Tell(statLine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|