Changed whole project structure (split client and server into separat projects)
This commit is contained in:
99
ReallifeGamemode.Server/Business/BusinessBase.cs
Normal file
99
ReallifeGamemode.Server/Business/BusinessBase.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System.Linq;
|
||||
|
||||
namespace reallife_gamemode.Server.Business
|
||||
{
|
||||
public abstract class BusinessBase : IBankAccountOwner
|
||||
{
|
||||
private TextLabel _informationLabel;
|
||||
private Marker _marker;
|
||||
private ColShape _colShape;
|
||||
|
||||
public abstract int Id { get; }
|
||||
public abstract string Name { get; }
|
||||
|
||||
public abstract Vector3 Position { get; }
|
||||
|
||||
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
||||
{
|
||||
if (databaseContext == null)
|
||||
{
|
||||
using (databaseContext = new DatabaseContext())
|
||||
{
|
||||
return databaseContext.BusinessBankAccounts.FirstOrDefault(u => u.BusinessId == Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return databaseContext.BusinessBankAccounts.FirstOrDefault(u => u.BusinessId == Id);
|
||||
}
|
||||
}
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
_informationLabel = NAPI.TextLabel.CreateTextLabel(Name, Position.Add(new Vector3(0, 0, 0.5)), 20.0f, 1.3f, 0, new Color(255, 255, 255));
|
||||
_marker = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, Position.Subtract(new Vector3(0, 0, 1.5)), new Vector3(), new Vector3(), 1f, new Color(255, 255, 255));
|
||||
|
||||
_colShape = NAPI.ColShape.CreateSphereColShape(Position.Subtract(new Vector3(0, 0, 1.5)), 3f);
|
||||
_colShape.OnEntityEnterColShape += EntityEnterBusinessColShape;
|
||||
_colShape.OnEntityExitColShape += EntityExitBusinessColShape;
|
||||
|
||||
if (GetBankAccount() == null)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput("Creating Bank Account for Business: " + Name);
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
|
||||
dbContext.BusinessBankAccounts.Add(new BusinessBankAccount()
|
||||
{
|
||||
BusinessId = Id,
|
||||
Balance = 0
|
||||
});
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EntityExitBusinessColShape(ColShape colShape, Client client)
|
||||
{
|
||||
client.TriggerEvent("business_removeHelp", true);
|
||||
}
|
||||
|
||||
private void EntityEnterBusinessColShape(ColShape colShape, Client client)
|
||||
{
|
||||
if (GetOwner() != null && GetOwner().Id == client.GetUser()?.Id && !client.IsInVehicle)
|
||||
{
|
||||
client.TriggerEvent("business_showHelp", Name, (GetBankAccount()?.Balance ?? 0).ToMoneyString());
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(int? money = null)
|
||||
{
|
||||
if (money == null) money = GetBankAccount()?.Balance ?? 0;
|
||||
User owner = GetOwner();
|
||||
string infoText = Name + "\n" + "Besitzer: " + (owner == null ? "Niemand" : owner.Name) + "\nKasse: ~g~" + money.ToMoneyString();
|
||||
_informationLabel.Text = infoText;
|
||||
}
|
||||
|
||||
public User GetOwner(DatabaseContext dbContext = null)
|
||||
{
|
||||
if(dbContext == null)
|
||||
{
|
||||
using (dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Users.FirstOrDefault(u => u.BusinessId == Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return dbContext.Users.FirstOrDefault(u => u.BusinessId == Id);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void Load();
|
||||
}
|
||||
}
|
||||
13
ReallifeGamemode.Server/Business/CarDealerBusinessBase.cs
Normal file
13
ReallifeGamemode.Server/Business/CarDealerBusinessBase.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using GTANetworkAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Business
|
||||
{
|
||||
public abstract class CarDealerBusinessBase : BusinessBase
|
||||
{
|
||||
public abstract Vector3 CarSpawnPositon { get; }
|
||||
public abstract float CarSpawnHeading { get; }
|
||||
}
|
||||
}
|
||||
21
ReallifeGamemode.Server/Business/ShopBusiness.cs
Normal file
21
ReallifeGamemode.Server/Business/ShopBusiness.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
|
||||
namespace reallife_gamemode.Server.Business
|
||||
{
|
||||
public class ShopBusiness : BusinessBase
|
||||
{
|
||||
public override int Id => 2;
|
||||
|
||||
public override string Name => "24/7 Business";
|
||||
|
||||
public override Vector3 Position => new Vector3(-443, 1134, 326);
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
21
ReallifeGamemode.Server/Business/TelefonBusiness.cs
Normal file
21
ReallifeGamemode.Server/Business/TelefonBusiness.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
|
||||
namespace reallife_gamemode.Server.Business
|
||||
{
|
||||
public class TelefonBusiness : BusinessBase
|
||||
{
|
||||
public override int Id => 1;
|
||||
|
||||
public override string Name => "Telefon Business";
|
||||
|
||||
public override Vector3 Position => new Vector3(-423, 1130, 326);
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
25
ReallifeGamemode.Server/Business/VapidCarDealerBusiness.cs
Normal file
25
ReallifeGamemode.Server/Business/VapidCarDealerBusiness.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
|
||||
namespace reallife_gamemode.Server.Business
|
||||
{
|
||||
public class VapidCarDealerBusiness : CarDealerBusinessBase
|
||||
{
|
||||
public override int Id => 3;
|
||||
|
||||
public override string Name => "Vapid Autohaus";
|
||||
|
||||
public override Vector3 Position => new Vector3(-177, -1156, 23);
|
||||
|
||||
public override Vector3 CarSpawnPositon => new Vector3(-222, -1162, 22.5);
|
||||
|
||||
public override float CarSpawnHeading => 356.6f;
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
16
ReallifeGamemode.Server/Classes/TempBlip.cs
Normal file
16
ReallifeGamemode.Server/Classes/TempBlip.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Classes
|
||||
{
|
||||
public class TempBlip
|
||||
{
|
||||
public byte Color { get; set; }
|
||||
public string Name { get; set; }
|
||||
public byte Transparency { get; set; }
|
||||
public bool ShortRange { get; set; }
|
||||
public uint Sprite { get; set; }
|
||||
public float Scale { get; set; }
|
||||
}
|
||||
}
|
||||
2370
ReallifeGamemode.Server/Commands/Admin.cs
Normal file
2370
ReallifeGamemode.Server/Commands/Admin.cs
Normal file
File diff suppressed because it is too large
Load Diff
274
ReallifeGamemode.Server/Commands/Faction.cs
Normal file
274
ReallifeGamemode.Server/Commands/Faction.cs
Normal file
@@ -0,0 +1,274 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Factions.Medic;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Services;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Faction Commands (Faction.cs)
|
||||
* @author VegaZ, hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Commands
|
||||
{
|
||||
class Faction : Script
|
||||
{
|
||||
#region Chat Commands
|
||||
|
||||
[Command("f", "~m~Benutzung: ~s~/f [Nachricht]", GreedyArg = true)]
|
||||
public void CmdFactionF(Client player, string message)
|
||||
{
|
||||
Entities.Faction f = player.GetUser()?.GetFaction();
|
||||
if (f == null || f.StateOwned)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
message = Regex.Replace(message, "(~[a-zA-Z]~{1})|(!{(.*)})", "");
|
||||
|
||||
string broadcastMessage = "!{02FCFF}** " + player.GetUser().GetFactionRank().RankName + " " + player.Name + ": " + message + " )) **";
|
||||
ChatService.BroadcastFaction(broadcastMessage, f);
|
||||
}
|
||||
|
||||
[Command("r", "~m~Benutzung: ~s~/r [Nachricht]", GreedyArg = true)]
|
||||
public void CmdFactionR(Client player, string message)
|
||||
{
|
||||
Entities.Faction f = player.GetUser()?.GetFaction();
|
||||
if (f == null || !f.StateOwned)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
message = Regex.Replace(message, "(~[a-zA-Z]~{1})|(!{(.*)})", "");
|
||||
|
||||
string broadcastMessage = "!{33AA33}** " + player.GetUser().GetFactionRank().RankName + " " + player.Name + ": " + message + ", over **";
|
||||
ChatService.BroadcastFaction(broadcastMessage, f);
|
||||
}
|
||||
|
||||
[Command("d", "~m~Benutzung: ~s~/d [Nachricht]", GreedyArg = true)]
|
||||
public void CmdFactionD(Client player, string message)
|
||||
{
|
||||
Entities.Faction f = player.GetUser()?.GetFaction();
|
||||
if (f == null || !f.StateOwned)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
message = Regex.Replace(message, "(~[a-zA-Z]~{1})|(!{(.*)})", "");
|
||||
|
||||
string broadcastMessage = "!{CC3333}** " + player.GetUser().GetFactionRank().RankName + " " + player.Name + ": " + message + ", over **";
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
ChatService.BroadcastFaction(broadcastMessage, context.Factions.ToList().FindAll(c => c.StateOwned));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Leader Commands
|
||||
|
||||
[Command("invite", "~m~Benutzung: ~s~/invite [Name]")]
|
||||
public void CmdFactionInvite(Client player, string name)
|
||||
{
|
||||
if (player.GetUser()?.FactionId == null || player.GetUser().FactionLeader == false)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Client target = ClientService.GetClientByNameOrId(name);
|
||||
if (target == null || !target.IsLoggedIn())
|
||||
{
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.GetUser()?.FactionId != null)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Dieser Spieler ist schon in einer Fraktion.");
|
||||
return;
|
||||
}
|
||||
|
||||
target.SetData("accept_invite", player.Handle);
|
||||
|
||||
player.SendChatMessage("!{02FCFF}Du hast dem Spieler " + target.Name + " eine Einladung in deine Fraktion gesendet.");
|
||||
target.SendChatMessage("!{02FCFF}Du hast von " + player.Name + " eine Einladung in die Fraktion \"" + player.GetUser().GetFaction().Name + "\" erhalten.");
|
||||
target.SendChatMessage("!{02FCFF}Benutze '/accept invite', um die Einladung anzunehmen");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
[Command("giverank", "~m~Benutzung: ~s~/giverank [Name] [Rang]", GreedyArg = true)]
|
||||
public void CmdFactionGiverank(Client player, string name, string rank)
|
||||
{
|
||||
if (player.GetUser()?.FactionId == null || player.GetUser().FactionLeader == false)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Client target = ClientService.GetClientByNameOrId(name);
|
||||
if (target == null || !target.IsLoggedIn())
|
||||
{
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.GetUser()?.FactionId != player.GetUser()?.FactionId)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Dieser Spieler ist nicht in deiner Fraktion.");
|
||||
return;
|
||||
}
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
FactionRank fr = dbContext.FactionRanks.FirstOrDefault(r => r.RankName == rank && r.FactionId == player.GetUser(dbContext).FactionId);
|
||||
if (fr == null)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Dieser Rang existiert nicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
target.GetUser(dbContext).FactionRankId = fr.Id;
|
||||
|
||||
player.SendChatMessage("!{02FCFF}Du hast " + target.Name + " den Rang '" + fr.RankName + "' gegeben.");
|
||||
target.SendChatMessage("!{02FCFF}Du hast von " + player.Name + " den Rang '" + fr.RankName + "' erhalten.");
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
[Command("uninvite", "~m~Benutzung: ~s~/uninvite [Name]")]
|
||||
public void CmdFactionUninvite(Client player, string name)
|
||||
{
|
||||
if (player.GetUser()?.FactionId == null || player.GetUser().FactionLeader == false)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Client target = ClientService.GetClientByNameOrId(name);
|
||||
if (target == null || !target.IsLoggedIn())
|
||||
{
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.GetUser()?.FactionId != player.GetUser()?.FactionId)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Dieser Spieler ist nicht in deiner Fraktion.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.Handle == target.Handle)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Du kannst dich nicht selber uninviten.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.GetUser()?.FactionLeader ?? false)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Du kannst keinen Leader uninviten.");
|
||||
return;
|
||||
}
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
|
||||
target.GetUser(dbContext).FactionRankId = null;
|
||||
target.GetUser(dbContext).FactionId = null;
|
||||
|
||||
player.SendChatMessage("!{02FCFF}Du hast " + target.Name + " aus der Fraktion geworfen.");
|
||||
target.SendChatMessage("!{02FCFF}Du wurdest von " + player.Name + " aus der Fraktion geworfen.");
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
[Command("lc", "~m~Benutzung: ~s~/lc [Nachricht]", GreedyArg = true)]
|
||||
public void CmdFactionLc(Client player, string message)
|
||||
{
|
||||
if (player.GetUser()?.FactionId == null || player.GetUser().FactionLeader == false)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
message = Regex.Replace(message, "(~[a-zA-Z]~{1})|(!{(.*)})", "");
|
||||
|
||||
string broadcastMsg = "~y~[" + player.GetUser().GetFaction().Name + "] " + player.Name + ": " + message;
|
||||
|
||||
NAPI.Pools.GetAllPlayers().ForEach(p =>
|
||||
{
|
||||
if (p.GetUser()?.FactionLeader ?? false) p.SendChatMessage(broadcastMsg);
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
#region Sanitäter Commands
|
||||
|
||||
[Command("revive", "~m~Benutzung: ~s~/revive")]
|
||||
public void CmdFactionMedicRevive(Client player)
|
||||
{
|
||||
if (player.GetUser()?.FactionId == null || player.GetUser().FactionId != 2)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
if (player.IsInVehicle)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Du kannst in einem Auto nicht wiederbeleben!");
|
||||
return;
|
||||
}
|
||||
|
||||
var nearPlayers = NAPI.Player.GetPlayersInRadiusOfPlayer(2, player);
|
||||
var deadPlayer = nearPlayers.Where(i => i.GetData("isDead") == true).FirstOrDefault();
|
||||
if (player == deadPlayer)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Du kannst dich nicht selbst wiederbeleben!");
|
||||
return;
|
||||
}
|
||||
player.PlayAnimation("amb@medic@standing@kneel@enter", "enter", 0);
|
||||
|
||||
deadPlayer.TriggerEvent("onPlayerRevived");
|
||||
deadPlayer.SendNotification("Du wurdest von ~r~" + player.Name + "~s~ wiederbelebt.");
|
||||
deadPlayer.SetData("isDead", false);
|
||||
NAPI.Player.SpawnPlayer(deadPlayer, deadPlayer.Position);
|
||||
deadPlayer.Health = 50;
|
||||
|
||||
MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == deadPlayer.Name);
|
||||
Medic.RemoveTaskFromList(task);
|
||||
}
|
||||
|
||||
[Command("heal", "~m~Benutzung: ~s~/heal [Spieler]")] //TODO Eventuell noch mit Geldbetrag wie bei SA:MP
|
||||
public void CmdFactionMedicHealive(Client player, string receiver)
|
||||
{
|
||||
if (player.GetUser()?.FactionId == null || player.GetUser().FactionId != 2)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
if (player.IsInVehicle)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Du kannst in einem Auto nicht heilen!");
|
||||
return;
|
||||
}
|
||||
Client target = ClientService.GetClientByNameOrId(receiver);
|
||||
target.Health = 100;
|
||||
target.SendNotification("Du wurdest von ~g~" + player.Name + " ~s~geheilt.", false);
|
||||
player.SendNotification("Du hast~g~" + target.Name + " ~s~geheilt.", false);
|
||||
}
|
||||
#endregion
|
||||
#region Global Fraktions Commands
|
||||
[Command("duty", "~m~Benutzung: ~s~/duty")]
|
||||
public void CmdFactionDuty(Client player)
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
85
ReallifeGamemode.Server/Commands/User.cs
Normal file
85
ReallifeGamemode.Server/Commands/User.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System.Linq;
|
||||
|
||||
namespace reallife_gamemode.Server.Commands
|
||||
{
|
||||
class User : Script
|
||||
{
|
||||
[Command("accept", "~m~Benutzung: ~s~/accept [invite]")]
|
||||
public void CmdUserAccept(Client player, string option)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
|
||||
option = option.ToLower();
|
||||
|
||||
switch(option)
|
||||
{
|
||||
case "invite":
|
||||
{
|
||||
if(!player.HasData("accept_invite"))
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Du hast keine Einladung in eine Fraktion erhalten.");
|
||||
return;
|
||||
}
|
||||
|
||||
player.ResetData("accept_data");
|
||||
|
||||
using(var dbContext = new DatabaseContext())
|
||||
{
|
||||
Client leader = NAPI.Player.GetPlayerFromHandle((NetHandle)player.GetData("accept_invite"));
|
||||
|
||||
if(leader == null)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Die Einladung ist abgelaufen.");
|
||||
return;
|
||||
}
|
||||
|
||||
Entities.User u = leader.GetUser(dbContext);
|
||||
Entities.User own = player.GetUser(dbContext);
|
||||
|
||||
own.FactionId = u.FactionId;
|
||||
own.FactionLeader = false;
|
||||
own.FactionRankId = dbContext.FactionRanks.
|
||||
OrderBy(x => x.Order)
|
||||
.FirstOrDefault(r => r.FactionId == own.FactionId)?.Id ?? null;
|
||||
|
||||
leader.SendChatMessage("!{02FCFF}" + player.Name + " hat die Einladung angenommen.");
|
||||
player.SendChatMessage("!{02FCFF}Du hast die Einladung angenommen.");
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Command("car", "~m~Benutzung: ~s~/car")]
|
||||
public void CmdUserCar(Client player)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
if (!player.IsInVehicle) return;
|
||||
|
||||
Vehicle pVeh = player.Vehicle;
|
||||
|
||||
if(pVeh.GetServerVehicle() is ServerVehicle veh)
|
||||
{
|
||||
if(player.GetUser().IsAdmin(AdminLevel.SUPPORTER))
|
||||
{
|
||||
player.SendChatMessage("~m~" + ((VehicleHash)pVeh.Model) + " | " + veh.ToString() + " | Farbe 1: " + pVeh.PrimaryColor + " | Farbe 2: " + pVeh.SecondaryColor + " | ID: " + pVeh.Handle.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SendChatMessage("~m~" + ((VehicleHash)pVeh.Model) + " | Farbe 1: " + pVeh.PrimaryColor + " | Farbe 2: " + pVeh.SecondaryColor + " | ID: " + pVeh.Handle.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SendChatMessage("~m~" + ((VehicleHash)pVeh.Model) + " | Farbe 1: " + pVeh.PrimaryColor + " | Farbe 2: " + pVeh.SecondaryColor + " | ID: " + pVeh.Handle.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
ReallifeGamemode.Server/Entities/Ban.cs
Normal file
32
ReallifeGamemode.Server/Entities/Ban.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities Ban (Ban.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class Ban
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
public string Reason { get; set; }
|
||||
public string BannedBy { get; set; }
|
||||
|
||||
public int Applied { get; set; }
|
||||
public int UntilDateTime { get; set; }
|
||||
}
|
||||
}
|
||||
31
ReallifeGamemode.Server/Entities/BusinessBankAccount.cs
Normal file
31
ReallifeGamemode.Server/Entities/BusinessBankAccount.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using reallife_gamemode.Server.Business;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class BusinessBankAccount : IBankAccount
|
||||
{
|
||||
[NotMapped]
|
||||
private int _balance;
|
||||
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
public int Balance {
|
||||
get => _balance;
|
||||
set
|
||||
{
|
||||
_balance = value;
|
||||
BusinessManager.GetBusiness(BusinessId).Update(value);
|
||||
}
|
||||
}
|
||||
|
||||
public int BusinessId { get; set; }
|
||||
}
|
||||
}
|
||||
82
ReallifeGamemode.Server/Entities/Character.cs
Normal file
82
ReallifeGamemode.Server/Entities/Character.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities Ban (Ban.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class Character
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
public bool Gender { get; set; }
|
||||
public byte Father { get; set; }
|
||||
public byte Mother { get; set; }
|
||||
public float Similarity { get; set; }
|
||||
public float SkinSimilarity { get; set; }
|
||||
|
||||
public float NoseWidth { get; set; }
|
||||
public float NoseBottomHeight { get; set; }
|
||||
public float NoseTipLength { get; set; }
|
||||
public float NoseBridgeDepth { get; set; }
|
||||
public float NoseTipHeight { get; set; }
|
||||
public float NoseBroken { get; set; }
|
||||
public float BrowHeight { get; set; }
|
||||
public float BrowDepth { get; set; }
|
||||
public float CheekboneHeight { get; set; }
|
||||
public float CheekboneWidth { get; set; }
|
||||
public float CheekDepth { get; set; }
|
||||
public float EyeSize { get; set; }
|
||||
public float LipThickness { get; set; }
|
||||
public float JawWidth { get; set; }
|
||||
public float JawShape { get; set; }
|
||||
public float ChinHeight { get; set; }
|
||||
public float ChinDepth { get; set; }
|
||||
public float ChinWidth { get; set; }
|
||||
public float ChinIndent { get; set; }
|
||||
public float NeckWidth { get; set; }
|
||||
|
||||
public byte Blemishes { get; set; }
|
||||
public float BlemishesOpacity { get; set; }
|
||||
public byte FacialHair { get; set; }
|
||||
public float FacialHairOpacity { get; set; }
|
||||
public byte Eyebrows { get; set; }
|
||||
public float EyebrowsOpacity { get; set; }
|
||||
public byte Ageing { get; set; }
|
||||
public float AgeingOpacity { get; set; }
|
||||
public byte Makeup { get; set; }
|
||||
public float MakeupOpacity { get; set; }
|
||||
public byte Blush { get; set; }
|
||||
public float BlushOpacity { get; set; }
|
||||
public byte Complexion { get; set; }
|
||||
public float ComplexionOpacity { get; set; }
|
||||
public byte SunDamage { get; set; }
|
||||
public float SunDamageOpacity { get; set; }
|
||||
public byte Lipstick { get; set; }
|
||||
public float LipstickOpacity { get; set; }
|
||||
public byte Freckles { get; set; }
|
||||
public float FrecklesOpacity { get; set; }
|
||||
public byte ChestHair { get; set; }
|
||||
public float ChestHairOpacity { get; set; }
|
||||
|
||||
public byte Hair { get; set; }
|
||||
public byte HairColor { get; set; }
|
||||
public byte HairHighlightColor { get; set; }
|
||||
public byte EyebrowColor { get; set; }
|
||||
public byte BeardColor { get; set; }
|
||||
public byte EyeColor { get; set; }
|
||||
public byte BlushColor { get; set; }
|
||||
public byte LipstickColor { get; set; }
|
||||
public byte ChestHairColor { get; set; }
|
||||
}
|
||||
}
|
||||
28
ReallifeGamemode.Server/Entities/CharacterCloth.cs
Normal file
28
ReallifeGamemode.Server/Entities/CharacterCloth.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities CharacterCloth CharacterCloth.cs
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class CharacterCloth
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
public bool Duty { get; set; }
|
||||
|
||||
public byte SlotType { get; set; }
|
||||
public int SlotId { get; set; }
|
||||
public int ClothId { get; set; }
|
||||
}
|
||||
}
|
||||
25
ReallifeGamemode.Server/Entities/ClothCombination.cs
Normal file
25
ReallifeGamemode.Server/Entities/ClothCombination.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities MaleCombination (MaleCombination.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class ClothCombination
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public bool Gender { get; set; }
|
||||
public int Top { get; set; }
|
||||
public int Torso { get; set; }
|
||||
public int Undershirt { get; set; }
|
||||
}
|
||||
}
|
||||
36
ReallifeGamemode.Server/Entities/Door.cs
Normal file
36
ReallifeGamemode.Server/Entities/Door.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using GTANetworkAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities Door (Door.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class Door
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Category { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool Locked { get; set; }
|
||||
public int Model { get; set; }
|
||||
public float X { get; set; }
|
||||
public float Y { get; set; }
|
||||
public float Z { get; set; }
|
||||
public float Radius { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public Vector3 Position => new Vector3(X, Y, Z);
|
||||
|
||||
[ForeignKey("FactionId")]
|
||||
public int? FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
}
|
||||
}
|
||||
31
ReallifeGamemode.Server/Entities/DutyCloth.cs
Normal file
31
ReallifeGamemode.Server/Entities/DutyCloth.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities DutyCloth DutyCloth.cs
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class DutyCloth
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("Faction")]
|
||||
public int FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
|
||||
public bool Gender { get; set; }
|
||||
|
||||
public byte SlotType { get; set; }
|
||||
public int SlotId { get; set; }
|
||||
public int ClothId { get; set; }
|
||||
}
|
||||
}
|
||||
39
ReallifeGamemode.Server/Entities/Faction.cs
Normal file
39
ReallifeGamemode.Server/Entities/Faction.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities Faction (Faction.cs)
|
||||
* @author VegaZ, hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class Faction : IBankAccountOwner
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
[StringLength(32)]
|
||||
public string Name { get; set; }
|
||||
public bool StateOwned { get; set; }
|
||||
|
||||
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
||||
{
|
||||
if (databaseContext == null)
|
||||
{
|
||||
using (databaseContext = new DatabaseContext())
|
||||
{
|
||||
return databaseContext.FactionBankAccounts.FirstOrDefault(u => u.FactionId == this.Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return databaseContext.FactionBankAccounts.FirstOrDefault(u => u.FactionId == this.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
ReallifeGamemode.Server/Entities/FactionBankAccount.cs
Normal file
31
ReallifeGamemode.Server/Entities/FactionBankAccount.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities FactionBankAccount (FactionBankAccount.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class FactionBankAccount : IBankAccount
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
[ForeignKey("Faction")]
|
||||
public int FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
[StringLength(12)]
|
||||
public string Bic { get; set; }
|
||||
[StringLength(32)]
|
||||
public string Iban { get; set; }
|
||||
public int Balance { get; set; }
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
}
|
||||
26
ReallifeGamemode.Server/Entities/FactionRank.cs
Normal file
26
ReallifeGamemode.Server/Entities/FactionRank.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using reallife_gamemode.Server.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class FactionRank
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string RankName { get; set; }
|
||||
public int Order { get; set; }
|
||||
|
||||
|
||||
public int FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
|
||||
public Faction GetFaction()
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
return context.Factions.FirstOrDefault(f => f.Id == FactionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
ReallifeGamemode.Server/Entities/FactionVehicles.cs
Normal file
33
ReallifeGamemode.Server/Entities/FactionVehicles.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using reallife_gamemode.Server.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities FactionVehicles (FactionVehicle.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
[Table("FactionVehicles")]
|
||||
public class FactionVehicle : ServerVehicle
|
||||
{
|
||||
[ForeignKey("Faction")]
|
||||
public int? FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
|
||||
public Faction GetFaction()
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
return context.Factions.FirstOrDefault(f => f.Id == FactionId);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Fraktions Fahrzeug | Fraktion: " + GetFaction().Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
ReallifeGamemode.Server/Entities/GotoPoints.cs
Normal file
28
ReallifeGamemode.Server/Entities/GotoPoints.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities GotoPoints (GotoPoints.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class GotoPoint
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
[StringLength(32)]
|
||||
public string Description { get; set; }
|
||||
public float X { get; set; }
|
||||
public float Y { get; set; }
|
||||
public float Z { get; set; }
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
}
|
||||
75
ReallifeGamemode.Server/Entities/Interior.cs
Normal file
75
ReallifeGamemode.Server/Entities/Interior.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class Interior
|
||||
{
|
||||
[NotMapped]
|
||||
private Vector3 _enterPosition;
|
||||
[NotMapped]
|
||||
private Vector3 _exitPosition;
|
||||
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column("EnterPosition")]
|
||||
public string EnterPositionStr
|
||||
{
|
||||
get
|
||||
{
|
||||
return JsonConvert.SerializeObject(this._enterPosition);
|
||||
}
|
||||
set
|
||||
{
|
||||
this._enterPosition = JsonConvert.DeserializeObject<Vector3>(value);
|
||||
}
|
||||
}
|
||||
|
||||
[Column("ExitPosition")]
|
||||
public string ExitPositionStr
|
||||
{
|
||||
get
|
||||
{
|
||||
return JsonConvert.SerializeObject(this._exitPosition);
|
||||
}
|
||||
set
|
||||
{
|
||||
this._exitPosition = JsonConvert.DeserializeObject<Vector3>(value);
|
||||
}
|
||||
}
|
||||
|
||||
[NotMapped]
|
||||
public Vector3 EnterPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._enterPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._enterPosition = value;
|
||||
}
|
||||
}
|
||||
|
||||
[NotMapped]
|
||||
public Vector3 ExitPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._exitPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._exitPosition = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
ReallifeGamemode.Server/Entities/News.cs
Normal file
24
ReallifeGamemode.Server/Entities/News.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class News
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("User")]
|
||||
public int? UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
public string Caption { get; set; }
|
||||
public string Content { get; set; }
|
||||
public bool Active { get; set; }
|
||||
public int Timestamp { get; set; }
|
||||
}
|
||||
}
|
||||
72
ReallifeGamemode.Server/Entities/ServerVehicle.cs
Normal file
72
ReallifeGamemode.Server/Entities/ServerVehicle.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public abstract class ServerVehicle
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public VehicleHash Model { get; set; }
|
||||
public float PositionX { get; set; }
|
||||
public float PositionY { get; set; }
|
||||
public float PositionZ { get; set; }
|
||||
public float Heading { get; set; }
|
||||
[StringLength(8)]
|
||||
public string NumberPlate { get; set; }
|
||||
public int PrimaryColor { get; set; }
|
||||
public int SecondaryColor { get; set; }
|
||||
public bool Locked { get; set; }
|
||||
public bool Active { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public Vector3 Position => new Vector3(PositionX, PositionY, PositionZ);
|
||||
|
||||
public Vehicle Spawn(Vehicle currentVeh = null)
|
||||
{
|
||||
if (currentVeh != null) VehicleManager.DeleteVehicle(currentVeh);
|
||||
Vector3 position = this.Position;
|
||||
uint model = (uint)this.Model;
|
||||
float heading = this.Heading;
|
||||
int c1 = this.PrimaryColor;
|
||||
int c2 = this.SecondaryColor;
|
||||
string np = this.NumberPlate;
|
||||
Vehicle veh = NAPI.Vehicle.CreateVehicle(Model, position, heading, c1, c2, "", 255, false, false);
|
||||
VehicleStreaming.SetEngineState(veh, false);
|
||||
VehicleStreaming.SetLockStatus(veh, this.Locked);
|
||||
VehicleManager.AddVehicle(this, veh);
|
||||
|
||||
string numberplate = $"{this.Id}";
|
||||
|
||||
if(this is FactionVehicle fV)
|
||||
{
|
||||
numberplate = $"F{fV.FactionId} " + numberplate;
|
||||
}
|
||||
|
||||
if (this is UserVehicle uV)
|
||||
{
|
||||
numberplate = $"U{uV.UserId} " + numberplate;
|
||||
}
|
||||
|
||||
if(this is ShopVehicle sV)
|
||||
{
|
||||
numberplate = "Shop";
|
||||
VehicleStreaming.SetLockStatus(veh, false);
|
||||
TextLabel label = NAPI.TextLabel.CreateTextLabel(NAPI.Vehicle.GetVehicleDisplayName((VehicleHash)veh.Model) + "\n" + "~g~" + sV.Price.ToMoneyString(),
|
||||
veh.Position.Add(new Vector3(0, 0, 1.3)), 10.0f, 1f, 1, new Color(255, 255, 255));
|
||||
}
|
||||
|
||||
veh.NumberPlate = numberplate;
|
||||
|
||||
return veh;
|
||||
}
|
||||
|
||||
public abstract override string ToString();
|
||||
}
|
||||
}
|
||||
31
ReallifeGamemode.Server/Entities/ShopVehicles.cs
Normal file
31
ReallifeGamemode.Server/Entities/ShopVehicles.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Business;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities ShopVehicles (ShopVehicles.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
[Table("ShopVehicles")]
|
||||
public class ShopVehicle : ServerVehicle
|
||||
{
|
||||
[ForeignKey("Shop")]
|
||||
public int? ShopId { get; set; }
|
||||
public int BusinessId { get; set; }
|
||||
public int Price { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "ShopVehicle";
|
||||
}
|
||||
}
|
||||
}
|
||||
163
ReallifeGamemode.Server/Entities/User.cs
Normal file
163
ReallifeGamemode.Server/Entities/User.cs
Normal file
@@ -0,0 +1,163 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities User (User.cs)
|
||||
* @author VegaZ, hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class User : IBankAccountOwner
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
[StringLength(32)]
|
||||
public string Name { get; set; }
|
||||
[StringLength(32)]
|
||||
public string SocialClubName { get; set; }
|
||||
[StringLength(64)]
|
||||
public string Password { get; set; }
|
||||
public int LogUserId { get; set; }
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public DateTime RegistrationDate { get; set; }
|
||||
|
||||
[EmailAddress]
|
||||
[StringLength(64)]
|
||||
public string Email { get; set; }
|
||||
public AdminLevel AdminLevel { get; set; }
|
||||
|
||||
public bool Dead { get; set; }
|
||||
|
||||
public float PositionX { get; set; }
|
||||
public float PositionY { get; set; }
|
||||
public float PositionZ { get; set; }
|
||||
|
||||
[ForeignKey("Character")]
|
||||
public int? CharacterId { get; set; }
|
||||
public Character Character { get; set; }
|
||||
|
||||
[ForeignKey("Ban")]
|
||||
public int? BanId { get; set; }
|
||||
public Ban Ban { get; set; }
|
||||
|
||||
public int? FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
|
||||
public bool FactionLeader { get; set; }
|
||||
|
||||
public int? FactionRankId { get; set; }
|
||||
public FactionRank FactionRank { get;set; }
|
||||
|
||||
public int? BusinessId { get; set; }
|
||||
|
||||
public Faction GetFaction()
|
||||
{
|
||||
using(var context = new DatabaseContext())
|
||||
{
|
||||
return context.Factions.FirstOrDefault(f => f.Id == FactionId);
|
||||
}
|
||||
}
|
||||
|
||||
public FactionRank GetFactionRank()
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
FactionRank toReturn = context.FactionRanks.FirstOrDefault(fR => fR.Id == FactionRankId);
|
||||
if(toReturn == null)
|
||||
{
|
||||
toReturn = context.FactionRanks.OrderBy(f => f.Order).FirstOrDefault(f => f.FactionId == FactionId);
|
||||
}
|
||||
|
||||
if(toReturn == null)
|
||||
{
|
||||
toReturn = new FactionRank
|
||||
{
|
||||
RankName = "Rang-Fehler"
|
||||
};
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
||||
public void BanPlayer(Client admin, string reason, int mins)
|
||||
{
|
||||
using (var banUserContext = new DatabaseContext())
|
||||
{
|
||||
int unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
Ban banUser;
|
||||
|
||||
if (mins == 0)
|
||||
{
|
||||
NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + this.Name + " wurde von " + admin.Name + " permanent gebannt. [" + reason + "]");
|
||||
banUser = new Ban { UserId = this.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp };
|
||||
|
||||
GetClient()?.Kick();
|
||||
|
||||
mins--;
|
||||
}
|
||||
else
|
||||
{
|
||||
NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + this.Name + " wurde von " + admin.Name + " für " + mins + " Minuten gebannt. [" + reason + "]");
|
||||
banUser = new Ban { UserId = this.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp + mins * 60 };
|
||||
GetClient()?.Kick();
|
||||
}
|
||||
|
||||
banUserContext.Bans.Add(banUser);
|
||||
banUserContext.SaveChanges();
|
||||
|
||||
var targetUser = banUserContext.Users.FirstOrDefault(u => u.Name == this.Name);
|
||||
targetUser.BanId = banUser.Id;
|
||||
banUserContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public void UnbanPlayer()
|
||||
{
|
||||
using (var unbanUser = new DatabaseContext())
|
||||
{
|
||||
var targetUser = unbanUser.Users.FirstOrDefault(u => u.Id == this.Id);
|
||||
targetUser.BanId = null;
|
||||
unbanUser.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public List<UserItem> GetItems()
|
||||
{
|
||||
using(var dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.UserItems.ToList().FindAll(u => u.UserId == this.Id);
|
||||
}
|
||||
}
|
||||
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
||||
|
||||
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
||||
{
|
||||
if (databaseContext == null)
|
||||
{
|
||||
using (databaseContext = new DatabaseContext())
|
||||
{
|
||||
return databaseContext.UserBankAccounts.FirstOrDefault(u => u.UserId == this.Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return databaseContext.UserBankAccounts.FirstOrDefault(u => u.UserId == this.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public Client GetClient()
|
||||
{
|
||||
return NAPI.Player.GetPlayerFromName(Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
44
ReallifeGamemode.Server/Entities/UserBankAccount.cs
Normal file
44
ReallifeGamemode.Server/Entities/UserBankAccount.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Services;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities UserBankAccount (UserBankAccount.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class UserBankAccount : IBankAccount
|
||||
{
|
||||
[NotMapped]
|
||||
private int _balance;
|
||||
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
[StringLength(12)]
|
||||
public string Bic { get; set; }
|
||||
[StringLength(32)]
|
||||
public string Iban { get; set; }
|
||||
public int Balance {
|
||||
get => _balance;
|
||||
set
|
||||
{
|
||||
_balance = value;
|
||||
using(var dbContext = new DatabaseContext())
|
||||
{
|
||||
ClientService.GetClientByNameOrId(dbContext.Users.First(u => u.Id == UserId).Name).TriggerEvent("updateMoney", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
}
|
||||
37
ReallifeGamemode.Server/Entities/UserItem.cs
Normal file
37
ReallifeGamemode.Server/Entities/UserItem.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using reallife_gamemode.Server.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities UserItem (UserItem.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class UserItem
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public int ItemId { get; set; }
|
||||
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
public int Amount { get; set; }
|
||||
public int Slot { get; set; }
|
||||
|
||||
public User GetUser()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Users.FirstOrDefault(u => u.Id == UserId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
ReallifeGamemode.Server/Entities/UserVehicle.cs
Normal file
40
ReallifeGamemode.Server/Entities/UserVehicle.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using reallife_gamemode.Server.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities UserVehicle (UserVehicle.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
[Table("UserVehicles")]
|
||||
public class UserVehicle : ServerVehicle
|
||||
{
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Spieler Fahrzeug | Besitzer: " + GetOwner().Name;
|
||||
}
|
||||
|
||||
public User GetOwner(DatabaseContext dbContext = null)
|
||||
{
|
||||
if (dbContext == null)
|
||||
{
|
||||
using (dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Users.FirstOrDefault(u => u.Id == UserId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return dbContext.Users.FirstOrDefault(u => u.Id == UserId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
ReallifeGamemode.Server/Entities/VehicleMod.cs
Normal file
22
ReallifeGamemode.Server/Entities/VehicleMod.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class VehicleMod
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("Vehicle")]
|
||||
public int ServerVehicleId { get; set; }
|
||||
public ServerVehicle Vehicle { get; set; }
|
||||
|
||||
public int Slot { get; set; }
|
||||
public int ModId { get; set; }
|
||||
}
|
||||
}
|
||||
16
ReallifeGamemode.Server/Entities/Whitelist.cs
Normal file
16
ReallifeGamemode.Server/Entities/Whitelist.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class Whitelist
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
public string SocialClubName { get; set; }
|
||||
}
|
||||
}
|
||||
16
ReallifeGamemode.Server/Events/Chat.cs
Normal file
16
ReallifeGamemode.Server/Events/Chat.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using GTANetworkAPI;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
public class Chat : Script
|
||||
{
|
||||
[ServerEvent(Event.ChatMessage)]
|
||||
public void ChatEvent(Client player, string message)
|
||||
{
|
||||
string serverMsg = Regex.Replace(message, "(~[a-zA-Z]~{1})|(!{(.*)})", "");
|
||||
if (serverMsg.Trim().Length == 0) return;
|
||||
NAPI.Player.GetPlayersInRadiusOfPlayer(10, player).ForEach(p => p.SendChatMessage($"{player.Name} sagt: {serverMsg}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
91
ReallifeGamemode.Server/Events/Connect.cs
Normal file
91
ReallifeGamemode.Server/Events/Connect.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Services;
|
||||
using reallife_gamemode.Server.Util;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Event Login (Login.cs)
|
||||
* @author VegaZ, xSprite
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
class Connect : Script
|
||||
{
|
||||
|
||||
|
||||
[ServerEvent(Event.PlayerConnected)]
|
||||
public void OnPlayerConnected(Client player)
|
||||
{
|
||||
player.SetData("isLoggedIn", false);
|
||||
player.Position = new Vector3(-1883.736, -781.4911, -10);
|
||||
player.FreezePosition = true;
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
if(!dbContext.WhitelistEntries.Any(w => w.SocialClubName.ToLower() == player.SocialClubName.ToLower()))
|
||||
{
|
||||
player.TriggerEvent("disableLogin");
|
||||
|
||||
string msg2 = "~m~*** " + player.Name + "[" + player.SocialClubName + "] (" + player.Address + ") hat versucht, sich einzuloggen, steht aber nicht auf der Whitelist.";
|
||||
ChatService.BroadcastAdmin(msg2, AdminLevel.ADMIN);
|
||||
|
||||
NAPI.Util.ConsoleOutput(player.Name + " tried to join without whitelist entry");
|
||||
|
||||
player.SendChatMessage("~m~Du stehst nicht auf der Whitelist");
|
||||
|
||||
player.Kick();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string msg = "~m~*** " + player.Name + " [" + player.SocialClubName + "] [ID:" + player.Handle.Value + "] (" + player.Address + ")";
|
||||
ChatService.BroadcastAdmin(msg, AdminLevel.ADMIN);
|
||||
}
|
||||
|
||||
[RemoteEvent("IsPlayerBanned")]
|
||||
public void IsPlayerBanned(Client player)
|
||||
{
|
||||
using (var loginUser = new DatabaseContext())
|
||||
{
|
||||
var user = loginUser.Users.SingleOrDefault(b => b.Name == player.Name);
|
||||
if (user == null)
|
||||
{
|
||||
player.TriggerEvent("showLogin");
|
||||
return;
|
||||
}
|
||||
if (user.BanId != null)
|
||||
{
|
||||
var dt = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
||||
var bannedUser = loginUser.Bans.SingleOrDefault(u => u.Id == user.BanId);
|
||||
if (bannedUser.Applied == bannedUser.UntilDateTime)
|
||||
{
|
||||
player.SendChatMessage("!{#FF4040}Du wurdest permanent gebannt! [" + bannedUser.Reason + "]");
|
||||
player.Kick();
|
||||
}
|
||||
else
|
||||
{
|
||||
var timeStamp = bannedUser.UntilDateTime;
|
||||
int unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
|
||||
if(timeStamp > unixTimestamp)
|
||||
{
|
||||
player.SendChatMessage("Du bist noch bis zum !{#FF4040}" + dt.AddSeconds(timeStamp).ToLocalTime() + " Uhr ~s~gebannt. [" + bannedUser.Reason + "]");
|
||||
player.Kick();
|
||||
}
|
||||
else
|
||||
{
|
||||
user.BanId = null;
|
||||
loginUser.SaveChanges();
|
||||
player.TriggerEvent("showLogin");
|
||||
}
|
||||
}
|
||||
}
|
||||
else player.TriggerEvent("showLogin");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
109
ReallifeGamemode.Server/Events/Death.cs
Normal file
109
ReallifeGamemode.Server/Events/Death.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Factions.Medic;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Services;
|
||||
using reallife_gamemode.Server.Util;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Events Death (Death.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
public class Death : Script
|
||||
{
|
||||
[ServerEvent(Event.PlayerDeath)]
|
||||
public void OnPlayerDeath(Client player, Client killer, uint reason)
|
||||
{
|
||||
if (!player.IsLoggedIn()) player.Kick();
|
||||
player.SetData("isDead", true);
|
||||
|
||||
if (player.GetUser().IsAdmin(AdminLevel.ADMIN) == true)
|
||||
{
|
||||
player.TriggerEvent("startDeathTimer", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.TriggerEvent("startDeathTimer", false);
|
||||
}
|
||||
|
||||
//var dutyMedics = 0;
|
||||
//var allPlayers = NAPI.Pools.GetAllPlayers();
|
||||
|
||||
//foreach (Client medic in allPlayers)
|
||||
//{
|
||||
// if (medic.GetUser()?.FactionId == 2)
|
||||
// {
|
||||
// dutyMedics++;
|
||||
// }
|
||||
//}
|
||||
//player.TriggerEvent("medicInfo", dutyMedics);
|
||||
|
||||
//TODO: Zum Full Release entfernen
|
||||
NAPI.Chat.SendChatMessageToPlayer(player, "Du bist durch " + killer.Name + " gestorben: " + reason.ToString());
|
||||
|
||||
int? killerId;
|
||||
float killerPosX;
|
||||
float killerPosY;
|
||||
float killerPosZ;
|
||||
float killerHeading;
|
||||
|
||||
if (killer.IsNull)
|
||||
{
|
||||
killerId = null;
|
||||
killerPosX = -1;
|
||||
killerPosY = -1;
|
||||
killerPosZ = -1;
|
||||
killerHeading = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
killerId = killer.GetUser().Id;
|
||||
killerPosX = killer.Position.X;
|
||||
killerPosY = killer.Position.Y;
|
||||
killerPosZ = killer.Position.Z;
|
||||
killerHeading = killer.Heading;
|
||||
if(player != killer)
|
||||
{
|
||||
string message = "~y~[HINWEIS]: " + killer.Name + " hat " + player.Name + " getötet (" + NAPI.Player.GetPlayerCurrentWeapon(killer) + ")";
|
||||
ChatService.BroadcastAdmin(message, AdminLevel.ADMIN);
|
||||
}
|
||||
}
|
||||
//MEDIC AUFTRAG
|
||||
MedicTask reviveTask = new MedicTask()
|
||||
{
|
||||
Victim = player.Name,
|
||||
Position = player.Position,
|
||||
CauseOfDeath = reason.ToString(),
|
||||
Caller = null,
|
||||
Description = "Gestorben",
|
||||
Time = DateTime.Now,
|
||||
Type = 0,
|
||||
MedicName = "none"
|
||||
};
|
||||
Medic.AddTaskToList(reviveTask);
|
||||
|
||||
//TODO PICTURE NOTIFICATION + SOUND für Medics
|
||||
|
||||
using (var userDeath = new DatabaseContext())
|
||||
{
|
||||
var dead = new Logs.Death { VictimId = player.GetUser().Id, KillerId = killerId, KillerPositionX = killerPosX, KillerPositionY = killerPosY,
|
||||
KillerPositionZ = killerPosZ, KillerHeading = killerHeading, VictimPositionX = player.Position.X, VictimPositionY = player.Position.Y,
|
||||
VictimPositionZ = player.Position.Z, VictimHeading = player.Heading, CauseOfDeath = reason.ToString()};
|
||||
userDeath.DeathLogs.Add(dead);
|
||||
userDeath.SaveChanges();
|
||||
}
|
||||
}
|
||||
[RemoteEvent("RespawnPlayerAtHospital")]
|
||||
public void RespawnPlayerAtHospital(Client player)
|
||||
{
|
||||
player.SetData("isDead", false);
|
||||
player.RemoveAllWeapons();
|
||||
NAPI.Player.SpawnPlayer(player, new Vector3(-495.45, -336.33, 34.5));
|
||||
}
|
||||
}
|
||||
}
|
||||
55
ReallifeGamemode.Server/Events/Disconnect.cs
Normal file
55
ReallifeGamemode.Server/Events/Disconnect.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Models;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Event Login (Login.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
public class Disconnect : Script
|
||||
{
|
||||
[ServerEvent(Event.PlayerDisconnected)]
|
||||
public void OnPlayerDisconnected(Client player, DisconnectionType type, string reason)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
|
||||
if (type == DisconnectionType.Left)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput(player.Name + " left");
|
||||
}
|
||||
if (type == DisconnectionType.Kicked)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput(player.Name + " kicked");
|
||||
}
|
||||
if (type == DisconnectionType.Timeout)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput(player.Name + " Timeoutet");
|
||||
}
|
||||
|
||||
using (var saveUser = new DatabaseContext())
|
||||
{
|
||||
var user = player.GetUser(saveUser);
|
||||
Vector3 pos = player.Position;
|
||||
|
||||
if(!float.IsNaN(pos.X) && !float.IsNaN(pos.Y) && !float.IsNaN(pos.Z))
|
||||
{
|
||||
user.PositionX = pos.X;
|
||||
user.PositionY = pos.Y;
|
||||
user.PositionZ = pos.Z;
|
||||
saveUser.SaveChanges();
|
||||
}
|
||||
|
||||
user.Dead = player.HasData("isDead") ? player.GetData("isDead") : false;
|
||||
}
|
||||
player.SetData("isLoggedIn", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
ReallifeGamemode.Server/Events/EnterVehicleAttempt.cs
Normal file
35
ReallifeGamemode.Server/Events/EnterVehicleAttempt.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
|
||||
public class EnterVehicleAttempt : Script
|
||||
{
|
||||
[ServerEvent(Event.PlayerEnterVehicleAttempt)]
|
||||
public void OnPlayerEnterVehicleAttempt(Client player, Vehicle vehicle, sbyte seat)
|
||||
{
|
||||
if ((VehicleHash)vehicle.Model == VehicleHash.Dune3)
|
||||
{
|
||||
if (seat == 1) seat = 0;
|
||||
else if (seat == 0) seat = 1;
|
||||
}
|
||||
|
||||
if (seat != 0) return;
|
||||
|
||||
if (vehicle.GetServerVehicle() is FactionVehicle veh)
|
||||
{
|
||||
if(veh.FactionId != player.GetUser().FactionId)
|
||||
{
|
||||
player.StopAnimation();
|
||||
player.SendNotification("~r~Du darfst dieses Fahrzeug nicht benutzen!", true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
67
ReallifeGamemode.Server/Events/Faction.cs
Normal file
67
ReallifeGamemode.Server/Events/Faction.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
class Faction : Script
|
||||
{
|
||||
[RemoteEvent("OnFactionRanksEdit")]
|
||||
public void OnFactionRanksEdit(Client player, string jsonData)
|
||||
{
|
||||
FactionRankHelper helper = JsonConvert.DeserializeObject<FactionRankHelper>(jsonData);
|
||||
using(var context = new DatabaseContext())
|
||||
{
|
||||
Entities.Faction f = context.Factions.FirstOrDefault(x => x.Id == helper.FactionId);
|
||||
if (f == null)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Bei der Bearbeitung der Ränge ist ein Fehler aufgetreten: Die Fraktion existiert nicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
List<Rank> ranks = helper.Ranks;
|
||||
int length = ranks.Count;
|
||||
|
||||
List<FactionRank> factionRanks = context.FactionRanks.ToList().FindAll(fR => fR.FactionId == f.Id);
|
||||
|
||||
List<int> found = new List<int>();
|
||||
|
||||
for(int i = 0; i < ranks.Count; i++)
|
||||
{
|
||||
Rank newRank = ranks[i];
|
||||
if(newRank.Id == 0)
|
||||
{
|
||||
context.FactionRanks.Add(new FactionRank
|
||||
{
|
||||
RankName = newRank.Name,
|
||||
FactionId = f.Id,
|
||||
Order = length - i
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
FactionRank factionRank = factionRanks.Find(r => r.Id == newRank.Id);
|
||||
factionRank.RankName = newRank.Name;
|
||||
factionRank.Order = length - i;
|
||||
found.Add(factionRank.Id);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < factionRanks.Count; i++)
|
||||
{
|
||||
if(!found.Contains(factionRanks[i].Id))
|
||||
{
|
||||
context.FactionRanks.Remove(factionRanks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
player.SendChatMessage("~g~Die Ränge wurden erfolgreich gespeichert.");
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
260
ReallifeGamemode.Server/Events/Key.cs
Normal file
260
ReallifeGamemode.Server/Events/Key.cs
Normal file
@@ -0,0 +1,260 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
using reallife_gamemode.Server.Classes;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Factions.Medic;
|
||||
using reallife_gamemode.Server.Inventory;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Util;
|
||||
/**
|
||||
* @overview Life of German Reallife - Event Key (Key.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
public class Key : Script
|
||||
{
|
||||
[RemoteEvent("keyPress:NUM2")]
|
||||
public void KeyPressNUM2(Client player)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
if (player.GetData("editmode") == true && player.GetUser().IsAdmin(AdminLevel.HEADADMIN) == true)
|
||||
{
|
||||
TempBlip tempBlip = NAPI.Data.GetWorldData("blipTemplate");
|
||||
SaveManager.OnSaveBlipData(player, tempBlip.Sprite.ToString(), tempBlip.Name, tempBlip.Scale.ToString(), tempBlip.Color.ToString(),
|
||||
tempBlip.Transparency.ToString(), 200.ToString(), tempBlip.ShortRange.ToString(), 0.ToString(), 0.ToString());
|
||||
player.SendNotification("~y~Blip~s~ erstellt!", false);
|
||||
}
|
||||
|
||||
GroundItem.PickUpGroundItem(player);
|
||||
}
|
||||
[RemoteEvent("keyPress:LEFT_ARROW")]
|
||||
public void KeyPressLeftArrow(Client player)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
List<Client> nearbyPlayers = NAPI.Player.GetPlayersInRadiusOfPlayer(3, player);
|
||||
|
||||
if (nearbyPlayers.Count > 1)
|
||||
{
|
||||
List<string> nearbyPlayerList = new List<string>();
|
||||
foreach (Client nearPlayer in nearbyPlayers)
|
||||
{
|
||||
if (nearPlayer.Name != player.Name)
|
||||
{
|
||||
nearbyPlayerList.Add(nearPlayer.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
player.TriggerEvent("showPlayerInteraction", JsonConvert.SerializeObject(nearbyPlayerList));
|
||||
}
|
||||
}
|
||||
[RemoteEvent("keyPress:RIGHT_ARROW")]
|
||||
public void KeyPressRightArrow(Client player)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
User user = player.GetUser();
|
||||
switch (user.FactionId)
|
||||
{
|
||||
//LSFD
|
||||
case 2:
|
||||
player.TriggerEvent("showFactionInteraction", user.FactionId, user.GetFaction().Name, user.FactionLeader, Medic.ReviveTasks.Count.ToString(), Medic.HealTasks.Count.ToString(), Medic.FireTasks.Count.ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("keyPress:E")]
|
||||
public void KeyPressE(Client player)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
var user = player.GetUser();
|
||||
if (user?.FactionId != null)
|
||||
{
|
||||
DutyPoint nearest = PositionManager.DutyPoints.Find(d => d.Position.DistanceTo(player.Position) <= 1.5);
|
||||
if (nearest == null) return;
|
||||
if (player.Position.DistanceTo(nearest.Position) <= 1.5 && nearest.FactionId == user.FactionId)
|
||||
{
|
||||
var nameTagColor = new Color(0, 0, 0);
|
||||
var factionId = user.FactionId;
|
||||
|
||||
if (player.GetData("duty") == false)
|
||||
{
|
||||
player.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()?.GetFaction().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.ToList().FindAll(u => u.UserId == user.Id && u.Duty == true);
|
||||
|
||||
foreach(var cloth in clothes)
|
||||
{
|
||||
if(cloth.SlotType == 0)
|
||||
{
|
||||
player.SetClothes(cloth.SlotId, cloth.ClothId, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cloth.ClothId != -1)
|
||||
{
|
||||
player.SetAccessories(cloth.SlotId, cloth.ClothId, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.ClearAccessory(cloth.SlotId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
[RemoteEvent("keyPress:I")]
|
||||
public void KeyPressI(Client player)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
InventoryManager.GetUserItems(player);
|
||||
}
|
||||
[RemoteEvent("keyPress:J")]
|
||||
public void KeyPressJ(Client player)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
List<Client> players = NAPI.Pools.GetAllPlayers();
|
||||
List<ListPlayer> ListPlayers = new List<ListPlayer>();
|
||||
|
||||
foreach(Client listPlayer in players)
|
||||
{
|
||||
var lPlayer = new ListPlayer
|
||||
{
|
||||
Id = listPlayer.Handle.Value,
|
||||
Name = listPlayer.Name,
|
||||
Ping = listPlayer.Ping
|
||||
};
|
||||
|
||||
ListPlayers.Add(lPlayer);
|
||||
}
|
||||
player.TriggerEvent("fetchPlayerList", JsonConvert.SerializeObject(ListPlayers));
|
||||
}
|
||||
[RemoteEvent("keyPress:K")]
|
||||
public void KeyPressK(Client player)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
var user = player.GetUser();
|
||||
if (user?.FactionId != null)
|
||||
{
|
||||
DutyPoint nearest = PositionManager.DutyPoints.Find(d => d.Position.DistanceTo(player.Position) <= 1.5);
|
||||
if (nearest == null) return;
|
||||
if (player.Position.DistanceTo(nearest.Position) <= 1.5 && nearest.FactionId == user.FactionId)
|
||||
{
|
||||
List<string> hats = new List<string>();
|
||||
List<string> tops = new List<string>();
|
||||
List<string> legs = new List<string>();
|
||||
List<string> shoes = new List<string>();
|
||||
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
List<DutyCloth> clothes = context.DutyClothes.ToList().FindAll(c => c.FactionId == user.FactionId && c.Gender == user.GetCharacter().Gender);
|
||||
foreach(var cloth in clothes)
|
||||
{
|
||||
if(cloth.SlotType == 1)
|
||||
{
|
||||
if (cloth.ClothId != -1)
|
||||
{
|
||||
hats.Add(cloth.ClothId.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
hats.Add("Keinen");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (cloth.SlotId)
|
||||
{
|
||||
case 11:
|
||||
tops.Add(cloth.ClothId.ToString());
|
||||
break;
|
||||
case 4:
|
||||
legs.Add(cloth.ClothId.ToString());
|
||||
break;
|
||||
case 6:
|
||||
shoes.Add(cloth.ClothId.ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
player.TriggerEvent("showDutyClothMenu", hats.ToArray(), tops.ToArray(), legs.ToArray(), shoes.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
[RemoteEvent("keyPress:L")]
|
||||
public void KeyPressL(Client player)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
DoorManager.ChangeDoorState(player);
|
||||
}
|
||||
[RemoteEvent("keyPress:N")]
|
||||
public void KeyPressN(Client player)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
}
|
||||
|
||||
[RemoteEvent("keyPress:X")]
|
||||
public void KeyPressX(Client player)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
if (player.IsInVehicle && player.VehicleSeat == -1)
|
||||
{
|
||||
ServerVehicle veh = player.Vehicle.GetServerVehicle();
|
||||
if(veh != null)
|
||||
{
|
||||
if(veh is FactionVehicle fV && fV.FactionId != player.GetUser()?.FactionId && (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN3) ?? false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if(veh is ShopVehicle)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
player.TriggerEvent("ToggleVehicleMenu");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
97
ReallifeGamemode.Server/Events/Login.cs
Normal file
97
ReallifeGamemode.Server/Events/Login.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Util;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Event Login (Login.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
public class Login : Script
|
||||
{
|
||||
[RemoteEvent("OnPlayerLogin")]
|
||||
public void OnPlayerLogin(Client player, string password)
|
||||
{
|
||||
using (var loginUser = new DatabaseContext())
|
||||
{
|
||||
var user = loginUser.Users.SingleOrDefault(b => b.Name == player.Name);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
player.TriggerEvent("loginFail", "Benutzer existiert nicht! Registriere dich zuerst!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (user.SocialClubName != player.SocialClubName && user.Password == NAPI.Util.GetHashSha256(password))
|
||||
{
|
||||
player.TriggerEvent("loginDeny", "Dieser Benutzer gehört dir nicht!");
|
||||
//TODO ?? Log einbauen für den bösen Bub.
|
||||
player.Kick();
|
||||
}
|
||||
if (user.Password != NAPI.Util.GetHashSha256(password))
|
||||
{
|
||||
player.TriggerEvent("loginFail", "Passwort inkorrekt!");
|
||||
}
|
||||
else
|
||||
{
|
||||
player.TriggerEvent("loginSuccess");
|
||||
player.SetData("isLoggedIn", true);
|
||||
player.SetData("spec", true);
|
||||
player.SetData("duty", false);
|
||||
|
||||
if (user.IsAdmin(AdminLevel.HEADADMIN) == true)
|
||||
{
|
||||
player.SetData("editmode", false);
|
||||
}
|
||||
|
||||
var userBankAccount = loginUser.UserBankAccounts.SingleOrDefault(u => u.UserId == user.Id);
|
||||
userBankAccount.Balance = userBankAccount.Balance;
|
||||
|
||||
var userItems = loginUser.UserItems.ToList().FindAll(u => u.UserId == user.Id);
|
||||
player.SetData("items", userItems);
|
||||
|
||||
if (user.CharacterId == null)
|
||||
{
|
||||
var currentPlayerCreatorDimension = (uint)NAPI.Data.GetWorldData("playerCreatorDimension");
|
||||
currentPlayerCreatorDimension++;
|
||||
NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension);
|
||||
player.Dimension = NAPI.Data.GetWorldData("playerCreatorDimension");
|
||||
player.Position = new Vector3(402.8664, -996.4108, -99.00027);
|
||||
player.TriggerEvent("toggleCreator");
|
||||
}
|
||||
else
|
||||
{
|
||||
CharacterCreator.ApplyCharacter(player);
|
||||
UpdateCharacterCloth.LoadCharacterDefaults(player);
|
||||
NAPI.Player.SpawnPlayer(player, new Vector3(user.PositionX, user.PositionY, user.PositionZ), 0);
|
||||
player.TriggerEvent("draw", player.Name, player.Handle.Value);
|
||||
}
|
||||
if (user.Dead == true)
|
||||
{
|
||||
if (user.IsAdmin(AdminLevel.ADMIN) == true)
|
||||
{
|
||||
player.TriggerEvent("startDeathTimer", true);
|
||||
player.Health = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.TriggerEvent("startDeathTimer", false);
|
||||
player.Health = 0;
|
||||
}
|
||||
player.SetData("isDead", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SetData("isDead", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
67
ReallifeGamemode.Server/Events/Register.cs
Normal file
67
ReallifeGamemode.Server/Events/Register.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Models;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Event Register (Register.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
class Register : Script
|
||||
{
|
||||
[RemoteEvent("OnPlayerRegister")]
|
||||
public void OnPlayerRegister(Client player, string password)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
var checkedUser = dbContext.Users.SingleOrDefault(b => b.Name == player.Name);
|
||||
if (checkedUser == null)
|
||||
{
|
||||
var user = new Entities.User
|
||||
{
|
||||
Name = player.Name,
|
||||
SocialClubName = player.SocialClubName,
|
||||
Password = NAPI.Util.GetHashSha256(password),
|
||||
PositionX = Main.DEFAULT_SPAWN_POSITION.X,
|
||||
PositionY = Main.DEFAULT_SPAWN_POSITION.Y,
|
||||
PositionZ = Main.DEFAULT_SPAWN_POSITION.Z
|
||||
};
|
||||
|
||||
dbContext.Users.Add(user);
|
||||
dbContext.SaveChanges();
|
||||
var userBankAccount = new Entities.UserBankAccount
|
||||
{
|
||||
UserId = user.Id,
|
||||
Balance = 5000,
|
||||
Active = true
|
||||
};
|
||||
|
||||
dbContext.UserBankAccounts.Add(userBankAccount);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
player.TriggerEvent("registerSuccess");
|
||||
player.SetData("isLoggedIn", true);
|
||||
player.SetData("isDead", false);
|
||||
|
||||
var currentPlayerCreatorDimension = (uint) NAPI.Data.GetWorldData("playerCreatorDimension");
|
||||
currentPlayerCreatorDimension++;
|
||||
NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension);
|
||||
player.Dimension = NAPI.Data.GetWorldData("playerCreatorDimension");
|
||||
player.TriggerEvent("toggleCreator");
|
||||
}
|
||||
|
||||
else if (player.SocialClubName == checkedUser.SocialClubName)
|
||||
{
|
||||
player.TriggerEvent("registerFail", "Dieser SocialClubAccount ist schon registriert!");
|
||||
}
|
||||
else if (checkedUser.Name == player.Name)
|
||||
{
|
||||
player.TriggerEvent("registerFail", "Benutzername existiert schon!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
39
ReallifeGamemode.Server/Events/ResourceStop.cs
Normal file
39
ReallifeGamemode.Server/Events/ResourceStop.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using GTANetworkAPI;
|
||||
using GTANetworkMethods;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Event ResourceStop (ResourceStop.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
public class ResourceStop : Script
|
||||
{
|
||||
[ServerEvent(Event.ResourceStop)]
|
||||
public void OnResourceStop()
|
||||
{
|
||||
var users = NAPI.Pools.GetAllPlayers();
|
||||
|
||||
foreach(Client user in users)
|
||||
{
|
||||
using (var saveUsers = new DatabaseContext())
|
||||
{
|
||||
var saveUser = saveUsers.Users.SingleOrDefault(u => u.Name == user.Name);
|
||||
|
||||
saveUser.PositionX = user.Position.X;
|
||||
saveUser.PositionY = user.Position.Y;
|
||||
saveUser.PositionZ = user.Position.Z;
|
||||
saveUsers.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
ReallifeGamemode.Server/Events/Siren.cs
Normal file
26
ReallifeGamemode.Server/Events/Siren.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using GTANetworkAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
class Siren : Script
|
||||
{
|
||||
private Dictionary<NetHandle, bool> _sirenStates = new Dictionary<NetHandle, bool>();
|
||||
|
||||
[RemoteEvent("keyPress:B:toggleSiren")]
|
||||
public void ToggleSirenEvent(Client player)
|
||||
{
|
||||
if (!player.IsInVehicle || player.VehicleSeat != -1) return;
|
||||
Vehicle pV = player.Vehicle;
|
||||
bool oldValue = _sirenStates.ContainsKey(pV.Handle) ? _sirenStates[pV.Handle] : false;
|
||||
bool newValue = !oldValue;
|
||||
|
||||
_sirenStates[pV.Handle] = newValue;
|
||||
pV.SetSharedData("sirenSound", newValue);
|
||||
|
||||
NAPI.ClientEvent.TriggerClientEventForAll("toggleVehicleSiren", pV, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
154
ReallifeGamemode.Server/Events/UpdateCharacterCloth.cs
Normal file
154
ReallifeGamemode.Server/Events/UpdateCharacterCloth.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Models;
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
public class UpdateCharacterCloth : Script
|
||||
{
|
||||
[RemoteEvent("updateDutyProp")]
|
||||
public void UpdateDutyProp(Client player, int componentId, int componentVariation)
|
||||
{
|
||||
if (componentId != -1)
|
||||
{
|
||||
player.SetAccessories(componentId, componentVariation, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.ClearAccessory(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[RemoteEvent("updateDutyCloth")]
|
||||
public void UpdateDutyCloth(Client player, int componentId, int componentVariation)
|
||||
{
|
||||
if (componentId == 11)
|
||||
{
|
||||
//TODO Spezielle Duty Kleidung in Datenbank einpflegen (Ergibt bei Cop-Kleidung NULL)
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
var character = player.GetUser().GetCharacter();
|
||||
|
||||
var combination = context.ClothCombinations.FirstOrDefault(c => c.Top == componentVariation && c.Gender == character.Gender);
|
||||
player.SetClothes(11, componentVariation, 0);
|
||||
if (combination != null)
|
||||
{
|
||||
player.SetClothes(3, combination.Torso, 0);
|
||||
player.SetClothes(8, combination.Undershirt, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SetClothes(componentId, componentVariation, 0);
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("saveCharacterCloth")]
|
||||
public void SaveDutyCloth(Client client, string JSlotType, string JSlotId, string JClothId)
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
int[] slotType = JsonConvert.DeserializeObject<int[]>(JSlotType);
|
||||
int[] slotId = JsonConvert.DeserializeObject<int[]>(JSlotId);
|
||||
int[] clothId = JsonConvert.DeserializeObject<int[]>(JClothId);
|
||||
|
||||
User user = client.GetUser();
|
||||
user = context.Users.FirstOrDefault(u => u.Id == user.Id);
|
||||
|
||||
var character = client.GetUser().GetCharacter();
|
||||
|
||||
var charClothes = context.CharacterClothes.FirstOrDefault(c => c.UserId == user.Id);
|
||||
if (charClothes == null)
|
||||
{
|
||||
for (var x = 0; x < slotType.Length; x++)
|
||||
{
|
||||
CharacterCloth newCloth = new CharacterCloth
|
||||
{
|
||||
UserId = user.Id,
|
||||
|
||||
Duty = true,
|
||||
|
||||
SlotType = (byte)slotType[x],
|
||||
SlotId = slotId[x],
|
||||
ClothId = clothId[x]
|
||||
};
|
||||
context.CharacterClothes.Add(newCloth);
|
||||
}
|
||||
if (user.GetCharacter().Gender == false)
|
||||
{
|
||||
CharacterCloth newTorso = new CharacterCloth
|
||||
{
|
||||
UserId = user.Id,
|
||||
|
||||
Duty = true,
|
||||
|
||||
SlotType = 0,
|
||||
SlotId = 3,
|
||||
ClothId = context.ClothCombinations.FirstOrDefault(c => c.Top == clothId[1] && c.Gender == character.Gender).Torso
|
||||
};
|
||||
CharacterCloth newUndershirt = new CharacterCloth
|
||||
{
|
||||
UserId = user.Id,
|
||||
|
||||
Duty = true,
|
||||
|
||||
SlotType = 0,
|
||||
SlotId = 8,
|
||||
ClothId = context.ClothCombinations.FirstOrDefault(c => c.Top == clothId[1] && c.Gender == character.Gender).Undershirt
|
||||
};
|
||||
context.CharacterClothes.Add(newTorso);
|
||||
context.CharacterClothes.Add(newUndershirt);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var x = 0; x < slotType.Length; x++)
|
||||
{
|
||||
var loopCloth = context.CharacterClothes.FirstOrDefault(u => u.UserId == user.Id && u.SlotType == slotType[x] && u.SlotId == slotId[x]);
|
||||
loopCloth.ClothId = clothId[x];
|
||||
}
|
||||
CharacterCloth torso = context.CharacterClothes.FirstOrDefault(u => u.UserId == user.Id && u.SlotType == 0 && u.SlotId == 3);
|
||||
CharacterCloth undershirt = context.CharacterClothes.FirstOrDefault(u => u.UserId == user.Id && u.SlotType == 0 && u.SlotId == 8);
|
||||
|
||||
torso.ClothId = context.ClothCombinations.FirstOrDefault(c => c.Top == clothId[1] && c.Gender == character.Gender).Torso;
|
||||
undershirt.ClothId = context.ClothCombinations.FirstOrDefault(c => c.Top == clothId[1] && c.Gender == character.Gender).Undershirt;
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
LoadCharacterDefaults(client);
|
||||
}
|
||||
|
||||
[RemoteEvent("defaultCharacterCloth")]
|
||||
public static void LoadCharacterDefaults(Client player)
|
||||
{
|
||||
User user = player.GetUser();
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
List<CharacterCloth> charClothes = context.CharacterClothes.ToList().FindAll(c => c.UserId == user.Id && c.Duty == false);
|
||||
player.ClearAccessory(0);
|
||||
player.ClearAccessory(1);
|
||||
player.ClearAccessory(2);
|
||||
player.ClearAccessory(6);
|
||||
player.ClearAccessory(7);
|
||||
|
||||
foreach (var cloth in charClothes)
|
||||
{
|
||||
if(cloth.SlotType == 1)
|
||||
{
|
||||
player.SetAccessories(cloth.SlotId, cloth.ClothId, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SetClothes(cloth.SlotId, cloth.ClothId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
130
ReallifeGamemode.Server/Events/VehicleMenu.cs
Normal file
130
ReallifeGamemode.Server/Events/VehicleMenu.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
public class VehicleMenu : Script
|
||||
{
|
||||
[RemoteEvent("VehicleMenu_ToggleEngine")]
|
||||
public void VehicleMenuToggleEngineEvent(Client player)
|
||||
{
|
||||
if (player.IsInVehicle && player.VehicleSeat == -1)
|
||||
{
|
||||
Vehicle v = player.Vehicle;
|
||||
|
||||
User u = player.GetUser();
|
||||
if (u == null) return;
|
||||
|
||||
if (NAPI.Entity.GetEntityVelocity(v).Length() > 1)
|
||||
{
|
||||
player.SendNotification("~r~Der Motor kann nur im Stand betätigt werden.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
bool state = VehicleStreaming.GetEngineState(v);
|
||||
ServerVehicle sV = v.GetServerVehicle();
|
||||
if (sV != null)
|
||||
{
|
||||
if (sV is ShopVehicle)
|
||||
{
|
||||
VehicleStreaming.SetEngineState(v, false);
|
||||
return;
|
||||
}
|
||||
else if (sV is FactionVehicle fV)
|
||||
{
|
||||
if (fV.FactionId != u.FactionId && !state)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
VehicleStreaming.SetEngineState(v, !state);
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("VehicleMenu_LockCar")]
|
||||
public void VehicleMenuLockCarEvent(Client player)
|
||||
{
|
||||
if (player.IsInVehicle && player.VehicleSeat == -1)
|
||||
{
|
||||
Vehicle v = player.Vehicle;
|
||||
|
||||
User u = player.GetUser();
|
||||
if (u == null) return;
|
||||
|
||||
bool state = VehicleStreaming.GetLockState(v);
|
||||
ServerVehicle sV = v.GetServerVehicle();
|
||||
|
||||
if (sV != null)
|
||||
{
|
||||
if (sV is ShopVehicle)
|
||||
{
|
||||
VehicleStreaming.SetEngineState(v, false);
|
||||
return;
|
||||
}
|
||||
else if (sV is FactionVehicle fV)
|
||||
{
|
||||
if (fV.FactionId != u.FactionId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(sV is UserVehicle uV)
|
||||
{
|
||||
if(uV.UserId != u.Id && !u.IsAdmin(AdminLevel.ADMIN3))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
VehicleStreaming.SetLockStatus(v, !state);
|
||||
state = !state;
|
||||
string msg = "Fahrzeug ";
|
||||
msg += state ? "~g~abgeschlossen" : "~r~aufgeschlossen";
|
||||
player.SendNotification(msg);
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("VehicleMenu_ToggleSingleDoor")]
|
||||
public void VehicleMenuToggleSingleDoorEvent(Client player, int door)
|
||||
{
|
||||
if (!player.IsInVehicle) return;
|
||||
Vehicle veh = player.Vehicle;
|
||||
|
||||
DoorID doorId = (DoorID)door;
|
||||
|
||||
DoorState state = VehicleStreaming.GetDoorState(veh, doorId);
|
||||
|
||||
VehicleStreaming.SetDoorState(veh, doorId, state == DoorState.DoorOpen ? DoorState.DoorClosed : DoorState.DoorOpen);
|
||||
}
|
||||
|
||||
[RemoteEvent("VehicleMenu_OpenAllDoors")]
|
||||
public void VehicleMenuOpenAllDoorsEvent(Client player)
|
||||
{
|
||||
if (!player.IsInVehicle) return;
|
||||
Vehicle veh = player.Vehicle;
|
||||
|
||||
foreach (DoorID doorId in Enum.GetValues(typeof(DoorID)))
|
||||
{
|
||||
VehicleStreaming.SetDoorState(veh, doorId, DoorState.DoorOpen);
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("VehicleMenu_CloseAllDoors")]
|
||||
public void VehicleMenuCloseAllDoorsEvent(Client player)
|
||||
{
|
||||
if (!player.IsInVehicle) return;
|
||||
Vehicle veh = player.Vehicle;
|
||||
|
||||
foreach (DoorID doorId in Enum.GetValues(typeof(DoorID)))
|
||||
{
|
||||
VehicleStreaming.SetDoorState(veh, doorId, DoorState.DoorClosed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
35
ReallifeGamemode.Server/Extensions/AdminLevelExtension.cs
Normal file
35
ReallifeGamemode.Server/Extensions/AdminLevelExtension.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using reallife_gamemode.Server.Util;
|
||||
using static reallife_gamemode.Server.Util.AdminLevel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static class AdminLevelExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Gibt den richtigen Namen eines Admin Levels zurück
|
||||
/// </summary>
|
||||
/// <param name="level">Das Admin Level, dessen Namen man bekommen möchte</param>
|
||||
/// <returns></returns>
|
||||
public static string GetName(this AdminLevel level)
|
||||
{
|
||||
switch(level)
|
||||
{
|
||||
case SUPPORTER:
|
||||
return "Supporter";
|
||||
case ADMIN:
|
||||
case ADMIN2:
|
||||
case ADMIN3:
|
||||
return "Admin";
|
||||
case HEADADMIN:
|
||||
return "Headadmin";
|
||||
case PROJEKTLEITUNG:
|
||||
return "Projektleiter";
|
||||
default:
|
||||
return "Spieler";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
77
ReallifeGamemode.Server/Extensions/ClientExtension.cs
Normal file
77
ReallifeGamemode.Server/Extensions/ClientExtension.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Client Extension (ClientExtension.cs)
|
||||
* @author hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static class ClientExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Gibt das User-Objekt eines Client's zurück.
|
||||
/// Gibt nichts zurück, wenn der Client nicht eingeloggt ist
|
||||
/// </summary>
|
||||
/// <param name="client">Der Client, dessen User man bekommen möchte</param>
|
||||
/// <param name="context">Ein eventuell vorhandener Datenbank-Context, falls man Änderungen in der Datenbank vornehmen will</param>
|
||||
/// <returns></returns>
|
||||
public static User GetUser(this Client client, DatabaseContext context = null)
|
||||
{
|
||||
if (!client.IsLoggedIn()) return null;
|
||||
if(context == null)
|
||||
{
|
||||
using (context = new DatabaseContext())
|
||||
{
|
||||
return context.Users.FirstOrDefault(u => u.Name == client.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Users.FirstOrDefault(u => u.Name == client.Name);
|
||||
}
|
||||
}
|
||||
|
||||
public static Character GetCharacter(this User user, DatabaseContext context = null)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
using (context = new DatabaseContext())
|
||||
{
|
||||
return context.Characters.FirstOrDefault(u => u.UserId == user.Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Characters.FirstOrDefault(u => u.UserId == user.Id);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt zurück, ob ein Client eingeloggt ist
|
||||
/// </summary>
|
||||
/// <param name="player">Der Client, dessen Login-Status man bekommen möchte</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsLoggedIn(this Client player)
|
||||
{
|
||||
return player.HasData("isLoggedIn") ? player.GetData("isLoggedIn") : false;
|
||||
}
|
||||
|
||||
public static Vector3 GetPositionFromPlayer(Client player, float distance, int offset = 0)
|
||||
{
|
||||
var pos = player.Position;
|
||||
var a = player.Heading + offset;
|
||||
var rad = a * Math.PI / 180;
|
||||
var newpos = new Vector3(pos.X + (distance * Math.Sin(-rad)),
|
||||
pos.Y + (distance * Math.Cos(-rad)),
|
||||
pos.Z);
|
||||
return newpos;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
18
ReallifeGamemode.Server/Extensions/IntegerExtension.cs
Normal file
18
ReallifeGamemode.Server/Extensions/IntegerExtension.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static class IntegerExtension
|
||||
{
|
||||
public static string ToMoneyString(this int? money)
|
||||
{
|
||||
return ToMoneyString(money ?? 0);
|
||||
}
|
||||
public static string ToMoneyString(this int money)
|
||||
{
|
||||
return "$" + string.Format(Main.SERVER_CULTURE, "{0:C0}", money).Replace("€", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
17
ReallifeGamemode.Server/Extensions/VehicleExtension.cs
Normal file
17
ReallifeGamemode.Server/Extensions/VehicleExtension.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static class VehicleExtension
|
||||
{
|
||||
public static ServerVehicle GetServerVehicle(this Vehicle veh)
|
||||
{
|
||||
return VehicleManager.GetServerVehicleFromVehicle(veh);
|
||||
}
|
||||
}
|
||||
}
|
||||
87
ReallifeGamemode.Server/Factions/Medic/Medic.cs
Normal file
87
ReallifeGamemode.Server/Factions/Medic/Medic.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
using reallife_gamemode.Server.Services;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Server Factions Medic Medic.cs
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
|
||||
namespace reallife_gamemode.Server.Factions.Medic
|
||||
{
|
||||
public class Medic : Script
|
||||
{
|
||||
public static List<MedicTask> ReviveTasks = new List<MedicTask>();
|
||||
public static List<MedicTask> HealTasks = new List<MedicTask>();
|
||||
public static List<MedicTask> FireTasks = new List<MedicTask>();
|
||||
|
||||
public static void AddTaskToList(MedicTask task)
|
||||
{
|
||||
switch (task.Type)
|
||||
{
|
||||
case 0:
|
||||
ReviveTasks.Add(task);
|
||||
break;
|
||||
case 1:
|
||||
HealTasks.Add(task);
|
||||
break;
|
||||
case 2:
|
||||
FireTasks.Add(task);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveTaskFromList(MedicTask task)
|
||||
{
|
||||
switch (task.Type)
|
||||
{
|
||||
case 0:
|
||||
ReviveTasks.Remove(task);
|
||||
break;
|
||||
case 1:
|
||||
HealTasks.Remove(task);
|
||||
break;
|
||||
case 2:
|
||||
FireTasks.Remove(task);
|
||||
break;
|
||||
}
|
||||
}
|
||||
[RemoteEvent("loadMedicTasks")]
|
||||
public void LoadMedicTasks(Client player, int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
player.TriggerEvent("showMedicTasks", 0, JsonConvert.SerializeObject(ReviveTasks));
|
||||
break;
|
||||
case 1:
|
||||
player.TriggerEvent("showMedicTasks", 1, JsonConvert.SerializeObject(HealTasks));
|
||||
break;
|
||||
case 2:
|
||||
player.TriggerEvent("showMedicTasks", 2, JsonConvert.SerializeObject(FireTasks));
|
||||
break;
|
||||
}
|
||||
}
|
||||
[RemoteEvent("updateMedicTask")]
|
||||
public void UpdateMedicTasks(Client player, int type, int index, string medicName)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
ReviveTasks[index].MedicName = medicName;
|
||||
break;
|
||||
case 1:
|
||||
HealTasks[index].MedicName = medicName;
|
||||
break;
|
||||
case 2:
|
||||
FireTasks[index].MedicName = medicName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
ReallifeGamemode.Server/Factions/Medic/MedicTask.cs
Normal file
26
ReallifeGamemode.Server/Factions/Medic/MedicTask.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Server Factions Medic MedicTask.cs
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
|
||||
namespace reallife_gamemode.Server.Factions.Medic
|
||||
{
|
||||
public class MedicTask
|
||||
{
|
||||
public string Victim { get; set; }
|
||||
public Vector3 Position { get; set; }
|
||||
public int Type { get; set; }
|
||||
public string CauseOfDeath { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Caller { get; set; }
|
||||
public DateTime Time { get; set; }
|
||||
public string MedicName { get; set; }
|
||||
}
|
||||
}
|
||||
110
ReallifeGamemode.Server/Inventory/GroundItem.cs
Normal file
110
ReallifeGamemode.Server/Inventory/GroundItem.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System.Collections.Generic;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using System.Linq;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Models;
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory
|
||||
{
|
||||
public class GroundItem : Script
|
||||
{
|
||||
public int ItemId { get; set; }
|
||||
public int Amount { get; set; }
|
||||
public Vector3 Position { get; set; }
|
||||
|
||||
public static List<GroundItem> GroundItems = new List<GroundItem>();
|
||||
public static List<GTANetworkAPI.Object> GroundObjects = new List<GTANetworkAPI.Object>();
|
||||
public static List<TextLabel> GroundTextLabels = new List<TextLabel>();
|
||||
|
||||
public static void AddGroundItem(GroundItem grndItem, GTANetworkAPI.Object grndObject, TextLabel grndTextLabel)
|
||||
{
|
||||
GroundItems.Add(grndItem);
|
||||
GroundObjects.Add(grndObject);
|
||||
GroundTextLabels.Add(grndTextLabel);
|
||||
}
|
||||
|
||||
public static void PickUpGroundItem(Client player)
|
||||
{
|
||||
GroundItem nearest = GroundItems.FirstOrDefault(d => d.Position.DistanceTo(player.Position) <= 1.2);
|
||||
if (nearest != null)
|
||||
{
|
||||
var invWeight = InventoryManager.GetUserInventoryWeight(player);
|
||||
var itemsToAdd = 0;
|
||||
GTANetworkAPI.Object nearestObject = GroundObjects.FirstOrDefault(d => d.Position == nearest.Position);
|
||||
TextLabel nearestTextLabel = GroundTextLabels.FirstOrDefault(d => d.Position == nearest.Position);
|
||||
IItem nearestItem = InventoryManager.GetItemById(nearest.ItemId);
|
||||
UserItem existingItem = InventoryManager.UserHasThisItem(player, nearest.ItemId);
|
||||
var user = player.GetUser();
|
||||
if (nearestItem.Gewicht * nearest.Amount + invWeight > 40000)
|
||||
{
|
||||
for(var i = 1; i <= nearest.Amount; i++)
|
||||
{
|
||||
if(invWeight + (i * nearestItem.Gewicht) > 40000)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemsToAdd = i;
|
||||
}
|
||||
}
|
||||
if(itemsToAdd < 1)
|
||||
{
|
||||
player.SendNotification("~r~Du hast keinen Platz im Inventar!", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(existingItem != null)
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
UserItem existingUserItem = context.UserItems.FirstOrDefault(i => i.Id == existingItem.Id);
|
||||
existingUserItem.Amount += itemsToAdd;
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UserItem newItem = new UserItem { ItemId = nearest.ItemId, UserId = user.Id, Amount = nearest.Amount };
|
||||
InventoryManager.AddItemToInventory(player, newItem);
|
||||
}
|
||||
nearest.Amount -= itemsToAdd;
|
||||
nearestTextLabel.Text = nearestItem.Name + " ~s~(~y~" + nearest.Amount + "~s~)";
|
||||
player.SendNotification("Du hast nur ~g~" + itemsToAdd + " ~y~" + nearestItem.Name + "~s~ aufgehoben.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existingItem != null)
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
UserItem existingUserItem = context.UserItems.FirstOrDefault(i => i.Id == existingItem.Id && i.UserId == user.Id);
|
||||
existingUserItem.Amount += nearest.Amount;
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UserItem item = new UserItem() { ItemId = nearest.ItemId, UserId = user.Id, Amount = nearest.Amount };
|
||||
InventoryManager.AddItemToInventory(player, item);
|
||||
}
|
||||
RemoveGroundItem(nearest, nearestObject, nearestTextLabel);
|
||||
player.SendNotification("Du hast ~g~" + nearest.Amount + " ~y~" + nearestItem.Name + " ~s~aufgehoben.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveGroundItem(GroundItem grndItem, GTANetworkAPI.Object grndObject, TextLabel grndTextLabel)
|
||||
{
|
||||
GroundItems.Remove(grndItem);
|
||||
NAPI.Entity.DeleteEntity(grndObject);
|
||||
NAPI.Entity.DeleteEntity(grndTextLabel);
|
||||
GroundObjects.Remove(grndObject);
|
||||
GroundTextLabels.Remove(grndTextLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Interfaces DroppableItem (IDroppableItem.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Interfaces
|
||||
{
|
||||
public interface IDroppableItem : IItem
|
||||
{
|
||||
uint Object { get; }
|
||||
}
|
||||
}
|
||||
21
ReallifeGamemode.Server/Inventory/Interfaces/IItem.cs
Normal file
21
ReallifeGamemode.Server/Inventory/Interfaces/IItem.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Interfaces Item (IItem.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Interfaces
|
||||
{
|
||||
public interface IItem
|
||||
{
|
||||
int Id { get; }
|
||||
string Name { get; }
|
||||
string Description { get; }
|
||||
int Gewicht { get; }
|
||||
string Einheit { get; }
|
||||
}
|
||||
}
|
||||
19
ReallifeGamemode.Server/Inventory/Interfaces/IUsableItem.cs
Normal file
19
ReallifeGamemode.Server/Inventory/Interfaces/IUsableItem.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Interfaces UsableItem (IUsableItem.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Interfaces
|
||||
{
|
||||
public interface IUsableItem : IItem, IDroppableItem
|
||||
{
|
||||
void Use(UserItem uItem);
|
||||
}
|
||||
}
|
||||
24
ReallifeGamemode.Server/Inventory/Items/Cheeseburger.cs
Normal file
24
ReallifeGamemode.Server/Inventory/Items/Cheeseburger.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Items Cheeseburger (Cheeseburger.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Items
|
||||
{
|
||||
public class Cheeseburger : FoodItem
|
||||
{
|
||||
public override int Id => 2;
|
||||
public override string Name => "Cheeseburger";
|
||||
public override string Description => "Wie der Hamburger, nur mit Käse.";
|
||||
public override int Gewicht => 320;
|
||||
public override string Einheit => "g";
|
||||
public override int HpAmount => 20;
|
||||
public override uint Object => 2240524752;
|
||||
}
|
||||
}
|
||||
24
ReallifeGamemode.Server/Inventory/Items/Chickenburger.cs
Normal file
24
ReallifeGamemode.Server/Inventory/Items/Chickenburger.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Items Chickenburger (Chickenburger.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Items
|
||||
{
|
||||
public class Chickenburger : FoodItem
|
||||
{
|
||||
public override int Id => 3;
|
||||
public override string Name => "Chickenburger";
|
||||
public override string Description => "Hühnchenburger";
|
||||
public override int Gewicht => 330;
|
||||
public override string Einheit => "g";
|
||||
public override int HpAmount => 25;
|
||||
public override uint Object => 2240524752;
|
||||
}
|
||||
}
|
||||
28
ReallifeGamemode.Server/Inventory/Items/DropItem.cs
Normal file
28
ReallifeGamemode.Server/Inventory/Items/DropItem.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Items
|
||||
{
|
||||
public abstract class DropItem : IDroppableItem
|
||||
{
|
||||
public abstract int HpAmount { get; }
|
||||
public abstract int Id { get; }
|
||||
public abstract string Name { get; }
|
||||
public abstract string Description { get; }
|
||||
public abstract int Gewicht { get; }
|
||||
public abstract string Einheit { get; }
|
||||
public abstract uint Object { get; }
|
||||
|
||||
public void Drop(UserItem uItem, Client player, int amount)
|
||||
{
|
||||
player.SendNotification("Du hast ~g~" + amount + " ~y~" + InventoryManager.GetItemById(uItem.ItemId).Name + " ~s~weggeworfen.", false);
|
||||
InventoryManager.RemoveUserItem(player.GetUser(), uItem, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
ReallifeGamemode.Server/Inventory/Items/FoodItem.cs
Normal file
37
ReallifeGamemode.Server/Inventory/Items/FoodItem.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Items
|
||||
{
|
||||
public abstract class FoodItem : IUsableItem
|
||||
{
|
||||
public abstract int HpAmount { get; }
|
||||
public abstract int Id { get; }
|
||||
public abstract string Name { get; }
|
||||
public abstract string Description { get; }
|
||||
public abstract int Gewicht { get; }
|
||||
public abstract string Einheit { get; }
|
||||
public abstract uint Object { get; }
|
||||
|
||||
public void Use(UserItem uItem)
|
||||
{
|
||||
Client player = uItem.GetUser().GetClient();
|
||||
|
||||
int amountToAdd = HpAmount;
|
||||
if(player.Health + amountToAdd > 100)
|
||||
{
|
||||
amountToAdd = 100 - player.Health;
|
||||
}
|
||||
|
||||
player.Health += amountToAdd;
|
||||
player.SendNotification("Du hast ein/einen ~y~" + InventoryManager.GetItemById(uItem.ItemId).Name + " ~s~gegessen.", false);
|
||||
InventoryManager.RemoveUserItem(player.GetUser(), uItem, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
24
ReallifeGamemode.Server/Inventory/Items/Hamburger.cs
Normal file
24
ReallifeGamemode.Server/Inventory/Items/Hamburger.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Items Hamburger (Hamburger.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Items
|
||||
{
|
||||
public class Hamburger : FoodItem
|
||||
{
|
||||
public override int Id => 1;
|
||||
public override string Name => "Hamburger";
|
||||
public override string Description => "Ein leckerer Hamburger.";
|
||||
public override int Gewicht => 300;
|
||||
public override string Einheit => "g";
|
||||
public override int HpAmount => 20;
|
||||
public override uint Object => 2240524752;
|
||||
}
|
||||
}
|
||||
23
ReallifeGamemode.Server/Inventory/Items/Holz.cs
Normal file
23
ReallifeGamemode.Server/Inventory/Items/Holz.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Items Hamburger (Hamburger.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Items
|
||||
{
|
||||
public class Holz : IDroppableItem
|
||||
{
|
||||
public int Id => 4;
|
||||
public string Name => "Holz";
|
||||
public string Description => "Ich und mein Holz.";
|
||||
public int Gewicht => 1000;
|
||||
public string Einheit => "g";
|
||||
public uint Object => 1805779401;
|
||||
}
|
||||
}
|
||||
24
ReallifeGamemode.Server/Inventory/Items/Kraftstoff.cs
Normal file
24
ReallifeGamemode.Server/Inventory/Items/Kraftstoff.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Items Hamburger (Hamburger.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Items
|
||||
{
|
||||
public class Kraftstoff : DropItem
|
||||
{
|
||||
public override int Id => 5;
|
||||
public override string Name => "Kraftstoff";
|
||||
public override string Description => "Der Stoff gibt dir Kraft.";
|
||||
public override int Gewicht => 1000;
|
||||
public override string Einheit => "g";
|
||||
public override int HpAmount => 20;
|
||||
public override uint Object => 786272259;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Logs BankAccountTransactionHistory (BankAccountTransactionHistory.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Logs
|
||||
{
|
||||
public class BankAccountTransactionHistory
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[StringLength(32)]
|
||||
public string Sender { get; set; }
|
||||
public int SenderBalance { get; set; }
|
||||
public int MoneySent { get; set; }
|
||||
[StringLength(32)]
|
||||
public string Receiver { get; set; }
|
||||
public int ReceiverBalance { get; set; }
|
||||
public int NewSenderBalance { get; set; }
|
||||
public int NewReceiverBalance { get; set; }
|
||||
public int Fee { get; set; }
|
||||
[StringLength(32)]
|
||||
public string Origin { get; set; }
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public DateTime Timestamp { get; set; }
|
||||
}
|
||||
}
|
||||
45
ReallifeGamemode.Server/Logs/Death.cs
Normal file
45
ReallifeGamemode.Server/Logs/Death.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Logs Death (Death.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Logs
|
||||
{
|
||||
public class Death
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("Victim")]
|
||||
public int VictimId { get; set; }
|
||||
public User Victim { get; set; }
|
||||
|
||||
[ForeignKey("Killer")]
|
||||
public int? KillerId { get; set; }
|
||||
public User Killer { get; set; }
|
||||
|
||||
public float VictimPositionX { get; set; }
|
||||
public float VictimPositionY { get; set; }
|
||||
public float VictimPositionZ { get; set; }
|
||||
public float VictimHeading { get; set; }
|
||||
|
||||
public float KillerPositionX { get; set; }
|
||||
public float KillerPositionY { get; set; }
|
||||
public float KillerPositionZ { get; set; }
|
||||
public float KillerHeading { get; set; }
|
||||
|
||||
[StringLength(64)]
|
||||
public string CauseOfDeath { get; set; }
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public DateTime Timestamp { get; set; }
|
||||
}
|
||||
}
|
||||
64
ReallifeGamemode.Server/Main.cs
Normal file
64
ReallifeGamemode.Server/Main.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Globalization;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Classes;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using reallife_gamemode.Server.Util;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Main Class (Main.cs)
|
||||
* @author VegaZ, hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode
|
||||
{
|
||||
public class Main : Script
|
||||
{
|
||||
public static readonly Vector3 DEFAULT_SPAWN_POSITION = new Vector3(-427.5189, 1116.453, 326.7829);
|
||||
public static readonly float DEFAULT_SPAWN_HEADING = 340.8f;
|
||||
|
||||
public static readonly CultureInfo SERVER_CULTURE = new CultureInfo("de-DE");
|
||||
|
||||
[ServerEvent(Event.ResourceStart)]
|
||||
public void OnResourceStart()
|
||||
{
|
||||
NAPI.Server.SetGlobalServerChat(false);
|
||||
|
||||
NAPI.Server.SetCommandErrorMessage("~r~[FEHLER]~s~ Dieser Command existiert nicht.");
|
||||
NAPI.Server.SetDefaultSpawnLocation(DEFAULT_SPAWN_POSITION, DEFAULT_SPAWN_HEADING);
|
||||
NAPI.Server.SetAutoSpawnOnConnect(false);
|
||||
NAPI.Server.SetAutoRespawnAfterDeath(false);
|
||||
NAPI.Data.SetWorldData("playerCreatorDimension", 0);
|
||||
|
||||
|
||||
InventoryManager.LoadItems();
|
||||
TuningManager.AddTuningGarage(new Vector3(-341, -134, 38.5)); // Downtown LS
|
||||
TuningManager.AddTuningGarage(new Vector3(732, -1088, 21)); // LS Intersection
|
||||
TuningManager.AddTuningGarage(new Vector3(-1155, -2006, 12)); // LS Airport
|
||||
TuningManager.AddTuningGarage(new Vector3(110, 6628, 31)); // Paleto Bay
|
||||
TuningManager.AddTuningGarage(new Vector3(1175, 2639, 37)); // Route 69
|
||||
|
||||
TimeManager.StartTimeManager();
|
||||
|
||||
DatabaseHelper.InitDatabaseFirstTime();
|
||||
|
||||
FactionHelper.CheckFactionBankAccounts();
|
||||
BusinessManager.LoadBusinesses();
|
||||
InteriorManager.LoadInteriors();
|
||||
DoorManager.LoadDoors();
|
||||
|
||||
|
||||
TempBlip tempBlip = new TempBlip()
|
||||
{
|
||||
Color = 1,
|
||||
Name = "",
|
||||
Transparency = 0,
|
||||
ShortRange = true,
|
||||
Sprite = 1,
|
||||
Scale = 1,
|
||||
};
|
||||
|
||||
NAPI.Data.SetWorldData("blipTemplate", tempBlip);
|
||||
}
|
||||
}
|
||||
}
|
||||
95
ReallifeGamemode.Server/Managers/BankManager.cs
Normal file
95
ReallifeGamemode.Server/Managers/BankManager.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Business;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Util;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Managers BankManager (BankManager.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class BankManager
|
||||
{
|
||||
public static TransactionResult SetMoney(Client admin, IBankAccountOwner owner, int amount, string reason = "Von Admin gesetzt")
|
||||
{
|
||||
using (var transferMoney = new DatabaseContext())
|
||||
{
|
||||
if (amount < 0) return TransactionResult.NEGATIVE_MONEY_SENT;
|
||||
|
||||
IBankAccount account = owner.GetBankAccount(transferMoney);
|
||||
|
||||
if (account == null) return TransactionResult.RECEIVER_NO_BANKACCOUNT;
|
||||
|
||||
var transactionLog = new Logs.BankAccountTransactionHistory
|
||||
{
|
||||
Sender = "ADMIN: " + admin.Name,
|
||||
SenderBalance = 0,
|
||||
Receiver = owner.Name,
|
||||
ReceiverBalance = amount,
|
||||
NewReceiverBalance = amount,
|
||||
NewSenderBalance = 0,
|
||||
MoneySent = amount,
|
||||
Fee = 0,
|
||||
Origin = reason
|
||||
};
|
||||
|
||||
// add log
|
||||
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
|
||||
|
||||
account.Balance = amount;
|
||||
|
||||
transferMoney.SaveChanges();
|
||||
|
||||
return TransactionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
public static TransactionResult TransferMoney(IBankAccountOwner sender, IBankAccountOwner receiver, int amount, string origin)
|
||||
{
|
||||
using (var transferMoney = new DatabaseContext())
|
||||
{
|
||||
if (amount < 0) return TransactionResult.NEGATIVE_MONEY_SENT;
|
||||
|
||||
IBankAccount senderAccount = sender.GetBankAccount(transferMoney);
|
||||
IBankAccount receiverAccount = receiver.GetBankAccount(transferMoney);
|
||||
|
||||
if (senderAccount == null) return TransactionResult.SENDER_NO_BANKACCOUNT;
|
||||
if (receiverAccount == null) return TransactionResult.RECEIVER_NO_BANKACCOUNT;
|
||||
|
||||
if (senderAccount.Balance < amount) return TransactionResult.SENDER_NOT_ENOUGH_MONEY;
|
||||
|
||||
var transactionLog = new Logs.BankAccountTransactionHistory
|
||||
{
|
||||
Sender = sender.Name,
|
||||
SenderBalance = senderAccount.Balance,
|
||||
Receiver = receiver.Name,
|
||||
ReceiverBalance = receiverAccount.Balance,
|
||||
NewReceiverBalance = receiverAccount.Balance + amount,
|
||||
NewSenderBalance = senderAccount.Balance - amount,
|
||||
MoneySent = amount,
|
||||
Fee = 0,
|
||||
Origin = origin
|
||||
};
|
||||
|
||||
// add log
|
||||
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
|
||||
|
||||
senderAccount.Balance -= amount;
|
||||
receiverAccount.Balance += amount;
|
||||
|
||||
transferMoney.SaveChanges();
|
||||
|
||||
return TransactionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
164
ReallifeGamemode.Server/Managers/BusinessManager.cs
Normal file
164
ReallifeGamemode.Server/Managers/BusinessManager.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Business;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
class BusinessManager : Script
|
||||
{
|
||||
public static List<BusinessBase> Businesses { get; private set; }
|
||||
|
||||
public static void LoadBusinesses()
|
||||
{
|
||||
Businesses = new List<BusinessBase>();
|
||||
|
||||
IEnumerable<Type> allTypes = Assembly.GetExecutingAssembly().GetTypes().Where(type => type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(BusinessBase)));
|
||||
foreach (Type item in allTypes)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput($"Loading Business {item.Name}");
|
||||
if (Activator.CreateInstance(item) is BusinessBase o)
|
||||
{
|
||||
if (GetBusiness(o.Id) != null)
|
||||
{
|
||||
throw new InvalidOperationException($"Double Business ID found: {o.Id} | {o.Name}");
|
||||
}
|
||||
Businesses.Add(o);
|
||||
o.Setup();
|
||||
o.Load();
|
||||
o.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static T GetBusiness<T>() where T : BusinessBase
|
||||
{
|
||||
return (T)Businesses.Find(b => b.GetType() == typeof(T));
|
||||
}
|
||||
|
||||
public static BusinessBase GetBusiness(int? id)
|
||||
{
|
||||
return Businesses.Find(b => b.Id == id);
|
||||
}
|
||||
|
||||
[RemoteEvent("Business_DepositMoney")]
|
||||
public void BusinessDepositMoney(Client player, int amount)
|
||||
{
|
||||
User user = player.GetUser();
|
||||
if(user == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BusinessBase playerBusiness = GetBusiness(user.BusinessId);
|
||||
|
||||
TransactionResult result = BankManager.TransferMoney(user, playerBusiness, amount, "Überweisung");
|
||||
|
||||
/*if(result == TransactionResult.NEGATIVE_MONEY_SENT)
|
||||
{
|
||||
player.SendNotification("~r~Es können nur positive Beträge überwiesen werden");
|
||||
return;
|
||||
}
|
||||
else if(result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
|
||||
{
|
||||
player.SendNotification("~r~Du hast nicht genug Geld");
|
||||
return;
|
||||
}
|
||||
else */if(result == TransactionResult.SUCCESS)
|
||||
{
|
||||
player.TriggerEvent("business_updateMoney", playerBusiness.GetBankAccount().Balance.ToMoneyString());
|
||||
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("Business_WithdrawMoney")]
|
||||
public void BusinessWithdrawMoney(Client player, int amount)
|
||||
{
|
||||
User user = player.GetUser();
|
||||
if (user == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BusinessBase playerBusiness = GetBusiness(user.BusinessId);
|
||||
|
||||
TransactionResult result = BankManager.TransferMoney(playerBusiness, user, amount, "Überweisung");
|
||||
|
||||
if (result == TransactionResult.NEGATIVE_MONEY_SENT)
|
||||
{
|
||||
player.SendNotification("~r~Es können nur positive Beträge überwiesen werden");
|
||||
return;
|
||||
}
|
||||
else if (result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
|
||||
{
|
||||
player.SendNotification("~r~Es ist nicht genug Geld auf der Businesskasse vorhanden");
|
||||
return;
|
||||
}
|
||||
else if (result == TransactionResult.SUCCESS)
|
||||
{
|
||||
player.TriggerEvent("business_updateMoney", playerBusiness.GetBankAccount().Balance.ToMoneyString());
|
||||
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[ServerEvent(Event.PlayerEnterVehicle)]
|
||||
public void CarDealerBusiness_PlayerEnterVehicle(Client player, Vehicle veh, int seat)
|
||||
{
|
||||
ServerVehicle sVeh = veh.GetServerVehicle();
|
||||
if (sVeh == null) return;
|
||||
if(!(sVeh is ShopVehicle)) return;
|
||||
ShopVehicle shopVehicle = (ShopVehicle)sVeh;
|
||||
player.TriggerEvent("ShopVehicle_OpenMenu", GetBusiness(shopVehicle.BusinessId).Name, shopVehicle.Price);
|
||||
}
|
||||
|
||||
[RemoteEvent("VehShop_BuyVehicle")]
|
||||
public void CarDealerBusiness_BuyVehicle(Client player)
|
||||
{
|
||||
ServerVehicle sVeh = player.Vehicle?.GetServerVehicle();
|
||||
if (sVeh == null) return;
|
||||
if (!(sVeh is ShopVehicle)) return;
|
||||
ShopVehicle shopVehicle = (ShopVehicle)sVeh;
|
||||
int price = shopVehicle.Price;
|
||||
CarDealerBusinessBase business = (CarDealerBusinessBase)GetBusiness(shopVehicle.BusinessId);
|
||||
TransactionResult result = BankManager.TransferMoney(player.GetUser(), business, price, "Auto gekauft");
|
||||
if(result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
|
||||
{
|
||||
player.SendNotification("~r~Du hast nicht genug Geld: " + price.ToMoneyString());
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 spawnPos = business.CarSpawnPositon;
|
||||
|
||||
UserVehicle newVeh = new UserVehicle
|
||||
{
|
||||
Heading = business.CarSpawnHeading,
|
||||
PositionX = spawnPos.X,
|
||||
PositionY = spawnPos.Y,
|
||||
PositionZ = spawnPos.Z,
|
||||
Locked = false,
|
||||
UserId = player.GetUser().Id,
|
||||
Model = shopVehicle.Model,
|
||||
PrimaryColor = 111,
|
||||
SecondaryColor = 111,
|
||||
Active = true,
|
||||
NumberPlate = ""
|
||||
};
|
||||
|
||||
using(var dbContext = new DatabaseContext())
|
||||
{
|
||||
dbContext.UserVehicles.Add(newVeh);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
newVeh.Spawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
329
ReallifeGamemode.Server/Managers/CharacterCreator.cs
Normal file
329
ReallifeGamemode.Server/Managers/CharacterCreator.cs
Normal file
@@ -0,0 +1,329 @@
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Models;
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class CharacterCreator : Script
|
||||
{
|
||||
public CharacterCreator()
|
||||
{
|
||||
}
|
||||
|
||||
[RemoteEvent("creatorSave")]
|
||||
public void CreatorSave(Client player, bool gender, string parentData, string featureData, string appearanceData, string hairAndColorData)
|
||||
{
|
||||
var jParentData = JObject.Parse(parentData);
|
||||
var jFeatureData = JArray.Parse(featureData);
|
||||
var jAppearanceData = JArray.Parse(appearanceData);
|
||||
var jHairAndColorData = JArray.Parse(hairAndColorData);
|
||||
|
||||
byte father = jParentData.Value<byte>("Father");
|
||||
byte mother = jParentData.Value<byte>("Mother");
|
||||
float similarity = jParentData.Value<float>("Similarity");
|
||||
float skinSimilarity = jParentData.Value<float>("SkinSimilarity");
|
||||
|
||||
float noseWidth = jFeatureData.Value<float>(0);
|
||||
float noseBottomHeight = jFeatureData.Value<float>(1);
|
||||
float noseTipLength = jFeatureData.Value<float>(2);
|
||||
float noseBridgeDepth = jFeatureData.Value<float>(3);
|
||||
float noseTipHeight = jFeatureData.Value<float>(4);
|
||||
float noseBroken = jFeatureData.Value<float>(5);
|
||||
float browHeight = jFeatureData.Value<float>(6);
|
||||
float browDepth = jFeatureData.Value<float>(7);
|
||||
float cheekboneHeight = jFeatureData.Value<float>(8);
|
||||
float cheekboneWidth = jFeatureData.Value<float>(9);
|
||||
float cheekDepth = jFeatureData.Value<float>(10);
|
||||
float eyeSize = jFeatureData.Value<float>(11);
|
||||
float lipThickness = jFeatureData.Value<float>(12);
|
||||
float jawWidth = jFeatureData.Value<float>(13);
|
||||
float jawShape = jFeatureData.Value<float>(14);
|
||||
float chinHeight = jFeatureData.Value<float>(15);
|
||||
float chinDepth = jFeatureData.Value<float>(16);
|
||||
float chinWidth = jFeatureData.Value<float>(17);
|
||||
float chinIndent = jFeatureData.Value<float>(18);
|
||||
float neckWidth = jFeatureData.Value<float>(19);
|
||||
|
||||
byte blemishes = jAppearanceData[0].Value<byte>("Value");
|
||||
float blemishesOpacity = jAppearanceData[0].Value<byte>("Opacity");
|
||||
byte facialHair = jAppearanceData[1].Value<byte>("Value");
|
||||
float facialHairOpacity = jAppearanceData[1].Value<byte>("Opacity");
|
||||
byte eyebrows = jAppearanceData[2].Value<byte>("Value");
|
||||
float eyebrowsOpacity = jAppearanceData[2].Value<byte>("Opacity");
|
||||
byte ageing = jAppearanceData[3].Value<byte>("Value");
|
||||
float ageingOpacity = jAppearanceData[3].Value<byte>("Opacity");
|
||||
byte makeup = jAppearanceData[4].Value<byte>("Value");
|
||||
float makeupOpacity = jAppearanceData[4].Value<byte>("Opacity");
|
||||
byte blush = jAppearanceData[5].Value<byte>("Value");
|
||||
float blushOpacity = jAppearanceData[5].Value<byte>("Opacity");
|
||||
byte complexion = jAppearanceData[6].Value<byte>("Value");
|
||||
float complexionOpacity = jAppearanceData[6].Value<byte>("Opacity");
|
||||
byte sunDamage = jAppearanceData[7].Value<byte>("Value");
|
||||
float sunDamageOpacity = jAppearanceData[7].Value<byte>("Opacity");
|
||||
byte lipstick = jAppearanceData[8].Value<byte>("Value");
|
||||
float lipstickOpacity = jAppearanceData[8].Value<byte>("Opacity");
|
||||
byte freckles = jAppearanceData[9].Value<byte>("Value");
|
||||
float frecklesOpacity = jAppearanceData[9].Value<byte>("Opacity");
|
||||
byte chestHair = jAppearanceData[10].Value<byte>("Value");
|
||||
float chestHairOpacity = jAppearanceData[10].Value<byte>("Opacity");
|
||||
|
||||
byte hair = jHairAndColorData.Value<byte>(0);
|
||||
byte hairColor = jHairAndColorData.Value<byte>(1);
|
||||
byte hairHighlightColor = jHairAndColorData.Value<byte>(2);
|
||||
byte eyebrowColor = jHairAndColorData.Value<byte>(3);
|
||||
byte beardColor = jHairAndColorData.Value<byte>(4);
|
||||
byte eyeColor = jHairAndColorData.Value<byte>(5);
|
||||
byte blushColor = jHairAndColorData.Value<byte>(6);
|
||||
byte lipstickColor = jHairAndColorData.Value<byte>(7);
|
||||
byte chestHairColor = jHairAndColorData.Value<byte>(8);
|
||||
|
||||
using (var saveCharacter = new DatabaseContext())
|
||||
{
|
||||
var character = new Entities.Character
|
||||
{
|
||||
UserId = player.GetUser().Id,
|
||||
Gender = gender,
|
||||
Father = father,
|
||||
Mother = mother,
|
||||
Similarity = similarity,
|
||||
SkinSimilarity = skinSimilarity,
|
||||
|
||||
NoseWidth = noseWidth,
|
||||
NoseBottomHeight = noseBottomHeight,
|
||||
NoseTipLength = noseTipLength,
|
||||
NoseBridgeDepth = noseBridgeDepth,
|
||||
NoseTipHeight = noseTipHeight,
|
||||
NoseBroken = noseBroken,
|
||||
BrowHeight = browHeight,
|
||||
BrowDepth = browDepth,
|
||||
CheekboneHeight = cheekboneHeight,
|
||||
CheekboneWidth = cheekboneWidth,
|
||||
CheekDepth = cheekDepth,
|
||||
EyeSize = eyeSize,
|
||||
LipThickness = lipThickness,
|
||||
JawWidth = jawWidth,
|
||||
JawShape = jawShape,
|
||||
ChinHeight = chinHeight,
|
||||
ChinDepth = chinDepth,
|
||||
ChinWidth = chinWidth,
|
||||
ChinIndent = chinIndent,
|
||||
NeckWidth = neckWidth,
|
||||
|
||||
Blemishes = blemishes,
|
||||
BlemishesOpacity = blemishesOpacity,
|
||||
FacialHair = facialHair,
|
||||
FacialHairOpacity = facialHairOpacity,
|
||||
Eyebrows = eyebrows,
|
||||
EyebrowsOpacity = eyebrowsOpacity,
|
||||
Ageing = ageing,
|
||||
AgeingOpacity = ageingOpacity,
|
||||
Makeup = makeup,
|
||||
MakeupOpacity = makeupOpacity,
|
||||
Blush = blush,
|
||||
BlushOpacity = blushOpacity,
|
||||
Complexion = complexion,
|
||||
ComplexionOpacity = complexionOpacity,
|
||||
SunDamage = sunDamage,
|
||||
SunDamageOpacity = sunDamageOpacity,
|
||||
Lipstick = lipstick,
|
||||
LipstickOpacity = lipstickOpacity,
|
||||
Freckles = freckles,
|
||||
FrecklesOpacity = frecklesOpacity,
|
||||
ChestHair = chestHair,
|
||||
ChestHairOpacity = chestHairOpacity,
|
||||
|
||||
Hair = hair,
|
||||
HairColor = hairColor,
|
||||
HairHighlightColor = hairHighlightColor,
|
||||
EyebrowColor = eyebrowColor,
|
||||
BeardColor = beardColor,
|
||||
EyeColor = eyeColor,
|
||||
BlushColor = blushColor,
|
||||
LipstickColor = lipstickColor,
|
||||
ChestHairColor = chestHairColor
|
||||
};
|
||||
|
||||
saveCharacter.Characters.Add(character);
|
||||
saveCharacter.SaveChanges();
|
||||
|
||||
var userId = player.GetUser().Id;
|
||||
var user = saveCharacter.Users.SingleOrDefault(u => u.Id == userId);
|
||||
|
||||
user.CharacterId = character.Id;
|
||||
saveCharacter.SaveChanges();
|
||||
}
|
||||
//HeadOverlay makeupHo = new HeadOverlay()
|
||||
//{
|
||||
// Index = 0,
|
||||
// Opacity = 0.0f,
|
||||
// Color = 0,
|
||||
// SecondaryColor = 0
|
||||
//};
|
||||
//HeadOverlay blushHo = new HeadOverlay()
|
||||
//{
|
||||
// Index = 0,
|
||||
// Opacity = 0.0f,
|
||||
// Color = 0,
|
||||
// SecondaryColor = 0
|
||||
//};
|
||||
//player.SetHeadOverlay(4, makeupHo);
|
||||
//player.SetHeadOverlay(5, blushHo);
|
||||
NAPI.Player.SpawnPlayer(player, Main.DEFAULT_SPAWN_POSITION, Main.DEFAULT_SPAWN_HEADING);
|
||||
player.TriggerEvent("draw", player.Name, player.Handle.Value);
|
||||
player.Dimension = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wendet den Character eines Spielers auf diesen an
|
||||
/// </summary>
|
||||
/// <param name="player">Der Client, dessen Aussehen man setzen will</param>
|
||||
public static void ApplyCharacter(Client player)
|
||||
{
|
||||
var userId = player.GetUser().Id;
|
||||
using (var loadCharacter = new DatabaseContext())
|
||||
{
|
||||
var character = loadCharacter.Characters.SingleOrDefault(c => c.UserId == userId);
|
||||
|
||||
//Männlich / Weiblich
|
||||
if (character.Gender == false)
|
||||
{
|
||||
player.SetSkin(PedHash.FreemodeMale01);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SetSkin(PedHash.FreemodeFemale01);
|
||||
}
|
||||
|
||||
//Gesichtszüge
|
||||
float[] faceFeatures = new float[] { character.NoseWidth, character.NoseBottomHeight, character.NoseTipLength, character.NoseBridgeDepth, character.NoseTipHeight,
|
||||
character.NoseBroken, character.BrowHeight, character.BrowDepth, character.CheekboneHeight, character.CheekboneWidth,
|
||||
character.CheekboneWidth, character.CheekDepth, character.EyeSize, character.LipThickness, character.JawWidth,
|
||||
character.JawShape, character.ChinHeight, character.ChinDepth, character.ChinWidth, character.ChinIndent, character.NeckWidth };
|
||||
|
||||
for (var i = 0; i < faceFeatures.Length; i++)
|
||||
{
|
||||
player.SetFaceFeature(i, faceFeatures[i]);
|
||||
}
|
||||
|
||||
//Gesichtsmerkmale
|
||||
HeadOverlay blemishes = new HeadOverlay()
|
||||
{
|
||||
Index = character.Blemishes,
|
||||
Opacity = character.BlemishesOpacity,
|
||||
Color = 255,
|
||||
SecondaryColor = 255
|
||||
};
|
||||
HeadOverlay facialHair = new HeadOverlay()
|
||||
{
|
||||
Index = character.FacialHair,
|
||||
Opacity = character.FacialHairOpacity,
|
||||
Color = character.BeardColor,
|
||||
SecondaryColor = 255
|
||||
};
|
||||
HeadOverlay eyebrows = new HeadOverlay()
|
||||
{
|
||||
Index = character.Eyebrows,
|
||||
Opacity = character.EyebrowsOpacity,
|
||||
Color = character.EyebrowColor,
|
||||
SecondaryColor = 255
|
||||
};
|
||||
HeadOverlay ageing = new HeadOverlay()
|
||||
{
|
||||
Index = character.Ageing,
|
||||
Opacity = character.AgeingOpacity,
|
||||
Color = 255,
|
||||
SecondaryColor = 255
|
||||
};
|
||||
HeadOverlay makeup = new HeadOverlay()
|
||||
{
|
||||
Index = character.Makeup,
|
||||
Opacity = character.MakeupOpacity,
|
||||
Color = 255,
|
||||
SecondaryColor = 255
|
||||
};
|
||||
HeadOverlay blush = new HeadOverlay()
|
||||
{
|
||||
Index = character.Blush,
|
||||
Opacity = character.BlushOpacity,
|
||||
Color = character.BlushColor,
|
||||
SecondaryColor = 255
|
||||
};
|
||||
HeadOverlay complexion = new HeadOverlay()
|
||||
{
|
||||
Index = character.Complexion,
|
||||
Opacity = character.ComplexionOpacity,
|
||||
Color = 255,
|
||||
SecondaryColor = 255
|
||||
};
|
||||
HeadOverlay sunDamage = new HeadOverlay()
|
||||
{
|
||||
Index = character.SunDamage,
|
||||
Opacity = character.SunDamageOpacity,
|
||||
Color = 255,
|
||||
SecondaryColor = 255
|
||||
};
|
||||
HeadOverlay lipstick = new HeadOverlay()
|
||||
{
|
||||
Index = character.Lipstick,
|
||||
Opacity = character.LipstickOpacity,
|
||||
Color = character.LipstickColor,
|
||||
SecondaryColor = 255
|
||||
};
|
||||
HeadOverlay freckles = new HeadOverlay()
|
||||
{
|
||||
Index = character.Freckles,
|
||||
Opacity = character.FrecklesOpacity,
|
||||
Color = 255,
|
||||
SecondaryColor = 255
|
||||
};
|
||||
HeadOverlay chestHair = new HeadOverlay()
|
||||
{
|
||||
Index = character.ChestHair,
|
||||
Opacity = character.ChestHairOpacity,
|
||||
Color = character.ChestHairColor,
|
||||
SecondaryColor = 255
|
||||
};
|
||||
|
||||
player.SetHeadOverlay(0, blemishes);
|
||||
player.SetHeadOverlay(1, facialHair);
|
||||
player.SetHeadOverlay(2, eyebrows);
|
||||
player.SetHeadOverlay(3, ageing);
|
||||
player.SetHeadOverlay(4, makeup);
|
||||
player.SetHeadOverlay(5, blush);
|
||||
player.SetHeadOverlay(6, complexion);
|
||||
player.SetHeadOverlay(7, sunDamage);
|
||||
player.SetHeadOverlay(8, lipstick);
|
||||
player.SetHeadOverlay(9, freckles);
|
||||
player.SetHeadOverlay(10, chestHair);
|
||||
player.SetHeadOverlay(11, blemishes);
|
||||
player.SetHeadOverlay(12, blemishes);
|
||||
|
||||
|
||||
//Gesicht (Vererbung durch Mutter / Vater)
|
||||
HeadBlend headBlend = new HeadBlend()
|
||||
{
|
||||
ShapeFirst = character.Mother,
|
||||
ShapeSecond = character.Father,
|
||||
ShapeThird = 0,
|
||||
SkinFirst = character.Mother,
|
||||
SkinSecond = character.Father,
|
||||
SkinThird = 0,
|
||||
ShapeMix = character.Similarity,
|
||||
SkinMix = character.SkinSimilarity,
|
||||
ThirdMix = 0.0f
|
||||
};
|
||||
NAPI.Player.SetPlayerHeadBlend(player, headBlend);
|
||||
|
||||
//Haare und Haarfarbe
|
||||
player.SetClothes(2, character.Hair, 0);
|
||||
NAPI.Player.SetPlayerHairColor(player, character.HairColor, character.HairHighlightColor);
|
||||
|
||||
//Augenfarbe
|
||||
NAPI.Player.SetPlayerEyeColor(player, character.EyeColor);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
84
ReallifeGamemode.Server/Managers/DoorManager.cs
Normal file
84
ReallifeGamemode.Server/Managers/DoorManager.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Util;
|
||||
/**
|
||||
* @overview Life of German Reallife - Managers BankManager (BankManager.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class DoorManager : Script
|
||||
{
|
||||
private static Dictionary<int, NetHandle> _doorColShapes = new Dictionary<int, NetHandle>();
|
||||
|
||||
public static void LoadDoors()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach(Door door in dbContext.Doors)
|
||||
{
|
||||
_doorColShapes[door.Id] = NAPI.ColShape.CreateSphereColShape(door.Position, 30f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReloadDoors()
|
||||
{
|
||||
foreach(var doorPair in _doorColShapes)
|
||||
{
|
||||
doorPair.Value.Entity<ColShape>().Delete();
|
||||
}
|
||||
_doorColShapes.Clear();
|
||||
LoadDoors();
|
||||
}
|
||||
|
||||
public static void ChangeDoorState(Client player)
|
||||
{
|
||||
var user = player.GetUser();
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
IQueryable<Door> NearDoors = dbContext.Doors.Where(d => d.Position.DistanceTo(player.Position) <= d.Radius);
|
||||
foreach (Door d in NearDoors)
|
||||
{
|
||||
if(!user.IsAdmin(AdminLevel.ADMIN) && (d.FactionId != user.FactionId || d.FactionId == null))
|
||||
{
|
||||
string lockState = "~r~Du hast kein Recht diese T\u00fcr " + (d.Locked == true ? "auf" : "ab") + "zuschlie\u00dfen!";
|
||||
player.SendNotification(lockState, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
d.Locked = !d.Locked;
|
||||
|
||||
string notStr = d.Name + " " + (d.Locked == false ? "~g~auf" : "~r~ab") + "geschlossen";
|
||||
|
||||
player.SendNotification(notStr, true);
|
||||
|
||||
NAPI.Pools.GetAllPlayers().ForEach(p => p.TriggerEvent("changeDoorState", d.Model, d.X, d.Y, d.Z, (d.Locked ? 1 : 0), 0.0f, 0.0f, 0.0f));
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
[ServerEvent(Event.PlayerEnterColshape)]
|
||||
public void DoorManagerPlayerEnterColShapeEvent(ColShape colShape, Client player)
|
||||
{
|
||||
if(_doorColShapes.ContainsValue(colShape.Handle))
|
||||
{
|
||||
int doorId = _doorColShapes.Where(d => d.Value.Value == colShape.Handle.Value).FirstOrDefault().Key;
|
||||
|
||||
using(var dbContext = new DatabaseContext())
|
||||
{
|
||||
Door door = dbContext.Doors.Where(d => d.Id == doorId).First();
|
||||
player.TriggerEvent("changeDoorState", door.Model, door.X, door.Y, door.Z, (door.Locked ? 1 : 0), 0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
62
ReallifeGamemode.Server/Managers/InteractionManager.cs
Normal file
62
ReallifeGamemode.Server/Managers/InteractionManager.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Managers Interaction (InteractionManager.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class InteractionManager : Script
|
||||
{
|
||||
#region Umgebungsinteraktionen PFEILTASTE-HOCH
|
||||
#endregion
|
||||
#region Eigeninteraktionen PFEILTASTE-RUNTER
|
||||
#endregion
|
||||
#region Spielerinteraktionen PFEILTASTE-LINKS
|
||||
[RemoteEvent("openTradeInventory")]
|
||||
public void OpenTradeInventory(Client player, string targetPlayer)
|
||||
{
|
||||
InventoryManager.GetUserItems(player);
|
||||
player.TriggerEvent("openTradeMenu", targetPlayer);
|
||||
}
|
||||
|
||||
[RemoteEvent("sendTradeItemsToPartner")]
|
||||
public void SendTradeItemsToPartner(Client player, string tradeItemArray, int tradePrize, string tradePartnerName)
|
||||
{
|
||||
var tradeItems = JsonConvert.DeserializeObject<string[][]>(tradeItemArray);
|
||||
Client tradePartner = ClientService.GetClientByNameOrId(tradePartnerName);
|
||||
InventoryManager.GetUserItems(player);
|
||||
tradePartner.TriggerEvent("showTradeRequest", player.Name, tradeItems, tradePrize);
|
||||
player.TriggerEvent("startTradeRequestTimer");
|
||||
}
|
||||
|
||||
[RemoteEvent("tradeDecision")]
|
||||
public void TradeDecision(Client player, string tradeSelection, string tradeItemArray, string tradeRequesterName)
|
||||
{
|
||||
var tradeItems = JsonConvert.DeserializeObject<string[][]>(tradeItemArray);
|
||||
Client tradeRequester = ClientService.GetClientByNameOrId(tradeRequesterName);
|
||||
if (tradeSelection == "accept")
|
||||
{
|
||||
InventoryManager.GetUserItems(player);
|
||||
tradeRequester.TriggerEvent("clearTradeItems");
|
||||
player.TriggerEvent("showTradeItems", tradeItemArray);
|
||||
//TODO: Geld abziehen
|
||||
}
|
||||
else
|
||||
{
|
||||
tradeRequester.TriggerEvent("unlockTradeItems");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Fraktionsinteraktionen / Jobinteraktionen PFEILTASTE-RECHTS
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
145
ReallifeGamemode.Server/Managers/InteriorManager.cs
Normal file
145
ReallifeGamemode.Server/Managers/InteriorManager.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class InteriorManager : Script
|
||||
{
|
||||
public static Dictionary<int, NetHandle> _interiorEnterTextLabels = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorExitTextLabels = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorEnterMarkers = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorExitMarkers = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorEnterColShapes = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorExitColShapes = new Dictionary<int, NetHandle>();
|
||||
|
||||
public static Interior GetInteriorByName(string name, DatabaseContext dbContext = null)
|
||||
{
|
||||
if(dbContext == null)
|
||||
{
|
||||
using (dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Interiors.Where(i => i.Name.ToLower() == name.ToLower()).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return dbContext.Interiors.Where(i => i.Name.ToLower() == name.ToLower()).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public static Interior GetInteriorById(int id, DatabaseContext dbContext = null)
|
||||
{
|
||||
if (dbContext == null)
|
||||
{
|
||||
using (dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Interiors.Where(i => i.Id == id).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return dbContext.Interiors.Where(i => i.Id == id).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadInteriors()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach (Interior interior in dbContext.Interiors)
|
||||
{
|
||||
LoadInterior(interior);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadInterior(Interior interior)
|
||||
{
|
||||
if (interior.EnterPosition != null)
|
||||
{
|
||||
_interiorEnterTextLabels[interior.Id] = NAPI.TextLabel.CreateTextLabel("~y~" + interior.Name + "\n~s~Eingang", interior.EnterPosition, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
_interiorEnterMarkers[interior.Id] = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, interior.EnterPosition.Subtract(new Vector3(0, 0, 1.7)), new Vector3(), new Vector3(), 2.0f, new Color(255, 255, 255, 100));
|
||||
_interiorEnterColShapes[interior.Id] = NAPI.ColShape.CreateSphereColShape(interior.EnterPosition, 1.5f);
|
||||
}
|
||||
|
||||
if (interior.ExitPosition != null)
|
||||
{
|
||||
_interiorExitTextLabels[interior.Id] = NAPI.TextLabel.CreateTextLabel("~y~" + interior.Name + "\n~s~Ausgang", interior.ExitPosition, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
_interiorExitMarkers[interior.Id] = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, interior.ExitPosition.Subtract(new Vector3(0, 0, 1.7)), new Vector3(), new Vector3(), 1.6f, new Color(255, 255, 255, 100));
|
||||
_interiorExitColShapes[interior.Id] = NAPI.ColShape.CreateSphereColShape(interior.ExitPosition, 1.3f);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteInterior(Interior interior)
|
||||
{
|
||||
TextLabel enT = GetInteriorEnterTextLabel(interior);
|
||||
TextLabel exT = GetInteriorExitTextLabel(interior);
|
||||
Marker enM = GetInteriorEnterMarker(interior);
|
||||
Marker exM = GetInteriorExitMarkers(interior);
|
||||
ColShape enC = GetInteriorEnterColShape(interior);
|
||||
ColShape exC = GetInteriorExitColShape(interior);
|
||||
|
||||
if (enT != null) enT.Delete();
|
||||
if (exT != null) exT.Delete();
|
||||
if (enM != null) enM.Delete();
|
||||
if (exM != null) exM.Delete();
|
||||
if (enC != null) enC.Delete();
|
||||
if (exC != null) exC.Delete();
|
||||
|
||||
_interiorEnterTextLabels.Remove(interior.Id);
|
||||
_interiorExitTextLabels.Remove(interior.Id);
|
||||
_interiorEnterMarkers.Remove(interior.Id);
|
||||
_interiorExitMarkers.Remove(interior.Id);
|
||||
_interiorEnterColShapes.Remove(interior.Id);
|
||||
_interiorExitColShapes.Remove(interior.Id);
|
||||
}
|
||||
|
||||
public static TextLabel GetInteriorEnterTextLabel(Interior interior) => NAPI.Pools.GetAllTextLabels().Find(t => t.Handle.Value == _interiorEnterTextLabels.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
public static TextLabel GetInteriorExitTextLabel(Interior interior) => NAPI.Pools.GetAllTextLabels().Find(t => t.Handle.Value == _interiorExitTextLabels.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
|
||||
public static Marker GetInteriorEnterMarker(Interior interior) => NAPI.Pools.GetAllMarkers().Find(t => t.Handle.Value == _interiorEnterMarkers.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
public static Marker GetInteriorExitMarkers(Interior interior) => NAPI.Pools.GetAllMarkers().Find(t => t.Handle.Value == _interiorExitMarkers.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
|
||||
public static ColShape GetInteriorEnterColShape(Interior interior) => NAPI.Pools.GetAllColShapes().Find(t => t.Handle.Value == _interiorEnterColShapes.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
public static ColShape GetInteriorExitColShape(Interior interior) => NAPI.Pools.GetAllColShapes().Find(t => t.Handle.Value == _interiorExitColShapes.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
|
||||
public static int GetInteriorIdFromEnterColShape(NetHandle handle) => _interiorEnterColShapes.FirstOrDefault(c => c.Value.Value == handle.Value).Key;
|
||||
public static int GetInteriorIdFromExitColShape(NetHandle handle) => _interiorExitColShapes.FirstOrDefault(c => c.Value.Value == handle.Value).Key;
|
||||
|
||||
[ServerEvent(Event.PlayerEnterColshape)]
|
||||
public void InteriorManagerPlayerEnterColshapeEvent(ColShape colShape, Client player)
|
||||
{
|
||||
int enterId = GetInteriorIdFromEnterColShape(colShape);
|
||||
int exitId = GetInteriorIdFromExitColShape(colShape);
|
||||
if(enterId != 0)
|
||||
{
|
||||
Interior interior = GetInteriorById(enterId);
|
||||
player.TriggerEvent("InteriorManager_ShowHelpText", interior.Name, interior.Id, 0);
|
||||
}
|
||||
else if(exitId != 0)
|
||||
{
|
||||
Interior interior = GetInteriorById(exitId);
|
||||
player.TriggerEvent("InteriorManager_ShowHelpText", interior.Name, interior.Id, 1);
|
||||
}
|
||||
}
|
||||
|
||||
[ServerEvent(Event.PlayerExitColshape)]
|
||||
public void InteriorManagerPlayerExitColshapeEvent(ColShape colShape, Client player)
|
||||
{
|
||||
if(GetInteriorIdFromEnterColShape(colShape) != 0 || GetInteriorIdFromExitColShape(colShape) != 0)
|
||||
{
|
||||
player.TriggerEvent("InteriorManager_ClearHelpText");
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("InteriorManager_UseTeleport")]
|
||||
public void InteriorManagerUseTeleportEvent(Client player, int id, int enterExit)
|
||||
{
|
||||
Interior interior = GetInteriorById(id);
|
||||
player.Position = enterExit == 0 ? interior.ExitPosition : interior.EnterPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
321
ReallifeGamemode.Server/Managers/InventoryManager.cs
Normal file
321
ReallifeGamemode.Server/Managers/InventoryManager.cs
Normal file
@@ -0,0 +1,321 @@
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Inventory;
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Managers InventoryManager (InventoryManager.cs)
|
||||
* @author hydrant, VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class InventoryManager : Script
|
||||
{
|
||||
public static List<IItem> itemList;
|
||||
|
||||
public static void LoadItems()
|
||||
{
|
||||
itemList = new List<IItem>();
|
||||
|
||||
Type[] allTypes = Assembly.GetExecutingAssembly().GetTypes();
|
||||
foreach (Type item in allTypes)
|
||||
{
|
||||
if (item.GetInterfaces().Contains((typeof(IItem))) && !item.IsAbstract)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput($"Loading Item {item.Name}");
|
||||
if (Activator.CreateInstance(item) is IItem o)
|
||||
{
|
||||
if (GetItemById(o.Id) != null)
|
||||
{
|
||||
throw new InvalidOperationException($"Double ItemID found: {o.Id} | {o.Name}");
|
||||
}
|
||||
itemList.Add(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IItem GetItemById(int id)
|
||||
{
|
||||
return itemList.Find(i => i.Id == id);
|
||||
}
|
||||
|
||||
public static IItem GetItemByName(string name)
|
||||
{
|
||||
return itemList.Find(i => i.Name.ToLower() == name.ToLower());
|
||||
}
|
||||
|
||||
public static void RemoveUserItem(User user, UserItem item, int amount)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
var userItem = dbContext.UserItems.FirstOrDefault(i => i.Id == item.Id);
|
||||
|
||||
userItem.Amount -= amount;
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
if (userItem.Amount == 0)
|
||||
{
|
||||
dbContext.Remove(userItem);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetUserItems(Client player)
|
||||
{
|
||||
var user = player.GetUser();
|
||||
var inventoryWeight = 0;
|
||||
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
List<UserItem> userItems = context.UserItems.ToList().FindAll(i => i.UserId == user.Id);
|
||||
string[][] items = new string[userItems.Count][];
|
||||
foreach (var item in userItems)
|
||||
{
|
||||
IItem iItem = GetItemById(item.ItemId);
|
||||
var currentItemWeight = iItem.Gewicht * item.Amount;
|
||||
inventoryWeight += currentItemWeight;
|
||||
|
||||
items[userItems.IndexOf(item)] = new string[6];
|
||||
items[userItems.IndexOf(item)][0] = iItem.Name;
|
||||
items[userItems.IndexOf(item)][1] = iItem.Description;
|
||||
items[userItems.IndexOf(item)][2] = iItem.Gewicht.ToString();
|
||||
items[userItems.IndexOf(item)][3] = item.Amount.ToString();
|
||||
items[userItems.IndexOf(item)][4] = item.Slot.ToString();
|
||||
items[userItems.IndexOf(item)][5] = item.Id.ToString();
|
||||
}
|
||||
player.TriggerEvent("showInventory", inventoryWeight, items);
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetUserInventoryWeight(Client player)
|
||||
{
|
||||
var user = player.GetUser();
|
||||
var inventoryWeight = 0;
|
||||
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
List<UserItem> userItems = context.UserItems.ToList().FindAll(i => i.UserId == user.Id);
|
||||
foreach (var item in userItems)
|
||||
{
|
||||
IItem iItem = GetItemById(item.ItemId);
|
||||
var currentItemWeight = iItem.Gewicht * item.Amount;
|
||||
inventoryWeight += currentItemWeight;
|
||||
}
|
||||
}
|
||||
|
||||
return inventoryWeight;
|
||||
}
|
||||
|
||||
public static UserItem UserHasThisItem(Client player, int itemId)
|
||||
{
|
||||
var user = player.GetUser();
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
UserItem existingItem = context.UserItems.FirstOrDefault(i => i.UserId == user.Id && i.ItemId == itemId);
|
||||
return existingItem;
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetUserItemsAsAdmin(Client player, Entities.User user)
|
||||
{
|
||||
var inventoryWeight = 0;
|
||||
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
List<UserItem> userItems = context.UserItems.ToList().FindAll(i => i.UserId == user.Id);
|
||||
string[][] items = new string[userItems.Count][];
|
||||
foreach (var item in userItems)
|
||||
{
|
||||
IItem iItem = GetItemById(item.ItemId);
|
||||
var currentItemWeight = iItem.Gewicht * item.Amount;
|
||||
inventoryWeight += currentItemWeight;
|
||||
|
||||
items[userItems.IndexOf(item)] = new string[6];
|
||||
items[userItems.IndexOf(item)][0] = iItem.Name;
|
||||
items[userItems.IndexOf(item)][1] = iItem.Description;
|
||||
items[userItems.IndexOf(item)][2] = iItem.Gewicht.ToString();
|
||||
items[userItems.IndexOf(item)][3] = item.Amount.ToString();
|
||||
items[userItems.IndexOf(item)][4] = item.Slot.ToString();
|
||||
items[userItems.IndexOf(item)][5] = item.Id.ToString();
|
||||
}
|
||||
player.TriggerEvent("showInventoryToAdmin", user.Name, inventoryWeight, items);
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("saveInventory")]
|
||||
public void SavePlayerInventory(Client player, string itemArray)
|
||||
{
|
||||
|
||||
var user = player.GetUser();
|
||||
var items = JsonConvert.DeserializeObject<string[][]>(itemArray);
|
||||
|
||||
//player.SendChatMessage(items);
|
||||
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
for (var i = 0; i < items.Length; i++)
|
||||
{
|
||||
UserItem cItem = new UserItem
|
||||
{
|
||||
Amount = int.Parse(items[i][3]),
|
||||
ItemId = GetItemByName(items[i][0]).Id,
|
||||
UserId = user.Id,
|
||||
Slot = int.Parse(items[i][4]),
|
||||
};
|
||||
|
||||
if (int.Parse(items[i][5]) == -1)
|
||||
{
|
||||
context.UserItems.Add(cItem);
|
||||
}
|
||||
else if (cItem.Slot == -1)
|
||||
{
|
||||
UserItem fItem = context.UserItems.FirstOrDefault(j => j.Id == int.Parse(items[i][5]));
|
||||
context.UserItems.Remove(fItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
UserItem fItem = context.UserItems.FirstOrDefault(j => j.Id == int.Parse(items[i][5]));
|
||||
fItem.Amount = cItem.Amount;
|
||||
fItem.Slot = cItem.Slot;
|
||||
}
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddItemToInventory(Client player, UserItem item)
|
||||
{
|
||||
var user = player.GetUser();
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
UserItem existingItem = context.UserItems.FirstOrDefault(i => i.ItemId == item.ItemId && i.UserId == item.UserId);
|
||||
if (existingItem != null)
|
||||
{
|
||||
existingItem.Amount += item.Amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
List<UserItem> allItemsByUser = context.UserItems.ToList().FindAll(i => i.UserId == user.Id);
|
||||
var slotArr = Enumerable.Range(1, 20).ToList();
|
||||
allItemsByUser.ForEach(allItem =>
|
||||
{
|
||||
if (slotArr.Contains(allItem.Slot)) slotArr.Remove(allItem.Slot);
|
||||
});
|
||||
|
||||
int newSlot = slotArr.Min();
|
||||
|
||||
item.Slot = newSlot;
|
||||
context.UserItems.Add(item);
|
||||
|
||||
IItem iItem = GetItemById(item.ItemId);
|
||||
|
||||
string[] newItem = new string[] { iItem.Name, iItem.Description, iItem.Gewicht.ToString(), item.Amount.ToString(), newSlot.ToString(), item.Id.ToString() };
|
||||
|
||||
player.TriggerEvent("addItem", JsonConvert.SerializeObject(newItem));
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("removeItemAsAdmin")]
|
||||
public void SavePlayerInventory(Client player, string amount, string userItemId, string targetPlayerName)
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
UserItem fItem = context.UserItems.FirstOrDefault(j => j.Id == int.Parse(userItemId));
|
||||
|
||||
Client targetPlayer = ClientService.GetClientByNameOrId(targetPlayerName);
|
||||
|
||||
if (amount == "stack")
|
||||
{
|
||||
var itemSlot = fItem.Slot;
|
||||
targetPlayer.TriggerEvent("removeItem", userItemId, fItem.Amount);
|
||||
context.UserItems.Remove(fItem);
|
||||
}
|
||||
else if (amount == "one")
|
||||
{
|
||||
var itemSlot = fItem.Slot;
|
||||
targetPlayer.TriggerEvent("removeItem", userItemId, 1);
|
||||
fItem.Amount--;
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
[RemoteEvent("itemInteract")]
|
||||
public void ItemInteract(Client player, string type, string itemId, int amount)
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
UserItem fItem = context.UserItems.FirstOrDefault(j => j.Id == int.Parse(itemId));
|
||||
IItem iItem = GetItemById(fItem.ItemId);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case "use":
|
||||
player.SendChatMessage("use item: " + iItem.Name);
|
||||
if (iItem == null)
|
||||
{
|
||||
player.SendChatMessage("Dieses Essen existiert nicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (fItem == null)
|
||||
{
|
||||
player.SendChatMessage("Du hast dieses Item nicht");
|
||||
return;
|
||||
}
|
||||
|
||||
if (iItem is IUsableItem usableItemObj)
|
||||
{
|
||||
usableItemObj.Use(fItem);
|
||||
player.TriggerEvent("removeItem", itemId, amount);
|
||||
}
|
||||
else player.SendChatMessage("not useable");
|
||||
break;
|
||||
case "drop":
|
||||
|
||||
if (iItem == null)
|
||||
{
|
||||
player.SendChatMessage("Dieses Item existiert nicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (fItem == null)
|
||||
{
|
||||
player.SendChatMessage("Du hast dieses Item nicht");
|
||||
return;
|
||||
}
|
||||
|
||||
if (iItem is IDroppableItem usableItemObj2)
|
||||
{
|
||||
Vector3 dropPosition = ClientExtension.GetPositionFromPlayer(player, 0.6f, 0);
|
||||
dropPosition.Z -= 0.8f;
|
||||
//new Vector3(player.Position.X, player.Position.Y, player.Position.Z - 0.8f);
|
||||
Random r = new Random();
|
||||
GTANetworkAPI.Object grndObject = NAPI.Object.CreateObject(3777723516, dropPosition, new Vector3(0, 0, r.Next(0, 360)), 0);
|
||||
GroundItem grndItem = new GroundItem { ItemId = iItem.Id, Amount = amount, Position = dropPosition};
|
||||
TextLabel grndTxtLbl = NAPI.TextLabel.CreateTextLabel(iItem.Name + " ~s~(~y~" + amount + "~s~)", dropPosition, 5, 0.5f, 4, new Color(255, 255, 255), false, 0);
|
||||
GroundItem.AddGroundItem(grndItem, grndObject, grndTxtLbl);
|
||||
fItem.Amount -= amount;
|
||||
player.TriggerEvent("removeItem", itemId, amount);
|
||||
}
|
||||
break;
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
ReallifeGamemode.Server/Managers/LoadManager.cs
Normal file
41
ReallifeGamemode.Server/Managers/LoadManager.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Saves;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Managers LoadManager (LoadManager.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class LoadManager : Script
|
||||
{
|
||||
|
||||
[ServerEvent(Event.ResourceStart)]
|
||||
public void OnResourceStart()
|
||||
{
|
||||
using (var loadData = new DatabaseContext())
|
||||
{
|
||||
foreach (SavedBlip b in loadData.Blips)
|
||||
{
|
||||
if(b.Active == true)
|
||||
{
|
||||
NAPI.Blip.CreateBlip((uint) b.Sprite, new Vector3(b.PositionX, b.PositionY, b.PositionZ), b.Scale,
|
||||
b.Color, b.Name, b.Alpha, b.DrawDistance, b.ShortRange, (short) b.Rotation, b.Dimension);
|
||||
}
|
||||
}
|
||||
|
||||
foreach(ServerVehicle veh in loadData.ServerVehicles)
|
||||
{
|
||||
if (!veh.Active) continue;
|
||||
|
||||
Vehicle current = veh.Spawn();
|
||||
TuningManager.ApplyTuningToServerVehicle(veh);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
ReallifeGamemode.Server/Managers/PositionManager.cs
Normal file
41
ReallifeGamemode.Server/Managers/PositionManager.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class PositionManager : Script
|
||||
{
|
||||
public static List<DutyPoint> DutyPoints = new List<DutyPoint>();
|
||||
public static List<ColShape> DutyColShapes = new List<ColShape>();
|
||||
|
||||
[ServerEvent(Event.ResourceStart)]
|
||||
public void OnResourceStart()
|
||||
{
|
||||
DutyPoint dutyPointLSPD = new DutyPoint()
|
||||
{
|
||||
Position = new Vector3(458.24, -990.86, 30.68),
|
||||
FactionId = 1
|
||||
};
|
||||
|
||||
DutyPoints.Add(dutyPointLSPD);
|
||||
|
||||
foreach (DutyPoint d in DutyPoints)
|
||||
{
|
||||
NAPI.Marker.CreateMarker(1, new Vector3(d.Position.X, d.Position.Y, d.Position.Z - 2), new Vector3(d.Position.X, d.Position.Y, d.Position.Z + 1),
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DutyPoint
|
||||
{
|
||||
public Vector3 Position { get; set; }
|
||||
public int FactionId { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
175
ReallifeGamemode.Server/Managers/SaveManager.cs
Normal file
175
ReallifeGamemode.Server/Managers/SaveManager.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Business;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using reallife_gamemode.Server.Saves;
|
||||
using System;
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class SaveManager : Script
|
||||
{
|
||||
[RemoteEvent("OnSaveBlipData")]
|
||||
public static void OnSaveBlipData(Client player, string blipSprite, string blipName, string blipScale, string blipColor,
|
||||
string blipAlpha, string blipDrawDistance, string blipShortRange, string blipRotation, string blipDimension)
|
||||
{
|
||||
float x = player.Position.X;
|
||||
float y = player.Position.Y;
|
||||
float z = player.Position.Z;
|
||||
short sprite = short.Parse(blipSprite);
|
||||
string name = blipName;
|
||||
float scale = float.Parse(blipScale);
|
||||
byte color = Convert.ToByte(blipColor);
|
||||
byte alpha = Convert.ToByte(blipAlpha);
|
||||
float drawDistance = float.Parse(blipDrawDistance);
|
||||
bool shortRange = bool.Parse(blipShortRange);
|
||||
float rotation = float.Parse(blipRotation);
|
||||
byte dimension = Convert.ToByte(blipDimension);
|
||||
|
||||
NAPI.Blip.CreateBlip(uint.Parse(blipSprite), new Vector3(x,y,z), scale, color, name, alpha, drawDistance, shortRange, short.Parse(blipRotation), dimension);
|
||||
|
||||
using (var saveData = new DatabaseContext())
|
||||
{
|
||||
var dataSet = new SavedBlip
|
||||
{
|
||||
Sprite = sprite,
|
||||
PositionX = x,
|
||||
PositionY = y,
|
||||
PositionZ = z,
|
||||
Name = blipName,
|
||||
Scale = scale,
|
||||
Color = color,
|
||||
Alpha = alpha,
|
||||
DrawDistance = drawDistance,
|
||||
ShortRange = shortRange,
|
||||
Rotation = rotation,
|
||||
Dimension = dimension,
|
||||
Active = true
|
||||
};
|
||||
saveData.Blips.Add(dataSet);
|
||||
saveData.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public static Vehicle SaveVehicleData(Vehicle veh, VehicleHash vehicleModel, Vector3 vehiclePosition, float vehicleHeading,
|
||||
string vehicleNumberPlate, int vehiclePrimaryColor, int vehicleSecondaryColor, bool vehicleLocked)
|
||||
{
|
||||
using (var saveData = new DatabaseContext())
|
||||
{
|
||||
var dataSet = new SavedVehicle
|
||||
{
|
||||
Model = vehicleModel,
|
||||
PositionX = vehiclePosition.X,
|
||||
PositionY = vehiclePosition.Y,
|
||||
PositionZ = vehiclePosition.Z,
|
||||
Heading = vehicleHeading,
|
||||
NumberPlate = vehicleNumberPlate,
|
||||
PrimaryColor = vehiclePrimaryColor,
|
||||
SecondaryColor = vehicleSecondaryColor,
|
||||
Locked = vehicleLocked,
|
||||
Active = true
|
||||
};
|
||||
saveData.Vehicles.Add(dataSet);
|
||||
saveData.SaveChanges();
|
||||
|
||||
return dataSet.Spawn(veh);
|
||||
}
|
||||
}
|
||||
public static Vehicle SaveFactionVehicleData(Vehicle veh, VehicleHash vehicleModel, Vector3 vehiclePosition, float vehicleHeading,
|
||||
string vehicleNumberPlate, int vehiclePrimaryColor, int vehicleSecondaryColor, bool vehicleLocked, bool vehicleEngine, int? factionId)
|
||||
{
|
||||
using (var saveData = new DatabaseContext())
|
||||
{
|
||||
var dataSet = new FactionVehicle
|
||||
{
|
||||
Model = vehicleModel,
|
||||
FactionId = factionId,
|
||||
PositionX = vehiclePosition.X,
|
||||
PositionY = vehiclePosition.Y,
|
||||
PositionZ = vehiclePosition.Z,
|
||||
Heading = vehicleHeading,
|
||||
NumberPlate = vehicleNumberPlate,
|
||||
PrimaryColor = vehiclePrimaryColor,
|
||||
SecondaryColor = vehicleSecondaryColor,
|
||||
Locked = vehicleLocked,
|
||||
Active = true
|
||||
};
|
||||
saveData.FactionVehicles.Add(dataSet);
|
||||
saveData.SaveChanges();
|
||||
|
||||
return dataSet.Spawn(veh);
|
||||
}
|
||||
}
|
||||
public static Vehicle SaveShopVehicleData(Vehicle veh, VehicleHash vehicleModel, string vehicleModelName, Vector3 vehiclePosition, float vehicleHeading,
|
||||
string vehicleNumberPlate, int vehiclePrimaryColor, int vehicleSecondaryColor, BusinessBase business, int price)
|
||||
{
|
||||
using (var saveData = new DatabaseContext())
|
||||
{
|
||||
var dataSet = new ShopVehicle
|
||||
{
|
||||
Model = vehicleModel,
|
||||
PositionX = vehiclePosition.X,
|
||||
PositionY = vehiclePosition.Y,
|
||||
PositionZ = vehiclePosition.Z,
|
||||
Heading = vehicleHeading,
|
||||
NumberPlate = vehicleNumberPlate,
|
||||
PrimaryColor = vehiclePrimaryColor,
|
||||
SecondaryColor = vehicleSecondaryColor,
|
||||
Active = true,
|
||||
BusinessId = business.Id,
|
||||
Price = price
|
||||
};
|
||||
saveData.ShopVehicles.Add(dataSet);
|
||||
saveData.SaveChanges();
|
||||
|
||||
return dataSet.Spawn(veh);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveGotoPoint(Client player, string description)
|
||||
{
|
||||
using (var saveData = new DatabaseContext())
|
||||
{
|
||||
var dataSet = new Entities.GotoPoint
|
||||
{
|
||||
Description = description,
|
||||
X = player.Position.X,
|
||||
Y = player.Position.Y,
|
||||
Z = player.Position.Z,
|
||||
Active = true
|
||||
};
|
||||
saveData.GotoPoints.Add(dataSet);
|
||||
saveData.SaveChanges();
|
||||
}
|
||||
}
|
||||
public static void SaveAllOnSave()
|
||||
{
|
||||
// Alle Fahrzeuge
|
||||
using (var saveAll = new DatabaseContext())
|
||||
{
|
||||
foreach(ServerVehicle veh in saveAll.ServerVehicles)
|
||||
{
|
||||
Vehicle v = VehicleManager.GetVehicleFromServerVehicle(veh);
|
||||
|
||||
veh.PositionX = v.Position.X;
|
||||
veh.PositionY = v.Position.Y;
|
||||
veh.PositionZ = v.Position.Z;
|
||||
veh.Heading = v.Heading;
|
||||
}
|
||||
|
||||
//Alle Spieler
|
||||
foreach (Client player in NAPI.Pools.GetAllPlayers())
|
||||
{
|
||||
Vector3 pos = player.Position;
|
||||
User user = player.GetUser(saveAll);
|
||||
user.PositionX = pos.X;
|
||||
user.PositionY = pos.Y;
|
||||
user.PositionZ = pos.Z;
|
||||
}
|
||||
|
||||
saveAll.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
35
ReallifeGamemode.Server/Managers/TimeManager.cs
Normal file
35
ReallifeGamemode.Server/Managers/TimeManager.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using GTANetworkAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Timers;
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class TimeManager
|
||||
{
|
||||
private static Timer realTimeTimer;
|
||||
|
||||
public static void StartTimeManager()
|
||||
{
|
||||
if(realTimeTimer == null)
|
||||
{
|
||||
realTimeTimer = new Timer(1000);
|
||||
realTimeTimer.Elapsed += SetTime;
|
||||
}
|
||||
|
||||
realTimeTimer.Start();
|
||||
}
|
||||
|
||||
public static void PauseTimeManager()
|
||||
{
|
||||
realTimeTimer.Stop();
|
||||
}
|
||||
|
||||
private static void SetTime(object sender, ElapsedEventArgs args)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
NAPI.World.SetTime(now.Hour, now.Minute, now.Second);
|
||||
}
|
||||
}
|
||||
}
|
||||
150
ReallifeGamemode.Server/Managers/TuningManager.cs
Normal file
150
ReallifeGamemode.Server/Managers/TuningManager.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
class TuningManager : Script
|
||||
{
|
||||
private static List<ColShape> tuningGarages = new List<ColShape>();
|
||||
|
||||
/// <summary>
|
||||
/// Fügt eine Tuning-Garage zum Spiel hinzu
|
||||
/// </summary>
|
||||
/// <param name="pos">Die Position der Garage</param>
|
||||
public static void AddTuningGarage(Vector3 pos)
|
||||
{
|
||||
ColShape colShape = NAPI.ColShape.CreateSphereColShape(pos, 5, 0);
|
||||
|
||||
colShape.OnEntityEnterColShape += (cs, c) =>
|
||||
{
|
||||
if(c.IsInVehicle)
|
||||
{
|
||||
Vehicle v = c.Vehicle;
|
||||
if(v.GetServerVehicle() is FactionVehicle fV && fV.GetFaction().StateOwned)
|
||||
{
|
||||
return;
|
||||
}
|
||||
c.TriggerEvent("showTuningInfo");
|
||||
}
|
||||
};
|
||||
|
||||
colShape.OnEntityExitColShape += (cs, c) =>
|
||||
{
|
||||
c.TriggerEvent("hideTuningInfo", true);
|
||||
};
|
||||
|
||||
tuningGarages.Add(colShape);
|
||||
}
|
||||
|
||||
public static void ApplyTuningToServerVehicle(ServerVehicle sVeh)
|
||||
{
|
||||
Vehicle veh = VehicleManager.GetVehicleFromServerVehicle(sVeh);
|
||||
if (veh == null) return;
|
||||
|
||||
|
||||
veh.SetSharedData("mod18", false);
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach(VehicleMod vMod in dbContext.VehicleMods.ToList().FindAll(vM => vM.ServerVehicleId == sVeh.Id))
|
||||
{
|
||||
if(vMod.Slot == 18)
|
||||
{
|
||||
veh.SetSharedData("mod" + vMod.Slot, true);
|
||||
}
|
||||
else if(vMod.Slot == 22)
|
||||
{
|
||||
int color = vMod.ModId - 2;
|
||||
if (vMod.ModId == 0) color = -1;
|
||||
if (vMod.ModId == 1) color = 13;
|
||||
veh.SetSharedData("headlightColor", color);
|
||||
}
|
||||
else veh.SetMod(vMod.Slot, vMod.ModId - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("startPlayerTuning")]
|
||||
public void StartPlayerTuning(Client player)
|
||||
{
|
||||
if (!player.IsInVehicle) return;
|
||||
|
||||
player.TriggerEvent("showTuningMenu");
|
||||
}
|
||||
|
||||
[RemoteEvent("repairVehicle")]
|
||||
public void RepairVehicle(Client player)
|
||||
{
|
||||
if (!player.IsInVehicle) return;
|
||||
player.Vehicle.Repair();
|
||||
}
|
||||
|
||||
[RemoteEvent("setVehicleMod")]
|
||||
public void SetVehicleMod(Client player, int slot, int index)
|
||||
{
|
||||
Vehicle pV = player.Vehicle;
|
||||
if (index == 0) index--;
|
||||
|
||||
if(slot != 18)
|
||||
{
|
||||
if(slot == 22)
|
||||
{
|
||||
int color = index - 2;
|
||||
if (index == 0) color = -1;
|
||||
if (index == 1) color = 13;
|
||||
pV.SetSharedData("headlightColor", color);
|
||||
}
|
||||
else
|
||||
{
|
||||
pV.SetMod(slot, index - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool newVal = index == -1 ? false : true;
|
||||
pV.SetSharedData("mod" + slot, newVal);
|
||||
NAPI.ClientEvent.TriggerClientEventForAll("vehicleToggleMod", pV, slot, newVal);
|
||||
}
|
||||
|
||||
ServerVehicle sV = player.Vehicle.GetServerVehicle();
|
||||
if (sV == null) return;
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
VehicleMod vMod = dbContext.VehicleMods.FirstOrDefault(m => m.ServerVehicleId == sV.Id && m.Slot == slot);
|
||||
if(vMod == null && index != -1)
|
||||
{
|
||||
vMod = new VehicleMod
|
||||
{
|
||||
ServerVehicleId = sV.Id,
|
||||
Slot = slot,
|
||||
ModId = index
|
||||
};
|
||||
dbContext.VehicleMods.Add(vMod);
|
||||
}
|
||||
else if(vMod != null && index == -1)
|
||||
{
|
||||
dbContext.VehicleMods.Remove(vMod);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vMod == null)
|
||||
{
|
||||
vMod = new VehicleMod
|
||||
{
|
||||
ServerVehicleId = sV.Id,
|
||||
Slot = slot
|
||||
};
|
||||
dbContext.VehicleMods.Add(vMod);
|
||||
}
|
||||
vMod.ModId = index;
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
144
ReallifeGamemode.Server/Managers/VehicleManager.cs
Normal file
144
ReallifeGamemode.Server/Managers/VehicleManager.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class VehicleManager
|
||||
{
|
||||
private static readonly List<string> _enabledMods = new List<string>()
|
||||
{
|
||||
"models",
|
||||
"polamggtr",
|
||||
"impaler3",
|
||||
"monster4",
|
||||
"monster5",
|
||||
"slamvan6",
|
||||
"issi6",
|
||||
"cerberus2",
|
||||
"cerberus3",
|
||||
"deathbike2",
|
||||
"dominator6",
|
||||
"deathbike3",
|
||||
"impaler4",
|
||||
"slamvan4",
|
||||
"slamvan5",
|
||||
"brutus",
|
||||
"brutus2",
|
||||
"brutus3",
|
||||
"deathbike",
|
||||
"dominator4",
|
||||
"dominator5",
|
||||
"bruiser",
|
||||
"bruiser2",
|
||||
"bruiser3",
|
||||
"rcbandito",
|
||||
"italigto",
|
||||
"cerberus",
|
||||
"impaler2",
|
||||
"monster3",
|
||||
"tulip",
|
||||
"scarab",
|
||||
"scarab2",
|
||||
"scarab3",
|
||||
"issi4",
|
||||
"issi5",
|
||||
"clique",
|
||||
"deveste",
|
||||
"vamos",
|
||||
"imperator",
|
||||
"imperator2",
|
||||
"imperator3",
|
||||
"toros",
|
||||
"deviant",
|
||||
"schlagen",
|
||||
"impaler",
|
||||
"zr380",
|
||||
"zr3802",
|
||||
"zr3803",
|
||||
"flashgt",
|
||||
"gb200",
|
||||
"dominator3"
|
||||
};
|
||||
|
||||
private static Dictionary<int, NetHandle> _serverVehicles = new Dictionary<int, NetHandle>();
|
||||
|
||||
public static void AddVehicle(ServerVehicle serverVehicle, Vehicle vehicle)
|
||||
{
|
||||
if(_serverVehicles.ContainsKey(serverVehicle.Id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_serverVehicles.ContainsValue(vehicle.Handle))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_serverVehicles[serverVehicle.Id] = vehicle.Handle;
|
||||
}
|
||||
internal static void DeleteVehicle(Vehicle veh)
|
||||
{
|
||||
ServerVehicle sVeh;
|
||||
if ((sVeh = GetServerVehicleFromVehicle(veh)) != null)
|
||||
{
|
||||
_serverVehicles.Remove(sVeh.Id);
|
||||
}
|
||||
|
||||
veh.Delete();
|
||||
}
|
||||
|
||||
public static Vehicle GetVehicleFromHandle(NetHandle handle)
|
||||
{
|
||||
return NAPI.Pools.GetAllVehicles().Find(v => v.Handle == handle);
|
||||
}
|
||||
|
||||
public static Vehicle GetVehicleFromId(int id)
|
||||
{
|
||||
return NAPI.Pools.GetAllVehicles().Find(v => v.Handle.Value == id);
|
||||
}
|
||||
|
||||
public static Vehicle GetVehicleFromServerVehicle(ServerVehicle serverVehicle)
|
||||
{
|
||||
if(!_serverVehicles.ContainsKey(serverVehicle.Id))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return GetVehicleFromHandle(_serverVehicles[serverVehicle.Id]);
|
||||
}
|
||||
|
||||
public static ServerVehicle GetServerVehicleFromVehicle(Vehicle veh)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach(KeyValuePair<int, NetHandle> pair in _serverVehicles)
|
||||
{
|
||||
if (pair.Value == veh.Handle)
|
||||
{
|
||||
return dbContext.ServerVehicles.Find(pair.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool IsValidHash(uint hash)
|
||||
{
|
||||
foreach(VehicleHash vh in Enum.GetValues(typeof(VehicleHash)))
|
||||
{
|
||||
if ((uint)vh == hash) return true;
|
||||
}
|
||||
|
||||
foreach(string mod in _enabledMods)
|
||||
{
|
||||
if (NAPI.Util.GetHashKey(mod) == hash) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
103
ReallifeGamemode.Server/Model/DatabaseContext.cs
Normal file
103
ReallifeGamemode.Server/Model/DatabaseContext.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - DatabaseContext.cs
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Models
|
||||
{
|
||||
public partial class DatabaseContext : DbContext
|
||||
{
|
||||
public DatabaseContext(DbContextOptions<DatabaseContext> options) :base (options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DatabaseContext()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
optionsBuilder.UseMySql("Host=localhost;Port=3306;Database=gtav-devdb;Username=gtav-dev;Password=Test123");
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<Server.Entities.BusinessBankAccount>()
|
||||
.HasIndex(b => b.BusinessId)
|
||||
.IsUnique(true);
|
||||
|
||||
modelBuilder.Entity<Server.Entities.User>()
|
||||
.HasIndex(u => u.BusinessId)
|
||||
.IsUnique(true);
|
||||
|
||||
modelBuilder.Entity<Server.Entities.ServerVehicle>()
|
||||
.Property(sv => sv.Active)
|
||||
.HasDefaultValue(true);
|
||||
|
||||
modelBuilder.Entity<Server.Entities.VehicleMod>()
|
||||
.HasIndex(vM => new { vM.ServerVehicleId, vM.Slot }).IsUnique();
|
||||
}
|
||||
|
||||
//User
|
||||
public DbSet<Server.Entities.Ban> Bans { get; set; }
|
||||
public DbSet<Server.Entities.Character> Characters { get; set; }
|
||||
public DbSet<Server.Entities.CharacterCloth> CharacterClothes { get; set; }
|
||||
public DbSet<Server.Entities.DutyCloth> DutyClothes { get; set; }
|
||||
public DbSet<Server.Entities.ClothCombination> ClothCombinations { get; set; }
|
||||
public DbSet<Server.Entities.User> Users { get; set; }
|
||||
public DbSet<Server.Entities.UserVehicle> UserVehicles { get; set; }
|
||||
public DbSet<Server.Entities.UserBankAccount> UserBankAccounts { get; set; }
|
||||
|
||||
|
||||
//Inventar
|
||||
public DbSet<Server.Entities.UserItem> UserItems { get; set; }
|
||||
|
||||
//Faction
|
||||
public DbSet<Server.Entities.Faction> Factions { get; set; }
|
||||
public DbSet<Server.Entities.FactionBankAccount> FactionBankAccounts { get; set; }
|
||||
public DbSet<Server.Entities.FactionRank> FactionRanks { get; set; }
|
||||
public DbSet<Server.Entities.FactionVehicle> FactionVehicles { get; set; }
|
||||
|
||||
//Shops
|
||||
|
||||
//Logs
|
||||
//public DbSet<Server.Logs.Ban> BanLogs { get; set; }
|
||||
public DbSet<Server.Logs.BankAccountTransactionHistory> BankAccountTransactionLogs { get; set; }
|
||||
public DbSet<Server.Logs.Death> DeathLogs { get; set; }
|
||||
|
||||
//Saves
|
||||
public DbSet<Server.Saves.SavedBlip> Blips { get; set; }
|
||||
public DbSet<Server.Entities.Door> Doors { get; set; }
|
||||
public DbSet<Server.Entities.GotoPoint> GotoPoints { get; set; }
|
||||
public DbSet<Server.Saves.SavedMarker> Markers { get; set; }
|
||||
public DbSet<Server.Saves.SavedPed> Peds { get; set; }
|
||||
public DbSet<Server.Saves.SavedPickup> Pickups { get; set; }
|
||||
public DbSet<Server.Saves.SavedTextLabel> TextLabels { get; set; }
|
||||
public DbSet<Server.Saves.SavedVehicle> Vehicles { get; set; }
|
||||
public DbSet<Server.Entities.ShopVehicle> ShopVehicles { get; set; }
|
||||
|
||||
// Business
|
||||
public DbSet<Server.Entities.BusinessBankAccount> BusinessBankAccounts { get; set; }
|
||||
|
||||
// Control Panel
|
||||
public DbSet<Server.Entities.News> News { get; set; }
|
||||
|
||||
// Server Vehicles
|
||||
public DbSet<Server.Entities.ServerVehicle> ServerVehicles { get; set; }
|
||||
public DbSet<Server.Entities.VehicleMod> VehicleMods { get; set; }
|
||||
|
||||
// Whitelist
|
||||
public DbSet<Server.Entities.Whitelist> WhitelistEntries { get; set; }
|
||||
|
||||
// Interiors
|
||||
public DbSet<Server.Entities.Interior> Interiors { get; set; }
|
||||
}
|
||||
}
|
||||
9
ReallifeGamemode.Server/Properties/launchSettings.json
Normal file
9
ReallifeGamemode.Server/Properties/launchSettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"profiles": {
|
||||
"ReallifeGamemode.Server": {
|
||||
"commandName": "Executable",
|
||||
"executablePath": "S:\\RAGEMP\\server-files\\server.exe",
|
||||
"workingDirectory": "S:\\RAGEMP\\server-files\\"
|
||||
}
|
||||
}
|
||||
}
|
||||
37
ReallifeGamemode.Server/ReallifeGamemode.Server.csproj
Normal file
37
ReallifeGamemode.Server/ReallifeGamemode.Server.csproj
Normal file
@@ -0,0 +1,37 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<RootNamespace>ReallifeGamemode</RootNamespace>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="meta.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.4" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(ConfigurationName)' != 'ServerBuild'">
|
||||
<Reference Include="Bootstrapper">
|
||||
<HintPath>..\..\bridge\runtime\Bootstrapper.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(ConfigurationName)' == 'ServerBuild'">
|
||||
<Reference Include="Bootstrapper">
|
||||
<HintPath>..\Bootstrapper.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(ConfigurationName)' != 'ServerBuild'">
|
||||
<Exec Command="powershell.exe .\Scripts\moveItems.ps1 -outDir $(OutDir) -outFile $(TargetFileName)" />
|
||||
</Target>
|
||||
</Project>
|
||||
38
ReallifeGamemode.Server/Saves/SavedBlip.cs
Normal file
38
ReallifeGamemode.Server/Saves/SavedBlip.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Saves SavedBlip.cs
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Saves
|
||||
{
|
||||
public class SavedBlip
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public short Sprite { get; set; }
|
||||
[Required]
|
||||
public float PositionX { get; set; }
|
||||
[Required]
|
||||
public float PositionY { get; set; }
|
||||
[Required]
|
||||
public float PositionZ { get; set; }
|
||||
public string Name { get; set; }
|
||||
public float Scale { get; set; }
|
||||
public byte Color { get; set; }
|
||||
public byte Alpha { get; set; }
|
||||
public float DrawDistance { get; set; }
|
||||
public bool ShortRange { get; set; }
|
||||
public float Rotation { get; set; }
|
||||
public byte Dimension { get; set; }
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
}
|
||||
39
ReallifeGamemode.Server/Saves/SavedMarker.cs
Normal file
39
ReallifeGamemode.Server/Saves/SavedMarker.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Saves SavedMarker.cs
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Saves
|
||||
{
|
||||
public class SavedMarker
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
public byte Type { get; set; }
|
||||
public float PositionX { get; set; }
|
||||
public float PositionY { get; set; }
|
||||
public float PositionZ { get; set; }
|
||||
public float Scale { get; set; }
|
||||
public float DirectionX { get; set; }
|
||||
public float DirectionY { get; set; }
|
||||
public float DirectionZ { get; set; }
|
||||
public float RotationX { get; set; }
|
||||
public float RotationY { get; set; }
|
||||
public float RotationZ { get; set; }
|
||||
public byte ColorR { get; set; }
|
||||
public byte ColorG { get; set; }
|
||||
public byte ColorB { get; set; }
|
||||
public byte ColorA { get; set; }
|
||||
public bool Visible { get; set; }
|
||||
public byte Dimension { get; set; }
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
}
|
||||
28
ReallifeGamemode.Server/Saves/SavedPed.cs
Normal file
28
ReallifeGamemode.Server/Saves/SavedPed.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Saves SavedPed.cs
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Saves
|
||||
{
|
||||
public class SavedPed
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
public string HashModel { get; set; }
|
||||
public float PositionX { get; set; }
|
||||
public float PositionY { get; set; }
|
||||
public float PositionZ { get; set; }
|
||||
public float Heading { get; set; }
|
||||
public byte Dimension { get; set; }
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
}
|
||||
32
ReallifeGamemode.Server/Saves/SavedPickup.cs
Normal file
32
ReallifeGamemode.Server/Saves/SavedPickup.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Saves SavedPickup.cs
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Saves
|
||||
{
|
||||
public class SavedPickup
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
[StringLength(128)]
|
||||
public float PositionX { get; set; }
|
||||
public float PositionY { get; set; }
|
||||
public float PositionZ { get; set; }
|
||||
public float RotationX { get; set; }
|
||||
public float RotationY { get; set; }
|
||||
public float RotationZ { get; set; }
|
||||
public bool Vehicle { get; set; }
|
||||
public int RespawnTime { get; set; }
|
||||
public byte Dimension { get; set; }
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
}
|
||||
38
ReallifeGamemode.Server/Saves/SavedTextLabel.cs
Normal file
38
ReallifeGamemode.Server/Saves/SavedTextLabel.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Saves SavedTextLabel.cs
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Saves
|
||||
{
|
||||
public class SavedTextLabel
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Text { get; set; }
|
||||
[Required]
|
||||
public float PositionX { get; set; }
|
||||
[Required]
|
||||
public float PositionY { get; set; }
|
||||
[Required]
|
||||
public float PositionZ { get; set; }
|
||||
public bool LOS { get; set; }
|
||||
public byte Font { get; set; }
|
||||
public float DrawDistance { get; set; }
|
||||
public byte ColorR { get; set; }
|
||||
public byte ColorG { get; set; }
|
||||
public byte ColorB { get; set; }
|
||||
public byte ColorA { get; set; }
|
||||
public byte Dimension { get; set; }
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
}
|
||||
24
ReallifeGamemode.Server/Saves/SavedVehicle.cs
Normal file
24
ReallifeGamemode.Server/Saves/SavedVehicle.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Saves SavedVehicle.cs
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Saves
|
||||
{
|
||||
public class SavedVehicle : ServerVehicle
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return "Gespeichertes Fahrzeug";
|
||||
}
|
||||
}
|
||||
}
|
||||
38
ReallifeGamemode.Server/Scripts/moveItems.ps1
Normal file
38
ReallifeGamemode.Server/Scripts/moveItems.ps1
Normal file
@@ -0,0 +1,38 @@
|
||||
# Verschiebt die Dateien aus dem Output-Verzeichnis in den resources Ordner
|
||||
|
||||
param (
|
||||
[string]$outDir,
|
||||
[string]$outFile
|
||||
)
|
||||
|
||||
$rootPath = "$PSScriptRoot\.."
|
||||
|
||||
$outputPath = "$rootPath\$outDir"
|
||||
|
||||
$bridgePath = "$rootPath\..\..\bridge\"
|
||||
|
||||
$resourcePath = "$bridgePath\resources\reallife-gamemode"
|
||||
$runtimePath = "$bridgePath\runtime"
|
||||
|
||||
# Pruefen, ob Output-Pfad existiert
|
||||
if(!(Test-Path $outputPath))
|
||||
{
|
||||
$absoluteOutputPath = Resolve-Path $outputPath
|
||||
Write-Host "Output Folder ($absoluteOutputPath) does not exist."
|
||||
Exit 0
|
||||
}
|
||||
|
||||
# Pruefen, ob resources-Pfad existiert
|
||||
# Wenn NEIN => erstellen
|
||||
if(!(Test-Path $resourcePath))
|
||||
{
|
||||
Write-Host "Creating 'copsandrobbers' resources directory"
|
||||
New-Item -ItemType Directory -Path $resourcePath | Out-Null
|
||||
}
|
||||
|
||||
# Gamemode und Meta-Datei verschieben
|
||||
Copy-Item "$outputPath\$outFile" "$resourcePath\" -Force
|
||||
Copy-Item "$outputPath\meta.xml" "$resourcePath\" -Force
|
||||
|
||||
# Abhaengige DLLs in runtime Ordner verschieben
|
||||
Copy-Item "$outputPath\*.dll" "$runtimePath\" -Exclude "CopsAndRobbers.Server.dll"
|
||||
82
ReallifeGamemode.Server/Services/ChatService.cs
Normal file
82
ReallifeGamemode.Server/Services/ChatService.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Chat Service (ChatService.cs)
|
||||
* @author hydrant, xSprite
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Services
|
||||
{
|
||||
class ChatService
|
||||
{
|
||||
public static void NotAuthorized(Client player)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Du kannst diesen Befehl nicht ausführen.");
|
||||
}
|
||||
|
||||
public static void PlayerNotFound(Client player)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Der Spieler wurde nicht gefunden.");
|
||||
}
|
||||
|
||||
public static void PlayerNotLoggedIn(Client player)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Du bist nicht eingeloggt.");
|
||||
}
|
||||
public static void ErrorMsg(Client player)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Die Aktion wurde nicht ausgeführt.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sendet eine Nachricht an eine Liste von Fraktionen
|
||||
/// </summary>
|
||||
/// <param name="message">Die Nachricht, die gesendet werden soll</param>
|
||||
/// <param name="factions">Die Liste an Fraktionen, die diese Nachricht bekommen sollen</param>
|
||||
public static void BroadcastFaction(string message, List<Faction> factions)
|
||||
{
|
||||
foreach (Client c in NAPI.Pools.GetAllPlayers())
|
||||
{
|
||||
Faction f = c.GetUser()?.GetFaction();
|
||||
if (f != null)
|
||||
{
|
||||
if (factions.Find(fT => fT.Id == f.Id) != null)
|
||||
{
|
||||
c.SendChatMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sendet eine Nachricht an eine Fraktion
|
||||
/// </summary>
|
||||
/// <param name="message">Die Nachricht, die gesendet werden soll</param>
|
||||
/// <param name="f">Die Fraktion, die diese Nachricht bekommen soll</param>
|
||||
public static void BroadcastFaction(string message, Faction f)
|
||||
{
|
||||
BroadcastFaction(message, new List<Faction>() { f });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sendet eine Nachricht an alle Spieler mit einem bestimmten Admin Level
|
||||
/// </summary>
|
||||
/// <param name="message">Die Nachricht, die gesendet werden soll</param>
|
||||
/// <param name="minLevel">Das mindest Admin Level, das für das Erhalten dieser Nachricht benötigt wird</param>
|
||||
public static void BroadcastAdmin(string message, AdminLevel minLevel)
|
||||
{
|
||||
NAPI.Pools.GetAllPlayers().ForEach(p =>
|
||||
{
|
||||
if(p.GetUser()?.IsAdmin(minLevel) ?? false)
|
||||
{
|
||||
p.SendChatMessage(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
44
ReallifeGamemode.Server/Services/ClientService.cs
Normal file
44
ReallifeGamemode.Server/Services/ClientService.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using GTANetworkAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Client Service (ClientService.cs)
|
||||
* @author hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Services
|
||||
{
|
||||
class ClientService
|
||||
{
|
||||
/// <summary>
|
||||
/// Gibt einen Client anhand seines Namens oder der ID zurück
|
||||
/// </summary>
|
||||
/// <param name="nameOrId">Die ID oder der Name, nach dem gesucht werden soll</param>
|
||||
/// <returns></returns>
|
||||
public static Client GetClientByNameOrId(string nameOrId)
|
||||
{
|
||||
Client toReturn = null;
|
||||
nameOrId = nameOrId.ToLower();
|
||||
|
||||
List<Client> playerList = NAPI.Pools.GetAllPlayers();
|
||||
|
||||
if(int.TryParse(nameOrId, out int id))
|
||||
{
|
||||
toReturn = playerList.Find(p => p.Handle.Value == id);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
toReturn = playerList.Find(p => p.Name.ToLower() == nameOrId);
|
||||
|
||||
if(toReturn == null)
|
||||
{
|
||||
toReturn = playerList.Find(p => p.Name.ToLower().StartsWith(nameOrId));
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
ReallifeGamemode.Server/Util/AdminLevel.cs
Normal file
23
ReallifeGamemode.Server/Util/AdminLevel.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Admin Levels (AdminLevel.cs)
|
||||
* @author VegaZ, hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Util
|
||||
{
|
||||
public enum AdminLevel : int
|
||||
{
|
||||
PLAYER = 0,
|
||||
SUPPORTER = 1,
|
||||
ADMIN = 2,
|
||||
ADMIN2 = 3,
|
||||
ADMIN3 = 4,
|
||||
HEADADMIN = 1337,
|
||||
PROJEKTLEITUNG = 1338
|
||||
}
|
||||
}
|
||||
40
ReallifeGamemode.Server/Util/Converter.cs
Normal file
40
ReallifeGamemode.Server/Util/Converter.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using GTANetworkAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Util
|
||||
{
|
||||
public class Converter
|
||||
{
|
||||
public static Color HexToColor(string hexColor)
|
||||
{
|
||||
//Remove # if present
|
||||
if (hexColor.IndexOf('#') != -1)
|
||||
hexColor = hexColor.Replace("#", "");
|
||||
|
||||
int red = 0;
|
||||
int green = 0;
|
||||
int blue = 0;
|
||||
|
||||
if (hexColor.Length == 6)
|
||||
{
|
||||
//#RRGGBB
|
||||
red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
|
||||
green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
|
||||
blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
|
||||
}
|
||||
else if (hexColor.Length == 3)
|
||||
{
|
||||
//#RGB
|
||||
red = int.Parse(hexColor[0].ToString() + hexColor[0].ToString(), NumberStyles.AllowHexSpecifier);
|
||||
green = int.Parse(hexColor[1].ToString() + hexColor[1].ToString(), NumberStyles.AllowHexSpecifier);
|
||||
blue = int.Parse(hexColor[2].ToString() + hexColor[2].ToString(), NumberStyles.AllowHexSpecifier);
|
||||
}
|
||||
|
||||
Color returnColor = new Color(red, green, blue);
|
||||
return returnColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
ReallifeGamemode.Server/Util/DatabaseHelper.cs
Normal file
19
ReallifeGamemode.Server/Util/DatabaseHelper.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using System.Linq;
|
||||
|
||||
namespace reallife_gamemode.Server.Util
|
||||
{
|
||||
class DatabaseHelper
|
||||
{
|
||||
public static void InitDatabaseFirstTime()
|
||||
{
|
||||
NAPI.Util.ConsoleOutput("Initializing database...");
|
||||
using(var dbContext = new DatabaseContext())
|
||||
{
|
||||
dbContext.Users.FirstOrDefault();
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
ReallifeGamemode.Server/Util/FactionHelper.cs
Normal file
34
ReallifeGamemode.Server/Util/FactionHelper.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Models;
|
||||
|
||||
namespace reallife_gamemode.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)
|
||||
{
|
||||
if(faction.GetBankAccount(dbContext) == null)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput("Adding bank account for faction: " + faction.Name);
|
||||
FactionBankAccount factionBankAccount = new FactionBankAccount()
|
||||
{
|
||||
Balance = 0,
|
||||
Bic = "",
|
||||
Iban = "",
|
||||
FactionId = faction.Id,
|
||||
Active = true
|
||||
};
|
||||
dbContext.FactionBankAccounts.Add(factionBankAccount);
|
||||
}
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
ReallifeGamemode.Server/Util/FactionRankHelper.cs
Normal file
18
ReallifeGamemode.Server/Util/FactionRankHelper.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Util
|
||||
{
|
||||
class FactionRankHelper
|
||||
{
|
||||
public int FactionId { get; set; }
|
||||
public List<Rank> Ranks { get; set; }
|
||||
}
|
||||
|
||||
class Rank
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
11
ReallifeGamemode.Server/Util/IBankAccount.cs
Normal file
11
ReallifeGamemode.Server/Util/IBankAccount.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Util
|
||||
{
|
||||
public interface IBankAccount
|
||||
{
|
||||
int Balance { get; set; }
|
||||
}
|
||||
}
|
||||
11
ReallifeGamemode.Server/Util/IBankAccountOwner.cs
Normal file
11
ReallifeGamemode.Server/Util/IBankAccountOwner.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using reallife_gamemode.Server.Models;
|
||||
|
||||
namespace reallife_gamemode.Server.Util
|
||||
{
|
||||
public interface IBankAccountOwner
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
IBankAccount GetBankAccount(DatabaseContext databaseContext = null);
|
||||
}
|
||||
}
|
||||
20
ReallifeGamemode.Server/Util/ListPlayer.cs
Normal file
20
ReallifeGamemode.Server/Util/ListPlayer.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Util ListPlayer ListPlayer.cs
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Util
|
||||
{
|
||||
public class ListPlayer
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Ping { get; set; }
|
||||
}
|
||||
}
|
||||
40
ReallifeGamemode.Server/Util/SmoothThrottle.cs
Normal file
40
ReallifeGamemode.Server/Util/SmoothThrottle.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using GTANetworkAPI;
|
||||
|
||||
namespace reallife_gamemode.Server.Util
|
||||
{
|
||||
public class SmoothThrottleAntiReverse : Script
|
||||
{
|
||||
[ServerEvent(Event.PlayerExitVehicle)]
|
||||
public void SmoothThrottleExitEvent(Client player, Vehicle veh)
|
||||
{
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "SmoothThrottle_PlayerExitVehicle", veh);
|
||||
}
|
||||
|
||||
[ServerEvent(Event.PlayerEnterVehicle)]
|
||||
public void SmoothThrottleEnterEvent(Client player, Vehicle veh, sbyte seat)
|
||||
{
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "SmoothThrottle_PlayerEnterVehicle", veh, seat);
|
||||
}
|
||||
|
||||
//You can call these to change settings on player if you want.
|
||||
//Note that these are toggles, you only need to call them once.
|
||||
|
||||
//This disables/enables the smooth throttle
|
||||
public static void SetSmoothThrottle(Client player, bool turnedOn)
|
||||
{
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "SmoothThrottle_SetSmoothThrottle", turnedOn);
|
||||
}
|
||||
|
||||
//This disables/enables anti reverse
|
||||
public static void SetAntiReverse(Client player, bool turnedOn)
|
||||
{
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "SmoothThrottle_SetAntiReverse", turnedOn);
|
||||
}
|
||||
|
||||
//This disables/enables both
|
||||
public static void SetSmoothThrottleAntiReverse(Client player, bool turnedOn)
|
||||
{
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "SmoothThrottle_SetGlobal", turnedOn);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
ReallifeGamemode.Server/Util/TransactionResult.cs
Normal file
15
ReallifeGamemode.Server/Util/TransactionResult.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Util
|
||||
{
|
||||
public enum TransactionResult
|
||||
{
|
||||
SUCCESS,
|
||||
SENDER_NO_BANKACCOUNT,
|
||||
RECEIVER_NO_BANKACCOUNT,
|
||||
SENDER_NOT_ENOUGH_MONEY,
|
||||
NEGATIVE_MONEY_SENT
|
||||
}
|
||||
}
|
||||
452
ReallifeGamemode.Server/Util/VehicleSync.cs
Normal file
452
ReallifeGamemode.Server/Util/VehicleSync.cs
Normal file
@@ -0,0 +1,452 @@
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
//Disapproved by god himself
|
||||
|
||||
//Just use the API functions, you have nothing else to worry about
|
||||
|
||||
//Things to note
|
||||
//More things like vehicle mods will be added in the next version
|
||||
|
||||
/* API FUNCTIONS:
|
||||
public static void SetVehicleWindowState(Vehicle veh, WindowID window, WindowState state)
|
||||
public static WindowState GetVehicleWindowState(Vehicle veh, WindowID window)
|
||||
public static void SetVehicleWheelState(Vehicle veh, WheelID wheel, WheelState state)
|
||||
public static WheelState GetVehicleWheelState(Vehicle veh, WheelID wheel)
|
||||
public static void SetVehicleDirt(Vehicle veh, float dirt)
|
||||
public static float GetVehicleDirt(Vehicle veh)
|
||||
public static void SetDoorState(Vehicle veh, DoorID door, DoorState state)
|
||||
public static DoorState GetDoorState(Vehicle veh, DoorID door)
|
||||
public static void SetEngineState(Vehicle veh, bool status)
|
||||
public static bool GetEngineState(Vehicle veh)
|
||||
public static void SetLockStatus(Vehicle veh, bool status)
|
||||
public static bool GetLockState(Vehicle veh)
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Util
|
||||
{
|
||||
//Enums for ease of use
|
||||
public enum WindowID
|
||||
{
|
||||
WindowFrontRight,
|
||||
WindowFrontLeft,
|
||||
WindowRearRight,
|
||||
WindowRearLeft
|
||||
}
|
||||
|
||||
public enum WindowState
|
||||
{
|
||||
WindowFixed,
|
||||
WindowDown,
|
||||
WindowBroken
|
||||
}
|
||||
|
||||
public enum DoorID
|
||||
{
|
||||
DoorFrontLeft,
|
||||
DoorFrontRight,
|
||||
DoorRearLeft,
|
||||
DoorRearRight,
|
||||
DoorHood,
|
||||
DoorTrunk
|
||||
}
|
||||
|
||||
public enum DoorState
|
||||
{
|
||||
DoorClosed,
|
||||
DoorOpen,
|
||||
DoorBroken,
|
||||
}
|
||||
|
||||
public enum WheelID
|
||||
{
|
||||
Wheel0,
|
||||
Wheel1,
|
||||
Wheel2,
|
||||
Wheel3,
|
||||
Wheel4,
|
||||
Wheel5,
|
||||
Wheel6,
|
||||
Wheel7,
|
||||
Wheel8,
|
||||
Wheel9
|
||||
}
|
||||
|
||||
public enum WheelState
|
||||
{
|
||||
WheelFixed,
|
||||
WheelBurst,
|
||||
WheelOnRim,
|
||||
}
|
||||
|
||||
public class VehicleStreaming : Script
|
||||
{
|
||||
//This is the data object which will be synced to vehicles
|
||||
public class VehicleSyncData
|
||||
{
|
||||
//Used to bypass some streaming bugs
|
||||
public Vector3 Position { get; set; } = new Vector3();
|
||||
public Vector3 Rotation { get; set; } = new Vector3();
|
||||
|
||||
//Basics
|
||||
public float Dirt { get; set; } = 0.0f;
|
||||
public bool Locked { get; set; } = true;
|
||||
public bool Engine { get; set; } = false;
|
||||
|
||||
//(Not synced)
|
||||
public float BodyHealth { get; set; } = 1000.0f;
|
||||
public float EngineHealth { get; set; } = 1000.0f;
|
||||
|
||||
//Doors 0-7 (0 = closed, 1 = open, 2 = broken) (This uses enums so don't worry about it)
|
||||
public int[] Door { get; set; } = new int[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
//Windows (0 = up, 1 = down, 2 = smashed) (This uses enums so don't worry about it)
|
||||
public int[] Window { get; set; } = new int[4] { 0, 0, 0, 0 };
|
||||
|
||||
//Wheels 0-7, 45/47 (0 = fixed, 1 = flat, 2 = missing) (This uses enums so don't worry about it)
|
||||
public int[] Wheel { get; set; } = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
|
||||
//API functions for people to use
|
||||
public static void SetVehicleWindowState(Vehicle veh, WindowID window, WindowState state)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData)) //If data doesn't exist create a new one. This is the process for all API functions
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Window[(int)window] = (int)state;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleWindowStatus_Single", veh.Handle, (int)window, (int)state);
|
||||
}
|
||||
|
||||
public static WindowState GetVehicleWindowState(Vehicle veh, WindowID window)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
{
|
||||
data = new VehicleSyncData();
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
}
|
||||
return (WindowState)data.Window[(int)window];
|
||||
}
|
||||
|
||||
public static void SetVehicleWheelState(Vehicle veh, WheelID wheel, WheelState state)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Wheel[(int)wheel] = (int)state;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleWheelStatus_Single", veh.Handle, (int)wheel, (int)state);
|
||||
}
|
||||
|
||||
public static WheelState GetVehicleWheelState(Vehicle veh, WheelID wheel)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
{
|
||||
data = new VehicleSyncData();
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
}
|
||||
return (WheelState)data.Wheel[(int)wheel];
|
||||
}
|
||||
|
||||
public static void SetVehicleDirt(Vehicle veh, float dirt)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Dirt = dirt;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDirtLevel", veh.Handle, dirt);
|
||||
}
|
||||
|
||||
public static float GetVehicleDirt(Vehicle veh)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
{
|
||||
data = new VehicleSyncData();
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
}
|
||||
return data.Dirt;
|
||||
}
|
||||
|
||||
public static void SetDoorState(Vehicle veh, DoorID door, DoorState state)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Door[(int)door] = (int)state;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDoorStatus_Single", veh, (int)door, (int)state);
|
||||
}
|
||||
|
||||
public static DoorState GetDoorState(Vehicle veh, DoorID door)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
{
|
||||
data = new VehicleSyncData();
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
}
|
||||
return (DoorState)data.Door[(int)door];
|
||||
}
|
||||
|
||||
public static void SetEngineState(Vehicle veh, bool status)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Engine = status;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetEngineStatus", veh, status);
|
||||
}
|
||||
|
||||
public static bool GetEngineState(Vehicle veh)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
{
|
||||
data = new VehicleSyncData();
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
}
|
||||
return data.Engine;
|
||||
}
|
||||
|
||||
public static void SetLockStatus(Vehicle veh, bool status)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Locked = status;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetLockStatus", veh, status);
|
||||
NAPI.Pools.GetAllPlayers().ForEach(p =>
|
||||
{
|
||||
if(p.IsInVehicle && p.Vehicle.Handle == veh.Handle)
|
||||
{
|
||||
p.TriggerEvent("Vehicle_setLockStatus", status);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static bool GetLockState(Vehicle veh)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
{
|
||||
data = new VehicleSyncData();
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
}
|
||||
return data.Locked;
|
||||
}
|
||||
|
||||
//Used internally only but publicly available in case any of you need it
|
||||
public static VehicleSyncData GetVehicleSyncData(Vehicle veh)
|
||||
{
|
||||
if (veh != null)
|
||||
{
|
||||
if (NAPI.Entity.DoesEntityExist(veh))
|
||||
{
|
||||
if (NAPI.Data.HasEntitySharedData(veh.Handle, "VehicleSyncData"))
|
||||
{
|
||||
//API converts class objects to JObject so we have to change it back
|
||||
JObject obj = NAPI.Data.GetEntitySharedData(veh.Handle, "VehicleSyncData");
|
||||
return obj.ToObject<VehicleSyncData>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return default(VehicleSyncData); //null
|
||||
}
|
||||
|
||||
//Used internally only but publicly available in case any of you need it
|
||||
public static bool UpdateVehicleSyncData(Vehicle veh, VehicleSyncData data)
|
||||
{
|
||||
if (veh != null)
|
||||
{
|
||||
if (NAPI.Entity.DoesEntityExist(veh))
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
data.Position = veh.Position;
|
||||
data.Rotation = veh.Rotation;
|
||||
NAPI.Data.SetEntitySharedData(veh, "VehicleSyncData", data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//Called from the client to sync dirt level
|
||||
[RemoteEvent("VehStream_SetDirtLevel")]
|
||||
public void VehStreamSetDirtLevel(Client player, Vehicle veh, float dirt)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Dirt = dirt;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
|
||||
//Re-distribute the goods
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDirtLevel", veh.Handle, dirt);
|
||||
}
|
||||
|
||||
//Called from the client to sync door data
|
||||
[RemoteEvent("VehStream_SetDoorData")]
|
||||
public void VehStreamSetDoorData(Client player, Vehicle veh, int door1state, int door2state, int door3state, int door4state, int door5state, int door6state, int door7state, int door8state)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Door[0] = door1state;
|
||||
data.Door[1] = door2state;
|
||||
data.Door[2] = door3state;
|
||||
data.Door[3] = door4state;
|
||||
data.Door[4] = door5state;
|
||||
data.Door[5] = door6state;
|
||||
data.Door[6] = door7state;
|
||||
data.Door[7] = door8state;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
|
||||
//Re-distribute the goods
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDoorStatus", veh.Handle, door1state, door2state, door3state, door4state, door5state, door6state, door7state, door8state);
|
||||
}
|
||||
|
||||
//Called from the client to sync window data
|
||||
[RemoteEvent("VehStream_SetWindowData")]
|
||||
public void VehStreamSetWindowData(Client player, Vehicle veh, int window1state, int window2state, int window3state, int window4state)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Window[0] = window1state;
|
||||
data.Window[1] = window2state;
|
||||
data.Window[2] = window3state;
|
||||
data.Window[3] = window4state;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
|
||||
//Re-distribute the goods
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleWindowStatus", veh.Handle, window1state, window2state, window3state, window4state);
|
||||
}
|
||||
|
||||
//Called from the client to sync wheel data
|
||||
[RemoteEvent("VehStream_SetWheelData")]
|
||||
public void VehStreamSetWheelData(Client player, Vehicle veh, int wheel1state, int wheel2state, int wheel3state, int wheel4state, int wheel5state, int wheel6state, int wheel7state, int wheel8state, int wheel9state, int wheel10state)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Wheel[0] = wheel1state;
|
||||
data.Wheel[1] = wheel2state;
|
||||
data.Wheel[2] = wheel3state;
|
||||
data.Wheel[3] = wheel4state;
|
||||
data.Wheel[4] = wheel5state;
|
||||
data.Wheel[5] = wheel6state;
|
||||
data.Wheel[6] = wheel7state;
|
||||
data.Wheel[7] = wheel8state;
|
||||
data.Wheel[8] = wheel9state;
|
||||
data.Wheel[9] = wheel10state;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
|
||||
//Re-distribute the goods
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleWheelStatus", veh.Handle, wheel1state, wheel2state, wheel3state, wheel4state, wheel5state, wheel6state, wheel7state, wheel8state, wheel9state, wheel10state);
|
||||
}
|
||||
|
||||
//Other events
|
||||
[ServerEvent(Event.PlayerEnterVehicleAttempt)]
|
||||
public void VehStreamEnterAttempt(Client player, Vehicle veh, sbyte seat)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "VehStream_PlayerEnterVehicleAttempt", veh.Handle.Value, seat);
|
||||
}
|
||||
|
||||
[ServerEvent(Event.PlayerExitVehicleAttempt)]
|
||||
public void VehStreamExitAttempt(Client player, Vehicle veh)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Position = veh.Position;
|
||||
data.Rotation = veh.Rotation;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "VehStream_PlayerExitVehicleAttempt", veh);
|
||||
}
|
||||
|
||||
[ServerEvent(Event.PlayerExitVehicle)]
|
||||
public void VehStreamExit(Client player, Vehicle veh)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Position = veh.Position;
|
||||
data.Rotation = veh.Rotation;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "VehStream_PlayerExitVehicle", veh.Handle.Value);
|
||||
}
|
||||
|
||||
[ServerEvent(Event.PlayerEnterVehicle)]
|
||||
public void VehStreamEnter(Client player, Vehicle veh, sbyte seat)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "VehStream_PlayerEnterVehicle", veh, seat);
|
||||
player.TriggerEvent("Vehicle_setLockStatus", data.Locked);
|
||||
}
|
||||
|
||||
[ServerEvent(Event.VehicleDamage)]
|
||||
public void VehDamage(Vehicle veh, float bodyHealthLoss, float engineHealthLoss)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.BodyHealth -= bodyHealthLoss;
|
||||
data.EngineHealth -= engineHealthLoss;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
|
||||
if (NAPI.Vehicle.GetVehicleDriver(veh) != default(Client)) //Doesn't work?
|
||||
NAPI.ClientEvent.TriggerClientEvent(NAPI.Vehicle.GetVehicleDriver(veh), "VehStream_PlayerExitVehicleAttempt", veh);
|
||||
}
|
||||
|
||||
[ServerEvent(Event.VehicleDoorBreak)]
|
||||
public void VehDoorBreak(Vehicle veh, int index)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Door[index] = 2;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDoorStatus", veh.Handle, data.Door[0], data.Door[1], data.Door[2], data.Door[3], data.Door[4], data.Door[5], data.Door[6], data.Door[7]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user