diff --git a/ReallifeGamemode.Client/Interaction/worldinteraction.ts b/ReallifeGamemode.Client/Interaction/worldinteraction.ts
index 102c0820..86c7d23a 100644
--- a/ReallifeGamemode.Client/Interaction/worldinteraction.ts
+++ b/ReallifeGamemode.Client/Interaction/worldinteraction.ts
@@ -26,14 +26,14 @@
//GELD EINZAHLEN in1
case 0:
mp.events.call("SERVER:SET_HANDMONEY", inputField1 * -1); //GEHT NACH HANDMONEY.TS
- mp.events.callRemote("CLIENT:ATM_ACTION", site, inputField1, inputField2);
+ mp.events.callRemote("CLIENT:ATM_MANAGER:ATM_ACTION", site, inputField1, inputField2);
break;
//GELD AUSZAHLEN in1
case 1:
- //mp.events.call("CLIENT:CHECK_ATM_BALANCE", inputField1);
- mp.events.call("SERVER:SET_HANDMONEY", inputField1); //GEHT NACH HANDMONEY.TS
- mp.events.callRemote("CLIENT:ATM_ACTION", site, inputField1, inputField2)
+ mp.events.callRemote("CLIENT:ATM_MAN:CHECK_BALANCE", inputField1);
+ //mp.events.call("SERVER:SET_HANDMONEY", inputField1); //GEHT NACH HANDMONEY.TS
+ //mp.events.callRemote("CLIENT:ATM_ACTION", site, inputField1, inputField2)
break;
//GELD ÜBERWEISEN in1 = Kontonr // in2 = Betrag
@@ -43,4 +43,17 @@
}
});
+ mp.events.add("SERVER:WORLD_INTERACTION:UPDATE_HANDMONEY", (inputField1) => {
+ mp.events.call("SERVER:SET_HANDMONEY", inputField1); //GEHT NACH HANDMONEY.TS
+ });
+
+ mp.events.add("SERVER:WORLD_INTERACTION:ATM_ERROR", (errorId, p2) => {
+ switch (errorId) {
+
+ //Nicht genügend BALANCE im ATM
+ case 0:
+ atmBrowser.execute(`noBalance();`);
+ break;
+ }
+ });
}
\ No newline at end of file
diff --git a/ReallifeGamemode.Client/assets/html/atm/index.html b/ReallifeGamemode.Client/assets/html/atm/index.html
index e17f122a..8d4f22b4 100644
--- a/ReallifeGamemode.Client/assets/html/atm/index.html
+++ b/ReallifeGamemode.Client/assets/html/atm/index.html
@@ -79,32 +79,33 @@
-
-
+
@@ -385,7 +386,9 @@
playClick();
mp.trigger("CEF:closeATM");
}
-
+ function noBalance() {
+ document.getElementById("auszahlen_error").textContent = "Fehler";
+ }
function action(ac)
{
mp.trigger("atmAction", ac);
diff --git a/ReallifeGamemode.Server/Managers/ATMManager.cs b/ReallifeGamemode.Server/Managers/ATMManager.cs
index 2a73a4b3..d6efd2e5 100644
--- a/ReallifeGamemode.Server/Managers/ATMManager.cs
+++ b/ReallifeGamemode.Server/Managers/ATMManager.cs
@@ -85,34 +85,56 @@ namespace ReallifeGamemode.Server.Managers
{
player.TriggerEvent("SERVER:ShowAtmUi", atmId);
}
- [RemoteEvent("CLIENT:CHECK_ATM_BALANCE")]
- public void CheckATMBalance(Client client, int site, int inputField1, int inputField2)
+ [RemoteEvent("CLIENT:ATM_MAN:CHECK_BALANCE")]
+ public void CheckATMBalance(Client client, int inputField1)
{
+ var user = client.GetUser();
+ int nearATM = client.GetData("nearATM");
+ using (var dbContext = new DatabaseContext())
+ {
+ var checkATM = dbContext.ATMs.FirstOrDefault(a => a.Id == nearATM);
+ if(checkATM.Balance < inputField1)
+ {
+ //TODO im CEFBrowser anzeigen client.SendChatMessage("Nicht genügend Geld im Automaten. Maximal Verfügbar: " + checkATM.Balance);
+ client.TriggerEvent("SERVER:WORLD_INTERACTION:ATM_ERROR", 0, checkATM.Balance);
+ }
+ else
+ {
+ client.TriggerEvent("SERVER:WORLD_INTERACTION:UPDATE_HANDMONEY", inputField1);
+ AtmAction(client, 1, inputField1, 0);
+ }
+ }
}
- [RemoteEvent("CLIENT:ATM_ACTION")]
+ [RemoteEvent("CLIENT:ATM_MANAGER:ATM_ACTION")]
public void AtmAction(Client client, int site, int inputField1, int inputField2)
{
var user = client.GetUser();
using (var dbContext = new DatabaseContext())
{
+ int nearATM = client.GetData("nearATM");
//SITE //0 Geld einzahlen //1 Geld auszahlen //2 Geld überweisen
switch (site)
{
//GELD EINZAHLEN in1
case 0:
+
var updateHandMoneyIn = dbContext.Users.FirstOrDefault(u => u.Id == user.Id);
var updateBankMoneyIn = dbContext.UserBankAccounts.FirstOrDefault(b => b.UserId == user.Id);
+ var updateATMBalanceIn = dbContext.ATMs.FirstOrDefault(a => a.Id == nearATM);
updateHandMoneyIn.Handmoney -= inputField1;
updateBankMoneyIn.Balance += inputField1;
+ updateATMBalanceIn.Balance += inputField1;
break;
//GELD AUSZAHLEN in1
case 1:
var updateHandMoneyOut = dbContext.Users.FirstOrDefault(u => u.Id == user.Id);
var updateBankMoneyOut = dbContext.UserBankAccounts.FirstOrDefault(b => b.UserId == user.Id);
+ var updateATMBalanceOut = dbContext.ATMs.FirstOrDefault(a => a.Id == nearATM);
updateHandMoneyOut.Handmoney += inputField1;
updateBankMoneyOut.Balance -= inputField1;
+ updateATMBalanceOut.Balance -= inputField1;
break;
//GELD ÜBERWEISEN in1 = Kontonr // in2 = Betrag