samen kaufen und hanf -> joint

This commit is contained in:
hydrant
2021-05-24 00:04:55 +02:00
parent d72f7216cc
commit a49fcf09c7
11 changed files with 1126 additions and 788 deletions

View File

@@ -1,6 +1,4 @@
export default function PedCreator() { var PedHashes = {
// Update 04/03/2020, Ped count [739]
var PedHashes = {
a_c_boar: 0xCE5FF074, a_c_boar: 0xCE5FF074,
a_c_cat_01: 0x573201B8, a_c_cat_01: 0x573201B8,
a_c_chickenhawk: 0xAAB71F62, a_c_chickenhawk: 0xAAB71F62,
@@ -740,8 +738,14 @@
u_m_y_staggrm_01: 0x9194CE03, u_m_y_staggrm_01: 0x9194CE03,
u_m_y_tattoo_01: 0x94AE2B8C, u_m_y_tattoo_01: 0x94AE2B8C,
u_m_y_zombie_01: 0xAC4B4506, u_m_y_zombie_01: 0xAC4B4506,
} hanf_verarbeiter_typ: 0x6C8C08E5,
hanf_verarbeiter_wachmann: 0x7ED5AD78,
hanf_verarbeiter_wachhund: 0x9563221D
};
var CreatedPeds: Array<PedMp> = []; var CreatedPeds: Array<PedMp> = [];
export default function PedCreator() {
mp.events.add("SERVER:CreateStaticPeds", (jsonVector3s, jsonHeadings, jsonCharHashes, jsonDimension) => { mp.events.add("SERVER:CreateStaticPeds", (jsonVector3s, jsonHeadings, jsonCharHashes, jsonDimension) => {
var vector3s = JSON.parse(jsonVector3s); var vector3s = JSON.parse(jsonVector3s);
var headings = JSON.parse(jsonHeadings); var headings = JSON.parse(jsonHeadings);
@@ -756,7 +760,7 @@
hash = tmpHash; hash = tmpHash;
} }
//mp.gui.chat.push(`adding ped ${hash} (${charHashes[i]}`); mp.gui.chat.push(`adding ped ${hash} (${charHashes[i]}`);
let p = mp.peds.new(hash, vector3s[i], headings[i], dimension[i]); let p = mp.peds.new(hash, vector3s[i], headings[i], dimension[i]);
p.freezePosition(true); p.freezePosition(true);
@@ -775,6 +779,7 @@
} }
}); });
}); });
}
function getPedHashByName(name: string) { function getPedHashByName(name: string) {
var keys = Object.keys(PedHashes); var keys = Object.keys(PedHashes);
@@ -785,4 +790,8 @@
return -1; return -1;
} }
export function getCreatedPedByName(name: string): PedMp {
var hash = getPedHashByName(name);
return CreatedPeds.filter(p => p.model === hash)[0];
} }

View 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);
});
}

View File

@@ -295,6 +295,9 @@ rentCar(globalData);
import Carwash from './util/carwash'; import Carwash from './util/carwash';
Carwash(globalData); Carwash(globalData);
import hanfSystem from './drugs/hanf';
hanfSystem(globalData);
require('./Gui/policedepartment'); require('./Gui/policedepartment');
require('./Gui/helptext'); require('./Gui/helptext');
require('./admin/spectate'); require('./admin/spectate');

View File

