From 7c4191b1e6f0e64534b29f46a6597e6cdd293025 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Tue, 3 Jan 2012 20:27:31 -0200 Subject: [PATCH] menu working, still need to fix size and add events --- modules/game/thing.lua | 49 ++++++++++++++++--- src/otclient/core/game.cpp | 14 ++++++ src/otclient/core/game.h | 1 + src/otclient/core/thing.cpp | 20 ++++++++ src/otclient/core/thing.h | 4 ++ src/otclient/core/thingtype.h | 6 +-- src/otclient/core/tile.cpp | 88 ++++------------------------------- src/otclient/core/tile.h | 1 + src/otclient/luafunctions.cpp | 8 ++++ 9 files changed, 102 insertions(+), 89 deletions(-) diff --git a/modules/game/thing.lua b/modules/game/thing.lua index ba2eb1c6..072c2425 100644 --- a/modules/game/thing.lua +++ b/modules/game/thing.lua @@ -5,14 +5,51 @@ function Thing:createMenu(menuPosition) menu:addOption('Look', function() Game.look(self) end) -- Open or Use, depending if thing is a container - if self:isContainer() then - menu:addOption('Open', function() print('open') end) + if not self:asCreature() then + if self:isContainer() then + menu:addOption('Open', function() print('open') end) + else + if self:isMultiUse() then + menu:addOption('Use with ...', function() print('use with...') end) + else + menu:addOption('Use', function() Game.use(self) end) + end + end + + if self:isRotateable() then + menu:addOption('Rotate', function() print('rotate') end) + end + + menu:addSeparator() + + if not self:isNotMoveable() and self:isPickupable() then + menu:addOption('Trade with ...', function() print('trade with') end) + end + else - menu:addOption('Use', function() print('use') end) - end - if self:asLocalPlayer() then - menu:addOption('Set Outfit', function() Game.openOutfitWindow() end) + menu:addSeparator() + + if self:asLocalPlayer() then + menu:addOption('Set Outfit', function() Game.openOutfitWindow() end) + else + -- todo: check for stop attack/follow + menu:addOption('Attack', function() print('attack') end) + menu:addOption('Follow', function() print('follow') end) + + if self:asPlayer() then + menu:addSeparator() + menu:addOption('Message to ' .. self:asCreature():getName(), function() print('message') end) + menu:addOption('Add to VIP list', function() print('vip') end) + menu:addOption('Ignore ' .. self:asCreature():getName(), function() print('ignore') end) + menu:addOption('Invite to Party', function() print('invite to party') end) + end + + end + + menu:addSeparator() + menu:addOption('Copy Name', function() print('copy name') end) + end menu:display(menuPosition) diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 4e728144..b77daa09 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -185,6 +185,20 @@ void Game::look(const ThingPtr& thing) m_protocolGame->sendLookAt(thing->getPosition(), thing->getId(), 0); } +void Game::use(const ThingPtr& thing) +{ + // thing is at map + if(thing->getPosition().x != 65535) { + TilePtr tile = g_map.getTile(thing->getPosition()); + int stackpos = tile->getThingStackpos(thing); + if(stackpos != -1) + m_protocolGame->sendUseItem(thing->getPosition(), thing->getId(), stackpos, 0); + } + // thing is at inventory + else + m_protocolGame->sendUseItem(thing->getPosition(), thing->getId(), 0, 0); // last 0 has something to do with container +} + void Game::talkChannel(int channelType, int channelId, const std::string& message) { if(!m_online) diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index 6d693305..7ef5a408 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -49,6 +49,7 @@ public: void walk(Otc::Direction direction); void turn(Otc::Direction direction); void look(const ThingPtr& thing); + void use(const ThingPtr& thing); void talkChannel(int channelType, int channelId, const std::string& message); void talkPrivate(int channelType, const std::string& receiver, const std::string& message); void openOutfitWindow(); diff --git a/src/otclient/core/thing.cpp b/src/otclient/core/thing.cpp index 5b694900..c141e10f 100644 --- a/src/otclient/core/thing.cpp +++ b/src/otclient/core/thing.cpp @@ -82,3 +82,23 @@ bool Thing::isContainer() { return m_type->properties[ThingType::IsContainer]; } + +bool Thing::isMultiUse() +{ + return m_type->properties[ThingType::IsMultiUse]; +} + +bool Thing::isRotateable() +{ + return m_type->properties[ThingType::IsRotateable]; +} + +bool Thing::isNotMoveable() +{ + return m_type->properties[ThingType::IsNotMovable]; +} + +bool Thing::isPickupable() +{ + return m_type->properties[ThingType::IsPickupable]; +} diff --git a/src/otclient/core/thing.h b/src/otclient/core/thing.h index befb8004..a5c8dc8e 100644 --- a/src/otclient/core/thing.h +++ b/src/otclient/core/thing.h @@ -67,6 +67,10 @@ public: virtual StaticTextPtr asStaticText() { return nullptr; } bool isContainer(); + bool isMultiUse(); + bool isRotateable(); + bool isNotMoveable(); + bool isPickupable(); protected: void internalDraw(const Point& p, int layer); diff --git a/src/otclient/core/thingtype.h b/src/otclient/core/thingtype.h index 7067a942..ee2a6311 100644 --- a/src/otclient/core/thingtype.h +++ b/src/otclient/core/thingtype.h @@ -62,14 +62,14 @@ struct ThingType IsFluidContainer, IsFluid, NotWalkable, - NotMovable, + IsNotMovable, BlockProjectile, NotPathable, - Pickupable, + IsPickupable, IsHangable, HookSouth, HookEast, - IsRotable, + IsRotateable, HasLight, DontHide, IsTranslucent, diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index 789303ee..6965f656 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -133,6 +133,14 @@ ThingPtr Tile::getThing(int stackPos) return nullptr; } +int Tile::getThingStackpos(const ThingPtr& thing) +{ + for(uint stackpos = 0; stackpos < m_things.size(); ++stackpos) + if(thing == m_things[stackpos]) + return stackpos; + return -1; +} + ThingPtr Tile::getTopThing() { if(isEmpty()) @@ -262,83 +270,3 @@ bool Tile::isEmpty() { return m_things.size() == 0; } - -/*bool Tile::canAttack() -{ - return hasCreature(); -} - -bool Tile::canFollow() -{ - return hasCreature(); -} - -bool Tile::canCopyName() -{ - return hasCreature(); -}*/ - -// TODO: -/* - - Get menu options - - - if creature: - Look - ----- - Attack - Follow - ----- - Copy Name - - if item: - Look - Use (if not container) - Open (if container) - Use with ... (if multiuse?) - Rotate (if rotable) - ----- - Trade with ... (if pickupable?) - - if player: - Look - ----- - Attack - Follow - ----- - Message to NAME - Add to VIP list - Ignore NAME - Invite to Party - ----- - Report Offense - ----- - Copy Name - - if localplayer: - Look - ----- - Set Outfit - ----- - Copy Name -*/ - -void Tile::useItem() -{ - // Get top item of stack priority 2 (do a function to do this later) - ThingPtr thing; - int lastStackpos = -1; - for(int stackPos = 0; stackPos < (int)m_things.size(); ++stackPos) { - int otherPriority = m_things[stackPos]->getStackPriority(); - if(otherPriority == 2) { - thing = m_things[stackPos]; - lastStackpos = stackPos; - } - } - - if(lastStackpos != -1) { - // use this - g_game.getProtocolGame()->sendUseItem(m_position, thing->getId(), lastStackpos, 0); // 0 has something to do with container - } -} diff --git a/src/otclient/core/tile.h b/src/otclient/core/tile.h index 607162eb..f243009e 100644 --- a/src/otclient/core/tile.h +++ b/src/otclient/core/tile.h @@ -39,6 +39,7 @@ public: ThingPtr addThing(const ThingPtr& thing, int stackPos = -1); ThingPtr getThing(int stackPos); + int getThingStackpos(const ThingPtr& thing); ThingPtr getTopThing(); ThingPtr removeThing(int stackPos); ThingPtr removeThing(const ThingPtr& thing); diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index d4b4e2bb..eff74e19 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -38,9 +38,16 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("getId", &Thing::getId); g_lua.bindClassMemberFunction("getType", &Thing::getType); g_lua.bindClassMemberFunction("isContainer", &Thing::isContainer); + g_lua.bindClassMemberFunction("isMultiUse", &Thing::isMultiUse); + g_lua.bindClassMemberFunction("isRotateable", &Thing::isRotateable); + g_lua.bindClassMemberFunction("isNotMoveable", &Thing::isNotMoveable); + g_lua.bindClassMemberFunction("isPickupable", &Thing::isPickupable); + g_lua.bindClassMemberFunction("asCreature", &Thing::asCreature); + g_lua.bindClassMemberFunction("asPlayer", &Thing::asPlayer); g_lua.bindClassMemberFunction("asLocalPlayer", &Thing::asLocalPlayer); g_lua.registerClass(); + g_lua.bindClassMemberFunction("getName", &Creature::getName); g_lua.bindClassMemberFunction("setOutfit", &Creature::setOutfit); g_lua.bindClassMemberFunction("getOutfit", &Creature::getOutfit); @@ -58,6 +65,7 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("openOutfitWindow", std::bind(&Game::openOutfitWindow, &g_game)); g_lua.bindClassStaticFunction("setOutfit", std::bind(&Game::setOutfit, &g_game, _1)); g_lua.bindClassStaticFunction("look", std::bind(&Game::look, &g_game, _1)); + g_lua.bindClassStaticFunction("use", std::bind(&Game::use, &g_game, _1)); g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &UIItem::create);