using System; using System.Collections.Generic; using System.Linq; using System.Text; using GTANetworkAPI; using ReallifeGamemode.Server.Entities; using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Models; /** * @overview Life of German Reallife - Managers ATMManager (ATMManager.cs) * @author VegaZ * @copyright (c) 2008 - 2018 Life of German */ namespace ReallifeGamemode.Server.Managers { public class ATMManager : Script { public static List ATMColShapes = new List(); public static void InitATMs() { var addedATMs = 0; using (var dbContext = new DatabaseContext()) { foreach (var currentATM in dbContext.Blips) { if (currentATM.Sprite == 500) { if(dbContext.ATMs.FirstOrDefault(a => a.Id == currentATM.Id) == null) { var dataSet = new ATM { Id = currentATM.Id, X = currentATM.PositionX, Y = currentATM.PositionY, Z = currentATM.PositionZ }; dbContext.Add(dataSet); addedATMs++; } else { continue; } } } if(addedATMs > 0) { NAPI.Util.ConsoleOutput(addedATMs + " Geldautomaten hinzugefügt"); } else { NAPI.Util.ConsoleOutput("Keine Geldautomaten hinzugefügt"); } dbContext.SaveChanges(); LoadATMs(); } } public static void LoadATMs() { using (var dbContext = new DatabaseContext()) { foreach (var currentATM in dbContext.ATMs) { var currentColShape = NAPI.ColShape.CreateCylinderColShape(new Vector3(currentATM.X, currentATM.Y, currentATM.Z), 2.5f, 3, 0); currentColShape.OnEntityEnterColShape += EnterATMRange; currentColShape.OnEntityExitColShape += ExitATMRange; ATMColShapes.Add(currentColShape); currentColShape.SetData("id", currentATM.Id); } } } public static void EnterATMRange(ColShape colShape, Client client) { client.SetData("nearATM", colShape.GetData("id")); } public static void ExitATMRange(ColShape colShape, Client client) { client.ResetData("nearATM"); } public static void ShowAtmUi(Client player, int atmId) { player.TriggerEvent("SERVER:ShowAtmUi", atmId); } [RemoteEvent("CLIENT:CHECK_ATM_BALANCE")] public void CheckATMBalance(Client client, int site, int inputField1, int inputField2) { } [RemoteEvent("CLIENT:ATM_ACTION")] public void AtmAction(Client client, int site, int inputField1, int inputField2) { var user = client.GetUser(); using (var dbContext = new DatabaseContext()) { //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); updateHandMoneyIn.Handmoney -= inputField1; updateBankMoneyIn.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); updateHandMoneyOut.Handmoney += inputField1; updateBankMoneyOut.Balance -= inputField1; break; //GELD ÜBERWEISEN in1 = Kontonr // in2 = Betrag case 2: break; } dbContext.SaveChanges(); } } } }