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
|
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
public CViewStats() : base("stats", Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_VIEW_DESC"], "xlrstats", Player.Permission.User, false, new CommandArgument[]
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
|
|
|
|
new CommandArgument()
|
|
|
|
|
{
|
|
|
|
|
Name = "player",
|
|
|
|
|
Required = false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
{ }
|
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
public override async Task ExecuteAsync(GameEvent E)
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
2018-04-24 18:01:27 -04:00
|
|
|
|
|
2018-02-10 01:26:38 -05:00
|
|
|
|
String statLine;
|
|
|
|
|
EFClientStatistics pStats;
|
|
|
|
|
|
|
|
|
|
if (E.Data.Length > 0 && E.Target == null)
|
|
|
|
|
{
|
2018-06-05 17:31:36 -04:00
|
|
|
|
E.Target = E.Owner.GetClientByName(E.Data).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (E.Target == null)
|
|
|
|
|
{
|
|
|
|
|
await E.Origin.Tell(loc["PLUGINS_STATS_COMMANDS_VIEW_FAIL"]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-06-05 17:31:36 -04:00
|
|
|
|
|
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-05-17 19:31:58 -04:00
|
|
|
|
statLine = $"^5{pStats.Kills} ^7{loc["PLUGINS_STATS_TEXT_KILLS"]} | ^5{pStats.Deaths} ^7{loc["PLUGINS_STATS_TEXT_DEATHS"]} | ^5{pStats.KDR} ^7KDR | ^5{pStats.Performance} ^7{loc["PLUGINS_STATS_COMMANDS_PERFORMANCE"].ToUpper()}";
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-02-15 23:01:28 -05:00
|
|
|
|
pStats = pStats = clientStats.Find(c => c.ServerId == serverId && c.ClientId == E.Origin.ClientId).First();
|
2018-05-17 19:31:58 -04:00
|
|
|
|
statLine = $"^5{pStats.Kills} ^7{loc["PLUGINS_STATS_TEXT_KILLS"]} | ^5{pStats.Deaths} ^7{loc["PLUGINS_STATS_TEXT_DEATHS"]} | ^5{pStats.KDR} ^7KDR | ^5{pStats.Performance} ^7{loc["PLUGINS_STATS_COMMANDS_PERFORMANCE"].ToUpper()}";
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Message.IsBroadcastCommand())
|
|
|
|
|
{
|
|
|
|
|
string name = E.Target == null ? E.Origin.Name : E.Target.Name;
|
2018-04-24 18:01:27 -04:00
|
|
|
|
await E.Owner.Broadcast($"{loc["PLUGINS_STATS_COMMANDS_VIEW_SUCCESS"]} ^5{name}^7");
|
2018-02-10 01:26:38 -05:00
|
|
|
|
await E.Owner.Broadcast(statLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (E.Target != null)
|
2018-04-24 18:01:27 -04:00
|
|
|
|
await E.Origin.Tell($"{loc["PLUGINS_STATS_COMMANDS_VIEW_SUCCESS"]} ^5{E.Target.Name}^7");
|
2018-02-10 01:26:38 -05:00
|
|
|
|
await E.Origin.Tell(statLine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|