bank account refactor
This commit is contained in:
@@ -24,5 +24,7 @@ namespace ReallifeGamemode.Server.Business
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override string BankAccountName => Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,12 @@ using ReallifeGamemode.Database;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace ReallifeGamemode.Server.Business
|
||||
{
|
||||
public abstract class BusinessBase : IBankAccountOwner
|
||||
public abstract class BusinessBase : BankAccountHolder<BusinessBankAccount>, IBankAccountOwner
|
||||
{
|
||||
private TextLabel _informationLabel;
|
||||
private ColShape _colShape;
|
||||
@@ -23,6 +24,34 @@ namespace ReallifeGamemode.Server.Business
|
||||
|
||||
public abstract Vector3 Position { get; }
|
||||
|
||||
public override BusinessBankAccount BankAccount
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.BusinessBankAccounts.Where(b => b.BusinessId == this.Id).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int? BankAccountId
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.BusinessBankAccounts.Where(b => b.BusinessId == this.Id).Select(b => b.Id).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string BankAccountName => Name;
|
||||
|
||||
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
||||
{
|
||||
if (databaseContext == null)
|
||||
@@ -110,8 +139,8 @@ namespace ReallifeGamemode.Server.Business
|
||||
{
|
||||
if (client.IsInVehicle || !client.IsLoggedIn()) return;
|
||||
|
||||
client.TriggerEvent("SERVER:Business_ShowMenuHelp");
|
||||
SendBusinessDataToPlayer(client);
|
||||
client.TriggerEvent("SERVER:Business_ShowMenuHelp");
|
||||
}
|
||||
|
||||
public void SendBusinessDataToPlayer(Player player)
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
}
|
||||
using (var getFaction = new DatabaseContext())
|
||||
{
|
||||
Faction receiverUser = getFaction.Factions.FirstOrDefault(u => u.Name == receiver);
|
||||
Faction receiverUser = getFaction.Factions.Include(u => u.BankAccount).FirstOrDefault(u => u.Name == receiver);
|
||||
|
||||
if (receiverUser == null)
|
||||
{
|
||||
@@ -108,7 +108,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
BankManager.TransferMoney(player.GetUser(), receiverUser, amount, "/FPAY");
|
||||
BankManager.TransferMoney(player.GetUser(), receiverUser, amount, "/FPAY", getFaction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2536,7 +2536,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
target.GetUser().GetBankAccount(dbContext).Balance = amount;
|
||||
target.GetUser().BankAccount.Balance = amount;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast das Geld von " + target.Name + " auf ~g~$" + amount + "~s~ gesetzt.");
|
||||
@@ -2561,7 +2561,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
target.GetUser().GetBankAccount(dbContext).Balance += amount;
|
||||
target.GetUser(dbContext).BankAccount.Balance += amount;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast " + target.Name + " ~g~$" + amount + "~s~ gegeben.");
|
||||
|
||||
@@ -9,6 +9,7 @@ using ReallifeGamemode.Server.Util;
|
||||
using ReallifeGamemode.Server.Wanted;
|
||||
using ReallifeGamemode.Database;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Event Login (Login.cs)
|
||||
@@ -27,6 +28,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
{
|
||||
var user = dbContext.Users
|
||||
.Include(u => u.Group)
|
||||
.Include(u => u.BankAccount)
|
||||
.SingleOrDefault(b => b.Name == username);
|
||||
|
||||
if (user == null)
|
||||
@@ -54,17 +56,17 @@ namespace ReallifeGamemode.Server.Events
|
||||
player.SetData("duty", false);
|
||||
player.TriggerEvent("SERVER:SET_HANDMONEY", user.Handmoney, 0);
|
||||
Gangwar.Gangwar.loadPlayer(player);
|
||||
if (player.GetUser().FactionLeader)
|
||||
if (user.FactionLeader)
|
||||
{
|
||||
player.TriggerEvent("CLIENT:Turf_LoadLeaderBlip");
|
||||
}
|
||||
if (user.IsAdmin(AdminLevel.HEADADMIN) == true)
|
||||
if (user.IsAdmin(AdminLevel.HEADADMIN))
|
||||
{
|
||||
player.SetData("editmode", false);
|
||||
player.SetData("quicksavemode", "none");
|
||||
}
|
||||
|
||||
var userBankAccount = user.GetBankAccount();
|
||||
var userBankAccount = user.BankAccount;
|
||||
userBankAccount.Balance = userBankAccount.Balance;
|
||||
|
||||
user.Wanteds = user.Wanteds;
|
||||
@@ -110,7 +112,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension);
|
||||
player.Dimension = NAPI.Data.GetWorldData("playerCreatorDimension");
|
||||
player.Position = new Vector3(402.8664, -996.4108, -99.00027);
|
||||
player.Rotation = new Vector3(0,0,180);
|
||||
player.Rotation = new Vector3(0, 0, 180);
|
||||
player.TriggerEvent("toggleCreator");
|
||||
}
|
||||
else
|
||||
|
||||
@@ -18,29 +18,29 @@ namespace ReallifeGamemode.Server.Events
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
if (!dbContext.Users.Any(u => u.Name.ToLower() == username.ToLower().Trim()))
|
||||
if (dbContext.Users.Where(u => u.SocialClubName == player.SocialClubName).Count() >= 3)
|
||||
{
|
||||
var user = new Database.Entities.User
|
||||
player.TriggerEvent("SERVER:Login_Error", "Es sind schon 3 Konten mit dieser Socialclub-ID registriert.");
|
||||
}
|
||||
else if (!dbContext.Users.Any(u => u.Name.ToLower() == username.ToLower().Trim()))
|
||||
{
|
||||
var user = new User
|
||||
{
|
||||
Name = player.Name,
|
||||
SocialClubName = player.SocialClubName,
|
||||
Password = NAPI.Util.GetHashSha256(password),
|
||||
PositionX = Main.DEFAULT_SPAWN_POSITION.X,
|
||||
PositionY = Main.DEFAULT_SPAWN_POSITION.Y,
|
||||
PositionZ = Main.DEFAULT_SPAWN_POSITION.Z
|
||||
PositionZ = Main.DEFAULT_SPAWN_POSITION.Z,
|
||||
BankAccount = new UserBankAccount
|
||||
{
|
||||
Balance = 5000,
|
||||
Active = true
|
||||
}
|
||||
};
|
||||
|
||||
dbContext.Users.Add(user);
|
||||
dbContext.SaveChanges();
|
||||
var userBankAccount = new Database.Entities.UserBankAccount
|
||||
{
|
||||
UserId = user.Id,
|
||||
Balance = 5000,
|
||||
Active = true
|
||||
};
|
||||
|
||||
dbContext.UserBankAccounts.Add(userBankAccount);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
player.TriggerEvent("SERVER:Login_Success");
|
||||
player.SetData("isLoggedIn", true);
|
||||
@@ -54,10 +54,6 @@ namespace ReallifeGamemode.Server.Events
|
||||
player.Position = new Vector3(402.8664, -996.4108, -99.00027);
|
||||
//player.Position = new Vector3(user.PositionX, user.PositionY, user.PositionZ);
|
||||
}
|
||||
else if (dbContext.Users.Where(u => u.SocialClubName == player.SocialClubName).Count() >= 3)
|
||||
{
|
||||
player.TriggerEvent("SERVER:Login_Error", "Es sind schon 3 Konten mit dieser Socialclub-ID registriert.");
|
||||
}
|
||||
else
|
||||
{
|
||||
player.TriggerEvent("SERVER:Login_Error", "Dieser Benutzername kann nicht registriert werden.");
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace ReallifeGamemode.Server.Extensions
|
||||
.Include(u => u.FactionRank)
|
||||
.Include(u => u.Group)
|
||||
.Include(u => u.House)
|
||||
.Include(u => u.BankAccount)
|
||||
.Where(u => u.Name == client.Name)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace ReallifeGamemode.Server.Finance
|
||||
|
||||
public static (int, float, float) GetEconomyClass(Player client, int wage)
|
||||
{
|
||||
int bankAccount = client.GetUser().GetBankAccount().Balance;
|
||||
int bankAccount = client.GetUser().BankAccount.Balance;
|
||||
float financialHelp = -(float)Math.Pow(1.0005, -bankAccount) * -1000;
|
||||
float financialInterest = 1 - (float)Math.Pow(1.00006, -wage) * 1;
|
||||
if (financialInterest >= 0.7)
|
||||
@@ -182,7 +182,7 @@ namespace ReallifeGamemode.Server.Finance
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
client.GetUser().GetBankAccount(dbContext).Balance += paycheck.Amount;
|
||||
client.GetUser(dbContext).BankAccount.Balance += paycheck.Amount;
|
||||
client.GetUser(dbContext).Wage = 0;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,12 @@ using ReallifeGamemode.Server.Common;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using ReallifeGamemode.Server.Job;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Services;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Main Class (Main.cs)
|
||||
@@ -105,6 +111,16 @@ namespace ReallifeGamemode.Server
|
||||
Jail.JailTimer();
|
||||
Economy.PaydayTimer();
|
||||
WeaponDealManager.WeaponDealTimer();
|
||||
|
||||
UserBankAccount.BalanceChanged += (account) =>
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
var user = dbContext.Users.Where(u => u.BankAccountId == account.Id).Select(u => u.Name).FirstOrDefault();
|
||||
if (user == null) return;
|
||||
PlayerService.GetPlayerByNameOrId(user).TriggerEvent("updateMoney", account.Balance);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:Event")]
|
||||
|
||||
@@ -89,18 +89,17 @@ namespace ReallifeGamemode.Server.Managers
|
||||
[RemoteEvent("CLIENT:ATM_MANAGER:ATM_ACTION")]
|
||||
public void AtmAction(Player client, int site, int inputField1, int inputField2)
|
||||
{
|
||||
var user = client.GetUser();
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
var user = client.GetUser(dbContext);
|
||||
int nearATM = client.GetData<int>("nearATM");
|
||||
//SITE //0 Geld einzahlen //1 Geld auszahlen //2 Geld überweisen
|
||||
switch (site)
|
||||
{
|
||||
//GELD EINZAHLEN in1
|
||||
case 0:
|
||||
var checkPlayer = dbContext.Users.FirstOrDefault(u => u.Id == user.Id);
|
||||
|
||||
if (checkPlayer.Handmoney < inputField1)
|
||||
if (user.Handmoney < inputField1)
|
||||
{
|
||||
//TODO im CEFBrowser anzeigen
|
||||
//client.TriggerEvent("SERVER:WORLD_INTERACTION:ATM_ERROR", 0, checkATM.Balance);
|
||||
@@ -108,22 +107,20 @@ namespace ReallifeGamemode.Server.Managers
|
||||
}
|
||||
else
|
||||
{
|
||||
var updateHandMoneyIn = dbContext.Users.FirstOrDefault(u => u.Id == user.Id);
|
||||
var updateBankMoneyIn = dbContext.UserBankAccounts.FirstOrDefault(b => b.UserId == user.Id);
|
||||
var updateBankMoneyIn = user.BankAccount;
|
||||
var updateATMBalanceIn = dbContext.ATMs.FirstOrDefault(a => a.Id == nearATM);
|
||||
updateHandMoneyIn.Handmoney -= inputField1;
|
||||
user.Handmoney -= inputField1;
|
||||
updateBankMoneyIn.Balance += inputField1;
|
||||
updateATMBalanceIn.Balance += inputField1;
|
||||
client.TriggerEvent("SERVER:SET_HANDMONEY", updateHandMoneyIn.Handmoney);
|
||||
client.TriggerEvent("SERVER:SET_HANDMONEY", user.Handmoney);
|
||||
}
|
||||
break;
|
||||
|
||||
//GELD AUSZAHLEN in1
|
||||
case 1:
|
||||
var checkATM = dbContext.ATMs.FirstOrDefault(a => a.Id == nearATM);
|
||||
var checkBankAccount = dbContext.UserBankAccounts.FirstOrDefault(b => b.UserId == user.Id);
|
||||
|
||||
if (checkBankAccount.Balance < inputField1)
|
||||
if (user.BankAccount.Balance < inputField1)
|
||||
{
|
||||
client.SendNotification("~r~Nicht genügend Geld auf dem Bankkonto!"); //TODO Im Automaten anzeigen lassen
|
||||
}
|
||||
@@ -134,10 +131,9 @@ namespace ReallifeGamemode.Server.Managers
|
||||
else
|
||||
{
|
||||
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;
|
||||
user.BankAccount.Balance -= inputField1;
|
||||
updateATMBalanceOut.Balance -= inputField1;
|
||||
client.TriggerEvent("SERVER:SET_HANDMONEY", updateHandMoneyOut.Handmoney);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using ReallifeGamemode.Server.Util;
|
||||
using ReallifeGamemode.Database;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Database.Entities.Logs;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Managers BankManager (BankManager.cs)
|
||||
@@ -54,43 +55,63 @@ namespace ReallifeGamemode.Server.Managers
|
||||
}
|
||||
}
|
||||
|
||||
public static TransactionResult TransferMoney(IBankAccountOwner sender, IBankAccountOwner receiver, int amount, string origin)
|
||||
public static TransactionResult TransferMoney<TSender, TReceiver>(
|
||||
BankAccountHolder<TSender> sender,
|
||||
BankAccountHolder<TReceiver> receiver,
|
||||
int amount,
|
||||
string origin,
|
||||
DatabaseContext dbContext) where TSender : class, IBankAccount, new() where TReceiver : class, IBankAccount, new()
|
||||
{
|
||||
using (var transferMoney = new DatabaseContext())
|
||||
if (amount < 0) return TransactionResult.NEGATIVE_MONEY_SENT;
|
||||
|
||||
IBankAccount senderAccount;
|
||||
IBankAccount receiverAccount;
|
||||
|
||||
if (sender is BankAccountHolder<BusinessBankAccount> businessSender)
|
||||
{
|
||||
if (amount < 0) return TransactionResult.NEGATIVE_MONEY_SENT;
|
||||
|
||||
IBankAccount senderAccount = sender.GetBankAccount(transferMoney);
|
||||
IBankAccount receiverAccount = receiver.GetBankAccount(transferMoney);
|
||||
|
||||
if (senderAccount == null) return TransactionResult.SENDER_NO_BANKACCOUNT;
|
||||
if (receiverAccount == null) return TransactionResult.RECEIVER_NO_BANKACCOUNT;
|
||||
|
||||
if (senderAccount.Balance < amount) return TransactionResult.SENDER_NOT_ENOUGH_MONEY;
|
||||
|
||||
var transactionLog = new BankAccountTransactionHistory
|
||||
{
|
||||
Sender = sender.Name,
|
||||
SenderBalance = senderAccount.Balance,
|
||||
Receiver = receiver.Name,
|
||||
ReceiverBalance = receiverAccount.Balance,
|
||||
NewReceiverBalance = receiverAccount.Balance + amount,
|
||||
NewSenderBalance = senderAccount.Balance - amount,
|
||||
MoneySent = amount,
|
||||
Fee = 0,
|
||||
Origin = origin
|
||||
};
|
||||
|
||||
// add log
|
||||
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
|
||||
|
||||
senderAccount.Balance -= amount;
|
||||
receiverAccount.Balance += amount;
|
||||
|
||||
transferMoney.SaveChanges();
|
||||
|
||||
return TransactionResult.SUCCESS;
|
||||
senderAccount = dbContext.BusinessBankAccounts.Where(b => b.Id == businessSender.BankAccountId).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
senderAccount = sender.BankAccount;
|
||||
}
|
||||
|
||||
if (receiver is BankAccountHolder<BusinessBankAccount> businessReceiver)
|
||||
{
|
||||
receiverAccount = dbContext.BusinessBankAccounts.Where(b => b.Id == businessReceiver.BankAccountId).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
receiverAccount = receiver.BankAccount;
|
||||
}
|
||||
|
||||
if (senderAccount == null) return TransactionResult.SENDER_NO_BANKACCOUNT;
|
||||
if (receiverAccount == null) return TransactionResult.RECEIVER_NO_BANKACCOUNT;
|
||||
|
||||
if (senderAccount.Balance < amount) return TransactionResult.SENDER_NOT_ENOUGH_MONEY;
|
||||
|
||||
var transactionLog = new BankAccountTransactionHistory
|
||||
{
|
||||
Sender = sender.BankAccountName,
|
||||
SenderBalance = senderAccount.Balance,
|
||||
Receiver = receiver.BankAccountName,
|
||||
ReceiverBalance = receiverAccount.Balance,
|
||||
NewReceiverBalance = receiverAccount.Balance + amount,
|
||||
NewSenderBalance = senderAccount.Balance - amount,
|
||||
MoneySent = amount,
|
||||
Fee = 0,
|
||||
Origin = origin
|
||||
};
|
||||
|
||||
// add log
|
||||
dbContext.BankAccountTransactionLogs.Add(transactionLog);
|
||||
|
||||
senderAccount.Balance -= amount;
|
||||
receiverAccount.Balance += amount;
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
return TransactionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,62 +59,70 @@ namespace ReallifeGamemode.Server.Managers
|
||||
[RemoteEvent("Business_DepositMoney")]
|
||||
public void BusinessDepositMoney(Player player, int amount)
|
||||
{
|
||||
User user = player.GetUser();
|
||||
if (user == null)
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
return;
|
||||
}
|
||||
User user = player.GetUser(dbContext);
|
||||
if (user == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BusinessBase playerBusiness = GetBusiness(user.BusinessId);
|
||||
BusinessBase playerBusiness = GetBusiness(user.BusinessId);
|
||||
|
||||
TransactionResult result = BankManager.TransferMoney(user, playerBusiness, amount, "Überweisung");
|
||||
TransactionResult result = BankManager.TransferMoney(user, playerBusiness, amount, "Überweisung", dbContext);
|
||||
|
||||
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)
|
||||
{
|
||||
playerBusiness.SendBusinessDataToPlayer(player);
|
||||
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
|
||||
return;
|
||||
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)
|
||||
{
|
||||
playerBusiness.SendBusinessDataToPlayer(player);
|
||||
playerBusiness.Update();
|
||||
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("Business_WithdrawMoney")]
|
||||
public void BusinessWithdrawMoney(Player player, int amount)
|
||||
{
|
||||
User user = player.GetUser();
|
||||
if (user == null)
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
return;
|
||||
}
|
||||
User user = player.GetUser(dbContext);
|
||||
if (user == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BusinessBase playerBusiness = GetBusiness(user.BusinessId);
|
||||
BusinessBase playerBusiness = GetBusiness(user.BusinessId);
|
||||
|
||||
TransactionResult result = BankManager.TransferMoney(playerBusiness, user, amount, "Überweisung");
|
||||
TransactionResult result = BankManager.TransferMoney(playerBusiness, user, amount, "Überweisung", dbContext);
|
||||
|
||||
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)
|
||||
{
|
||||
playerBusiness.SendBusinessDataToPlayer(player);
|
||||
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
|
||||
return;
|
||||
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)
|
||||
{
|
||||
playerBusiness.SendBusinessDataToPlayer(player);
|
||||
playerBusiness.Update();
|
||||
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,81 +148,80 @@ namespace ReallifeGamemode.Server.Managers
|
||||
[RemoteEvent("VehShop_BuyVehicle")]
|
||||
public void CarDealerBusiness_BuyVehicle(Player player, string target)
|
||||
{
|
||||
ServerVehicle sVeh = player.Vehicle?.GetServerVehicle();
|
||||
if (sVeh == null) return;
|
||||
if (!(sVeh is ShopVehicle)) return;
|
||||
ShopVehicle shopVehicle = (ShopVehicle)sVeh;
|
||||
int price = shopVehicle.Price;
|
||||
CarDealerBusinessBase business = GetBusiness(shopVehicle.BusinessId) as CarDealerBusinessBase;
|
||||
TransactionResult result = BankManager.TransferMoney(player.GetUser(), business, price, "Auto gekauft");
|
||||
if (result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
|
||||
{
|
||||
player.SendNotification("~r~Du hast nicht genug Geld: " + price.ToMoneyString());
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 spawnPos = business.CarSpawnPositon.Around(3);
|
||||
|
||||
player.TriggerEvent("SERVER:Util_setWaypoint", spawnPos.X, spawnPos.Y);
|
||||
|
||||
ServerVehicle newVeh = null;
|
||||
|
||||
if (target == "Spieler")
|
||||
{
|
||||
newVeh = new UserVehicle
|
||||
{
|
||||
Heading = business.CarSpawnHeading,
|
||||
PositionX = spawnPos.X,
|
||||
PositionY = spawnPos.Y,
|
||||
PositionZ = spawnPos.Z,
|
||||
Locked = false,
|
||||
UserId = player.GetUser().Id,
|
||||
Model = shopVehicle.Model,
|
||||
PrimaryColor = 111,
|
||||
SecondaryColor = 111,
|
||||
Active = true,
|
||||
};
|
||||
}
|
||||
else if (target == "Fraktion")
|
||||
{
|
||||
newVeh = new FactionVehicle
|
||||
{
|
||||
Heading = business.CarSpawnHeading,
|
||||
PositionX = spawnPos.X,
|
||||
PositionY = spawnPos.Y,
|
||||
PositionZ = spawnPos.Z,
|
||||
Locked = false,
|
||||
FactionId = player.GetUser().FactionId,
|
||||
Model = shopVehicle.Model,
|
||||
PrimaryColor = 111,
|
||||
SecondaryColor = 111,
|
||||
Active = true,
|
||||
};
|
||||
}
|
||||
else if (target == "Gruppe")
|
||||
{
|
||||
newVeh = new GroupVehicle
|
||||
{
|
||||
Heading = business.CarSpawnHeading,
|
||||
PositionX = spawnPos.X,
|
||||
PositionY = spawnPos.Y,
|
||||
PositionZ = spawnPos.Z,
|
||||
Locked = false,
|
||||
GroupId = player.GetUser().Group.Id,
|
||||
Model = shopVehicle.Model,
|
||||
PrimaryColor = 111,
|
||||
SecondaryColor = 111,
|
||||
Active = true,
|
||||
};
|
||||
}
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
ServerVehicle sVeh = player.Vehicle?.GetServerVehicle();
|
||||
if (sVeh == null) return;
|
||||
if (!(sVeh is ShopVehicle)) return;
|
||||
ShopVehicle shopVehicle = (ShopVehicle)sVeh;
|
||||
int price = shopVehicle.Price;
|
||||
CarDealerBusinessBase business = GetBusiness(shopVehicle.BusinessId) as CarDealerBusinessBase;
|
||||
TransactionResult result = BankManager.TransferMoney(player.GetUser(dbContext), business, price, "Auto gekauft", dbContext);
|
||||
if (result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
|
||||
{
|
||||
player.SendNotification("~r~Du hast nicht genug Geld: " + price.ToMoneyString());
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 spawnPos = business.CarSpawnPositon.Around(3);
|
||||
|
||||
player.TriggerEvent("SERVER:Util_setWaypoint", spawnPos.X, spawnPos.Y);
|
||||
|
||||
ServerVehicle newVeh = null;
|
||||
|
||||
if (target == "Spieler")
|
||||
{
|
||||
newVeh = new UserVehicle
|
||||
{
|
||||
Heading = business.CarSpawnHeading,
|
||||
PositionX = spawnPos.X,
|
||||
PositionY = spawnPos.Y,
|
||||
PositionZ = spawnPos.Z,
|
||||
Locked = false,
|
||||
UserId = player.GetUser().Id,
|
||||
Model = shopVehicle.Model,
|
||||
PrimaryColor = 111,
|
||||
SecondaryColor = 111,
|
||||
Active = true,
|
||||
};
|
||||
}
|
||||
else if (target == "Fraktion")
|
||||
{
|
||||
newVeh = new FactionVehicle
|
||||
{
|
||||
Heading = business.CarSpawnHeading,
|
||||
PositionX = spawnPos.X,
|
||||
PositionY = spawnPos.Y,
|
||||
PositionZ = spawnPos.Z,
|
||||
Locked = false,
|
||||
FactionId = player.GetUser().FactionId,
|
||||
Model = shopVehicle.Model,
|
||||
PrimaryColor = 111,
|
||||
SecondaryColor = 111,
|
||||
Active = true,
|
||||
};
|
||||
}
|
||||
else if (target == "Gruppe")
|
||||
{
|
||||
newVeh = new GroupVehicle
|
||||
{
|
||||
Heading = business.CarSpawnHeading,
|
||||
PositionX = spawnPos.X,
|
||||
PositionY = spawnPos.Y,
|
||||
PositionZ = spawnPos.Z,
|
||||
Locked = false,
|
||||
GroupId = player.GetUser().Group.Id,
|
||||
Model = shopVehicle.Model,
|
||||
PrimaryColor = 111,
|
||||
SecondaryColor = 111,
|
||||
Active = true,
|
||||
};
|
||||
}
|
||||
dbContext.ServerVehicles.Add(newVeh);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
newVeh.Spawn();
|
||||
newVeh.Spawn();
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:Business_BuyBusiness")]
|
||||
@@ -239,7 +246,7 @@ namespace ReallifeGamemode.Server.Managers
|
||||
ChatService.ErrorMessage(player, "Du kannst nicht mehrere Businesse besitzen");
|
||||
}
|
||||
|
||||
IBankAccount bankAccount = user.GetBankAccount(dbContext);
|
||||
IBankAccount bankAccount = user.BankAccount;
|
||||
|
||||
if (price > bankAccount.Balance)
|
||||
{
|
||||
|
||||
@@ -229,7 +229,7 @@ namespace ReallifeGamemode.Server.Managers
|
||||
|
||||
House house = GetNearHouse(player.Position, dbContext);
|
||||
|
||||
var userBank = user.GetBankAccount(dbContext);
|
||||
var userBank = user.BankAccount;
|
||||
|
||||
if (userBank.Balance < house.Price)
|
||||
{
|
||||
@@ -400,7 +400,7 @@ namespace ReallifeGamemode.Server.Managers
|
||||
|
||||
ChatService.SendMessage(player, "Du bekommst vom Hausverkauf ~g~" + backMoney.ToMoneyString() + "~s~ zurück.");
|
||||
|
||||
user.GetBankAccount(dbContext).Balance += backMoney;
|
||||
user.BankAccount.Balance += backMoney;
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using GTANetworkAPI;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
|
||||
@@ -11,20 +12,18 @@ namespace ReallifeGamemode.Server.Util
|
||||
NAPI.Util.ConsoleOutput("Checking faction bank accounts...");
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach (Faction faction in dbContext.Factions)
|
||||
foreach (Faction faction in dbContext.Factions.Include(f => f.BankAccount))
|
||||
{
|
||||
if (faction.GetBankAccount(dbContext) == null)
|
||||
if (faction.BankAccount == null)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput("Adding bank account for faction: " + faction.Name);
|
||||
FactionBankAccount factionBankAccount = new FactionBankAccount()
|
||||
faction.BankAccount = new FactionBankAccount()
|
||||
{
|
||||
Balance = 0,
|
||||
Bic = "",
|
||||
Iban = "",
|
||||
FactionId = faction.Id,
|
||||
Active = true
|
||||
};
|
||||
dbContext.FactionBankAccounts.Add(factionBankAccount);
|
||||
}
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
|
||||
Reference in New Issue
Block a user