weaponschein fertig

This commit is contained in:
hydrant
2020-03-13 22:51:30 +01:00
parent 6467615a32
commit 359762965d
16 changed files with 1574 additions and 14 deletions

View File

@@ -0,0 +1,41 @@
import game from "..";
import { Key } from "../game";
import { Menu, Point, UIMenuItem } from "../libs/NativeUI";
import { createMenuItem } from "../util";
import moneyformat from "../moneyformat";
var menu: Menu = new Menu("Polizeirevier", "Die Hilfestelle der Polizei", new Point(50, 50));
menu.AddItem(createMenuItem("Waffenschein kaufen", "Erwerbe einen Waffenschein", (item) => {
item.SetRightLabel("$" + moneyformat(5000));
}));
menu.Close();
menu.ItemSelect.on((item, index: number) => {
game.events.callServer("PoliceDepartment_MenuSelect", index);
menu.Close();
});
menu.MenuClose.on(() => {
game.ui.inMenu = false;
});
game.events.add("SERVER:PoliceDepartment_EnterColShape", () => {
game.ui.setHelpText("Drücke ~INPUT_CONTEXT~, um das Menü des Polizeireviers zu öffnen");
game.events.bindKey(Key.E, false, keyPressHandler);
});
game.events.add("SERVER:PoliceDepartment_ExitColShape", () => {
game.ui.clearHelpText();
game.events.unbindKey(Key.E, false, keyPressHandler);
menu.Close();
});
function keyPressHandler() {
game.ui.clearHelpText();
game.ui.inMenu = true;
menu.Open();
}

View File

