mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-21 20:27:47 +00:00
Removed the inventory lock stuff.
This commit is contained in:
parent
5fd48fad6b
commit
08dfd22bfa
1 changed files with 298 additions and 358 deletions
|
@ -125,109 +125,100 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
||||||
|
|
||||||
public INV_ERROR AddItem(InventoryItem itemRef)
|
public INV_ERROR AddItem(InventoryItem itemRef)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
//If it isn't a single item (ie: armor) just add like normal (not valid for BAZAAR)
|
||||||
|
if (itemPackageCode != BAZAAR && itemRef.GetItemData().maxStack > 1)
|
||||||
|
return AddItem(itemRef.itemId, itemRef.quantity, itemRef.quality);
|
||||||
|
|
||||||
|
if (!IsSpaceForAdd(itemRef.itemId, itemRef.quantity, itemRef.quality))
|
||||||
|
return INV_ERROR.INVENTORY_FULL;
|
||||||
|
|
||||||
|
ItemData gItem = Server.GetItemGamedata(itemRef.itemId);
|
||||||
|
|
||||||
|
if (gItem == null)
|
||||||
{
|
{
|
||||||
//If it isn't a single item (ie: armor) just add like normal (not valid for BAZAAR)
|
Program.Log.Error("Inventory.AddItem: unable to find item %u", itemRef.itemId);
|
||||||
if (itemPackageCode != BAZAAR && itemRef.GetItemData().maxStack > 1)
|
return INV_ERROR.SYSTEM_ERROR;
|
||||||
return AddItem(itemRef.itemId, itemRef.quantity, itemRef.quality);
|
|
||||||
|
|
||||||
if (!IsSpaceForAdd(itemRef.itemId, itemRef.quantity, itemRef.quality))
|
|
||||||
return INV_ERROR.INVENTORY_FULL;
|
|
||||||
|
|
||||||
ItemData gItem = Server.GetItemGamedata(itemRef.itemId);
|
|
||||||
|
|
||||||
if (gItem == null)
|
|
||||||
{
|
|
||||||
Program.Log.Error("Inventory.AddItem: unable to find item %u", itemRef.itemId);
|
|
||||||
return INV_ERROR.SYSTEM_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemRef.RefreshPositioning(owner, itemPackageCode, (ushort)endOfListIndex);
|
|
||||||
|
|
||||||
isDirty[endOfListIndex] = true;
|
|
||||||
list[endOfListIndex++] = itemRef;
|
|
||||||
DoDatabaseAdd(itemRef);
|
|
||||||
|
|
||||||
SendUpdatePackets();
|
|
||||||
|
|
||||||
return INV_ERROR.SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemRef.RefreshPositioning(owner, itemPackageCode, (ushort)endOfListIndex);
|
||||||
|
|
||||||
|
isDirty[endOfListIndex] = true;
|
||||||
|
list[endOfListIndex++] = itemRef;
|
||||||
|
DoDatabaseAdd(itemRef);
|
||||||
|
|
||||||
|
SendUpdatePackets();
|
||||||
|
|
||||||
|
return INV_ERROR.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public INV_ERROR AddItem(uint itemId, int quantity, byte quality)
|
public INV_ERROR AddItem(uint itemId, int quantity, byte quality)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
if (!IsSpaceForAdd(itemId, quantity, quality))
|
||||||
|
return INV_ERROR.INVENTORY_FULL;
|
||||||
|
|
||||||
|
ItemData gItem = Server.GetItemGamedata(itemId);
|
||||||
|
|
||||||
|
//If it's unique, abort
|
||||||
|
if (HasItem(itemId) && gItem.isExclusive)
|
||||||
|
return INV_ERROR.ALREADY_HAS_UNIQUE;
|
||||||
|
|
||||||
|
if (gItem == null)
|
||||||
{
|
{
|
||||||
if (!IsSpaceForAdd(itemId, quantity, quality))
|
Program.Log.Error("Inventory.AddItem: unable to find item %u", itemId);
|
||||||
return INV_ERROR.INVENTORY_FULL;
|
return INV_ERROR.SYSTEM_ERROR;
|
||||||
|
|
||||||
ItemData gItem = Server.GetItemGamedata(itemId);
|
|
||||||
|
|
||||||
//If it's unique, abort
|
|
||||||
if (HasItem(itemId) && gItem.isExclusive)
|
|
||||||
return INV_ERROR.ALREADY_HAS_UNIQUE;
|
|
||||||
|
|
||||||
if (gItem == null)
|
|
||||||
{
|
|
||||||
Program.Log.Error("Inventory.AddItem: unable to find item %u", itemId);
|
|
||||||
return INV_ERROR.SYSTEM_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if item id exists
|
|
||||||
int quantityCount = quantity;
|
|
||||||
for (int i = 0; i < endOfListIndex; i++)
|
|
||||||
{
|
|
||||||
InventoryItem item = list[i];
|
|
||||||
|
|
||||||
Debug.Assert(item != null, "Item slot was null!!!");
|
|
||||||
|
|
||||||
if (item.itemId == itemId && item.quality == quality && item.quantity < gItem.maxStack)
|
|
||||||
{
|
|
||||||
int oldQuantity = item.quantity;
|
|
||||||
item.quantity = Math.Min(item.quantity + quantityCount, gItem.maxStack);
|
|
||||||
isDirty[i] = true;
|
|
||||||
quantityCount -= (gItem.maxStack - oldQuantity);
|
|
||||||
|
|
||||||
DoDatabaseQuantity(item.uniqueId, item.quantity);
|
|
||||||
|
|
||||||
if (quantityCount <= 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//New item that spilled over
|
|
||||||
while (quantityCount > 0)
|
|
||||||
{
|
|
||||||
InventoryItem.ItemModifier modifiers = null;
|
|
||||||
if (gItem.durability != 0)
|
|
||||||
{
|
|
||||||
modifiers = new InventoryItem.ItemModifier();
|
|
||||||
modifiers.durability = (uint)gItem.durability;
|
|
||||||
}
|
|
||||||
|
|
||||||
InventoryItem addedItem = Database.CreateItem(itemId, Math.Min(quantityCount, gItem.maxStack), quality, modifiers);
|
|
||||||
addedItem.RefreshPositioning(owner, itemPackageCode, (ushort)endOfListIndex);
|
|
||||||
isDirty[endOfListIndex] = true;
|
|
||||||
list[endOfListIndex++] = addedItem;
|
|
||||||
quantityCount -= gItem.maxStack;
|
|
||||||
|
|
||||||
DoDatabaseAdd(addedItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
SendUpdatePackets();
|
|
||||||
|
|
||||||
return INV_ERROR.SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Check if item id exists
|
||||||
|
int quantityCount = quantity;
|
||||||
|
for (int i = 0; i < endOfListIndex; i++)
|
||||||
|
{
|
||||||
|
InventoryItem item = list[i];
|
||||||
|
|
||||||
|
Debug.Assert(item != null, "Item slot was null!!!");
|
||||||
|
|
||||||
|
if (item.itemId == itemId && item.quality == quality && item.quantity < gItem.maxStack)
|
||||||
|
{
|
||||||
|
int oldQuantity = item.quantity;
|
||||||
|
item.quantity = Math.Min(item.quantity + quantityCount, gItem.maxStack);
|
||||||
|
isDirty[i] = true;
|
||||||
|
quantityCount -= (gItem.maxStack - oldQuantity);
|
||||||
|
|
||||||
|
DoDatabaseQuantity(item.uniqueId, item.quantity);
|
||||||
|
|
||||||
|
if (quantityCount <= 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//New item that spilled over
|
||||||
|
while (quantityCount > 0)
|
||||||
|
{
|
||||||
|
InventoryItem.ItemModifier modifiers = null;
|
||||||
|
if (gItem.durability != 0)
|
||||||
|
{
|
||||||
|
modifiers = new InventoryItem.ItemModifier();
|
||||||
|
modifiers.durability = (uint)gItem.durability;
|
||||||
|
}
|
||||||
|
|
||||||
|
InventoryItem addedItem = Database.CreateItem(itemId, Math.Min(quantityCount, gItem.maxStack), quality, modifiers);
|
||||||
|
addedItem.RefreshPositioning(owner, itemPackageCode, (ushort)endOfListIndex);
|
||||||
|
isDirty[endOfListIndex] = true;
|
||||||
|
list[endOfListIndex++] = addedItem;
|
||||||
|
quantityCount -= gItem.maxStack;
|
||||||
|
|
||||||
|
DoDatabaseAdd(addedItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
SendUpdatePackets();
|
||||||
|
|
||||||
|
return INV_ERROR.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetItem(ushort slot, InventoryItem item)
|
public void SetItem(ushort slot, InventoryItem item)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
list[slot] = item;
|
||||||
{
|
SendUpdatePackets();
|
||||||
list[slot] = item;
|
item.RefreshPositioning(owner, itemPackageCode, slot);
|
||||||
SendUpdatePackets();
|
|
||||||
item.RefreshPositioning(owner, itemPackageCode, slot);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveItem(uint itemId)
|
public void RemoveItem(uint itemId)
|
||||||
|
@ -242,54 +233,51 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
||||||
|
|
||||||
public void RemoveItem(uint itemId, int quantity, int quality)
|
public void RemoveItem(uint itemId, int quantity, int quality)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
if (!HasItem(itemId, quantity, quality))
|
||||||
|
return;
|
||||||
|
|
||||||
|
List<ushort> slotsToUpdate = new List<ushort>();
|
||||||
|
List<InventoryItem> itemsToRemove = new List<InventoryItem>();
|
||||||
|
List<ushort> slotsToRemove = new List<ushort>();
|
||||||
|
List<SubPacket> AddItemPackets = new List<SubPacket>();
|
||||||
|
|
||||||
|
//Remove as we go along
|
||||||
|
int quantityCount = quantity;
|
||||||
|
ushort lowestSlot = 0;
|
||||||
|
for (int i = endOfListIndex - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (!HasItem(itemId, quantity, quality))
|
InventoryItem item = list[i];
|
||||||
return;
|
|
||||||
|
|
||||||
List<ushort> slotsToUpdate = new List<ushort>();
|
Debug.Assert(item != null, "Item slot was null!!!");
|
||||||
List<InventoryItem> itemsToRemove = new List<InventoryItem>();
|
|
||||||
List<ushort> slotsToRemove = new List<ushort>();
|
|
||||||
List<SubPacket> AddItemPackets = new List<SubPacket>();
|
|
||||||
|
|
||||||
//Remove as we go along
|
if (item.itemId == itemId && item.quality == quality)
|
||||||
int quantityCount = quantity;
|
|
||||||
ushort lowestSlot = 0;
|
|
||||||
for (int i = endOfListIndex - 1; i >= 0; i--)
|
|
||||||
{
|
{
|
||||||
InventoryItem item = list[i];
|
int oldQuantity = item.quantity;
|
||||||
|
//Stack nomnomed
|
||||||
Debug.Assert(item != null, "Item slot was null!!!");
|
if (item.quantity - quantityCount <= 0)
|
||||||
|
|
||||||
if (item.itemId == itemId && item.quality == quality)
|
|
||||||
{
|
{
|
||||||
int oldQuantity = item.quantity;
|
DoDatabaseRemove(list[i].uniqueId);
|
||||||
//Stack nomnomed
|
list[i] = null;
|
||||||
if (item.quantity - quantityCount <= 0)
|
}
|
||||||
{
|
//Stack reduced
|
||||||
DoDatabaseRemove(list[i].uniqueId);
|
else
|
||||||
list[i] = null;
|
{
|
||||||
}
|
item.quantity -= quantityCount;
|
||||||
//Stack reduced
|
DoDatabaseQuantity(list[i].uniqueId, list[i].quantity);
|
||||||
else
|
|
||||||
{
|
|
||||||
item.quantity -= quantityCount;
|
|
||||||
DoDatabaseQuantity(list[i].uniqueId, list[i].quantity);
|
|
||||||
}
|
|
||||||
|
|
||||||
isDirty[i] = true;
|
|
||||||
|
|
||||||
quantityCount -= oldQuantity;
|
|
||||||
lowestSlot = item.slot;
|
|
||||||
|
|
||||||
if (quantityCount <= 0)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
DoRealign();
|
isDirty[i] = true;
|
||||||
SendUpdatePackets();
|
|
||||||
|
quantityCount -= oldQuantity;
|
||||||
|
lowestSlot = item.slot;
|
||||||
|
|
||||||
|
if (quantityCount <= 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DoRealign();
|
||||||
|
SendUpdatePackets();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveItem(InventoryItem item)
|
public void RemoveItem(InventoryItem item)
|
||||||
|
@ -304,106 +292,94 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
||||||
|
|
||||||
public void RemoveItemByUniqueId(ulong itemDBId, int quantity)
|
public void RemoveItemByUniqueId(ulong itemDBId, int quantity)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
ushort slot = 0;
|
||||||
|
InventoryItem toDelete = null;
|
||||||
|
for (int i = 0; i < endOfListIndex; i++)
|
||||||
{
|
{
|
||||||
ushort slot = 0;
|
InventoryItem item = list[i];
|
||||||
InventoryItem toDelete = null;
|
|
||||||
for (int i = 0; i < endOfListIndex; i++)
|
Debug.Assert(item != null, "Item slot was null!!!");
|
||||||
|
|
||||||
|
if (item.uniqueId == itemDBId)
|
||||||
{
|
{
|
||||||
InventoryItem item = list[i];
|
toDelete = item;
|
||||||
|
break;
|
||||||
Debug.Assert(item != null, "Item slot was null!!!");
|
|
||||||
|
|
||||||
if (item.uniqueId == itemDBId)
|
|
||||||
{
|
|
||||||
toDelete = item;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
slot++;
|
|
||||||
}
|
}
|
||||||
|
slot++;
|
||||||
if (toDelete == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (quantity >= toDelete.quantity)
|
|
||||||
{
|
|
||||||
DoDatabaseRemove(toDelete.uniqueId);
|
|
||||||
list[slot].RefreshPositioning(null, 0xFFFF, 0xFFFF);
|
|
||||||
list[slot] = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
list[slot].quantity -= quantity;
|
|
||||||
DoDatabaseQuantity(list[slot].uniqueId, list[slot].quantity);
|
|
||||||
}
|
|
||||||
|
|
||||||
isDirty[slot] = true;
|
|
||||||
|
|
||||||
DoRealign();
|
|
||||||
SendUpdatePackets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (toDelete == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (quantity >= toDelete.quantity)
|
||||||
|
{
|
||||||
|
DoDatabaseRemove(toDelete.uniqueId);
|
||||||
|
list[slot].RefreshPositioning(null, 0xFFFF, 0xFFFF);
|
||||||
|
list[slot] = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list[slot].quantity -= quantity;
|
||||||
|
DoDatabaseQuantity(list[slot].uniqueId, list[slot].quantity);
|
||||||
|
}
|
||||||
|
|
||||||
|
isDirty[slot] = true;
|
||||||
|
|
||||||
|
DoRealign();
|
||||||
|
SendUpdatePackets();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveItemAtSlot(ushort slot)
|
public void RemoveItemAtSlot(ushort slot)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
if (slot >= endOfListIndex)
|
||||||
{
|
return;
|
||||||
if (slot >= endOfListIndex)
|
|
||||||
return;
|
|
||||||
|
|
||||||
DoDatabaseRemove(list[slot].uniqueId);
|
DoDatabaseRemove(list[slot].uniqueId);
|
||||||
|
|
||||||
list[slot].RefreshPositioning(null, 0xFFFF, 0xFFFF);
|
list[slot].RefreshPositioning(null, 0xFFFF, 0xFFFF);
|
||||||
list[slot] = null;
|
list[slot] = null;
|
||||||
isDirty[slot] = true;
|
isDirty[slot] = true;
|
||||||
|
|
||||||
DoRealign();
|
DoRealign();
|
||||||
SendUpdatePackets();
|
SendUpdatePackets();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveItemAtSlot(ushort slot, int quantity)
|
public void RemoveItemAtSlot(ushort slot, int quantity)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
if (slot >= endOfListIndex)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (list[slot] != null)
|
||||||
{
|
{
|
||||||
if (slot >= endOfListIndex)
|
list[slot].quantity -= quantity;
|
||||||
return;
|
|
||||||
|
|
||||||
if (list[slot] != null)
|
if (list[slot].quantity <= 0)
|
||||||
{
|
{
|
||||||
list[slot].quantity -= quantity;
|
DoDatabaseRemove(list[slot].uniqueId);
|
||||||
|
|
||||||
if (list[slot].quantity <= 0)
|
list[slot].RefreshPositioning(null, 0xFFFF, 0xFFFF);
|
||||||
{
|
list[slot] = null;
|
||||||
DoDatabaseRemove(list[slot].uniqueId);
|
DoRealign();
|
||||||
|
|
||||||
list[slot].RefreshPositioning(null, 0xFFFF, 0xFFFF);
|
|
||||||
list[slot] = null;
|
|
||||||
DoRealign();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
DoDatabaseQuantity(list[slot].uniqueId, list[slot].quantity);
|
|
||||||
|
|
||||||
isDirty[slot] = true;
|
|
||||||
SendUpdatePackets();
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
DoDatabaseQuantity(list[slot].uniqueId, list[slot].quantity);
|
||||||
|
|
||||||
|
isDirty[slot] = true;
|
||||||
|
SendUpdatePackets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
for (int i = 0; i < endOfListIndex; i++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < endOfListIndex; i++)
|
list[i].RefreshPositioning(null, 0xFFFF, 0xFFFF);
|
||||||
{
|
list[i] = null;
|
||||||
list[i].RefreshPositioning(null, 0xFFFF, 0xFFFF);
|
isDirty[i] = true;
|
||||||
list[i] = null;
|
|
||||||
isDirty[i] = true;
|
|
||||||
}
|
|
||||||
endOfListIndex = 0;
|
|
||||||
|
|
||||||
SendUpdatePackets();
|
|
||||||
}
|
}
|
||||||
|
endOfListIndex = 0;
|
||||||
|
|
||||||
|
SendUpdatePackets();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryItem[] GetRawList()
|
public InventoryItem[] GetRawList()
|
||||||
|
@ -430,143 +406,116 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
||||||
#region Packet Functions
|
#region Packet Functions
|
||||||
public void SendFullInventory(Player player)
|
public void SendFullInventory(Player player)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, itemPackageCapacity, itemPackageCode));
|
||||||
{
|
SendInventoryPackets(player, 0);
|
||||||
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, itemPackageCapacity, itemPackageCode));
|
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
||||||
SendInventoryPackets(player, 0);
|
|
||||||
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendInventoryPackets(Player player, InventoryItem item)
|
private void SendInventoryPackets(Player player, InventoryItem item)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
player.QueuePacket(InventoryListX01Packet.BuildPacket(owner.actorId, item));
|
||||||
{
|
|
||||||
player.QueuePacket(InventoryListX01Packet.BuildPacket(owner.actorId, item));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendInventoryPackets(Player player, List<InventoryItem> items)
|
private void SendInventoryPackets(Player player, List<InventoryItem> items)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
int currentIndex = 0;
|
||||||
{
|
|
||||||
int currentIndex = 0;
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
{
|
||||||
|
if (items.Count - currentIndex >= 64)
|
||||||
|
player.QueuePacket(InventoryListX64Packet.BuildPacket(owner.actorId, items, ref currentIndex));
|
||||||
|
else if (items.Count - currentIndex >= 32)
|
||||||
|
player.QueuePacket(InventoryListX32Packet.BuildPacket(owner.actorId, items, ref currentIndex));
|
||||||
|
else if (items.Count - currentIndex >= 16)
|
||||||
|
player.QueuePacket(InventoryListX16Packet.BuildPacket(owner.actorId, items, ref currentIndex));
|
||||||
|
else if (items.Count - currentIndex > 1)
|
||||||
|
player.QueuePacket(InventoryListX08Packet.BuildPacket(owner.actorId, items, ref currentIndex));
|
||||||
|
else if (items.Count - currentIndex == 1)
|
||||||
{
|
{
|
||||||
if (items.Count - currentIndex >= 64)
|
player.QueuePacket(InventoryListX01Packet.BuildPacket(owner.actorId, items[currentIndex]));
|
||||||
player.QueuePacket(InventoryListX64Packet.BuildPacket(owner.actorId, items, ref currentIndex));
|
currentIndex++;
|
||||||
else if (items.Count - currentIndex >= 32)
|
|
||||||
player.QueuePacket(InventoryListX32Packet.BuildPacket(owner.actorId, items, ref currentIndex));
|
|
||||||
else if (items.Count - currentIndex >= 16)
|
|
||||||
player.QueuePacket(InventoryListX16Packet.BuildPacket(owner.actorId, items, ref currentIndex));
|
|
||||||
else if (items.Count - currentIndex > 1)
|
|
||||||
player.QueuePacket(InventoryListX08Packet.BuildPacket(owner.actorId, items, ref currentIndex));
|
|
||||||
else if (items.Count - currentIndex == 1)
|
|
||||||
{
|
|
||||||
player.QueuePacket(InventoryListX01Packet.BuildPacket(owner.actorId, items[currentIndex]));
|
|
||||||
currentIndex++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendInventoryPackets(Player player, int startOffset)
|
private void SendInventoryPackets(Player player, int startOffset)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
int currentIndex = startOffset;
|
||||||
|
|
||||||
|
List<InventoryItem> lst = new List<InventoryItem>();
|
||||||
|
for (int i = 0; i < endOfListIndex; i++)
|
||||||
|
lst.Add(list[i]);
|
||||||
|
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
int currentIndex = startOffset;
|
if (endOfListIndex - currentIndex >= 64)
|
||||||
|
player.QueuePacket(InventoryListX64Packet.BuildPacket(owner.actorId, lst, ref currentIndex));
|
||||||
List<InventoryItem> lst = new List<InventoryItem>();
|
else if (endOfListIndex - currentIndex >= 32)
|
||||||
for (int i = 0; i < endOfListIndex; i++)
|
player.QueuePacket(InventoryListX32Packet.BuildPacket(owner.actorId, lst, ref currentIndex));
|
||||||
lst.Add(list[i]);
|
else if (endOfListIndex - currentIndex >= 16)
|
||||||
|
player.QueuePacket(InventoryListX16Packet.BuildPacket(owner.actorId, lst, ref currentIndex));
|
||||||
while (true)
|
else if (endOfListIndex - currentIndex > 1)
|
||||||
|
player.QueuePacket(InventoryListX08Packet.BuildPacket(owner.actorId, lst, ref currentIndex));
|
||||||
|
else if (endOfListIndex - currentIndex == 1)
|
||||||
{
|
{
|
||||||
if (endOfListIndex - currentIndex >= 64)
|
player.QueuePacket(InventoryListX01Packet.BuildPacket(owner.actorId, list[currentIndex]));
|
||||||
player.QueuePacket(InventoryListX64Packet.BuildPacket(owner.actorId, lst, ref currentIndex));
|
currentIndex++;
|
||||||
else if (endOfListIndex - currentIndex >= 32)
|
|
||||||
player.QueuePacket(InventoryListX32Packet.BuildPacket(owner.actorId, lst, ref currentIndex));
|
|
||||||
else if (endOfListIndex - currentIndex >= 16)
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
player.QueuePacket(InventoryListX01Packet.BuildPacket(owner.actorId, list[currentIndex]));
|
|
||||||
currentIndex++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendInventoryRemovePackets(Player player, ushort index)
|
private void SendInventoryRemovePackets(Player player, ushort index)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
player.QueuePacket(InventoryRemoveX01Packet.BuildPacket(owner.actorId, index));
|
||||||
{
|
|
||||||
player.QueuePacket(InventoryRemoveX01Packet.BuildPacket(owner.actorId, index));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendInventoryRemovePackets(Player player, List<ushort> indexes)
|
private void SendInventoryRemovePackets(Player player, List<ushort> indexes)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
int currentIndex = 0;
|
||||||
{
|
|
||||||
int currentIndex = 0;
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
{
|
||||||
|
if (indexes.Count - currentIndex >= 64)
|
||||||
|
player.QueuePacket(InventoryRemoveX64Packet.BuildPacket(owner.actorId, indexes, ref currentIndex));
|
||||||
|
else if (indexes.Count - currentIndex >= 32)
|
||||||
|
player.QueuePacket(InventoryRemoveX32Packet.BuildPacket(owner.actorId, indexes, ref currentIndex));
|
||||||
|
else if (indexes.Count - currentIndex >= 16)
|
||||||
|
player.QueuePacket(InventoryRemoveX16Packet.BuildPacket(owner.actorId, indexes, ref currentIndex));
|
||||||
|
else if (indexes.Count - currentIndex > 1)
|
||||||
|
player.QueuePacket(InventoryRemoveX08Packet.BuildPacket(owner.actorId, indexes, ref currentIndex));
|
||||||
|
else if (indexes.Count - currentIndex == 1)
|
||||||
{
|
{
|
||||||
if (indexes.Count - currentIndex >= 64)
|
player.QueuePacket(InventoryRemoveX01Packet.BuildPacket(owner.actorId, indexes[currentIndex]));
|
||||||
player.QueuePacket(InventoryRemoveX64Packet.BuildPacket(owner.actorId, indexes, ref currentIndex));
|
currentIndex++;
|
||||||
else if (indexes.Count - currentIndex >= 32)
|
|
||||||
player.QueuePacket(InventoryRemoveX32Packet.BuildPacket(owner.actorId, indexes, ref currentIndex));
|
|
||||||
else if (indexes.Count - currentIndex >= 16)
|
|
||||||
player.QueuePacket(InventoryRemoveX16Packet.BuildPacket(owner.actorId, indexes, ref currentIndex));
|
|
||||||
else if (indexes.Count - currentIndex > 1)
|
|
||||||
player.QueuePacket(InventoryRemoveX08Packet.BuildPacket(owner.actorId, indexes, ref currentIndex));
|
|
||||||
else if (indexes.Count - currentIndex == 1)
|
|
||||||
{
|
|
||||||
player.QueuePacket(InventoryRemoveX01Packet.BuildPacket(owner.actorId, indexes[currentIndex]));
|
|
||||||
currentIndex++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshItem(Player player, InventoryItem item)
|
public void RefreshItem(Player player, InventoryItem item)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, itemPackageCapacity, itemPackageCode));
|
||||||
{
|
SendInventoryPackets(player, item);
|
||||||
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, itemPackageCapacity, itemPackageCode));
|
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
||||||
SendInventoryPackets(player, item);
|
|
||||||
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshItem(Player player, params InventoryItem[] items)
|
public void RefreshItem(Player player, params InventoryItem[] items)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, itemPackageCapacity, itemPackageCode));
|
||||||
{
|
SendInventoryPackets(player, items.ToList());
|
||||||
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, itemPackageCapacity, itemPackageCode));
|
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
||||||
SendInventoryPackets(player, items.ToList());
|
|
||||||
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshItem(Player player, List<InventoryItem> items)
|
public void RefreshItem(Player player, List<InventoryItem> items)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, itemPackageCapacity, itemPackageCode));
|
||||||
{
|
SendInventoryPackets(player, items);
|
||||||
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, itemPackageCapacity, itemPackageCode));
|
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
||||||
SendInventoryPackets(player, items);
|
|
||||||
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -623,37 +572,34 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
||||||
|
|
||||||
public void SendUpdatePackets(Player player)
|
public void SendUpdatePackets(Player player)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
List<InventoryItem> items = new List<InventoryItem>();
|
||||||
|
List<ushort> slotsToRemove = new List<ushort>();
|
||||||
|
|
||||||
|
for (int i = 0; i < list.Length; i++)
|
||||||
{
|
{
|
||||||
List<InventoryItem> items = new List<InventoryItem>();
|
if (i == endOfListIndex)
|
||||||
List<ushort> slotsToRemove = new List<ushort>();
|
break;
|
||||||
|
if (isDirty[i])
|
||||||
for (int i = 0; i < list.Length; i++)
|
items.Add(list[i]);
|
||||||
{
|
|
||||||
if (i == endOfListIndex)
|
|
||||||
break;
|
|
||||||
if (isDirty[i])
|
|
||||||
items.Add(list[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = endOfListIndex; i < list.Length; i++)
|
|
||||||
{
|
|
||||||
if (isDirty[i])
|
|
||||||
slotsToRemove.Add((ushort)i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!holdingUpdates)
|
|
||||||
Array.Clear(isDirty, 0, isDirty.Length);
|
|
||||||
|
|
||||||
player.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
|
|
||||||
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, itemPackageCapacity, itemPackageCode));
|
|
||||||
//Send Updated Slots
|
|
||||||
SendInventoryPackets(player, items);
|
|
||||||
//Send Remove packets for tail end
|
|
||||||
SendInventoryRemovePackets(player, slotsToRemove);
|
|
||||||
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
|
||||||
player.QueuePacket(InventoryEndChangePacket.BuildPacket(owner.actorId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = endOfListIndex; i < list.Length; i++)
|
||||||
|
{
|
||||||
|
if (isDirty[i])
|
||||||
|
slotsToRemove.Add((ushort)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!holdingUpdates)
|
||||||
|
Array.Clear(isDirty, 0, isDirty.Length);
|
||||||
|
|
||||||
|
player.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
|
||||||
|
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, itemPackageCapacity, itemPackageCode));
|
||||||
|
//Send Updated Slots
|
||||||
|
SendInventoryPackets(player, items);
|
||||||
|
//Send Remove packets for tail end
|
||||||
|
SendInventoryRemovePackets(player, slotsToRemove);
|
||||||
|
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
|
||||||
|
player.QueuePacket(InventoryEndChangePacket.BuildPacket(owner.actorId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartSendUpdate()
|
public void StartSendUpdate()
|
||||||
|
@ -679,23 +625,20 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
||||||
|
|
||||||
public bool IsSpaceForAdd(uint itemId, int quantity, int quality)
|
public bool IsSpaceForAdd(uint itemId, int quantity, int quality)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
int quantityCount = quantity;
|
||||||
|
for (int i = 0; i < endOfListIndex; i++)
|
||||||
{
|
{
|
||||||
int quantityCount = quantity;
|
InventoryItem item = list[i];
|
||||||
for (int i = 0; i < endOfListIndex; i++)
|
ItemData gItem = Server.GetItemGamedata(item.itemId);
|
||||||
|
if (item.itemId == itemId && item.quality == quality && item.quantity < gItem.maxStack)
|
||||||
{
|
{
|
||||||
InventoryItem item = list[i];
|
quantityCount -= (gItem.maxStack - item.quantity);
|
||||||
ItemData gItem = Server.GetItemGamedata(item.itemId);
|
if (quantityCount <= 0)
|
||||||
if (item.itemId == itemId && item.quality == quality && item.quantity < gItem.maxStack)
|
break;
|
||||||
{
|
|
||||||
quantityCount -= (gItem.maxStack - item.quantity);
|
|
||||||
if (quantityCount <= 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return quantityCount <= 0 || (quantityCount > 0 && !IsFull());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return quantityCount <= 0 || (quantityCount > 0 && !IsFull());
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasItem(uint itemId)
|
public bool HasItem(uint itemId)
|
||||||
|
@ -710,25 +653,22 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
||||||
|
|
||||||
public bool HasItem(uint itemId, int minQuantity, int quality)
|
public bool HasItem(uint itemId, int minQuantity, int quality)
|
||||||
{
|
{
|
||||||
lock (inventoryLock)
|
int count = 0;
|
||||||
|
|
||||||
|
for (int i = endOfListIndex - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
int count = 0;
|
InventoryItem item = list[i];
|
||||||
|
|
||||||
for (int i = endOfListIndex - 1; i >= 0; i--)
|
Debug.Assert(item != null, "Item slot was null!!!");
|
||||||
{
|
|
||||||
InventoryItem item = list[i];
|
|
||||||
|
|
||||||
Debug.Assert(item != null, "Item slot was null!!!");
|
if (item.itemId == itemId && item.quality == quality)
|
||||||
|
count += item.quantity;
|
||||||
|
|
||||||
if (item.itemId == itemId && item.quality == quality)
|
if (count >= minQuantity)
|
||||||
count += item.quantity;
|
return true;
|
||||||
|
|
||||||
if (count >= minQuantity)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetNextEmptySlot()
|
public int GetNextEmptySlot()
|
||||||
|
|
Loading…
Add table
Reference in a new issue