Merge branch 'gift-placing-fix' into 'dev'

Fix placing furni from gifts to a room

See merge request morningstar/Arcturus-Community!37
This commit is contained in:
Alejandro 2019-05-18 12:28:34 -04:00
commit 64c62b92cb
12 changed files with 81 additions and 22 deletions

View File

@ -414,11 +414,14 @@ public class MarketPlace
RequestOffersEvent.cachedResults.clear(); RequestOffersEvent.cachedResults.clear();
try try
{ {
client.sendResponse(new RemoveHabboItemComposer(event.item.getGiftAdjustedId()));
client.sendResponse(new InventoryRefreshComposer());
event.item.setFromGift(false);
MarketPlaceOffer offer = new MarketPlaceOffer(event.item, event.price, client.getHabbo()); MarketPlaceOffer offer = new MarketPlaceOffer(event.item, event.price, client.getHabbo());
client.getHabbo().getInventory().addMarketplaceOffer(offer); client.getHabbo().getInventory().addMarketplaceOffer(offer);
client.getHabbo().getInventory().getItemsComponent().removeHabboItem(event.item); client.getHabbo().getInventory().getItemsComponent().removeHabboItem(event.item);
client.sendResponse(new RemoveHabboItemComposer(event.item.getId()));
client.sendResponse(new InventoryRefreshComposer());
item.setUserId(-1); item.setUserId(-1);
item.needsUpdate(true); item.needsUpdate(true);
Emulator.getThreading().run(item); Emulator.getThreading().run(item);

View File

@ -43,6 +43,7 @@ public abstract class HabboItem implements Runnable, IEventTriggers
private int limitedSells; private int limitedSells;
private boolean needsUpdate = false; private boolean needsUpdate = false;
private boolean needsDelete = false; private boolean needsDelete = false;
private boolean isFromGift = false;
public HabboItem(ResultSet set, Item baseItem) throws SQLException public HabboItem(ResultSet set, Item baseItem) throws SQLException
{ {
@ -131,6 +132,12 @@ public abstract class HabboItem implements Runnable, IEventTriggers
return this.id; return this.id;
} }
public int getGiftAdjustedId() {
if (this.isFromGift) return -this.id;
return this.id;
}
public int getUserId() public int getUserId()
{ {
return this.userId; return this.userId;
@ -508,4 +515,12 @@ public abstract class HabboItem implements Runnable, IEventTriggers
{ {
return true; return true;
} }
public boolean isFromGift() {
return isFromGift;
}
public void setFromGift(boolean fromGift) {
isFromGift = fromGift;
}
} }

View File

@ -117,7 +117,7 @@ public class ItemsComponent
public HabboItem getHabboItem(int itemId) public HabboItem getHabboItem(int itemId)
{ {
return this.items.get(itemId); return this.items.get(Math.abs(itemId));
} }
public HabboItem getAndRemoveHabboItem(final Item item) public HabboItem getAndRemoveHabboItem(final Item item)

View File

@ -50,7 +50,7 @@ public class RecycleEvent extends MessageHandler
for (HabboItem item : items) for (HabboItem item : items)
{ {
this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item);
this.client.sendResponse(new RemoveHabboItemComposer(item.getId())); this.client.sendResponse(new RemoveHabboItemComposer(item.getGiftAdjustedId()));
Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId()));
} }
} }

View File

@ -74,7 +74,7 @@ public class CraftingCraftItemEvent extends MessageHandler
@Override @Override
public boolean execute(HabboItem object) public boolean execute(HabboItem object)
{ {
CraftingCraftItemEvent.this.client.sendResponse(new RemoveHabboItemComposer(object.getId())); CraftingCraftItemEvent.this.client.sendResponse(new RemoveHabboItemComposer(object.getGiftAdjustedId()));
return true; return true;
} }
}); });

View File

@ -93,7 +93,7 @@ public class CraftingCraftSecretEvent extends MessageHandler
for (HabboItem item : habboItems) for (HabboItem item : habboItems)
{ {
this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item);
this.client.sendResponse(new RemoveHabboItemComposer(item.getId())); this.client.sendResponse(new RemoveHabboItemComposer(item.getGiftAdjustedId()));
Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId()));
} }
this.client.sendResponse(new InventoryRefreshComposer()); this.client.sendResponse(new InventoryRefreshComposer());

