using System; using System.Collections.Generic; using System.Text; using GTANetworkAPI; using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Models; using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Inventory.Interfaces; using ReallifeGamemode.Server.Util; namespace ReallifeGamemode.Server.Inventory.Items { public class Joint : UseItem, IIllegalItem { private static Dictionary lastJointUse = new Dictionary(); private static readonly TimeSpan _jointCooldown = TimeSpan.FromMinutes(10); public override int Id { get; } = 110; public override string Name { get; } = "Joint"; public override string Description { get; } = "stay high bis zum tod"; public override int Gewicht { get; } = 20; public override string Einheit { get; } = "g"; public override int Price { get; } = 0; public override uint Object { get; } public override bool Legal => false; public override bool RemoveWhenUsed => true; public int PriceForConfiscation { get; } = 150; public override bool Use(Player player, User user, DatabaseContext databaseContext) { if (!CanUserUseJoint(user)) { player.TriggerEvent("Error", $"Versuche es nach {-1 * (int)((DateTime.Now - lastJointUse[user.Id]) - _jointCooldown).TotalSeconds} Sekunden erneut."); return false; } player.SyncAnimation("jointUse"); player.ToggleInventory(InventoryToggleOption.HIDE); int armorToSet = Math.Min(player.Armor + 25, 100); player.SafeSetArmor(armorToSet); lastJointUse[user.Id] = DateTime.Now; return true; } private bool CanUserUseJoint(User user) { if (!lastJointUse.ContainsKey(user.Id)) { return true; } return DateTime.Now - lastJointUse[user.Id] > _jointCooldown; } } }