[+] Weapon-Deal System

This commit is contained in:
Lukas Moungos
2019-10-02 19:40:02 +02:00
parent 8f7ba2a7b5
commit 9ec30fd419
11 changed files with 1426 additions and 15 deletions

View File

@@ -20,5 +20,6 @@ namespace ReallifeGamemode.Database.Entities
public string WeaponModel { get; set; }
public int SlotID { get; set; }
public int Rank { get; set; }
public int Ammount { get; set; }
}
}

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 FactionWeaponAmount : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "Ammount",
table: "FactionWeapons",
nullable: false,
defaultValue: 0);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Ammount",
table: "FactionWeapons");
}
}
}

View File

@@ -410,6 +410,8 @@ namespace ReallifeGamemode.Database.Migrations
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("Ammount");
b.Property<int?>("FactionId");
b.Property<int>("Rank");

View File

@@ -12,7 +12,7 @@ namespace ReallifeGamemode.Server.Events
public class EnterVehicle : Script
{
[ServerEvent(Event.PlayerEnterVehicle)]
public void OnPlayerEnterVehicle(Client client, Vehicle vehicle, sbyte seat)
public void OnPlayerEnterVehicle(Client client, GTANetworkAPI.Vehicle vehicle, sbyte seat)
{
if (seat != -1)
return;

View File

@@ -12,7 +12,7 @@ namespace ReallifeGamemode.Server.Events
public class ExitVehicle:Script
{
[ServerEvent(Event.PlayerExitVehicleAttempt)]
public void OnPlayerExitVehicle(Client client, Vehicle vehicle)
public void OnPlayerExitVehicle(Client client, GTANetworkAPI.Vehicle vehicle)
{
if (client.VehicleSeat != -1)
return;

View File

@@ -40,7 +40,7 @@ namespace ReallifeGamemode.Server.Events
}
}
public List<VehicleInventory> getVehItem(Vehicle veh)
public List<VehicleInventory> getVehItem(GTANetworkAPI.Vehicle veh)
{
List<string> iName = new List<string>();
List<int> iAmount = new List<int>();

View File

@@ -13,6 +13,7 @@ using ReallifeGamemode.Server.Services;
using ReallifeGamemode.Database;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Util;
using ReallifeGamemode.Server.Inventory.Interfaces;
/**
* @overview Life of German Reallife - Event Key (Key.cs)
* @author VegaZ
@@ -235,11 +236,31 @@ namespace ReallifeGamemode.Server.Events
secondarys.Add("Keine");
melees.Add("Keine");
specials.Add("Keine");
using (var context = new DatabaseContext())
{
List<UserItem> fItem = context.UserItems.Where(u => u.UserId == user.Id).ToList();
foreach(var item in fItem)
{
IItem iItem = InventoryManager.GetItemById(item.ItemId);
if(iItem is IWeaponDealItem obj)
{
FactionWeapon weapon = context.FactionWeapons.Where(w => w.FactionId == user.FactionId && w.WeaponModel == iItem.Name).FirstOrDefault();
if (weapon == null)
continue;
weapon.Ammount += item.Amount;
ChatService.SendMessage(player, item.Amount + " " + iItem.Name + " wurden im Waffenlager hinzugefürgt.");
context.Remove(item);
}
}
context.SaveChanges();
List<FactionWeapon> weapons = context.FactionWeapons.Where(w => w.FactionId == user.FactionId).ToList();
Database.Entities.Faction faction = context.Factions.Where(fac => fac.Id == user.FactionId).FirstOrDefault();
if (faction.WeaponDealTime > 0)
dealTime = "noch " + faction.WeaponDealTime.ToString()+" min. übrig";
@@ -248,6 +269,8 @@ namespace ReallifeGamemode.Server.Events
foreach (var weapon in weapons)
{
if (weapon.Ammount <= 0)
continue;
switch (weapon.SlotID)
{
case 1:

View File

@@ -1,4 +1,9 @@
using GTANetworkAPI;
using System.Collections.Generic;
using System.Linq;
using GTANetworkAPI;
using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Extensions;
namespace ReallifeGamemode.Server.Events
{
@@ -63,10 +68,10 @@ namespace ReallifeGamemode.Server.Events
if (meleeModel.Contains("mk2") && !meleeModel.Contains("_mk2")) meleeModel = meleeModel.Replace("mk2", "_mk2");
melee = NAPI.Util.GetHashKey($"weapon_{meleeModel}");
}
client.GiveWeapon((WeaponHash)primary, 150);
client.GiveWeapon((WeaponHash)secondary, 600);
client.GiveWeapon((WeaponHash)primary, 50);
client.GiveWeapon((WeaponHash)secondary, 150);
client.GiveWeapon((WeaponHash)melee, 1);
if(specialModel != "Schutzweste")
{
@@ -77,9 +82,29 @@ namespace ReallifeGamemode.Server.Events
special = NAPI.Util.GetHashKey($"weapon_{specialModel}");
}
client.GiveWeapon((WeaponHash)special, 50);
return;
}
client.Armor = 100;
else
{
client.Armor = 50;
}
using(var context = new DatabaseContext())
{
User user = client.GetUser();
FactionWeapon slot1 = context.FactionWeapons.Where(w => w.FactionId == user.FactionId && w.WeaponModel == primaryModel).FirstOrDefault();
if (slot1 != null)
slot1.Ammount -= 1;
FactionWeapon slot2 = context.FactionWeapons.Where(w => w.FactionId == user.FactionId && w.WeaponModel == secondaryModel).FirstOrDefault();
if (slot2 != null)
slot2.Ammount -= 1;
FactionWeapon slot3 = context.FactionWeapons.Where(w => w.FactionId == user.FactionId && w.WeaponModel == meleeModel).FirstOrDefault();
if (slot3 != null)
slot3.Ammount -= 1;
FactionWeapon slot4 = context.FactionWeapons.Where(w => w.FactionId == user.FactionId && w.WeaponModel == specialModel).FirstOrDefault();
if (slot4 != null)
slot4.Ammount -= 1;
context.SaveChanges();
}
}
}
}

View File

@@ -11,10 +11,10 @@ using System.Text;
namespace ReallifeGamemode.Server.Inventory.Items
{
public class Pistol05 : WeaponDealItem
public class Pistol50 : WeaponDealItem
{
public override int Id => 11;
public override string Name => "Pistol05";
public override string Name => "Pistol50";
public override string Description => "Waffe";
public override int Gewicht => 1180;
public override string Einheit => "g";

View File

@@ -44,12 +44,10 @@ namespace ReallifeGamemode.Server.WeaponDeal
WeaponDealPoints.factionWeaponDeal[user.FactionId.Value] = -1;
user.Faction.WeaponDealTime = 60;
context.SaveChanges();
return;
}
else
{
ChatService.ErrorMessage(client, "Du kannst noch kein Waffendeal starten");
return;
}
}
}
@@ -69,7 +67,7 @@ namespace ReallifeGamemode.Server.WeaponDeal
fVeh.SetData("WeaponDealLoad", true);
InventoryManager.RemoveAllItemsfromVehicleInventory(fVeh);
Random rnd = new Random();
if(factionVehicle.Id == 8 || factionVehicle.Id == 7)
if(factionVehicle.FactionId == 8 || factionVehicle.FactionId == 7)
{
VehicleItem item = new VehicleItem() { ItemId = 11, VehicleId = factionVehicle.Id, Amount = rnd.Next(45, 100) }; //pistole
InventoryManager.AddItemToVehicleInventory(client, item, fVeh);