rentcar cancel by afk

This commit is contained in:
Fabian
2021-06-15 10:46:11 +02:00
parent 5fe9b5de8a
commit 39967be34e
8 changed files with 4525 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
@@ -41,7 +41,7 @@ namespace ReallifeGamemode.Server.Commands
return;
}
Rentcar.cancelRent(player);
Rentcar.cancelRent(player, RentCancelReason.byPlayer);
}
[Command("eventport", "~m~eventport")]

View File

@@ -138,7 +138,7 @@ namespace ReallifeGamemode.Server.Events
if (Rentcar.mapPlayerRentcarBill.ContainsKey(player.Name))
{
Rentcar.cancelRent(player);
Rentcar.cancelRent(player, RentCancelReason.byDisconnect);
}
//Vehicle LastVehicle = player.GetData<Vehicle>("LastVehicle");

View File

@@ -4,6 +4,7 @@ using System.Text;
using GTANetworkAPI;
using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Services;
using ReallifeGamemode.Server.Util;
namespace ReallifeGamemode.Server.Events
{
@@ -30,7 +31,11 @@ namespace ReallifeGamemode.Server.Events
{
return;
}
if (Rentcar.mapPlayerRentcarBill.ContainsKey(player.Name))
{
Rentcar.cancelRent(player, RentCancelReason.byAfk);
}
player.SendNotification("Du wurdest ~b~AFK~s~ gesetzt", true);
}
}

View File

@@ -12,6 +12,14 @@ using ReallifeGamemode.Server.Services;
namespace ReallifeGamemode.Server.Util
{
public enum RentCancelReason
{
byPlayer,
byDisconnect,
byAfk,
byNoMoney
}
class Rentcar : Script
{
private static readonly ILogger logger = LogManager.GetLogger<Rentcar>();
@@ -71,19 +79,31 @@ namespace ReallifeGamemode.Server.Util
lamesaVehicleProperties.Add(new RentcarProperty("panto", 200));
}
public static void cancelRent(Player player)
public static void cancelRent(Player player, RentCancelReason cancelReason)
{
using (var dbContext = new DatabaseContext())
{
User user = player.GetUser(dbContext);
user.BankAccount.Balance -= mapPlayerRentcarBill[player.Name].Item2;
logger.LogInformation("Player {0} cancelled a rent and payed {1} dollars", player.Name, mapPlayerRentcarBill[player.Name].Item2);
logger.LogInformation("Player {0} cancelled a rent and payed {1} dollars ({3})", player.Name, mapPlayerRentcarBill[player.Name].Item2, cancelReason.ToString());
dbContext.SaveChanges();
}
if (cancelReason == RentCancelReason.byPlayer)
{
player.SendChatMessage("~y~[Fahrzeugverleih] ~w~Mietfahrzeug erfolgreich gekündigt (Kosten: ~g~$~w~" + mapPlayerRentcarBill[player.Name].Item2 + ").");
}
else if (cancelReason == RentCancelReason.byAfk)
{
player.SendChatMessage("~y~[Fahrzeugverleih] ~w~Da du Afk bist wurde die Fahrzeugmiete automatisch gekündigt");
}
else if (cancelReason == RentCancelReason.byNoMoney)
{
ChatService.ErrorMessage(player, "Du hast nicht genügend Geld auf dem Konto. Dein Mietfahrzeug wurde zurückgegeben");
}
player.SetData("hasRentcar", false);
player.TriggerEvent("abortRentcarTimer");
player.SendChatMessage("~y~[Fahrzeugverleih] ~w~Mietfahrzeug erfolgreich gekündigt (Kosten: ~g~$~w~" + mapPlayerRentcarBill[player.Name].Item2 + ").");
VehicleManager.DeleteVehicle(mapPlayerRentcarBill[player.Name].Item1);
Rentcar.mapPlayerRentcarBill.Remove(player.Name);
}
@@ -102,8 +122,7 @@ namespace ReallifeGamemode.Server.Util
if (bill > user.BankAccount.Balance)
{
ChatService.ErrorMessage(player, "Du hast nicht genügend Geld auf dem Konto. Dein Mietfahrzeug wurde zurückgegeben");
cancelRent(player);
cancelRent(player, RentCancelReason.byNoMoney);
dbContext.SaveChanges();
return;
}