Hanf Changes

- 50 Plants maximal
- Pro gepflanzter Pflanze einen Samen kaufen
- Cops 5 Sekunden rausrupfen
This commit is contained in:
hydrant
2021-06-07 10:21:45 +02:00
parent 6e5577fcfb
commit 7277555de8
2 changed files with 177 additions and 21 deletions

View File

@@ -53,6 +53,7 @@ export default function animationSync() {
animationSyncData.register("manufacturJoint", "anim@mp_snowball", "pickup_snowball", 1000 * 10, false, 1, false);
//animationSyncData.register("harvestPlantEnter", "amb@world_human_gardener_plant@female@enter", "enter_female", 1000 * 3.5, false, 1, false);
animationSyncData.register("harvestPlant", "amb@world_human_gardener_plant@male@base", "base", 1000 * 10, false, 1, false, "Hanf_FinishDiggingAnimation");
animationSyncData.register("harvestPlantCop", "amb@world_human_gardener_plant@male@base", "base", 1000 * 5, false, 1, false, "Hanf_FinishDiggingAnimation");
//animationSyncData.register("harvestPlantExit", "amb@world_human_gardener_plant@female@exit", "exit_female", 1000 * 3.5, false, 1, false, "Hanf_FinishDiggingAnimation");
animationSyncData.register("jointUse", "amb@world_human_smoking_pot@male@base", "base", 1000 * 10, false, 1, false);
});

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -28,19 +28,21 @@ namespace ReallifeGamemode.Server.Managers
private readonly static List<Vector3> _cannabisSellPoints = new List<Vector3>();
/// <summary>
/// Aktueller Samen-Preis
/// Minimum Preis für Samen
/// </summary>
public static int SEED_PRICE = 0;
private const int SEED_PRICE_MIN = 175;
/// <summary>
/// Maximum Preis für Samen
/// </summary>
private const int SEED_PRICE_MAX = 225;
/// <summary>
/// Aktueller Hanf-Verkaufspreis
/// Minimum Preis für Cannabis
/// </summary>
public static int CANNABIS_PRICE = 0;
private const int CANNABIS_PRICE_MIN = 80;
/// <summary>
/// Maximum Preis für Cannabis
/// </summary>
private const int CANNABIS_PRICE_MAX = 140;
/// <summary>
@@ -48,6 +50,11 @@ namespace ReallifeGamemode.Server.Managers
/// </summary>
private const int MAX_SEEDS_PER_DAY = 50;
/// <summary>
/// Wie viele Pflanzen ein Spieler gleichzeitig anpflanen darf
/// </summary>
private const int MAX_CONCURRENT_PLANTS = 5;
/// <summary>
/// Wie viel Cannabis man für einen Joint braucht
/// </summary>
@@ -73,6 +80,11 @@ namespace ReallifeGamemode.Server.Managers
/// </summary>
private const string PLAYER_CURRENTLY_PLANTING_DATA_KEY = "isPlantingCannabis";
/// <summary>
/// Data-Key, bei welchem Hanf-NPC der Spieler grade steht
/// </summary>
private const string CURRENT_HANF_NPC_DATA_KEY = "CurrentHanfNpc";
/// <summary>
/// Ab welcher Zeit Pflanzen verwelken
/// </summary>
@@ -85,6 +97,8 @@ namespace ReallifeGamemode.Server.Managers
/// </summary>
private static Timer _manufacturerDoneTimer = new Timer(TimeSpan.FromSeconds(10).TotalMilliseconds);
public static List<HanfNpc> HanfNpcs { get; private set; } = new List<HanfNpc>();
/// <summary>
/// Zufallsgenerator für weibliche Pflanze und erhaltenes Cannabis
/// </summary>
@@ -103,12 +117,6 @@ namespace ReallifeGamemode.Server.Managers
/// </summary>
public static void Load()
{
var priceRandom = new Random();
SEED_PRICE = priceRandom.Next(SEED_PRICE_MIN, SEED_PRICE_MAX + 1);
CANNABIS_PRICE = priceRandom.Next(CANNABIS_PRICE_MIN, CANNABIS_PRICE_MAX + 1);
logger.LogInformation("Generated hanf prices: seed = {0}, cannabis = {1}", SEED_PRICE, CANNABIS_PRICE);
_seedsBuyPoints.Add(new Vector3(-30.21876, -585.3222, 17.917326));
_seedsBuyPoints.Add(new Vector3(-680.89386, -634.6783, 25.29923));
_seedsBuyPoints.Add(new Vector3(-1310.743, -608.9064, 29.382874));
@@ -117,10 +125,21 @@ namespace ReallifeGamemode.Server.Managers
ColShape colShape = null;
int npcId = 0;
foreach (Vector3 buyPoint in _seedsBuyPoints)
{
colShape = NAPI.ColShape.CreateSphereColShape(buyPoint, 10.0f);
colShape = NAPI.ColShape.CreateSphereColShape(buyPoint, 8.0f);
HanfNpcs.Add(new HanfNpc()
{
ColShape = colShape,
Position = buyPoint,
Id = ++npcId,
Type = HanfNpcType.BUY_SEEDS,
});
colShape.OnEntityEnterColShape += OnSeedBuyRangeColShapeEnter;
colShape.OnEntityEnterColShape += OnHanfNpcColShapeEnter;
colShape.OnEntityExitColShape += OnHanfNpcColShapeExit;
}
_cannabisSellPoints.Add(new Vector3(2220.04, 5614.24, 54.72));
@@ -129,10 +148,21 @@ namespace ReallifeGamemode.Server.Managers
foreach (Vector3 sellPoint in _cannabisSellPoints)
{
colShape = NAPI.ColShape.CreateSphereColShape(sellPoint, 10.0f);
colShape = NAPI.ColShape.CreateSphereColShape(sellPoint, 8.0f);
HanfNpcs.Add(new HanfNpc()
{
ColShape = colShape,
Position = sellPoint,
Id = ++npcId,
Type = HanfNpcType.SELL_CANNABIS
});
colShape.OnEntityEnterColShape += OnCannabisSellRangeColShapeEnter;
colShape.OnEntityEnterColShape += OnHanfNpcColShapeEnter;
colShape.OnEntityExitColShape += OnHanfNpcColShapeExit;
}
RegeneratePrices();
NAPI.Marker.CreateMarker(GTANetworkAPI.MarkerType.VerticalCylinder, ASSERVATENKAMMER_POSITION.Subtract(new Vector3(0, 0, 3.0)), new Vector3(), new Vector3(), 3.0f, Colors.White);
NAPI.TextLabel.CreateTextLabel("Asservatenkammer~n~Drücke ~y~E~s~, um den ~y~Riot~s~ zu entladen", ASSERVATENKAMMER_POSITION, 10.0f, 10.0f, 0, Colors.White);
@@ -145,6 +175,72 @@ namespace ReallifeGamemode.Server.Managers
updateHanfDataTimer.Start();
}
private static void RegeneratePrices()
{
foreach (HanfNpc hanfNpc in HanfNpcs)
{
hanfNpc.Price = hanfNpc.Type switch
{
HanfNpcType.BUY_SEEDS => GetRandomSeedPrice(),
HanfNpcType.SELL_CANNABIS => GetRandomCannabisPrice(),
_ => int.MaxValue
};
}
string generatedPricesStr = string.Join(", ", HanfNpcs.Select(h =>
{
return $"{h.Id} ({h.Type}) {h.Price} dollars";
}));
logger.LogInformation("Generated prices: {0}", generatedPricesStr);
}
private static HanfNpc GetHanfNpcFromColShape(ColShape colShape)
{
return HanfNpcs.Where(h => h.ColShape.Handle.Value == colShape.Handle.Value).FirstOrDefault();
}
private static HanfNpc GetHanfNpcWherePlayerIsStanding(Player client)
{
if (!client.HasData(CURRENT_HANF_NPC_DATA_KEY))
{
return null;
}
int npcId = client.GetData<int>(CURRENT_HANF_NPC_DATA_KEY);
return GetHanfNpcFromId(npcId);
}
public static HanfNpc GetHanfNpcFromId(int id)
{
return HanfNpcs.Where(h => h.Id == id).FirstOrDefault();
}
private static void OnHanfNpcColShapeExit(ColShape colShape, Player client)
{
client.ResetData(CURRENT_HANF_NPC_DATA_KEY);
}
private static void OnHanfNpcColShapeEnter(ColShape colShape, Player client)
{
HanfNpc hanfNpc = GetHanfNpcFromColShape(colShape);
if (hanfNpc != null)
{
client.SetData(CURRENT_HANF_NPC_DATA_KEY, hanfNpc.Id);
}
}
private static int GetRandomSeedPrice()
{
return _random.Next(SEED_PRICE_MIN, SEED_PRICE_MAX + 1);
}
private static int GetRandomCannabisPrice()
{
return _random.Next(CANNABIS_PRICE_MIN, CANNABIS_PRICE_MAX + 1);
}
private static void OnCannabisSellRangeColShapeEnter(ColShape colShape, Player player)
{
if (!player.IsLoggedIn())
@@ -229,6 +325,12 @@ namespace ReallifeGamemode.Server.Managers
return;
}
if (dbContext.CannabisPlants.Where(p => p.PlantedById == user.Id && !p.Harvested).Count() >= MAX_CONCURRENT_PLANTS)
{
player.SendNotification($"~r~Du kannst nur {MAX_CONCURRENT_PLANTS} Pflanzen gleichzeitig anpflanzen");
return;
}
player.SetData(PLAYER_CURRENTLY_PLANTING_DATA_KEY, true);
player.TriggerEvent("SERVER:Hanf_StartPlanting");
@@ -252,6 +354,11 @@ namespace ReallifeGamemode.Server.Managers
using var dbContext = new DatabaseContext();
var user = player.GetUser(dbContext);
if (user.CannabisSeedsBoughtToday > 0)
{
user.CannabisSeedsBoughtToday -= 1;
}
InventoryManager.RemoveUserItem(user, userCannabisSeedsItem, 1);
CannabisPlant newPlant = new CannabisPlant()
@@ -349,7 +456,14 @@ namespace ReallifeGamemode.Server.Managers
return;
}
var price = amount * SEED_PRICE;
HanfNpc hanfNpc = GetHanfNpcWherePlayerIsStanding(player);
if (hanfNpc == null)
{
player.SendNotification("~r~Du bist nicht mehr beim Dealer");
return;
}
var price = amount * hanfNpc.Price;
if (user.Handmoney < price)
{
@@ -357,7 +471,7 @@ namespace ReallifeGamemode.Server.Managers
return;
}
logger.LogInformation("Player {0} bought {1} cannabis seeds for {2} dollars (price per seed: {3})", player.Name, amount, price, SEED_PRICE); // <-- WICHTIG LOGS
logger.LogInformation("Player {0} bought {1} cannabis seeds for {2} dollars (price per seed: {3})", player.Name, amount, price, hanfNpc.Price); // <-- WICHTIG LOGS
if (user.LastTimeBoughtCannabisSeeds == null || user.LastTimeBoughtCannabisSeeds.Value.Date != DateTime.Now.Date)
{
@@ -428,6 +542,7 @@ namespace ReallifeGamemode.Server.Managers
logger.LogInformation("Player {0} harvested the cannabis plant {1} from {2}", player.Name, plant.Id, plant.PlantedBy.Name);
player.SyncAnimation("harvestPlant");
plant.Harvested = true;
bool isPlantRotten = DateTime.Now - plant.PlantDate > MAX_PLANT_TIME;
if (isPlantRotten)
{
@@ -483,7 +598,7 @@ namespace ReallifeGamemode.Server.Managers
player.SendNotification($"Du hast eine Pflanze von ~y~{plant.PlantedBy.Name}~s~ ausgegraben");
player.SyncAnimation("harvestPlant");
player.SyncAnimation("harvestPlantCop");
plant.Harvested = true;
var modelToGet = GetModelFromPlant(plant);
@@ -598,7 +713,14 @@ namespace ReallifeGamemode.Server.Managers
return;
}
player.TriggerEvent("SERVER:Hanf_BuySeed", seedsUserCanBuy, SEED_PRICE);
HanfNpc hanfNpc = GetHanfNpcWherePlayerIsStanding(player);
if (hanfNpc == null)
{
player.SendNotification("~r~Du bist nicht bei einem Dealer");
return;
}
player.TriggerEvent("SERVER:Hanf_BuySeed", seedsUserCanBuy, hanfNpc.Price);
}
internal static void PlayerSellCannabis(Player player)
@@ -626,7 +748,14 @@ namespace ReallifeGamemode.Server.Managers
return;
}
player.TriggerEvent("SERVER:Hanf_SellCannabisMenu", cannabisAmount, CANNABIS_PRICE);
HanfNpc hanfNpc = GetHanfNpcWherePlayerIsStanding(player);
if (hanfNpc == null)
{
player.SendNotification("~r~Du bist nicht bei einem Dealer");
return;
}
player.TriggerEvent("SERVER:Hanf_SellCannabisMenu", cannabisAmount, hanfNpc.Price);
}
[RemoteEvent("CLIENT:Hanf_SellCannabis")]
@@ -651,7 +780,14 @@ namespace ReallifeGamemode.Server.Managers
return;
}
var price = amount * CANNABIS_PRICE;
HanfNpc hanfNpc = GetHanfNpcWherePlayerIsStanding(player);
if (hanfNpc == null)
{
player.SendNotification("~r~Du bist nicht mehr bei einem Dealer");
return;
}
var price = amount * hanfNpc.Price;
user.Handmoney += price;
InventoryManager.RemoveUserItem(user, cannabisUserItem, amount);
dbContext.SaveChanges();
@@ -663,4 +799,23 @@ namespace ReallifeGamemode.Server.Managers
player.SendNotification($"Du hast ~g~{amount} Hanfblüten~s~ für ~g~{price.ToMoneyString()}~s~ verkauft");
}
}
public class HanfNpc
{
public int Id { get; set; }
public HanfNpcType Type { get; set; }
public int Price { get; set; }
public ColShape ColShape { get; set; }
public Vector3 Position { get; set; }
}
public enum HanfNpcType
{
BUY_SEEDS,
SELL_CANNABIS
}
}