use items on creatures

This commit is contained in:
Eduardo Bart 2012-01-17 20:48:31 -02:00
parent cc5b36b1cb
commit cb1e833e6e
3 changed files with 24 additions and 13 deletions

View File

@ -24,10 +24,11 @@
#include "localplayer.h" #include "localplayer.h"
#include "map.h" #include "map.h"
#include "tile.h" #include "tile.h"
#include "creature.h"
#include "statictext.h"
#include <framework/core/eventdispatcher.h> #include <framework/core/eventdispatcher.h>
#include <framework/ui/uimanager.h> #include <framework/ui/uimanager.h>
#include <otclient/luascript/luavaluecasts.h> #include <otclient/luascript/luavaluecasts.h>
#include <otclient/core/statictext.h>
#include <otclient/net/protocolgame.h> #include <otclient/net/protocolgame.h>
Game g_game; Game g_game;
@ -261,9 +262,20 @@ void Game::useWith(const ThingPtr& fromThing, const ThingPtr& toThing)
if(!m_online || !fromThing || !toThing || !checkBotProtection()) if(!m_online || !fromThing || !toThing || !checkBotProtection())
return; return;
int fromStackpos = getThingStackpos(fromThing), toStackpos = getThingStackpos(toThing); Position pos = fromThing->getPos();
if(fromStackpos != -1 && toStackpos != -1) int fromStackpos = getThingStackpos(fromThing);
m_protocolGame->sendUseItemEx(fromThing->getPos(), fromThing->getId(), fromStackpos, toThing->getPos(), toThing->getId(), toStackpos); if(fromStackpos == -1)
return;
if(CreaturePtr creature = toThing->asCreature()) {
m_protocolGame->sendUseOnCreature(pos, fromThing->getId(), fromStackpos, creature->getId());
} else {
int toStackpos = getThingStackpos(toThing);
if(toStackpos == -1)
return;
m_protocolGame->sendUseItemEx(pos, fromThing->getId(), fromStackpos, toThing->getPos(), toThing->getId(), toStackpos);
}
} }
void Game::useHotkey(int itemId, const ThingPtr& toThing) void Game::useHotkey(int itemId, const ThingPtr& toThing)
@ -271,15 +283,16 @@ void Game::useHotkey(int itemId, const ThingPtr& toThing)
if(!m_online || !toThing || !checkBotProtection()) if(!m_online || !toThing || !checkBotProtection())
return; return;
m_protocolGame->sendUseItemEx(Position(0xFFFF, 0, 0), itemId, 0, toThing->getPos(), toThing->getId(), getThingStackpos(toThing)); Position pos = Position(0xFFFF, 0, 0); // means that is a hotkey use
} int toStackpos = getThingStackpos(toThing);
if(toStackpos == -1)
void Game::useOnCreature(const ThingPtr& thing, const CreaturePtr& creature)
{
if(!m_online || !thing || !checkBotProtection())
return; return;
m_protocolGame->sendUseOnCreature(thing->getPos(), thing->getId(), getThingStackpos(thing), creature->getId()); if(CreaturePtr creature = toThing->asCreature()) {
m_protocolGame->sendUseOnCreature(pos, itemId, 0, creature->getId());
} else {
m_protocolGame->sendUseItemEx(pos, itemId, 0, toThing->getPos(), toThing->getId(), toStackpos);
}
} }
void Game::attack(const CreaturePtr& creature) void Game::attack(const CreaturePtr& creature)

View File

@ -65,7 +65,6 @@ public:
void use(const ThingPtr& thing); void use(const ThingPtr& thing);
void useWith(const ThingPtr& fromThing, const ThingPtr& toThing); void useWith(const ThingPtr& fromThing, const ThingPtr& toThing);
void useHotkey(int itemId, const ThingPtr& toThing); void useHotkey(int itemId, const ThingPtr& toThing);
void useOnCreature(const ThingPtr& thing, const CreaturePtr& creature);
// attack/follow related // attack/follow related
void attack(const CreaturePtr& creature); void attack(const CreaturePtr& creature);

View File

@ -198,7 +198,6 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction<Game>("use", std::bind(&Game::use, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("use", std::bind(&Game::use, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("useWith", std::bind(&Game::useWith, &g_game, _1, _2)); g_lua.bindClassStaticFunction<Game>("useWith", std::bind(&Game::useWith, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("useHotkey", std::bind(&Game::useHotkey, &g_game, _1, _2)); g_lua.bindClassStaticFunction<Game>("useHotkey", std::bind(&Game::useHotkey, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("useOnCreature", std::bind(&Game::useOnCreature, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("walk", std::bind(&Game::walk, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("walk", std::bind(&Game::walk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("forceWalk", std::bind(&Game::forceWalk, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("forceWalk", std::bind(&Game::forceWalk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("attack", std::bind(&Game::attack, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("attack", std::bind(&Game::attack, &g_game, _1));