Miese Corona Zeiten push für Lenhardt
This commit is contained in:
@@ -1,86 +1,81 @@
|
||||
/***
|
||||
@overview Life of German - Economy
|
||||
/***
|
||||
@overview Life of German - Economy
|
||||
@author kookroach
|
||||
@copyright (c) 2008 - 2019 Life of German
|
||||
@copyright (c) 2008 - 2019 Life of German
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Services;
|
||||
using Newtonsoft.Json;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using ReallifeGamemode.Server.Services;
|
||||
|
||||
namespace ReallifeGamemode.Server.Finance
|
||||
{
|
||||
public class Economy
|
||||
{
|
||||
public static Dictionary<int, Paycheck> Paychecks { get; set; } = new Dictionary<int, Paycheck>();
|
||||
|
||||
public static (int, float, float) GetEconomyClass(Player client, int wage)
|
||||
{
|
||||
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)
|
||||
financialInterest = 0.7f;
|
||||
public static Dictionary<int, Paycheck> Paychecks { get; set; } = new Dictionary<int, Paycheck>();
|
||||
|
||||
if (financialHelp > 2500)
|
||||
financialHelp = 2500;
|
||||
|
||||
return (bankAccount, financialHelp, financialInterest);
|
||||
}
|
||||
|
||||
public static int GetVehicleTaxation(Player client)
|
||||
{
|
||||
int vehicleTaxation = 0;
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User user = client.GetUser(dbContext);
|
||||
foreach (UserVehicle uVeh in dbContext.UserVehicles.Where(u => u.UserId == user.Id))
|
||||
public static (int, float, float) GetEconomyClass(Player client, int wage)
|
||||
{
|
||||
if (uVeh.Price == null)
|
||||
{
|
||||
vehicleTaxation += 400;
|
||||
continue;
|
||||
}
|
||||
vehicleTaxation += (int)(uVeh.Price * 0.005f);
|
||||
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)
|
||||
financialInterest = 0.7f;
|
||||
|
||||
if (financialHelp > 2500)
|
||||
financialHelp = 2500;
|
||||
|
||||
return (bankAccount, financialHelp, financialInterest);
|
||||
}
|
||||
|
||||
}
|
||||
return vehicleTaxation;
|
||||
}
|
||||
public static int GetVehicleTaxation(Player client)
|
||||
{
|
||||
int vehicleTaxation = 0;
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User user = client.GetUser(dbContext);
|
||||
foreach (UserVehicle uVeh in dbContext.UserVehicles.Where(u => u.UserId == user.Id))
|
||||
{
|
||||
if (uVeh.Price == null)
|
||||
{
|
||||
vehicleTaxation += 400;
|
||||
continue;
|
||||
}
|
||||
vehicleTaxation += (int)(uVeh.Price * 0.005f);
|
||||
}
|
||||
}
|
||||
return vehicleTaxation;
|
||||
}
|
||||
|
||||
public static float GetPropertyTaxation(Player client)
|
||||
{
|
||||
float propertyTaxation = 0;
|
||||
User user = client.GetUser();
|
||||
if (user.HouseId != null)
|
||||
{
|
||||
propertyTaxation += user.House.Price * 0.005f;
|
||||
}
|
||||
public static float GetPropertyTaxation(Player client)
|
||||
{
|
||||
float propertyTaxation = 0;
|
||||
User user = client.GetUser();
|
||||
if (user.HouseId != null)
|
||||
{
|
||||
propertyTaxation += user.House.Price * 0.005f;
|
||||
}
|
||||
|
||||
return propertyTaxation;
|
||||
}
|
||||
return propertyTaxation;
|
||||
}
|
||||
|
||||
public static void SetPaycheck(Player client)
|
||||
{
|
||||
User user = client.GetUser();
|
||||
int wage = user.Wage;
|
||||
(int bankAccount, float financialHelp, float financialInterest) = GetEconomyClass(client, wage);
|
||||
float propertyTax = GetPropertyTaxation(client);
|
||||
int vehicleTaxation = GetVehicleTaxation(client);
|
||||
int rentalFees = GetRentalFees(client);
|
||||
|
||||
public static void SetPaycheck(Player client)
|
||||
{
|
||||
User user = client.GetUser();
|
||||
int wage = user.Wage;
|
||||
(int bankAccount, float financialHelp, float financialInterest) = GetEconomyClass(client, wage);
|
||||
float propertyTax = GetPropertyTaxation(client);
|
||||
int vehicleTaxation = GetVehicleTaxation(client);
|
||||
int rentalFees = GetRentalFees(client);
|
||||
|
||||
int healthInsurance = (int)(user.BankAccount.Balance * 0.001);
|
||||
|
||||
int healthInsurance = (int)(user.BankAccount.Balance * 0.001);
|
||||
|
||||
int? factionMoney = null;
|
||||
|
||||
@@ -96,88 +91,85 @@ namespace ReallifeGamemode.Server.Finance
|
||||
ReleasePayDay(client, paycheck);
|
||||
}
|
||||
|
||||
private static int GetRentalFees(Player client)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User user = client.GetUser();
|
||||
return dbContext.HouseRentals.Where(h => h.UserId == user.Id).Include(h => h.House).Sum(h => h.House.RentalFee);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReleasePayDay(Player client, Paycheck paycheck)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput("in release payday");
|
||||
if (client == null || paycheck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NAPI.Util.ConsoleOutput($"client = {client.Name}, paycheck = {JsonConvert.SerializeObject(paycheck)}");
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User u = client.GetUser(dbContext);
|
||||
NAPI.Util.ConsoleOutput("get user");
|
||||
u.BankAccount.Balance += paycheck.Amount;
|
||||
u.Wage = 0;
|
||||
|
||||
u.PaydayTimer = 60;
|
||||
|
||||
|
||||
NAPI.Util.ConsoleOutput("set sachen");
|
||||
|
||||
var rentals = dbContext.HouseRentals
|
||||
.Include(hR => hR.House)
|
||||
.ThenInclude(h => h.BankAccount)
|
||||
.Where(hR => hR.UserId == u.Id);
|
||||
|
||||
|
||||
NAPI.Util.ConsoleOutput("get rentals");
|
||||
|
||||
dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Id == 2).First().BankAccount.Balance += (int)(paycheck.HealthInsurance * 0.1);
|
||||
|
||||
if (rentals.Any())
|
||||
private static int GetRentalFees(Player client)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput("hat rentals");
|
||||
foreach (var rental in rentals)
|
||||
{
|
||||
if (rental?.House?.BankAccount != null)
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
rental.House.BankAccount.Balance += (int)(rental.House.RentalFee * 0.7);
|
||||
User user = client.GetUser();
|
||||
return dbContext.HouseRentals.Where(h => h.UserId == user.Id).Include(h => h.House).Sum(h => h.House.RentalFee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
if (paycheck.Amount > 0)
|
||||
ChatService.SendMessage(client, "~g~[PAYDAY]~s~ Dein Stundenumsatz beträgt + $~g~" + paycheck.Amount + "~s~.");
|
||||
else
|
||||
ChatService.SendMessage(client, "~g~[PAYDAY]~s~ Dein Stundenumsatz beträgt - $~r~" + paycheck.Amount + "~s~.");
|
||||
|
||||
}
|
||||
|
||||
public static void Timer_Elapsed()
|
||||
{
|
||||
using var dbContext = new DatabaseContext();
|
||||
foreach (var player in NAPI.Pools.GetAllPlayers())
|
||||
{
|
||||
User user = player.GetUser(dbContext);
|
||||
if (player.IsLoggedIn())
|
||||
public static void ReleasePayDay(Player client, Paycheck paycheck)
|
||||
{
|
||||
if (user.PaydayTimer <= 0)
|
||||
{
|
||||
Economy.SetPaycheck(player);
|
||||
user.PaydayTimer = 60;
|
||||
}
|
||||
else if (user.PaydayTimer > 0)
|
||||
{
|
||||
user.PaydayTimer -= 1;
|
||||
}
|
||||
NAPI.Util.ConsoleOutput("in release payday");
|
||||
if (client == null || paycheck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NAPI.Util.ConsoleOutput($"client = {client.Name}, paycheck = {JsonConvert.SerializeObject(paycheck)}");
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User u = client.GetUser(dbContext);
|
||||
NAPI.Util.ConsoleOutput("get user");
|
||||
u.BankAccount.Balance += paycheck.Amount;
|
||||
u.Wage = 0;
|
||||
|
||||
u.PaydayTimer = 60;
|
||||
|
||||
NAPI.Util.ConsoleOutput("set sachen");
|
||||
|
||||
var rentals = dbContext.HouseRentals
|
||||
.Include(hR => hR.House)
|
||||
.ThenInclude(h => h.BankAccount)
|
||||
.Where(hR => hR.UserId == u.Id);
|
||||
|
||||
NAPI.Util.ConsoleOutput("get rentals");
|
||||
|
||||
dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Id == 2).First().BankAccount.Balance += (int)(paycheck.HealthInsurance * 0.1);
|
||||
|
||||
if (rentals.Any())
|
||||
{
|
||||
NAPI.Util.ConsoleOutput("hat rentals");
|
||||
foreach (var rental in rentals)
|
||||
{
|
||||
if (rental?.House?.BankAccount != null)
|
||||
{
|
||||
rental.House.BankAccount.Balance += (int)(rental.House.RentalFee * 0.7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
if (paycheck.Amount > 0)
|
||||
ChatService.SendMessage(client, "~g~[PAYDAY]~s~ Dein Stundenumsatz beträgt + $~g~" + paycheck.Amount + "~s~.");
|
||||
else
|
||||
ChatService.SendMessage(client, "~g~[PAYDAY]~s~ Dein Stundenumsatz beträgt - $~r~" + paycheck.Amount + "~s~.");
|
||||
}
|
||||
|
||||
public static void Timer_Elapsed()
|
||||
{
|
||||
using var dbContext = new DatabaseContext();
|
||||
foreach (var player in NAPI.Pools.GetAllPlayers())
|
||||
{
|
||||
User user = player.GetUser(dbContext);
|
||||
if (player.IsLoggedIn())
|
||||
{
|
||||
if (user.PaydayTimer <= 0)
|
||||
{
|
||||
Economy.SetPaycheck(player);
|
||||
user.PaydayTimer = 60;
|
||||
}
|
||||
else if (user.PaydayTimer > 0)
|
||||
{
|
||||
user.PaydayTimer -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Services;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ReallifeGamemode.Server.Finance
|
||||
{
|
||||
public class Paycheck
|
||||
{
|
||||
[JsonProperty("financialHelp")]
|
||||
public float FinancialHelp { get; set; } = 0;
|
||||
{
|
||||
[JsonProperty("financialHelp")]
|
||||
public float FinancialHelp { get; set; } = 0;
|
||||
|
||||
[JsonProperty("financialInterest")]
|
||||
public float FinancialInterest { get; set; } = 0;
|
||||
[JsonProperty("financialInterest")]
|
||||
public float FinancialInterest { get; set; } = 0;
|
||||
|
||||
[JsonProperty("vehicleTaxation")]
|
||||
public int VehicleTaxation { get; set; } = 0;
|
||||
[JsonProperty("vehicleTaxation")]
|
||||
public int VehicleTaxation { get; set; } = 0;
|
||||
|
||||
[JsonProperty("propertyTaxation")]
|
||||
public float PropertyTaxation { get; set; } = 0;
|
||||
[JsonProperty("propertyTaxation")]
|
||||
public float PropertyTaxation { get; set; } = 0;
|
||||
|
||||
[JsonProperty("wage")]
|
||||
public int Wage { get; set; } = 0;
|
||||
[JsonProperty("wage")]
|
||||
public int Wage { get; set; } = 0;
|
||||
|
||||
[JsonProperty("amount")]
|
||||
public int Amount { get; set; } = 0;
|
||||
[JsonProperty("amount")]
|
||||
public int Amount { get; set; } = 0;
|
||||
|
||||
[JsonProperty("rentalFees")]
|
||||
public int RentalFees { get; set; } = 0;
|
||||
[JsonProperty("rentalFees")]
|
||||
public int RentalFees { get; set; } = 0;
|
||||
|
||||
[JsonProperty("healthInsurance")]
|
||||
public int HealthInsurance { get; set; } = 0;
|
||||
[JsonProperty("healthInsurance")]
|
||||
public int HealthInsurance { get; set; } = 0;
|
||||
|
||||
[JsonProperty("factionMoney")]
|
||||
public int? FactionMoney { get; set; } = 0;
|
||||
@@ -53,4 +44,4 @@ namespace ReallifeGamemode.Server.Finance
|
||||
this.FactionMoney = FactionMoney;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user