@@ -1,23 +1,5 @@
import { debug } from "util"; import { debug } from "util";
export default function animationSync() {
let blockInput = false;
let animationBreakTimer;
mp.events.add("SERVER:LoadAnimations", () => {
animationSyncData.register("Cuffed", "mp_arresting", "idle", -1, true, 50, false);
animationSyncData.register("doArrest", "mp_arrest_paired", "cop_p2_back_right", 3760, false, 0, false);
animationSyncData.register("getArrest", "mp_arrest_paired", "crook_p2_back_right", 3760, false, 0, false);
animationSyncData.register("doUncuff", "mp_arresting", "a_uncuff", 5500, false, 0, false);
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);
});
const animationBreakMessage = [
{ animName: "Cuffed", msg: "Handschellen gebrochen." }
];
const animationSyncData = const animationSyncData =
{ {
animations: [], animations: [],
@@ -40,9 +22,40 @@ export default function animationSync() {
} else { } else {
mp.game.graphics.notify("Animation Sync Error: ~r~Duplicate Entry"); 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;
mp.events.add("SERVER:LoadAnimations", () => {
animationSyncData.register("Cuffed", "mp_arresting", "idle", -1, true, 50, false);
animationSyncData.register("doArrest", "mp_arrest_paired", "cop_p2_back_right", 3760, false, 0, false);
animationSyncData.register("getArrest", "mp_arrest_paired", "crook_p2_back_right", 3760, false, 0, false);
animationSyncData.register("doUncuff", "mp_arresting", "a_uncuff", 5500, false, 0, false);
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." }
];
/* /*
mp.events.add("entityStreamIn", (entity) => { mp.events.add("entityStreamIn", (entity) => {
if (entity.type === "player" && entity.animationData) { if (entity.type === "player" && entity.animationData) {
@@ -90,6 +103,7 @@ export default function animationSync() {
clearTimeout(animationBreakTimer); clearTimeout(animationBreakTimer);
animationBreakTimer = null; animationBreakTimer = null;
} }
if (string == null) { if (string == null) {
blockInput = false; blockInput = false;
return; return;

View 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());
}
}
}

View File

@@ -243,6 +243,8 @@ namespace ReallifeGamemode.Server.Events
AmmunationPoint nearestAmmunationPoint = PositionManager.AmmunationPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.5); 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); 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); 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) if (user?.FactionId != null)
{ {
@@ -761,6 +763,18 @@ namespace ReallifeGamemode.Server.Events
return; return;
} }
} }
if (isNearCannabisSeedBuyPoint)
{
player.TriggerEvent("SERVER:Hanf_BuySeed", HanfManager.SEED_PRICE);
return;
}
if (isNearJointManufacturerPoint)
{
HanfManager.BuildJointsFromCannabis(player);
return;
}
} }
[RemoteEvent("keyPress:I")] [RemoteEvent("keyPress:I")]

View File

@@ -4,7 +4,8 @@ using System.Text;
using GTANetworkAPI; using GTANetworkAPI;
using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Database.Models; using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Services; using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Util;
namespace ReallifeGamemode.Server.Inventory.Items namespace ReallifeGamemode.Server.Inventory.Items
{ {
@@ -22,6 +23,7 @@ namespace ReallifeGamemode.Server.Inventory.Items
public override bool Use(Player player, User user, DatabaseContext databaseContext) public override bool Use(Player player, User user, DatabaseContext databaseContext)
{ {
player.ToggleInventory(InventoryToggleOption.HIDE);
return true; return true;
} }
} }

View File

@@ -147,6 +147,7 @@ namespace ReallifeGamemode.Server
PositionManager.LoadPositionManager(); PositionManager.LoadPositionManager();
LoadManager.LoadLoadManager(); LoadManager.LoadLoadManager();
Rentcar.Setup(); Rentcar.Setup();
HanfManager.Load();
World.WeatherSync.Load(); World.WeatherSync.Load();

View 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;
}
}
}

View File

@@ -75,6 +75,11 @@ namespace ReallifeGamemode.Server.Managers
player.SetSharedData("backpackItems", JsonConvert.SerializeObject(backpackItems[player].ToArray())); 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")] [RemoteEvent("CLIENT:getVehicleInventory")]
public static void SetVehicleItems(Player player) public static void SetVehicleItems(Player player)
{ {
@@ -134,6 +139,11 @@ namespace ReallifeGamemode.Server.Managers
player.SetSharedData("vehicleItems", JsonConvert.SerializeObject(vehicleItems[player].ToArray())); 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() public static void LoadItems()
{ {
itemList = new List<IItem>(); itemList = new List<IItem>();
@@ -179,12 +189,8 @@ namespace ReallifeGamemode.Server.Managers
if (userItem.Amount == 0) if (userItem.Amount == 0)
{ {
dbContext.Remove(userItem); dbContext.Remove(userItem);
dbContext.SaveChanges();
} }
Player player = user.Player;
List<UserItem> itemList = GetUserItems(player);
if (itemList == null) return;
dbContext.SaveChanges(); dbContext.SaveChanges();
} }
} }
@@ -216,16 +222,29 @@ namespace ReallifeGamemode.Server.Managers
return new DatabaseContext().VehicleItems.ToList().FindAll(i => i.GetVehicle().GetVehicle() == vehicle); 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(); if (dbContext == null)
{
using (dbContext = new DatabaseContext())
{
return GetUserItemsInternal(player, dbContext);
}
}
else
{
return GetUserItemsInternal(player, dbContext);
}
}
using (var context = new DatabaseContext()) private static List<UserItem> GetUserItemsInternal(Player player, DatabaseContext dbContext)
{ {
return context.UserItems.ToList().FindAll(i => i.UserId == user.Id); var user = player.GetUser(dbContext);
}
return dbContext.UserItems.ToList().FindAll(i => i.UserId == user.Id);
} }
public static int GetUserInventoryWeight(Player player) public static int GetUserInventoryWeight(Player player)
{ {
var user = player.GetUser(); var user = player.GetUser();

View 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);
}
}