bot traceback, moveup function, chat setting default ongamestart

This commit is contained in:
Henrique Santiago 2012-04-25 21:15:48 -03:00
parent c89665848d
commit 60495174a4
5 changed files with 21 additions and 3 deletions

View File

@ -194,8 +194,7 @@ function GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatu
if lookThing then if lookThing then
local parentContainer = lookThing:getParentContainer() local parentContainer = lookThing:getParentContainer()
if parentContainer and parentContainer:hasParent() then if parentContainer and parentContainer:hasParent() then
local pos = lookThing:getPosition() menu:addOption('Move up', function() g_game.moveToParentContainer(lookThing, lookThing:getCount()) end)
menu:addOption('Move up', function() g_game.move(lookThing, { x=pos.x, y=pos.y, z=254 }, lookThing:getCount()) end)
end end
end end

View File

@ -176,6 +176,12 @@ local function onChannelList(channelList)
end end
end end
local function onGameStart()
local tab = Console.getTab('Default')
if tab then
addEvent(function() consoleTabBar:selectTab(tab) end, false)
end
end
-- public functions -- public functions
function Console.init() function Console.init()
@ -185,6 +191,7 @@ function Console.init()
onOpenPrivateChannel = onOpenPrivateChannel, onOpenPrivateChannel = onOpenPrivateChannel,
onOpenOwnPrivateChannel = onOpenOwnPrivateChannel, onOpenOwnPrivateChannel = onOpenOwnPrivateChannel,
onCloseChannel = onCloseChannel, onCloseChannel = onCloseChannel,
onGameStart = onGameStart,
onGameEnd = Console.clear }) onGameEnd = Console.clear })
consolePanel = displayUI('console.otui', GameInterface.getBottomPanel()) consolePanel = displayUI('console.otui', GameInterface.getBottomPanel())
@ -221,6 +228,7 @@ function Console.terminate()
onOpenPrivateChannel = onOpenPrivateChannel, onOpenPrivateChannel = onOpenPrivateChannel,
onOpenOwnPrivateChannel = onOpenPrivateChannel, onOpenOwnPrivateChannel = onOpenPrivateChannel,
onCloseChannel = onCloseChannel, onCloseChannel = onCloseChannel,
onGameStart = onGameStart,
onGameEnd = Console.clear }) onGameEnd = Console.clear })
for channelid, channelname in pairs(channels) do for channelid, channelname in pairs(channels) do

View File

@ -521,6 +521,15 @@ void Game::move(const ThingPtr& thing, const Position& toPos, int count)
m_protocolGame->sendMove(thing->getPosition(), thing->getId(), thing->getStackpos(), toPos, count); m_protocolGame->sendMove(thing->getPosition(), thing->getId(), thing->getStackpos(), toPos, count);
} }
void Game::moveToParentContainer(const ThingPtr& thing, int count)
{
if(!canPerformGameAction() || !thing || count <= 0)
return;
Position position = thing->getPosition();
move(thing, Position(position.x, position.y, 254), count);
}
void Game::rotate(const ThingPtr& thing) void Game::rotate(const ThingPtr& thing)
{ {
if(!canPerformGameAction() || !thing) if(!canPerformGameAction() || !thing)
@ -927,7 +936,7 @@ bool Game::checkBotProtection()
// accepts calls comming from a stacktrace containing only C++ functions, // accepts calls comming from a stacktrace containing only C++ functions,
// if the stacktrace contains a lua function, then only accept if the engine is processing an input event // if the stacktrace contains a lua function, then only accept if the engine is processing an input event
if(g_lua.isInCppCallback() && !g_ui.isOnInputEvent()) { if(g_lua.isInCppCallback() && !g_ui.isOnInputEvent()) {
logError("caught a lua call to a bot protected game function, the call was canceled"); logError(g_lua.traceback("caught a lua call to a bot protected game function, the call was canceled"));
return false; return false;
} }
#endif #endif

View File

@ -132,6 +132,7 @@ public:
// item related // item related
void look(const ThingPtr& thing); void look(const ThingPtr& thing);
void move(const ThingPtr &thing, const Position& toPos, int count); void move(const ThingPtr &thing, const Position& toPos, int count);
void moveToParentContainer(const ThingPtr& thing, int count);
void rotate(const ThingPtr& thing); void rotate(const ThingPtr& thing);
void use(const ThingPtr& thing); void use(const ThingPtr& thing);
void useWith(const ItemPtr& fromThing, const ThingPtr& toThing); void useWith(const ItemPtr& fromThing, const ThingPtr& toThing);

View File

@ -89,6 +89,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction("g_game", "stop", std::bind(&Game::stop, &g_game)); g_lua.bindClassStaticFunction("g_game", "stop", std::bind(&Game::stop, &g_game));
g_lua.bindClassStaticFunction("g_game", "look", std::bind(&Game::look, &g_game, std::placeholders::_1)); g_lua.bindClassStaticFunction("g_game", "look", std::bind(&Game::look, &g_game, std::placeholders::_1));
g_lua.bindClassStaticFunction("g_game", "move", std::bind(&Game::move, &g_game, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); g_lua.bindClassStaticFunction("g_game", "move", std::bind(&Game::move, &g_game, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
g_lua.bindClassStaticFunction("g_game", "moveToParentContainer", std::bind(&Game::moveToParentContainer, &g_game, std::placeholders::_1, std::placeholders::_2));
g_lua.bindClassStaticFunction("g_game", "rotate", std::bind(&Game::rotate, &g_game, std::placeholders::_1)); g_lua.bindClassStaticFunction("g_game", "rotate", std::bind(&Game::rotate, &g_game, std::placeholders::_1));
g_lua.bindClassStaticFunction("g_game", "use", std::bind(&Game::use, &g_game, std::placeholders::_1)); g_lua.bindClassStaticFunction("g_game", "use", std::bind(&Game::use, &g_game, std::placeholders::_1));
g_lua.bindClassStaticFunction("g_game", "useWith", std::bind(&Game::useWith, &g_game, std::placeholders::_1, std::placeholders::_2)); g_lua.bindClassStaticFunction("g_game", "useWith", std::bind(&Game::useWith, &g_game, std::placeholders::_1, std::placeholders::_2));