diff --git a/ReallifeGamemode.Client/Interaction/bankmenu.ts b/ReallifeGamemode.Client/Interaction/bankmenu.ts new file mode 100644 index 00000000..74ff7779 --- /dev/null +++ b/ReallifeGamemode.Client/Interaction/bankmenu.ts @@ -0,0 +1,247 @@ +import * as NativeUI from '../libs/NativeUI'; +import InputHelper from '../inputhelper'; + +const Menu = NativeUI.Menu; +const UIMenuItem = NativeUI.UIMenuItem; +const UIMenuListItem = NativeUI.UIMenuListItem; +const UIMenuCheckboxItem = NativeUI.UIMenuCheckboxItem; +const BadgeStyle = NativeUI.BadgeStyle; +const Point = NativeUI.Point; +const ItemsCollection = NativeUI.ItemsCollection; +const Color = NativeUI.Color; + +let screenRes = mp.game.graphics.getScreenResolution(0, 0); +let saveItem = new UIMenuItem("Bestätigen", ""); +saveItem.BackColor = new Color(13, 71, 161); +saveItem.HighlightedBackColor = new Color(25, 118, 210); + +let cancelItem = new UIMenuItem("Schließen", ""); +cancelItem.BackColor = new Color(213, 0, 0); +cancelItem.HighlightedBackColor = new Color(229, 57, 53); + +export default function bankMenuHandle(globalData: IGlobalData) { + + var factionBankmenu: NativeUI.Menu; + var bankmenu: NativeUI.Menu; + + + var paymentItem = new UIMenuItem("Überweisen", "Spieler Geld überweisen (+5% Steuern)"); + + var payInItem = new UIMenuItem("Einzahlen", "Geld einzahlen"); + + var payOutItem = new UIMenuItem("Auszahlen", "Geld auszahlen"); + + var factionPaymentItem = new UIMenuItem("Überweisen", "Spieler Geld überweisen (+5% Steuern)"); + + var factionPayInItem = new UIMenuItem("Einzahlen", "Geld auf die Fraktionskasse zahlen"); + + var factionPayOutItem = new UIMenuItem("Überweisen", "Geld von der Fraktionskasse abheben"); + + var factionBankBalance = new UIMenuItem("Kontostand", ""); + + var paymentname: string; + + var factionname: string; + + mp.events.add('showBankMenu', () => { + if (!globalData.InMenu) { + + globalData.InMenu = true; + + bankmenu = new Menu("Bank", "", new Point(50, 50), null, null); + + bankmenu.AddItem(payInItem); + bankmenu.AddItem(payOutItem); + bankmenu.AddItem(paymentItem); + bankmenu.AddItem(cancelItem); + bankmenu.Visible = true; + + bankmenu.ItemSelect.on((item) => { + if (item.Text === "Einzahlen") { + mp.gui.chat.activate(true); + mp.gui.cursor.show(true, true); + globalData.InMenu = false; + globalData.InInput = true; + var input = new InputHelper("Wie viel möchtest du einzahlen?", globalData); + input.show(); + input.getValue(amount => { + mp.events.callRemote("CLIENT:payIn", amount); + mp.gui.cursor.show(false, false); + bankmenu.Close(true); + globalData.InInput = false; + }); + }else if (item.Text === "Auszahlen") { + mp.gui.chat.activate(true); + mp.gui.cursor.show(true, true); + globalData.InMenu = false; + globalData.InInput = true; + var input = new InputHelper("Wie viel möchtest du Auszahlen?", globalData); + input.show(); + input.getValue(amount => { + mp.events.callRemote("CLIENT:payOut", amount); + mp.gui.cursor.show(false, false); + bankmenu.Close(true); + globalData.InInput = false; + }); + } else if (item.Text === "Überweisen" ) { + mp.gui.chat.activate(true); + mp.gui.cursor.show(true, true); + globalData.InMenu = false; + globalData.InInput = true; + var input = new InputHelper("Wem möchtest du Geld überweisen? (Name/ID)", globalData); + input.show(); + input.getValue(name => { + mp.events.call("CLIENT:bank_name", name); + mp.gui.cursor.show(false, false); + bankmenu.Close(true); + globalData.InInput = false; + }); + + } else if (item.Text === "Schließen") { + mp.gui.cursor.show(false, false); + bankmenu.Close(true); + globalData.InInput = false; + } + }); + + bankmenu.MenuClose.on(() => { + globalData.InMenu = false; + }); + } + }); + + mp.events.add('removeBankmenu', () => { + mp.gui.cursor.show(false, false); + bankmenu.Close(true); + globalData.InInput = false; + }); + + mp.events.add("CLIENT:bank_name", (name) => { + paymentname = name; + globalData.InInput = true; + var input = new InputHelper("Wie viel möchtest du Überweisen??", globalData); + mp.gui.cursor.show(true, true); + input.show(); + input.getValue(amount => { + mp.events.callRemote("CLIENT:payment", JSON.stringify(paymentname), amount); + mp.gui.cursor.show(false, false); + globalData.InInput = false; + }); + }); + + + mp.events.add('removeFactionBankmenu', () => { + mp.gui.cursor.show(false, false); + factionBankmenu.Close(true); + globalData.InInput = false; + }); + + + + mp.events.add('showFactionBankMenu', (factionMoney) => { + if (!globalData.InMenu) { + + globalData.InMenu = true; + + factionBankmenu = new Menu("Fraktionskasse", "", new Point(50, 50), null, null); + factionBankmenu.AddItem(factionBankBalance); + factionBankBalance.SetRightLabel("$" + factionMoney); + factionBankmenu.AddItem(factionPayInItem); + factionBankmenu.AddItem(cancelItem); + factionBankmenu.Visible = true; + + factionBankmenu.ItemSelect.on((item) => { + if (item.Text === "Einzahlen") { + mp.gui.chat.activate(true); + mp.gui.cursor.show(true, true); + globalData.InMenu = false; + globalData.InInput = true; + var input = new InputHelper("Wie viel möchtest du einzahlen?", globalData); + input.show(); + input.getValue(amount => { + mp.events.callRemote("CLIENT:factionPayIn", amount); + mp.gui.cursor.show(false, false); + factionBankmenu.Close(true); + globalData.InInput = false; + }); + }else if (item.Text === "Schließen") { + mp.gui.cursor.show(false, false); + factionBankmenu.Close(true); + globalData.InInput = false; + } + }); + + factionBankmenu.MenuClose.on(() => { + globalData.InMenu = false; + }); + } + }); + + mp.events.add('showFactionBankMenuLeader', (factionMoney) => { + if (!globalData.InMenu) { + + globalData.InMenu = true; + + factionBankmenu = new Menu("Fraktionskasse", "", new Point(50, 50), null, null); + factionBankmenu.AddItem(factionBankBalance); + factionBankBalance.SetRightLabel("$" + factionMoney); + factionBankmenu.AddItem(factionPayInItem); + factionBankmenu.AddItem(factionPaymentItem); + factionBankmenu.AddItem(cancelItem); + factionBankmenu.Visible = true; + + factionBankmenu.ItemSelect.on((item) => { + if (item.Text === "Einzahlen") { + mp.gui.chat.activate(true); + mp.gui.cursor.show(true, true); + globalData.InMenu = false; + globalData.InInput = true; + var input = new InputHelper("Wie viel möchtest du einzahlen?", globalData); + input.show(); + input.getValue(amount => { + mp.events.callRemote("CLIENT:factionPayIn", amount); + mp.gui.cursor.show(false, false); + factionBankmenu.Close(true); + globalData.InInput = false; + }); + }else if (item.Text === "Überweisen") { + mp.gui.chat.activate(true); + mp.gui.cursor.show(true, true); + globalData.InMenu = false; + globalData.InInput = true; + var input = new InputHelper("Wem möchtest du Geld überweisen? (Name/ID)", globalData); + input.show(); + input.getValue(name => { + mp.events.call("CLIENT:bank_factionname", name); + mp.gui.cursor.show(false, false); + factionBankmenu.Close(true); + globalData.InInput = false; + }); + }else if (item.Text === "Schließen") { + mp.gui.cursor.show(false, false); + factionBankmenu.Close(true); + globalData.InInput = false; + } + }); + + factionBankmenu.MenuClose.on(() => { + globalData.InMenu = false; + }); + } + }); + + mp.events.add("CLIENT:bank_factionname", (name) => { + paymentname = name; + globalData.InInput = true; + var input = new InputHelper("Wie viel möchtest du Überweisen??", globalData); + mp.gui.cursor.show(true, true); + input.show(); + input.getValue(amount => { + mp.events.callRemote("CLIENT:factionPayment", JSON.stringify(paymentname), amount); + mp.gui.cursor.show(false, false); + globalData.InInput = false; + }); + }); + + +} \ No newline at end of file diff --git a/ReallifeGamemode.Client/Interaction/interactionmenu.ts b/ReallifeGamemode.Client/Interaction/interactionmenu.ts index 8f177947..b881f198 100644 --- a/ReallifeGamemode.Client/Interaction/interactionmenu.ts +++ b/ReallifeGamemode.Client/Interaction/interactionmenu.ts @@ -90,6 +90,10 @@ export default function (globalData: IGlobalData) { item.SetRightLabel("~g~+ $" + moneyFormat(p.wage)); paycheckMenu.AddItem(item); + item = new UIMenuItem("Sonstige Einkünfte"); + item.SetRightLabel("~g~+ $" + moneyFormat(p.otheramount)); + paycheckMenu.AddItem(item); + item = new UIMenuItem("Finanzhilfe"); item.SetRightLabel("~g~+ $" + moneyFormat(p.financialHelp)); paycheckMenu.AddItem(item); diff --git a/ReallifeGamemode.Client/global.d.ts b/ReallifeGamemode.Client/global.d.ts index fe31b5aa..b5d1204c 100644 --- a/ReallifeGamemode.Client/global.d.ts +++ b/ReallifeGamemode.Client/global.d.ts @@ -40,6 +40,7 @@ declare type Paycheck = { rentalFees: number; healthInsurance: number; factionMoney: number; + otheramount: number; } declare type Licenses = { diff --git a/ReallifeGamemode.Client/index.ts b/ReallifeGamemode.Client/index.ts index d8ef0342..32aefc49 100644 --- a/ReallifeGamemode.Client/index.ts +++ b/ReallifeGamemode.Client/index.ts @@ -230,6 +230,9 @@ attachmentManager(game); import relativeVector from './util/relativevector'; relativeVector(); +import bankMenuHandle from './Interaction/bankmenu'; +bankMenuHandle(globalData); + require('./Gui/policedepartment'); interface VehicleData { diff --git a/ReallifeGamemode.Database/Entities/User.cs b/ReallifeGamemode.Database/Entities/User.cs index ef6e7a8b..f7cb590c 100644 --- a/ReallifeGamemode.Database/Entities/User.cs +++ b/ReallifeGamemode.Database/Entities/User.cs @@ -123,6 +123,8 @@ namespace ReallifeGamemode.Database.Entities public bool IsAdmin(AdminLevel level) => AdminLevel >= level; public int Points { get; set; } + public int otheramount { get; set; } = 0; + [NotMapped] public Player Player { diff --git a/ReallifeGamemode.Server/Bank/bank.cs b/ReallifeGamemode.Server/Bank/bank.cs new file mode 100644 index 00000000..5cea6394 --- /dev/null +++ b/ReallifeGamemode.Server/Bank/bank.cs @@ -0,0 +1,203 @@ +using GTANetworkAPI; +using Newtonsoft.Json; +using ReallifeGamemode.Database.Models; +using ReallifeGamemode.Server.Extensions; +using ReallifeGamemode.Server.Finance; +using ReallifeGamemode.Services; +using System; + + +namespace ReallifeGamemode.Server.Bank +{ + class bank : Script + { + private static TextLabel informationLabel; + private static TextLabel factionInformationLabel; + private static Marker marker; + private static Marker factionMarker; + private static ColShape _colShape; + private static ColShape _factioncolShape; + public static Vector3 Position { get; } + + + public static void Setup() + { + informationLabel = NAPI.TextLabel.CreateTextLabel("Bank", new Vector3(246.48, 223.01, 106.28), 20.0f, 1.3f, 0, new Color(255, 255, 255)); + marker = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, new Vector3(246.48, 223.01, 105.28), new Vector3(), new Vector3(), 1f, new Color(255, 255, 255)); + + factionInformationLabel = NAPI.TextLabel.CreateTextLabel("Fraktionskasse", new Vector3(251.61, 221.32, 106.28), 20.0f, 1.3f, 0, new Color(255, 255, 255)); + factionMarker = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, new Vector3(251.61, 221.32, 105.28), new Vector3(), new Vector3(), 1f, new Color(255, 255, 255)); + + _colShape = NAPI.ColShape.CreateSphereColShape(new Vector3(246.48, 223.01, 105.28), 2f); + _colShape.OnEntityEnterColShape += EntityEnterBankColShape; + _colShape.OnEntityExitColShape += EntityExitBankColShape; + + _factioncolShape = NAPI.ColShape.CreateSphereColShape(new Vector3(251.61, 221.32, 105.28), 2f); + _factioncolShape.OnEntityEnterColShape += EntityEnterFactionBankColShape; + _factioncolShape.OnEntityExitColShape += EntityExitFactionBankColShape; + + NAPI.Blip.CreateBlip(207, new Vector3(231.35, 214.98, 106.27), 1.0f, 2, "Bank", shortRange: true); + } + + private static void EntityEnterBankColShape(ColShape colShape, Player client) + { + if (client.IsInVehicle || !client.IsLoggedIn()) return; + + client.TriggerEvent("showBankMenu"); + } + + private static void EntityExitBankColShape(ColShape colShape, Player client) + { + client.TriggerEvent("removeBankmenu"); + } + + private static void EntityEnterFactionBankColShape(ColShape colShape, Player client) + { + if (client.IsInVehicle || !client.IsLoggedIn()) return; + + if (client.GetUser().FactionLeader == true) + { + client.TriggerEvent("showFactionBankMenuLeader", client.GetUser().Faction.BankAccount.Balance.ToString()); + } + client.TriggerEvent("showFactionBankMenu", client.GetUser().Faction.BankAccount.Balance.ToString()); + } + + private static void EntityExitFactionBankColShape(ColShape colShape, Player client) + { + client.TriggerEvent("removeFactionBankmenu"); + } + + [RemoteEvent("CLIENT:payIn")] + public void bank_payIn(Player player, string stringAmount) + { + int amount = Int32.Parse(stringAmount); + + + using (var dbContext = new DatabaseContext()) + { + + if (amount <= 0 || amount > player.GetUser(dbContext).Handmoney) + { + player.SendNotification($"~r~Dieser Betrag ist ungültig."); + return; + } + else + { + player.SendNotification($"~w~Du hast $~g~{amount} ~w~eingezahlt."); + player.GetUser(dbContext).Handmoney -= amount; + player.GetUser(dbContext).BankAccount.Balance += amount; + dbContext.SaveChanges(); + } + } + } + [RemoteEvent("CLIENT:payOut")] + public void bank_payOut(Player player, string stringAmount) + { + int amount = Int32.Parse(stringAmount); + + + using (var dbContext = new DatabaseContext()) + { + + if (amount <= 0 || amount > player.GetUser(dbContext).BankAccount.Balance) + { + player.SendNotification($"~r~Dieser Betrag ist ungültig."); + return; + } + else + { + player.SendNotification($"~w~Du hast $~g~{amount} ~w~abgehoben."); + player.GetUser(dbContext).Handmoney += amount; + player.GetUser(dbContext).BankAccount.Balance -= amount; + dbContext.SaveChanges(); + } + } + } + + [RemoteEvent("CLIENT:payment")] + public void bank_payment(Player player, string jsonNameOrId, string stringAmount) + { + string nameOrId = (string)JsonConvert.DeserializeObject(jsonNameOrId); + int amount = Int32.Parse(stringAmount); + Player target = PlayerService.GetPlayerByNameOrId(nameOrId); + + using (var dbContext = new DatabaseContext()) + { + if(player.GetUser(dbContext) == target.GetUser(dbContext)) + { + player.SendNotification($"~r~Du kannst dir selber kein Geld überweisen."); + return; + }else if(!target.IsLoggedIn()) + { + player.SendNotification($"~r~Dieser Spieler ist nicht Online."); + + } + else if (amount <= 0 || (int)(amount*1.05) > player.GetUser(dbContext).BankAccount.Balance) + { + player.SendNotification($"~r~Dieser Betrag kann nicht überwiesen werden."); + return; + } + else + { + player.SendNotification($"~w~Du hast {target.Name} $~g~{amount} ~w~ Überwiesen."); + player.GetUser(dbContext).BankAccount.Balance -= (int)(amount*1.05); + target.GetUser(dbContext).otheramount = amount; + dbContext.SaveChanges(); + } + } + } + [RemoteEvent("CLIENT:factionPayIn")] + public void bank_factionPayIn(Player player, string stringAmount) + { + int amount = Int32.Parse(stringAmount); + + + using (var dbContext = new DatabaseContext()) + { + + if (amount <= 0 || amount > player.GetUser(dbContext).Handmoney) + { + player.SendNotification($"~r~Dieser Betrag ist ungültig."); + return; + } + else + { + player.SendNotification($"~w~Du hast $~g~{amount} ~w~ in die Fraktionskasse eingezahlt."); + player.GetUser(dbContext).Handmoney -= amount; + player.GetUser(dbContext).Faction.BankAccount.Balance += amount; + dbContext.SaveChanges(); + } + } + } + + [RemoteEvent("CLIENT:factionPayment")] + public void bank_factionPayment(Player player, string jsonNameOrId, string stringAmount) + { + string nameOrId = (string)JsonConvert.DeserializeObject(jsonNameOrId); + int amount = Int32.Parse(stringAmount); + Player target = PlayerService.GetPlayerByNameOrId(nameOrId); + + using (var dbContext = new DatabaseContext()) + { + if (!target.IsLoggedIn()) + { + player.SendNotification($"~r~Dieser Spieler ist nicht Online."); + + } + else if (amount <= 0 || (int)(amount * 1.05) > player.GetUser(dbContext).Faction.BankAccount.Balance) + { + player.SendNotification($"~r~Dieser Betrag kann nicht überwiesen werden."); + return; + } + else + { + player.SendNotification($"~w~Du hast {target.Name} $~g~{amount} ~w~ Überwiesen."); + player.GetUser(dbContext).Faction.BankAccount.Balance -= (int)(amount * 1.05); + target.GetUser(dbContext).otheramount = amount; + dbContext.SaveChanges(); + } + } + } + } + +} diff --git a/ReallifeGamemode.Server/Finance/Economy.cs b/ReallifeGamemode.Server/Finance/Economy.cs index fa2b3d63..44135fd2 100644 --- a/ReallifeGamemode.Server/Finance/Economy.cs +++ b/ReallifeGamemode.Server/Finance/Economy.cs @@ -76,7 +76,7 @@ namespace ReallifeGamemode.Server.Finance float propertyTax = GetPropertyTaxation(client); int vehicleTaxation = GetVehicleTaxation(client); int rentalFees = GetRentalFees(client); - + int healthInsurance = (int)(user.BankAccount.Balance * 0.001); if (healthInsurance < 0) { @@ -89,10 +89,10 @@ namespace ReallifeGamemode.Server.Finance { factionMoney = user.FactionRank.Order * 1000; } + int otheramount = user.otheramount; + int amount = wage - (int)(wage * financialInterest) - vehicleTaxation - (int)propertyTax + (int)financialHelp - rentalFees - healthInsurance + (factionMoney ?? 0) + otheramount; - int amount = wage - (int)(wage * financialInterest) - vehicleTaxation - (int)propertyTax + (int)financialHelp - rentalFees - healthInsurance + (factionMoney ?? 0); - - Paycheck paycheck = new Paycheck(financialHelp, financialInterest, vehicleTaxation, propertyTax, wage, amount, rentalFees, healthInsurance, factionMoney); + Paycheck paycheck = new Paycheck(financialHelp, financialInterest, vehicleTaxation, propertyTax, wage, amount, rentalFees, healthInsurance, factionMoney, otheramount); Paychecks[user.Id] = paycheck; ReleasePayDay(client, paycheck, minusJail); } @@ -136,7 +136,7 @@ namespace ReallifeGamemode.Server.Finance u.BankAccount.Balance += paycheck.Amount; u.Wage = 0; - + u.otheramount = 0; u.PaydayTimer = 60; var rentals = dbContext.HouseRentals diff --git a/ReallifeGamemode.Server/Finance/Paycheck.cs b/ReallifeGamemode.Server/Finance/Paycheck.cs index 3f96b286..9c4c0805 100644 --- a/ReallifeGamemode.Server/Finance/Paycheck.cs +++ b/ReallifeGamemode.Server/Finance/Paycheck.cs @@ -31,7 +31,10 @@ namespace ReallifeGamemode.Server.Finance [JsonProperty("factionMoney")] public int? FactionMoney { get; set; } = 0; - public Paycheck(float FinancialHelp, float FinancialInterest, int VehicleTaxation, float PropertyTaxation, int Wage, int Amount, int RentalFees, int HealthInsurance, int? FactionMoney) + [JsonProperty("otheramount")] + public int? otheramount { get; set; } = 0; + + public Paycheck(float FinancialHelp, float FinancialInterest, int VehicleTaxation, float PropertyTaxation, int Wage, int Amount, int RentalFees, int HealthInsurance, int? FactionMoney, int? otheramount) { this.FinancialHelp = FinancialHelp; this.FinancialInterest = FinancialInterest; @@ -42,6 +45,7 @@ namespace ReallifeGamemode.Server.Finance this.RentalFees = RentalFees; this.HealthInsurance = HealthInsurance; this.FactionMoney = FactionMoney; + this.otheramount = otheramount; } } } diff --git a/ReallifeGamemode.Server/Main.cs b/ReallifeGamemode.Server/Main.cs index 2a3aa044..44356a1c 100644 --- a/ReallifeGamemode.Server/Main.cs +++ b/ReallifeGamemode.Server/Main.cs @@ -129,6 +129,7 @@ namespace ReallifeGamemode.Server DrivingSchool.DrivingSchool.Setup(); PlaneSchool.Setup(); Gangwar.Gangwar.loadTurfs(); + Bank.bank.Setup(); TempBlip tempBlip = new TempBlip() {