View File

@ -36,7 +36,8 @@ public class PostItPlaceEvent extends MessageHandler
item.needsUpdate(true); item.needsUpdate(true);
room.sendComposer(new AddWallItemComposer(item, this.client.getHabbo().getHabboInfo().getUsername()).compose()); room.sendComposer(new AddWallItemComposer(item, this.client.getHabbo().getHabboInfo().getUsername()).compose());
this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item);
this.client.sendResponse(new RemoveHabboItemComposer(item.getId())); this.client.sendResponse(new RemoveHabboItemComposer(item.getGiftAdjustedId()));
item.setFromGift(false);
Emulator.getThreading().run(item); Emulator.getThreading().run(item);
if (room.getOwnerId() != this.client.getHabbo().getHabboInfo().getId()) if (room.getOwnerId() != this.client.getHabbo().getHabboInfo().getId())

View File

@ -23,11 +23,6 @@ public class RoomPlaceItemEvent extends MessageHandler
int itemId = -1; int itemId = -1;
if (values.length != 0) itemId = Integer.valueOf(values[0]); if (values.length != 0) itemId = Integer.valueOf(values[0]);
if(itemId < 0)
{
this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.key, FurnitureMovementError.INVALID_MOVE.errorCode));
return;
}
if(!this.client.getHabbo().getRoomUnit().isInRoom()) if(!this.client.getHabbo().getRoomUnit().isInRoom())
{ {
@ -122,7 +117,8 @@ public class RoomPlaceItemEvent extends MessageHandler
} }
} }
this.client.sendResponse(new RemoveHabboItemComposer(item.getId())); this.client.sendResponse(new RemoveHabboItemComposer(item.getGiftAdjustedId()));
this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item.getId()); this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item.getId());
item.setFromGift(false);
} }
} }

View File

