Fix missing database migration

This commit is contained in:
hydrant
2019-07-21 16:50:18 +02:00
parent 28e6a461f0
commit 29c0e8771f
14 changed files with 1816 additions and 97 deletions

View File

@@ -131,66 +131,166 @@ namespace ReallifeGamemode.Server.Events
var user = player.GetUser();
if (user?.FactionId != null)
{
DutyPoint nearest = PositionManager.DutyPoints.Find(d => d.Position.DistanceTo(player.Position) <= 1.5 && d.FactionId == user.FactionId);
if (nearest == null) return;
var nameTagColor = new Color(0, 0, 0);
var factionId = user.FactionId;
if (user.GetData<bool>("duty") == false)
DutyPoint nearestDuty = PositionManager.DutyPoints.Find(d => d.Position.DistanceTo(player.Position) <= 1.5 && d.FactionId == user.FactionId);
WeaponPoint nearestWeapon = PositionManager.WeaponPoints.Find(w => w.Position.DistanceTo(player.Position) <= 1.5 && w.FactionId == user.FactionId);
JailReleasePoint nearestJailReleasePoint = PositionManager.JailReleasePoints.Find(j => j.Position.DistanceTo(player.Position) <= 1.5 && (user.FactionId == 1 || user.FactionId == 3) && user.GetData<bool>("duty"));
if (nearestDuty != null)// Duty Point
{
user.SetData("duty", true);
player.SendNotification("Du bist nun ~g~im Dienst.");
if (player.GetUser().FactionId == 2) //Fire Department
{
int medicCount = 0;
foreach (Client c in NAPI.Pools.GetAllPlayers())
{
if ((c.GetUser()?.Faction.Id ?? 0) == 2)
{
medicCount++;
}
}
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", medicCount);
}
switch (factionId)
{
//LSPD
case 1:
nameTagColor = new Color(28, 134, 238);
break;
}
player.NametagColor = nameTagColor;
using (var context = new DatabaseContext())
{
List<CharacterCloth> clothes = context.CharacterClothes.Where(u => u.UserId == user.Id && u.Duty == true).ToList();
var nameTagColor = new Color(0, 0, 0);
var factionId = user.FactionId;
foreach (var cloth in clothes)
if (user.GetData<bool>("duty") == false)
{
user.SetData("duty", true);
player.SendNotification("Du bist nun ~g~im Dienst.");
if (player.GetUser().FactionId == 2) //Fire Department
{
if (cloth.SlotType == 0)
int medicCount = 0;
foreach (Client c in NAPI.Pools.GetAllPlayers())
{
player.SetClothes(cloth.SlotId, cloth.ClothId, 0);
}
else
{
if (cloth.ClothId != -1)
if ((c.GetUser()?.Faction.Id ?? 0) == 2)
{
player.SetAccessories(cloth.SlotId, cloth.ClothId, 0);
medicCount++;
}
}
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", medicCount);
}
switch (factionId)
{
//LSPD
case 1:
nameTagColor = new Color(28, 134, 238);
player.SetSharedData("blipColor", 38);
break;
//Medic
case 2:
nameTagColor = new Color(255, 0, 0);
player.SetSharedData("blipColor", 79);
break;
//FBI
case 3:
nameTagColor = new Color(173, 0, 118);
player.SetSharedData("blipColor", 83);
break;
}
player.NametagColor = nameTagColor;
using (var context = new DatabaseContext())
{
List<CharacterCloth> clothes = context.CharacterClothes.Where(u => u.UserId == user.Id && u.Duty == true).ToList();
foreach (var cloth in clothes)
{
if (cloth.SlotType == 0)
{
player.SetClothes(cloth.SlotId, cloth.ClothId, 0);
}
else
{
player.ClearAccessory(cloth.SlotId);
if (cloth.ClothId != -1)
{
player.SetAccessories(cloth.SlotId, cloth.ClothId, 0);
}
else
{
player.ClearAccessory(cloth.SlotId);
}
}
}
}
}
else
{
user.SetData("duty", false);
player.SendNotification("Du bist nun ~r~außer Dienst.");
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", false);
player.NametagColor = new Color(255, 255, 255);
UpdateCharacterCloth.LoadCharacterDefaults(player);
}
}
else
if (nearestWeapon != null) // Weapon Point
{
user.SetData("duty", false);
player.SendNotification("Du bist nun ~r~außer Dienst.");
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", false);
player.NametagColor = new Color(255, 255, 255);
UpdateCharacterCloth.LoadCharacterDefaults(player);
List<string> primarys = new List<string>();
List<string> secondarys = new List<string>();
List<string> melees = new List<string>();
List<string> specials = new List<string>();
using (var context = new DatabaseContext())
{
List<FactionWeapon> weapons = context.FactionWeapons.ToList().FindAll(w => w.FactionId == user.FactionId);
foreach (var weapon in weapons)
{
switch (weapon.SlotID)
{
case 1:
if (weapon.WeaponHash != -1)
{
if (user.FactionRank.Order >= weapon.Rank)
primarys.Add(weapon.WeaponModel.ToString());
}
else
{
primarys.Add("Keine");
}
break;
case 2:
if (weapon.WeaponHash != -1)
{
if (user.FactionRank.Order >= weapon.Rank)
secondarys.Add(weapon.WeaponModel.ToString());
}
else
{
secondarys.Add("Keine");
}
break;
case 3:
if (weapon.WeaponHash != -1)
{
if (user.FactionRank.Order >= weapon.Rank)
melees.Add(weapon.WeaponModel.ToString());
}
else
{
melees.Add("Keine");
}
break;
case 4:
if (weapon.WeaponHash != -1)
{
if (user.FactionRank.Order >= weapon.Rank)
specials.Add(weapon.WeaponModel.ToString());
}
else
{
specials.Add("Keine");
specials.Add("Schutzweste");
}
break;
}
}
}
player.TriggerEvent("showWeaponMenu", primarys.ToArray(), secondarys.ToArray(), melees.ToArray(), specials.ToArray());
}
if(nearestJailReleasePoint != null)
{
List<string> criminals = new List<string>();
foreach (Client target in NAPI.Pools.GetAllPlayers())
{
User c = target.GetUser();
{
if (c.JailTime > 0)
{
criminals.Add(c.Name.ToString());
}
}
}
player.TriggerEvent("showJailMenu", criminals.ToArray());
}
}
}