Business kaufen

This commit is contained in:
hydrant
2019-09-11 22:18:37 +02:00
parent fe90891801
commit 146261bc03
9 changed files with 1618 additions and 105 deletions

View File

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