hanf vielleicht fertig

This commit is contained in:
hydrant
2021-05-27 21:06:20 +02:00
parent 211269d03a
commit 60f55e0eeb
20 changed files with 2996 additions and 56 deletions

View File

@@ -5,12 +5,16 @@ 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
public class Joint : UseItem, IIllegalItem
{
private static Dictionary<int, DateTime> lastJointUse = new Dictionary<int, DateTime>();
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";
@@ -21,10 +25,33 @@ namespace ReallifeGamemode.Server.Inventory.Items
public override bool Legal => false;
public override bool RemoveWhenUsed => true;
public int PriceForConfiscation { get; } = 25;
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;
}
}
}