backdoor
haus-konto geld abheben (30% steuern) alten hausmanager entfernt interiormanager in core verschoben
This commit is contained in:
@@ -41,6 +41,7 @@ function keyPressHandler() {
|
||||
var setRentalFeeItem: UIMenuItem;
|
||||
var cancelRentalsItem: UIMenuItem;
|
||||
var sellHouseItem: UIMenuItem;
|
||||
var withdrawBankItem: UIMenuItem;
|
||||
|
||||
var houseRentals = houseData.Rentals.length;
|
||||
|
||||
@@ -87,8 +88,14 @@ function keyPressHandler() {
|
||||
houseMenu.BindMenuToItem(cancelRentalsMenu, cancelRentalsItem);
|
||||
}
|
||||
|
||||
withdrawBankItem = new UIMenuItem("Konto", "Hebe Geld vom Konto ab");
|
||||
withdrawBankItem.SetRightLabel(moneyFormat(houseData.Balance) + "$");
|
||||
houseMenu.AddItem(withdrawBankItem);
|
||||
|
||||
sellHouseItem = new UIMenuItem("Haus verkaufen");
|
||||
houseMenu.AddItem(sellHouseItem);
|
||||
|
||||
|
||||
} else if (houseState === 2) {
|
||||
cancelOwnRentalItem = new UIMenuItem("Mietvertrag kündigen", "Ziehe aus der Wohnung aus");
|
||||
houseMenu.AddItem(cancelOwnRentalItem);
|
||||
@@ -129,6 +136,19 @@ function keyPressHandler() {
|
||||
} else if (item === sellHouseItem) {
|
||||
game.events.callServer("House_SellHouse");
|
||||
houseMenu.Close();
|
||||
} else if (item == withdrawBankItem) {
|
||||
var input = new InputHelper("Wie viel willst du abheben");
|
||||
input.show();
|
||||
input.getValue(data => {
|
||||
if (isNaN(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var withdrawAmount = parseInt(data);
|
||||
|
||||
game.events.callServer("House_WithdrawMoney", withdrawAmount);
|
||||
houseMenu.Close();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,34 +1,26 @@
|
||||
export default function interiors(globalData: IGlobalData) {
|
||||
import game from "..";
|
||||
import { Key } from "../game";
|
||||
|
||||
var keyBound = false;
|
||||
var interiorId = -1;
|
||||
var enterExit = undefined;
|
||||
var interiorId = -1;
|
||||
var enterExit = undefined;
|
||||
|
||||
mp.events.add('InteriorManager_ClearHelpText', () => {
|
||||
mp.game.ui.clearHelp(true);
|
||||
game.events.add('SERVER:InteriorManager_ClearHelpText', () => {
|
||||
game.ui.clearHelpText();
|
||||
|
||||
enterExit = undefined;
|
||||
enterExit = undefined;
|
||||
game.events.unbindKey(Key.E, false, keyPressHandler);
|
||||
});
|
||||
|
||||
if (keyBound) {
|
||||
mp.keys.unbind(0x45, false, keyPressHandler);
|
||||
keyBound = false;
|
||||
}
|
||||
});
|
||||
game.events.add('SERVER:InteriorManager_ShowHelpText', (interior, intId, entEx) => {
|
||||
game.ui.setHelpText('Drücke ~INPUT_CONTEXT~, um ~b~' + interior + ' ~s~zu ' + (entEx === 0 ? 'betreten' : 'verlassen'));
|
||||
|
||||
mp.events.add('InteriorManager_ShowHelpText', (interior, intId, entEx) => {
|
||||
mp.game.ui.setTextComponentFormat('STRING');
|
||||
mp.game.ui.addTextComponentSubstringPlayerName('Drücke ~INPUT_CONTEXT~, um ~b~' + interior + ' ~s~zu ' + (entEx === 0 ? 'betreten' : 'verlassen'));
|
||||
mp.game.ui.displayHelpTextFromStringLabel(0, true, true, -1);
|
||||
interiorId = intId;
|
||||
enterExit = entEx;
|
||||
|
||||
interiorId = intId;
|
||||
enterExit = entEx;
|
||||
game.events.bindKey(Key.E, false, keyPressHandler);
|
||||
});
|
||||
|
||||
mp.keys.bind(0x45, false, keyPressHandler);
|
||||
keyBound = true;
|
||||
});
|
||||
|
||||
function keyPressHandler() {
|
||||
if (globalData.InChat) return;
|
||||
mp.events.callRemote('InteriorManager_UseTeleport', interiorId, enterExit);
|
||||
}
|
||||
function keyPressHandler() {
|
||||
if (game.ui.inChat) return;
|
||||
game.events.callServer('InteriorManager_UseTeleport', [interiorId, enterExit]);
|
||||
}
|
||||
@@ -100,8 +100,7 @@ license(globalData);
|
||||
import vehicleMenu from './Gui/vehiclemenu/main';
|
||||
vehicleMenu(globalData);
|
||||
|
||||
import interiors from './Gui/interiors';
|
||||
interiors(globalData);
|
||||
require('./Gui/interiors');
|
||||
|
||||
import factionInteraction from './Interaction/factioninteraction';
|
||||
factionInteraction(globalData);
|
||||
|
||||
@@ -6,7 +6,7 @@ using ReallifeGamemode.Server.Core.API;
|
||||
|
||||
namespace ReallifeGamemode.Database.Entities
|
||||
{
|
||||
public partial class House
|
||||
public partial class House : BankAccountHolder<HouseBankAccount>
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
@@ -34,5 +34,7 @@ namespace ReallifeGamemode.Database.Entities
|
||||
public User Owner { get; set; }
|
||||
|
||||
public ICollection<HouseRental> Rentals { get; set; }
|
||||
|
||||
public override string BankAccountName => "Haus-Konto";
|
||||
}
|
||||
}
|
||||
|
||||
17
ReallifeGamemode.Database/Entities/HouseBankAccount.cs
Normal file
17
ReallifeGamemode.Database/Entities/HouseBankAccount.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Database.Entities
|
||||
{
|
||||
public class HouseBankAccount : IBankAccount
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public int Balance { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,16 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
|
||||
namespace ReallifeGamemode.Database.Entities
|
||||
{
|
||||
public partial class Interior
|
||||
{
|
||||
[NotMapped]
|
||||
private Vector3 _enterPosition;
|
||||
private Position _enterPosition;
|
||||
[NotMapped]
|
||||
private Vector3 _exitPosition;
|
||||
private Position _exitPosition;
|
||||
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
@@ -26,7 +27,7 @@ namespace ReallifeGamemode.Database.Entities
|
||||
}
|
||||
set
|
||||
{
|
||||
this._enterPosition = JsonConvert.DeserializeObject<Vector3>(value);
|
||||
this._enterPosition = JsonConvert.DeserializeObject<Position>(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,12 +40,12 @@ namespace ReallifeGamemode.Database.Entities
|
||||
}
|
||||
set
|
||||
{
|
||||
this._exitPosition = JsonConvert.DeserializeObject<Vector3>(value);
|
||||
this._exitPosition = JsonConvert.DeserializeObject<Position>(value);
|
||||
}
|
||||
}
|
||||
|
||||
[NotMapped]
|
||||
public Vector3 EnterPosition
|
||||
public Position EnterPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -57,7 +58,7 @@ namespace ReallifeGamemode.Database.Entities
|
||||
}
|
||||
|
||||
[NotMapped]
|
||||
public Vector3 ExitPosition
|
||||
public Position ExitPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
1439
ReallifeGamemode.Database/Migrations/20200330201122_HouseBankAccounts.Designer.cs
generated
Normal file
1439
ReallifeGamemode.Database/Migrations/20200330201122_HouseBankAccounts.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,60 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace ReallifeGamemode.Database.Migrations
|
||||
{
|
||||
public partial class HouseBankAccounts : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "BankAccountId",
|
||||
table: "Houses",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "HouseBankAccounts",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Balance = table.Column<int>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_HouseBankAccounts", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Houses_BankAccountId",
|
||||
table: "Houses",
|
||||
column: "BankAccountId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Houses_HouseBankAccounts_BankAccountId",
|
||||
table: "Houses",
|
||||
column: "BankAccountId",
|
||||
principalTable: "HouseBankAccounts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Houses_HouseBankAccounts_BankAccountId",
|
||||
table: "Houses");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "HouseBankAccounts");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Houses_BankAccountId",
|
||||
table: "Houses");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "BankAccountId",
|
||||
table: "Houses");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -481,6 +481,8 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int?>("BankAccountId");
|
||||
|
||||
b.Property<bool>("CanRentIn");
|
||||
|
||||
b.Property<DateTime>("LastRentSetTime");
|
||||
@@ -501,11 +503,25 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BankAccountId");
|
||||
|
||||
b.HasIndex("OwnerId");
|
||||
|
||||
b.ToTable("Houses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.HouseBankAccount", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("Balance");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("HouseBankAccounts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.HouseRental", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -1307,6 +1323,10 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.House", b =>
|
||||
{
|
||||
b.HasOne("ReallifeGamemode.Database.Entities.HouseBankAccount", "BankAccount")
|
||||
.WithMany()
|
||||
.HasForeignKey("BankAccountId");
|
||||
|
||||
b.HasOne("ReallifeGamemode.Database.Entities.User", "Owner")
|
||||
.WithMany()
|
||||
.HasForeignKey("OwnerId");
|
||||
@@ -1315,7 +1335,7 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.HouseRental", b =>
|
||||
{
|
||||
b.HasOne("ReallifeGamemode.Database.Entities.House", "House")
|
||||
.WithMany()
|
||||
.WithMany("Rentals")
|
||||
.HasForeignKey("HouseId");
|
||||
|
||||
b.HasOne("ReallifeGamemode.Database.Entities.User", "User")
|
||||
|
||||
@@ -51,25 +51,6 @@ namespace ReallifeGamemode.Database.Models
|
||||
|
||||
modelBuilder.Entity<Entities.VehicleMod>()
|
||||
.HasIndex(vM => new { vM.ServerVehicleId, vM.Slot }).IsUnique();
|
||||
|
||||
modelBuilder.Entity<Entities.HouseRental>()
|
||||
.HasIndex(hR => new
|
||||
{
|
||||
hR.HouseId,
|
||||
hR.UserId
|
||||
}).IsUnique();
|
||||
|
||||
modelBuilder.Entity<Entities.House>()
|
||||
.HasMany(h => h.Rentals)
|
||||
.WithOne(hR => hR.House);
|
||||
|
||||
modelBuilder.Entity<Entities.User>()
|
||||
.HasOne(u => u.House)
|
||||
.WithOne(h => h.Owner);
|
||||
|
||||
modelBuilder.Entity<Entities.House>()
|
||||
.HasOne(h => h.Owner)
|
||||
.WithOne(u => u.House);
|
||||
}
|
||||
|
||||
//User
|
||||
@@ -146,6 +127,7 @@ namespace ReallifeGamemode.Database.Models
|
||||
// Houses
|
||||
public DbSet<Entities.House> Houses { get; set; }
|
||||
public DbSet<Entities.HouseRental> HouseRentals { get; set; }
|
||||
public DbSet<Entities.HouseBankAccount> HouseBankAccounts { get; set; }
|
||||
|
||||
// Bus Routes
|
||||
public DbSet<Entities.BusRoute> BusRoutes { get; set; }
|
||||
|
||||
@@ -46,10 +46,11 @@ namespace ReallifeGamemode.Server.Core.Commands.Admin
|
||||
};
|
||||
|
||||
dbContext.Houses.Add(house);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
houseManager.LoadHouse(house);
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
player.SendNotification("Das Haus wurde erstellt");
|
||||
|
||||
return;
|
||||
@@ -98,11 +99,12 @@ namespace ReallifeGamemode.Server.Core.Commands.Admin
|
||||
}
|
||||
|
||||
nearHouse.Price = price;
|
||||
dbContext.SaveChanges();
|
||||
|
||||
houseManager.RemoveHouse(nearHouse);
|
||||
houseManager.LoadHouse(nearHouse);
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
player.SendNotification("Der Hauspreis wurde gesetzt");
|
||||
return;
|
||||
}
|
||||
@@ -122,11 +124,12 @@ namespace ReallifeGamemode.Server.Core.Commands.Admin
|
||||
}
|
||||
|
||||
nearHouse.Type = option2;
|
||||
dbContext.SaveChanges();
|
||||
|
||||
houseManager.RemoveHouse(nearHouse);
|
||||
houseManager.LoadHouse(nearHouse);
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
player.SendNotification("Der Haustyp wurde gesetzt");
|
||||
|
||||
return;
|
||||
|
||||
114
ReallifeGamemode.Server.Core/Commands/Admin/InteriorCommand.cs
Normal file
114
ReallifeGamemode.Server.Core/Commands/Admin/InteriorCommand.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
using ReallifeGamemode.Server.Core.Managers;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.Commands.Admin
|
||||
{
|
||||
class InteriorCommand : AdminCommand
|
||||
{
|
||||
public override string CommandName => "interior";
|
||||
|
||||
public override string HelpText => "[Add / Remove / SetEnter / SetExit][Name / ID]";
|
||||
|
||||
protected override AdminLevel AdminLevel => AdminLevel.HEADADMIN;
|
||||
|
||||
public void Handle(IPlayer player, string option1, string option2 = null)
|
||||
{
|
||||
option1 = option1.ToString();
|
||||
|
||||
if (option1 != "add" && option1 != "remove" && option1 != "setenter" && option1 != "setexit")
|
||||
{
|
||||
player.SendMessage("/interior [Add / Remove / SetEnter / SetExit] [Name / ID]", ChatPrefix.Usage);
|
||||
return;
|
||||
}
|
||||
|
||||
var interiorManager = Main.GetScript<InteriorManager>();
|
||||
|
||||
switch (option1)
|
||||
{
|
||||
case "add":
|
||||
using (var dbContext = GetDbContext())
|
||||
{
|
||||
Interior interiorAdd = new Interior
|
||||
{
|
||||
Name = option2
|
||||
};
|
||||
dbContext.Interiors.Add(interiorAdd);
|
||||
dbContext.SaveChanges();
|
||||
player.SendMessage("Das Interior ~y~" + option2 + "~s~ wurde erstellt. ~m~ID: " + interiorAdd.Id, ChatPrefix.Admin);
|
||||
}
|
||||
break;
|
||||
case "remove":
|
||||
using (var dbContext = GetDbContext())
|
||||
{
|
||||
if (!int.TryParse(option2, out int intId))
|
||||
{
|
||||
player.SendMessage("Es muss eine Nummer angegeben werden", ChatPrefix.Error);
|
||||
return;
|
||||
}
|
||||
Interior interiorRemove = interiorManager.GetInteriorById(intId, dbContext);
|
||||
if (interiorRemove == null)
|
||||
{
|
||||
player.SendMessage("Dieses Interior existiert nicht", ChatPrefix.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
interiorManager.DeleteInterior(interiorRemove);
|
||||
|
||||
dbContext.Interiors.Remove(interiorRemove);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
player.SendMessage("Das Interior wurde gelöscht", ChatPrefix.Admin);
|
||||
break;
|
||||
case "setenter":
|
||||
using (var dbContext = GetDbContext())
|
||||
{
|
||||
if (!int.TryParse(option2, out int intIdEnter))
|
||||
{
|
||||
player.SendMessage("Es muss eine Nummer angegeben werden", ChatPrefix.Error);
|
||||
return;
|
||||
}
|
||||
Interior interior = interiorManager.GetInteriorById(intIdEnter, dbContext);
|
||||
if (interior == null)
|
||||
{
|
||||
player.SendMessage("Dieses Interior existiert nicht", ChatPrefix.Error);
|
||||
return;
|
||||
}
|
||||
interior.EnterPosition = player.Position;
|
||||
dbContext.SaveChanges();
|
||||
interiorManager.DeleteInterior(interior);
|
||||
interiorManager.LoadInterior(interior);
|
||||
player.SendMessage("Die Eingangs-Position vom Interior ~y~" + interior.Name + "~s~ wurde gesetzt", ChatPrefix.Admin);
|
||||
interiorManager.LoadInteriors();
|
||||
}
|
||||
break;
|
||||
case "setexit":
|
||||
using (var dbContext = GetDbContext())
|
||||
{
|
||||
if (!int.TryParse(option2, out int intIdExit))
|
||||
{
|
||||
player.SendMessage("Es muss eine Nummer angegeben werden", ChatPrefix.Error);
|
||||
return;
|
||||
}
|
||||
Interior interior = interiorManager.GetInteriorById(intIdExit, dbContext);
|
||||
if (interior == null)
|
||||
{
|
||||
player.SendMessage("Dieses Interior existiert nicht", ChatPrefix.Error);
|
||||
return;
|
||||
}
|
||||
interior.ExitPosition = player.Position;
|
||||
dbContext.SaveChanges();
|
||||
interiorManager.DeleteInterior(interior);
|
||||
interiorManager.LoadInterior(interior);
|
||||
player.SendMessage("Die Eingangs-Position vom Interior ~y~" + interior.Name + "~s~ wurde gesetzt", ChatPrefix.Admin);
|
||||
interiorManager.LoadInteriors();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
EventHandler.RegisterClientEvent("House_RentInHouse", HouseManagerRentInHouseEvent);
|
||||
EventHandler.RegisterClientEvent("House_CancelOwnRental", HouseManagerCancelOwnRentalEvent);
|
||||
EventHandler.RegisterClientEvent("House_SellHouse", HouseManagerSellHouseEvent);
|
||||
EventHandler.RegisterClientEvent("House_WithdrawMoney", HouseManagerWithdrawMoneyEvent);
|
||||
|
||||
LoadHouses();
|
||||
}
|
||||
@@ -37,11 +38,12 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
private void LoadHouses()
|
||||
{
|
||||
using var dbContext = GetDbContext();
|
||||
var houses = dbContext.Houses.Include(h => h.Owner);
|
||||
var houses = dbContext.Houses.Include(h => h.Owner).Include(h => h.BankAccount);
|
||||
foreach (House house in houses)
|
||||
{
|
||||
LoadHouse(house);
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
public void LoadHouse(House house)
|
||||
@@ -69,13 +71,18 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
|
||||
houseLabels[house.Id] = Api.TextLabel.CreateTextLabel(text, housePos, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
|
||||
if (house.Price != 0)
|
||||
if (house.Price != 0 || house.RentalFee != 0)
|
||||
{
|
||||
houseColShapes[house.Id] = Api.ColShape.CreateCyclinder(housePos.Subtract(new Position(0, 0, 2)), 4.0f, 2f);
|
||||
|
||||
houseColShapes[house.Id].OnEntityEnter += HouseManager_OnEntityEnterColShape;
|
||||
houseColShapes[house.Id].OnEntityExit += HouseManager_OnEntityExitColShape;
|
||||
}
|
||||
|
||||
if (house.BankAccount == null)
|
||||
{
|
||||
house.BankAccount = new HouseBankAccount();
|
||||
}
|
||||
}
|
||||
|
||||
private void HouseManager_OnEntityExitColShape(IColShape colShape, IPlayer client)
|
||||
@@ -117,6 +124,7 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
.Include(h => h.Owner)
|
||||
.Include(h => h.Rentals)
|
||||
.ThenInclude(hR => hR.User)
|
||||
.Include(h => h.BankAccount)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -138,7 +146,8 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
house.RentalFee,
|
||||
house.Price,
|
||||
house.Type,
|
||||
Rentals = rentals.Select(r => r.User.Name)
|
||||
Rentals = rentals.Select(r => r.User.Name),
|
||||
house.BankAccount.Balance
|
||||
};
|
||||
|
||||
player.TriggerEvent("SetHouseData", newHouse.SerializeJson(), userHouseStatus);
|
||||
@@ -178,13 +187,18 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
|
||||
public House GetNearHouse(Position position, DatabaseContext dbContext)
|
||||
{
|
||||
return dbContext.Houses.Where(h => h.Position.DistanceTo(position) <= 5f).Include(h => h.Owner).OrderBy(h => h.Position.DistanceTo(position)).FirstOrDefault();
|
||||
return dbContext.Houses.Where(h => h.Position.DistanceTo(position) <= 5f)
|
||||
.Include(h => h.Owner)
|
||||
.Include(h => h.BankAccount)
|
||||
.Include(h => h.Rentals)
|
||||
.OrderBy(h => h.Position.DistanceTo(position))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public void ReloadAllHouses()
|
||||
{
|
||||
using var dbContext = GetDbContext();
|
||||
foreach (House house in dbContext.Houses.Include(h => h.Owner).ToList())
|
||||
foreach (House house in dbContext.Houses.Include(h => h.Owner).Include(h => h.BankAccount))
|
||||
{
|
||||
RemoveHouse(house);
|
||||
LoadHouse(house);
|
||||
@@ -377,7 +391,7 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
private void HouseManagerSellHouseEvent(IPlayer player, params object[] args)
|
||||
{
|
||||
using var dbContext = GetDbContext();
|
||||
User user = player.GetUser(dbContext);
|
||||
User user = player.GetUser(dbContext, bankAccount: true);
|
||||
if (user.HouseId == null)
|
||||
{
|
||||
player.SendMessage("Du besitzt kein Haus", ChatPrefix.Error);
|
||||
@@ -403,5 +417,41 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
|
||||
SendPlayerHouseData(player, house);
|
||||
}
|
||||
|
||||
private void HouseManagerWithdrawMoneyEvent(IPlayer player, object[] args)
|
||||
{
|
||||
var amount = args[0].ToInt();
|
||||
|
||||
if (amount <= 0)
|
||||
{
|
||||
player.SendMessage("Du musst mindestens 1$ abheben", ChatPrefix.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
using var dbContext = GetDbContext();
|
||||
User user = player.GetUser(dbContext, bankAccount: true);
|
||||
if (user.HouseId == null)
|
||||
{
|
||||
player.SendMessage("Du besitzt kein Haus", ChatPrefix.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
House house = GetHouseById(user.HouseId.Value, dbContext);
|
||||
|
||||
if (house.BankAccount.Balance < amount)
|
||||
{
|
||||
player.SendMessage("Auf dem Konto deines Hauses ist nicht genug Geld", ChatPrefix.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
user.BankAccount.Balance += amount;
|
||||
house.BankAccount.Balance -= amount;
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
player.SendMessage($"Du hast {amount.ToMoneyString()} von dem Konto deines Hauses abgehoben", ChatPrefix.Info);
|
||||
|
||||
SendPlayerHouseData(player, house);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
140
ReallifeGamemode.Server.Core/Managers/InteriorManager.cs
Normal file
140
ReallifeGamemode.Server.Core/Managers/InteriorManager.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ReallifeGamemode.Server.Common;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.Managers
|
||||
{
|
||||
class InteriorManager : Script
|
||||
{
|
||||
public static Dictionary<int, ITextLabel> _interiorEnterTextLabels = new Dictionary<int, ITextLabel>();
|
||||
public static Dictionary<int, ITextLabel> _interiorExitTextLabels = new Dictionary<int, ITextLabel>();
|
||||
public static Dictionary<int, IMarker> _interiorEnterMarkers = new Dictionary<int, IMarker>();
|
||||
public static Dictionary<int, IMarker> _interiorExitMarkers = new Dictionary<int, IMarker>();
|
||||
public static Dictionary<int, IColShape> _interiorEnterColShapes = new Dictionary<int, IColShape>();
|
||||
public static Dictionary<int, IColShape> _interiorExitColShapes = new Dictionary<int, IColShape>();
|
||||
|
||||
public InteriorManager()
|
||||
{
|
||||
LoadInteriors();
|
||||
|
||||
EventHandler.RegisterClientEvent("InteriorManager_UseTeleport", InteriorManagerUseTeleportEvent);
|
||||
}
|
||||
|
||||
public Interior GetInteriorByName(string name, DatabaseContext dbContext)
|
||||
{
|
||||
return dbContext.Interiors.Where(i => i.Name.ToLower() == name.ToLower()).FirstOrDefault();
|
||||
}
|
||||
|
||||
public Interior GetInteriorById(int id, DatabaseContext dbContext)
|
||||
{
|
||||
return dbContext.Interiors.Where(i => i.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public void LoadInteriors()
|
||||
{
|
||||
using var dbContext = GetDbContext();
|
||||
foreach (Interior interior in dbContext.Interiors)
|
||||
{
|
||||
LoadInterior(interior);
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadInterior(Interior interior)
|
||||
{
|
||||
if (interior.EnterPosition != null)
|
||||
{
|
||||
_interiorEnterTextLabels[interior.Id] = Api.TextLabel.CreateTextLabel("~y~" + interior.Name + "\n~s~Eingang", interior.EnterPosition, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
_interiorEnterMarkers[interior.Id] = Api.Marker.CreateMarker(MarkerType.VerticalCylinder, interior.EnterPosition.Subtract(new Position(0, 0, 1.7)), new Position(), new Position(), 1.6f, Color.White);
|
||||
_interiorEnterColShapes[interior.Id] = Api.ColShape.CreateSphere(interior.EnterPosition, 1.5f);
|
||||
|
||||
_interiorEnterColShapes[interior.Id].OnEntityEnter += InteriorManagerPlayerEnterColshapeEvent;
|
||||
_interiorEnterColShapes[interior.Id].OnEntityExit += InteriorManagerPlayerExitColshapeEvent;
|
||||
}
|
||||
|
||||
if (interior.ExitPosition != null)
|
||||
{
|
||||
_interiorExitTextLabels[interior.Id] = Api.TextLabel.CreateTextLabel("~y~" + interior.Name + "\n~s~Ausgang", interior.ExitPosition, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
_interiorExitMarkers[interior.Id] = Api.Marker.CreateMarker(MarkerType.VerticalCylinder, interior.ExitPosition.Subtract(new Position(0, 0, 1.7)), new Position(), new Position(), 1.6f, Color.White);
|
||||
_interiorExitColShapes[interior.Id] = Api.ColShape.CreateSphere(interior.ExitPosition, 1.5f);
|
||||
|
||||
_interiorExitColShapes[interior.Id].OnEntityEnter += InteriorManagerPlayerEnterColshapeEvent;
|
||||
_interiorExitColShapes[interior.Id].OnEntityExit += InteriorManagerPlayerExitColshapeEvent;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteInterior(Interior interior)
|
||||
{
|
||||
ITextLabel enT = GetInteriorEnterTextLabel(interior);
|
||||
ITextLabel exT = GetInteriorExitTextLabel(interior);
|
||||
IMarker enM = GetInteriorEnterMarker(interior);
|
||||
IMarker exM = GetInteriorExitMarkers(interior);
|
||||
IColShape enC = GetInteriorEnterColShape(interior);
|
||||
IColShape exC = GetInteriorExitColShape(interior);
|
||||
|
||||
if (enT != null) enT.Remove();
|
||||
if (exT != null) exT.Remove();
|
||||
if (enM != null) enM.Remove();
|
||||
if (exM != null) exM.Remove();
|
||||
if (enC != null) enC.Remove();
|
||||
if (exC != null) exC.Remove();
|
||||
|
||||
_interiorEnterTextLabels.Remove(interior.Id);
|
||||
_interiorExitTextLabels.Remove(interior.Id);
|
||||
_interiorEnterMarkers.Remove(interior.Id);
|
||||
_interiorExitMarkers.Remove(interior.Id);
|
||||
_interiorEnterColShapes.Remove(interior.Id);
|
||||
_interiorExitColShapes.Remove(interior.Id);
|
||||
}
|
||||
|
||||
public ITextLabel GetInteriorEnterTextLabel(Interior interior) => _interiorEnterTextLabels[interior.Id];
|
||||
public ITextLabel GetInteriorExitTextLabel(Interior interior) => _interiorExitTextLabels[interior.Id];
|
||||
|
||||
public IMarker GetInteriorEnterMarker(Interior interior) => _interiorEnterMarkers[interior.Id];
|
||||
public IMarker GetInteriorExitMarkers(Interior interior) => _interiorExitMarkers[interior.Id];
|
||||
|
||||
public IColShape GetInteriorEnterColShape(Interior interior) => _interiorEnterColShapes[interior.Id];
|
||||
public IColShape GetInteriorExitColShape(Interior interior) => _interiorExitColShapes[interior.Id];
|
||||
|
||||
public int GetInteriorIdFromEnterColShape(IColShape handle) => _interiorEnterColShapes.FirstOrDefault(c => c.Value == handle).Key;
|
||||
public int GetInteriorIdFromExitColShape(IColShape handle) => _interiorExitColShapes.FirstOrDefault(c => c.Value == handle).Key;
|
||||
|
||||
public void InteriorManagerPlayerEnterColshapeEvent(IColShape colShape, IPlayer player)
|
||||
{
|
||||
using var dbContext = GetDbContext();
|
||||
|
||||
int enterId = GetInteriorIdFromEnterColShape(colShape);
|
||||
int exitId = GetInteriorIdFromExitColShape(colShape);
|
||||
if (enterId != 0)
|
||||
{
|
||||
Interior interior = GetInteriorById(enterId, dbContext);
|
||||
player.TriggerEvent("InteriorManager_ShowHelpText", interior.Name, interior.Id, 0);
|
||||
}
|
||||
else if (exitId != 0)
|
||||
{
|
||||
Interior interior = GetInteriorById(exitId, dbContext);
|
||||
player.TriggerEvent("InteriorManager_ShowHelpText", interior.Name, interior.Id, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void InteriorManagerPlayerExitColshapeEvent(IColShape colShape, IPlayer player)
|
||||
{
|
||||
if (GetInteriorIdFromEnterColShape(colShape) != 0 || GetInteriorIdFromExitColShape(colShape) != 0)
|
||||
{
|
||||
player.TriggerEvent("InteriorManager_ClearHelpText");
|
||||
}
|
||||
}
|
||||
|
||||
public void InteriorManagerUseTeleportEvent(IPlayer player, params object[] args)
|
||||
{
|
||||
var id = args[0].ToInt();
|
||||
var enterExit = args[1].ToInt();
|
||||
|
||||
Interior interior = GetInteriorById(id, GetDbContext());
|
||||
player.Position = enterExit == 0 ? interior.ExitPosition : interior.EnterPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ namespace ReallifeGamemode.Server.Log
|
||||
builder.AddDebug();
|
||||
builder.AddFilter("ReallifeGamemode.Server", LogLevel.Debug);
|
||||
builder.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Information);
|
||||
builder.AddFilter("Microsoft.EntityFrameworkCore.Infrastructure", LogLevel.Warning);
|
||||
});
|
||||
|
||||
public static ILogger<T> GetLogger<T>()
|
||||
|
||||
@@ -2680,105 +2680,17 @@ namespace ReallifeGamemode.Server.Commands
|
||||
BankManager.SetMoney(player, business, amount, "Admin");
|
||||
}
|
||||
|
||||
[Command("interior", "~m~Benutzung: ~s~/interior [Add / Remove / SetEnter / SetExit] [Name / ID]")]
|
||||
public void CmdAdminInterior(Player player, string option1, string option2)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
//[Command("interior", "~m~Benutzung: ~s~/interior [Add / Remove / SetEnter / SetExit] [Name / ID]")]
|
||||
//public void CmdAdminInterior(Player player, string option1, string option2)
|
||||
//{
|
||||
// if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
|
||||
// {
|
||||
// ChatService.NotAuthorized(player);
|
||||
// return;
|
||||
// }
|
||||
|
||||
option1 = option1.ToString();
|
||||
|
||||
if (option1 != "add" && option1 != "remove" && option1 != "setenter" && option1 != "setexit")
|
||||
{
|
||||
ChatService.SendMessage(player, "~m~Benutzung: ~s~/interior [Add / Remove / SetEnter / SetExit] [Name / ID]");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (option1)
|
||||
{
|
||||
case "add":
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
Interior interiorAdd = new Interior
|
||||
{
|
||||
Name = option2
|
||||
};
|
||||
dbContext.Interiors.Add(interiorAdd);
|
||||
dbContext.SaveChanges();
|
||||
ChatService.SendMessage(player, "~b~[ADMIN]~s~ Das Interior ~y~" + option2 + "~s~ wurde erstellt. ~m~ID: " + interiorAdd.Id);
|
||||
}
|
||||
break;
|
||||
case "remove":
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
if (!int.TryParse(option2, out int intId))
|
||||
{
|
||||
ChatService.ErrorMessage(player, "Es muss eine Nummer angegeben werden");
|
||||
return;
|
||||
}
|
||||
Interior interiorRemove = InteriorManager.GetInteriorById(intId, dbContext);
|
||||
if (interiorRemove == null)
|
||||
{
|
||||
ChatService.ErrorMessage(player, "Dieses Interior existiert nicht");
|
||||
return;
|
||||
}
|
||||
|
||||
InteriorManager.DeleteInterior(interiorRemove);
|
||||
|
||||
dbContext.Interiors.Remove(interiorRemove);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
ChatService.SendMessage(player, "~b~[ADMIN]~s~ Das Interior wurde gelöscht.");
|
||||
break;
|
||||
case "setenter":
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
if (!int.TryParse(option2, out int intIdEnter))
|
||||
{
|
||||
ChatService.ErrorMessage(player, "Es muss eine Nummer angegeben werden");
|
||||
return;
|
||||
}
|
||||
Interior interior = InteriorManager.GetInteriorById(intIdEnter, dbContext);
|
||||
if (interior == null)
|
||||
{
|
||||
ChatService.ErrorMessage(player, "Dieses Interior existiert nicht");
|
||||
return;
|
||||
}
|
||||
interior.EnterPosition = player.Position;
|
||||
dbContext.SaveChanges();
|
||||
InteriorManager.DeleteInterior(interior);
|
||||
InteriorManager.LoadInterior(interior);
|
||||
ChatService.SendMessage(player, "~b~[ADMIN]~s~ Die Eingangs-Position vom Interior ~y~" + interior.Name + "~s~ wurde gesetzt.");
|
||||
InteriorManager.LoadInteriors();
|
||||
}
|
||||
break;
|
||||
case "setexit":
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
if (!int.TryParse(option2, out int intIdExit))
|
||||
{
|
||||
ChatService.ErrorMessage(player, "Es muss eine Nummer angegeben werden");
|
||||
return;
|
||||
}
|
||||
Interior interior = InteriorManager.GetInteriorById(intIdExit, dbContext);
|
||||
if (interior == null)
|
||||
{
|
||||
ChatService.ErrorMessage(player, "Dieses Interior existiert nicht");
|
||||
return;
|
||||
}
|
||||
interior.ExitPosition = player.Position;
|
||||
dbContext.SaveChanges();
|
||||
InteriorManager.DeleteInterior(interior);
|
||||
InteriorManager.LoadInterior(interior);
|
||||
ChatService.SendMessage(player, "~b~[ADMIN]~s~ Die Eingangs-Position vom Interior ~y~" + interior.Name + "~s~ wurde gesetzt.");
|
||||
InteriorManager.LoadInteriors();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
[Command("reloaddoors", "~m~Benutzung: ~s~/reloaddoors")]
|
||||
public void CmdAdminReloaddoors(Player player)
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
|
||||
player.TriggerEvent("SERVER:Login_Success");
|
||||
player.SetData("isLoggedIn", true);
|
||||
player.SetSharedData("isLoggedIn", true);
|
||||
player.SetData("isDead", false);
|
||||
|
||||
var currentPlayerCreatorDimension = (uint)NAPI.Data.GetWorldData("playerCreatorDimension");
|
||||
|
||||
@@ -97,8 +97,20 @@ namespace ReallifeGamemode.Server.Finance
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
client.GetUser(dbContext).BankAccount.Balance += paycheck.Amount;
|
||||
client.GetUser(dbContext).Wage = 0;
|
||||
User u = client.GetUser(dbContext);
|
||||
u.BankAccount.Balance += paycheck.Amount;
|
||||
u.Wage = 0;
|
||||
|
||||
var rentals = dbContext.HouseRentals
|
||||
.Include(hR => hR.House)
|
||||
.ThenInclude(h => h.BankAccount)
|
||||
.Where(hR => hR.UserId == u.Id);
|
||||
|
||||
foreach (var rental in rentals)
|
||||
{
|
||||
rental.House.BankAccount.Balance += (int)(rental.House.RentalFee * 0.7);
|
||||
}
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
if (paycheck.Amount > 0)
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace ReallifeGamemode.Server
|
||||
|
||||
FactionHelper.CheckFactionBankAccounts();
|
||||
BusinessManager.LoadBusinesses();
|
||||
InteriorManager.LoadInteriors();
|
||||
//InteriorManager.LoadInteriors();
|
||||
DoorManager.LoadDoors();
|
||||
ATMManager.InitATMs();
|
||||
CityHallManager.LoadCityHall();
|
||||
|
||||
@@ -1,443 +0,0 @@
|
||||
using GTANetworkAPI;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using ReallifeGamemode.Server.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Managers
|
||||
{
|
||||
//public class HouseManager : Script
|
||||
//{
|
||||
// private static readonly Dictionary<int, NetHandle> houseMarkers = new Dictionary<int, NetHandle>();
|
||||
// private static readonly Dictionary<int, NetHandle> houseLabels = new Dictionary<int, NetHandle>();
|
||||
// private static readonly Dictionary<int, NetHandle> houseColShapes = new Dictionary<int, NetHandle>();
|
||||
// private static readonly Dictionary<int, NetHandle> houseBlips = new Dictionary<int, NetHandle>();
|
||||
|
||||
// private static readonly Dictionary<int, List<Player>> playerInColShape = new Dictionary<int, List<Player>>();
|
||||
|
||||
// public static async void LoadHouses()
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
// public static async void ReloadAllHouses()
|
||||
// {
|
||||
// using (var dbContext = new DatabaseContext())
|
||||
// {
|
||||
// foreach (House house in await dbContext.Houses.Include(h => h.Owner).ToListAsync())
|
||||
// {
|
||||
// RemoveHouse(house);
|
||||
// LoadHouse(house, false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static House GetNearHouse(Vector3 position, DatabaseContext dbContext = null)
|
||||
// {
|
||||
// if (dbContext == null)
|
||||
// {
|
||||
// using (dbContext = new DatabaseContext())
|
||||
// {
|
||||
// return dbContext.Houses.Where(h => h.Position.DistanceTo(position) <= 5f).Include(h => h.Owner).OrderBy(h => h.Position.DistanceTo(position)).FirstOrDefault();
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return dbContext.Houses.Where(h => h.Position.DistanceTo(position) <= 5f).Include(h => h.Owner).OrderBy(h => h.Position.DistanceTo(position)).FirstOrDefault();
|
||||
// }
|
||||
// }
|
||||
|
||||
// public void AddHouse(string type, int price, Vector3 position)
|
||||
// {
|
||||
// using (var dbContext = new DatabaseContext())
|
||||
// {
|
||||
// var house = new House()
|
||||
// {
|
||||
// Price = price,
|
||||
// Type = type,
|
||||
// X = position.X,
|
||||
// Y = position.Y,
|
||||
// Z = position.Z
|
||||
// };
|
||||
|
||||
// dbContext.Houses.Add(house);
|
||||
// dbContext.SaveChanges();
|
||||
|
||||
// LoadHouse(house);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static House GetHouseById(int id, DatabaseContext dbContext = null)
|
||||
// {
|
||||
// if (dbContext == null)
|
||||
// {
|
||||
// using (dbContext = new DatabaseContext())
|
||||
// {
|
||||
// return dbContext.Houses.Where(h => h.Id == id).Include(h => h.Owner).FirstOrDefault();
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return dbContext.Houses.Where(h => h.Id == id).Include(h => h.Owner).FirstOrDefault();
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static void LoadHouse(House house, bool loadUser = true)
|
||||
// {
|
||||
// if (loadUser) house = house.Refresh();
|
||||
|
||||
// playerInColShape[house.Id] = new List<Player>();
|
||||
|
||||
// houseMarkers[house.Id] = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, house.Position.Subtract(new Vector3(0, 0, 1.7)), new Vector3(), new Vector3(), 1.6f, new Color(255, 255, 255)).Handle;
|
||||
// string text = $"~g~Zum Verkauf\n~s~{house.Type}\nPreis: ~y~{(house.Price == 0 ? "~r~Nicht verkäuflich" : house.Price.ToMoneyString())}";
|
||||
|
||||
// if (house.OwnerId != null)
|
||||
// {
|
||||
// text = $"{house.Type}\n~s~Besitzer: ~y~{house.Owner.Name}";
|
||||
|
||||
// if (house.RentalFee != 0)
|
||||
// {
|
||||
// text += $"\n~s~Mietpreis: ~g~{house.RentalFee.ToMoneyString()}";
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //houseBlips[house.Id] = NAPI.Blip.CreateBlip(40, house.Position, 0.7f, 11, "Haus", shortRange: true); too many blips
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// houseLabels[house.Id] = NAPI.TextLabel.CreateTextLabel(text, house.Position, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
|
||||
// if (house.Price != 0)
|
||||
// {
|
||||
// houseColShapes[house.Id] = NAPI.ColShape.CreateCylinderColShape(house.Position.Subtract(new Vector3(0, 0, 2)), 2.0f, 5f);
|
||||
|
||||
// houseColShapes[house.Id].Entity<ColShape>().OnEntityEnterColShape += HouseManager_OnEntityEnterColShape;
|
||||
// houseColShapes[house.Id].Entity<ColShape>().OnEntityExitColShape += HouseManager_OnEntityExitColShape;
|
||||
// }
|
||||
// }
|
||||
|
||||
// private static void HouseManager_OnEntityExitColShape(ColShape colShape, Player client)
|
||||
// {
|
||||
// if (!client.IsLoggedIn() || client.IsInVehicle) return;
|
||||
// if (!houseColShapes.ContainsValue(colShape.Handle))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// int houseId = houseColShapes.Where(p => p.Value.Value == colShape.Handle.Value).FirstOrDefault().Key;
|
||||
// playerInColShape[houseId].Remove(client);
|
||||
|
||||
// client.TriggerEvent("SERVER:CloseHouseMenu");
|
||||
// }
|
||||
|
||||
// private static void HouseManager_OnEntityEnterColShape(ColShape colShape, Player client)
|
||||
// {
|
||||
// if (!client.IsLoggedIn() || client.IsInVehicle) return;
|
||||
// if (!houseColShapes.ContainsValue(colShape.Handle))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// int houseId = houseColShapes.Where(p => p.Value.Value == colShape.Handle.Value).FirstOrDefault().Key;
|
||||
// playerInColShape[houseId].Add(client);
|
||||
// House house = GetHouseById(houseId);
|
||||
// User user = client.GetUser();
|
||||
|
||||
// client.TriggerEvent("SERVER:ShowHouseMenu");
|
||||
// SendPlayerHouseData(client, house);
|
||||
// }
|
||||
|
||||
// private static void SendPlayerHouseData(Player player, House house)
|
||||
// {
|
||||
// User user = player.GetUser();
|
||||
// var userHouseStatus = -1;
|
||||
|
||||
// using (var dbContext = new DatabaseContext())
|
||||
// {
|
||||
// if (house.OwnerId == null) userHouseStatus = 0;
|
||||
// else if (house.OwnerId == user?.Id) userHouseStatus = 1;
|
||||
// else if (dbContext.HouseRentals.Where(h => h.HouseId == house.Id && h.UserId == user.Id).Count() == 1) userHouseStatus = 2;
|
||||
|
||||
// var rentals = dbContext.HouseRentals.Where(h => h.HouseId == house.Id).Include(h => h.User).Select(h => h.User.Name).ToList();
|
||||
|
||||
// var newHouse = new
|
||||
// {
|
||||
// OwnerName = house.Owner?.Name,
|
||||
// house.RentalFee,
|
||||
// house.Price,
|
||||
// house.Type,
|
||||
// Rentals = rentals
|
||||
// };
|
||||
|
||||
// player.TriggerEvent("SERVER:SetHouseData", JsonConvert.SerializeObject(newHouse), userHouseStatus);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static void RemoveHouse(House house)
|
||||
// {
|
||||
// if (houseMarkers.ContainsKey(house.Id))
|
||||
// {
|
||||
// houseMarkers[house.Id].Entity<Marker>().Delete();
|
||||
// houseMarkers.Remove(house.Id);
|
||||
// }
|
||||
|
||||
// if (houseLabels.ContainsKey(house.Id))
|
||||
// {
|
||||
// houseLabels[house.Id].Entity<TextLabel>().Delete();
|
||||
// houseLabels.Remove(house.Id);
|
||||
// }
|
||||
|
||||
// if (houseColShapes.ContainsKey(house.Id))
|
||||
// {
|
||||
// houseColShapes[house.Id].Entity<ColShape>().Delete();
|
||||
// houseColShapes.Remove(house.Id);
|
||||
// }
|
||||
|
||||
// if (houseBlips.ContainsKey(house.Id))
|
||||
// {
|
||||
// houseBlips[house.Id].Entity<Blip>().Delete();
|
||||
// houseBlips.Remove(house.Id);
|
||||
// }
|
||||
|
||||
// foreach (Player client in playerInColShape[house.Id])
|
||||
// {
|
||||
// client.TriggerEvent("SERVER:CloseHouseMenu");
|
||||
// }
|
||||
// }
|
||||
|
||||
// [RemoteEvent("CLIENT:House_BuyHouse")]
|
||||
// public void HouseManagerBuyHouseEvent(Player player)
|
||||
// {
|
||||
// using (var dbContext = new DatabaseContext())
|
||||
// {
|
||||
// User user = player.GetUser(dbContext);
|
||||
|
||||
// if (user.HouseId != null)
|
||||
// {
|
||||
// ChatService.ErrorMessage(player, "Du kann nicht mehrere Häuser besitzen");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// House house = GetNearHouse(player.Position, dbContext);
|
||||
|
||||
// var userBank = user.BankAccount;
|
||||
|
||||
// if (userBank.Balance < house.Price)
|
||||
// {
|
||||
// ChatService.ErrorMessage(player, $"Du hast nicht genug Geld für das Haus ({house.Price.ToMoneyString()})");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// house.Owner = user;
|
||||
// user.House = house;
|
||||
|
||||
// userBank.Balance -= house.Price;
|
||||
|
||||
// dbContext.SaveChanges();
|
||||
|
||||
// RemoveHouse(house);
|
||||
// LoadHouse(house);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [RemoteEvent("CLIENT:House_SetRentalFee")]
|
||||
// public void HouseManagerSetRentalFeeEvent(Player player, int rentalFee)
|
||||
// {
|
||||
// using (var dbContext = new DatabaseContext())
|
||||
// {
|
||||
// User user = player.GetUser(dbContext);
|
||||
|
||||
// if (user.HouseId == null)
|
||||
// {
|
||||
// ChatService.ErrorMessage(player, "Du besitzt kein Haus");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// House house = GetHouseById(user.HouseId.Value, dbContext);
|
||||
|
||||
// if (DateTime.Now - house.LastRentSetTime < TimeSpan.FromDays(7))
|
||||
// {
|
||||
// DateTime newPossibility = house.LastRentSetTime.AddDays(7);
|
||||
// string dateStr = newPossibility.ToLongDateString();
|
||||
// string timeStr = newPossibility.ToShortTimeString();
|
||||
// player.SendNotification(
|
||||
// $"~r~Die Miete wurde in den letzten 7 Tagen schon verändert. Die nächste Änderung kann am {dateStr} um {timeStr} Uhr geändert werden.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (rentalFee < 0)
|
||||
// {
|
||||
// player.SendNotification("~r~Die Miete darf kein negativer Betrag sein!");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (rentalFee > 5000)
|
||||
// {
|
||||
// player.SendNotification($"~r~Die Miete darf einen Preis von {5000.ToMoneyString()} nicht überschreiten!");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// house.LastRentSetTime = DateTime.Now;
|
||||
// house.RentalFee = rentalFee;
|
||||
|
||||
// dbContext.SaveChanges();
|
||||
|
||||
// player.SendNotification($"Der Mietpreis wurde auf ~g~{rentalFee.ToMoneyString()}~s~ gesetzt");
|
||||
|
||||
// RemoveHouse(house);
|
||||
// LoadHouse(house);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [RemoteEvent("CLIENT:House_CancelUserRental")]
|
||||
// public void HouseManagerCancelUserRentalEvent(Player player, string userName)
|
||||
// {
|
||||
// using (var dbContext = new DatabaseContext())
|
||||
// {
|
||||
// User user = player.GetUser(dbContext);
|
||||
// if (user.HouseId == null)
|
||||
// {
|
||||
// ChatService.ErrorMessage(player, "Du besitzt kein Haus");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// User target = dbContext.Users.Where(u => u.Name == userName).FirstOrDefault();
|
||||
// if (target == null)
|
||||
// {
|
||||
// player.SendNotification("~r~Dieser Spieler wurde nicht gefunden.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// House house = GetHouseById(user.HouseId.Value, dbContext);
|
||||
|
||||
// HouseRental rental = dbContext.HouseRentals.Where(h => h.HouseId == house.Id && h.UserId == target.Id).FirstOrDefault();
|
||||
// if (rental == null)
|
||||
// {
|
||||
// player.SendNotification("~r~Der Spieler ist nicht in deinem Haus eingemietet");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// dbContext.HouseRentals.Remove(rental);
|
||||
// dbContext.SaveChanges();
|
||||
|
||||
// target.Player?.SendNotification($"~y~{player.Name}~s~ hat deinen Mietvertrag ~g~gekündigt~s~.");
|
||||
|
||||
// player.SendNotification("Du hast dem Spieler ~y~" + target.Name + "~s~ den Mietvertrag gekündigt.");
|
||||
// SendPlayerHouseData(player, house);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [RemoteEvent("CLIENT:House_RentInHouse")]
|
||||
// public void HouseManagerRentInHouseEvent(Player player)
|
||||
// {
|
||||
// using (var dbContext = new DatabaseContext())
|
||||
// {
|
||||
// User user = player.GetUser(dbContext);
|
||||
// House house = GetNearHouse(player.Position, dbContext);
|
||||
|
||||
// if (house == null)
|
||||
// {
|
||||
// ChatService.ErrorMessage(player, "In deiner Nähe ist kein Haus");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (house.RentalFee == 0)
|
||||
// {
|
||||
// player.SendChatMessage("~r~Dieses Haus hat keinen Platz für Mieter!");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// HouseRental newRental = new HouseRental
|
||||
// {
|
||||
// HouseId = house.Id,
|
||||
// UserId = user.Id
|
||||
// };
|
||||
|
||||
// dbContext.HouseRentals.Add(newRental);
|
||||
|
||||
// dbContext.SaveChanges();
|
||||
|
||||
// player.SendNotification("~g~Du hast dich in das Haus eingemietet");
|
||||
|
||||
// house.User?.SendNotification($"~y~{player.Name}~s~ hat sich in dein Haus eingemietet.");
|
||||
// SendPlayerHouseData(player, house);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [RemoteEvent("CLIENT:House_CancelOwnRental")]
|
||||
// public void HouseManagerCancelOwnRentalEvent(Player player)
|
||||
// {
|
||||
// using (var dbContext = new DatabaseContext())
|
||||
// {
|
||||
// User user = player.GetUser(dbContext);
|
||||
// House house = GetNearHouse(player.Position, dbContext);
|
||||
|
||||
// if (house == null)
|
||||
// {
|
||||
// ChatService.ErrorMessage(player, "In deiner Nähe ist kein Haus");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// HouseRental rental = dbContext.HouseRentals.Where(h => h.HouseId == house.Id && h.UserId == user.Id).FirstOrDefault();
|
||||
|
||||
// if (rental == null)
|
||||
// {
|
||||
// player.SendNotification("~r~Du bist nin diesem Haus nicht eingemietet");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// dbContext.HouseRentals.Remove(rental);
|
||||
|
||||
// dbContext.SaveChanges();
|
||||
|
||||
// player.SendNotification("~g~Du hast den Mietvertrag gekündigt.");
|
||||
// house.User?.SendNotification($"~y~{player.Name}~s~ hat seinen Mietvertrag gekündigt.");
|
||||
|
||||
// RemoveHouse(house);
|
||||
// LoadHouse(house);
|
||||
|
||||
// SendPlayerHouseData(player, house);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [RemoteEvent("CLIENT:House_SellHouse")]
|
||||
// public void HouseManagerSellHouseEvent(Player player)
|
||||
// {
|
||||
// using (var dbContext = new DatabaseContext())
|
||||
// {
|
||||
// User user = player.GetUser(dbContext);
|
||||
// if (user.HouseId == null)
|
||||
// {
|
||||
// ChatService.ErrorMessage(player, "Du besitzt kein Haus");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// House house = GetHouseById(user.HouseId.Value, dbContext);
|
||||
// house.OwnerId = null;
|
||||
// user.HouseId = null;
|
||||
|
||||
// var backMoney = (int)(house.Price * 0.4);
|
||||
|
||||
// ChatService.SendMessage(player, "Du bekommst vom Hausverkauf ~g~" + backMoney.ToMoneyString() + "~s~ zurück.");
|
||||
|
||||
// user.BankAccount.Balance += backMoney;
|
||||
|
||||
// dbContext.SaveChanges();
|
||||
|
||||
// player.SendChatMessage("!{#81F7BE}* Du hast dein Haus verkauft.");
|
||||
|
||||
// RemoveHouse(house);
|
||||
// LoadHouse(house);
|
||||
|
||||
// SendPlayerHouseData(player, house);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
using GTANetworkAPI;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ReallifeGamemode.Server.Managers
|
||||
{
|
||||
public class InteriorManager : Script
|
||||
{
|
||||
public static Dictionary<int, NetHandle> _interiorEnterTextLabels = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorExitTextLabels = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorEnterMarkers = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorExitMarkers = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorEnterColShapes = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorExitColShapes = new Dictionary<int, NetHandle>();
|
||||
|
||||
public static Interior GetInteriorByName(string name, DatabaseContext dbContext = null)
|
||||
{
|
||||
if (dbContext == null)
|
||||
{
|
||||
using (dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Interiors.Where(i => i.Name.ToLower() == name.ToLower()).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return dbContext.Interiors.Where(i => i.Name.ToLower() == name.ToLower()).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public static Interior GetInteriorById(int id, DatabaseContext dbContext = null)
|
||||
{
|
||||
if (dbContext == null)
|
||||
{
|
||||
using (dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Interiors.Where(i => i.Id == id).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return dbContext.Interiors.Where(i => i.Id == id).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadInteriors()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach (Interior interior in dbContext.Interiors)
|
||||
{
|
||||
LoadInterior(interior);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadInterior(Interior interior)
|
||||
{
|
||||
if (interior.EnterPosition != null)
|
||||
{
|
||||
_interiorEnterTextLabels[interior.Id] = NAPI.TextLabel.CreateTextLabel("~y~" + interior.Name + "\n~s~Eingang", interior.EnterPosition, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
_interiorEnterMarkers[interior.Id] = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, interior.EnterPosition.Subtract(new Vector3(0, 0, 1.7)), new Vector3(), new Vector3(), 1.6f, new Color(255, 255, 255, 100));
|
||||
_interiorEnterColShapes[interior.Id] = NAPI.ColShape.CreateSphereColShape(interior.EnterPosition, 1.5f);
|
||||
}
|
||||
|
||||
if (interior.ExitPosition != null)
|
||||
{
|
||||
_interiorExitTextLabels[interior.Id] = NAPI.TextLabel.CreateTextLabel("~y~" + interior.Name + "\n~s~Ausgang", interior.ExitPosition, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
_interiorExitMarkers[interior.Id] = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, interior.ExitPosition.Subtract(new Vector3(0, 0, 1.7)), new Vector3(), new Vector3(), 1.6f, new Color(255, 255, 255, 100));
|
||||
_interiorExitColShapes[interior.Id] = NAPI.ColShape.CreateSphereColShape(interior.ExitPosition, 1.5f);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteInterior(Interior interior)
|
||||
{
|
||||
TextLabel enT = GetInteriorEnterTextLabel(interior);
|
||||
TextLabel exT = GetInteriorExitTextLabel(interior);
|
||||
Marker enM = GetInteriorEnterMarker(interior);
|
||||
Marker exM = GetInteriorExitMarkers(interior);
|
||||
ColShape enC = GetInteriorEnterColShape(interior);
|
||||
ColShape exC = GetInteriorExitColShape(interior);
|
||||
|
||||
if (enT != null) enT.Delete();
|
||||
if (exT != null) exT.Delete();
|
||||
if (enM != null) enM.Delete();
|
||||
if (exM != null) exM.Delete();
|
||||
if (enC != null) enC.Delete();
|
||||
if (exC != null) exC.Delete();
|
||||
|
||||
_interiorEnterTextLabels.Remove(interior.Id);
|
||||
_interiorExitTextLabels.Remove(interior.Id);
|
||||
_interiorEnterMarkers.Remove(interior.Id);
|
||||
_interiorExitMarkers.Remove(interior.Id);
|
||||
_interiorEnterColShapes.Remove(interior.Id);
|
||||
_interiorExitColShapes.Remove(interior.Id);
|
||||
}
|
||||
|
||||
public static TextLabel GetInteriorEnterTextLabel(Interior interior) => NAPI.Pools.GetAllTextLabels().Find(t => t.Handle.Value == _interiorEnterTextLabels.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
public static TextLabel GetInteriorExitTextLabel(Interior interior) => NAPI.Pools.GetAllTextLabels().Find(t => t.Handle.Value == _interiorExitTextLabels.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
|
||||
public static Marker GetInteriorEnterMarker(Interior interior) => NAPI.Pools.GetAllMarkers().Find(t => t.Handle.Value == _interiorEnterMarkers.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
public static Marker GetInteriorExitMarkers(Interior interior) => NAPI.Pools.GetAllMarkers().Find(t => t.Handle.Value == _interiorExitMarkers.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
|
||||
public static ColShape GetInteriorEnterColShape(Interior interior) => NAPI.Pools.GetAllColShapes().Find(t => t.Handle.Value == _interiorEnterColShapes.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
public static ColShape GetInteriorExitColShape(Interior interior) => NAPI.Pools.GetAllColShapes().Find(t => t.Handle.Value == _interiorExitColShapes.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
|
||||
public static int GetInteriorIdFromEnterColShape(NetHandle handle) => _interiorEnterColShapes.FirstOrDefault(c => c.Value.Value == handle.Value).Key;
|
||||
public static int GetInteriorIdFromExitColShape(NetHandle handle) => _interiorExitColShapes.FirstOrDefault(c => c.Value.Value == handle.Value).Key;
|
||||
|
||||
[ServerEvent(Event.PlayerEnterColshape)]
|
||||
public void InteriorManagerPlayerEnterColshapeEvent(ColShape colShape, Player player)
|
||||
{
|
||||
int enterId = GetInteriorIdFromEnterColShape(colShape);
|
||||
int exitId = GetInteriorIdFromExitColShape(colShape);
|
||||
if (enterId != 0)
|
||||
{
|
||||
Interior interior = GetInteriorById(enterId);
|
||||
player.TriggerEvent("InteriorManager_ShowHelpText", interior.Name, interior.Id, 0);
|
||||
}
|
||||
else if (exitId != 0)
|
||||
{
|
||||
Interior interior = GetInteriorById(exitId);
|
||||
player.TriggerEvent("InteriorManager_ShowHelpText", interior.Name, interior.Id, 1);
|
||||
}
|
||||
}
|
||||
|
||||
[ServerEvent(Event.PlayerExitColshape)]
|
||||
public void InteriorManagerPlayerExitColshapeEvent(ColShape colShape, Player player)
|
||||
{
|
||||
if (GetInteriorIdFromEnterColShape(colShape) != 0 || GetInteriorIdFromExitColShape(colShape) != 0)
|
||||
{
|
||||
player.TriggerEvent("InteriorManager_ClearHelpText");
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("InteriorManager_UseTeleport")]
|
||||
public void InteriorManagerUseTeleportEvent(Player player, int id, int enterExit)
|
||||
{
|
||||
Interior interior = GetInteriorById(id);
|
||||
player.Position = enterExit == 0 ? interior.ExitPosition : interior.EnterPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user