Business kaufen
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user