Heal Decision / JobManager dadurch angepasst
This commit is contained in:
@@ -136,7 +136,8 @@ export default function keys(globalData: IGlobalData) {
|
||||
//J // Job Starten
|
||||
mp.keys.bind(0x4A, false, () => {
|
||||
if (!globalData.InChat && globalData.LoggedIn && !globalData.InTuning) {
|
||||
mp.events.callRemote("CLIENT:JobManager_ShowJobMenu");
|
||||
//mp.events.callRemote("CLIENT:JobManager_ShowJobMenu");
|
||||
mp.events.callRemote("keyPress:J");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -347,7 +347,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
}
|
||||
|
||||
[Command("heal", "~m~Benutzung: ~s~/heal [Spieler] (Preis)")] //TODO Eventuell noch mit Geldbetrag wie bei SA:MP
|
||||
public void CmdFactionMedicHealive(Player player, string receiver, int price = 100)
|
||||
public void CmdFactionMedicHealive(Player player, string receiver, int price = 10)
|
||||
{
|
||||
Player target = PlayerService.GetPlayerByNameOrId(receiver);
|
||||
if (player.GetUser()?.FactionId != 2)
|
||||
@@ -391,28 +391,9 @@ namespace ReallifeGamemode.Server.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
using var dbContext = new DatabaseContext();
|
||||
User targetUser = target.GetUser(dbContext);
|
||||
|
||||
if (targetUser.Handmoney >= price)
|
||||
{
|
||||
targetUser.Handmoney -= price;
|
||||
}
|
||||
else
|
||||
{
|
||||
int bankMoney = price - targetUser.Handmoney;
|
||||
targetUser.Handmoney = 0;
|
||||
targetUser.BankAccount.Balance -= bankMoney;
|
||||
}
|
||||
|
||||
dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Id == 2).First().BankAccount.Balance += price;
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
target.Health = 100;
|
||||
target.SendNotification($"Du wurdest von ~g~{player.Name} ~s~ für ~g~{price.ToMoneyString()} geheilt.", false);
|
||||
player.SendNotification($"Du hast ~g~{target.Name} ~s~ für {price.ToMoneyString()} geheilt.", false);
|
||||
player.TriggerEvent("delHealTask");
|
||||
ChatService.SendMessage(target,"~g~" + player.GetUser().Name + " ~s~möchte dich für ~g~$" + price + " ~s~heilen. Drücke ~g~J~s~ zum Erlauben oder ~r~N ~s~zum Verbieten");
|
||||
target.SetData<bool>("healDecision", true);
|
||||
Medic.HealDecisions.Add(new Medic.HealDecision {dMedic = player, dTarget = target, dPrice = price});
|
||||
}
|
||||
|
||||
#endregion Sanitäter Commands
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
@@ -11,6 +12,7 @@ using ReallifeGamemode.Server.Factions.Medic;
|
||||
using ReallifeGamemode.Server.Finance;
|
||||
using ReallifeGamemode.Server.Inventory;
|
||||
using ReallifeGamemode.Server.Inventory.Interfaces;
|
||||
using ReallifeGamemode.Server.Job;
|
||||
using ReallifeGamemode.Server.Managers;
|
||||
using ReallifeGamemode.Server.Services;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
@@ -624,6 +626,71 @@ namespace ReallifeGamemode.Server.Events
|
||||
InventoryManager.SetBackpackItems(player);
|
||||
}
|
||||
|
||||
[RemoteEvent("keyPress:J")]
|
||||
public void KeyPressJ(Player player)
|
||||
{
|
||||
if (!player.IsLoggedIn()) return;
|
||||
if (player.GetData<bool>("healDecision") == true)
|
||||
{
|
||||
player.SetData<bool>("healDecision", false);
|
||||
Medic.MakeHealDecision(player, true);
|
||||
}
|
||||
|
||||
User u = player.GetUser();
|
||||
|
||||
if (u.JobId == null) return;
|
||||
|
||||
JobBase job = JobManager.GetJob(u.JobId.Value);
|
||||
|
||||
dynamic data = null;
|
||||
|
||||
if (job.Id == 1 && job.GetUsersInJob().Contains(player))
|
||||
{
|
||||
var taxiCalls = JobManager.GetJob<TaxiDriverJob>().TaxiContracts;
|
||||
if (!taxiCalls.Any(t => t.Driver?.Handle == player.Handle)) // Spieler in keiner aktiven Fahrt
|
||||
{
|
||||
data = new
|
||||
{
|
||||
job.Id,
|
||||
Status = 0,
|
||||
JobData = new
|
||||
{
|
||||
TaxiCalls = taxiCalls
|
||||
.Where(t => t.Driver == null)
|
||||
.Select(t => new
|
||||
{
|
||||
t.Name,
|
||||
Distance = Math.Round(t.Position.DistanceTo(player.Position), 0)
|
||||
})
|
||||
.OrderBy(t => t.Distance)
|
||||
}
|
||||
};
|
||||
}
|
||||
else // Spieler in aktiver Fahrt
|
||||
{
|
||||
data = new
|
||||
{
|
||||
job.Id,
|
||||
Status = 1,
|
||||
JobData = new
|
||||
{
|
||||
taxiCalls.Where(t => t.Driver.Handle == player.Handle).First().Name
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
//JobPoint nearJobPoint = PositionManager.JobPoints.Find(p => p.Position.DistanceTo(player.Position) <= 2);
|
||||
if (u.JobId == 2 || u.JobId == 3 || u.JobId == 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var json = JsonConvert.SerializeObject(data);
|
||||
|
||||
player.TriggerEvent("SERVER:Job_ShowJobMenu", job.Name, json);
|
||||
}
|
||||
|
||||
|
||||
[RemoteEvent("keyPress:O")]
|
||||
public void KeyPressO(Player player)
|
||||
{
|
||||
@@ -715,6 +782,12 @@ namespace ReallifeGamemode.Server.Events
|
||||
if (!player.IsInVehicle) return;
|
||||
if (player.VehicleSeat != 0) return;
|
||||
|
||||
if (player.GetData<bool>("healDecision") == true)
|
||||
{
|
||||
player.SetData<bool>("healDecision", true);
|
||||
Medic.MakeHealDecision(player, false);
|
||||
}
|
||||
|
||||
GTANetworkAPI.Vehicle v = player.Vehicle;
|
||||
|
||||
User u = player.GetUser();
|
||||
|
||||
@@ -8,6 +8,7 @@ using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Server Factions Medic Medic.cs
|
||||
@@ -22,10 +23,18 @@ namespace ReallifeGamemode.Server.Factions.Medic
|
||||
public static List<MedicTask> ReviveTasks = new List<MedicTask>();
|
||||
public static List<MedicTask> HealTasks = new List<MedicTask>();
|
||||
public static List<MedicTask> FireTasks = new List<MedicTask>();
|
||||
public static List<HealDecision> HealDecisions = new List<HealDecision>();
|
||||
public static int ReviveIncome = 100;
|
||||
public static int dutyMedics = 0;
|
||||
public static int reviveTaskTime = 240;
|
||||
|
||||
public class HealDecision
|
||||
{
|
||||
public Player dMedic;
|
||||
public Player dTarget;
|
||||
public int dPrice;
|
||||
}
|
||||
|
||||
public static void AddTaskToList(MedicTask task)
|
||||
{
|
||||
if (task == null)
|
||||
@@ -72,6 +81,45 @@ namespace ReallifeGamemode.Server.Factions.Medic
|
||||
}
|
||||
}
|
||||
|
||||
public static void MakeHealDecision(Player target, bool decision)
|
||||
{
|
||||
var activeDecision = HealDecisions.FirstOrDefault(d => d.dTarget == target);
|
||||
if(decision == false)
|
||||
{
|
||||
ChatService.SendMessage(activeDecision.dMedic, activeDecision.dTarget + " hat den Heal abgelehnt");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatService.SendMessage(activeDecision.dMedic, activeDecision.dTarget + " hat den Heal akzeptiert");
|
||||
using var dbContext = new DatabaseContext();
|
||||
{
|
||||
User targetUser = target.GetUser(dbContext);
|
||||
|
||||
if (targetUser.Handmoney >= activeDecision.dPrice)
|
||||
{
|
||||
targetUser.Handmoney -= activeDecision.dPrice;
|
||||
}
|
||||
else
|
||||
{
|
||||
int bankMoney = activeDecision.dPrice - targetUser.Handmoney;
|
||||
targetUser.Handmoney = 0;
|
||||
targetUser.BankAccount.Balance -= bankMoney;
|
||||
}
|
||||
|
||||
dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Id == 2).First().BankAccount.Balance += activeDecision.dPrice / 2;
|
||||
activeDecision.dMedic.GetUser(dbContext).Wage += activeDecision.dPrice / 2;
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
activeDecision.dTarget.Health = 100;
|
||||
activeDecision.dTarget.SendNotification($"Du wurdest von ~g~{activeDecision.dMedic.Name} ~s~ für ~g~{activeDecision.dPrice.ToMoneyString()} geheilt", false);
|
||||
activeDecision.dMedic.SendNotification($"Du hast ~g~{activeDecision.dTarget.Name} ~s~ für {activeDecision.dPrice.ToMoneyString()} geheilt", false);
|
||||
delHealTask(activeDecision.dTarget);
|
||||
}
|
||||
HealDecisions.Remove(activeDecision);
|
||||
}
|
||||
|
||||
public static void UpdateTaskTimeLeft()
|
||||
{
|
||||
DateTime actualTime = DateTime.Now;
|
||||
@@ -139,7 +187,7 @@ namespace ReallifeGamemode.Server.Factions.Medic
|
||||
public static void delHealTask(Player player)
|
||||
{
|
||||
MedicTask task = HealTasks.FirstOrDefault(t => t.Victim == player.Name);
|
||||
RemoveTaskFromList(task);
|
||||
if(task != null) RemoveTaskFromList(task);
|
||||
player.SetData("healauftrag", false);
|
||||
}
|
||||
|
||||
|
||||
@@ -124,63 +124,6 @@ namespace ReallifeGamemode.Server.Managers
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:JobManager_ShowJobMenu")]
|
||||
public void ShowJobMenuEvent(Player player)
|
||||
{
|
||||
User u = player.GetUser();
|
||||
|
||||
if (u.JobId == null) return;
|
||||
|
||||
JobBase job = GetJob(u.JobId.Value);
|
||||
|
||||
dynamic data = null;
|
||||
|
||||
if (job.Id == 1 && job.GetUsersInJob().Contains(player))
|
||||
{
|
||||
var taxiCalls = JobManager.GetJob<TaxiDriverJob>().TaxiContracts;
|
||||
if (!taxiCalls.Any(t => t.Driver?.Handle == player.Handle)) // Spieler in keiner aktiven Fahrt
|
||||
{
|
||||
data = new
|
||||
{
|
||||
job.Id,
|
||||
Status = 0,
|
||||
JobData = new
|
||||
{
|
||||
TaxiCalls = taxiCalls
|
||||
.Where(t => t.Driver == null)
|
||||
.Select(t => new
|
||||
{
|
||||
t.Name,
|
||||
Distance = Math.Round(t.Position.DistanceTo(player.Position), 0)
|
||||
})
|
||||
.OrderBy(t => t.Distance)
|
||||
}
|
||||
};
|
||||
}
|
||||
else // Spieler in aktiver Fahrt
|
||||
{
|
||||
data = new
|
||||
{
|
||||
job.Id,
|
||||
Status = 1,
|
||||
JobData = new
|
||||
{
|
||||
taxiCalls.Where(t => t.Driver.Handle == player.Handle).First().Name
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
//JobPoint nearJobPoint = PositionManager.JobPoints.Find(p => p.Position.DistanceTo(player.Position) <= 2);
|
||||
if (u.JobId == 2 || u.JobId == 3 || u.JobId == 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var json = JsonConvert.SerializeObject(data);
|
||||
|
||||
player.TriggerEvent("SERVER:Job_ShowJobMenu", job.Name, json);
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:Job_StartJob")]
|
||||
public void StartJobEvent(Player player)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user