bool CanRedeemKit(Player player, KitData kit) { var playerData = kitsplayerdata[player.Id]; if (playerData == null) { playerData = new PlayerData(player); storedData.KitsPlayerData.Add(playerData); } KitUsage usage = null; foreach (var used in playerData.Data.Where(used => used.Name == kit.Name)) { usage = used; } if (usage == null) { usage = new KitUsage(kit.Name); } if (kit.UsesReset > 0) { if ((DateTime.Now - DateTime.Parse(usage.LastUseDate)).TotalDays > kit.UsesReset) { usage.Uses = 0; usage.LastUse = 0; usage.LastUseDate = DateTime.Now.ToString("yyyy-MM-dd"); } } if (kit.Uses > 0 && kit.Uses <= usage.Uses) { SendMessage(player, KitOutOfUses); return(false); } if ((ulong)kit.Cooldown >= (GetTimestamp() - usage.LastUse)) { SendMessage(player, KitOnCooldown, GetTimeSpan(kit.Cooldown - (int)(GetTimestamp() - usage.LastUse))); return(false); } if (kit.Permission != null && !HasPermission(player, kit.Permission)) { SendMessage(player, KitNoPermission); return(false); } usage.Uses += 1; usage.LastUse = GetTimestamp(); playerData.Data.Remove(usage); playerData.Data.Add(usage); kitsplayerdata[player.Id] = playerData; return(true); }
void ResetKit(Player player, string[] args, bool reply = true) { if (args.Length != 1) { SendMessage(player, InvalidArgs); return; } var kitname = args[0]; KitData kit; if (!FindKit(kitname, out kit) && kitname != "*") { SendMessage(player, KitNotFound, kitname); return; } if (kitname == "*") { foreach (var playerinfo in kitsplayerdata) { playerinfo.Value.Data = new List <KitUsage>(); } SendMessage(player, AKitReset, AllKits); return; } foreach (var playerinfo in kitsplayerdata) { KitUsage usage = null; foreach (var used in playerinfo.Value.Data) { if (used.Name == kit.Name) { usage = used; } } if (usage != null) { playerinfo.Value.Data.Remove(usage); } } if (reply) { SendMessage(player, AKitReset, kitname); } }