Changed whole project structure (split client and server into separat projects)

This commit is contained in:
hydrant
2019-02-25 22:12:05 +01:00
parent d2181c4987
commit 33abb3d04f
185 changed files with 282 additions and 596 deletions

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

View 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; }
}
}

View 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()
{
}
}
}

View 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()
{
}
}
}

View 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()
{
}
}
}