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

@@ -254,51 +254,7 @@ namespace ReallifeGamemode.Server.Commands
}
}
[Command("release", "~m~Benutzung: ~s~/release [Name / ID] [Grund]", GreedyArg = true)]
public void CmdFactionJailRelease(Client player, string nameOrId, string reason)
{
User user = player.GetUser();
if (user == null || (user.FactionId != 1 && user.FactionId != 3))
{
ChatService.NotAuthorized(player);
return;
}
Client target = ClientService.GetClientByNameOrId(nameOrId);
if (target == null || !target.IsLoggedIn())
{
ChatService.PlayerNotFound(player);
return;
}
User targetCop = target.GetUser();
if (targetCop.FactionId == 1 || targetCop.FactionId == 3)
{
ChatService.ErrorMessage(player, "Diese Person sollte sich nicht im Knast befinden");
return;
}
if (target.Position.DistanceTo(player.Position) < 6)
{
User targetUser = target.GetUser();
if (targetUser.JailTime > 0)
{
Jail.Release_Jail(target, reason);
ChatService.SendMessage(target, "~r~Du wurdest von " + player.Name + " aus dem Knast befreit");
ChatService.BroadcastFaction("~r~HQ: " + user.Name + " wurde von " + player.Name + " aus dem Knast entlassen. Grund: " + reason + ".", new List<int>() { 1, 3 });
}
else
{
ChatService.ErrorMessage(player, "Diese Person befindet sich nicht im Knast");
return;
}
}
else
{
ChatService.ErrorMessage(player, "Du bist zu weit entfernt");
return;
}
}
#endregion

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
using GTANetworkAPI;
namespace ReallifeGamemode.Server.Entities
{
public class FactionWeapon
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("Faction")]
public int FactionId { get; set; }
public Faction Faction { get; set; }
public int WeaponHash { get; set; }
public string WeaponModel { get; set; }
public int SlotID { get; set; }
public int Rank { get; set; }
}
}

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());
}
}
}

View File

@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GTANetworkAPI;
using Newtonsoft.Json;
using ReallifeGamemode.Server.Entities;
using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Models;
namespace ReallifeGamemode.Server.Events
{
public class UpdateCharacterWeapon : Script
{
[RemoteEvent("updateWeaponSelection")]
public void UpdateWeaponSelection(Client client, string weaponModel, int slot)
{
if(weaponModel == "Schutzweste")
{
client.Armor = 100;
return;
}
WeaponHash weaponHash = NAPI.Util.WeaponNameToModel(weaponModel);
if (slot == 1)
{
client.RemoveAllWeapons();
client.GiveWeapon(weaponHash, 0);
}
if (slot == 2)
{
client.RemoveAllWeapons();
client.GiveWeapon(weaponHash, 0);
}
if (slot == 3)
{
client.RemoveAllWeapons();
client.GiveWeapon(weaponHash, 0);
}
if (slot == 4)
{
client.RemoveAllWeapons();
client.GiveWeapon(weaponHash, 0);
client.Armor = 0;
}
}
[RemoteEvent("cancelWeaponSelection")]
public void CancelWeaponSelection(Client client)
{
client.RemoveAllWeapons();
}
[RemoteEvent("saveWeaponSelection")]
public void SaveWeaponSelection(Client client, string primaryModel, string secondaryModel, string meleeModel, string specialModel)
{
client.RemoveAllWeapons();
WeaponHash primary = NAPI.Util.WeaponNameToModel(primaryModel);
WeaponHash secondary = NAPI.Util.WeaponNameToModel(secondaryModel);
WeaponHash melee = NAPI.Util.WeaponNameToModel(meleeModel);
client.GiveWeapon(primary, 150);
client.GiveWeapon(secondary, 600);
client.GiveWeapon(melee, 1);
if(specialModel != "Schutzweste")
{
WeaponHash special = NAPI.Util.WeaponNameToModel(specialModel);
client.GiveWeapon(special, 50);
}
}
}
}

View File

