target rework, improved map clicking

This commit is contained in:
Henrique Santiago 2012-01-07 20:24:29 -02:00
parent 4a179cd212
commit d04596c5fd
9 changed files with 93 additions and 61 deletions

3
TODO
View File

@ -86,3 +86,6 @@
[baxnie] edit texts
[baxnie] ignore list
[baxnie] viplist marks
[baxnie] fix walk jump when cancel creature following
[baxnie] fix creature outfit when invisible or with item appearance

View File

@ -30,22 +30,24 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
end
if creatureThing then
menu:addSeparator()
if creatureThing:asLocalPlayer() then
menu:addOption('Set Outfit', function() Game.openOutfitWindow() end)
else
if Game.getAttackingCreature() ~= creatureThing then
menu:addOption('Attack', function() Game.attack(creatureThing) end)
else
menu:addOption('Stop Attack', function() Game.cancelAttack() end)
end
if Game.getFollowingCreature() ~= creatureThing then
menu:addOption('Follow', function() Game.follow(creatureThing) end)
else
menu:addOption('Stop Follow', function() Game.cancelFollow() end)
local localPlayer = Game.getLocalPlayer()
if localPlayer then
if localPlayer:getAttackingCreature() ~= creatureThing then
menu:addOption('Attack', function() Game.attack(creatureThing) end)
else
menu:addOption('Stop Attack', function() Game.cancelAttack() end)
end
if localPlayer:getFollowingCreature() ~= creatureThing then
menu:addOption('Follow', function() Game.follow(creatureThing) end)
else
menu:addOption('Stop Follow', function() Game.cancelFollow() end)
end
end
if creatureThing:asPlayer() then

View File

@ -116,19 +116,20 @@ void Game::processInventoryChange(int slot, const ItemPtr& item)
void Game::processAttackCancel()
{
if(m_attackingCreature) {
m_attackingCreature->hideStaticSquare();
m_attackingCreature = nullptr;
}
if(m_localPlayer->isAttacking())
m_localPlayer->setAttackingCreature(nullptr);
}
void Game::walk(Otc::Direction direction)
{
if(m_localPlayer->isFollowing()) {
cancelFollow();
return;
}
if(!isOnline() || isDead() || !checkBotProtection() || !m_localPlayer->canWalk(direction))
return;
cancelFollow();
m_localPlayer->clientWalk(direction);
switch(direction) {
@ -205,22 +206,17 @@ void Game::attack(const CreaturePtr& creature)
if(!m_online || !creature || !checkBotProtection())
return;
if(m_attackingCreature)
m_attackingCreature->hideStaticSquare();
creature->showStaticSquare(Fw::red);
m_attackingCreature = creature;
if(m_localPlayer->isFollowing())
cancelFollow();
m_localPlayer->setAttackingCreature(creature);
m_protocolGame->sendAttack(creature->getId());
}
void Game::cancelAttack()
{
if(m_attackingCreature) {
m_protocolGame->sendAttack(0);
m_attackingCreature->hideStaticSquare();
m_attackingCreature = nullptr;
}
m_localPlayer->setAttackingCreature(nullptr);
m_protocolGame->sendAttack(0);
}
void Game::follow(const CreaturePtr& creature)
@ -228,22 +224,17 @@ void Game::follow(const CreaturePtr& creature)
if(!m_online || !creature || !checkBotProtection())
return;
if(m_followingCreature)
m_followingCreature->hideStaticSquare();
creature->showStaticSquare(Fw::green);
m_followingCreature = creature;
if(m_localPlayer->isAttacking())
cancelAttack();
m_localPlayer->setFollowingCreature(creature);
m_protocolGame->sendFollow(creature->getId());
}
void Game::cancelFollow()
{
if(m_followingCreature) {
m_protocolGame->sendFollow(0);
m_followingCreature->hideStaticSquare();
m_followingCreature = nullptr;
}
m_localPlayer->setFollowingCreature(nullptr);
m_protocolGame->sendFollow(0);
}
void Game::rotate(const ThingPtr& thing)

View File

@ -70,9 +70,6 @@ public:
bool checkBotProtection();
CreaturePtr getAttackingCreature() { return m_attackingCreature; }
CreaturePtr getFollowingCreature() { return m_followingCreature; }
bool isOnline() { return m_online; }
bool isDead() { return m_dead; }
@ -89,7 +86,7 @@ private:
bool m_dead;
int m_serverBeat;
CreaturePtr m_attackingCreature, m_followingCreature;
};
extern Game g_game;

View File

@ -107,3 +107,29 @@ bool LocalPlayer::canWalk(Otc::Direction direction)
return true;
}
void LocalPlayer::setAttackingCreature(const CreaturePtr& creature)
{
if(m_attackingCreature) {
m_attackingCreature->hideStaticSquare();
m_attackingCreature = nullptr;
}
if(creature) {
creature->showStaticSquare(Fw::red);
m_attackingCreature = creature;
}
}
void LocalPlayer::setFollowingCreature(const CreaturePtr& creature)
{
if(m_followingCreature) {
m_followingCreature->hideStaticSquare();
m_followingCreature = nullptr;
}
if(creature) {
creature->showStaticSquare(Fw::green);
m_followingCreature = creature;
}
}

View File

