More world info;

Improved static code InventoryGrid.cs
This commit is contained in:
Lucca Faria Ferri 2023-02-12 04:50:54 -08:00
parent 7b214381a1
commit 60c3ad5317
2 changed files with 18 additions and 29 deletions

View File

@ -1,5 +1,6 @@
using System.Linq;
using DiIiS_NA.GameServer.GSSystem.ActorSystem.Implementations;
using DiIiS_NA.GameServer.MessageSystem;
using DiIiS_NA.LoginServer.AccountsSystem;
using DiIiS_NA.LoginServer.Battle;
@ -20,7 +21,10 @@ public class WorldCommand : CommandGroup
var world = player.World;
return $"[{world.SNO.ToString()}] - {world.SNO}\n{world.Players.Count} players\n" +
$"{world.Monsters.Count(s=>!s.Dead)} of {world.Monsters.Count} monsters alive\n" +
$"{world.Portals} portal(s)\n" +
$"~ {world.Monsters.Average(s=>s.Attributes[GameAttributes.Level]).ToString("F1")} avg. monsters level\n" +
$"~ {world.Monsters.Average(s=>s.Attributes[GameAttributes.Hitpoints_Max]).ToString("F1")} avg. monsters HP\n" +
$"{world.Portals.Count} portal(s)\n" +
$"{world.GetAllDoors().Length} door(s)\n" +
$"{world.Actors.Count(s=>s.Value is Door)} door(s)\n" +
$"{(world.Game.ActiveNephalemPortal ? "Nephalem portal is active" : "Nephalem portal is inactive")}\n" +
$"{world.Game.ActiveNephalemProgress} nephalem progress";

View File

@ -16,8 +16,8 @@ namespace DiIiS_NA.GameServer.Core
static readonly Logger Logger = LogManager.CreateLogger(nameof(InventoryGrid));
public int EquipmentSlot { get; private set; }
public int Rows { get { return _backpack.GetLength(0); } }
public int Columns { get { return _backpack.GetLength(1); } }
public int Rows => _backpack.GetLength(0);
public int Columns => _backpack.GetLength(1);
public Dictionary<uint, Item> Items { get; private set; }
private uint[,] _backpack;
@ -133,9 +133,8 @@ namespace DiIiS_NA.GameServer.Core
}
}
}
if (_owner is Player)
if (_owner is Player ownerPlayer)
{
var ownerPlayer = _owner as Player;
ownerPlayer.Inventory.RemoveItemFromDB(item);
}
}
@ -194,12 +193,10 @@ namespace DiIiS_NA.GameServer.Core
itm.UpdateStackCount(itm.Attributes[GameAttributes.ItemStackQuantityLo] - estimate);
break;
}
else
{
estimate -= itm.Attributes[GameAttributes.ItemStackQuantityLo];
consumed.Add(itm);
}
}
foreach (var itm in consumed)
{
RemoveItem(itm);
@ -259,9 +256,7 @@ namespace DiIiS_NA.GameServer.Core
{
// Find items of same type (GBID) and try to add it to one of them
List<Item> baseItems = Items.Values.Where(i => i.GBHandle.GBID == item.GBHandle.GBID).ToList();
foreach (Item baseItem in baseItems)
{
if (baseItem.Attributes[GameAttributes.ItemStackQuantityLo] + item.Attributes[GameAttributes.ItemStackQuantityLo] <= baseItem.ItemDefinition.MaxStackSize)
foreach (var baseItem in baseItems.Where(baseItem => baseItem.Attributes[GameAttributes.ItemStackQuantityLo] + item.Attributes[GameAttributes.ItemStackQuantityLo] <= baseItem.ItemDefinition.MaxStackSize))
{
baseItem.UpdateStackCount(baseItem.Attributes[GameAttributes.ItemStackQuantityLo] + item.Attributes[GameAttributes.ItemStackQuantityLo]);
baseItem.Attributes.SendChangedMessage((_owner as Player).InGameClient);
@ -269,7 +264,6 @@ namespace DiIiS_NA.GameServer.Core
return;
}
}
}
if (!Items.ContainsKey(item.GlobalID)) Items.Add(item.GlobalID, item);
@ -372,15 +366,9 @@ namespace DiIiS_NA.GameServer.Core
/// <summary>
/// Checks whether the inventory contains an item
/// </summary>
public bool Contains(uint itemID)
{
return Items.ContainsKey(itemID);
}
public bool Contains(uint itemId) => Items.ContainsKey(itemId);
public bool Contains(Item item)
{
return Contains(item.GlobalID);
}
public bool Contains(Item item) => Contains(item.GlobalID);
/// <summary>
/// Find an inventory slot with enough space for an item
@ -436,10 +424,7 @@ namespace DiIiS_NA.GameServer.Core
public Item GetItemByDynId(Player plr, uint dynId)
{
if (Items.Values.Any(it => it.IsRevealedToPlayer(plr) && it.DynamicID(plr) == dynId))
return Items.Values.Single(it => it.IsRevealedToPlayer(plr) && it.DynamicID(plr) == dynId);
return null;
return Items.Values.SingleOrDefault(it => it.IsRevealedToPlayer(plr) && it.DynamicID(plr) == dynId);
}
}
}