Skip to content

Commit

Permalink
More world info;
Browse files Browse the repository at this point in the history
Improved static code InventoryGrid.cs
  • Loading branch information
iamdroppy committed Feb 12, 2023
1 parent 7b21438 commit 60c3ad5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -20,7 +21,10 @@ public string Info(string[] @params, BattleClient invokerClient)
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";
Expand Down
41 changes: 13 additions & 28 deletions src/DiIiS-NA/D3-GameServer/Core/InventoryGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class InventoryGrid : IRevealable
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;

Expand Down Expand Up @@ -133,9 +133,8 @@ public void RemoveItem(Item item)
}
}
}
if (_owner is Player)
if (_owner is Player ownerPlayer)
{
var ownerPlayer = _owner as Player;
ownerPlayer.Inventory.RemoveItemFromDB(item);
}
}
Expand Down Expand Up @@ -194,11 +193,9 @@ public int TotalItemCount(int GBid)
itm.UpdateStackCount(itm.Attributes[GameAttributes.ItemStackQuantityLo] - estimate);
break;
}
else
{
estimate -= itm.Attributes[GameAttributes.ItemStackQuantityLo];
consumed.Add(itm);
}

estimate -= itm.Attributes[GameAttributes.ItemStackQuantityLo];
consumed.Add(itm);
}
foreach (var itm in consumed)
{
Expand Down Expand Up @@ -259,15 +256,12 @@ public void AddItem(Item item, int row, int column)
{
// 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)
foreach (var baseItem in baseItems.Where(baseItem => baseItem.Attributes[GameAttributes.ItemStackQuantityLo] + item.Attributes[GameAttributes.ItemStackQuantityLo] <= baseItem.ItemDefinition.MaxStackSize))
{
if (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);
baseItem.UpdateStackCount(baseItem.Attributes[GameAttributes.ItemStackQuantityLo] + item.Attributes[GameAttributes.ItemStackQuantityLo]);
baseItem.Attributes.SendChangedMessage((_owner as Player).InGameClient);

return;
}
return;
}
}

Expand Down Expand Up @@ -372,15 +366,9 @@ public Boolean HasFreeSpace(Item item, int row, int column)
/// <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
Expand Down Expand Up @@ -436,10 +424,7 @@ public Item GetItem(uint itemId)

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);
}
}
}

0 comments on commit 60c3ad5

Please sign in to comment.