diff --git a/Server/Business/ShopBusiness.cs b/Server/Business/ShopBusiness.cs index f498b60e..283f33bb 100644 --- a/Server/Business/ShopBusiness.cs +++ b/Server/Business/ShopBusiness.cs @@ -11,7 +11,7 @@ namespace reallife_gamemode.Server.Business public override string Name => "24/7 Business"; - public override Vector3 Position => new Vector3(); + public override Vector3 Position => new Vector3(-443, 1134, 326); public override void Load() { diff --git a/Server/Business/TestBusiness.cs b/Server/Business/TestBusiness.cs deleted file mode 100644 index 5dd58e44..00000000 --- a/Server/Business/TestBusiness.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using GTANetworkAPI; -using reallife_gamemode.Model; -using reallife_gamemode.Server.Util; - -namespace reallife_gamemode.Server.Business -{ - class TestBusiness : BusinessBase - { - public override int Id => 0; - - public override string Name => "Test Business"; - - public override Vector3 Position => new Vector3(-443, 1134, 326); - - public override void Load() - { - - } - } -} diff --git a/Server/Managers/BusinessManager.cs b/Server/Managers/BusinessManager.cs index 1ddc3b5d..7dd56a1f 100644 --- a/Server/Managers/BusinessManager.cs +++ b/Server/Managers/BusinessManager.cs @@ -1,5 +1,8 @@ using GTANetworkAPI; using reallife_gamemode.Server.Business; +using reallife_gamemode.Server.Entities; +using reallife_gamemode.Server.Extensions; +using reallife_gamemode.Server.Util; using System; using System.Collections.Generic; using System.Linq; @@ -22,7 +25,7 @@ namespace reallife_gamemode.Server.Managers NAPI.Util.ConsoleOutput($"Loading Business {item.Name}"); if (Activator.CreateInstance(item) is BusinessBase o) { - if (Businesses.Any(x => x.Id == o.Id)) + if (GetBusiness(o.Id) != null) { throw new InvalidOperationException($"Double Business ID found: {o.Id} | {o.Name}"); } @@ -43,5 +46,67 @@ namespace reallife_gamemode.Server.Managers { return Businesses.Find(b => b.Id == id); } + + [RemoteEvent("Business_DepositMoney")] + public void BusinessDepositMoney(Client player, int amount) + { + User user = player.GetUser(); + if(user == null) + { + return; + } + + BusinessBase playerBusiness = GetBusiness(user.BusinessId); + + TransactionResult result = BankManager.TransferMoney(user, playerBusiness, amount, "Überweisung"); + + if(result == TransactionResult.NEGATIVE_MONEY_SENT) + { + player.SendNotification("~r~Es können nur positive Beträge überwiesen werden"); + return; + } + else if(result == TransactionResult.SENDER_NOT_ENOUGH_MONEY) + { + player.SendNotification("~r~Du hast nicht genug Geld"); + return; + } + else if(result == TransactionResult.SUCCESS) + { + player.TriggerEvent("business_updateMoney", playerBusiness.GetBankAccount().Balance.ToMoneyString()); + player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen"); + return; + } + } + + [RemoteEvent("Business_WithdrawMoney")] + public void BusinessWithdrawMoney(Client player, int amount) + { + User user = player.GetUser(); + if (user == null) + { + return; + } + + BusinessBase playerBusiness = GetBusiness(user.BusinessId); + + TransactionResult result = BankManager.TransferMoney(playerBusiness, user, amount, "Überweisung"); + + if (result == TransactionResult.NEGATIVE_MONEY_SENT) + { + player.SendNotification("~r~Es können nur positive Beträge überwiesen werden"); + return; + } + else if (result == TransactionResult.SENDER_NOT_ENOUGH_MONEY) + { + player.SendNotification("~r~Es ist nicht genug Geld auf der Businesskasse vorhanden"); + return; + } + else if (result == TransactionResult.SUCCESS) + { + player.TriggerEvent("business_updateMoney", playerBusiness.GetBankAccount().Balance.ToMoneyString()); + player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen"); + return; + } + } } }