hanf vielleicht fertig
This commit is contained in:
@@ -31,7 +31,7 @@ export default function factionInteraction(globalData: IGlobalData) {
|
|||||||
var ticketName: string;
|
var ticketName: string;
|
||||||
var pointsName: string;
|
var pointsName: string;
|
||||||
|
|
||||||
var factionInteractionMenu;
|
var factionInteractionMenu: NativeUI.Menu;
|
||||||
var healTaskMenuMedic;
|
var healTaskMenuMedic;
|
||||||
var reviveTaskMenuMedic;
|
var reviveTaskMenuMedic;
|
||||||
var insDate;
|
var insDate;
|
||||||
@@ -42,7 +42,10 @@ export default function factionInteraction(globalData: IGlobalData) {
|
|||||||
//LSPD
|
//LSPD
|
||||||
let ticketTaskMenuLSPD;
|
let ticketTaskMenuLSPD;
|
||||||
let pointsTaskMenuLSPD;
|
let pointsTaskMenuLSPD;
|
||||||
let wantedsMenuLSPD
|
let wantedsMenuLSPD;
|
||||||
|
|
||||||
|
let friskUserMenuItem: NativeUI.UIMenuItem;
|
||||||
|
let friskVehicleMenuItem: NativeUI.UIMenuItem;
|
||||||
if (userFactionId == 1 || userFactionId == 3) {
|
if (userFactionId == 1 || userFactionId == 3) {
|
||||||
if (isDuty) {
|
if (isDuty) {
|
||||||
mp.gui.chat.activate(false);
|
mp.gui.chat.activate(false);
|
||||||
@@ -59,6 +62,12 @@ export default function factionInteraction(globalData: IGlobalData) {
|
|||||||
wantedsMenuLSPD = new UIMenuItem("Verbrecher Liste");
|
wantedsMenuLSPD = new UIMenuItem("Verbrecher Liste");
|
||||||
factionInteractionMenu.AddItem(wantedsMenuLSPD);
|
factionInteractionMenu.AddItem(wantedsMenuLSPD);
|
||||||
|
|
||||||
|
friskUserMenuItem = new UIMenuItem("Spieler durchsuchen", "Einen Spieler auf illegale Gegenstände durchsuchen.");
|
||||||
|
factionInteractionMenu.AddItem(friskUserMenuItem);
|
||||||
|
|
||||||
|
friskVehicleMenuItem = new UIMenuItem("Fahrzeug durchsuchen", "Das nächste Fahrzeug auf illegale Gegenstände durchsuchen.")
|
||||||
|
factionInteractionMenu.AddItem(friskVehicleMenuItem);
|
||||||
|
|
||||||
/*TaskMenuLSPD = new UIMenuItem("");
|
/*TaskMenuLSPD = new UIMenuItem("");
|
||||||
TaskMenuLSPD.SetRightLabel("");
|
TaskMenuLSPD.SetRightLabel("");
|
||||||
factionInteractionMenu.AddItem(TaskMenuLSPD);*/ //weiteres
|
factionInteractionMenu.AddItem(TaskMenuLSPD);*/ //weiteres
|
||||||
@@ -107,6 +116,20 @@ export default function factionInteraction(globalData: IGlobalData) {
|
|||||||
globalData.InMenu = false;
|
globalData.InMenu = false;
|
||||||
mp.events.callRemote("CLIENT:wantedlist");
|
mp.events.callRemote("CLIENT:wantedlist");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case friskUserMenuItem:
|
||||||
|
factionInteractionMenu.Visible = false;
|
||||||
|
var input = new InputHelper("Welchem Spieler möchtest du Strafpunkte geben (Name / ID)?", globalData);
|
||||||
|
input.show();
|
||||||
|
input.getValue(name => {
|
||||||
|
mp.events.callRemote("CLIENT:InteractionMenu_LSPD_FriskUser", name);
|
||||||
|
globalData.InMenu = false;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case friskVehicleMenuItem:
|
||||||
|
factionInteractionMenu.Close();
|
||||||
|
mp.events.callRemote("CLIENT:InteractionMenu_LSPD_FriskVehicle");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { getAnimFromId } from "../util/animationSync";
|
|||||||
import { getCreatedPedByName } from "../Ped/PedCreator";
|
import { getCreatedPedByName } from "../Ped/PedCreator";
|
||||||
import KeyBinder from 'ragemp-better-bindings';
|
import KeyBinder from 'ragemp-better-bindings';
|
||||||
|
|
||||||
const hanfPlantObjects = {
|
export const hanfPlantObjects = {
|
||||||
stage1: mp.game.joaat('bkr_prop_weed_bud_pruned_01a'),
|
stage1: mp.game.joaat('bkr_prop_weed_bud_pruned_01a'),
|
||||||
stage2: mp.game.joaat('bkr_prop_weed_bud_01b'),
|
stage2: mp.game.joaat('bkr_prop_weed_bud_01b'),
|
||||||
stage3: mp.game.joaat('prop_weed_02'),
|
stage3: mp.game.joaat('prop_weed_02'),
|
||||||
@@ -43,7 +43,7 @@ export default function hanfSystem(globalData: IGlobalData) {
|
|||||||
let currentlyPlanting: boolean = false;
|
let currentlyPlanting: boolean = false;
|
||||||
let lastPlantingState = true;
|
let lastPlantingState = true;
|
||||||
|
|
||||||
mp.events.add("SERVER:Hanf_BuySeed", price => {
|
mp.events.add("SERVER:Hanf_BuySeed", (maxSeedsToBuy, price) => {
|
||||||
if (globalData.InMenu || globalData.InChat) {
|
if (globalData.InMenu || globalData.InChat) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ export default function hanfSystem(globalData: IGlobalData) {
|
|||||||
|
|
||||||
var seedsToBuy = 0;
|
var seedsToBuy = 0;
|
||||||
|
|
||||||
var countItems = [...Array(50).keys()].map(x => x + 1);
|
var countItems = [...Array(maxSeedsToBuy).keys()].map(x => x + 1);
|
||||||
|
|
||||||
var soloPriceItem = createMenuItem("Einzelpreis", "Preis pro Samen", item => {
|
var soloPriceItem = createMenuItem("Einzelpreis", "Preis pro Samen", item => {
|
||||||
item.SetRightLabel("$" + moneyformat(price));
|
item.SetRightLabel("$" + moneyformat(price));
|
||||||
@@ -93,6 +93,56 @@ export default function hanfSystem(globalData: IGlobalData) {
|
|||||||
menu.Open();
|
menu.Open();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mp.events.add("SERVER:Hanf_SellCannabisMenu", (maxCannabisToSell, price) => {
|
||||||
|
if (globalData.InMenu || globalData.InChat) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
globalData.InMenu = true;
|
||||||
|
|
||||||
|
var menu = new Menu("Cannabis verkaufen", "Verkaufe dein Cannabis", new Point(50, 50));
|
||||||
|
|
||||||
|
var cannabisToSell = 0;
|
||||||
|
|
||||||
|
var countItems = [...Array(maxCannabisToSell).keys()].map(x => x + 1);
|
||||||
|
|
||||||
|
var soloPriceItem = createMenuItem("Einzelpreis", "Preis pro Hanfblüte", item => {
|
||||||
|
item.SetRightLabel("$" + moneyformat(price));
|
||||||
|
});
|
||||||
|
menu.AddItem(soloPriceItem);
|
||||||
|
|
||||||
|
var countItem = new UIMenuListItem("Anzahl", "Wähle die Anzahl der Blüten aus", new ItemsCollection(countItems), 0);
|
||||||
|
menu.AddItem(countItem);
|
||||||
|
|
||||||
|
var buyItem = new UIMenuItem("Verkaufen", "Verkaufe dein Cannabis");
|
||||||
|
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 Blüten");
|
||||||
|
menu.AddItem(completePriceItem);
|
||||||
|
|
||||||
|
menu.ListChange.on((item, index) => {
|
||||||
|
if (item === countItem) {
|
||||||
|
cannabisToSell = Number(countItem.SelectedValue);
|
||||||
|
completePriceItem.SetRightLabel("$" + moneyformat(cannabisToSell * price));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
menu.ItemSelect.on((item, index) => {
|
||||||
|
if (item === buyItem) {
|
||||||
|
mp.events.callRemote("CLIENT:Hanf_SellCannabis", cannabisToSell);
|
||||||
|
menu.Close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
menu.MenuClose.on(() => {
|
||||||
|
globalData.InMenu = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
menu.Open();
|
||||||
|
});
|
||||||
|
|
||||||
mp.events.add("SERVER:Hanf_PlayManufacturerAnim", animId => {
|
mp.events.add("SERVER:Hanf_PlayManufacturerAnim", animId => {
|
||||||
var anim = getAnimFromId(animId);
|
var anim = getAnimFromId(animId);
|
||||||
var npc = getCreatedPedByName("hanf_verarbeiter_typ");
|
var npc = getCreatedPedByName("hanf_verarbeiter_typ");
|
||||||
@@ -154,9 +204,9 @@ export default function hanfSystem(globalData: IGlobalData) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (!isSurfaceAllowed()) {
|
if (!isSurfaceAllowed()) {
|
||||||
// return false;
|
return false;
|
||||||
//}
|
}
|
||||||
|
|
||||||
if (currentPlantingPreviewObject) {
|
if (currentPlantingPreviewObject) {
|
||||||
var objectPos = getPlantPreviewPosition();
|
var objectPos = getPlantPreviewPosition();
|
||||||
@@ -177,14 +227,29 @@ export default function hanfSystem(globalData: IGlobalData) {
|
|||||||
const GET_RAYCAST_RESULT_NATIVE = "0x65287525D951F6BE";
|
const GET_RAYCAST_RESULT_NATIVE = "0x65287525D951F6BE";
|
||||||
|
|
||||||
function isSurfaceAllowed() {
|
function isSurfaceAllowed() {
|
||||||
|
return true;
|
||||||
const player = mp.players.local;
|
const player = mp.players.local;
|
||||||
var position = player.position;
|
var position = getPlantPreviewPosition();
|
||||||
var raycast = mp.game.invoke(RAYCAST_POINT_TO_POINT_NATIVE, position.x, position.y, position.z + 5, position.x, position.y, position.z - 5, -1, undefined, 0);
|
var raycast = mp.game.invoke(RAYCAST_POINT_TO_POINT_NATIVE, position.x, position.y, position.z + 5, position.x, position.y, position.z - 5, 1, 0, 7);
|
||||||
mp.gui.chat.push("raycast = " + raycast);
|
mp.gui.chat.push("raycast = " + raycast);
|
||||||
var hit: boolean, coord: Vector3Mp, surfaceNormal: Vector3Mp, materialHash: number, entityHit: EntityMp;
|
var resultObj = {
|
||||||
var raycastResult = mp.game.invoke(GET_RAYCAST_RESULT_NATIVE, raycast, hit, coord, surfaceNormal, materialHash, entityHit);
|
hit: [false],
|
||||||
|
coord: [new mp.Vector3()],
|
||||||
|
surface: [new mp.Vector3()],
|
||||||
|
material: [0],
|
||||||
|
entityHit: [null]
|
||||||
|
};
|
||||||
|
|
||||||
mp.gui.chat.push("result: " + raycastResult + ", hit = " + hit + ", test = " + materialHash);
|
var raycastResult = -1;
|
||||||
|
var retries = 10;
|
||||||
|
|
||||||
|
do {
|
||||||
|
raycastResult = mp.game.invoke(GET_RAYCAST_RESULT_NATIVE, raycast, resultObj.hit, resultObj.coord, resultObj.surface, resultObj.material, resultObj.entityHit);
|
||||||
|
retries--;
|
||||||
|
} while (raycastResult != 0 && raycastResult != 2 && retries > 0);
|
||||||
|
|
||||||
|
|
||||||
|
mp.gui.chat.push("result: " + raycastResult + ", result = " + JSON.stringify(resultObj));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -270,17 +335,15 @@ export default function hanfSystem(globalData: IGlobalData) {
|
|||||||
|
|
||||||
mp.events.add("SERVER:Hanf_UpdateHanfData", dataJson => {
|
mp.events.add("SERVER:Hanf_UpdateHanfData", dataJson => {
|
||||||
mp.console.logInfo(dataJson);
|
mp.console.logInfo(dataJson);
|
||||||
|
|
||||||
var data: Array<CannabisData> = <Array<CannabisData>>JSON.parse(dataJson)
|
var data: Array<CannabisData> = <Array<CannabisData>>JSON.parse(dataJson)
|
||||||
|
|
||||||
var newPlants = data.filter(d => currentHanfData.filter(x => x.Id === d.Id).length == 0);
|
var newPlants = data.filter(d => currentHanfData.filter(x => x.Id === d.Id).length == 0);
|
||||||
var removedPlants = currentHanfData.filter(d => data.filter(x => x.Id === d.Id).length == 0);
|
var removedPlants = currentHanfData.filter(d => data.filter(x => x.Id === d.Id).length == 0);
|
||||||
var existingPlants = data.filter(d => currentHanfData.filter(x => x.Id === d.Id).length == 1);
|
var existingPlants = data.filter(d => currentHanfData.filter(x => x.Id === d.Id).length == 1);
|
||||||
|
|
||||||
mp.gui.chat.push(`new: ${newPlants.length}, removed: ${removedPlants.length}, existing: ${existingPlants.length}`);
|
|
||||||
|
|
||||||
newPlants.forEach(plant => {
|
newPlants.forEach(plant => {
|
||||||
var model = getPlantModel(plant);
|
var model = getPlantModel(plant);
|
||||||
mp.gui.chat.push("new id: " + plant.Id + ", model = " + model);
|
|
||||||
var object = mp.objects.new(getPlantModel(plant), new mp.Vector3(plant.X, plant.Y, plant.Z));
|
var object = mp.objects.new(getPlantModel(plant), new mp.Vector3(plant.X, plant.Y, plant.Z));
|
||||||
hanfDataIdToObjectMap.set(plant.Id, object);
|
hanfDataIdToObjectMap.set(plant.Id, object);
|
||||||
|
|
||||||
@@ -292,7 +355,6 @@ export default function hanfSystem(globalData: IGlobalData) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
removedPlants.forEach(plant => {
|
removedPlants.forEach(plant => {
|
||||||
//mp.gui.chat.push("removed id: " + plant.Id);
|
|
||||||
var object = hanfDataIdToObjectMap.get(plant.Id);
|
var object = hanfDataIdToObjectMap.get(plant.Id);
|
||||||
hanfDataIdToObjectMap.delete(plant.Id);
|
hanfDataIdToObjectMap.delete(plant.Id);
|
||||||
object.destroy();
|
object.destroy();
|
||||||
@@ -302,11 +364,9 @@ export default function hanfSystem(globalData: IGlobalData) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
existingPlants.forEach(plant => {
|
existingPlants.forEach(plant => {
|
||||||
//mp.gui.chat.push("existing plant: " + plant.Id + ", plant time = " + new Date(plant.Time).toLocaleTimeString() + ", current time = " + new Date().toLocaleTimeString());
|
|
||||||
var object = hanfDataIdToObjectMap.get(plant.Id);
|
var object = hanfDataIdToObjectMap.get(plant.Id);
|
||||||
var model = getPlantModel(plant);
|
var model = getPlantModel(plant);
|
||||||
if (model != object.model) {
|
if (model != object.model) {
|
||||||
//mp.gui.chat.push("existing plant: " + plant.Id + ", changing model to = " + model);
|
|
||||||
object.destroy();
|
object.destroy();
|
||||||
var object = mp.objects.new(model, new mp.Vector3(plant.X, plant.Y, plant.Z));
|
var object = mp.objects.new(model, new mp.Vector3(plant.X, plant.Y, plant.Z));
|
||||||
hanfDataIdToObjectMap.delete(plant.Id);
|
hanfDataIdToObjectMap.delete(plant.Id);
|
||||||
@@ -341,4 +401,43 @@ export default function hanfSystem(globalData: IGlobalData) {
|
|||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mp.events.addProc("SERVER:Hanf_GetModelToGivePlayer", id => {
|
||||||
|
var plant = currentHanfData.filter(x => x.Id == id)[0];
|
||||||
|
var model = getPlantModel(plant);
|
||||||
|
if (model == hanfPlantObjects.stage1) {
|
||||||
|
return 1;
|
||||||
|
} else if (model == hanfPlantObjects.stage3) {
|
||||||
|
return 2;
|
||||||
|
} else if (model == hanfPlantObjects.stage4) {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//var rotationTestObject: ObjectMp = null;
|
||||||
|
//var a1: number, a2: number, a3: number, a4: number, a5: number, a6: number;
|
||||||
|
//mp.events.add(RageEnums.EventKey.PLAYER_COMMAND, (f) => {
|
||||||
|
// var args = f.split(' ');
|
||||||
|
// if (args[0] != "a") {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// a1 = parseFloat(args[1] || "0");
|
||||||
|
// a2 = parseFloat(args[2] || "0");
|
||||||
|
// a3 = parseFloat(args[3] || "0");
|
||||||
|
// a4 = parseFloat(args[4] || "0");
|
||||||
|
// a5 = parseFloat(args[5] || "0");
|
||||||
|
// a6 = parseFloat(args[6] || "0");
|
||||||
|
|
||||||
|
// mp.gui.chat.push(`a1: ${a1.toFixed(2)}, a2: ${a2.toFixed(2)}, a3: ${a3.toFixed(2)}, a4: ${a4.toFixed(2)}, a5: ${a5.toFixed(2)}, a6: ${a6.toFixed(2)},`)
|
||||||
|
|
||||||
|
// if (rotationTestObject != null) {
|
||||||
|
// rotationTestObject.attachTo(Number(mp.players.local.handle), mp.players.local.getBoneIndex(57005), a1, a2, a3, a4, a5, a6, true, false, false, false, 0, true);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// rotationTestObject = mp.objects.new(mp.game.joaat("prop_cs_trowel"), mp.players.local.position, {
|
||||||
|
// alpha: 255
|
||||||
|
// });
|
||||||
|
//});
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ const animationSyncData =
|
|||||||
{
|
{
|
||||||
animations: [],
|
animations: [],
|
||||||
|
|
||||||
register: function (name, animDict, animName, duration, loop, flag, endless) {
|
register: function (name, animDict, animName, duration, loop, flag, endless, eventAfter: string = null) {
|
||||||
let id = mp.game.joaat(name);
|
let id = mp.game.joaat(name);
|
||||||
|
|
||||||
if (!this.animations.hasOwnProperty(id)) {
|
if (!this.animations.hasOwnProperty(id)) {
|
||||||
@@ -17,7 +17,8 @@ const animationSyncData =
|
|||||||
duration: duration,
|
duration: duration,
|
||||||
loop: loop,
|
loop: loop,
|
||||||
flag: flag,
|
flag: flag,
|
||||||
endless: endless
|
endless: endless,
|
||||||
|
eventAfter: eventAfter
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
mp.game.graphics.notify("Animation Sync Error: ~r~Duplicate Entry");
|
mp.game.graphics.notify("Animation Sync Error: ~r~Duplicate Entry");
|
||||||
@@ -50,6 +51,10 @@ export default function animationSync() {
|
|||||||
animationSyncData.register("hup", "mp_am_hold_up", "handsup_base", -1, true, 50, true);
|
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("carryBox", "anim@heists@box_carry@", "idle", -1, true, 50, true);
|
||||||
animationSyncData.register("manufacturJoint", "anim@mp_snowball", "pickup_snowball", 1000 * 10, false, 1, false);
|
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("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);
|
||||||
});
|
});
|
||||||
|
|
||||||
const animationBreakMessage = [
|
const animationBreakMessage = [
|
||||||
@@ -115,7 +120,7 @@ export default function animationSync() {
|
|||||||
|
|
||||||
let animData = animationSyncData.animations[index];
|
let animData = animationSyncData.animations[index];
|
||||||
|
|
||||||
let { id, name, animDict, animName, duration, loop, flag, endless } = animData;
|
let { id, name, animDict, animName, duration, loop, flag, endless, eventAfter } = animData;
|
||||||
|
|
||||||
loadAnimDict(animDict, function () {
|
loadAnimDict(animDict, function () {
|
||||||
mp.players.exists(entity) && 0 !== entity.handle && entity.taskPlayAnim(animDict, animName, 1, 0, duration, parseInt(flag), 0, !1, !1, !1)
|
mp.players.exists(entity) && 0 !== entity.handle && entity.taskPlayAnim(animDict, animName, 1, 0, duration, parseInt(flag), 0, !1, !1, !1)
|
||||||
@@ -130,6 +135,9 @@ export default function animationSync() {
|
|||||||
let a = setTimeout(function () {
|
let a = setTimeout(function () {
|
||||||
clearTimeout(a);
|
clearTimeout(a);
|
||||||
mp.events.callRemote("CLIENT:ClearAnimationData", true);
|
mp.events.callRemote("CLIENT:ClearAnimationData", true);
|
||||||
|
if (eventAfter) {
|
||||||
|
mp.events.callRemote("CLIENT:" + eventAfter);
|
||||||
|
}
|
||||||
}, duration);
|
}, duration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { IGame, IEntity } from "../game";
|
import { IGame, IEntity } from "../game";
|
||||||
|
import { hanfPlantObjects } from "../drugs/hanf";
|
||||||
|
|
||||||
export default function attachmentManager(game: IGame) {
|
export default function attachmentManager(game: IGame) {
|
||||||
mp.events.add("SERVER:LoadAttachments", () => {
|
mp.events.add("SERVER:LoadAttachments", () => {
|
||||||
@@ -9,6 +10,10 @@ export default function attachmentManager(game: IGame) {
|
|||||||
attachmentMngr.register("weapondeal1", "ex_office_swag_guns02", "chassis_dummy", new mp.Vector3(0, 0.8, 0), new mp.Vector3(0, 0, 0));
|
attachmentMngr.register("weapondeal1", "ex_office_swag_guns02", "chassis_dummy", new mp.Vector3(0, 0.8, 0), new mp.Vector3(0, 0, 0));
|
||||||
attachmentMngr.register("weapondeal2", "w_sg_pumpshotgun", "chassis_dummy", new mp.Vector3(0.4, 1.6, 0.62), new mp.Vector3(90, 0, 180));
|
attachmentMngr.register("weapondeal2", "w_sg_pumpshotgun", "chassis_dummy", new mp.Vector3(0.4, 1.6, 0.62), new mp.Vector3(90, 0, 180));
|
||||||
attachmentMngr.register("handcuffs", "p_cs_cuffs_02_s", 28422, new mp.Vector3(-0.05, 0, 0), new mp.Vector3(90, 90, 0));
|
attachmentMngr.register("handcuffs", "p_cs_cuffs_02_s", 28422, new mp.Vector3(-0.05, 0, 0), new mp.Vector3(90, 90, 0));
|
||||||
|
attachmentMngr.register("shovel", "prop_cs_trowel", 28422, new mp.Vector3(0.1, 0.0, 0.0), new mp.Vector3(120, 70, 0));
|
||||||
|
attachmentMngr.register("CannabisPlantInHand1", hanfPlantObjects.stage1, 28422, new mp.Vector3(), new mp.Vector3());
|
||||||
|
attachmentMngr.register("CannabisPlantInHand2", hanfPlantObjects.stage3, 28422, new mp.Vector3(), new mp.Vector3());
|
||||||
|
attachmentMngr.register("CannabisPlantInHand3", hanfPlantObjects.stage4, 28422, new mp.Vector3(), new mp.Vector3());
|
||||||
});
|
});
|
||||||
|
|
||||||
const attachmentMngr =
|
const attachmentMngr =
|
||||||
@@ -140,7 +145,7 @@ export default function attachmentManager(game: IGame) {
|
|||||||
targetEntity, bone,
|
targetEntity, bone,
|
||||||
offset.x, offset.y, offset.z,
|
offset.x, offset.y, offset.z,
|
||||||
rotation.x, rotation.y, rotation.z,
|
rotation.x, rotation.y, rotation.z,
|
||||||
false, false, false, false, 2, true
|
true, false, false, false, 0, true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,6 +129,10 @@ namespace ReallifeGamemode.Database.Entities
|
|||||||
|
|
||||||
public bool FreeSurgery { get; set; } = true;
|
public bool FreeSurgery { get; set; } = true;
|
||||||
|
|
||||||
|
public DateTime? LastTimeBoughtCannabisSeeds { get; set; }
|
||||||
|
|
||||||
|
public int CannabisSeedsBoughtToday { get; set; }
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Player Player
|
public Player Player
|
||||||
{
|
{
|
||||||
|
|||||||
2229
ReallifeGamemode.Database/Migrations/20210527144901_AddUserCannabisSeedBuyData.Designer.cs
generated
Normal file
2229
ReallifeGamemode.Database/Migrations/20210527144901_AddUserCannabisSeedBuyData.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace ReallifeGamemode.Database.Migrations
|
||||||
|
{
|
||||||
|
public partial class AddUserCannabisSeedBuyData : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "CannabisSeedsBoughtToday",
|
||||||
|
table: "Users",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "LastTimeBoughtCannabisSeeds",
|
||||||
|
table: "Users",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "CannabisSeedsBoughtToday",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "LastTimeBoughtCannabisSeeds",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1456,6 +1456,9 @@ namespace ReallifeGamemode.Database.Migrations
|
|||||||
b.Property<int?>("BusinessId")
|
b.Property<int?>("BusinessId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("CannabisSeedsBoughtToday")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int?>("CharacterId")
|
b.Property<int?>("CharacterId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
@@ -1505,6 +1508,9 @@ namespace ReallifeGamemode.Database.Migrations
|
|||||||
b.Property<int?>("JobId")
|
b.Property<int?>("JobId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("LastTimeBoughtCannabisSeeds")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
b.Property<int>("LogUserId")
|
b.Property<int>("LogUserId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace ReallifeGamemode.Server
|
|||||||
{
|
{
|
||||||
public abstract class BaseScript : Script
|
public abstract class BaseScript : Script
|
||||||
{
|
{
|
||||||
protected readonly ILogger logger;
|
protected static ILogger logger { get; private set; }
|
||||||
|
|
||||||
public BaseScript()
|
public BaseScript()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -47,6 +47,14 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(player.HasData("IsCarryingPlant") || player.GetData<bool>("IsCarryingPlant"))
|
||||||
|
{
|
||||||
|
var currentModel = player.GetData<int>("HoldingCannabisPlant");
|
||||||
|
|
||||||
|
player.AddAttachment("CannabisPlantInHand" + currentModel, true);
|
||||||
|
player.ResetData("IsCarryingPlant");
|
||||||
|
}
|
||||||
|
|
||||||
using var dbContext = new DatabaseContext();
|
using var dbContext = new DatabaseContext();
|
||||||
|
|
||||||
User user = player.GetUser(dbContext);
|
User user = player.GetUser(dbContext);
|
||||||
|
|||||||
@@ -41,6 +41,14 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (player.HasData("IsCarryingPlant") || player.GetData<bool>("IsCarryingPlant"))
|
||||||
|
{
|
||||||
|
var currentModel = player.GetData<int>("HoldingCannabisPlant");
|
||||||
|
|
||||||
|
player.AddAttachment("CannabisPlantInHand" + currentModel, true);
|
||||||
|
player.ResetData("IsCarryingPlant");
|
||||||
|
}
|
||||||
|
|
||||||
var logEntry = new LoginLogoutLogEntry()
|
var logEntry = new LoginLogoutLogEntry()
|
||||||
{
|
{
|
||||||
LoginLogout = false,
|
LoginLogout = false,
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ using ReallifeGamemode.Server.Types;
|
|||||||
using ReallifeGamemode.Server.Util;
|
using ReallifeGamemode.Server.Util;
|
||||||
using ReallifeGamemode.Server.WeaponDeal;
|
using ReallifeGamemode.Server.WeaponDeal;
|
||||||
using ReallifeGamemode.Server.Log;
|
using ReallifeGamemode.Server.Log;
|
||||||
|
using ReallifeGamemode.Server.Inventory.Items;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using ReallifeGamemode.Server.Wanted;
|
using ReallifeGamemode.Server.Wanted;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -217,9 +219,61 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
[RemoteEvent("keyPress:E")]
|
[RemoteEvent("keyPress:E")]
|
||||||
public void KeyPressE(Player player)
|
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();
|
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"))
|
if (player.HasData("nearATM"))
|
||||||
{
|
{
|
||||||
ATMManager.ShowAtmUi(player, player.GetData<int>("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);
|
JailPoint nearestjailPoint = PositionManager.jailPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.5);
|
||||||
bool isNearCannabisSeedBuyPoint = HanfManager.IsPlayerNearSeedBuyPoint(player);
|
bool isNearCannabisSeedBuyPoint = HanfManager.IsPlayerNearSeedBuyPoint(player);
|
||||||
bool isNearJointManufacturerPoint = HanfManager.IsPlayerNearJointManufacturer(player);
|
bool isNearJointManufacturerPoint = HanfManager.IsPlayerNearJointManufacturer(player);
|
||||||
|
bool isNearCannabisSellPoint = HanfManager.IsPlayerNearCannabisSellPoint(player);
|
||||||
|
|
||||||
if (user?.FactionId != null)
|
if (user?.FactionId != null)
|
||||||
{
|
{
|
||||||
@@ -766,7 +821,7 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
|
|
||||||
if (isNearCannabisSeedBuyPoint)
|
if (isNearCannabisSeedBuyPoint)
|
||||||
{
|
{
|
||||||
player.TriggerEvent("SERVER:Hanf_BuySeed", HanfManager.SEED_PRICE);
|
HanfManager.ShowPlayerBuySeedMenu(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -775,6 +830,39 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
HanfManager.BuildJointsFromCannabis(player);
|
HanfManager.BuildJointsFromCannabis(player);
|
||||||
return;
|
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")]
|
[RemoteEvent("keyPress:I")]
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using GTANetworkAPI;
|
using GTANetworkAPI;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using ReallifeGamemode.Database.Entities;
|
using ReallifeGamemode.Database.Entities;
|
||||||
using ReallifeGamemode.Database.Models;
|
using ReallifeGamemode.Database.Models;
|
||||||
using ReallifeGamemode.Server.Extensions;
|
using ReallifeGamemode.Server.Extensions;
|
||||||
using ReallifeGamemode.Server.Types;
|
using ReallifeGamemode.Server.Types;
|
||||||
using ReallifeGamemode.Server.Util;
|
using ReallifeGamemode.Server.Util;
|
||||||
using ReallifeGamemode.Server.WeaponDeal;
|
using ReallifeGamemode.Server.WeaponDeal;
|
||||||
|
using ReallifeGamemode.Server.Log;
|
||||||
|
|
||||||
namespace ReallifeGamemode.Server.Events
|
namespace ReallifeGamemode.Server.Events
|
||||||
{
|
{
|
||||||
public class Vehicle : Script
|
public class Vehicle : Script
|
||||||
{
|
{
|
||||||
|
private static readonly ILogger logger = LogManager.GetLogger<Vehicle>();
|
||||||
|
|
||||||
[RemoteEvent("VehicleMenu_ToggleEngine")]
|
[RemoteEvent("VehicleMenu_ToggleEngine")]
|
||||||
public void VehicleMenuToggleEngineEvent(Player player)
|
public void VehicleMenuToggleEngineEvent(Player player)
|
||||||
{
|
{
|
||||||
@@ -271,6 +275,8 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
sV.PositionZ = pos.Z;
|
sV.PositionZ = pos.Z;
|
||||||
sV.Heading = v.Heading;
|
sV.Heading = v.Heading;
|
||||||
|
|
||||||
|
logger.LogInformation("Player {0} parked the car {1} at x:{2}, y:{3}, z:{4}", player.Name, sV.Id, pos.X, pos.Y, pos.Z);
|
||||||
|
|
||||||
|
|
||||||
player.SendNotification("~g~Das Fahrzeug wurde geparkt.");
|
player.SendNotification("~g~Das Fahrzeug wurde geparkt.");
|
||||||
|
|
||||||
|
|||||||
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
|
namespace ReallifeGamemode.Server.Inventory.Items
|
||||||
{
|
{
|
||||||
public class Cannabis : DropItem
|
public class Cannabis : DropItem, IIllegalItem
|
||||||
{
|
{
|
||||||
public override int Id => 108;
|
public override int Id => 108;
|
||||||
|
|
||||||
@@ -24,5 +24,9 @@ namespace ReallifeGamemode.Server.Inventory.Items
|
|||||||
public override uint Object => 3076948544;
|
public override uint Object => 3076948544;
|
||||||
|
|
||||||
public override int Price => 0;
|
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.Entities;
|
||||||
using ReallifeGamemode.Database.Models;
|
using ReallifeGamemode.Database.Models;
|
||||||
using ReallifeGamemode.Server.Extensions;
|
using ReallifeGamemode.Server.Extensions;
|
||||||
|
using ReallifeGamemode.Server.Inventory.Interfaces;
|
||||||
using ReallifeGamemode.Server.Managers;
|
using ReallifeGamemode.Server.Managers;
|
||||||
|
|
||||||
namespace ReallifeGamemode.Server.Inventory.Items
|
namespace ReallifeGamemode.Server.Inventory.Items
|
||||||
{
|
{
|
||||||
public class CannabisSeeds : UseItem
|
public class CannabisSeeds : UseItem, IIllegalItem
|
||||||
{
|
{
|
||||||
public override int Id { get; } = 109;
|
public override int Id { get; } = 109;
|
||||||
public override string Name { get; } = "Cannabis Samen";
|
public override string Name { get; } = "Cannabis Samen";
|
||||||
@@ -21,6 +22,7 @@ namespace ReallifeGamemode.Server.Inventory.Items
|
|||||||
|
|
||||||
public override uint Object { get; }
|
public override uint Object { get; }
|
||||||
public override bool RemoveWhenUsed { get; } = false;
|
public override bool RemoveWhenUsed { get; } = false;
|
||||||
|
public int PriceForConfiscation { get; } = 10;
|
||||||
|
|
||||||
public override bool Use(Player player, User user, DatabaseContext databaseContext)
|
public override bool Use(Player player, User user, DatabaseContext databaseContext)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,12 +5,16 @@ using GTANetworkAPI;
|
|||||||
using ReallifeGamemode.Database.Entities;
|
using ReallifeGamemode.Database.Entities;
|
||||||
using ReallifeGamemode.Database.Models;
|
using ReallifeGamemode.Database.Models;
|
||||||
using ReallifeGamemode.Server.Extensions;
|
using ReallifeGamemode.Server.Extensions;
|
||||||
|
using ReallifeGamemode.Server.Inventory.Interfaces;
|
||||||
using ReallifeGamemode.Server.Util;
|
using ReallifeGamemode.Server.Util;
|
||||||
|
|
||||||
namespace ReallifeGamemode.Server.Inventory.Items
|
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 int Id { get; } = 110;
|
||||||
public override string Name { get; } = "Joint";
|
public override string Name { get; } = "Joint";
|
||||||
public override string Description { get; } = "stay high bis zum tod";
|
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 Legal => false;
|
||||||
public override bool RemoveWhenUsed => true;
|
public override bool RemoveWhenUsed => true;
|
||||||
|
|
||||||
|
public int PriceForConfiscation { get; } = 25;
|
||||||
|
|
||||||
public override bool Use(Player player, User user, DatabaseContext databaseContext)
|
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);
|
player.ToggleInventory(InventoryToggleOption.HIDE);
|
||||||
|
int armorToSet = Math.Min(player.Armor + 25, 100);
|
||||||
|
player.SafeSetArmor(armorToSet);
|
||||||
|
lastJointUse[user.Id] = DateTime.Now;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool CanUserUseJoint(User user)
|
||||||
|
{
|
||||||
|
if(!lastJointUse.ContainsKey(user.Id))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DateTime.Now - lastJointUse[user.Id] > _jointCooldown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using GTANetworkAPI;
|
using GTANetworkAPI;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using ReallifeGamemode.Database.Entities;
|
using ReallifeGamemode.Database.Entities;
|
||||||
@@ -12,6 +13,7 @@ using ReallifeGamemode.Server.Extensions;
|
|||||||
using ReallifeGamemode.Server.Inventory.Interfaces;
|
using ReallifeGamemode.Server.Inventory.Interfaces;
|
||||||
using ReallifeGamemode.Server.Inventory.Items;
|
using ReallifeGamemode.Server.Inventory.Items;
|
||||||
using ReallifeGamemode.Server.Services;
|
using ReallifeGamemode.Server.Services;
|
||||||
|
using ReallifeGamemode.Server.Types;
|
||||||
using ReallifeGamemode.Server.Util;
|
using ReallifeGamemode.Server.Util;
|
||||||
|
|
||||||
namespace ReallifeGamemode.Server.Managers
|
namespace ReallifeGamemode.Server.Managers
|
||||||
@@ -23,10 +25,28 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly static List<Vector3> _seedsBuyPoints = new List<Vector3>();
|
private readonly static List<Vector3> _seedsBuyPoints = new List<Vector3>();
|
||||||
|
|
||||||
|
private readonly static List<Vector3> _cannabisSellPoints = new List<Vector3>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Aktueller Samen-Preis
|
/// Aktueller Samen-Preis
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static int SEED_PRICE = 50;
|
public static int SEED_PRICE = 0;
|
||||||
|
|
||||||
|
private const int SEED_PRICE_MIN = 40;
|
||||||
|
private const int SEED_PRICE_MAX = 75;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Aktueller Hanf-Verkaufspreis
|
||||||
|
/// </summary>
|
||||||
|
public static int CANNABIS_PRICE = 0;
|
||||||
|
|
||||||
|
private const int CANNABIS_PRICE_MIN = 50;
|
||||||
|
private const int CANNABIS_PRICE_MAX = 125;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wie viele Samen ein Spieler pro Tag maximal kaufen darf
|
||||||
|
/// </summary>
|
||||||
|
private const int MAX_SEEDS_PER_DAY = 50;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wie viele Joints man aus einem Cannabis bekommt
|
/// Wie viele Joints man aus einem Cannabis bekommt
|
||||||
@@ -72,6 +92,8 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
|
|
||||||
private static List<CannabisData> _currentCannabisData = new List<CannabisData>();
|
private static List<CannabisData> _currentCannabisData = new List<CannabisData>();
|
||||||
|
|
||||||
|
public static readonly Vector3 ASSERVATENKAMMER_POSITION = new Vector3(-5.45, -670.03, 32.33);
|
||||||
|
|
||||||
static HanfManager()
|
static HanfManager()
|
||||||
{
|
{
|
||||||
_manufacturerDoneTimer.Elapsed += ManufacturerDoneTimerCallback;
|
_manufacturerDoneTimer.Elapsed += ManufacturerDoneTimerCallback;
|
||||||
@@ -82,6 +104,12 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Load()
|
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(-30.21876, -585.3222, 17.917326));
|
||||||
_seedsBuyPoints.Add(new Vector3(-680.89386, -634.6783, 25.29923));
|
_seedsBuyPoints.Add(new Vector3(-680.89386, -634.6783, 25.29923));
|
||||||
_seedsBuyPoints.Add(new Vector3(-1310.743, -608.9064, 29.382874));
|
_seedsBuyPoints.Add(new Vector3(-1310.743, -608.9064, 29.382874));
|
||||||
@@ -92,17 +120,58 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
|
|
||||||
foreach (Vector3 buyPoint in _seedsBuyPoints)
|
foreach (Vector3 buyPoint in _seedsBuyPoints)
|
||||||
{
|
{
|
||||||
colShape = NAPI.ColShape.CreateSphereColShape(buyPoint, 20.0f);
|
colShape = NAPI.ColShape.CreateSphereColShape(buyPoint, 10.0f);
|
||||||
colShape.OnEntityEnterColShape += OnSeedBuyRangeColShapeEnter;
|
colShape.OnEntityEnterColShape += OnSeedBuyRangeColShapeEnter;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateHanfWorldData(new DatabaseContext());
|
_cannabisSellPoints.Add(new Vector3(2220.04, 5614.24, 54.72));
|
||||||
|
_cannabisSellPoints.Add(new Vector3(201.77, 2442.06, 60.45));
|
||||||
|
_cannabisSellPoints.Add(new Vector3(155.87, -3103.26, 7.03));
|
||||||
|
|
||||||
|
foreach (Vector3 sellPoint in _cannabisSellPoints)
|
||||||
|
{
|
||||||
|
colShape = NAPI.ColShape.CreateSphereColShape(sellPoint, 10.0f);
|
||||||
|
colShape.OnEntityEnterColShape += OnCannabisSellRangeColShapeEnter;
|
||||||
|
}
|
||||||
|
|
||||||
|
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, um den ~y~Riot~s~ zu entladen", ASSERVATENKAMMER_POSITION, 10.0f, 10.0f, 0, Colors.White);
|
||||||
|
|
||||||
|
using var dbContext = new DatabaseContext();
|
||||||
|
HarvestRottenPlants(dbContext);
|
||||||
|
UpdateHanfWorldData(dbContext);
|
||||||
|
|
||||||
Timer updateHanfDataTimer = new Timer(TimeSpan.FromMinutes(1).TotalMilliseconds);
|
Timer updateHanfDataTimer = new Timer(TimeSpan.FromMinutes(1).TotalMilliseconds);
|
||||||
updateHanfDataTimer.Elapsed += UpdateHanfDataTimer_Elapsed;
|
updateHanfDataTimer.Elapsed += UpdateHanfDataTimer_Elapsed;
|
||||||
updateHanfDataTimer.Start();
|
updateHanfDataTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void OnCannabisSellRangeColShapeEnter(ColShape colShape, Player player)
|
||||||
|
{
|
||||||
|
if (!player.IsLoggedIn())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = player.GetUser();
|
||||||
|
if (user?.Faction?.StateOwned == true)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatService.SendMessage(player, $"Fremder sagt: Pssst.. Hier kannst du dein Brokkoli loswerden.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void HarvestRottenPlants(DatabaseContext dbContext)
|
||||||
|
{
|
||||||
|
var rottenPlants = dbContext.CannabisPlants.Where(p => EF.Functions.DateDiffHour(p.PlantDate, DateTime.Now) > MAX_PLANT_TIME.TotalHours);
|
||||||
|
foreach (var plant in rottenPlants)
|
||||||
|
{
|
||||||
|
plant.Harvested = true;
|
||||||
|
}
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
private static void UpdateHanfDataTimer_Elapsed(object sender, ElapsedEventArgs e)
|
private static void UpdateHanfDataTimer_Elapsed(object sender, ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
using var dbContext = new DatabaseContext();
|
using var dbContext = new DatabaseContext();
|
||||||
@@ -148,7 +217,7 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
var user = player.GetUser(dbContext);
|
var user = player.GetUser(dbContext);
|
||||||
if (user.Faction?.StateOwned ?? false)
|
if (user.Faction?.StateOwned ?? false)
|
||||||
{
|
{
|
||||||
player.SendNotification("~r~Du darfst keine Hanfsamen einfplanzen");
|
player.SendNotification("~r~Du darfst keine Hanfsamen einpflanzen");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +289,7 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
public async static void UpdateHanfForPlayer(Player player, List<CannabisData> cannabisData = null)
|
public async static void UpdateHanfForPlayer(Player player, List<CannabisData> cannabisData = null)
|
||||||
{
|
{
|
||||||
cannabisData ??= _currentCannabisData;
|
cannabisData ??= _currentCannabisData;
|
||||||
var x = await NAPI.Task.WaitForMainThread();
|
await NAPI.Task.WaitForMainThread();
|
||||||
player.TriggerEvent("SERVER:Hanf_UpdateHanfData", JsonConvert.SerializeObject(cannabisData));
|
player.TriggerEvent("SERVER:Hanf_UpdateHanfData", JsonConvert.SerializeObject(cannabisData));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,6 +304,12 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
using var dbContext = new DatabaseContext();
|
using var dbContext = new DatabaseContext();
|
||||||
var user = player.GetUser(dbContext);
|
var user = player.GetUser(dbContext);
|
||||||
|
|
||||||
|
if (amount > GetAmountOfCannabisSeedsPlayerCanBuyToday(user))
|
||||||
|
{
|
||||||
|
player.SendNotification("~r~Du kannst heute nicht mehr so viele Samen kaufen");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
IItem seedItem = InventoryManager.GetItem<CannabisSeeds>();
|
IItem seedItem = InventoryManager.GetItem<CannabisSeeds>();
|
||||||
var newAmount = seedItem.Gewicht * amount;
|
var newAmount = seedItem.Gewicht * amount;
|
||||||
|
|
||||||
@@ -254,6 +329,16 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
|
|
||||||
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, SEED_PRICE); // <-- WICHTIG LOGS
|
||||||
|
|
||||||
|
if (user.LastTimeBoughtCannabisSeeds == null || user.LastTimeBoughtCannabisSeeds.Value.Date != DateTime.Now.Date)
|
||||||
|
{
|
||||||
|
user.CannabisSeedsBoughtToday = amount;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
user.CannabisSeedsBoughtToday += amount;
|
||||||
|
}
|
||||||
|
user.LastTimeBoughtCannabisSeeds = DateTime.Now;
|
||||||
|
|
||||||
user.Handmoney -= price;
|
user.Handmoney -= price;
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
@@ -263,7 +348,7 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[RemoteEvent("CLIENT:Hanf_HarvestHanf")]
|
[RemoteEvent("CLIENT:Hanf_HarvestHanf")]
|
||||||
public void HanfManagerHarvestHanf(Player player, long hanfId)
|
public async void HanfManagerHarvestHanf(Player player, long hanfId)
|
||||||
{
|
{
|
||||||
if (!player.IsLoggedIn())
|
if (!player.IsLoggedIn())
|
||||||
{
|
{
|
||||||
@@ -273,15 +358,10 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
using var dbContext = new DatabaseContext();
|
using var dbContext = new DatabaseContext();
|
||||||
|
|
||||||
User user = player.GetUser(dbContext);
|
User user = player.GetUser(dbContext);
|
||||||
CannabisPlant plant = dbContext.CannabisPlants.Find(hanfId);
|
CannabisPlant plant = dbContext.CannabisPlants.Include(p => p.PlantedBy).Where(p => p.Id == hanfId).FirstOrDefault();
|
||||||
if (plant == null)
|
if (plant == null)
|
||||||
{
|
{
|
||||||
logger.LogError("Player {0} tried to harvest cannabis plant {1} but it was not found in database", player.Name, hanfId);
|
logger.LogError("Player {0} tried to harvest cannabis plant {1} but it was not found in database", player.Name, hanfId);
|
||||||
}
|
|
||||||
|
|
||||||
if (user.Faction?.StateOwned == true && !(user.FactionId == 3 && player.IsDuty()))
|
|
||||||
{
|
|
||||||
player.SendNotification("~r~Du kannst kein Hanf ernten");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,10 +370,32 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plant.Harvested = true;
|
if (player.IsAdminDuty() && player.IsTSupport() && user.IsAdmin(AdminLevel.ADMIN))
|
||||||
|
|
||||||
if (user.FactionId != 3) // Zivi / Gangmember erntet ab
|
|
||||||
{
|
{
|
||||||
|
player.SendNotification($"Du hast die Hanf-Pflanze von ~y~{plant.PlantedBy.Name}~s~ entfernt");
|
||||||
|
plant.Harvested = true;
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
UpdateHanfWorldData(dbContext);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.Faction?.StateOwned == true)
|
||||||
|
{
|
||||||
|
if (!((user.FactionId == 1 || user.FactionId == 3) && player.IsDuty()))
|
||||||
|
{
|
||||||
|
player.SendNotification("~r~Du kannst kein Hanf ernten");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//player.SyncAnimation(new[] { "harvestPlantEnter", "harvestPlant", "harvestPlantExit" }.ToList());
|
||||||
|
//player.SyncAnimation("harvestPlant");
|
||||||
|
//player.AddAttachment("shovel", false);
|
||||||
|
|
||||||
|
if (user.FactionId != 3 && user.FactionId != 1) // Zivi / Gangmember erntet ab
|
||||||
|
{
|
||||||
|
player.SyncAnimation("harvestPlant");
|
||||||
|
plant.Harvested = true;
|
||||||
bool isPlantRotten = DateTime.Now - plant.PlantDate > MAX_PLANT_TIME;
|
bool isPlantRotten = DateTime.Now - plant.PlantDate > MAX_PLANT_TIME;
|
||||||
if (isPlantRotten)
|
if (isPlantRotten)
|
||||||
{
|
{
|
||||||
@@ -340,15 +442,32 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // FIB erntet ab
|
else // FIB / LSPD erntet ab
|
||||||
{
|
{
|
||||||
|
if (!(player.HasData("IsCarryingPlant") || player.GetData<bool>("IsCarryingPlant")))
|
||||||
|
{
|
||||||
|
player.SetData("IsCarryingPlant", true);
|
||||||
|
|
||||||
|
player.SendNotification($"Du hast eine Pflanze von ~y~{plant.PlantedBy.Name}~s~ ausgegraben");
|
||||||
|
|
||||||
|
player.SyncAnimation("harvestPlant");
|
||||||
|
plant.Harvested = true;
|
||||||
|
|
||||||
|
var modelToGet = await player.TriggerProcedure("SERVER:Hanf_GetModelToGivePlayer", plant.Id);
|
||||||
|
player.SetData("HoldingCannabisPlant", modelToGet);
|
||||||
|
player.AddAttachment("CannabisPlantInHand" + modelToGet, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
UpdateHanfWorldData(dbContext);
|
UpdateHanfWorldData(dbContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool IsPlayerNearCannabisSellPoint(Player player)
|
||||||
|
{
|
||||||
|
return _cannabisSellPoints.Any(p => p.DistanceTo(player.Position) <= 3);
|
||||||
|
}
|
||||||
|
|
||||||
internal static void BuildJointsFromCannabis(Player player)
|
internal static void BuildJointsFromCannabis(Player player)
|
||||||
{
|
{
|
||||||
if (player.HasAnimation(_manufacturerAnim) || _manufacturerCurrentlyUsed)
|
if (player.HasAnimation(_manufacturerAnim) || _manufacturerCurrentlyUsed)
|
||||||
@@ -396,5 +515,105 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
_manufacturerDoneTimer.Stop();
|
_manufacturerDoneTimer.Stop();
|
||||||
_manufacturerCurrentlyUsed = false;
|
_manufacturerCurrentlyUsed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RemoteEvent("CLIENT:Hanf_FinishDiggingAnimation")]
|
||||||
|
public void HanfManagerFinishDiggingAnimation(Player player)
|
||||||
|
{
|
||||||
|
player.AddAttachment("shovel", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int GetAmountOfCannabisSeedsPlayerCanBuyToday(User user)
|
||||||
|
{
|
||||||
|
if (user.LastTimeBoughtCannabisSeeds == null)
|
||||||
|
{
|
||||||
|
return MAX_SEEDS_PER_DAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.LastTimeBoughtCannabisSeeds.Value.Date != DateTime.Now.Date)
|
||||||
|
{
|
||||||
|
return MAX_SEEDS_PER_DAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MAX_SEEDS_PER_DAY - user.CannabisSeedsBoughtToday;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void ShowPlayerBuySeedMenu(Player player)
|
||||||
|
{
|
||||||
|
var user = player.GetUser();
|
||||||
|
|
||||||
|
if (user.Faction?.StateOwned == true)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var seedsUserCanBuy = GetAmountOfCannabisSeedsPlayerCanBuyToday(user);
|
||||||
|
|
||||||
|
if (seedsUserCanBuy == 0)
|
||||||
|
{
|
||||||
|
player.SendNotification("~r~Du kannst heute keine Samen mehr kaufen");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.TriggerEvent("SERVER:Hanf_BuySeed", seedsUserCanBuy, SEED_PRICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void PlayerSellCannabis(Player player)
|
||||||
|
{
|
||||||
|
if (!player.IsLoggedIn())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
using var dbContext = new DatabaseContext();
|
||||||
|
var user = player.GetUser(dbContext);
|
||||||
|
|
||||||
|
if (user.Faction?.StateOwned == true)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UserItem> items = InventoryManager.GetUserItems(player, dbContext);
|
||||||
|
|
||||||
|
IItem cannabisItem = InventoryManager.GetItem<Cannabis>();
|
||||||
|
var cannabisAmount = items.Where(i => i.ItemId == cannabisItem.Id).FirstOrDefault()?.Amount ?? 0;
|
||||||
|
|
||||||
|
if (cannabisAmount == 0)
|
||||||
|
{
|
||||||
|
player.SendNotification("~r~Du hast kein Cannabis dabei");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.TriggerEvent("SERVER:Hanf_SellCannabisMenu", cannabisAmount, CANNABIS_PRICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
[RemoteEvent("CLIENT:Hanf_SellCannabis")]
|
||||||
|
public void HanfManagerSellCannabis(Player player, int amount)
|
||||||
|
{
|
||||||
|
if (!player.IsLoggedIn())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var dbContext = new DatabaseContext();
|
||||||
|
var user = player.GetUser(dbContext);
|
||||||
|
List<UserItem> items = InventoryManager.GetUserItems(player, dbContext);
|
||||||
|
|
||||||
|
IItem cannabisItem = InventoryManager.GetItem<Cannabis>();
|
||||||
|
var cannabisUserItem = items.Where(i => i.ItemId == cannabisItem.Id).FirstOrDefault();
|
||||||
|
var cannabisAmount = cannabisUserItem?.Amount ?? 0;
|
||||||
|
|
||||||
|
if (cannabisAmount < amount)
|
||||||
|
{
|
||||||
|
player.SendNotification("~r~Du hast nicht so viel Cannabis dabei");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var price = amount * CANNABIS_PRICE;
|
||||||
|
user.Handmoney += price;
|
||||||
|
InventoryManager.RemoveUserItem(user, cannabisUserItem, amount);
|
||||||
|
|
||||||
|
logger.LogInformation("Player {0} sold {1} cannabis to the server for {2} dollars", player.Name, amount, price);
|
||||||
|
|
||||||
|
player.SendNotification($"Du hast ~g~{amount} Hanfblüten~s~ für ~g~{price.ToMoneyString()}~s~ verkauft");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ using ReallifeGamemode.Server.Core.API;
|
|||||||
using ReallifeGamemode.Server.Factions.Medic;
|
using ReallifeGamemode.Server.Factions.Medic;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using ReallifeGamemode.Server.Log;
|
using ReallifeGamemode.Server.Log;
|
||||||
|
using ReallifeGamemode.Server.Inventory.Interfaces;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @overview Life of German Reallife - Managers Interaction (InteractionManager.cs)
|
* @overview Life of German Reallife - Managers Interaction (InteractionManager.cs)
|
||||||
@@ -758,6 +759,150 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RemoteEvent("CLIENT:InteractionMenu_LSPD_FriskUser")]
|
||||||
|
public void InteractionMenuLspdFriskUser(Player player, string name)
|
||||||
|
{
|
||||||
|
if (!player.IsLoggedIn())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player target = PlayerService.GetPlayerByNameOrId(name);
|
||||||
|
if (!target.IsLoggedIn())
|
||||||
|
{
|
||||||
|
ChatService.PlayerNotFound(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var dbContext = new DatabaseContext();
|
||||||
|
var user = player.GetUser(dbContext);
|
||||||
|
|
||||||
|
if ((user.FactionId != 1 && user.FactionId != 3) || !player.IsDuty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.Position.DistanceTo(target.Position) > 5)
|
||||||
|
{
|
||||||
|
player.SendNotification("~r~Der Spieler ist nicht in deiner Nähe");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var targetUser = target.GetUser(dbContext);
|
||||||
|
|
||||||
|
var targetItems = InventoryManager.GetUserItems(target, dbContext);
|
||||||
|
List<string> illItemsList = new List<string>();
|
||||||
|
bool illegalItemsFound = false;
|
||||||
|
var price = 0;
|
||||||
|
|
||||||
|
foreach (var targetItem in targetItems)
|
||||||
|
{
|
||||||
|
IItem item = InventoryManager.GetItemById(targetItem.ItemId);
|
||||||
|
if (!item.Legal)
|
||||||
|
{
|
||||||
|
illItemsList.Add($"{targetItem.Amount}x {item.Name}");
|
||||||
|
InventoryManager.RemoveUserItem(targetUser, targetItem, targetItem.Amount);
|
||||||
|
illegalItemsFound = true;
|
||||||
|
price += ((IIllegalItem)item).PriceForConfiscation * targetItem.Amount;
|
||||||
|
logger.LogInformation("Player {0} confiscated the illegal item {1} ({2}, amount: {3}) from player {4}", player.Name, item.Name, item.Id, targetItem.Amount, target.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!illegalItemsFound)
|
||||||
|
{
|
||||||
|
player.SendNotification("~g~Der Spieler hat keine illegalen Gegenstände dabei");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.LogInformation("executive factions got {0} dollars from the confiscation", 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
|
string illItemsStr = "~y~" + string.Join("~s~,~y~ ", illItemsList) + "~s~";
|
||||||
|
ChatService.SendMessage(player, $"Du hast ~y~{target.Name}~s~ folgende Gegenstände abgenommen: {illItemsStr}");
|
||||||
|
ChatService.SendMessage(target, $"~y~{player.Name}~s~ hat die folgende Gegenstände abgenommen: {illItemsStr}");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[RemoteEvent("CLIENT:InteractionMenu_LSPD_FriskVehicle")]
|
||||||
|
public void InteractionMenuLspdFriskVehicle(Player player)
|
||||||
|
{
|
||||||
|
if (!player.IsLoggedIn())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var dbContext = new DatabaseContext();
|
||||||
|
var user = player.GetUser(dbContext);
|
||||||
|
|
||||||
|
if ((user.FactionId != 1 && user.FactionId != 3) || !player.IsDuty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var vehicle = NAPI.Pools.GetAllVehicles().Where(v => v.Position.DistanceTo(player.Position) <= 5).OrderBy(v => v.Position.DistanceTo(player.Position)).FirstOrDefault();
|
||||||
|
if (vehicle == null)
|
||||||
|
{
|
||||||
|
player.SendNotification("~r~Es befindet sich kein Fahrzeug in deiner Nähe");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerVehicle serverVehicle = vehicle.GetServerVehicle(dbContext);
|
||||||
|
if (serverVehicle == null)
|
||||||
|
{
|
||||||
|
player.SendNotification("~r~Dieses Fahrzeug kann nicht durchsucht werden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VehicleStreaming.GetLockState(vehicle) || serverVehicle.Locked)
|
||||||
|
{
|
||||||
|
player.SendNotification("~r~Dieses Fahrzeug ist abgeschlossen");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var targetItems = InventoryManager.GetVehicleItems(vehicle);
|
||||||
|
List<string> illItemsList = new List<string>();
|
||||||
|
bool illegalItemsFound = false;
|
||||||
|
var price = 0;
|
||||||
|
|
||||||
|
foreach (var targetItem in targetItems)
|
||||||
|
{
|
||||||
|
IItem item = InventoryManager.GetItemById(targetItem.ItemId);
|
||||||
|
if (!item.Legal)
|
||||||
|
{
|
||||||
|
illItemsList.Add($"{targetItem.Amount}x {item.Name}");
|
||||||
|
InventoryManager.RemoveVehicleItem(serverVehicle, targetItem, targetItem.Amount, null);
|
||||||
|
illegalItemsFound = true;
|
||||||
|
price += ((IIllegalItem)item).PriceForConfiscation * targetItem.Amount;
|
||||||
|
logger.LogInformation("Player {0} confiscated the illegal item {1} ({2}, amount: {3}) from vehicle {4}", player.Name, item.Name, item.Id, targetItem.Amount, serverVehicle.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!illegalItemsFound)
|
||||||
|
{
|
||||||
|
player.SendNotification("~g~Im Kofferraum sind keine illegalen Gegenstände");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.LogInformation("executive factions got {0} dollars from the confiscation", 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
|
string illItemsStr = "~y~" + string.Join("~s~,~y~ ", illItemsList) + "~s~";
|
||||||
|
ChatService.SendInRange(player.Position, 20, $"{player.Name} hat aus dem Kofferraum folgende Gegenstände beschlagnahmt: {illItemsStr}");
|
||||||
|
}
|
||||||
|
|
||||||
[RemoteEvent("CLIENT:InteractionMenu_Pay")]
|
[RemoteEvent("CLIENT:InteractionMenu_Pay")]
|
||||||
public void InteractionMenu_Pay(Player player, string jsonNameOrId, string stringAmount)
|
public void InteractionMenu_Pay(Player player, string jsonNameOrId, string stringAmount)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
public int Amount;
|
public int Amount;
|
||||||
public int ItemId;
|
public int ItemId;
|
||||||
public int Weight;
|
public int Weight;
|
||||||
public Vehicle vehicle;
|
public ushort vehicle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetBackpackItems(Player player)
|
public static void SetBackpackItems(Player player)
|
||||||
@@ -75,9 +75,9 @@ 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
|
internal static T GetItem<T>() where T : IItem
|
||||||
{
|
{
|
||||||
return itemList.Where(i => i.GetType() == typeof(T)).First();
|
return (T)itemList.Where(i => i.GetType() == typeof(T)).First();
|
||||||
}
|
}
|
||||||
|
|
||||||
[RemoteEvent("CLIENT:getVehicleInventory")]
|
[RemoteEvent("CLIENT:getVehicleInventory")]
|
||||||
@@ -86,7 +86,9 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
if (player.IsInVehicle)
|
if (player.IsInVehicle)
|
||||||
{
|
{
|
||||||
player.TriggerEvent("Error", "Du kannst deinen Kofferraum gerade nicht öffnen.");
|
player.TriggerEvent("Error", "Du kannst deinen Kofferraum gerade nicht öffnen.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vehicle veh = NAPI.Pools.GetAllVehicles()
|
Vehicle veh = NAPI.Pools.GetAllVehicles()
|
||||||
.ToList()
|
.ToList()
|
||||||
.Where(v => v.Position.DistanceTo(player.Position) <= 4)
|
.Where(v => v.Position.DistanceTo(player.Position) <= 4)
|
||||||
@@ -131,7 +133,7 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
Amount = i.Amount,
|
Amount = i.Amount,
|
||||||
ItemId = i.ItemId,
|
ItemId = i.ItemId,
|
||||||
Weight = GetVehicleInventoryWeight(veh),
|
Weight = GetVehicleInventoryWeight(veh),
|
||||||
vehicle = veh,
|
vehicle = veh.Handle.Value,
|
||||||
};
|
};
|
||||||
vehicleItems[player].Add(newItem);
|
vehicleItems[player].Add(newItem);
|
||||||
}
|
}
|
||||||
@@ -197,6 +199,10 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
|
|
||||||
public static void RemoveVehicleItem(ServerVehicle sVeh, VehicleItem item, int amount, Player player)
|
public static void RemoveVehicleItem(ServerVehicle sVeh, VehicleItem item, int amount, Player player)
|
||||||
{
|
{
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
using (var dbContext = new DatabaseContext())
|
using (var dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
var vehicleItem = dbContext.VehicleItems.FirstOrDefault(i => i.Id == item.Id);
|
var vehicleItem = dbContext.VehicleItems.FirstOrDefault(i => i.Id == item.Id);
|
||||||
@@ -327,20 +333,29 @@ namespace ReallifeGamemode.Server.Managers
|
|||||||
|
|
||||||
using (var context = new DatabaseContext())
|
using (var context = new DatabaseContext())
|
||||||
{
|
{
|
||||||
|
User user = player.GetUser(context);
|
||||||
if (!vehicleItems.ContainsKey(player))
|
if (!vehicleItems.ContainsKey(player))
|
||||||
vehicleItems.Add(player, new List<InventoryItem>());
|
vehicleItems.Add(player, new List<InventoryItem>());
|
||||||
Vehicle veh = null;
|
Vehicle veh = null;
|
||||||
if (vehicleItems[player].Count != 0)
|
if (vehicleItems[player].Count != 0)
|
||||||
veh = vehicleItems[player].FirstOrDefault().vehicle;
|
veh = new NetHandle(vehicleItems[player].FirstOrDefault().vehicle, EntityType.Vehicle).Entity<Vehicle>();
|
||||||
|
|
||||||
ServerVehicle serverVehicle = VehicleManager.GetServerVehicleFromVehicle(veh, context);
|
ServerVehicle serverVehicle = VehicleManager.GetServerVehicleFromVehicle(veh, context);
|
||||||
|
|
||||||
VehicleItem vehItem = context.VehicleItems.Where(v => v.VehicleId == serverVehicle.Id && v.ItemId == itemID).FirstOrDefault();
|
VehicleItem vehItem = context.VehicleItems.Where(v => v.VehicleId == serverVehicle.Id && v.ItemId == itemID).FirstOrDefault();
|
||||||
if (vehItem == null)
|
if (vehItem == null)
|
||||||
{
|
{
|
||||||
player.TriggerEvent("Error", "Transfer nicht möglich.");
|
player.TriggerEvent("Error", "Transfer nicht möglich.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (serverVehicle is FactionVehicle factionVehicle)
|
||||||
|
{
|
||||||
|
IItem item = GetItemById(itemID);
|
||||||
|
if (factionVehicle.Model == VehicleHash.Riot && user.Faction?.StateOwned == true)
|
||||||
|
{
|
||||||
|
player.TriggerEvent("Error", "Transfer nicht möglich.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RemoveVehicleItem(serverVehicle, vehItem, itemAmount, player);
|
RemoveVehicleItem(serverVehicle, vehItem, itemAmount, player);
|
||||||
SetVehicleItems(player);
|
SetVehicleItems(player);
|
||||||
|
|||||||
Reference in New Issue
Block a user