This commit is contained in:
Henrique Santiago 2012-01-11 21:10:44 -02:00
parent bb768f43c0
commit c1787c2a50
4 changed files with 44 additions and 6 deletions

View File

@ -3,13 +3,24 @@
function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing) function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing)
local keyboardModifiers = g_window.getKeyboardModifiers() local keyboardModifiers = g_window.getKeyboardModifiers()
if autoWalk and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then local selectedThing = Game.getSelectedThing()
if mouseButton == MouseRightButton and selectedThing then
Game.setSelectedThing(nil)
return true
end
if autoWalk and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton and not Game.getSelectedThing() then
-- todo auto walk -- todo auto walk
return true return true
end end
if not Options.classicControl then if not Options.classicControl then
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then if mouseButton == MouseLeftButton and selectedThing then
Game.useWith(Game.getSelectedThing(), useThing)
Game.setSelectedThing(nil)
-- restore cursor
return true
elseif keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing) Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true return true
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
@ -19,7 +30,8 @@ function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing,
if useThing:isContainer() then if useThing:isContainer() then
print "open" print "open"
elseif useThing:isMultiUse() then elseif useThing:isMultiUse() then
print "use with..." Game.setSelectedThing(useThing)
-- todo change cursor
else else
Game.use(useThing) Game.use(useThing)
end end
@ -29,13 +41,19 @@ function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing,
return true return true
end end
else else
if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then if mouseButton == MouseLeftButton and selectedThing then
Game.useWith(Game.getSelectedThing(), multiUseThing)
Game.setSelectedThing(nil)
-- restore cursor
return true
elseif multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
if multiUseThing:asCreature() then if multiUseThing:asCreature() then
Game.attack(multiUseThing:asCreature()) Game.attack(multiUseThing:asCreature())
elseif multiUseThing:isContainer() then elseif multiUseThing:isContainer() then
print "open" print "open"
elseif multiUseThing:isMultiUse() then elseif multiUseThing:isMultiUse() then
print "use with..." Game.setSelectedThing(multiUseThing)
-- todo change cursor
else else
Game.use(useThing) Game.use(useThing)
end end
@ -70,7 +88,8 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
menu:addOption('Open', function() print('open') end) menu:addOption('Open', function() print('open') end)
else else
if useThing:isMultiUse() then if useThing:isMultiUse() then
menu:addOption('Use with ...', function() print('use with...') end) -- todo change cursor
menu:addOption('Use with ...', function() Game.setSelectedThing(useThing) end)
else else
menu:addOption('Use', function() Game.use(useThing) end) menu:addOption('Use', function() Game.use(useThing) end)
end end

View File

@ -37,6 +37,7 @@ void Game::loginWorld(const std::string& account, const std::string& password, c
m_online = false; m_online = false;
m_dead = false; m_dead = false;
m_walkFeedback = true; m_walkFeedback = true;
m_selectedThing = nullptr;
m_walkPing = 0; m_walkPing = 0;
m_protocolGame = ProtocolGamePtr(new ProtocolGame); m_protocolGame = ProtocolGamePtr(new ProtocolGame);
m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName); m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName);
@ -251,6 +252,16 @@ void Game::use(const ThingPtr& thing)
m_protocolGame->sendUseItem(thing->getPos(), thing->getId(), stackpos, 0);// last 0 has something to do with container m_protocolGame->sendUseItem(thing->getPos(), thing->getId(), stackpos, 0);// last 0 has something to do with container
} }
void Game::useWith(const ThingPtr& fromThing, const ThingPtr& toThing)
{
if(!m_online || !fromThing || !toThing || !checkBotProtection())
return;
int fromStackpos = getThingStackpos(fromThing), toStackpos = getThingStackpos(toThing);
if(fromStackpos != -1 && toStackpos != -1)
m_protocolGame->sendUseItemEx(fromThing->getPos(), fromThing->getId(), fromStackpos, toThing->getPos(), toThing->getId(), toStackpos);
}
void Game::attack(const CreaturePtr& creature) void Game::attack(const CreaturePtr& creature)
{ {
if(!m_online || !creature || !checkBotProtection()) if(!m_online || !creature || !checkBotProtection())

View File

@ -57,6 +57,7 @@ public:
void turn(Otc::Direction direction); void turn(Otc::Direction direction);
void look(const ThingPtr& thing); void look(const ThingPtr& thing);
void use(const ThingPtr& thing); void use(const ThingPtr& thing);
void useWith(const ThingPtr& fromThing, const ThingPtr& toThing);
void attack(const CreaturePtr& creature); void attack(const CreaturePtr& creature);
void cancelAttack(); void cancelAttack();
void follow(const CreaturePtr& creature); void follow(const CreaturePtr& creature);
@ -82,6 +83,9 @@ public:
bool isOnline() { return m_online; } bool isOnline() { return m_online; }
bool isDead() { return m_dead; } bool isDead() { return m_dead; }
void setSelectedThing(const ThingPtr& thing) { m_selectedThing = thing; }
ThingPtr getSelectedThing() { return m_selectedThing; }
void setServerBeat(int serverBeat) { m_serverBeat = serverBeat; } void setServerBeat(int serverBeat) { m_serverBeat = serverBeat; }
int getServerBeat() { return m_serverBeat; } int getServerBeat() { return m_serverBeat; }
@ -101,6 +105,7 @@ private:
Timer m_walkPingTimer; Timer m_walkPingTimer;
int m_walkPing; int m_walkPing;
int m_serverBeat; int m_serverBeat;
ThingPtr m_selectedThing;
}; };
extern Game g_game; extern Game g_game;

View File

@ -179,6 +179,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction<Game>("setOutfit", std::bind(&Game::setOutfit, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("setOutfit", std::bind(&Game::setOutfit, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("look", std::bind(&Game::look, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("look", std::bind(&Game::look, &g_game, _1));
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>("attack", std::bind(&Game::attack, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("attack", std::bind(&Game::attack, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("cancelAttack", std::bind(&Game::cancelAttack, &g_game)); g_lua.bindClassStaticFunction<Game>("cancelAttack", std::bind(&Game::cancelAttack, &g_game));
g_lua.bindClassStaticFunction<Game>("follow", std::bind(&Game::follow, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("follow", std::bind(&Game::follow, &g_game, _1));
@ -199,6 +200,8 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction<Game>("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3)); g_lua.bindClassStaticFunction<Game>("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction<Game>("getLocalPlayer", std::bind(&Game::getLocalPlayer, &g_game)); g_lua.bindClassStaticFunction<Game>("getLocalPlayer", std::bind(&Game::getLocalPlayer, &g_game));
g_lua.bindClassStaticFunction<Game>("getProtocolVersion", std::bind(&Game::getProtocolVersion, &g_game)); g_lua.bindClassStaticFunction<Game>("getProtocolVersion", std::bind(&Game::getProtocolVersion, &g_game));
g_lua.bindClassStaticFunction<Game>("setSelectedThing", std::bind(&Game::setSelectedThing, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("getSelectedThing", std::bind(&Game::getSelectedThing, &g_game));
g_lua.registerClass<UIItem, UIWidget>(); g_lua.registerClass<UIItem, UIWidget>();
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); } ); g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); } );