Changed whole project structure (split client and server into separat projects)
This commit is contained in:
110
ReallifeGamemode.Server/Inventory/GroundItem.cs
Normal file
110
ReallifeGamemode.Server/Inventory/GroundItem.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System.Collections.Generic;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using System.Linq;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Models;
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Interfaces DroppableItem (IDroppableItem.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Interfaces
|
||||
{
|
||||
public interface IDroppableItem : IItem
|
||||
{
|
||||
uint Object { get; }
|
||||
}
|
||||
}
|
||||
21
ReallifeGamemode.Server/Inventory/Interfaces/IItem.cs
Normal file
21
ReallifeGamemode.Server/Inventory/Interfaces/IItem.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Interfaces Item (IItem.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Interfaces
|
||||
{
|
||||
public interface IItem
|
||||
{
|
||||
int Id { get; }
|
||||
string Name { get; }
|
||||
string Description { get; }
|
||||
int Gewicht { get; }
|
||||
string Einheit { get; }
|
||||
}
|
||||
}
|
||||
19
ReallifeGamemode.Server/Inventory/Interfaces/IUsableItem.cs
Normal file
19
ReallifeGamemode.Server/Inventory/Interfaces/IUsableItem.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Interfaces UsableItem (IUsableItem.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Interfaces
|
||||
{
|
||||
public interface IUsableItem : IItem, IDroppableItem
|
||||
{
|
||||
void Use(UserItem uItem);
|
||||
}
|
||||
}
|
||||
24
ReallifeGamemode.Server/Inventory/Items/Cheeseburger.cs
Normal file
24
ReallifeGamemode.Server/Inventory/Items/Cheeseburger.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Items Cheeseburger (Cheeseburger.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.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;
|
||||
}
|
||||
}
|
||||
24
ReallifeGamemode.Server/Inventory/Items/Chickenburger.cs
Normal file
24
ReallifeGamemode.Server/Inventory/Items/Chickenburger.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Items Chickenburger (Chickenburger.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.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;
|
||||
}
|
||||
}
|
||||
28
ReallifeGamemode.Server/Inventory/Items/DropItem.cs
Normal file
28
ReallifeGamemode.Server/Inventory/Items/DropItem.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
ReallifeGamemode.Server/Inventory/Items/FoodItem.cs
Normal file
37
ReallifeGamemode.Server/Inventory/Items/FoodItem.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Inventory.Items
|
||||
{
|
||||
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)
|
||||
{
|
||||
Client player = uItem.GetUser().GetClient();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
24
ReallifeGamemode.Server/Inventory/Items/Hamburger.cs
Normal file
24
ReallifeGamemode.Server/Inventory/Items/Hamburger.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Items Hamburger (Hamburger.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.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;
|
||||
}
|
||||
}
|
||||
23
ReallifeGamemode.Server/Inventory/Items/Holz.cs
Normal file
23
ReallifeGamemode.Server/Inventory/Items/Holz.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Items Hamburger (Hamburger.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.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;
|
||||
}
|
||||
}
|
||||
24
ReallifeGamemode.Server/Inventory/Items/Kraftstoff.cs
Normal file
24
ReallifeGamemode.Server/Inventory/Items/Kraftstoff.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Inventory Items Hamburger (Hamburger.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user