// Moves an item from one slot to another bool _Inventory::MoveInventory(_Buffer &Data, size_t OldSlot, size_t NewSlot) { if(!CanSwap(OldSlot, NewSlot)) return false; // Add to stack if(Slots[NewSlot].Item == Slots[OldSlot].Item) { Slots[NewSlot].Count += Slots[OldSlot].Count; // Group stacks if(Slots[NewSlot].Count > INVENTORY_MAX_STACK) { Slots[OldSlot].Count = Slots[NewSlot].Count - INVENTORY_MAX_STACK; Slots[NewSlot].Count = INVENTORY_MAX_STACK; } else Slots[OldSlot].Item = nullptr; } else { // Check for reverse swap if(!CanSwap(NewSlot, OldSlot)) return false; SwapItem(NewSlot, OldSlot); } // Build packet SerializeSlot(Data, NewSlot); SerializeSlot(Data, OldSlot); return true; }
void InventoryViewController::DragObserver(InventoryView* container, Rocket::Core::Element* element) { std::vector<InventoryView*>::iterator itView = _views.begin(); std::vector<InventoryView*>::iterator end = _views.end(); for (; itView != end && (!((*(*itView)) == element->GetParentNode())) ; ++itView); if (itView != _views.end()) { InventoryView& view = (*(*itView)); if (AllowDrop(view, *container)) { InventoryObject* object = view.GetObjectFromId(std::string(element->GetId().CString())); if (container->GetInventory().CanCarry(object) && CanSwap(object)) { view.GetInventory().DelObject(object); container->GetInventory().AddObject(object); view.UpdateView(); container->UpdateView(); } } } }