59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using System.Linq;
|
|
using GTANetworkAPI;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using ReallifeGamemode.Database.Entities;
|
|
using ReallifeGamemode.Database.Models;
|
|
using ReallifeGamemode.Server.Extensions;
|
|
using ReallifeGamemode.Server.Managers;
|
|
|
|
namespace ReallifeGamemode.Server.Util
|
|
{
|
|
class FactionHelper
|
|
{
|
|
public static void CheckFactionBankAccounts()
|
|
{
|
|
NAPI.Util.ConsoleOutput("Checking faction bank accounts...");
|
|
using (var dbContext = new DatabaseContext())
|
|
{
|
|
foreach (Faction faction in dbContext.Factions.Include(f => f.BankAccount))
|
|
{
|
|
if (faction.BankAccount == null)
|
|
{
|
|
NAPI.Util.ConsoleOutput("Adding bank account for faction: " + faction.Name);
|
|
faction.BankAccount = new FactionBankAccount()
|
|
{
|
|
Balance = 100000,
|
|
Bic = "",
|
|
Iban = "",
|
|
Active = true
|
|
};
|
|
}
|
|
}
|
|
dbContext.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public static void ResetPlayer(Player player, User user, DatabaseContext dbContext)
|
|
{
|
|
user.SetData("duty", false);
|
|
|
|
var userClothes = dbContext.CharacterClothes.Where(c => c.UserId == user.Id && c.Duty == true);
|
|
dbContext.CharacterClothes.RemoveRange(userClothes);
|
|
|
|
CharacterCreator.ApplyCharacter(player);
|
|
Events.UpdateCharacterCloth.LoadCharacterDefaults(player);
|
|
|
|
player.TriggerEvent("toggleDutyMode", true);
|
|
int medicCount = 0;
|
|
foreach (Player c in NAPI.Pools.GetAllPlayers())
|
|
{
|
|
if ((c.GetUser()?.Faction?.Id ?? 0) == 2)
|
|
{
|
|
medicCount++;
|
|
}
|
|
}
|
|
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", medicCount);
|
|
}
|
|
}
|
|
}
|