added editorconfig and formatted code
This commit is contained in:
@@ -9,102 +9,102 @@ using ReallifeGamemode.Server.Models;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory
|
||||
{
|
||||
public class GroundItem : Script
|
||||
public class GroundItem : Script
|
||||
{
|
||||
public int ItemId { get; set; }
|
||||
public int Amount { get; set; }
|
||||
public Vector3 Position { get; set; }
|
||||
|
||||
public static List<GroundItem> GroundItems = new List<GroundItem>();
|
||||
public static List<GTANetworkAPI.Object> GroundObjects = new List<GTANetworkAPI.Object>();
|
||||
public static List<TextLabel> GroundTextLabels = new List<TextLabel>();
|
||||
|
||||
public static void AddGroundItem(GroundItem grndItem, GTANetworkAPI.Object grndObject, TextLabel grndTextLabel)
|
||||
{
|
||||
public int ItemId { get; set; }
|
||||
public int Amount { get; set; }
|
||||
public Vector3 Position { get; set; }
|
||||
|
||||
public static List<GroundItem> GroundItems = new List<GroundItem>();
|
||||
public static List<GTANetworkAPI.Object> GroundObjects = new List<GTANetworkAPI.Object>();
|
||||
public static List<TextLabel> GroundTextLabels = new List<TextLabel>();
|
||||
|
||||
public static void AddGroundItem(GroundItem grndItem, GTANetworkAPI.Object grndObject, TextLabel grndTextLabel)
|
||||
{
|
||||
GroundItems.Add(grndItem);
|
||||
GroundObjects.Add(grndObject);
|
||||
GroundTextLabels.Add(grndTextLabel);
|
||||
}
|
||||
|
||||
public static void PickUpGroundItem(Client player)
|
||||
{
|
||||
GroundItem nearest = GroundItems.FirstOrDefault(d => d.Position.DistanceTo(player.Position) <= 1.2);
|
||||
if (nearest != null)
|
||||
{
|
||||
var invWeight = InventoryManager.GetUserInventoryWeight(player);
|
||||
var itemsToAdd = 0;
|
||||
GTANetworkAPI.Object nearestObject = GroundObjects.FirstOrDefault(d => d.Position == nearest.Position);
|
||||
TextLabel nearestTextLabel = GroundTextLabels.FirstOrDefault(d => d.Position == nearest.Position);
|
||||
IItem nearestItem = InventoryManager.GetItemById(nearest.ItemId);
|
||||
UserItem existingItem = InventoryManager.UserHasThisItem(player, nearest.ItemId);
|
||||
var user = player.GetUser();
|
||||
if (nearestItem.Gewicht * nearest.Amount + invWeight > 40000)
|
||||
{
|
||||
for (var i = 1; i <= nearest.Amount; i++)
|
||||
{
|
||||
if (invWeight + (i * nearestItem.Gewicht) > 40000)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemsToAdd = i;
|
||||
}
|
||||
}
|
||||
if (itemsToAdd < 1)
|
||||
{
|
||||
player.SendNotification("~r~Du hast keinen Platz im Inventar!", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existingItem != null)
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
UserItem existingUserItem = context.UserItems.FirstOrDefault(i => i.Id == existingItem.Id);
|
||||
existingUserItem.Amount += itemsToAdd;
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UserItem newItem = new UserItem { ItemId = nearest.ItemId, UserId = user.Id, Amount = nearest.Amount };
|
||||
InventoryManager.AddItemToInventory(player, newItem);
|
||||
}
|
||||
nearest.Amount -= itemsToAdd;
|
||||
nearestTextLabel.Text = nearestItem.Name + " ~s~(~y~" + nearest.Amount + "~s~)";
|
||||
player.SendNotification("Du hast nur ~g~" + itemsToAdd + " ~y~" + nearestItem.Name + "~s~ aufgehoben.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existingItem != null)
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
UserItem existingUserItem = context.UserItems.FirstOrDefault(i => i.Id == existingItem.Id && i.UserId == user.Id);
|
||||
existingUserItem.Amount += nearest.Amount;
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UserItem item = new UserItem() { ItemId = nearest.ItemId, UserId = user.Id, Amount = nearest.Amount };
|
||||
InventoryManager.AddItemToInventory(player, item);
|
||||
}
|
||||
RemoveGroundItem(nearest, nearestObject, nearestTextLabel);
|
||||
player.SendNotification("Du hast ~g~" + nearest.Amount + " ~y~" + nearestItem.Name + " ~s~aufgehoben.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveGroundItem(GroundItem grndItem, GTANetworkAPI.Object grndObject, TextLabel grndTextLabel)
|
||||
{
|
||||
GroundItems.Remove(grndItem);
|
||||
NAPI.Entity.DeleteEntity(grndObject);
|
||||
NAPI.Entity.DeleteEntity(grndTextLabel);
|
||||
GroundObjects.Remove(grndObject);
|
||||
GroundTextLabels.Remove(grndTextLabel);
|
||||
}
|
||||
GroundItems.Add(grndItem);
|
||||
GroundObjects.Add(grndObject);
|
||||
GroundTextLabels.Add(grndTextLabel);
|
||||
}
|
||||
|
||||
public static void PickUpGroundItem(Client player)
|
||||
{
|
||||
GroundItem nearest = GroundItems.FirstOrDefault(d => d.Position.DistanceTo(player.Position) <= 1.2);
|
||||
if (nearest != null)
|
||||
{
|
||||
var invWeight = InventoryManager.GetUserInventoryWeight(player);
|
||||
var itemsToAdd = 0;
|
||||
GTANetworkAPI.Object nearestObject = GroundObjects.FirstOrDefault(d => d.Position == nearest.Position);
|
||||
TextLabel nearestTextLabel = GroundTextLabels.FirstOrDefault(d => d.Position == nearest.Position);
|
||||
IItem nearestItem = InventoryManager.GetItemById(nearest.ItemId);
|
||||
UserItem existingItem = InventoryManager.UserHasThisItem(player, nearest.ItemId);
|
||||
var user = player.GetUser();
|
||||
if (nearestItem.Gewicht * nearest.Amount + invWeight > 40000)
|
||||
{
|
||||
for (var i = 1; i <= nearest.Amount; i++)
|
||||
{
|
||||
if (invWeight + (i * nearestItem.Gewicht) > 40000)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemsToAdd = i;
|
||||
}
|
||||
}
|
||||
if (itemsToAdd < 1)
|
||||
{
|
||||
player.SendNotification("~r~Du hast keinen Platz im Inventar!", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existingItem != null)
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
UserItem existingUserItem = context.UserItems.FirstOrDefault(i => i.Id == existingItem.Id);
|
||||
existingUserItem.Amount += itemsToAdd;
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UserItem newItem = new UserItem { ItemId = nearest.ItemId, UserId = user.Id, Amount = nearest.Amount };
|
||||
InventoryManager.AddItemToInventory(player, newItem);
|
||||
}
|
||||
nearest.Amount -= itemsToAdd;
|
||||
nearestTextLabel.Text = nearestItem.Name + " ~s~(~y~" + nearest.Amount + "~s~)";
|
||||
player.SendNotification("Du hast nur ~g~" + itemsToAdd + " ~y~" + nearestItem.Name + "~s~ aufgehoben.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existingItem != null)
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
UserItem existingUserItem = context.UserItems.FirstOrDefault(i => i.Id == existingItem.Id && i.UserId == user.Id);
|
||||
existingUserItem.Amount += nearest.Amount;
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UserItem item = new UserItem() { ItemId = nearest.ItemId, UserId = user.Id, Amount = nearest.Amount };
|
||||
InventoryManager.AddItemToInventory(player, item);
|
||||
}
|
||||
RemoveGroundItem(nearest, nearestObject, nearestTextLabel);
|
||||
player.SendNotification("Du hast ~g~" + nearest.Amount + " ~y~" + nearestItem.Name + " ~s~aufgehoben.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveGroundItem(GroundItem grndItem, GTANetworkAPI.Object grndObject, TextLabel grndTextLabel)
|
||||
{
|
||||
GroundItems.Remove(grndItem);
|
||||
NAPI.Entity.DeleteEntity(grndObject);
|
||||
NAPI.Entity.DeleteEntity(grndTextLabel);
|
||||
GroundObjects.Remove(grndObject);
|
||||
GroundTextLabels.Remove(grndTextLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Interfaces
|
||||
{
|
||||
public interface IDroppableItem : IItem
|
||||
{
|
||||
uint Object { get; }
|
||||
}
|
||||
public interface IDroppableItem : IItem
|
||||
{
|
||||
uint Object { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Interfaces
|
||||
{
|
||||
public interface IItem
|
||||
{
|
||||
int Id { get; }
|
||||
string Name { get; }
|
||||
string Description { get; }
|
||||
int Gewicht { get; }
|
||||
string Einheit { get; }
|
||||
}
|
||||
public interface IItem
|
||||
{
|
||||
int Id { get; }
|
||||
string Name { get; }
|
||||
string Description { get; }
|
||||
int Gewicht { get; }
|
||||
string Einheit { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Interfaces
|
||||
{
|
||||
public interface IUsableItem : IItem, IDroppableItem
|
||||
{
|
||||
void Use(UserItem uItem);
|
||||
}
|
||||
public interface IUsableItem : IItem, IDroppableItem
|
||||
{
|
||||
void Use(UserItem uItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Items
|
||||
{
|
||||
public class Cheeseburger : FoodItem
|
||||
{
|
||||
public override int Id => 2;
|
||||
public override string Name => "Cheeseburger";
|
||||
public override string Description => "Wie der Hamburger, nur mit Käse.";
|
||||
public override int Gewicht => 320;
|
||||
public override string Einheit => "g";
|
||||
public override int HpAmount => 20;
|
||||
public override uint Object => 2240524752;
|
||||
}
|
||||
public class Cheeseburger : FoodItem
|
||||
{
|
||||
public override int Id => 2;
|
||||
public override string Name => "Cheeseburger";
|
||||
public override string Description => "Wie der Hamburger, nur mit Käse.";
|
||||
public override int Gewicht => 320;
|
||||
public override string Einheit => "g";
|
||||
public override int HpAmount => 20;
|
||||
public override uint Object => 2240524752;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Items
|
||||
{
|
||||
public class Chickenburger : FoodItem
|
||||
{
|
||||
public override int Id => 3;
|
||||
public override string Name => "Chickenburger";
|
||||
public override string Description => "Hühnchenburger";
|
||||
public override int Gewicht => 330;
|
||||
public override string Einheit => "g";
|
||||
public override int HpAmount => 25;
|
||||
public override uint Object => 2240524752;
|
||||
}
|
||||
public class Chickenburger : FoodItem
|
||||
{
|
||||
public override int Id => 3;
|
||||
public override string Name => "Chickenburger";
|
||||
public override string Description => "Hühnchenburger";
|
||||
public override int Gewicht => 330;
|
||||
public override string Einheit => "g";
|
||||
public override int HpAmount => 25;
|
||||
public override uint Object => 2240524752;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,20 +9,20 @@ using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Items
|
||||
{
|
||||
public abstract class DropItem : IDroppableItem
|
||||
{
|
||||
public abstract int HpAmount { get; }
|
||||
public abstract int Id { get; }
|
||||
public abstract string Name { get; }
|
||||
public abstract string Description { get; }
|
||||
public abstract int Gewicht { get; }
|
||||
public abstract string Einheit { get; }
|
||||
public abstract uint Object { get; }
|
||||
public abstract class DropItem : IDroppableItem
|
||||
{
|
||||
public abstract int HpAmount { get; }
|
||||
public abstract int Id { get; }
|
||||
public abstract string Name { get; }
|
||||
public abstract string Description { get; }
|
||||
public abstract int Gewicht { get; }
|
||||
public abstract string Einheit { get; }
|
||||
public abstract uint Object { get; }
|
||||
|
||||
public void Drop(UserItem uItem, Client player, int amount)
|
||||
{
|
||||
player.SendNotification("Du hast ~g~" + amount + " ~y~" + InventoryManager.GetItemById(uItem.ItemId).Name + " ~s~weggeworfen.", false);
|
||||
InventoryManager.RemoveUserItem(player.GetUser(), uItem, amount);
|
||||
}
|
||||
public void Drop(UserItem uItem, Client player, int amount)
|
||||
{
|
||||
player.SendNotification("Du hast ~g~" + amount + " ~y~" + InventoryManager.GetItemById(uItem.ItemId).Name + " ~s~weggeworfen.", false);
|
||||
InventoryManager.RemoveUserItem(player.GetUser(), uItem, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,29 +9,29 @@ using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Items
|
||||
{
|
||||
public abstract class FoodItem : IUsableItem
|
||||
public abstract class FoodItem : IUsableItem
|
||||
{
|
||||
public abstract int HpAmount { get; }
|
||||
public abstract int Id { get; }
|
||||
public abstract string Name { get; }
|
||||
public abstract string Description { get; }
|
||||
public abstract int Gewicht { get; }
|
||||
public abstract string Einheit { get; }
|
||||
public abstract uint Object { get; }
|
||||
|
||||
public void Use(UserItem uItem)
|
||||
{
|
||||
public abstract int HpAmount { get; }
|
||||
public abstract int Id { get; }
|
||||
public abstract string Name { get; }
|
||||
public abstract string Description { get; }
|
||||
public abstract int Gewicht { get; }
|
||||
public abstract string Einheit { get; }
|
||||
public abstract uint Object { get; }
|
||||
Client player = uItem.GetUser().Client;
|
||||
|
||||
public void Use(UserItem uItem)
|
||||
{
|
||||
Client player = uItem.GetUser().Client;
|
||||
int amountToAdd = HpAmount;
|
||||
if (player.Health + amountToAdd > 100)
|
||||
{
|
||||
amountToAdd = 100 - player.Health;
|
||||
}
|
||||
|
||||
int amountToAdd = HpAmount;
|
||||
if (player.Health + amountToAdd > 100)
|
||||
{
|
||||
amountToAdd = 100 - player.Health;
|
||||
}
|
||||
|
||||
player.Health += amountToAdd;
|
||||
player.SendNotification("Du hast ein/einen ~y~" + InventoryManager.GetItemById(uItem.ItemId).Name + " ~s~gegessen.", false);
|
||||
InventoryManager.RemoveUserItem(player.GetUser(), uItem, 1);
|
||||
}
|
||||
player.Health += amountToAdd;
|
||||
player.SendNotification("Du hast ein/einen ~y~" + InventoryManager.GetItemById(uItem.ItemId).Name + " ~s~gegessen.", false);
|
||||
InventoryManager.RemoveUserItem(player.GetUser(), uItem, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Items
|
||||
{
|
||||
public class Hamburger : FoodItem
|
||||
{
|
||||
public override int Id => 1;
|
||||
public override string Name => "Hamburger";
|
||||
public override string Description => "Ein leckerer Hamburger.";
|
||||
public override int Gewicht => 300;
|
||||
public override string Einheit => "g";
|
||||
public override int HpAmount => 20;
|
||||
public override uint Object => 2240524752;
|
||||
}
|
||||
public class Hamburger : FoodItem
|
||||
{
|
||||
public override int Id => 1;
|
||||
public override string Name => "Hamburger";
|
||||
public override string Description => "Ein leckerer Hamburger.";
|
||||
public override int Gewicht => 300;
|
||||
public override string Einheit => "g";
|
||||
public override int HpAmount => 20;
|
||||
public override uint Object => 2240524752;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Items
|
||||
{
|
||||
public class Holz : IDroppableItem
|
||||
{
|
||||
public int Id => 4;
|
||||
public string Name => "Holz";
|
||||
public string Description => "Ich und mein Holz.";
|
||||
public int Gewicht => 1000;
|
||||
public string Einheit => "g";
|
||||
public uint Object => 1805779401;
|
||||
}
|
||||
public class Holz : IDroppableItem
|
||||
{
|
||||
public int Id => 4;
|
||||
public string Name => "Holz";
|
||||
public string Description => "Ich und mein Holz.";
|
||||
public int Gewicht => 1000;
|
||||
public string Einheit => "g";
|
||||
public uint Object => 1805779401;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Inventory.Items
|
||||
{
|
||||
public class Kraftstoff : DropItem
|
||||
{
|
||||
public override int Id => 5;
|
||||
public override string Name => "Kraftstoff";
|
||||
public override string Description => "Der Stoff gibt dir Kraft.";
|
||||
public override int Gewicht => 1000;
|
||||
public override string Einheit => "g";
|
||||
public override int HpAmount => 20;
|
||||
public override uint Object => 786272259;
|
||||
}
|
||||
public class Kraftstoff : DropItem
|
||||
{
|
||||
public override int Id => 5;
|
||||
public override string Name => "Kraftstoff";
|
||||
public override string Description => "Der Stoff gibt dir Kraft.";
|
||||
public override int Gewicht => 1000;
|
||||
public override string Einheit => "g";
|
||||
public override int HpAmount => 20;
|
||||
public override uint Object => 786272259;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user