Fixed a bunch of SQL errors. Added checks for quality so a remove command didn't take out items regardless of quality. Fixed errors.

This commit is contained in:
Filip Maj 2017-09-09 12:21:37 -04:00
parent a14e36fadc
commit 8755ca4f33
2 changed files with 63 additions and 39 deletions

View File

@ -1338,12 +1338,12 @@ namespace FFXIVClassic_Map_Server
INSERT INTO characters_inventory INSERT INTO characters_inventory
(characterId, inventoryType, serverItemId, quantity) (characterId, inventoryType, serverItemId, quantity)
VALUES VALUES
(@charId, @inventoryType, uid, @quantity) (@charId, @inventoryType, @serverItemId, @quantity)
"; ";
MySqlCommand cmd = new MySqlCommand(query, conn); MySqlCommand cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@uid", addedItem.uniqueId); cmd.Parameters.AddWithValue("@serverItemId", addedItem.uniqueId);
cmd.Parameters.AddWithValue("@charId", player.actorId); cmd.Parameters.AddWithValue("@charId", player.actorId);
cmd.Parameters.AddWithValue("@inventoryType", type); cmd.Parameters.AddWithValue("@inventoryType", type);
cmd.Parameters.AddWithValue("@quantity", addedItem.quantity); cmd.Parameters.AddWithValue("@quantity", addedItem.quantity);
@ -1404,7 +1404,7 @@ namespace FFXIVClassic_Map_Server
string query = @" string query = @"
DELETE FROM characters_inventory DELETE FROM characters_inventory
WHERE characterId = @charId and serverItemId = @itemDBCode; WHERE characterId = @charId and serverItemId = @serverItemId;
"; ";
MySqlCommand cmd = new MySqlCommand(query, conn); MySqlCommand cmd = new MySqlCommand(query, conn);

View File

@ -5,6 +5,7 @@ using FFXIVClassic_Map_Server.dataobjects;
using FFXIVClassic_Map_Server.packets.send.actor.inventory; using FFXIVClassic_Map_Server.packets.send.actor.inventory;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
namespace FFXIVClassic_Map_Server.actors.chara.player namespace FFXIVClassic_Map_Server.actors.chara.player
@ -62,8 +63,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
{ {
InventoryItem item = list[i]; InventoryItem item = list[i];
if (item == null) Debug.Assert(item != null, "Item slot was null!!!");
throw new Exception("Item slot was null!!!");
if (item.uniqueId == uniqueItemId) if (item.uniqueId == uniqueItemId)
return item; return item;
@ -77,8 +77,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
{ {
InventoryItem item = list[i]; InventoryItem item = list[i];
if (item == null) Debug.Assert(item != null, "Item slot was null!!!");
throw new Exception("Item slot was null!!!");
if (item.itemId == catelogId) if (item.itemId == catelogId)
return item; return item;
@ -98,7 +97,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
public bool AddItem(uint itemId, int quantity, byte quality) public bool AddItem(uint itemId, int quantity, byte quality)
{ {
if (!IsSpaceForAdd(itemId, quantity)) if (!IsSpaceForAdd(itemId, quantity, quality))
return false; return false;
ItemData gItem = Server.GetItemGamedata(itemId); ItemData gItem = Server.GetItemGamedata(itemId);
@ -115,10 +114,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
{ {
InventoryItem item = list[i]; InventoryItem item = list[i];
if (item == null) Debug.Assert(item != null, "Item slot was null!!!");
throw new Exception("Item slot was null!!!");
if (item.itemId == itemId && item.quantity < gItem.maxStack) if (item.itemId == itemId && item.quality == quality && item.quantity < gItem.maxStack)
{ {
int oldQuantity = item.quantity; int oldQuantity = item.quantity;
item.quantity = Math.Min(item.quantity + quantityCount, gItem.maxStack); item.quantity = Math.Min(item.quantity + quantityCount, gItem.maxStack);
@ -166,9 +164,19 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
return true; return true;
} }
public void RemoveItem(uint itemId)
{
RemoveItem(itemId, 1);
}
public void RemoveItem(uint itemId, int quantity) public void RemoveItem(uint itemId, int quantity)
{ {
if (!HasItem(itemId, quantity)) RemoveItem(itemId, quantity, 1);
}
public void RemoveItem(uint itemId, int quantity, int quality)
{
if (!HasItem(itemId, quantity, quality))
return; return;
List<ushort> slotsToUpdate = new List<ushort>(); List<ushort> slotsToUpdate = new List<ushort>();
@ -183,10 +191,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
{ {
InventoryItem item = list[i]; InventoryItem item = list[i];
if (item == null) Debug.Assert(item != null, "Item slot was null!!!");
throw new Exception("Item slot was null!!!");
if (item.itemId == itemId) if (item.itemId == itemId && item.quality == quality)
{ {
int oldQuantity = item.quantity; int oldQuantity = item.quantity;
//Stack nomnomed //Stack nomnomed
@ -223,8 +230,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
{ {
ushort slot = 0; ushort slot = 0;
InventoryItem toDelete = null; InventoryItem toDelete = null;
foreach (InventoryItem item in list) for (int i = endOfListIndex - 1; i >= 0; i--)
{ {
InventoryItem item = list[i];
Debug.Assert(item != null, "Item slot was null!!!");
if (item.uniqueId == itemDBId) if (item.uniqueId == itemDBId)
{ {
toDelete = item; toDelete = item;
@ -241,7 +252,10 @@ 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 RemoveItemAtSlot(ushort slot) public void RemoveItemAtSlot(ushort slot)
@ -254,6 +268,7 @@ 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) if (owner is Player)
SendUpdatePackets((Player)owner); SendUpdatePackets((Player)owner);
@ -464,14 +479,14 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
return endOfListIndex >= inventoryCapacity; return endOfListIndex >= inventoryCapacity;
} }
public bool IsSpaceForAdd(uint itemId, int quantity) public bool IsSpaceForAdd(uint itemId, int quantity, int quality)
{ {
int quantityCount = quantity; int quantityCount = quantity;
for (int i = 0; i < endOfListIndex; i++) for (int i = 0; i < endOfListIndex; i++)
{ {
InventoryItem item = list[i]; InventoryItem item = list[i];
ItemData gItem = Server.GetItemGamedata(item.itemId); ItemData gItem = Server.GetItemGamedata(item.itemId);
if (item.itemId == itemId && item.quantity < gItem.maxStack) if (item.itemId == itemId && item.quality == quality && item.quantity < gItem.maxStack)
{ {
quantityCount -= (gItem.maxStack - item.quantity); quantityCount -= (gItem.maxStack - item.quantity);
if (quantityCount <= 0) if (quantityCount <= 0)
@ -488,12 +503,21 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
} }
public bool HasItem(uint itemId, int minQuantity) public bool HasItem(uint itemId, int minQuantity)
{
return HasItem(itemId, minQuantity, 1);
}
public bool HasItem(uint itemId, int minQuantity, int quality)
{ {
int count = 0; int count = 0;
foreach (InventoryItem item in list) for (int i = endOfListIndex - 1; i >= 0; i--)
{ {
if (item.itemId == itemId) InventoryItem item = list[i];
Debug.Assert(item != null, "Item slot was null!!!");
if (item.itemId == itemId && item.quality == quality)
count += item.quantity; count += item.quantity;
if (count >= minQuantity) if (count >= minQuantity)