Business kaufen
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
using ReallifeGamemode.Server.Entities;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using ReallifeGamemode.Server.Models;
|
||||
@@ -65,26 +66,86 @@ namespace ReallifeGamemode.Server.Business
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
BusinessData data = GetData();
|
||||
|
||||
if(data == null)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
data = new BusinessData()
|
||||
{
|
||||
BusinessId = this.Id,
|
||||
Price = -1
|
||||
};
|
||||
|
||||
dbContext.BusinessData.Add(data);
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EntityExitBusinessColShape(ColShape colShape, Client client)
|
||||
{
|
||||
client.TriggerEvent("business_removeHelp", true);
|
||||
client.TriggerEvent("SERVER:Business_RemoveHelp", true);
|
||||
}
|
||||
|
||||
public BusinessData GetData(DatabaseContext dbContext = null)
|
||||
{
|
||||
if(dbContext == null)
|
||||
{
|
||||
using (dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.BusinessData.Where(b => b.BusinessId == this.Id).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return dbContext.BusinessData.Where(b => b.BusinessId == this.Id).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
private void EntityEnterBusinessColShape(ColShape colShape, Client client)
|
||||
{
|
||||
if (GetOwner() != null && GetOwner().Id == client.GetUser()?.Id && !client.IsInVehicle)
|
||||
if (client.IsInVehicle || !client.IsLoggedIn()) return;
|
||||
|
||||
client.TriggerEvent("SERVER:Business_ShowMenuHelp");
|
||||
SendBusinessDataToClient(client);
|
||||
}
|
||||
|
||||
public void SendBusinessDataToClient(Client player)
|
||||
{
|
||||
User owner = GetOwner();
|
||||
|
||||
int state = -1; // Keine Beziehung
|
||||
|
||||
if (owner == null) // Kein Besitzer
|
||||
{
|
||||
client.TriggerEvent("business_showHelp", Name, (GetBankAccount()?.Balance ?? 0).ToMoneyString());
|
||||
state = 0;
|
||||
}
|
||||
else if (owner.Id == player.GetUser()?.Id) // Besitzer
|
||||
{
|
||||
state = 1;
|
||||
}
|
||||
|
||||
var business = new
|
||||
{
|
||||
this.Name,
|
||||
Price = this.GetData().Price.ToMoneyString(),
|
||||
Balance = this.GetBankAccount().Balance.ToMoneyString()
|
||||
};
|
||||
|
||||
player.TriggerEvent("SERVER:Business_SetData", JsonConvert.SerializeObject(business), state);
|
||||
}
|
||||
|
||||
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();
|
||||
string infoText = Name;
|
||||
if (owner == null) infoText += "\n~g~Zum Verkauf\n~s~Preis: ~y~" + this.GetData().Price.ToMoneyString();
|
||||
else infoText += $"\nBesitzer: ~g~{owner.Name}\n~s~Kasse: ~y~{money.ToMoneyString()}";
|
||||
_informationLabel.Text = infoText;
|
||||
}
|
||||
|
||||
|
||||
@@ -2871,6 +2871,47 @@ namespace ReallifeGamemode.Server.Commands
|
||||
}
|
||||
}
|
||||
|
||||
[Command("business", "~m~Benutzung:~s~ /business [price] [Option]")]
|
||||
public void CmdAdminBusiness(Client player, string option, string option1)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
BusinessBase business = BusinessManager.GetNearBusiness(player);
|
||||
|
||||
if(business == null)
|
||||
{
|
||||
ChatService.ErrorMessage(player, "In deiner Nähe ist kein Business");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (option.ToLower())
|
||||
{
|
||||
case "price":
|
||||
if(!int.TryParse(option1, out int price))
|
||||
{
|
||||
ChatService.ErrorMessage(player, "Es muss ein gültiger Preis angegeben werden");
|
||||
return;
|
||||
}
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
BusinessData data = business.GetData(dbContext);
|
||||
data.Price = price;
|
||||
dbContext.SaveChanges();
|
||||
|
||||
player.SendChatMessage($"Der Preis wurde auf {price.ToMoneyString()} gesetzt");
|
||||
|
||||
business.Update();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
player.SendChatMessage("~m~Benutzung:~s~ /business [price] [Option]");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
19
ReallifeGamemode.Server/Entities/BusinessData.cs
Normal file
19
ReallifeGamemode.Server/Entities/BusinessData.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Entities
|
||||
{
|
||||
public class BusinessData
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public int BusinessId { get; set; }
|
||||
|
||||
public int Price { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using ReallifeGamemode.Server.Business;
|
||||
using ReallifeGamemode.Server.Entities;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using ReallifeGamemode.Server.Models;
|
||||
using ReallifeGamemode.Server.Services;
|
||||
using ReallifeGamemode.Server.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -48,6 +49,11 @@ namespace ReallifeGamemode.Server.Managers
|
||||
return Businesses.Find(b => b.Id == id);
|
||||
}
|
||||
|
||||
public static BusinessBase GetNearBusiness(Client player)
|
||||
{
|
||||
return Businesses.Where(b => b.Position.DistanceTo(player.Position) < 5f).FirstOrDefault();
|
||||
}
|
||||
|
||||
[RemoteEvent("Business_DepositMoney")]
|
||||
public void BusinessDepositMoney(Client player, int amount)
|
||||
{
|
||||
@@ -61,20 +67,19 @@ namespace ReallifeGamemode.Server.Managers
|
||||
|
||||
TransactionResult result = BankManager.TransferMoney(user, playerBusiness, amount, "Überweisung");
|
||||
|
||||
/*if(result == TransactionResult.NEGATIVE_MONEY_SENT)
|
||||
if (result == TransactionResult.NEGATIVE_MONEY_SENT)
|
||||
{
|
||||
player.SendNotification("~r~Es können nur positive Beträge überwiesen werden");
|
||||
return;
|
||||
player.SendNotification("~r~Es können nur positive Beträge überwiesen werden");
|
||||
return;
|
||||
}
|
||||
else if(result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
|
||||
else if (result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
|
||||
{
|
||||
player.SendNotification("~r~Du hast nicht genug Geld");
|
||||
return;
|
||||
player.SendNotification("~r~Du hast nicht genug Geld");
|
||||
return;
|
||||
}
|
||||
else */
|
||||
if (result == TransactionResult.SUCCESS)
|
||||
else if (result == TransactionResult.SUCCESS)
|
||||
{
|
||||
player.TriggerEvent("business_updateMoney", playerBusiness.GetBankAccount().Balance.ToMoneyString());
|
||||
playerBusiness.SendBusinessDataToClient(player);
|
||||
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
|
||||
return;
|
||||
}
|
||||
@@ -105,7 +110,7 @@ namespace ReallifeGamemode.Server.Managers
|
||||
}
|
||||
else if (result == TransactionResult.SUCCESS)
|
||||
{
|
||||
player.TriggerEvent("business_updateMoney", playerBusiness.GetBankAccount().Balance.ToMoneyString());
|
||||
playerBusiness.SendBusinessDataToClient(player);
|
||||
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
|
||||
return;
|
||||
}
|
||||
@@ -209,5 +214,46 @@ namespace ReallifeGamemode.Server.Managers
|
||||
|
||||
newVeh.Spawn();
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:Business_BuyBusiness")]
|
||||
public void BusinessEventBuyBusiness(Client player)
|
||||
{
|
||||
BusinessBase business = GetNearBusiness(player);
|
||||
if (business == null) return;
|
||||
|
||||
if (business.GetOwner() != null)
|
||||
{
|
||||
ChatService.ErrorMessage(player, "Dieses Business hat einen Besitzer");
|
||||
return;
|
||||
}
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
int price = business.GetData().Price;
|
||||
User user = player.GetUser(dbContext);
|
||||
|
||||
if(user.BusinessId != null)
|
||||
{
|
||||
ChatService.ErrorMessage(player, "Du kannst nicht mehrere Businesse besitzen");
|
||||
}
|
||||
|
||||
IBankAccount bankAccount = user.GetBankAccount(dbContext);
|
||||
|
||||
if (price > bankAccount.Balance)
|
||||
{
|
||||
ChatService.ErrorMessage(player, "Du hast nicht genung Geld");
|
||||
return;
|
||||
}
|
||||
|
||||
user.BusinessId = business.Id;
|
||||
bankAccount.Balance -= price;
|
||||
|
||||
player.SendChatMessage("Business gekauft");
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
business.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1310
ReallifeGamemode.Server/Migrations/20190911192912_BusinessData.Designer.cs
generated
Normal file
1310
ReallifeGamemode.Server/Migrations/20190911192912_BusinessData.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace ReallifeGamemode.Migrations
|
||||
{
|
||||
public partial class BusinessData : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BusinessData",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
BusinessId = table.Column<int>(nullable: false),
|
||||
Price = table.Column<int>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BusinessData", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "BusinessData");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,20 @@ namespace ReallifeGamemode.Migrations
|
||||
b.ToTable("BusinessBankAccounts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.BusinessData", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("BusinessId");
|
||||
|
||||
b.Property<int>("Price");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("BusinessData");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Character", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
||||
@@ -79,6 +79,7 @@ namespace ReallifeGamemode.Server.Models
|
||||
|
||||
// Business
|
||||
public DbSet<Entities.BusinessBankAccount> BusinessBankAccounts { get; set; }
|
||||
public DbSet<Entities.BusinessData> BusinessData { get; set; }
|
||||
|
||||
// Control Panel
|
||||
public DbSet<Entities.News> News { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user