2018-04-08 17:50:58 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
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-10-07 22:34:30 -04:00
|
|
|
|
using SharedLibraryCore.Database;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2018-10-15 20:51:04 -04:00
|
|
|
|
using IW4MAdmin.Plugins.Stats.Helpers;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
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-11-05 22:01:29 -05:00
|
|
|
|
public CViewStats() : base("stats", Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_VIEW_DESC"], "xlrstats", EFClient.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)
|
|
|
|
|
{
|
2018-09-29 15:52:22 -04:00
|
|
|
|
E.Origin.Tell(loc["PLUGINS_STATS_COMMANDS_VIEW_FAIL"]);
|
2018-06-05 17:31:36 -04:00
|
|
|
|
}
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-23 19:34:31 -04:00
|
|
|
|
long serverId = StatManager.GetIdForServer(E.Owner);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
2018-10-07 22:34:30 -04:00
|
|
|
|
using (var ctx = new DatabaseContext(disableTracking: true))
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
2018-10-07 22:34:30 -04:00
|
|
|
|
if (E.Target != null)
|
|
|
|
|
{
|
2018-10-15 20:51:04 -04:00
|
|
|
|
int performanceRanking = await StatManager.GetClientOverallRanking(E.Target.ClientId);
|
|
|
|
|
string performanceRankingString = performanceRanking == 0 ? loc["WEBFRONT_STATS_INDEX_UNRANKED"] : $"{loc["WEBFRONT_STATS_INDEX_RANKED"]} #{performanceRanking}";
|
|
|
|
|
|
2018-10-07 22:34:30 -04:00
|
|
|
|
pStats = (await ctx.Set<EFClientStatistics>().FirstAsync(c => c.ServerId == serverId && c.ClientId == E.Target.ClientId));
|
2018-10-15 20:51:04 -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()} | {performanceRankingString}";
|
2018-10-07 22:34:30 -04:00
|
|
|
|
}
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
2018-10-07 22:34:30 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
2018-10-15 20:51:04 -04:00
|
|
|
|
int performanceRanking = await StatManager.GetClientOverallRanking(E.Origin.ClientId);
|
|
|
|
|
string performanceRankingString = performanceRanking == 0 ? loc["WEBFRONT_STATS_INDEX_UNRANKED"] : $"{loc["WEBFRONT_STATS_INDEX_RANKED"]} #{performanceRanking}";
|
|
|
|
|
|
2018-10-07 22:34:30 -04:00
|
|
|
|
pStats = (await ctx.Set<EFClientStatistics>().FirstAsync((c => c.ServerId == serverId && c.ClientId == E.Origin.ClientId)));
|
2018-10-15 20:51:04 -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()} | {performanceRankingString}";
|
2018-10-07 22:34:30 -04:00
|
|
|
|
}
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Message.IsBroadcastCommand())
|
|
|
|
|
{
|
|
|
|
|
string name = E.Target == null ? E.Origin.Name : E.Target.Name;
|
2019-04-09 16:02:49 -04:00
|
|
|
|
E.Owner.Broadcast(loc["PLUGINS_STATS_COMMANDS_VIEW_SUCCESS"].FormatExt(name));
|
2018-09-29 15:52:22 -04:00
|
|
|
|
E.Owner.Broadcast(statLine);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (E.Target != null)
|
2018-09-29 15:52:22 -04:00
|
|
|
|
{
|
2019-04-09 16:02:49 -04:00
|
|
|
|
E.Origin.Tell(loc["PLUGINS_STATS_COMMANDS_VIEW_SUCCESS"].FormatExt(E.Target.Name));
|
2018-09-29 15:52:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
E.Origin.Tell(statLine);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|