Continued business system
This commit is contained in:
2
Main.cs
2
Main.cs
@@ -34,6 +34,8 @@ namespace reallife_gamemode
|
|||||||
|
|
||||||
TuningManager.AddTuningGarage(new Vector3(-341, -134, 38.5));
|
TuningManager.AddTuningGarage(new Vector3(-341, -134, 38.5));
|
||||||
|
|
||||||
|
BusinessManager.LoadBusinesses();
|
||||||
|
|
||||||
using (var context = new DatabaseContext())
|
using (var context = new DatabaseContext())
|
||||||
{
|
{
|
||||||
context.Bans.FirstOrDefault();
|
context.Bans.FirstOrDefault();
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace reallife_gamemode.Model
|
|||||||
|
|
||||||
public DatabaseContext()
|
public DatabaseContext()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
@@ -34,6 +35,10 @@ namespace reallife_gamemode.Model
|
|||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity<Server.Entities.BusinessBankAccount>()
|
||||||
|
.HasIndex(b => b.BusinessId)
|
||||||
|
.IsUnique(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//User
|
//User
|
||||||
@@ -69,7 +74,6 @@ namespace reallife_gamemode.Model
|
|||||||
public DbSet<Server.Entities.ShopVehicle> ShopVehicles { get; set; }
|
public DbSet<Server.Entities.ShopVehicle> ShopVehicles { get; set; }
|
||||||
|
|
||||||
// Business
|
// Business
|
||||||
public DbSet<Server.Entities.Business> Businesses { get; set; }
|
|
||||||
public DbSet<Server.Entities.BusinessBankAccount> BusinessBankAccounts { get; set; }
|
public DbSet<Server.Entities.BusinessBankAccount> BusinessBankAccounts { get; set; }
|
||||||
|
|
||||||
// Control Panel
|
// Control Panel
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
using reallife_gamemode.Model;
|
using GTANetworkAPI;
|
||||||
|
using reallife_gamemode.Model;
|
||||||
using reallife_gamemode.Server.Util;
|
using reallife_gamemode.Server.Util;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace reallife_gamemode.Server.Entities
|
namespace reallife_gamemode.Server.Business
|
||||||
{
|
{
|
||||||
public class Business : IBankAccountOwner
|
public abstract class BusinessBase : IBankAccountOwner
|
||||||
{
|
{
|
||||||
[Key]
|
public abstract int Id { get; }
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
public abstract string Name { get; }
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
public string Name { get; set; }
|
public abstract Vector3 Position { get; }
|
||||||
|
|
||||||
public IBankAccount GetBankAccount (DatabaseContext databaseContext = null)
|
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
||||||
{
|
{
|
||||||
if (databaseContext == null)
|
if (databaseContext == null)
|
||||||
{
|
{
|
||||||
@@ -31,5 +29,7 @@ namespace reallife_gamemode.Server.Entities
|
|||||||
return databaseContext.BusinessBankAccounts.FirstOrDefault(u => u.BusinessId == this.Id);
|
return databaseContext.BusinessBankAccounts.FirstOrDefault(u => u.BusinessId == this.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void Load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
23
Server/Business/TestBusiness.cs
Normal file
23
Server/Business/TestBusiness.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using GTANetworkAPI;
|
||||||
|
using reallife_gamemode.Model;
|
||||||
|
using reallife_gamemode.Server.Util;
|
||||||
|
|
||||||
|
namespace reallife_gamemode.Server.Business
|
||||||
|
{
|
||||||
|
class TestBusiness : BusinessBase
|
||||||
|
{
|
||||||
|
public override int Id => 1;
|
||||||
|
|
||||||
|
public override string Name => "Test Business";
|
||||||
|
|
||||||
|
public override Vector3 Position => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public override void Load()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using reallife_gamemode.Server.Util;
|
using reallife_gamemode.Server.Business;
|
||||||
|
using reallife_gamemode.Server.Util;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
@@ -14,8 +15,8 @@ namespace reallife_gamemode.Server.Entities
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int Balance { get; set; }
|
public int Balance { get; set; }
|
||||||
|
|
||||||
[ForeignKey("Business")]
|
|
||||||
public int BusinessId { get; set; }
|
public int BusinessId { get; set; }
|
||||||
public Business Business { get; set; }
|
[NotMapped]
|
||||||
|
public BusinessBase Business { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ using reallife_gamemode.Server.Util;
|
|||||||
|
|
||||||
namespace reallife_gamemode.Server.Managers
|
namespace reallife_gamemode.Server.Managers
|
||||||
{
|
{
|
||||||
public class BankManager : Script
|
public class BankManager
|
||||||
{
|
{
|
||||||
public static TransactionResult TransferMoney(IBankAccountOwner sender, IBankAccountOwner receiver, int amount, string origin)
|
public static TransactionResult TransferMoney(IBankAccountOwner sender, IBankAccountOwner receiver, int amount, string origin)
|
||||||
{
|
{
|
||||||
|
|||||||
41
Server/Managers/BusinessManager.cs
Normal file
41
Server/Managers/BusinessManager.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using GTANetworkAPI;
|
||||||
|
using reallife_gamemode.Server.Business;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace reallife_gamemode.Server.Managers
|
||||||
|
{
|
||||||
|
class BusinessManager : Script
|
||||||
|
{
|
||||||
|
private static List<BusinessBase> businesses;
|
||||||
|
|
||||||
|
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 (businesses.Find(b => b.GetType() == item) != null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Double Business found: {o.Id} | {o.Name}");
|
||||||
|
}
|
||||||
|
businesses.Add(o);
|
||||||
|
o.Load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T GetBusiness<T>() where T : BusinessBase
|
||||||
|
{
|
||||||
|
return (T)businesses.Find(b => b.GetType() == typeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,9 @@
|
|||||||
<HintPath>..\Bootstrapper.dll</HintPath>
|
<HintPath>..\Bootstrapper.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Migrations\" />
|
||||||
|
</ItemGroup>
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(ConfigurationName)' == 'Debug'">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(ConfigurationName)' == 'Debug'">
|
||||||
<Exec Command="del "..\..\client_packages\*" /Q /S
xcopy "$(OutDir)*" "..\..\bridge\resources\reallife-gamemode" /Y /Q
del "..\..\client_packages\*.*" /Q
xcopy "..\..\reallife-gamemode\reallife-gamemode\Client\*" "..\..\client_packages\" /S /Q /Y
" />
|
<Exec Command="del "..\..\client_packages\*" /Q /S
xcopy "$(OutDir)*" "..\..\bridge\resources\reallife-gamemode" /Y /Q
del "..\..\client_packages\*.*" /Q
xcopy "..\..\reallife-gamemode\reallife-gamemode\Client\*" "..\..\client_packages\" /S /Q /Y
" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|||||||
Reference in New Issue
Block a user