diff --git a/Game/ui/inventorymenu.cpp b/Game/ui/inventorymenu.cpp index 1eb120032..18512c5b6 100644 --- a/Game/ui/inventorymenu.cpp +++ b/Game/ui/inventorymenu.cpp @@ -175,6 +175,7 @@ void InventoryMenu::keyDownEvent(KeyEvent &e) { e.ignore(); return; } + e.accept(); auto& pg = activePage(); auto& sel = activePageSel(); @@ -204,11 +205,30 @@ void InventoryMenu::keyDownEvent(KeyEvent &e) { else if(sel.sel+1useItem (r.clsId()); } else if(state==State::Chest || state==State::Trade || state==State::Ransack) { + lootMode = LootMode::Normal; takeTimer.start(200); onTakeStuff(); } @@ -309,39 +330,58 @@ InventoryMenu::PageLocal &InventoryMenu::activePageSel() { return pageLocal[1]; } -void InventoryMenu::onTakeStuff() { - ++takeCount; - for(int i = 0; i < pow(10,takeCount / 10); ++i) { - auto& page = activePage(); - auto& sel = activePageSel(); - if(sel.sel >= page.size()) - return; - auto& r = page[sel.sel]; - if(r.count() == 1) { - takeCount = 1; +void InventoryMenu::onTakeStuff() { + uint8_t itemCount = 0; + auto& page = activePage(); + auto& sel = activePageSel(); + if(sel.sel >= page.size()) + return; + auto& r = page[sel.sel]; + if(r.isEquiped()) { + return; + } + + if(lootMode==LootMode::Normal) { + ++takeCount; + itemCount = pow(10,takeCount / 10); + if(r.count() <= itemCount) { + itemCount = r.count(); + takeCount = 0; } + } + else if(lootMode==LootMode::Stack) { + itemCount = r.count(); + } + else if(lootMode==LootMode::Ten) { + itemCount = 10; + } + else if(lootMode==LootMode::Hundred) { + itemCount = 100; + } + if(r.count() < itemCount) { + itemCount = r.count(); + } - if(state==State::Chest) { - if(page.is(&player->inventory())) { - player->moveItem(r.clsId(),*chest); - } else { - player->addItem(r.clsId(),*chest); - } + if(state==State::Chest) { + if(page.is(&player->inventory())) { + player->moveItem(r.clsId(),*chest,itemCount); + } else { + player->addItem(r.clsId(),*chest,itemCount); } - else if(state==State::Trade) { - if(page.is(&player->inventory())) { - player->sellItem(r.clsId(),*trader); - } else { - player->buyItem(r.clsId(),*trader); - } + } + else if(state==State::Trade) { + if(page.is(&player->inventory())) { + player->sellItem(r.clsId(),*trader,itemCount); + } else { + player->buyItem(r.clsId(),*trader,itemCount); } - else if(state==State::Ransack) { - if(page.is(&trader->inventory())) { - player->addItem(r.clsId(),*trader); - } + } + else if(state==State::Ransack) { + if(page.is(&trader->inventory())) { + player->addItem(r.clsId(),*trader,itemCount); } - adjustScroll(); } + adjustScroll(); } void InventoryMenu::adjustScroll() { diff --git a/Game/ui/inventorymenu.h b/Game/ui/inventorymenu.h index c48e1136d..b47463772 100644 --- a/Game/ui/inventorymenu.h +++ b/Game/ui/inventorymenu.h @@ -24,6 +24,13 @@ class InventoryMenu : public Tempest::Widget { Ransack }; + enum class LootMode:uint8_t { + Normal=0, + Stack, + Ten, + Hundred + }; + void close(); void open(Npc& pl); void trade(Npc& pl,Npc& tr); @@ -80,6 +87,7 @@ class InventoryMenu : public Tempest::Widget { uint8_t page =0; Tempest::Timer takeTimer; size_t takeCount =0; + LootMode lootMode =LootMode::Normal; InventoryRenderer renderer; size_t columsCount=5; diff --git a/Game/world/npc.cpp b/Game/world/npc.cpp index d81a70f44..f095556e8 100644 --- a/Game/world/npc.cpp +++ b/Game/world/npc.cpp @@ -1987,34 +1987,39 @@ Item* Npc::addItem(std::unique_ptr&& i) { return invent.addItem(std::move(i)); } -void Npc::addItem(uint32_t id, Interactive &chest) { - Inventory::trasfer(invent,chest.inventory(),nullptr,id,1,owner); +void Npc::addItem(uint32_t id, Interactive &chest, uint32_t count) { + Inventory::trasfer(invent,chest.inventory(),nullptr,id,count,owner); } -void Npc::addItem(uint32_t id, Npc &from) { - Inventory::trasfer(invent,from.invent,&from,id,1,owner); +void Npc::addItem(uint32_t id, Npc &from, uint32_t count) { + Inventory::trasfer(invent,from.invent,&from,id,count,owner); } -void Npc::moveItem(uint32_t id, Interactive &to) { - Inventory::trasfer(to.inventory(),invent,this,id,1,owner); +void Npc::moveItem(uint32_t id, Interactive &to, uint32_t count) { + Inventory::trasfer(to.inventory(),invent,this,id,count,owner); } -void Npc::sellItem(uint32_t id, Npc &to) { +void Npc::sellItem(uint32_t id, Npc &to, uint32_t count) { int32_t price = invent.sellPriceOf(id); - Inventory::trasfer(to.invent,invent,this,id,1,owner); + if(id==owner.script().goldId()) + return; + Inventory::trasfer(to.invent,invent,this,id,count,owner); invent.addItem(owner.script().goldId(),uint32_t(price),owner); } -void Npc::buyItem(uint32_t id, Npc &from) { +void Npc::buyItem(uint32_t id, Npc &from, uint32_t count) { if(id==owner.script().goldId()) return; int32_t price = from.invent.priceOf(id); - if(price>int32_t(invent.goldCount())) { + if(price*count>int32_t(invent.goldCount())) { owner.script().printCannotBuyError(*this); + if(int32_t(invent.goldCount())/price >= 1){ + buyItem(id,from,int32_t(invent.goldCount())/price); + } return; } - Inventory::trasfer(invent,from.invent,nullptr,id,1,owner); - invent.delItem(owner.script().goldId(),uint32_t(price),*this); + Inventory::trasfer(invent,from.invent,nullptr,id,count,owner); + invent.delItem(owner.script().goldId(),uint32_t(price)*count,*this); } void Npc::clearInventory() { diff --git a/Game/world/npc.h b/Game/world/npc.h index b4ff192da..a63d81590 100644 --- a/Game/world/npc.h +++ b/Game/world/npc.h @@ -362,11 +362,11 @@ class Npc final { void useItem (uint32_t item, bool force=false); void setCurrentItem(uint32_t item); void unequipItem(uint32_t item); - void addItem (uint32_t id,Interactive& chest); - void addItem (uint32_t id,Npc& from); - void moveItem (uint32_t id,Interactive& to); - void sellItem (uint32_t id,Npc& to); - void buyItem (uint32_t id,Npc& from); + void addItem (uint32_t id,Interactive& chest,uint32_t count=1); + void addItem (uint32_t id,Npc& from,uint32_t count=1); + void moveItem (uint32_t id,Interactive& to,uint32_t count=1); + void sellItem (uint32_t id,Npc& to,uint32_t count=1); + void buyItem (uint32_t id,Npc& from,uint32_t count=1); void clearInventory(); Item* currentArmour(); Item* currentMeleWeapon();