@@ -11,9 +11,17 @@ namespace ReallifeGamemode.Server.Managers
public static List<DutyPoint> DutyPoints = new List<DutyPoint>();
public static List<ColShape> DutyColShapes = new List<ColShape>();
public static List<WeaponPoint> WeaponPoints = new List<WeaponPoint>();
public static List<ColShape> WeaponColShapes = new List<ColShape>();
public static List<JailReleasePoint> JailReleasePoints = new List<JailReleasePoint>();
public static List<ColShape> JailReleaseColShapes = new List<ColShape>();
[ServerEvent(Event.ResourceStart)]
public void OnResourceStart()
{
#region DutyPoints
DutyPoint dutyPointLSPD = new DutyPoint()
{
Position = new Vector3(458.24, -990.86, 30.68),
@@ -28,6 +36,39 @@ namespace ReallifeGamemode.Server.Managers
new Vector3(0, 0, 0), 3, new Color(255, 255, 255, 50), false, 0);
NAPI.TextLabel.CreateTextLabel("Stempeluhr - Dr\u00fccke ~y~E\n~s~Dienstkleidung - Dr\u00fccke ~y~K", d.Position, 7, 1, 0, new Color(255, 255, 255), false, 0);
}
#endregion
#region WeaponPoints
WeaponPoint weaponPointLSPD = new WeaponPoint()
{
Position = new Vector3(460.3162,-981.0168,30.68959),
FactionId = 1
};
WeaponPoints.Add(weaponPointLSPD);
foreach(WeaponPoint w in WeaponPoints)
{
NAPI.Marker.CreateMarker(1, new Vector3(w.Position.X, w.Position.Y, w.Position.Z - 2), new Vector3(w.Position.X, w.Position.Y, w.Position.Z + 1),
new Vector3(0, 0, 0), 2, new Color(255, 255, 255, 50), false, 0);
NAPI.TextLabel.CreateTextLabel("Waffenspind - Dr\u00fccke ~y~E", w.Position, 7, 1, 0, new Color(255, 255, 255), false, 0);
}
#endregion
#region JailReleasePoint
JailReleasePoint jailPointLSPD = new JailReleasePoint()
{
Position = new Vector3(459.5327, -988.8435, 24.91487)
};
JailReleasePoints.Add(jailPointLSPD);
foreach(JailReleasePoint j in JailReleasePoints)
{
NAPI.Marker.CreateMarker(1, new Vector3(j.Position.X, j.Position.Y, j.Position.Z - 2), new Vector3(j.Position.X, j.Position.Y, j.Position.Z + 1),
new Vector3(0, 0, 0), 1.5f, new Color(255, 255, 255, 50), false, 0);
NAPI.TextLabel.CreateTextLabel("Gefängnis PC - Dr\u00fccke ~y~E", j.Position, 7, 1, 0, new Color(255, 255, 255), false, 0);
}
#endregion
}
}
@@ -37,5 +78,16 @@ namespace ReallifeGamemode.Server.Managers
public int FactionId { get; set; }
}
public class WeaponPoint
{
public Vector3 Position { get; set; }
public int FactionId { get; set; }
}
public class JailReleasePoint
{
public Vector3 Position { get; set; }
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace ReallifeGamemode.Migrations
{
public partial class FactionWeapons : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "FactionWeapons",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
FactionId = table.Column<int>(nullable: false),
WeaponHash = table.Column<int>(nullable: false),
WeaponModel = table.Column<string>(nullable: true),
SlotID = table.Column<int>(nullable: false),
Rank = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_FactionWeapons", x => x.Id);
table.ForeignKey(
name: "FK_FactionWeapons_Factions_FactionId",
column: x => x.FactionId,
principalTable: "Factions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_FactionWeapons_FactionId",
table: "FactionWeapons",
column: "FactionId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "FactionWeapons");
}
}
}

View File

@@ -389,6 +389,28 @@ namespace ReallifeGamemode.Migrations
b.ToTable("FactionRanks");
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.FactionWeapon", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("FactionId");
b.Property<int>("Rank");
b.Property<int>("SlotID");
b.Property<int>("WeaponHash");
b.Property<string>("WeaponModel");
b.HasKey("Id");
b.HasIndex("FactionId");
b.ToTable("FactionWeapons");
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.GotoPoint", b =>
{
b.Property<int>("Id")
@@ -851,7 +873,7 @@ namespace ReallifeGamemode.Migrations
b.Property<string>("Password")
.HasMaxLength(64);
b.Property<int>("PaydayTimer");
b.Property<float>("PositionX");
@@ -1093,6 +1115,14 @@ namespace ReallifeGamemode.Migrations
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.FactionWeapon", b =>
{
b.HasOne("ReallifeGamemode.Server.Entities.Faction", "Faction")
.WithMany()
.HasForeignKey("FactionId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.GroupBankAccount", b =>
{
b.HasOne("ReallifeGamemode.Server.Entities.Group", "Group")

View File

@@ -41,6 +41,7 @@ namespace ReallifeGamemode.Server.Models
public DbSet<Entities.Character> Characters { get; set; }
public DbSet<Entities.CharacterCloth> CharacterClothes { get; set; }
public DbSet<Entities.DutyCloth> DutyClothes { get; set; }
public DbSet<Entities.FactionWeapon> FactionWeapons { get; set; }
public DbSet<Entities.ClothCombination> ClothCombinations { get; set; }
public DbSet<Entities.User> Users { get; set; }
public DbSet<Entities.UserVehicle> UserVehicles { get; set; }

View File

@@ -11,7 +11,7 @@ using ReallifeGamemode.Server.Services;
namespace ReallifeGamemode.Server.Wanted
{
public class Jail
public class Jail : Script
{
private static Dictionary<int, int> Jailtime { get; set; } = new Dictionary<int, int>(); //time in seconds
@@ -172,8 +172,15 @@ namespace ReallifeGamemode.Server.Wanted
}
}
public static void Release_Jail(Client player, string reason)
[RemoteEvent("setPrisonerFree")]
public void Release_Jail(Client cop, string client)
{
Client player = ClientService.GetClientByNameOrId(client);
if (player == null)
return;
User user = player.GetUser();
if (Jailtime.ContainsKey(user.Id))
{
@@ -191,7 +198,7 @@ namespace ReallifeGamemode.Server.Wanted
User copUser = copPlayer.GetUser();
if ((copUser.FactionId == 1 || copUser.FactionId == 3))
{
ChatService.SendMessage(copPlayer, "~r~HQ: Beamter " + copPlayer.Name + " hat " + user.Name + " aus dem Knast entlassen. Grund: " + reason + ".");
ChatService.SendMessage(copPlayer, "~r~HQ: Beamter " + cop.Name + " hat " + user.Name + " aus dem Knast entlassen.");
}
}