84 lines
3.0 KiB
C#
84 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using GTANetworkAPI;
|
|
using ReallifeGamemode.Server.Entities;
|
|
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<ColShape> ATMColShapes = new List<ColShape>();
|
|
|
|
public static void InitATMs()
|
|
{
|
|
using (var dbContext = new DatabaseContext())
|
|
{
|
|
foreach (var currentATM in dbContext.Blips)
|
|
{
|
|
if (currentATM.Sprite == 500)
|
|
{
|
|
if(dbContext.ATMs.FirstOrDefault(a => a.X == currentATM.PositionX && a.Y == currentATM.PositionY && a.Z == currentATM.PositionZ) == null)
|
|
{
|
|
var dataSet = new ATM
|
|
{
|
|
X = currentATM.PositionX,
|
|
Y = currentATM.PositionY,
|
|
Z = currentATM.PositionZ
|
|
};
|
|
dbContext.Add(dataSet);
|
|
}
|
|
else
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
public static void EnterATMRange(ColShape colShape, Client client)
|
|
{
|
|
using (var dbContext = new DatabaseContext())
|
|
{
|
|
var nearATM = dbContext.ATMs.FirstOrDefault(a => a.X == colShape.Position.X && a.Y == colShape.Position.Y && a.Z == colShape.Position.Z);
|
|
client.SetData("nearATM", nearATM.Id);
|
|
}
|
|
}
|
|
public static void ExitATMRange(ColShape colShape, Client client)
|
|
{
|
|
client.ResetData("nearATM");
|
|
}
|
|
public static void ShowAtmUi(Client player, int atmId)
|
|
{
|
|
using (var dbContext = new DatabaseContext())
|
|
{
|
|
var atmBalance = dbContext.ATMs.FirstOrDefault(a => a.Id == atmId);
|
|
player.TriggerEvent("SERVER:ShowAtmUi", atmId, atmBalance.Balance);
|
|
}
|
|
}
|
|
}
|
|
}
|