From 3766c45c62eeca442e9ab700c09c547f08615b62 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 29 Jun 2016 17:56:48 -0400 Subject: chests, item dropping --- src/mob.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/mob.cpp') diff --git a/src/mob.cpp b/src/mob.cpp index 20273d6..99d6f34 100644 --- a/src/mob.cpp +++ b/src/mob.cpp @@ -432,11 +432,26 @@ Chest::Chest(void) : Mob() width = HLINES(10); height = HLINES(5); tex = TextureIterator({"assets/chest.png"}); + inv = new Inventory(1); } void Chest::act(void) { - //die(); + if (isInside(ui::mouse) && player->isNear(this)) { + if ((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)) && !ui::dialogBoxExists) + for (auto &i : inv->Items) { + player->inv->addItem(i.first->name, i.second); + inv->takeItem(i.first->name, i.second); + } + } + + for (auto &e : currentWorld->entity) { + if (e->type == OBJECTT && e->isNear(this)) { + auto o = dynamic_cast(e); + inv->addItem(o->iname, 1); + e->health = 0; + } + } } void Chest::onHit(unsigned int _health) -- cgit v1.2.3