@@ -141,6 +141,7 @@ export default function keys(globalData: GlobalData) {
//2 // Job Starten
mp.keys.bind(0x4A, false, () => {
mp.gui.chat.push("inchat: " + globalData.InChat + " inInput: " + globalData.InInput + " inMenu: " + globalData.InMenu + " LoggedIn: " + globalData.LoggedIn);
if (!globalData.InChat && !globalData.InInput && !globalData.InMenu && globalData.LoggedIn) {
mp.events.callRemote("CLIENT:JobManager_ShowJobMenu");
}

View File

@@ -16,6 +16,7 @@
<p id="0"></p>
<p id="1"></p>
<p id="2"></p>
<p id="3"></p>
</div>

View File

@@ -11,13 +11,15 @@ function add_licenses(info) {
console.log(infoArr);
for (var i = 0; i < infoArr.length; i++) {
var Schein = "";
if (infoArr[i] == true) {
if (i == 0) {
if (infoArr[i] === true) {
if (i === 0) {
Schein = "Auto";
} else if (i == 1) {
} else if (i === 1) {
Schein = "Motorrad";
} else if (i == 2) {
} else if (i === 2) {
Schein = "Flugzeug";
} else if (i === 3) {
Schein = "Waffen";
}
}
$('#'+i).append(""+Schein);

View File

@@ -32,7 +32,7 @@ export default class RageEvents implements IEvents {
}
callServer(event: string, args?: any[] | any): void {
if (args) {
if (args !== null) {
if (typeof args === 'object') {
args.push(event);
} else {
@@ -41,7 +41,10 @@ export default class RageEvents implements IEvents {
} else {
args = [event];
}
mp.events.callRemote('CLIENT:Event', JSON.stringify(args));
var params = JSON.stringify(args);
mp.events.callRemote('CLIENT:Event', params);
}
bindKey(key: Key, hold: boolean, callback: Function) {

View File

@@ -2,6 +2,14 @@ import { IUi, IBrowser } from "../../game";
import { Menu } from "../../libs/NativeUI/index";
export default class RageUi implements IUi {
setHelpText(text: string): void {
mp.game.ui.setTextComponentFormat('STRING');
mp.game.ui.addTextComponentSubstringPlayerName(text);
mp.game.ui.displayHelpTextFromStringLabel(0, true, true, -1);
}
clearHelpText(): void {
mp.game.ui.clearHelp(true);
}
private _inMenu: boolean = false;
private _activeMenu: Menu = null;

View File

@@ -28,6 +28,8 @@ interface IUi {
openBrower(path: string): IBrowser;
setCursor(freeze: boolean, show: boolean): void;
toggleChat(toggle: boolean): void;
setHelpText(text: string): void;
clearHelpText(): void;
inMenu: boolean;
inChat: boolean;
}
@@ -98,7 +100,8 @@ enum Key {
ENTER = 0x0D,
M = 0x4D,
T = 0x54,
X = 0x58
X = 0x58,
E = 0x45
}
enum VehicleSeat {

View File

@@ -167,7 +167,7 @@ import smoothThrottle from './vehiclesync/smoothtrottle';
smoothThrottle();
import vehicleIndicators from './vehiclesync/vehicleindicators';
vehicleIndicators();
vehicleIndicators();
import reportList from './Player/reportmenu';
reportList(globalData);
@@ -202,6 +202,8 @@ itemShopList(globalData);
import taximeterInput from './Gui/taximeter';
taximeterInput(globalData);
require('./Gui/policedepartment');
interface VehicleData {
EngineState: boolean;
Locked: boolean;

View File

@@ -94,6 +94,8 @@ namespace ReallifeGamemode.Database.Entities
public bool DriverLicenseBike { get; set; } = false;
public bool WeaponLicense { get; set; } = false;
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace ReallifeGamemode.Database.Migrations
{
public partial class UserWeaponLicense : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "WeaponLicense",
table: "Users",
nullable: false,
defaultValue: false);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "WeaponLicense",
table: "Users");
}
}
}

View File

@@ -1026,6 +1026,8 @@ namespace ReallifeGamemode.Database.Migrations
b.Property<int>("Wanteds");
b.Property<bool>("WeaponLicense");
b.HasKey("Id");
b.HasIndex("BanId");

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using ReallifeGamemode.Server.Core.API;
using ReallifeGamemode.Server.Types;
using ReallifeGamemode.Server.Core.Extensions;
namespace ReallifeGamemode.Server.Core.Menus
{
@@ -15,6 +16,42 @@ namespace ReallifeGamemode.Server.Core.Menus
// Marker position: 440.869 -981.045 30.689
CreateVisuals();
EventHandler.RegisterClientEvent("PoliceDepartment_MenuSelect", OnMenuSelect);
}
private void OnMenuSelect(IPlayer player, object[] args)
{
var index = (long)args[0];
using (var dbContext = GetDbContext())
{
var user = player.GetUser(dbContext);
if (index == 0)
{
if (user.WeaponLicense)
{
player.SendMessage("Du besitzt schon einen Waffenschein.", ChatPrefix.Info);
return;
}
var account = user.GetBankAccount(dbContext);
if (account.Balance < 5000)
{
player.SendMessage("Du hast nicht genug Geld auf der Bank (5.000$)!", ChatPrefix.Error);
return;
}
account.Balance -= 5000;
player.SendMessage("Du hast den Waffenschein erfolgreich erworben.", ChatPrefix.Info);
user.WeaponLicense = true;
dbContext.SaveChanges();
}
}
}
private void CreateVisuals()
@@ -22,8 +59,8 @@ namespace ReallifeGamemode.Server.Core.Menus
Position pos = new Position(440.869, -981.045, 30.689);
Api.TextLabel.CreateTextLabel("Polizeirevier\n\nDrücke ~y~E~s~, um das Menü zu öffnen", pos, 20f, 1.3f, Font.ChaletLondon, Color.White);
Api.Marker.CreateMarker(MarkerType.VerticalCylinder, pos.Subtract(new Position(0, 0, 1.5)), new Position(), new Position(), 1f, new Color());
IColShape colShape = Api.ColShape.CreateSphere(pos.Subtract(new Position(0, 0, 1.5)), 3f);
Api.Marker.CreateMarker(MarkerType.VerticalCylinder, pos.Subtract(new Position(0, 0, 1.7)), new Position(), new Position(), 1f, Color.White);
IColShape colShape = Api.ColShape.CreateSphere(pos, 2f);
colShape.OnEntityEnter += OnPlayerEnterPoliceDepartment;
colShape.OnEntityExit += OnPlayerExitPoliceDepartment;
@@ -31,12 +68,12 @@ namespace ReallifeGamemode.Server.Core.Menus
private void OnPlayerEnterPoliceDepartment(IColShape colShape, IPlayer player)
{
player.TriggerEvent("PoliceDepartment_EnterColShape");
}
private void OnPlayerExitPoliceDepartment(IColShape colShape, IPlayer player)
{
player.TriggerEvent("PoliceDepartment_ExitColShape");
}
}
}

View File

@@ -13,6 +13,7 @@
<ProjectReference Include="..\ReallifeGamemode.Server.Common\ReallifeGamemode.Server.Common.csproj" />
<ProjectReference Include="..\ReallifeGamemode.Server.Core.API\ReallifeGamemode.Server.Core.API.csproj" />
<ProjectReference Include="..\ReallifeGamemode.Server.Core.Events\ReallifeGamemode.Server.Core.Events.csproj" />
<ProjectReference Include="..\ReallifeGamemode.Server.Core.Extensions\ReallifeGamemode.Server.Core.Extensions.csproj" />
<ProjectReference Include="..\ReallifeGamemode.Server.Log\ReallifeGamemode.Server.Log.csproj" />
<ProjectReference Include="..\ReallifeGamemode.Server.Types\ReallifeGamemode.Server.Types.csproj" />
</ItemGroup>

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.Logging;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Core.API;
using ReallifeGamemode.Server.Log;
@@ -9,13 +10,17 @@ namespace ReallifeGamemode.Server.Core
{
internal abstract class Script
{
protected IAPI Api { get; } = Main.API;
protected IAPI Api => Main.API;
protected ILogger Log { get; }
protected Events.EventHandler EventHandler => Main.EventHandler;
public Script()
{
Log = LogManager.GetLogger(GetType());
}
protected DatabaseContext GetDbContext() => Main.GetDbContext();
}
}

View File

@@ -140,7 +140,7 @@ namespace ReallifeGamemode.Server.Managers
if (type == "License")
{
if (!playerUser.DriverLicenseBike && !playerUser.DriverLicenseVehicle && !playerUser.FlyingLicensePlane)
if (!playerUser.DriverLicenseBike && !playerUser.DriverLicenseVehicle && !playerUser.FlyingLicensePlane && !playerUser.WeaponLicense)
{
player.SendNotification("~r~Sie besitzen keine Scheine!");
return;
@@ -158,6 +158,7 @@ namespace ReallifeGamemode.Server.Managers
licenses.Add(playerUser.DriverLicenseVehicle);
licenses.Add(playerUser.DriverLicenseBike);
licenses.Add(playerUser.FlyingLicensePlane);
licenses.Add(playerUser.WeaponLicense);
target.TriggerEvent("ShowLicenses", player.Name, licenses.ToArray());
}