2018-04-08 17:50:58 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Objects;
|
|
|
|
|
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 ResetStats : Command
|
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
public ResetStats() : base("resetstats", Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_RESET_DESC"], "rs", Player.Permission.User, false) { }
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
public override async Task ExecuteAsync(GameEvent E)
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
|
|
|
|
if (E.Origin.ClientNumber >= 0)
|
|
|
|
|
{
|
2018-04-08 17:50:58 -04:00
|
|
|
|
var svc = new SharedLibraryCore.Services.GenericRepository<EFClientStatistics>();
|
2018-02-26 23:24:19 -05:00
|
|
|
|
int serverId = E.Owner.GetHashCode();
|
2018-02-15 23:01:28 -05:00
|
|
|
|
var stats = svc.Find(s => s.ClientId == E.Origin.ClientId && s.ServerId == serverId).First();
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
|
|
|
|
stats.Deaths = 0;
|
|
|
|
|
stats.Kills = 0;
|
2018-04-11 18:24:21 -04:00
|
|
|
|
stats.SPM = 0.0;
|
|
|
|
|
stats.Skill = 0.0;
|
2018-04-28 01:22:18 -04:00
|
|
|
|
stats.TimePlayed = 0;
|
2018-05-17 19:31:58 -04:00
|
|
|
|
// todo: make this more dynamic
|
|
|
|
|
stats.EloRating = 200.0;
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
2018-03-06 02:22:19 -05:00
|
|
|
|
// reset the cached version
|
|
|
|
|
Plugin.Manager.ResetStats(E.Origin.ClientId, E.Owner.GetHashCode());
|
|
|
|
|
|
2018-02-10 01:26:38 -05:00
|
|
|
|
// fixme: this doesn't work properly when another context exists
|
|
|
|
|
await svc.SaveChangesAsync();
|
2018-09-29 15:52:22 -04:00
|
|
|
|
E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_RESET_SUCCESS"]);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-09-29 15:52:22 -04:00
|
|
|
|
E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_RESET_FAIL"]);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|