mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-02 19:42:05 -04:00
Moved all DB update code into it's own method.
This commit is contained in:
parent
9529a1374e
commit
9174801fdb
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
using FFXIVClassic.Common;
|
using FFXIVClassic.Common;
|
||||||
|
using FFXIVClassic_Map_Server.actors.chara.npc;
|
||||||
using FFXIVClassic_Map_Server.Actors;
|
using FFXIVClassic_Map_Server.Actors;
|
||||||
using FFXIVClassic_Map_Server.dataobjects;
|
using FFXIVClassic_Map_Server.dataobjects;
|
||||||
using FFXIVClassic_Map_Server.packets.send.actor.inventory;
|
using FFXIVClassic_Map_Server.packets.send.actor.inventory;
|
||||||
@ -27,15 +28,17 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
|
|
||||||
private Character owner;
|
private Character owner;
|
||||||
private ushort inventoryCapacity;
|
private ushort inventoryCapacity;
|
||||||
private ushort inventoryCode;
|
private ushort inventoryCode;
|
||||||
|
private bool isTemporary;
|
||||||
private InventoryItem[] list;
|
private InventoryItem[] list;
|
||||||
private bool[] isDirty;
|
private bool[] isDirty;
|
||||||
|
|
||||||
public Inventory(Character ownerPlayer, ushort capacity, ushort code)
|
public Inventory(Character ownerPlayer, ushort capacity, ushort code, bool temporary = false)
|
||||||
{
|
{
|
||||||
owner = ownerPlayer;
|
owner = ownerPlayer;
|
||||||
inventoryCapacity = capacity;
|
inventoryCapacity = capacity;
|
||||||
inventoryCode = code;
|
inventoryCode = code;
|
||||||
|
isTemporary = temporary;
|
||||||
list = new InventoryItem[capacity];
|
list = new InventoryItem[capacity];
|
||||||
isDirty = new bool[capacity];
|
isDirty = new bool[capacity];
|
||||||
}
|
}
|
||||||
@ -125,7 +128,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
|
|
||||||
if (owner is Player)
|
if (owner is Player)
|
||||||
{
|
{
|
||||||
Database.SetQuantity((Player)owner, item.uniqueId, item.quantity);
|
DoDatabaseQuantity(item.uniqueId, item.quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quantityCount <= 0)
|
if (quantityCount <= 0)
|
||||||
@ -148,12 +151,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
addedItem.slot = (ushort)endOfListIndex;
|
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)
|
DoDatabaseAdd(addedItem);
|
||||||
{
|
|
||||||
Database.AddItem((Player)owner, addedItem, inventoryCode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (owner is Player)
|
if (owner is Player)
|
||||||
@ -199,16 +199,14 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
//Stack nomnomed
|
//Stack nomnomed
|
||||||
if (item.quantity - quantityCount <= 0)
|
if (item.quantity - quantityCount <= 0)
|
||||||
{
|
{
|
||||||
if (owner is Player)
|
DoDatabaseRemove(list[i].uniqueId);
|
||||||
Database.RemoveItem((Player)owner, list[i].uniqueId);
|
|
||||||
list[i] = null;
|
list[i] = null;
|
||||||
}
|
}
|
||||||
//Stack reduced
|
//Stack reduced
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
item.quantity -= quantityCount;
|
item.quantity -= quantityCount;
|
||||||
if (owner is Player)
|
DoDatabaseQuantity(list[i].uniqueId, list[i].quantity);
|
||||||
Database.SetQuantity((Player)owner, list[i].uniqueId, list[i].quantity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isDirty[i] = true;
|
isDirty[i] = true;
|
||||||
@ -221,7 +219,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doRealign();
|
DoRealign();
|
||||||
if (owner is Player)
|
if (owner is Player)
|
||||||
SendUpdatePackets((Player)owner);
|
SendUpdatePackets((Player)owner);
|
||||||
}
|
}
|
||||||
@ -246,14 +244,13 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
|
|
||||||
if (toDelete == null)
|
if (toDelete == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (owner is Player)
|
DoDatabaseRemove(toDelete.uniqueId);
|
||||||
Database.RemoveItem((Player)owner, toDelete.uniqueId);
|
|
||||||
|
|
||||||
list[slot] = null;
|
list[slot] = null;
|
||||||
isDirty[slot] = true;
|
isDirty[slot] = true;
|
||||||
|
|
||||||
doRealign();
|
DoRealign();
|
||||||
if (owner is Player)
|
if (owner is Player)
|
||||||
SendUpdatePackets((Player)owner);
|
SendUpdatePackets((Player)owner);
|
||||||
}
|
}
|
||||||
@ -263,13 +260,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
if (slot >= endOfListIndex)
|
if (slot >= endOfListIndex)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (owner is Player)
|
DoDatabaseRemove(list[slot].uniqueId);
|
||||||
Database.RemoveItem((Player)owner, list[slot].uniqueId);
|
|
||||||
|
|
||||||
list[slot] = null;
|
list[slot] = null;
|
||||||
isDirty[slot] = true;
|
isDirty[slot] = true;
|
||||||
|
|
||||||
doRealign();
|
DoRealign();
|
||||||
if (owner is Player)
|
if (owner is Player)
|
||||||
SendUpdatePackets((Player)owner);
|
SendUpdatePackets((Player)owner);
|
||||||
}
|
}
|
||||||
@ -285,17 +281,13 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
|
|
||||||
if (list[slot].quantity <= 0)
|
if (list[slot].quantity <= 0)
|
||||||
{
|
{
|
||||||
if (owner is Player)
|
DoDatabaseRemove(list[slot].uniqueId);
|
||||||
Database.RemoveItem((Player)owner, list[slot].uniqueId);
|
|
||||||
|
|
||||||
list[slot] = null;
|
list[slot] = null;
|
||||||
doRealign();
|
DoRealign();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (owner is Player)
|
|
||||||
Database.SetQuantity((Player)owner, list[slot].uniqueId, list[slot].quantity);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
DoDatabaseQuantity(list[slot].uniqueId, list[slot].quantity);
|
||||||
|
|
||||||
isDirty[slot] = true;
|
isDirty[slot] = true;
|
||||||
if (owner is Player)
|
if (owner is Player)
|
||||||
@ -439,7 +431,47 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Client Updating
|
#region Client and DB Updating
|
||||||
|
|
||||||
|
private void DoDatabaseAdd(InventoryItem addedItem)
|
||||||
|
{
|
||||||
|
if (isTemporary)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (owner is Player)
|
||||||
|
Database.AddItem((Player)owner, addedItem, inventoryCode);
|
||||||
|
else if (owner is Retainer)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DoDatabaseQuantity(ulong itemDBId, int quantity)
|
||||||
|
{
|
||||||
|
if (isTemporary)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (owner is Player)
|
||||||
|
Database.SetQuantity((Player)owner, itemDBId, inventoryCode);
|
||||||
|
else if (owner is Retainer)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DoDatabaseRemove(ulong itemDBId)
|
||||||
|
{
|
||||||
|
if (isTemporary)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (owner is Player)
|
||||||
|
Database.RemoveItem((Player)owner, itemDBId);
|
||||||
|
else if (owner is Retainer)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void SendUpdatePackets(Player player)
|
private void SendUpdatePackets(Player player)
|
||||||
{
|
{
|
||||||
List<InventoryItem> items = new List<InventoryItem>();
|
List<InventoryItem> items = new List<InventoryItem>();
|
||||||
@ -532,7 +564,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
return endOfListIndex;
|
return endOfListIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doRealign()
|
private void DoRealign()
|
||||||
{
|
{
|
||||||
int lastNullSlot = -1;
|
int lastNullSlot = -1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user