mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-22 20:57:47 +00:00
Fixed bugs in the new inventory code.
This commit is contained in:
parent
81d82cd7a8
commit
5bec522c8e
4 changed files with 94 additions and 46 deletions
|
@ -1265,7 +1265,9 @@ namespace FFXIVClassic_Map_Server
|
|||
byte materia4 = reader.GetByte(11);
|
||||
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));
|
||||
|
||||
if (list[slot] != null)
|
||||
normalInventory.RefreshItem(list[slot], item);
|
||||
normalInventory.RefreshItem(owner, list[slot], item);
|
||||
else
|
||||
normalInventory.RefreshItem(item);
|
||||
normalInventory.RefreshItem(owner, item);
|
||||
|
||||
owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
|
||||
SendEquipmentPackets(slot, item);
|
||||
|
@ -180,7 +180,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
|
||||
owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
|
||||
|
||||
normalInventory.RefreshItem(list[slot]);
|
||||
normalInventory.RefreshItem(owner, list[slot]);
|
||||
|
||||
owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
|
||||
SendEquipmentPackets(slot, null);
|
||||
|
|
|
@ -24,19 +24,19 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
|
||||
private int endOfListIndex = 0;
|
||||
|
||||
private Character owner;
|
||||
private List<Player> viewer;
|
||||
private Character owner;
|
||||
private ushort inventoryCapacity;
|
||||
private ushort inventoryCode;
|
||||
private InventoryItem[] list;
|
||||
private InventoryItem[] lastList;
|
||||
private bool[] isDirty;
|
||||
|
||||
public Inventory(Character ownerPlayer, ushort capacity, ushort code)
|
||||
{
|
||||
owner = ownerPlayer;
|
||||
inventoryCapacity = capacity;
|
||||
inventoryCode = code;
|
||||
inventoryCode = code;
|
||||
list = new InventoryItem[capacity];
|
||||
isDirty = new bool[capacity];
|
||||
}
|
||||
|
||||
#region Inventory Management
|
||||
|
@ -44,7 +44,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
{
|
||||
int i = 0;
|
||||
foreach (InventoryItem item in itemsFromDB)
|
||||
list[i++] = item;
|
||||
list[i++] = item;
|
||||
endOfListIndex = i;
|
||||
}
|
||||
|
||||
public InventoryItem GetItemAtSlot(ushort slot)
|
||||
|
@ -56,9 +57,14 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
}
|
||||
|
||||
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)
|
||||
return item;
|
||||
}
|
||||
|
@ -67,22 +73,27 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
|
||||
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)
|
||||
return item;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AddItem(uint itemId)
|
||||
}
|
||||
|
||||
public bool AddItem(uint itemId)
|
||||
{
|
||||
AddItem(itemId, 1, 1);
|
||||
}
|
||||
|
||||
public void AddItem(uint itemId, int quantity)
|
||||
{
|
||||
AddItem(itemId, quantity, 1);
|
||||
return AddItem(itemId, 1, 1);
|
||||
}
|
||||
|
||||
public bool AddItem(uint itemId, int quantity)
|
||||
{
|
||||
return AddItem(itemId, quantity, 1);
|
||||
}
|
||||
|
||||
public bool AddItem(uint itemId, int quantity, byte quality)
|
||||
|
@ -130,10 +141,14 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
while (quantityCount > 0)
|
||||
{
|
||||
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;
|
||||
list[endOfListIndex++] = addedItem;
|
||||
quantityCount -= gItem.maxStack;
|
||||
}
|
||||
}
|
||||
|
||||
if (owner is Player)
|
||||
SendUpdatePackets((Player)owner);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -178,8 +193,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
}
|
||||
}
|
||||
|
||||
doRealign();
|
||||
|
||||
doRealign();
|
||||
if (owner is Player)
|
||||
SendUpdatePackets((Player)owner);
|
||||
}
|
||||
|
||||
public void RemoveItemByUniqueId(ulong itemDBId)
|
||||
|
@ -211,22 +227,24 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
|
||||
list[slot] = null;
|
||||
isDirty[slot] = true;
|
||||
doRealign();
|
||||
doRealign();
|
||||
if (owner is Player)
|
||||
SendUpdatePackets((Player)owner);
|
||||
}
|
||||
|
||||
public void ChangeDurability(uint slot, uint durabilityChange)
|
||||
{
|
||||
|
||||
{
|
||||
isDirty[slot] = true;
|
||||
}
|
||||
|
||||
public void ChangeSpiritBind(uint slot, uint spiritBindChange)
|
||||
{
|
||||
|
||||
{
|
||||
isDirty[slot] = true;
|
||||
}
|
||||
|
||||
public void ChangeMateria(uint slot, byte materiaSlot, byte materiaId)
|
||||
{
|
||||
|
||||
{
|
||||
isDirty[slot] = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -272,10 +290,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
{
|
||||
int currentIndex = startOffset;
|
||||
|
||||
List<InventoryItem> lst = new List<InventoryItem>(list);
|
||||
|
||||
while (true)
|
||||
{
|
||||
List<InventoryItem> lst = new List<InventoryItem>();
|
||||
for (int i = 0; i < endOfListIndex; i++)
|
||||
lst.Add(list[i]);
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (endOfListIndex - currentIndex >= 64)
|
||||
player.QueuePacket(InventoryListX64Packet.BuildPacket(owner.actorId, lst, ref currentIndex));
|
||||
else if (endOfListIndex - currentIndex >= 32)
|
||||
|
@ -284,13 +304,13 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
player.QueuePacket(InventoryListX16Packet.BuildPacket(owner.actorId, lst, ref currentIndex));
|
||||
else if (endOfListIndex - currentIndex > 1)
|
||||
player.QueuePacket(InventoryListX08Packet.BuildPacket(owner.actorId, lst, ref currentIndex));
|
||||
else if (endOfListIndex - currentIndex == 1)
|
||||
else if (endOfListIndex - currentIndex == 1)
|
||||
{
|
||||
player.QueuePacket(InventoryListX01Packet.BuildPacket(owner.actorId, list[currentIndex]));
|
||||
currentIndex++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
player.QueuePacket(InventoryListX01Packet.BuildPacket(owner.actorId, list[currentIndex]));
|
||||
currentIndex++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -323,6 +343,27 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -341,17 +382,20 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
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);
|
||||
}
|
||||
|
||||
Array.Clear(isDirty, 0, isDirty.Length);
|
||||
|
||||
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
|
||||
//Send Updated Slots
|
||||
SendInventoryPackets(player, items);
|
||||
|
||||
//Send Remove packets for tail end
|
||||
SendInventoryRemovePackets(player, slotsToRemove);
|
||||
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -412,7 +456,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||
|
||||
for (int i = 0; i < endOfListIndex; i++)
|
||||
{
|
||||
if (list[i] == null && lastNullSlot != -1)
|
||||
if (list[i] == null && lastNullSlot == -1)
|
||||
{
|
||||
lastNullSlot = i;
|
||||
continue;
|
||||
|
|
|
@ -169,7 +169,9 @@ namespace FFXIVClassic_World_Server
|
|||
{
|
||||
uint sessionId = subpacket.header.targetId;
|
||||
Session session = GetSession(sessionId);
|
||||
subpacket.DebugPrintSubPacket();
|
||||
|
||||
if (subpacket.gameMessage.opcode != 0x1 && subpacket.gameMessage.opcode != 0xca)
|
||||
subpacket.DebugPrintSubPacket();
|
||||
if (subpacket.gameMessage.opcode >= 0x1000)
|
||||
{
|
||||
//subpacket.DebugPrintSubPacket();
|
||||
|
|
Loading…
Add table
Reference in a new issue