samen kaufen und hanf -> joint
This commit is contained in:
File diff suppressed because it is too large
Load Diff
67
ReallifeGamemode.Client/drugs/hanf.ts
Normal file
67
ReallifeGamemode.Client/drugs/hanf.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { Menu, Point, UIMenuSliderItem, UIMenuItem, Color, UIMenuListItem, ItemsCollection } from "../libs/NativeUI";
|
||||
import { createMenuItem } from "../util";
|
||||
import moneyformat from "../moneyformat";
|
||||
import { getAnimFromId } from "../util/animationSync";
|
||||
import { getCreatedPedByName } from "../Ped/PedCreator";
|
||||
|
||||
export default function hanfSystem(globalData: IGlobalData) {
|
||||
mp.events.add("SERVER:Hanf_BuySeed", price => {
|
||||
if (globalData.InMenu || globalData.InChat) {
|
||||
return;
|
||||
}
|
||||
|
||||
globalData.InMenu = true;
|
||||
|
||||
var menu = new Menu("Samen kaufen", "Kaufe dir Hanfsamen", new Point(50, 50));
|
||||
|
||||
var seedsToBuy = 0;
|
||||
|
||||
var countItems = [...Array(50).keys()].map(x => x + 1);
|
||||
|
||||
var soloPriceItem = createMenuItem("Einzelpreis", "Preis pro Samen", item => {
|
||||
item.SetRightLabel("$" + moneyformat(price));
|
||||
});
|
||||
menu.AddItem(soloPriceItem);
|
||||
|
||||
var countItem = new UIMenuListItem("Anzahl", "Wähle die Anzahl der Samen aus", new ItemsCollection(countItems), 0);
|
||||
menu.AddItem(countItem);
|
||||
|
||||
var buyItem = new UIMenuItem("Kaufen", "Kaufe die Samen");
|
||||
buyItem.BackColor = new Color(0, 100, 0);
|
||||
buyItem.HighlightedBackColor = new Color(0, 150, 0);
|
||||
menu.AddItem(buyItem);
|
||||
|
||||
var completePriceItem = new UIMenuItem("Gesamtpreis", "Preis für alle Samen");
|
||||
menu.AddItem(completePriceItem);
|
||||
|
||||
menu.ListChange.on((item, index) => {
|
||||
if (item === countItem) {
|
||||
seedsToBuy = Number(countItem.SelectedValue);
|
||||
completePriceItem.SetRightLabel("$" + moneyformat(seedsToBuy * price));
|
||||
}
|
||||
});
|
||||
|
||||
menu.ItemSelect.on((item, index) => {
|
||||
if (item === buyItem) {
|
||||
mp.events.callRemote("CLIENT:Hanf_BuySeeds", seedsToBuy);
|
||||
menu.Close();
|
||||
}
|
||||
});
|
||||
|
||||
menu.MenuClose.on(() => {
|
||||
globalData.InMenu = false;
|
||||
});
|
||||
|
||||
menu.Open();
|
||||
});
|
||||
|
||||
mp.events.add("SERVER:Hanf_PlayManufacturerAnim", animId => {
|
||||
var anim = getAnimFromId(animId);
|
||||
var npc = getCreatedPedByName("hanf_verarbeiter_typ");
|
||||
npc.taskPlayAnim(anim.dict, anim.name, 1, 0, 1000 * 10, 1, 0, !1, !1, !1);
|
||||
setTimeout(() => {
|
||||
npc.stopAnim(anim.name, anim.dict, 3);
|
||||
npc.stopAnimTask(anim.dict, anim.name, 3);
|
||||
}, 1000 * 10);
|
||||
});
|
||||
}
|
||||
@@ -295,6 +295,9 @@ rentCar(globalData);
|
||||
import Carwash from './util/carwash';
|
||||
Carwash(globalData);
|
||||
|
||||
import hanfSystem from './drugs/hanf';
|
||||
hanfSystem(globalData);
|
||||
|
||||
require('./Gui/policedepartment');
|
||||
require('./Gui/helptext');
|
||||
require('./admin/spectate');
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
import { debug } from "util";
|
||||
|
||||
const animationSyncData =
|
||||
{
|
||||
animations: [],
|
||||
|
||||
register: function (name, animDict, animName, duration, loop, flag, endless) {
|
||||
let id = mp.game.joaat(name);
|
||||
|
||||
if (!this.animations.hasOwnProperty(id)) {
|
||||
this.animations[id] =
|
||||
{
|
||||
id: id,
|
||||
name: name,
|
||||
animDict: animDict,
|
||||
animName: animName,
|
||||
duration: duration,
|
||||
loop: loop,
|
||||
flag: flag,
|
||||
endless: endless
|
||||
};
|
||||
} else {
|
||||
mp.game.graphics.notify("Animation Sync Error: ~r~Duplicate Entry");
|
||||
}
|
||||
},
|
||||
|
||||
getAnimFromId: function (name: string): { dict: string, name: string } {
|
||||
var anim = this.animations[mp.game.joaat(name)];
|
||||
return {
|
||||
dict: anim.animDict,
|
||||
name: anim.animName
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export function getAnimFromId(name: string) {
|
||||
return animationSyncData.getAnimFromId(name);
|
||||
}
|
||||
|
||||
export default function animationSync() {
|
||||
let blockInput = false;
|
||||
let animationBreakTimer;
|
||||
@@ -12,37 +49,13 @@ export default function animationSync() {
|
||||
animationSyncData.register("getUncuff", "mp_arresting", "b_uncuff", 5500, false, 0, false);
|
||||
animationSyncData.register("hup", "mp_am_hold_up", "handsup_base", -1, true, 50, true);
|
||||
animationSyncData.register("carryBox", "anim@heists@box_carry@", "idle", -1, true, 50, true);
|
||||
animationSyncData.register("manufacturJoint", "anim@mp_snowball", "pickup_snowball", 1000 * 10, false, 1, false);
|
||||
});
|
||||
|
||||
const animationBreakMessage = [
|
||||
{ animName: "Cuffed", msg: "Handschellen gebrochen." }
|
||||
];
|
||||
|
||||
const animationSyncData =
|
||||
{
|
||||
animations: [],
|
||||
|
||||
register: function (name, animDict, animName, duration, loop, flag, endless) {
|
||||
let id = mp.game.joaat(name);
|
||||
|
||||
if (!this.animations.hasOwnProperty(id)) {
|
||||
this.animations[id] =
|
||||
{
|
||||
id: id,
|
||||
name: name,
|
||||
animDict: animDict,
|
||||
animName: animName,
|
||||
duration: duration,
|
||||
loop: loop,
|
||||
flag: flag,
|
||||
endless: endless
|
||||
};
|
||||
} else {
|
||||
mp.game.graphics.notify("Animation Sync Error: ~r~Duplicate Entry");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
mp.events.add("entityStreamIn", (entity) => {
|
||||
if (entity.type === "player" && entity.animationData) {
|
||||
@@ -90,6 +103,7 @@ export default function animationSync() {
|
||||
clearTimeout(animationBreakTimer);
|
||||
animationBreakTimer = null;
|
||||
}
|
||||
|
||||
if (string == null) {
|
||||
blockInput = false;
|
||||
return;
|
||||
|
||||
19
ReallifeGamemode.Server/BaseScript.cs
Normal file
19
ReallifeGamemode.Server/BaseScript.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ReallifeGamemode.Server.Log;
|
||||
|
||||
namespace ReallifeGamemode.Server
|
||||
{
|
||||
public abstract class BaseScript : Script
|
||||
{
|
||||
protected readonly ILogger logger;
|
||||
|
||||
public BaseScript()
|
||||
{
|
||||
logger = LogManager.GetLogger(this.GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -243,6 +243,8 @@ namespace ReallifeGamemode.Server.Events
|
||||
AmmunationPoint nearestAmmunationPoint = PositionManager.AmmunationPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.5);
|
||||
RentcarPoint nearestRentcarPoint = PositionManager.rentcarPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.5);
|
||||
JailPoint nearestjailPoint = PositionManager.jailPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.5);
|
||||
bool isNearCannabisSeedBuyPoint = HanfManager.IsPlayerNearSeedBuyPoint(player);
|
||||
bool isNearJointManufacturerPoint = HanfManager.IsPlayerNearJointManufacturer(player);
|
||||
|
||||
if (user?.FactionId != null)
|
||||
{
|
||||
@@ -761,6 +763,18 @@ namespace ReallifeGamemode.Server.Events
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isNearCannabisSeedBuyPoint)
|
||||
{
|
||||
player.TriggerEvent("SERVER:Hanf_BuySeed", HanfManager.SEED_PRICE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNearJointManufacturerPoint)
|
||||
{
|
||||
HanfManager.BuildJointsFromCannabis(player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("keyPress:I")]
|
||||
|
||||
@@ -4,7 +4,8 @@ using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Services;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using ReallifeGamemode.Server.Util;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Items
|
||||
{
|
||||
@@ -22,6 +23,7 @@ namespace ReallifeGamemode.Server.Inventory.Items
|
||||
|
||||
public override bool Use(Player player, User user, DatabaseContext databaseContext)
|
||||
{
|
||||
player.ToggleInventory(InventoryToggleOption.HIDE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,6 +147,7 @@ namespace ReallifeGamemode.Server
|
||||
PositionManager.LoadPositionManager();
|
||||
LoadManager.LoadLoadManager();
|
||||
Rentcar.Setup();
|
||||
HanfManager.Load();
|
||||
|
||||
World.WeatherSync.Load();
|
||||
|
||||
|
||||
178
ReallifeGamemode.Server/Managers/HanfManager.cs
Normal file
178
ReallifeGamemode.Server/Managers/HanfManager.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Timers;
|
||||
using GTANetworkAPI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using ReallifeGamemode.Server.Inventory.Interfaces;
|
||||
using ReallifeGamemode.Server.Inventory.Items;
|
||||
using ReallifeGamemode.Server.Services;
|
||||
using ReallifeGamemode.Server.Util;
|
||||
|
||||
namespace ReallifeGamemode.Server.Managers
|
||||
{
|
||||
public class HanfManager : BaseScript
|
||||
{
|
||||
/// <summary>
|
||||
/// Punkte zum Samen kaufen
|
||||
/// </summary>
|
||||
private readonly static List<Vector3> _seedsBuyPoints = new List<Vector3>();
|
||||
|
||||
/// <summary>
|
||||
/// Aktueller Samen-Preis
|
||||
/// </summary>
|
||||
public static int SEED_PRICE = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Wie viele Joints man aus einem Cannabis bekommt
|
||||
/// </summary>
|
||||
public static int CANNABIS_TO_JOINT_RATIO = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Flag, ob der Verarbeiter aktuell benutzt wird
|
||||
/// </summary>
|
||||
private static bool _manufacturerCurrentlyUsed = false;
|
||||
|
||||
/// <summary>
|
||||
/// Marihuana -> Joint
|
||||
/// </summary>
|
||||
private readonly static Vector3 _jointManufacturerPoint = new Vector3(-127.726105, 1921.5142, 197.31104);
|
||||
|
||||
/// <summary>
|
||||
/// Animations-ID des Verarbeitens
|
||||
/// </summary>
|
||||
private const string _manufacturerAnim = "manufacturJoint";
|
||||
|
||||
private static Timer _manufacturerDoneTimer = new Timer(TimeSpan.FromSeconds(10).TotalMilliseconds);
|
||||
|
||||
static HanfManager()
|
||||
{
|
||||
_manufacturerDoneTimer.Elapsed += ManufacturerDoneTimerCallback;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ladefunktion zum
|
||||
/// </summary>
|
||||
public static void Load()
|
||||
{
|
||||
_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));
|
||||
_seedsBuyPoints.Add(new Vector3(-758.6156, -1595.2686, 6.302392));
|
||||
_seedsBuyPoints.Add(new Vector3(-441.0504, 1595.4435, 358.4195));
|
||||
|
||||
ColShape colShape = null;
|
||||
|
||||
foreach (Vector3 buyPoint in _seedsBuyPoints)
|
||||
{
|
||||
colShape = NAPI.ColShape.CreateSphereColShape(buyPoint, 20.0f);
|
||||
colShape.OnEntityEnterColShape += OnSeedBuyRangeColShapeEnter;
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnSeedBuyRangeColShapeEnter(ColShape colShape, Player player)
|
||||
{
|
||||
ChatService.SendMessage(player, $"Fremder sagt: Pssst.. Willst paar Samen erwerben?");
|
||||
}
|
||||
|
||||
internal static bool IsPlayerNearSeedBuyPoint(Player player)
|
||||
{
|
||||
return _seedsBuyPoints.Any(p => player.Position.DistanceTo(p) <= 2.5f);
|
||||
}
|
||||
|
||||
internal static bool IsPlayerNearJointManufacturer(Player player)
|
||||
{
|
||||
return _jointManufacturerPoint.DistanceTo(player.Position) <= 2.5f;
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:Hanf_BuySeeds")]
|
||||
public void HanfManagerBuySeeds(Player player, int amount)
|
||||
{
|
||||
if (!player.IsLoggedIn())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using var dbContext = new DatabaseContext();
|
||||
var user = player.GetUser(dbContext);
|
||||
|
||||
IItem seedItem = InventoryManager.GetItem<CannabisSeeds>();
|
||||
var newAmount = seedItem.Gewicht * amount;
|
||||
|
||||
if (!InventoryManager.CanPlayerHoldMoreWeight(player, newAmount))
|
||||
{
|
||||
player.TriggerEvent("~r~So viele Samen passen nicht mehr in deine Hosentasche");
|
||||
return;
|
||||
}
|
||||
|
||||
var price = amount * SEED_PRICE;
|
||||
|
||||
if (user.Handmoney < price)
|
||||
{
|
||||
player.SendNotification("~r~Du hast nicht genug Geld dafür");
|
||||
return;
|
||||
}
|
||||
|
||||
logger.LogInformation("Player {0} bought {1} cannabis seeds for {2} dollars (price per seed: {3})", player.Name, amount, price, SEED_PRICE); // <-- WICHTIG LOGS
|
||||
|
||||
user.Handmoney -= price;
|
||||
dbContext.SaveChanges();
|
||||
|
||||
InventoryManager.AddItemToInventory(player, seedItem.Id, amount);
|
||||
|
||||
player.SendNotification($"Du hast {amount} Hanfsamen gekauft");
|
||||
}
|
||||
|
||||
internal static void BuildJointsFromCannabis(Player player)
|
||||
{
|
||||
if(player.HasAnimation(_manufacturerAnim) || _manufacturerCurrentlyUsed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using var dbContext = new DatabaseContext();
|
||||
var user = player.GetUser(dbContext);
|
||||
var userItems = InventoryManager.GetUserItems(player, dbContext);
|
||||
|
||||
IItem cannabisItem = InventoryManager.GetItem<Cannabis>();
|
||||
IItem jointItem = InventoryManager.GetItem<Joint>();
|
||||
|
||||
var addWeight = jointItem.Gewicht * CANNABIS_TO_JOINT_RATIO - cannabisItem.Gewicht;
|
||||
|
||||
if (!InventoryManager.CanPlayerHoldMoreWeight(player, addWeight))
|
||||
{
|
||||
player.SendNotification("~r~Für die Verarbeitung hast du nicht genug Platz im Rucksack");
|
||||
return;
|
||||
}
|
||||
|
||||
UserItem userCannabisItem = userItems.Where(i => i.ItemId == cannabisItem.Id).FirstOrDefault();
|
||||
if (userCannabisItem == null)
|
||||
{
|
||||
player.SendNotification("~r~Du hast kein Cannabis dabei");
|
||||
return;
|
||||
}
|
||||
|
||||
_manufacturerCurrentlyUsed = true;
|
||||
_manufacturerDoneTimer.Start();
|
||||
|
||||
player.SyncAnimation(_manufacturerAnim);
|
||||
|
||||
InventoryManager.RemoveUserItem(user, userCannabisItem, 1);
|
||||
InventoryManager.AddItemToInventory(player, jointItem.Id, CANNABIS_TO_JOINT_RATIO);
|
||||
|
||||
player.SendNotification($"Du hast 1 Cannabis in {CANNABIS_TO_JOINT_RATIO} Joints verarbeitet");
|
||||
|
||||
NAPI.ClientEvent.TriggerClientEventInRange(player.Position, 100.0f, "SERVER:Hanf_PlayManufacturerAnim", _manufacturerAnim);
|
||||
}
|
||||
|
||||
private static void ManufacturerDoneTimerCallback(object sender, EventArgs args)
|
||||
{
|
||||
_manufacturerDoneTimer.Stop();
|
||||
_manufacturerCurrentlyUsed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,11 @@ namespace ReallifeGamemode.Server.Managers
|
||||
player.SetSharedData("backpackItems", JsonConvert.SerializeObject(backpackItems[player].ToArray()));
|
||||
}
|
||||
|
||||
internal static IItem GetItem<T>() where T : IItem
|
||||
{
|
||||
return itemList.Where(i => i.GetType() == typeof(T)).First();
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:getVehicleInventory")]
|
||||
public static void SetVehicleItems(Player player)
|
||||
{
|
||||
@@ -134,6 +139,11 @@ namespace ReallifeGamemode.Server.Managers
|
||||
player.SetSharedData("vehicleItems", JsonConvert.SerializeObject(vehicleItems[player].ToArray()));
|
||||
}
|
||||
|
||||
public static bool CanPlayerHoldMoreWeight(Player player, int moreWeight)
|
||||
{
|
||||
return GetUserInventoryWeight(player) + moreWeight <= MAX_USER_INVENTORY;
|
||||
}
|
||||
|
||||
public static void LoadItems()
|
||||
{
|
||||
itemList = new List<IItem>();
|
||||
@@ -179,12 +189,8 @@ namespace ReallifeGamemode.Server.Managers
|
||||
if (userItem.Amount == 0)
|
||||
{
|
||||
dbContext.Remove(userItem);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
Player player = user.Player;
|
||||
|
||||
List<UserItem> itemList = GetUserItems(player);
|
||||
if (itemList == null) return;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
@@ -216,16 +222,29 @@ namespace ReallifeGamemode.Server.Managers
|
||||
return new DatabaseContext().VehicleItems.ToList().FindAll(i => i.GetVehicle().GetVehicle() == vehicle);
|
||||
}
|
||||
|
||||
public static List<UserItem> GetUserItems(Player player)
|
||||
public static List<UserItem> GetUserItems(Player player, DatabaseContext dbContext = null)
|
||||
{
|
||||
var user = player.GetUser();
|
||||
|
||||
using (var context = new DatabaseContext())
|
||||
if (dbContext == null)
|
||||
{
|
||||
return context.UserItems.ToList().FindAll(i => i.UserId == user.Id);
|
||||
using (dbContext = new DatabaseContext())
|
||||
{
|
||||
return GetUserItemsInternal(player, dbContext);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetUserItemsInternal(player, dbContext);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<UserItem> GetUserItemsInternal(Player player, DatabaseContext dbContext)
|
||||
{
|
||||
var user = player.GetUser(dbContext);
|
||||
|
||||
return dbContext.UserItems.ToList().FindAll(i => i.UserId == user.Id);
|
||||
}
|
||||
|
||||
|
||||
public static int GetUserInventoryWeight(Player player)
|
||||
{
|
||||
var user = player.GetUser();
|
||||
|
||||
12
ReallifeGamemode.Server/Util/Colors.cs
Normal file
12
ReallifeGamemode.Server/Util/Colors.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
|
||||
namespace ReallifeGamemode.Server.Util
|
||||
{
|
||||
public static class Colors
|
||||
{
|
||||
public static Color White = new Color(255, 255, 255);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user