hanf vielleicht fertig
This commit is contained in:
11
ReallifeGamemode.Server/Inventory/Interfaces/IIllegalItem.cs
Normal file
11
ReallifeGamemode.Server/Inventory/Interfaces/IIllegalItem.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Interfaces
|
||||
{
|
||||
interface IIllegalItem : IItem
|
||||
{
|
||||
int PriceForConfiscation { get; }
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using ReallifeGamemode.Server.Inventory.Interfaces;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Items
|
||||
{
|
||||
public class Cannabis : DropItem
|
||||
public class Cannabis : DropItem, IIllegalItem
|
||||
{
|
||||
public override int Id => 108;
|
||||
|
||||
@@ -24,5 +24,9 @@ namespace ReallifeGamemode.Server.Inventory.Items
|
||||
public override uint Object => 3076948544;
|
||||
|
||||
public override int Price => 0;
|
||||
|
||||
public override bool Legal => false;
|
||||
|
||||
public int PriceForConfiscation { get; } = 5;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@ using GTANetworkAPI;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using ReallifeGamemode.Server.Inventory.Interfaces;
|
||||
using ReallifeGamemode.Server.Managers;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Items
|
||||
{
|
||||
public class CannabisSeeds : UseItem
|
||||
public class CannabisSeeds : UseItem, IIllegalItem
|
||||
{
|
||||
public override int Id { get; } = 109;
|
||||
public override string Name { get; } = "Cannabis Samen";
|
||||
@@ -21,14 +22,15 @@ namespace ReallifeGamemode.Server.Inventory.Items
|
||||
|
||||
public override uint Object { get; }
|
||||
public override bool RemoveWhenUsed { get; } = false;
|
||||
public int PriceForConfiscation { get; } = 10;
|
||||
|
||||
public override bool Use(Player player, User user, DatabaseContext databaseContext)
|
||||
{
|
||||
if(!player.IsInVehicle)
|
||||
if (!player.IsInVehicle)
|
||||
{
|
||||
HanfManager.StartCannabisPlanting(player);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user