mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-02 19:42:05 -04:00
Fixed bugs in the new inventory code.
This commit is contained in:
parent
81d82cd7a8
commit
5bec522c8e
@ -1265,7 +1265,9 @@ namespace FFXIVClassic_Map_Server
|
|||||||
byte materia4 = reader.GetByte(11);
|
byte materia4 = reader.GetByte(11);
|
||||||
byte materia5 = reader.GetByte(12);
|
byte materia5 = reader.GetByte(12);
|
||||||
|
|
||||||
items.Add(new InventoryItem(uniqueId, itemId, quantity, itemType, qualityNumber, durability, spiritBind, materia1, materia2, materia3, materia4, materia5));
|
InventoryItem item = new InventoryItem(uniqueId, itemId, quantity, itemType, qualityNumber, durability, spiritBind, materia1, materia2, materia3, materia4, materia5);
|
||||||
|
item.slot = slot;
|
||||||
|
items.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,9 +152,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
|
owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
|
||||||
|
|
||||||
if (list[slot] != null)
|
if (list[slot] != null)
|
||||||
normalInventory.RefreshItem(list[slot], item);
|
normalInventory.RefreshItem(owner, list[slot], item);
|
||||||
else
|
else
|
||||||
normalInventory.RefreshItem(item);
|
normalInventory.RefreshItem(owner, item);
|
||||||
|
|
||||||
owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
|
owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
|
||||||
SendEquipmentPackets(slot, item);
|
SendEquipmentPackets(slot, item);
|
||||||
@ -180,7 +180,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
|
|
||||||
owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
|
owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
|
||||||
|
|
||||||
normalInventory.RefreshItem(list[slot]);
|
normalInventory.RefreshItem(owner, list[slot]);
|
||||||
|
|
||||||
owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
|
owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
|
||||||
SendEquipmentPackets(slot, null);
|
SendEquipmentPackets(slot, null);
|
||||||
|
@ -25,11 +25,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
private int endOfListIndex = 0;
|
private int endOfListIndex = 0;
|
||||||
|
|
||||||
private Character owner;
|
private Character owner;
|
||||||
private List<Player> viewer;
|
|
||||||
private ushort inventoryCapacity;
|
private ushort inventoryCapacity;
|
||||||
private ushort inventoryCode;
|
private ushort inventoryCode;
|
||||||
private InventoryItem[] list;
|
private InventoryItem[] list;
|
||||||
private InventoryItem[] lastList;
|
|
||||||
private bool[] isDirty;
|
private bool[] isDirty;
|
||||||
|
|
||||||
public Inventory(Character ownerPlayer, ushort capacity, ushort code)
|
public Inventory(Character ownerPlayer, ushort capacity, ushort code)
|
||||||
@ -37,6 +35,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
owner = ownerPlayer;
|
owner = ownerPlayer;
|
||||||
inventoryCapacity = capacity;
|
inventoryCapacity = capacity;
|
||||||
inventoryCode = code;
|
inventoryCode = code;
|
||||||
|
list = new InventoryItem[capacity];
|
||||||
|
isDirty = new bool[capacity];
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Inventory Management
|
#region Inventory Management
|
||||||
@ -45,6 +45,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (InventoryItem item in itemsFromDB)
|
foreach (InventoryItem item in itemsFromDB)
|
||||||
list[i++] = item;
|
list[i++] = item;
|
||||||
|
endOfListIndex = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryItem GetItemAtSlot(ushort slot)
|
public InventoryItem GetItemAtSlot(ushort slot)
|
||||||
@ -57,8 +58,13 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
|
|
||||||
public InventoryItem GetItemByUniqueId(ulong uniqueItemId)
|
public InventoryItem GetItemByUniqueId(ulong uniqueItemId)
|
||||||
{
|
{
|
||||||
foreach (InventoryItem item in list)
|
for (int i = 0; i < endOfListIndex; i++)
|
||||||
{
|
{
|
||||||
|
InventoryItem item = list[i];
|
||||||
|
|
||||||
|
if (item == null)
|
||||||
|
throw new Exception("Item slot was null!!!");
|
||||||
|
|
||||||
if (item.uniqueId == uniqueItemId)
|
if (item.uniqueId == uniqueItemId)
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@ -67,22 +73,27 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
|
|
||||||
public InventoryItem GetItemByCatelogId(ulong catelogId)
|
public InventoryItem GetItemByCatelogId(ulong catelogId)
|
||||||
{
|
{
|
||||||
foreach (InventoryItem item in list)
|
for (int i = 0; i < endOfListIndex; i++)
|
||||||
{
|
{
|
||||||
|
InventoryItem item = list[i];
|
||||||
|
|
||||||
|
if (item == null)
|
||||||
|
throw new Exception("Item slot was null!!!");
|
||||||
|
|
||||||
if (item.itemId == catelogId)
|
if (item.itemId == catelogId)
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddItem(uint itemId)
|
public bool AddItem(uint itemId)
|
||||||
{
|
{
|
||||||
AddItem(itemId, 1, 1);
|
return AddItem(itemId, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddItem(uint itemId, int quantity)
|
public bool AddItem(uint itemId, int quantity)
|
||||||
{
|
{
|
||||||
AddItem(itemId, quantity, 1);
|
return AddItem(itemId, quantity, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddItem(uint itemId, int quantity, byte quality)
|
public bool AddItem(uint itemId, int quantity, byte quality)
|
||||||
@ -130,11 +141,15 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
while (quantityCount > 0)
|
while (quantityCount > 0)
|
||||||
{
|
{
|
||||||
InventoryItem addedItem = Database.CreateItem(itemId, Math.Min(quantityCount, gItem.maxStack), quality, gItem.isExclusive ? (byte)0x3 : (byte)0x0, gItem.durability);
|
InventoryItem addedItem = Database.CreateItem(itemId, Math.Min(quantityCount, gItem.maxStack), quality, gItem.isExclusive ? (byte)0x3 : (byte)0x0, gItem.durability);
|
||||||
|
addedItem.slot = (ushort)endOfListIndex;
|
||||||
isDirty[endOfListIndex] = true;
|
isDirty[endOfListIndex] = true;
|
||||||
list[endOfListIndex++] = addedItem;
|
list[endOfListIndex++] = addedItem;
|
||||||
quantityCount -= gItem.maxStack;
|
quantityCount -= gItem.maxStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (owner is Player)
|
||||||
|
SendUpdatePackets((Player)owner);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +194,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
}
|
}
|
||||||
|
|
||||||
doRealign();
|
doRealign();
|
||||||
|
if (owner is Player)
|
||||||
|
SendUpdatePackets((Player)owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveItemByUniqueId(ulong itemDBId)
|
public void RemoveItemByUniqueId(ulong itemDBId)
|
||||||
@ -212,21 +228,23 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
list[slot] = null;
|
list[slot] = null;
|
||||||
isDirty[slot] = true;
|
isDirty[slot] = true;
|
||||||
doRealign();
|
doRealign();
|
||||||
|
if (owner is Player)
|
||||||
|
SendUpdatePackets((Player)owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeDurability(uint slot, uint durabilityChange)
|
public void ChangeDurability(uint slot, uint durabilityChange)
|
||||||
{
|
{
|
||||||
|
isDirty[slot] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeSpiritBind(uint slot, uint spiritBindChange)
|
public void ChangeSpiritBind(uint slot, uint spiritBindChange)
|
||||||
{
|
{
|
||||||
|
isDirty[slot] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeMateria(uint slot, byte materiaSlot, byte materiaId)
|
public void ChangeMateria(uint slot, byte materiaSlot, byte materiaId)
|
||||||
{
|
{
|
||||||
|
isDirty[slot] = true;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -272,7 +290,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
{
|
{
|
||||||
int currentIndex = startOffset;
|
int currentIndex = startOffset;
|
||||||
|
|
||||||
List<InventoryItem> lst = new List<InventoryItem>(list);
|
List<InventoryItem> lst = new List<InventoryItem>();
|
||||||
|
for (int i = 0; i < endOfListIndex; i++)
|
||||||
|
lst.Add(list[i]);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -325,6 +345,27 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RefreshItem(Player player, InventoryItem item)
|
||||||
|
{
|
||||||
|
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
|
||||||
|
SendInventoryPackets(player, item);
|
||||||
|
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RefreshItem(Player player, params InventoryItem[] items)
|
||||||
|
{
|
||||||
|
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
|
||||||
|
SendInventoryPackets(player, items.ToList());
|
||||||
|
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RefreshItem(Player player, List<InventoryItem> items)
|
||||||
|
{
|
||||||
|
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
|
||||||
|
SendInventoryPackets(player, items);
|
||||||
|
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Client Updating
|
#region Client Updating
|
||||||
@ -341,17 +382,20 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
items.Add(list[i]);
|
items.Add(list[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = endOfListIndex; i < lastList.Length; i++)
|
for (int i = endOfListIndex; i < list.Length; i++)
|
||||||
{
|
{
|
||||||
if (lastList[i] != null)
|
if (isDirty[i])
|
||||||
slotsToRemove.Add((ushort)i);
|
slotsToRemove.Add((ushort)i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Array.Clear(isDirty, 0, isDirty.Length);
|
||||||
|
|
||||||
|
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
|
||||||
//Send Updated Slots
|
//Send Updated Slots
|
||||||
SendInventoryPackets(player, items);
|
SendInventoryPackets(player, items);
|
||||||
|
|
||||||
//Send Remove packets for tail end
|
//Send Remove packets for tail end
|
||||||
SendInventoryRemovePackets(player, slotsToRemove);
|
SendInventoryRemovePackets(player, slotsToRemove);
|
||||||
|
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -412,7 +456,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
|
|
||||||
for (int i = 0; i < endOfListIndex; i++)
|
for (int i = 0; i < endOfListIndex; i++)
|
||||||
{
|
{
|
||||||
if (list[i] == null && lastNullSlot != -1)
|
if (list[i] == null && lastNullSlot == -1)
|
||||||
{
|
{
|
||||||
lastNullSlot = i;
|
lastNullSlot = i;
|
||||||
continue;
|
continue;
|
||||||
|
@ -169,6 +169,8 @@ namespace FFXIVClassic_World_Server
|
|||||||
{
|
{
|
||||||
uint sessionId = subpacket.header.targetId;
|
uint sessionId = subpacket.header.targetId;
|
||||||
Session session = GetSession(sessionId);
|
Session session = GetSession(sessionId);
|
||||||
|
|
||||||
|
if (subpacket.gameMessage.opcode != 0x1 && subpacket.gameMessage.opcode != 0xca)
|
||||||
subpacket.DebugPrintSubPacket();
|
subpacket.DebugPrintSubPacket();
|
||||||
if (subpacket.gameMessage.opcode >= 0x1000)
|
if (subpacket.gameMessage.opcode >= 0x1000)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user