Game.useOnCreature lua api

This commit is contained in:
Eduardo Bart 2012-01-17 20:28:55 -02:00
parent 0b08552bbc
commit cc5b36b1cb
7 changed files with 18 additions and 4 deletions

View File

@ -22,7 +22,8 @@ end
function debugContainersItems() function debugContainersItems()
function UIItem:onHoverChange(hovered) function UIItem:onHoverChange(hovered)
if hovered then if hovered then
ToolTip.display(self:getItem():getId()) local item = self:getItem()
if item then ToolTip.display(item:getId()) end
else else
ToolTip.hide() ToolTip.hide()
end end

View File

@ -18,12 +18,15 @@ function UIPopupMenu:display(pos)
end end
displayUI(self, {x = pos.x, y = pos.y}) displayUI(self, {x = pos.x, y = pos.y})
self:bindRectToParent()
self:grabMouse() self:grabMouse()
self:grabKeyboard() self:grabKeyboard()
table.insert(displayedMenuList, self) table.insert(displayedMenuList, self)
end end
function UIPopupMenu:onGeometryChange()
self:bindRectToParent()
end
function UIPopupMenu:addOption(optionName, optionCallback) function UIPopupMenu:addOption(optionName, optionCallback)
local optionWidget = createWidget(self:getStyleName() .. 'Button', self) local optionWidget = createWidget(self:getStyleName() .. 'Button', self)
local lastOptionWidget = self:getLastChild() local lastOptionWidget = self:getLastChild()

View File

@ -274,6 +274,14 @@ void Game::useHotkey(int itemId, const ThingPtr& toThing)
m_protocolGame->sendUseItemEx(Position(0xFFFF, 0, 0), itemId, 0, toThing->getPos(), toThing->getId(), getThingStackpos(toThing)); m_protocolGame->sendUseItemEx(Position(0xFFFF, 0, 0), itemId, 0, toThing->getPos(), toThing->getId(), getThingStackpos(toThing));
} }
void Game::useOnCreature(const ThingPtr& thing, const CreaturePtr& creature)
{
if(!m_online || !thing || !checkBotProtection())
return;
m_protocolGame->sendUseOnCreature(thing->getPos(), thing->getId(), getThingStackpos(thing), creature->getId());
}
void Game::attack(const CreaturePtr& creature) void Game::attack(const CreaturePtr& creature)
{ {
if(!m_online || !creature || !checkBotProtection()) if(!m_online || !creature || !checkBotProtection())

View File

@ -65,6 +65,7 @@ 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,6 +198,7 @@ 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));

View File

@ -66,7 +66,7 @@ public:
void sendRejectTrade(); void sendRejectTrade();
void sendUseItem(const Position& position, int itemId, int stackpos, int index); void sendUseItem(const Position& position, int itemId, int stackpos, int index);
void sendUseItemEx(const Position& fromPos, int fromThingId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos); void sendUseItemEx(const Position& fromPos, int fromThingId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos);
void sendUseItemCreature(const Position& pos, int thingId, int stackpos, uint creatureId); void sendUseOnCreature(const Position& pos, int thingId, int stackpos, uint creatureId);
void sendRotateItem(const Position& pos, int thingId, int stackpos); void sendRotateItem(const Position& pos, int thingId, int stackpos);
void sendCloseContainer(int containerId); void sendCloseContainer(int containerId);
void sendUpContainer(int containerId); void sendUpContainer(int containerId);

View File

@ -275,7 +275,7 @@ void ProtocolGame::sendUseItemEx(const Position& fromPos, int fromThingId, int f
send(oMsg); send(oMsg);
} }
void ProtocolGame::sendUseItemCreature(const Position& pos, int thingId, int stackpos, uint creatureId) void ProtocolGame::sendUseOnCreature(const Position& pos, int thingId, int stackpos, uint creatureId)
{ {
OutputMessage oMsg; OutputMessage oMsg;
oMsg.addU8(Proto::ClientUseOnCreature); oMsg.addU8(Proto::ClientUseOnCreature);