Start finance system
This commit is contained in:
@@ -15,10 +15,11 @@ using ReallifeGamemode.Server.Classes;
|
|||||||
using ReallifeGamemode.Server.Factions.Medic;
|
using ReallifeGamemode.Server.Factions.Medic;
|
||||||
using ReallifeGamemode.Server.Models;
|
using ReallifeGamemode.Server.Models;
|
||||||
using ReallifeGamemode.Server.Job;
|
using ReallifeGamemode.Server.Job;
|
||||||
|
using ReallifeGamemode.Server.Finance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @overview Life of German Reallife - Admin Commands (Admin.cs)
|
* @overview Life of German Reallife - Admin Commands (Admin.cs)
|
||||||
* @author VegaZ, hydrant, xSprite, balbo
|
* @author VegaZ, hydrant, xSprite, balbo, kookroach
|
||||||
* @copyright (c) 2008 - 2018 Life of German
|
* @copyright (c) 2008 - 2018 Life of German
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -2558,6 +2559,47 @@ namespace ReallifeGamemode.Server.Commands
|
|||||||
|
|
||||||
player.SendChatMessage("~m~Benutzung: ~s~/house [add / remove / price / type / reloadhouses]");
|
player.SendChatMessage("~m~Benutzung: ~s~/house [add / remove / price / type / reloadhouses]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Command("paydaydrop", "~m~Benutzung: ~s~/paydaydrop")]
|
||||||
|
public void CmdAdminPaydaydrop(Client player)
|
||||||
|
{
|
||||||
|
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
|
||||||
|
{
|
||||||
|
ChatService.NotAuthorized(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var target in NAPI.Pools.GetAllPlayers().Select(c => c.GetUser()))
|
||||||
|
{
|
||||||
|
Economy.SetPaycheck(target.Client, target.Wage);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast ein Payday gedroppt.");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("setwage", "~m~Benutzung: ~s~/setwage [Name/Id] [Lohn]")]
|
||||||
|
public void CmdAdminSetWage(Client player, string nameOrId, int wage)
|
||||||
|
{
|
||||||
|
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
|
||||||
|
{
|
||||||
|
ChatService.NotAuthorized(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Client target = ClientService.GetClientByNameOrId(nameOrId);
|
||||||
|
if (target == null || !target.IsLoggedIn())
|
||||||
|
{
|
||||||
|
ChatService.PlayerNotFound(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
target.GetUser(dbContext).Wage = wage;
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ALevel1338
|
#region ALevel1338
|
||||||
|
|||||||
@@ -28,5 +28,12 @@ namespace ReallifeGamemode.Server.Commands
|
|||||||
}
|
}
|
||||||
ChatService.SendMessage(player, "~m~" + ((VehicleHash)pVeh.Model) + " | Farbe 1: " + pVeh.PrimaryColor + " | Farbe 2: " + pVeh.SecondaryColor + " | ID: " + pVeh.Handle.Value);
|
ChatService.SendMessage(player, "~m~" + ((VehicleHash)pVeh.Model) + " | Farbe 1: " + pVeh.PrimaryColor + " | Farbe 2: " + pVeh.SecondaryColor + " | ID: " + pVeh.Handle.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Command("paycheck", "~m~Benutzung: ~s~/paycheck")]
|
||||||
|
public void CmdUserPaycheck(Client client)
|
||||||
|
{
|
||||||
|
ChatService.SendMessage(client, "~g~[PAYCHECK] -------------------------------------------------------");
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ namespace ReallifeGamemode.Server.Entities
|
|||||||
Client.TriggerEvent("SERVER:SetWanteds", value);
|
Client.TriggerEvent("SERVER:SetWanteds", value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int Wage { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
||||||
|
|
||||||
|
|||||||
180
ReallifeGamemode.Server/Finance/Economy.cs
Normal file
180
ReallifeGamemode.Server/Finance/Economy.cs
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
/***
|
||||||
|
@overview Life of German - Economy
|
||||||
|
@author kookroach
|
||||||
|
@copyright (c) 2008 - 2019 Life of German
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using GTANetworkAPI;
|
||||||
|
using ReallifeGamemode.Server.Entities;
|
||||||
|
using ReallifeGamemode.Server.Extensions;
|
||||||
|
using ReallifeGamemode.Server.Models;
|
||||||
|
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(Client client)
|
||||||
|
{
|
||||||
|
int bankAccount = client.GetUser().GetBankAccount().Balance;
|
||||||
|
float financialHelp = (float)Math.Pow(-1.0005, -bankAccount) * -1000;
|
||||||
|
float financialInterest = 1 - (float)Math.Pow(1.00005, -bankAccount) * 1;
|
||||||
|
|
||||||
|
return (bankAccount, financialHelp, financialInterest);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int GetVehicleTaxation(Client client)
|
||||||
|
{
|
||||||
|
int vehicleTaxation = 0;
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
User user = client.GetUser(dbContext);
|
||||||
|
foreach (VehicleHash vehHash in dbContext.UserVehicles.Where(u => u.UserId == user.Id).Select(u => u.Model))
|
||||||
|
{
|
||||||
|
int type = NAPI.Vehicle.GetVehicleClass(vehHash);
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
0 Compacts
|
||||||
|
1 Sedans
|
||||||
|
2 SUVs
|
||||||
|
3 Coupes
|
||||||
|
4 Muscle
|
||||||
|
5 Sports
|
||||||
|
6 Sports
|
||||||
|
7 Super
|
||||||
|
8 Motorcycles
|
||||||
|
9 Off-Road
|
||||||
|
10 Industrial
|
||||||
|
11 Utility
|
||||||
|
12 Vans
|
||||||
|
13 Cycles
|
||||||
|
14 Boats
|
||||||
|
15 Helicopters
|
||||||
|
16 Planes
|
||||||
|
17 Service
|
||||||
|
18 Emergency
|
||||||
|
19 Military
|
||||||
|
20 Commercial
|
||||||
|
21 Trains
|
||||||
|
*/
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
vehicleTaxation += 250;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
vehicleTaxation += 350;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
vehicleTaxation += 500;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
vehicleTaxation += 400;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
vehicleTaxation += 300;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
vehicleTaxation += 800;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
vehicleTaxation += 950;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
vehicleTaxation += 0;
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
vehicleTaxation += 400;
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
vehicleTaxation += 500;
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
vehicleTaxation += 300;
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
vehicleTaxation += 0;
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
vehicleTaxation += 350;
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
|
vehicleTaxation += 0;
|
||||||
|
break;
|
||||||
|
case 14:
|
||||||
|
vehicleTaxation += 500;
|
||||||
|
break;
|
||||||
|
case 15:
|
||||||
|
vehicleTaxation += 650;
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
vehicleTaxation += 750;
|
||||||
|
break;
|
||||||
|
case 17:
|
||||||
|
vehicleTaxation += 0;
|
||||||
|
break;
|
||||||
|
case 18:
|
||||||
|
vehicleTaxation += 0;
|
||||||
|
break;
|
||||||
|
case 19:
|
||||||
|
vehicleTaxation += 0;
|
||||||
|
break;
|
||||||
|
case 20:
|
||||||
|
vehicleTaxation += 400;
|
||||||
|
break;
|
||||||
|
case 21:
|
||||||
|
vehicleTaxation += 69696969;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vehicleTaxation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float GetPropertyTaxation(Client client)
|
||||||
|
{
|
||||||
|
float propertyTaxation = 0;
|
||||||
|
User user = client.GetUser();
|
||||||
|
if (user.HouseId != null)
|
||||||
|
{
|
||||||
|
propertyTaxation += user.House.Price * 0.005f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return propertyTaxation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void SetPaycheck(Client client, int wage)
|
||||||
|
{
|
||||||
|
(int bankAccount, float financialHelp, float financialInterest) = GetEconomyClass(client);
|
||||||
|
float propertyTax = GetPropertyTaxation(client);
|
||||||
|
int vehicleTaxation = GetVehicleTaxation(client);
|
||||||
|
|
||||||
|
int amount = wage - (int)(wage * financialInterest) - vehicleTaxation - (int)propertyTax + (int)financialHelp;
|
||||||
|
|
||||||
|
Paycheck paycheck = new Paycheck(financialHelp, financialInterest, vehicleTaxation, propertyTax, wage, amount);
|
||||||
|
|
||||||
|
ReleasePayDay(client, paycheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ReleasePayDay(Client client, Paycheck paycheck)
|
||||||
|
{
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
client.GetUser().GetBankAccount(dbContext).Balance += paycheck.Amount;
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
if (paycheck.Amount > 0)
|
||||||
|
ChatService.SendMessage(client, "~g~[PAYDAY]~s~ Du hast einen Payday von ~g~$" + paycheck.Amount + "~s~ bekommen.");
|
||||||
|
else
|
||||||
|
ChatService.SendMessage(client, "~g~[PAYDAY]~s~ Du hast einen Payday von ~r~$" + paycheck.Amount + "~s~ bekommen.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
34
ReallifeGamemode.Server/Finance/Paycheck.cs
Normal file
34
ReallifeGamemode.Server/Finance/Paycheck.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using GTANetworkAPI;
|
||||||
|
using ReallifeGamemode.Server.Entities;
|
||||||
|
using ReallifeGamemode.Server.Extensions;
|
||||||
|
using ReallifeGamemode.Server.Models;
|
||||||
|
using ReallifeGamemode.Server.Services;
|
||||||
|
|
||||||
|
namespace ReallifeGamemode.Server.Finance
|
||||||
|
{
|
||||||
|
public class Paycheck
|
||||||
|
{
|
||||||
|
public float FinancialHelp { get; set; } = 0;
|
||||||
|
public float FinancialInterest { get; set; } = 0;
|
||||||
|
public int VehicleTaxation { get; set; } = 0;
|
||||||
|
public float PropertyTaxation { get; set; } = 0;
|
||||||
|
public int Wage { get; set; } = 0;
|
||||||
|
public int Amount { get; set; } = 0;
|
||||||
|
|
||||||
|
public Paycheck(float FinancialHelp, float FinancialInterest, int VehicleTaxation, float PropertyTaxation, int Wage, int Amount)
|
||||||
|
{
|
||||||
|
this.FinancialHelp = FinancialHelp;
|
||||||
|
this.FinancialInterest = FinancialInterest;
|
||||||
|
this.VehicleTaxation = VehicleTaxation;
|
||||||
|
this.PropertyTaxation = PropertyTaxation;
|
||||||
|
this.Wage = Wage;
|
||||||
|
this.Amount = Amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
1161
ReallifeGamemode.Server/Migrations/20190706132925_UserWage.Designer.cs
generated
Normal file
1161
ReallifeGamemode.Server/Migrations/20190706132925_UserWage.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace ReallifeGamemode.Migrations
|
||||||
|
{
|
||||||
|
public partial class UserWage : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "Wage",
|
||||||
|
table: "Users",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Wage",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,11 +23,6 @@
|
|||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.4" />
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.4" />
|
||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Condition="'$(ConfigurationName)' != 'ServerBuild'">
|
|
||||||
<Reference Include="Bootstrapper">
|
|
||||||
<HintPath>..\..\bridge\runtime\Bootstrapper.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup Condition="'$(ConfigurationName)' == 'ServerBuild'">
|
<ItemGroup Condition="'$(ConfigurationName)' == 'ServerBuild'">
|
||||||
<Reference Include="Bootstrapper">
|
<Reference Include="Bootstrapper">
|
||||||
<HintPath>..\..\Bootstrapper.dll</HintPath>
|
<HintPath>..\..\Bootstrapper.dll</HintPath>
|
||||||
@@ -36,6 +31,11 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Properties\" />
|
<Folder Include="Properties\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Bootstrapper">
|
||||||
|
<HintPath>..\..\bridge\runtime\Bootstrapper.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(ConfigurationName)' != 'ServerBuild'">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(ConfigurationName)' != 'ServerBuild'">
|
||||||
<Exec Command="powershell.exe .\Scripts\moveItems.ps1 -outDir $(OutDir) -outFile $(TargetFileName)" />
|
<Exec Command="powershell.exe .\Scripts\moveItems.ps1 -outDir $(OutDir) -outFile $(TargetFileName)" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|||||||
Reference in New Issue
Block a user