GELD LOGS

(cherry picked from commit a2db770316)
This commit is contained in:
hydrant
2021-05-15 03:14:37 +02:00
parent 3c63002c03
commit 7411fa02f3
22 changed files with 448 additions and 306 deletions

View File

@@ -4,18 +4,20 @@
* @copyright (c) 2008 - 2021 Life of German
*/
using GTANetworkAPI;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Finance;
using ReallifeGamemode.Server.Log;
using ReallifeGamemode.Services;
using System;
namespace ReallifeGamemode.Server.Bank
{
class bank : Script
class Bank : Script
{
private static TextLabel informationLabel;
private static TextLabel factionInformationLabel;
@@ -25,6 +27,7 @@ namespace ReallifeGamemode.Server.Bank
private static ColShape _factioncolShape;
public static Vector3 Position { get; }
private static readonly ILogger logger = LogManager.GetLogger<Bank>();
public static void Setup()
{
@@ -58,7 +61,7 @@ namespace ReallifeGamemode.Server.Bank
}
private static void EntityEnterFactionBankColShape(ColShape colShape, Player client)
{
{
if (client.IsInVehicle || !client.IsLoggedIn() || client.GetUser().FactionId is null) return;
User user = client.GetUser();
@@ -92,6 +95,7 @@ namespace ReallifeGamemode.Server.Bank
}
else
{
logger.LogInformation("Player {0} did a deposit of {1} dollars at the bank", player.Name, amount);
player.SendNotification($"~w~Du hast $~g~{amount} ~w~eingezahlt.");
player.GetUser(dbContext).Handmoney -= amount;
player.GetUser(dbContext).BankAccount.Balance += amount;
@@ -115,6 +119,7 @@ namespace ReallifeGamemode.Server.Bank
}
else
{
logger.LogInformation("Player {0} did a withdraw of {1} dollars at the bank", player.Name, amount);
player.SendNotification($"~w~Du hast $~g~{amount} ~w~abgehoben.");
player.GetUser(dbContext).Handmoney += amount;
player.GetUser(dbContext).BankAccount.Balance -= amount;
@@ -130,34 +135,40 @@ namespace ReallifeGamemode.Server.Bank
int amount = Int32.Parse(stringAmount);
Player target = PlayerService.GetPlayerByNameOrId(nameOrId);
if (!target.IsLoggedIn())
{
player.SendNotification($"~r~Dieser Spieler ist nicht Online.");
return;
}
using (var dbContext = new DatabaseContext())
{
if (player.GetUser().PlayedMinutes < 180)
User user = player.GetUser(dbContext);
if (user.PlayedMinutes < 180)
{
player.SendNotification("~r~Du kannst Geld erst ab 3 Spielstunden vergeben");
return;
}
if (player.GetUser(dbContext) == target.GetUser(dbContext))
User targetUser = target.GetUser(dbContext);
if (user == targetUser)
{
player.SendNotification($"~r~Du kannst dir selber kein Geld überweisen.");
return;
}
else if (!target.IsLoggedIn())
{
player.SendNotification($"~r~Dieser Spieler ist nicht Online.");
}
else if (amount <= 0 || (int)(amount * 1.05) > player.GetUser(dbContext).BankAccount.Balance)
else if (amount <= 0 || (int)(amount * 1.05) > user.BankAccount.Balance)
{
player.SendNotification($"~r~Dieser Betrag kann nicht überwiesen werden.");
return;
}
else
{
logger.LogInformation("Player {0} did a transfer of {1} dollars to {2}", user.Name, amount, targetUser.Name);
player.SendNotification($"~w~Du hast {target.Name} $~g~{amount} ~w~Überwiesen.");
target.SendNotification($"~w~{player.Name} hat dir $~g~{amount} ~w~Überwiesen.");
player.GetUser(dbContext).BankAccount.Balance -= (int)(amount * 1.05);
target.GetUser(dbContext).otheramount += amount;
user.BankAccount.Balance -= (int)(amount * 1.05);
targetUser.otheramount += amount;
dbContext.SaveChanges();
}
}
@@ -170,17 +181,23 @@ namespace ReallifeGamemode.Server.Bank
using (var dbContext = new DatabaseContext())
{
User user = player.GetUser(dbContext);
if (user.FactionId == null)
{
return;
}
if (amount <= 0 || amount > player.GetUser(dbContext).BankAccount.Balance)
if (amount <= 0 || amount > user.BankAccount.Balance)
{
player.SendNotification($"~r~Dieser Betrag ist ungültig.");
return;
}
else
{
logger.LogInformation("Player {0} did a faction payin of {1} dollars to faction {2}", user.Name, amount, user.Faction.Id);
player.SendNotification($"~w~Du hast $~g~{amount}~w~ in die Fraktionskasse eingezahlt.");
player.GetUser(dbContext).BankAccount.Balance -= amount;
player.GetUser(dbContext).Faction.BankAccount.Balance += amount;
user.BankAccount.Balance -= amount;
user.Faction.BankAccount.Balance += amount;
dbContext.SaveChanges();
}
}
@@ -193,23 +210,28 @@ namespace ReallifeGamemode.Server.Bank
int amount = Int32.Parse(stringAmount);
Player target = PlayerService.GetPlayerByNameOrId(nameOrId);
if (!target.IsLoggedIn())
{
player.SendNotification($"~r~Dieser Spieler ist nicht Online.");
return;
}
using (var dbContext = new DatabaseContext())
{
if (!target.IsLoggedIn())
{
player.SendNotification($"~r~Dieser Spieler ist nicht Online.");
}
else if (amount <= 0 || (int)(amount * 1.05) > player.GetUser(dbContext).Faction.BankAccount.Balance)
User user = player.GetUser(dbContext);
User targetUser = target.GetUser(dbContext);
if (amount <= 0 || (int)(amount * 1.05) > user.Faction.BankAccount.Balance)
{
player.SendNotification($"~r~Dieser Betrag kann nicht überwiesen werden.");
return;
}
else
{
player.SendNotification($"~w~Du hast {target.Name} $~g~{amount} ~w~Überwiesen.");
player.GetUser(dbContext).Faction.BankAccount.Balance -= (int)(amount * 1.05);
target.GetUser(dbContext).otheramount += amount;
logger.LogInformation("Player {0} did a faction transfer of {1} dollars from faction {2} to {3}", user.Name, amount, user.Faction.Id, target);
player.SendNotification($"Du hast ~g~{amount.ToMoneyString()}~s~ an ~y~{targetUser.Name}~s~ überwiesen");
target.SendNotification($"Dir wurden ~g~{amount.ToMoneyString()}~s~ von ~y~{user.Name}~s~ überwiesen");
user.Faction.BankAccount.Balance -= (int)(amount * 1.05);
targetUser.otheramount += amount;
dbContext.SaveChanges();
}
}