add job menu and start job

This commit is contained in:
hydrant
2019-05-16 18:35:43 +02:00
parent 5b014d6668
commit 2fb1f198cf
10 changed files with 117 additions and 12 deletions

View File

@@ -1,6 +1,8 @@
using GTANetworkAPI;
using ReallifeGamemode.Server.Entities;
using ReallifeGamemode.Server.Managers;
using ReallifeGamemode.Server.Models;
using ReallifeGamemode.Server.Services;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -22,21 +24,31 @@ namespace ReallifeGamemode.Server.Job
public abstract string Name { get; }
public abstract bool NeedVehicleToStart { get; }
public void StartJob(Client player)
{
_inJob.Add(player);
JobStart();
if (NeedVehicleToStart && !GetJobVehicles().Any(v => VehicleManager.GetVehicleFromServerVehicle(v).Handle.Value == player.Vehicle?.Handle.Value))
{
ChatService.Error(player, "Zum Start dieses Jobs musst du in einem Jobfahrzeug sein");
return;
}
JobStart?.Invoke();
}
public void StopJob(Client player)
{
_inJob.Remove(player);
JobStop();
JobStop?.Invoke();
}
public List<JobVehicle> GetJobVehicles()
{
using(var dbContext = new DatabaseContext())
using (var dbContext = new DatabaseContext())
{
return dbContext.JobVehicles.Where(j => j.JobId == Id).ToList();
}