From a95ec44baa2af823c8b4ce011e77ea8d07a37a8b Mon Sep 17 00:00:00 2001 From: VegaZ Date: Thu, 15 Apr 2021 22:43:43 +0200 Subject: [PATCH] Progress --- .../Interaction/ammunation/ammunation.ts | 53 ++++++++++++++++--- ReallifeGamemode.Client/global.d.ts | 7 ++- ReallifeGamemode.Client/index.ts | 3 ++ ReallifeGamemode.Server/Events/Key.cs | 9 +++- .../Managers/PositionManager.cs | 13 +++-- .../Shop/Ammunation/Ammunation.cs | 23 +------- 6 files changed, 75 insertions(+), 33 deletions(-) diff --git a/ReallifeGamemode.Client/Interaction/ammunation/ammunation.ts b/ReallifeGamemode.Client/Interaction/ammunation/ammunation.ts index 71a8876a..2604f1ef 100644 --- a/ReallifeGamemode.Client/Interaction/ammunation/ammunation.ts +++ b/ReallifeGamemode.Client/Interaction/ammunation/ammunation.ts @@ -12,17 +12,56 @@ const Color = NativeUI.Color; export default function ammunation(globalData: IGlobalData) { var screenRes = mp.game.graphics.getScreenResolution(0, 0); + var weapons: Weapon[]; - class Weapon { + mp.events.add("AmmunationShop:LoadNativeUI", (weaponList: string) => { + mp.gui.chat.push("a "+ weaponList); + //mp.gui.chat.activate(false); + //globalData.InMenu = true; + weapons = JSON.parse(weaponList); + mp.gui.chat.push("b " +weapons.toString()); - } + var menu = getAmmunationMenu(); - mp.events.add("AmmunationShop:LoadNativeUI", (weapons: Weapon[]) => { - mp.gui.chat.activate(false); - globalData.InMenu = true; - mp.gui.chat.push(weapons.toString()); + //Schaut nach ob mindestens eine Waffe in weapons existiert welche die CategoryId beinhaltet + for (var c = 1; c < 9; c++) { + switch (c) { + case 1: {//Meelee + + break; + } - var ammunationMenu = new Menu("Ammunation", "", new Point(0, screenRes.y / 3), null, null); + case 2: {//Pistolen + if (weapons.find(w => w.CategoryId == c)) { + var pistolItem = new MenuItem("Pistolen", "",); + menu.AddItem(pistolItem); + menu.BindMenuToItem(getWeaponsFromCategory(menu, c, "Pistolen"),pistolItem); + } + break; + } + } + } + + }); + + function getAmmunationMenu(): NativeUI.Menu { + return new Menu("Ammunation", "", new Point(0, screenRes.y / 3), null, null); + } + + function getWeaponsFromCategory(parentMenu: NativeUI.Menu, category: number, categoryName: string): NativeUI.Menu { + var categoryMenu = new Menu(categoryName, "", new Point(0, screenRes.y / 3), null, null); + + var cWeapons: Weapon[] = weapons.filter(w => w.CategoryId == category); + + cWeapons.forEach(weapon => { + var menuItem = new MenuItem(weapon.WeaponModel, "Munition: " + weapon.Ammo); + categoryMenu.AddItem(menuItem); + menuItem.SetRightLabel("~g~$~w~" + weapon.Price.toString()); + }) + + return categoryMenu; + + }; }; \ No newline at end of file diff --git a/ReallifeGamemode.Client/global.d.ts b/ReallifeGamemode.Client/global.d.ts index 297908cd..4f4eba3e 100644 --- a/ReallifeGamemode.Client/global.d.ts +++ b/ReallifeGamemode.Client/global.d.ts @@ -78,8 +78,13 @@ declare type FactionRank = { declare type Weapon = { WeaponModel: string; - Category: number; + CategoryId: number; SlotID: number; Ammo: number; Price: number; +} + +declare type WeaponCategory = { + Category: number; + Weapons: Weapon[]; } \ No newline at end of file diff --git a/ReallifeGamemode.Client/index.ts b/ReallifeGamemode.Client/index.ts index 303729b5..7768f9ac 100644 --- a/ReallifeGamemode.Client/index.ts +++ b/ReallifeGamemode.Client/index.ts @@ -258,6 +258,9 @@ animationSync(); import antiCheat from './admin/anticheat'; antiCheat(globalData); +import ammunation from './Interaction/ammunation/ammunation'; +ammunation(globalData); + require('./Gui/policedepartment'); require('./Gui/helptext'); diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index 8f489190..9ab5bffb 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -519,7 +519,14 @@ namespace ReallifeGamemode.Server.Events } if (nearestAmmunationPoint != null) { - nearestAmmunationPoint.Ammunation.LoadShopNUI(player); + if (!user.WeaponLicense) + { + player.SendNotification("~r~Du besitzt keinen Waffenschein"); + } + else + { + nearestAmmunationPoint.Ammunation.LoadShopNUI(player); + } } if (user.FactionLeader) { diff --git a/ReallifeGamemode.Server/Managers/PositionManager.cs b/ReallifeGamemode.Server/Managers/PositionManager.cs index ab871efd..e53e9aef 100644 --- a/ReallifeGamemode.Server/Managers/PositionManager.cs +++ b/ReallifeGamemode.Server/Managers/PositionManager.cs @@ -283,11 +283,18 @@ namespace ReallifeGamemode.Server.Managers NAPI.TextLabel.CreateTextLabel("24/7 - Dr\u00fccke ~y~E", s.Position, 7, 1, 0, new Color(255, 255, 255), false, 0); } - foreach (AmmunationPoint s in AmmunationPoints) + foreach (Ammunation s in ShopManager.Ammunations) { - NAPI.Marker.CreateMarker(1, new Vector3(s.Position.X, s.Position.Y, s.Position.Z - 2), new Vector3(s.Position.X, s.Position.Y, s.Position.Z + 1), + NAPI.Marker.CreateMarker(1, new Vector3(s.vector.X, s.vector.Y, s.vector.Z - 2), new Vector3(s.vector.X, s.vector.Y, s.vector.Z + 1), new Vector3(0, 0, 0), 2, new Color(255, 255, 255, 50), false, 0); - NAPI.TextLabel.CreateTextLabel("Ammunation - Dr\u00fccke ~y~E", s.Position, 7, 1, 0, new Color(255, 255, 255), false, 0); + NAPI.TextLabel.CreateTextLabel("Ammunation - Dr\u00fccke ~y~E", s.vector, 7, 1, 0, new Color(255, 255, 255), false, 0); + + AmmunationPoint ammuShop = new AmmunationPoint + { + Position = s.vector, + Ammunation = s + }; + AmmunationPoints.Add(ammuShop); } #endregion Shops diff --git a/ReallifeGamemode.Server/Shop/Ammunation/Ammunation.cs b/ReallifeGamemode.Server/Shop/Ammunation/Ammunation.cs index 9848ef29..0cb768a2 100644 --- a/ReallifeGamemode.Server/Shop/Ammunation/Ammunation.cs +++ b/ReallifeGamemode.Server/Shop/Ammunation/Ammunation.cs @@ -17,7 +17,7 @@ namespace ReallifeGamemode.Server.Shop.Ammunation public Ammunation(Vector3 position) { - this.vector = vector; + this.vector = position; LoadWeapons(); } @@ -30,27 +30,8 @@ namespace ReallifeGamemode.Server.Shop.Ammunation } public void LoadShopNUI(Player client) { - User u = client.GetUser(); - if (u == null) - { - return; - } - - //List melee = weaponList.ToList().FindAll(w => w.Category == "Nahkampfwaffen"); //1 - List handguns = weaponList.ToList().FindAll(w => w.CategoryId == 2); //2 - //List smgs = weaponList.ToList().FindAll(w => w.Category == "Maschinenpistolen"); //3 - //List shotguns = weaponList.ToList().FindAll(w => w.Category == "Schrotflinten"); //4 - //List assaultrifles = weaponList.ToList().FindAll(w => w.Category == "Sturmgewehre"); //5 - //List lmgs = weaponList.ToList().FindAll(w => w.Category == "Leichte Maschinengewehre"); //6 - //List sniperrifles = weaponList.ToList().FindAll(w => w.Category == "Scharfschützengewehre"); //7 - //List heavyweapons = weaponList.ToList().FindAll(w => w.Category == "Schwere Waffen"); //8 - //List throwables = weaponList.ToList().FindAll(w => w.Category == "Werfbare Waffen"); //9 - - List shopWeapons = new List - { - handguns.ToArray(), - }; + List shopWeapons = weaponList.ToList(); client.TriggerEvent("AmmunationShop:LoadNativeUI", JsonConvert.SerializeObject(shopWeapons)); } }