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

@@ -21,6 +21,8 @@ using ReallifeGamemode.Server.Types;
using ReallifeGamemode.Server.Util;
using ReallifeGamemode.Server.WeaponDeal;
using ReallifeGamemode.Server.Log;
using ReallifeGamemode.Server.Inventory.Items;
using Microsoft.EntityFrameworkCore;
using ReallifeGamemode.Server.Wanted;
/**
@@ -217,9 +219,61 @@ namespace ReallifeGamemode.Server.Events
[RemoteEvent("keyPress:E")]
public void KeyPressE(Player player)
{
if (!player.IsLoggedIn() || player.GetData<bool>("isDead") || player.IsInVehicle) return;
if (!player.IsLoggedIn() || player.GetData<bool>("isDead")) return;
var user = player.GetUser();
if (player.IsInVehicle
&& player.VehicleSeat == 0
&& player.Vehicle.Model == (uint)VehicleHash.Riot
&& (user.FactionId == 1 || user.FactionId == 3)
&& player.Position.DistanceTo(HanfManager.ASSERVATENKAMMER_POSITION) <= 3
/*&& player.IsDuty()*/)
{
using var dbContext = new DatabaseContext();
GTANetworkAPI.Vehicle veh = player.Vehicle;
ServerVehicle serverVehicle = veh.GetServerVehicle(dbContext);
List<VehicleItem> items = InventoryManager.GetVehicleItems(veh);
if (items.Count() == 0)
{
player.SendNotification("Der Riot ist leer");
return;
}
IIllegalItem cannabisItem = InventoryManager.GetItem<Cannabis>();
IIllegalItem cannabisSeedItem = InventoryManager.GetItem<CannabisSeeds>();
VehicleItem vehicleCannabisItem = items.Where(i => i.ItemId == cannabisItem.Id).FirstOrDefault();
VehicleItem vehicleCannabisSeedItem = items.Where(i => i.ItemId == cannabisSeedItem.Id).FirstOrDefault();
int cannabisAmount = vehicleCannabisItem?.Amount ?? 0;
int cannabisSeedAmount = vehicleCannabisSeedItem?.Amount ?? 0;
InventoryManager.RemoveVehicleItem(serverVehicle, vehicleCannabisItem, cannabisAmount, player);
InventoryManager.RemoveVehicleItem(serverVehicle, vehicleCannabisSeedItem, cannabisSeedAmount, player);
var price = cannabisSeedAmount * cannabisSeedItem.PriceForConfiscation + cannabisAmount * cannabisItem.PriceForConfiscation;
logger.LogInformation("Player {0} unloaded the riot truck with {1} cannabis and {2} cannabis seed and the faction got {3}", player.Name, cannabisAmount, cannabisSeedAmount, price);
var factions = dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Id == 1 || f.Id == 3);
foreach (var faction in factions)
{
faction.BankAccount.Balance += price;
}
player.SendNotification("~g~Der Riot wurde erfolgreich entladen");
dbContext.SaveChanges();
return;
}
if (player.IsInVehicle)
{
return;
}
if (player.HasData("nearATM"))
{
ATMManager.ShowAtmUi(player, player.GetData<int>("nearATM"));
@@ -245,6 +299,7 @@ namespace ReallifeGamemode.Server.Events
JailPoint nearestjailPoint = PositionManager.jailPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.5);
bool isNearCannabisSeedBuyPoint = HanfManager.IsPlayerNearSeedBuyPoint(player);
bool isNearJointManufacturerPoint = HanfManager.IsPlayerNearJointManufacturer(player);
bool isNearCannabisSellPoint = HanfManager.IsPlayerNearCannabisSellPoint(player);
if (user?.FactionId != null)
{
@@ -766,7 +821,7 @@ namespace ReallifeGamemode.Server.Events
if (isNearCannabisSeedBuyPoint)
{
player.TriggerEvent("SERVER:Hanf_BuySeed", HanfManager.SEED_PRICE);
HanfManager.ShowPlayerBuySeedMenu(player);
return;
}
@@ -775,6 +830,39 @@ namespace ReallifeGamemode.Server.Events
HanfManager.BuildJointsFromCannabis(player);
return;
}
if (isNearCannabisSellPoint)
{
HanfManager.PlayerSellCannabis(player);
return;
}
if (player.HasData("IsCarryingPlant") || player.GetData<bool>("IsCarryingPlant") && (user.FactionId == 3 || user.FactionId == 1) && player.IsDuty())
{
using var dbContext = new DatabaseContext();
FactionVehicle riot = dbContext.FactionVehicles.Where(f => f.Model == VehicleHash.Riot).ToList().Where(f => f.GetOwners().Contains(3)).FirstOrDefault();
if (riot == null)
{
return;
}
GTANetworkAPI.Vehicle riotVehicle = VehicleManager.GetVehicleFromServerVehicle(riot);
if (riotVehicle.Position.DistanceTo(player.Position) > 3)
{
return;
}
var currentModel = player.GetData<int>("HoldingCannabisPlant");
player.AddAttachment("CannabisPlantInHand" + currentModel, true);
player.ResetData("IsCarryingPlant");
var cannabisItem = InventoryManager.GetItem<Cannabis>();
var cannabisSeedsItem = InventoryManager.GetItem<CannabisSeeds>();
int itemIdToGive = currentModel == 3 ? cannabisItem.Id : cannabisSeedsItem.Id;
int amountToGive = currentModel == 3 ? new Random().Next(4, 10) + 1 : 1;
InventoryManager.AddItemToVehicleInventory(riotVehicle, itemIdToGive, amountToGive);
}
}
[RemoteEvent("keyPress:I")]