@ -30,32 +30,37 @@ class LocalPlayer : public Player
public:
LocalPlayer();
void setDrawSpeed(uint16 drawSpeed) { m_drawSpeed = drawSpeed; }
uint16 getDrawSpeed() { return m_drawSpeed; }
void setCanReportBugs(uint8 canReportBugs) { m_canReportBugs = (canReportBugs != 0); }
bool getCanReportBugs() { return m_canReportBugs; }
void setSkill(Otc::Skill skill, Otc::SkillType skillType, int value) { m_skills[skill][skillType] = value; }
int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; }
void setStatistic(Otc::Statistic statistic, double value) { m_statistics[statistic] = value; }
void setAttackingCreature(const CreaturePtr& creature);
void setFollowingCreature(const CreaturePtr& creature);
void setIcons(int icons) { m_icons = icons; }
bool getCanReportBugs() { return m_canReportBugs; }
int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; }
double getStatistic(Otc::Statistic statistic) { return m_statistics[statistic]; }
CreaturePtr getAttackingCreature() { return m_attackingCreature; }
CreaturePtr getFollowingCreature() { return m_followingCreature; }
Otc::Direction getNextWalkDirection() { return m_nextWalkDirection; }
int getIcons() { return m_icons; }
bool isAttacking() { return m_attackingCreature != nullptr; }
bool isFollowing() { return m_followingCreature != nullptr; }
void clientWalk(Otc::Direction direction);
void walk(const Position& position, bool inverse);
void cancelWalk(Otc::Direction direction, bool force = false);
bool canWalk(Otc::Direction direction);
Otc::Direction getNextWalkDirection() { return m_nextWalkDirection; }
LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); }
private:
uint16 m_drawSpeed;
bool m_canReportBugs;
bool m_clientWalking;
Otc::Direction m_nextWalkDirection;
CreaturePtr m_attackingCreature, m_followingCreature;
int m_icons;
int m_skills[Otc::LastSkill][Otc::LastSkillType];
double m_statistics[Otc::LastStatistic];
};

View File

@ -84,7 +84,11 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Creature>("setEmblemTexture", &Creature::setEmblemTexture);
g_lua.registerClass<Player, Creature>();
g_lua.registerClass<LocalPlayer, Player>();
g_lua.bindClassMemberFunction<LocalPlayer>("getAttackingCreature", &LocalPlayer::getAttackingCreature);
g_lua.bindClassMemberFunction<LocalPlayer>("getFollowingCreature", &LocalPlayer::getFollowingCreature);
g_lua.registerClass<Item, Thing>();
g_lua.registerClass<Tile>();
g_lua.registerClass<Map>();
@ -106,11 +110,10 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction<Game>("inviteToParty", std::bind(&Game::inviteToParty, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("addVip", std::bind(&Game::addVip, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("removeVip", std::bind(&Game::removeVip, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("getAttackingCreature", std::bind(&Game::getAttackingCreature, &g_game));
g_lua.bindClassStaticFunction<Game>("getFollowingCreature", std::bind(&Game::getFollowingCreature, &g_game));
g_lua.bindClassStaticFunction<Game>("talk", std::bind(&Game::talk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("talkChannel", std::bind(&Game::talkChannel, &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.registerClass<UIItem, UIWidget>();
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); } );

View File

@ -265,13 +265,12 @@ void ProtocolGame::parseMessage(InputMessage& msg)
void ProtocolGame::parsePlayerLogin(InputMessage& msg)
{
int playerId = msg.getU32();
int playerDrawSpeed = msg.getU16();
int serverBeat = msg.getU16();
int playerCanReportBugs = msg.getU8();
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
m_localPlayer->setId(playerId);
g_game.setServerBeat(playerDrawSpeed);
m_localPlayer->setDrawSpeed(playerDrawSpeed);
g_game.setServerBeat(serverBeat);
m_localPlayer->setCanReportBugs(playerCanReportBugs);
}
@ -536,7 +535,6 @@ void ProtocolGame::parseMagicEffect(InputMessage& msg)
EffectPtr effect = EffectPtr(new Effect());
effect->setId(effectId);
effect->setPos(pos);
g_map.addThing(effect, pos);
}
@ -548,7 +546,6 @@ void ProtocolGame::parseAnimatedText(InputMessage& msg)
std::string text = msg.getString();
AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText);
animatedText->setPos(position);
animatedText->setColor(color);
animatedText->setText(text);
@ -731,7 +728,8 @@ void ProtocolGame::parsePlayerSkills(InputMessage& msg)
void ProtocolGame::parsePlayerIcons(InputMessage& msg)
{
msg.getU16(); // icons
uint16 icons = msg.getU16();
m_localPlayer->setIcons(icons);
}
void ProtocolGame::parsePlayerCancelAttack(InputMessage& msg)

View File

@ -26,9 +26,8 @@
#include <framework/otml/otml.h>
#include <framework/graphics/graphics.h>
#include <otclient/core/tile.h>
#include <otclient/core/missile.h>
#include <otclient/core/localplayer.h>
#include <otclient/core/effect.h>
#include <otclient/core/animatedtext.h>
UIMap::UIMap()
{
@ -63,6 +62,9 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
// Get tile position
Point relativeStretchMousePos = mousePos - m_mapRect.topLeft();
LocalPlayerPtr localPlayer = g_game.getLocalPlayer();
if(localPlayer)
relativeStretchMousePos += localPlayer->getWalkOffset();
Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS);
PointF stretchFactor(m_mapRect.width() / (float)mapSize.width(), m_mapRect.height() / (float)mapSize.height());
@ -91,6 +93,11 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
if(button == Fw::MouseLeftButton) {
g_game.look(tile->getTopLookThing());
EffectPtr effect = EffectPtr(new Effect);
static int id = 0;
effect->setId(id++);
dump << id;
g_map.addThing(effect, tilePos);
}
else if(button == Fw::MouseRightButton) {