add bank (überweisen, einzahlen, auszahlen, Fraktionskasse)
This commit is contained in:
203
ReallifeGamemode.Server/Bank/bank.cs
Normal file
203
ReallifeGamemode.Server/Bank/bank.cs
Normal file
@@ -0,0 +1,203 @@
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using ReallifeGamemode.Server.Finance;
|
||||
using ReallifeGamemode.Services;
|
||||
using System;
|
||||
|
||||
|
||||
namespace ReallifeGamemode.Server.Bank
|
||||
{
|
||||
class bank : Script
|
||||
{
|
||||
private static TextLabel informationLabel;
|
||||
private static TextLabel factionInformationLabel;
|
||||
private static Marker marker;
|
||||
private static Marker factionMarker;
|
||||
private static ColShape _colShape;
|
||||
private static ColShape _factioncolShape;
|
||||
public static Vector3 Position { get; }
|
||||
|
||||
|
||||
public static void Setup()
|
||||
{
|
||||
informationLabel = NAPI.TextLabel.CreateTextLabel("Bank", new Vector3(246.48, 223.01, 106.28), 20.0f, 1.3f, 0, new Color(255, 255, 255));
|
||||
marker = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, new Vector3(246.48, 223.01, 105.28), new Vector3(), new Vector3(), 1f, new Color(255, 255, 255));
|
||||
|
||||
factionInformationLabel = NAPI.TextLabel.CreateTextLabel("Fraktionskasse", new Vector3(251.61, 221.32, 106.28), 20.0f, 1.3f, 0, new Color(255, 255, 255));
|
||||
factionMarker = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, new Vector3(251.61, 221.32, 105.28), new Vector3(), new Vector3(), 1f, new Color(255, 255, 255));
|
||||
|
||||
_colShape = NAPI.ColShape.CreateSphereColShape(new Vector3(246.48, 223.01, 105.28), 2f);
|
||||
_colShape.OnEntityEnterColShape += EntityEnterBankColShape;
|
||||
_colShape.OnEntityExitColShape += EntityExitBankColShape;
|
||||
|
||||
_factioncolShape = NAPI.ColShape.CreateSphereColShape(new Vector3(251.61, 221.32, 105.28), 2f);
|
||||
_factioncolShape.OnEntityEnterColShape += EntityEnterFactionBankColShape;
|
||||
_factioncolShape.OnEntityExitColShape += EntityExitFactionBankColShape;
|
||||
|
||||
NAPI.Blip.CreateBlip(207, new Vector3(231.35, 214.98, 106.27), 1.0f, 2, "Bank", shortRange: true);
|
||||
}
|
||||
|
||||
private static void EntityEnterBankColShape(ColShape colShape, Player client)
|
||||
{
|
||||
if (client.IsInVehicle || !client.IsLoggedIn()) return;
|
||||
|
||||
client.TriggerEvent("showBankMenu");
|
||||
}
|
||||
|
||||
private static void EntityExitBankColShape(ColShape colShape, Player client)
|
||||
{
|
||||
client.TriggerEvent("removeBankmenu");
|
||||
}
|
||||
|
||||
private static void EntityEnterFactionBankColShape(ColShape colShape, Player client)
|
||||
{
|
||||
if (client.IsInVehicle || !client.IsLoggedIn()) return;
|
||||
|
||||
if (client.GetUser().FactionLeader == true)
|
||||
{
|
||||
client.TriggerEvent("showFactionBankMenuLeader", client.GetUser().Faction.BankAccount.Balance.ToString());
|
||||
}
|
||||
client.TriggerEvent("showFactionBankMenu", client.GetUser().Faction.BankAccount.Balance.ToString());
|
||||
}
|
||||
|
||||
private static void EntityExitFactionBankColShape(ColShape colShape, Player client)
|
||||
{
|
||||
client.TriggerEvent("removeFactionBankmenu");
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:payIn")]
|
||||
public void bank_payIn(Player player, string stringAmount)
|
||||
{
|
||||
int amount = Int32.Parse(stringAmount);
|
||||
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
|
||||
if (amount <= 0 || amount > player.GetUser(dbContext).Handmoney)
|
||||
{
|
||||
player.SendNotification($"~r~Dieser Betrag ist ungültig.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SendNotification($"~w~Du hast $~g~{amount} ~w~eingezahlt.");
|
||||
player.GetUser(dbContext).Handmoney -= amount;
|
||||
player.GetUser(dbContext).BankAccount.Balance += amount;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
[RemoteEvent("CLIENT:payOut")]
|
||||
public void bank_payOut(Player player, string stringAmount)
|
||||
{
|
||||
int amount = Int32.Parse(stringAmount);
|
||||
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
|
||||
if (amount <= 0 || amount > player.GetUser(dbContext).BankAccount.Balance)
|
||||
{
|
||||
player.SendNotification($"~r~Dieser Betrag ist ungültig.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SendNotification($"~w~Du hast $~g~{amount} ~w~abgehoben.");
|
||||
player.GetUser(dbContext).Handmoney += amount;
|
||||
player.GetUser(dbContext).BankAccount.Balance -= amount;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:payment")]
|
||||
public void bank_payment(Player player, string jsonNameOrId, string stringAmount)
|
||||
{
|
||||
string nameOrId = (string)JsonConvert.DeserializeObject(jsonNameOrId);
|
||||
int amount = Int32.Parse(stringAmount);
|
||||
Player target = PlayerService.GetPlayerByNameOrId(nameOrId);
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
if(player.GetUser(dbContext) == target.GetUser(dbContext))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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).BankAccount.Balance -= (int)(amount*1.05);
|
||||
target.GetUser(dbContext).otheramount = amount;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
[RemoteEvent("CLIENT:factionPayIn")]
|
||||
public void bank_factionPayIn(Player player, string stringAmount)
|
||||
{
|
||||
int amount = Int32.Parse(stringAmount);
|
||||
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
|
||||
if (amount <= 0 || amount > player.GetUser(dbContext).Handmoney)
|
||||
{
|
||||
player.SendNotification($"~r~Dieser Betrag ist ungültig.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SendNotification($"~w~Du hast $~g~{amount} ~w~ in die Fraktionskasse eingezahlt.");
|
||||
player.GetUser(dbContext).Handmoney -= amount;
|
||||
player.GetUser(dbContext).Faction.BankAccount.Balance += amount;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:factionPayment")]
|
||||
public void bank_factionPayment(Player player, string jsonNameOrId, string stringAmount)
|
||||
{
|
||||
string nameOrId = (string)JsonConvert.DeserializeObject(jsonNameOrId);
|
||||
int amount = Int32.Parse(stringAmount);
|
||||
Player target = PlayerService.GetPlayerByNameOrId(nameOrId);
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -76,7 +76,7 @@ namespace ReallifeGamemode.Server.Finance
|
||||
float propertyTax = GetPropertyTaxation(client);
|
||||
int vehicleTaxation = GetVehicleTaxation(client);
|
||||
int rentalFees = GetRentalFees(client);
|
||||
|
||||
|
||||
int healthInsurance = (int)(user.BankAccount.Balance * 0.001);
|
||||
if (healthInsurance < 0)
|
||||
{
|
||||
@@ -89,10 +89,10 @@ namespace ReallifeGamemode.Server.Finance
|
||||
{
|
||||
factionMoney = user.FactionRank.Order * 1000;
|
||||
}
|
||||
int otheramount = user.otheramount;
|
||||
int amount = wage - (int)(wage * financialInterest) - vehicleTaxation - (int)propertyTax + (int)financialHelp - rentalFees - healthInsurance + (factionMoney ?? 0) + otheramount;
|
||||
|
||||
int amount = wage - (int)(wage * financialInterest) - vehicleTaxation - (int)propertyTax + (int)financialHelp - rentalFees - healthInsurance + (factionMoney ?? 0);
|
||||
|
||||
Paycheck paycheck = new Paycheck(financialHelp, financialInterest, vehicleTaxation, propertyTax, wage, amount, rentalFees, healthInsurance, factionMoney);
|
||||
Paycheck paycheck = new Paycheck(financialHelp, financialInterest, vehicleTaxation, propertyTax, wage, amount, rentalFees, healthInsurance, factionMoney, otheramount);
|
||||
Paychecks[user.Id] = paycheck;
|
||||
ReleasePayDay(client, paycheck, minusJail);
|
||||
}
|
||||
@@ -136,7 +136,7 @@ namespace ReallifeGamemode.Server.Finance
|
||||
|
||||
u.BankAccount.Balance += paycheck.Amount;
|
||||
u.Wage = 0;
|
||||
|
||||
u.otheramount = 0;
|
||||
u.PaydayTimer = 60;
|
||||
|
||||
var rentals = dbContext.HouseRentals
|
||||
|
||||
@@ -31,7 +31,10 @@ namespace ReallifeGamemode.Server.Finance
|
||||
[JsonProperty("factionMoney")]
|
||||
public int? FactionMoney { get; set; } = 0;
|
||||
|
||||
public Paycheck(float FinancialHelp, float FinancialInterest, int VehicleTaxation, float PropertyTaxation, int Wage, int Amount, int RentalFees, int HealthInsurance, int? FactionMoney)
|
||||
[JsonProperty("otheramount")]
|
||||
public int? otheramount { get; set; } = 0;
|
||||
|
||||
public Paycheck(float FinancialHelp, float FinancialInterest, int VehicleTaxation, float PropertyTaxation, int Wage, int Amount, int RentalFees, int HealthInsurance, int? FactionMoney, int? otheramount)
|
||||
{
|
||||
this.FinancialHelp = FinancialHelp;
|
||||
this.FinancialInterest = FinancialInterest;
|
||||
@@ -42,6 +45,7 @@ namespace ReallifeGamemode.Server.Finance
|
||||
this.RentalFees = RentalFees;
|
||||
this.HealthInsurance = HealthInsurance;
|
||||
this.FactionMoney = FactionMoney;
|
||||
this.otheramount = otheramount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +129,7 @@ namespace ReallifeGamemode.Server
|
||||
DrivingSchool.DrivingSchool.Setup();
|
||||
PlaneSchool.Setup();
|
||||
Gangwar.Gangwar.loadTurfs();
|
||||
Bank.bank.Setup();
|
||||
|
||||
TempBlip tempBlip = new TempBlip()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user