[+] Weapon-Deal System
This commit is contained in:
@@ -20,5 +20,6 @@ namespace ReallifeGamemode.Database.Entities
|
|||||||
public string WeaponModel { get; set; }
|
public string WeaponModel { get; set; }
|
||||||
public int SlotID { get; set; }
|
public int SlotID { get; set; }
|
||||||
public int Rank { get; set; }
|
public int Rank { get; set; }
|
||||||
|
public int Ammount { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1339
ReallifeGamemode.Database/Migrations/20190929202101_FactionWeaponAmount.Designer.cs
generated
Normal file
1339
ReallifeGamemode.Database/Migrations/20190929202101_FactionWeaponAmount.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -410,6 +410,8 @@ namespace ReallifeGamemode.Database.Migrations
|
|||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd();
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<int>("Ammount");
|
||||||
|
|
||||||
b.Property<int?>("FactionId");
|
b.Property<int?>("FactionId");
|
||||||
|
|
||||||
b.Property<int>("Rank");
|
b.Property<int>("Rank");
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
public class EnterVehicle : Script
|
public class EnterVehicle : Script
|
||||||
{
|
{
|
||||||
[ServerEvent(Event.PlayerEnterVehicle)]
|
[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)
|
if (seat != -1)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
public class ExitVehicle:Script
|
public class ExitVehicle:Script
|
||||||
{
|
{
|
||||||
[ServerEvent(Event.PlayerExitVehicleAttempt)]
|
[ServerEvent(Event.PlayerExitVehicleAttempt)]
|
||||||
public void OnPlayerExitVehicle(Client client, Vehicle vehicle)
|
public void OnPlayerExitVehicle(Client client, GTANetworkAPI.Vehicle vehicle)
|
||||||
{
|
{
|
||||||
if (client.VehicleSeat != -1)
|
if (client.VehicleSeat != -1)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -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<string> iName = new List<string>();
|
||||||
List<int> iAmount = new List<int>();
|
List<int> iAmount = new List<int>();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using ReallifeGamemode.Server.Services;
|
|||||||
using ReallifeGamemode.Database;
|
using ReallifeGamemode.Database;
|
||||||
using ReallifeGamemode.Database.Models;
|
using ReallifeGamemode.Database.Models;
|
||||||
using ReallifeGamemode.Server.Util;
|
using ReallifeGamemode.Server.Util;
|
||||||
|
using ReallifeGamemode.Server.Inventory.Interfaces;
|
||||||
/**
|
/**
|
||||||
* @overview Life of German Reallife - Event Key (Key.cs)
|
* @overview Life of German Reallife - Event Key (Key.cs)
|
||||||
* @author VegaZ
|
* @author VegaZ
|
||||||
@@ -235,11 +236,31 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
secondarys.Add("Keine");
|
secondarys.Add("Keine");
|
||||||
melees.Add("Keine");
|
melees.Add("Keine");
|
||||||
specials.Add("Keine");
|
specials.Add("Keine");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using (var context = new DatabaseContext())
|
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();
|
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();
|
Database.Entities.Faction faction = context.Factions.Where(fac => fac.Id == user.FactionId).FirstOrDefault();
|
||||||
|
|
||||||
|
|
||||||
if (faction.WeaponDealTime > 0)
|
if (faction.WeaponDealTime > 0)
|
||||||
dealTime = "noch " + faction.WeaponDealTime.ToString()+" min. übrig";
|
dealTime = "noch " + faction.WeaponDealTime.ToString()+" min. übrig";
|
||||||
@@ -248,6 +269,8 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
|
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
|
if (weapon.Ammount <= 0)
|
||||||
|
continue;
|
||||||
switch (weapon.SlotID)
|
switch (weapon.SlotID)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
|||||||
@@ -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
|
namespace ReallifeGamemode.Server.Events
|
||||||
{
|
{
|
||||||
@@ -63,10 +68,10 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
if (meleeModel.Contains("mk2") && !meleeModel.Contains("_mk2")) meleeModel = meleeModel.Replace("mk2", "_mk2");
|
if (meleeModel.Contains("mk2") && !meleeModel.Contains("_mk2")) meleeModel = meleeModel.Replace("mk2", "_mk2");
|
||||||
melee = NAPI.Util.GetHashKey($"weapon_{meleeModel}");
|
melee = NAPI.Util.GetHashKey($"weapon_{meleeModel}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
client.GiveWeapon((WeaponHash)primary, 50);
|
||||||
client.GiveWeapon((WeaponHash)primary, 150);
|
client.GiveWeapon((WeaponHash)secondary, 150);
|
||||||
client.GiveWeapon((WeaponHash)secondary, 600);
|
|
||||||
client.GiveWeapon((WeaponHash)melee, 1);
|
client.GiveWeapon((WeaponHash)melee, 1);
|
||||||
if(specialModel != "Schutzweste")
|
if(specialModel != "Schutzweste")
|
||||||
{
|
{
|
||||||
@@ -77,9 +82,29 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
special = NAPI.Util.GetHashKey($"weapon_{specialModel}");
|
special = NAPI.Util.GetHashKey($"weapon_{specialModel}");
|
||||||
}
|
}
|
||||||
client.GiveWeapon((WeaponHash)special, 50);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ using System.Text;
|
|||||||
|
|
||||||
namespace ReallifeGamemode.Server.Inventory.Items
|
namespace ReallifeGamemode.Server.Inventory.Items
|
||||||
{
|
{
|
||||||
public class Pistol05 : WeaponDealItem
|
public class Pistol50 : WeaponDealItem
|
||||||
{
|
{
|
||||||
public override int Id => 11;
|
public override int Id => 11;
|
||||||
public override string Name => "Pistol05";
|
public override string Name => "Pistol50";
|
||||||
public override string Description => "Waffe";
|
public override string Description => "Waffe";
|
||||||
public override int Gewicht => 1180;
|
public override int Gewicht => 1180;
|
||||||
public override string Einheit => "g";
|
public override string Einheit => "g";
|
||||||
@@ -44,12 +44,10 @@ namespace ReallifeGamemode.Server.WeaponDeal
|
|||||||
WeaponDealPoints.factionWeaponDeal[user.FactionId.Value] = -1;
|
WeaponDealPoints.factionWeaponDeal[user.FactionId.Value] = -1;
|
||||||
user.Faction.WeaponDealTime = 60;
|
user.Faction.WeaponDealTime = 60;
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ChatService.ErrorMessage(client, "Du kannst noch kein Waffendeal starten");
|
ChatService.ErrorMessage(client, "Du kannst noch kein Waffendeal starten");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +67,7 @@ namespace ReallifeGamemode.Server.WeaponDeal
|
|||||||
fVeh.SetData("WeaponDealLoad", true);
|
fVeh.SetData("WeaponDealLoad", true);
|
||||||
InventoryManager.RemoveAllItemsfromVehicleInventory(fVeh);
|
InventoryManager.RemoveAllItemsfromVehicleInventory(fVeh);
|
||||||
Random rnd = new Random();
|
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
|
VehicleItem item = new VehicleItem() { ItemId = 11, VehicleId = factionVehicle.Id, Amount = rnd.Next(45, 100) }; //pistole
|
||||||
InventoryManager.AddItemToVehicleInventory(client, item, fVeh);
|
InventoryManager.AddItemToVehicleInventory(client, item, fVeh);
|
||||||
|
|||||||
Reference in New Issue
Block a user