@ -47,7 +47,7 @@ public class InventoryItemsComposer extends MessageComposer implements TIntObjec
@Override @Override
public boolean execute(int a, HabboItem habboItem) public boolean execute(int a, HabboItem habboItem)
{ {
this.response.appendInt(habboItem.getId()); this.response.appendInt(habboItem.getGiftAdjustedId());
this.response.appendString(habboItem.getBaseItem().getType().code); this.response.appendString(habboItem.getBaseItem().getType().code);
this.response.appendInt(habboItem.getId()); this.response.appendInt(habboItem.getId());
this.response.appendInt(habboItem.getBaseItem().getSpriteId()); this.response.appendInt(habboItem.getBaseItem().getSpriteId());

View File

@ -19,8 +19,7 @@ public class InventoryUpdateItemComposer extends MessageComposer
public ServerMessage compose() public ServerMessage compose()
{ {
this.response.init(Outgoing.InventoryItemUpdateComposer); this.response.init(Outgoing.InventoryItemUpdateComposer);
this.response.appendInt(2); this.response.appendInt(this.habboItem.getGiftAdjustedId());
this.response.appendInt(this.habboItem.getId());
this.response.appendString(this.habboItem.getBaseItem().getType().code); this.response.appendString(this.habboItem.getBaseItem().getType().code);
this.response.appendInt(this.habboItem.getId()); this.response.appendInt(this.habboItem.getId());
this.response.appendInt(this.habboItem.getBaseItem().getSpriteId()); this.response.appendInt(this.habboItem.getBaseItem().getSpriteId());
@ -55,7 +54,7 @@ public class InventoryUpdateItemComposer extends MessageComposer
this.response.appendBoolean(false); this.response.appendBoolean(false);
this.response.appendInt(-1); this.response.appendInt(-1);
if (this.habboItem.getBaseItem().getType() != FurnitureType.WALL) { if (this.habboItem.getBaseItem().getType() == FurnitureType.FLOOR) {
this.response.appendString(""); //slotId this.response.appendString(""); //slotId
this.response.appendInt(0); this.response.appendInt(0);
} }

View File

@ -22,11 +22,11 @@ public class PresentItemOpenedComposer extends MessageComposer
public ServerMessage compose() public ServerMessage compose()
{ {
this.response.init(Outgoing.PresentItemOpenedComposer); this.response.init(Outgoing.PresentItemOpenedComposer);
this.response.appendString(this.item.getBaseItem().getType().code); this.response.appendString(this.item.getBaseItem().getType().code.toLowerCase());
this.response.appendInt(this.item.getBaseItem().getSpriteId()); this.response.appendInt(this.item.getBaseItem().getSpriteId());
this.response.appendString(this.item.getBaseItem().getName()); this.response.appendString(this.item.getBaseItem().getName());
this.response.appendInt(this.item.getId()); this.response.appendInt(this.item.getId());
this.response.appendString(this.item.getBaseItem().getType().code); this.response.appendString(this.item.getBaseItem().getType().code.toLowerCase());
this.response.appendBoolean(this.unknown); this.response.appendBoolean(this.unknown);
this.response.appendString(this.text); this.response.appendString(this.text);
return this.response; return this.response;

View File

@ -1,16 +1,25 @@
package com.eu.habbo.threading.runnables; package com.eu.habbo.threading.runnables;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.FurnitureType;
import com.eu.habbo.habbohotel.items.interactions.InteractionGift; import com.eu.habbo.habbohotel.items.interactions.InteractionGift;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer; import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer;
import com.eu.habbo.messages.outgoing.inventory.InventoryItemsComposer;
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer; import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
import com.eu.habbo.messages.outgoing.inventory.InventoryUpdateItemComposer;
import com.eu.habbo.messages.outgoing.rooms.items.PresentItemOpenedComposer; import com.eu.habbo.messages.outgoing.rooms.items.PresentItemOpenedComposer;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class OpenGift implements Runnable public class OpenGift implements Runnable
{ {
private final HabboItem item; private final HabboItem item;
@ -42,6 +51,8 @@ public class OpenGift implements Runnable
i.run(); i.run();
} }
if (inside != null) inside.setFromGift(true);
this.habbo.getInventory().getItemsComponent().addItems(items); this.habbo.getInventory().getItemsComponent().addItems(items);
RoomTile tile = this.room.getLayout().getTile(this.item.getX(), this.item.getY()); RoomTile tile = this.room.getLayout().getTile(this.item.getX(), this.item.getY());
@ -49,15 +60,49 @@ public class OpenGift implements Runnable
{ {
this.room.updateTile(tile); this.room.updateTile(tile);
} }
this.habbo.getClient().sendResponse(new AddHabboItemComposer(items));
this.habbo.getClient().sendResponse(new InventoryRefreshComposer());
Emulator.getThreading().run(new QueryDeleteHabboItem(this.item.getId())); Emulator.getThreading().run(new QueryDeleteHabboItem(this.item.getId()));
Emulator.getThreading().run(new RemoveFloorItemTask(this.room, this.item), this.item.getBaseItem().getName().contains("present_wrap") ? 5000 : 0); Emulator.getThreading().run(new RemoveFloorItemTask(this.room, this.item), this.item.getBaseItem().getName().contains("present_wrap") ? 5000 : 0);
this.habbo.getClient().sendResponse(new InventoryRefreshComposer());
Map<AddHabboItemComposer.AddHabboItemCategory, List<Integer>> unseenItems = new HashMap<>();
for (HabboItem item : items) {
switch (item.getBaseItem().getType()) {
case WALL:
case FLOOR:
if (!unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.OWNED_FURNI)) unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.OWNED_FURNI, new ArrayList<>());
unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.OWNED_FURNI).add(item.getGiftAdjustedId());
break;
case BADGE:
if (!unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.BADGE)) unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.BADGE, new ArrayList<>());
unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.BADGE).add(item.getId()); // badges cannot be placed so no need for gift adjusted ID
break;
case PET:
if (!unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.PET)) unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.PET, new ArrayList<>());
unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.PET).add(item.getGiftAdjustedId());
break;
case ROBOT:
if (!unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.BOT)) unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.BOT, new ArrayList<>());
unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.BOT).add(item.getGiftAdjustedId());
break;
}
}
this.habbo.getClient().sendResponse(new AddHabboItemComposer(unseenItems));
if (inside != null) if (inside != null)
{ {
this.habbo.getClient().sendResponse(new InventoryUpdateItemComposer(inside));
this.habbo.getClient().sendResponse(new PresentItemOpenedComposer(inside, "", false)); this.habbo.getClient().sendResponse(new PresentItemOpenedComposer(inside, "", false));
} }
} }