Added commands to assign business to user
This commit is contained in:
@@ -39,6 +39,10 @@ namespace reallife_gamemode.Model
|
||||
modelBuilder.Entity<Server.Entities.BusinessBankAccount>()
|
||||
.HasIndex(b => b.BusinessId)
|
||||
.IsUnique(true);
|
||||
|
||||
modelBuilder.Entity<Server.Entities.User>()
|
||||
.HasIndex(u => u.BusinessId)
|
||||
.IsUnique(true);
|
||||
}
|
||||
|
||||
//User
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -10,6 +11,8 @@ namespace reallife_gamemode.Server.Business
|
||||
{
|
||||
public abstract class BusinessBase : IBankAccountOwner
|
||||
{
|
||||
private TextLabel _informationLabel;
|
||||
|
||||
public abstract int Id { get; }
|
||||
public abstract string Name { get; }
|
||||
|
||||
@@ -21,12 +24,36 @@ namespace reallife_gamemode.Server.Business
|
||||
{
|
||||
using (databaseContext = new DatabaseContext())
|
||||
{
|
||||
return databaseContext.BusinessBankAccounts.FirstOrDefault(u => u.BusinessId == this.Id);
|
||||
return databaseContext.BusinessBankAccounts.FirstOrDefault(u => u.BusinessId == Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return databaseContext.BusinessBankAccounts.FirstOrDefault(u => u.BusinessId == this.Id);
|
||||
return databaseContext.BusinessBankAccounts.FirstOrDefault(u => u.BusinessId == Id);
|
||||
}
|
||||
}
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
_informationLabel = NAPI.TextLabel.CreateTextLabel(Name, Position, 20.0f, 1.3f, 0, new Color(255, 255, 255));
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
//NAPI.Util.ConsoleOutput("Updating Business: " + Name);
|
||||
|
||||
User owner = GetOwner();
|
||||
string infoText = Name + "\n" + "Besitzer: " + (owner == null ? "Niemand" : owner.Name) + "\nKasse: " + (GetBankAccount()?.Balance ?? 0);
|
||||
_informationLabel.Text = infoText;
|
||||
}
|
||||
|
||||
public User GetOwner()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User user = dbContext.Users.FirstOrDefault(u => u.BusinessId == Id);
|
||||
//NAPI.Util.ConsoleOutput("[" + Name + "] GetOwner: " + (user?.Name ?? "null"));
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
21
Server/Business/SmsBusiness.cs
Normal file
21
Server/Business/SmsBusiness.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 SmsBusiness : BusinessBase
|
||||
{
|
||||
public override int Id => 1;
|
||||
|
||||
public override string Name => "SMS Business";
|
||||
|
||||
public override Vector3 Position => new Vector3(-423, 1130, 326);
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,15 @@ namespace reallife_gamemode.Server.Business
|
||||
{
|
||||
class TestBusiness : BusinessBase
|
||||
{
|
||||
public override int Id => 1;
|
||||
public override int Id => 0;
|
||||
|
||||
public override string Name => "Test Business";
|
||||
|
||||
public override Vector3 Position => throw new NotImplementedException();
|
||||
public override Vector3 Position => new Vector3(-443, 1134, 326);
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ using reallife_gamemode.Server.Services;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using reallife_gamemode.Server.Saves;
|
||||
using reallife_gamemode.Server.Business;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Admin Commands (Admin.cs)
|
||||
@@ -172,6 +173,22 @@ namespace reallife_gamemode.Server.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Command("businesslist", "~m~Benutzung: ~s~/businesslist")]
|
||||
public void CmdAdminBusinessList(Client player)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
player.SendChatMessage("~m~__________ ~s~Businesses ~m~__________");
|
||||
foreach (Business.BusinessBase b in BusinessManager.Businesses)
|
||||
{
|
||||
player.SendChatMessage(b.Id.ToString().PadRight(3) + " | " + b.Name);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1644,6 +1661,7 @@ namespace reallife_gamemode.Server.Commands
|
||||
NAPI.Chat.SendChatMessageToPlayer(player, "~w~Das Wetter konnte nicht geändert werden");
|
||||
}
|
||||
}
|
||||
|
||||
[Command("aspeed", "~m~Benutzung: ~s~/aspeed [Modifier]")] //TODO: Überarbeiten ?? SetPlayerVelocity ??
|
||||
public void CmdAdminAspeed(Client player, float modifier)
|
||||
{
|
||||
@@ -1661,7 +1679,8 @@ namespace reallife_gamemode.Server.Commands
|
||||
|
||||
player.Vehicle.EnginePowerMultiplier = modifier;
|
||||
}
|
||||
[Command("setmoney")]
|
||||
|
||||
[Command("setmoney", "~m~Benutzung: ~s~/setmoney [Name] [Menge]")]
|
||||
public void SetPlayerMoney(Client player, string receiver, int amount)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
|
||||
@@ -1685,7 +1704,7 @@ namespace reallife_gamemode.Server.Commands
|
||||
target.SendChatMessage("~b~[ADMIN]~s~ Dein Geld wurde von Admin " + player.Name + " auf ~g~$" + amount + "~s~ gesetzt.");
|
||||
}
|
||||
|
||||
[Command("givemoney")]
|
||||
[Command("givemoney", "~m~Benutzung: ~s~/givemoney [Name] [Menge]")]
|
||||
public void GivePlayerMoney(Client player, string receiver, int amount)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
|
||||
@@ -1693,6 +1712,7 @@ namespace reallife_gamemode.Server.Commands
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Client target = ClientService.GetClientByNameOrId(receiver);
|
||||
if (target == null || !target.IsLoggedIn())
|
||||
{
|
||||
@@ -1708,6 +1728,46 @@ namespace reallife_gamemode.Server.Commands
|
||||
player.SendChatMessage("~b~[ADMIN]~s~ Du hast " + target.Name + " ~g~$" + amount + "~s~ gegeben.");
|
||||
target.SendChatMessage("~b~[ADMIN]~s~ Admin " + player.Name + " hat dir ~g~$" + amount + "~s~ gegeben.");
|
||||
}
|
||||
|
||||
[Command("setbusinessowner", "~m~Benutzung: ~s~/setbusinessowner [Name] [Business ID]")]
|
||||
public void CmdAdminSetbusinessowner(Client player, string name, int businessid)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Client target = ClientService.GetClientByNameOrId(name);
|
||||
if (target == null || !target.IsLoggedIn())
|
||||
{
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
BusinessBase business = BusinessManager.GetBusiness(businessid);
|
||||
if(business == null)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Dieses Business existiert nicht. ~m~/businesslist");
|
||||
return;
|
||||
}
|
||||
|
||||
if(business.GetOwner() != null)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Das Business hat momentan noch einen Besitzer: ~o~" + business.GetOwner().Name + "~s~. Entferne diesen Besitzer erst mit ~m~/clearbusiness");
|
||||
return;
|
||||
}
|
||||
|
||||
using(var dbContext = new DatabaseContext())
|
||||
{
|
||||
Entities.User targetUser = target.GetUser(dbContext);
|
||||
targetUser.BusinessId = businessid;
|
||||
|
||||
business.Update();
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ALevel1338
|
||||
|
||||
@@ -58,6 +58,8 @@ namespace reallife_gamemode.Server.Entities
|
||||
public int? FactionRankId { get; set; }
|
||||
public FactionRank FactionRank { get;set; }
|
||||
|
||||
public int? BusinessId { get; set; }
|
||||
|
||||
public Faction GetFaction()
|
||||
{
|
||||
using(var context = new DatabaseContext())
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace reallife_gamemode.Server.Managers
|
||||
class BusinessManager : Script
|
||||
{
|
||||
private static List<BusinessBase> businesses;
|
||||
public static List<BusinessBase> Businesses { get => businesses; }
|
||||
|
||||
public static void LoadBusinesses()
|
||||
{
|
||||
@@ -22,12 +23,14 @@ namespace reallife_gamemode.Server.Managers
|
||||
NAPI.Util.ConsoleOutput($"Loading Business {item.Name}");
|
||||
if (Activator.CreateInstance(item) is BusinessBase o)
|
||||
{
|
||||
if (businesses.Find(b => b.GetType() == item) != null)
|
||||
if (businesses.Any(x => x.Id == o.Id))
|
||||
{
|
||||
throw new InvalidOperationException($"Double Business found: {o.Id} | {o.Name}");
|
||||
throw new InvalidOperationException($"Double Business ID found: {o.Id} | {o.Name}");
|
||||
}
|
||||
businesses.Add(o);
|
||||
o.Setup();
|
||||
o.Load();
|
||||
o.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,5 +40,9 @@ namespace reallife_gamemode.Server.Managers
|
||||
return (T)businesses.Find(b => b.GetType() == typeof(T));
|
||||
}
|
||||
|
||||
public static BusinessBase GetBusiness(int id)
|
||||
{
|
||||
return businesses.Find(b => b.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user