-
[SwiftEMU] Empty command
I've been playing around with the Jukeboxes for a little and I've found a bug which has to do with the empty command. When you empty your inventory(which in my case has some Jukebox discs in it), the items will not be removed from the items table. When you then buy some new Jukebox discs, you're not able to use them anymore. When you delete the old Jukebox discs from your items table manually, the Jukebox will work again with your new discs.
The empty command makes use of the internal void ClearItems which in my case looks like this:
PHP Code:
internal void ClearItems()
{
using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
{
adapter.runFastQuery("DELETE FROM items_users WHERE user_id = " + this.UserId);
}
this.mAddedItems.Clear();
this.mRemovedItems.Clear();
this.floorItems.Clear();
this.wallItems.Clear();
this.discs.Clear();
this.isUpdated = true;
this.mClient.GetMessageHandler().GetResponse().Init(Outgoing.UpdateInventary);
this.GetClient().GetMessageHandler().SendResponse();
}
So somehow the deleted item_id's from items_users should be remembered and have to be run in a query like this:
PHP Code:
using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()){ adapter.runFastQuery("DELETE FROM items WHERE item_id IN (deleted1, deleted2, deleted3, deleted4, deleted5, etc.)");}
How would I do that?
- - - Updated - - -
I've rewritten the internal void ClearItems() to this now:
PHP Code:
internal void ClearItems()
{
DataTable table;
using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
{
adapter.setQuery("SELECT item_id FROM items_users WHERE user_id = " + this.UserId);
table = adapter.getTable();
adapter.runFastQuery("DELETE FROM items_users WHERE user_id = " + this.UserId);
foreach (DataRow row3 in table.Rows)
{
adapter.runFastQuery("DELETE FROM items WHERE item_id = " + (int) row3["item_id"]);
}
}
this.mAddedItems.Clear();
this.mRemovedItems.Clear();
this.floorItems.Clear();
this.wallItems.Clear();
this.discs.Clear();
this.isUpdated = true;
this.mClient.GetMessageHandler().GetResponse().Init(Outgoing.UpdateInventary);
this.GetClient().GetMessageHandler().SendResponse();
}
Would this be THE method or can I use something easier?
Please notice I am in no way a C# programmer, so what I try comes just from copy pasting from other parts of the emulator.