mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
init move items
This commit is contained in:
@@ -299,6 +299,20 @@ void Game::useInventoryItem(int itemId, const ThingPtr& toThing)
|
||||
}
|
||||
}
|
||||
|
||||
void Game::move(const ThingPtr& thing, const Position& toPos, int count)
|
||||
{
|
||||
if(!isOnline() || !thing || !checkBotProtection() || thing->getPos() == toPos || count <= 0)
|
||||
return;
|
||||
|
||||
m_localPlayer->lockWalk();
|
||||
|
||||
int stackpos = getThingStackpos(thing);
|
||||
if(stackpos == -1)
|
||||
return;
|
||||
|
||||
m_protocolGame->sendThrow(thing->getPos(), thing->getId(), stackpos, toPos, count);
|
||||
}
|
||||
|
||||
void Game::attack(const CreaturePtr& creature)
|
||||
{
|
||||
if(!isOnline() || !creature || !checkBotProtection())
|
||||
|
@@ -65,6 +65,7 @@ public:
|
||||
void use(const ThingPtr& thing);
|
||||
void useWith(const ThingPtr& fromThing, const ThingPtr& toThing);
|
||||
void useInventoryItem(int itemId, const ThingPtr& toThing);
|
||||
void move(const ThingPtr &thing, const Position& toPos, int count);
|
||||
|
||||
// attack/follow related
|
||||
void attack(const CreaturePtr& creature);
|
||||
|
@@ -247,6 +247,23 @@ CreaturePtr Tile::getTopCreature()
|
||||
return creature;
|
||||
}
|
||||
|
||||
ThingPtr Tile::getTopMoveThing()
|
||||
{
|
||||
if(isEmpty())
|
||||
return nullptr;
|
||||
|
||||
for(uint i = 0; i < m_things.size(); ++i) {
|
||||
ThingPtr thing = m_things[i];
|
||||
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->asCreature()) {
|
||||
if(i > 0 && thing->isNotMoveable())
|
||||
return m_things[i-1];
|
||||
return thing;
|
||||
}
|
||||
}
|
||||
|
||||
return m_things[0];
|
||||
}
|
||||
|
||||
ThingPtr Tile::getTopMultiUseThing()
|
||||
{
|
||||
// this is related to classic controls, getting top item, forceuse or creature
|
||||
|
@@ -48,6 +48,7 @@ public:
|
||||
ThingPtr getTopLookThing();
|
||||
ThingPtr getTopUseThing();
|
||||
CreaturePtr getTopCreature();
|
||||
ThingPtr getTopMoveThing();
|
||||
ThingPtr getTopMultiUseThing();
|
||||
|
||||
const Position& getPos() { return m_pos; }
|
||||
|
@@ -169,6 +169,7 @@ void OTClient::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopLookThing", &Tile::getTopLookThing);
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopUseThing", &Tile::getTopUseThing);
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopCreature", &Tile::getTopCreature);
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopMoveThing", &Tile::getTopMoveThing);
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopMultiUseThing", &Tile::getTopMultiUseThing);
|
||||
g_lua.bindClassMemberFunction<Tile>("getPos", &Tile::getPos);
|
||||
g_lua.bindClassMemberFunction<Tile>("getDrawElevation", &Tile::getDrawElevation);
|
||||
@@ -237,6 +238,7 @@ void OTClient::registerLuaFunctions()
|
||||
g_lua.registerClass<UIMap, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIMap>("create", []{ return UIMapPtr(new UIMap); } );
|
||||
g_lua.bindClassMemberFunction<UIMap>("getTile", &UIMap::getTile);
|
||||
g_lua.bindClassMemberFunction<UIMap>("getPosition", &UIMap::getPosition);
|
||||
|
||||
g_lua.registerClass<UIGame, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIGame>("create", []{ return UIGamePtr(new UIGame); } );
|
||||
|
@@ -38,10 +38,10 @@ void UIMap::draw()
|
||||
drawChildren();
|
||||
}
|
||||
|
||||
TilePtr UIMap::getTile(const Point& mousePos)
|
||||
Position UIMap::getPosition(const Point& mousePos)
|
||||
{
|
||||
if(!m_mapRect.contains(mousePos))
|
||||
return nullptr;
|
||||
return Position();
|
||||
|
||||
// Get tile position
|
||||
Point relativeStretchMousePos = mousePos - m_mapRect.topLeft();
|
||||
@@ -58,6 +58,15 @@ TilePtr UIMap::getTile(const Point& mousePos)
|
||||
PointF tilePosF = relativeMousePos / Map::NUM_TILE_PIXELS;
|
||||
Position tilePos = Position(1 + (int)tilePosF.x - g_map.getCentralOffset().x, 1 + (int)tilePosF.y - g_map.getCentralOffset().y, 0) + g_map.getCentralPosition();
|
||||
|
||||
return tilePos;
|
||||
}
|
||||
|
||||
TilePtr UIMap::getTile(const Point& mousePos)
|
||||
{
|
||||
Position tilePos = getPosition(mousePos);
|
||||
if(!tilePos.isValid())
|
||||
return nullptr;
|
||||
|
||||
// Get tile
|
||||
TilePtr tile = nullptr;
|
||||
|
||||
|
@@ -32,6 +32,7 @@ class UIMap : public UIWidget
|
||||
public:
|
||||
void draw();
|
||||
|
||||
Position getPosition(const Point& mousePos);
|
||||
TilePtr getTile(const Point& mousePos);
|
||||
|
||||
protected:
|
||||
|
Reference in New Issue
Block a user