target rework, improved map clicking
This commit is contained in:
parent
4a179cd212
commit
d04596c5fd
3
TODO
3
TODO
|
@ -86,3 +86,6 @@
|
||||||
[baxnie] edit texts
|
[baxnie] edit texts
|
||||||
[baxnie] ignore list
|
[baxnie] ignore list
|
||||||
[baxnie] viplist marks
|
[baxnie] viplist marks
|
||||||
|
[baxnie] fix walk jump when cancel creature following
|
||||||
|
[baxnie] fix creature outfit when invisible or with item appearance
|
||||||
|
|
||||||
|
|
|
@ -30,22 +30,24 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||||
end
|
end
|
||||||
|
|
||||||
if creatureThing then
|
if creatureThing then
|
||||||
|
|
||||||
menu:addSeparator()
|
menu:addSeparator()
|
||||||
|
|
||||||
if creatureThing:asLocalPlayer() then
|
if creatureThing:asLocalPlayer() then
|
||||||
menu:addOption('Set Outfit', function() Game.openOutfitWindow() end)
|
menu:addOption('Set Outfit', function() Game.openOutfitWindow() end)
|
||||||
else
|
else
|
||||||
if Game.getAttackingCreature() ~= creatureThing then
|
local localPlayer = Game.getLocalPlayer()
|
||||||
menu:addOption('Attack', function() Game.attack(creatureThing) end)
|
if localPlayer then
|
||||||
else
|
if localPlayer:getAttackingCreature() ~= creatureThing then
|
||||||
menu:addOption('Stop Attack', function() Game.cancelAttack() end)
|
menu:addOption('Attack', function() Game.attack(creatureThing) end)
|
||||||
end
|
else
|
||||||
|
menu:addOption('Stop Attack', function() Game.cancelAttack() end)
|
||||||
if Game.getFollowingCreature() ~= creatureThing then
|
end
|
||||||
menu:addOption('Follow', function() Game.follow(creatureThing) end)
|
|
||||||
else
|
if localPlayer:getFollowingCreature() ~= creatureThing then
|
||||||
menu:addOption('Stop Follow', function() Game.cancelFollow() end)
|
menu:addOption('Follow', function() Game.follow(creatureThing) end)
|
||||||
|
else
|
||||||
|
menu:addOption('Stop Follow', function() Game.cancelFollow() end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if creatureThing:asPlayer() then
|
if creatureThing:asPlayer() then
|
||||||
|
|
|
@ -116,19 +116,20 @@ void Game::processInventoryChange(int slot, const ItemPtr& item)
|
||||||
|
|
||||||
void Game::processAttackCancel()
|
void Game::processAttackCancel()
|
||||||
{
|
{
|
||||||
if(m_attackingCreature) {
|
if(m_localPlayer->isAttacking())
|
||||||
m_attackingCreature->hideStaticSquare();
|
m_localPlayer->setAttackingCreature(nullptr);
|
||||||
m_attackingCreature = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::walk(Otc::Direction direction)
|
void Game::walk(Otc::Direction direction)
|
||||||
{
|
{
|
||||||
|
if(m_localPlayer->isFollowing()) {
|
||||||
|
cancelFollow();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(!isOnline() || isDead() || !checkBotProtection() || !m_localPlayer->canWalk(direction))
|
if(!isOnline() || isDead() || !checkBotProtection() || !m_localPlayer->canWalk(direction))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cancelFollow();
|
|
||||||
|
|
||||||
m_localPlayer->clientWalk(direction);
|
m_localPlayer->clientWalk(direction);
|
||||||
|
|
||||||
switch(direction) {
|
switch(direction) {
|
||||||
|
@ -205,22 +206,17 @@ void Game::attack(const CreaturePtr& creature)
|
||||||
if(!m_online || !creature || !checkBotProtection())
|
if(!m_online || !creature || !checkBotProtection())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(m_attackingCreature)
|
if(m_localPlayer->isFollowing())
|
||||||
m_attackingCreature->hideStaticSquare();
|
cancelFollow();
|
||||||
|
|
||||||
creature->showStaticSquare(Fw::red);
|
|
||||||
m_attackingCreature = creature;
|
|
||||||
|
|
||||||
|
m_localPlayer->setAttackingCreature(creature);
|
||||||
m_protocolGame->sendAttack(creature->getId());
|
m_protocolGame->sendAttack(creature->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::cancelAttack()
|
void Game::cancelAttack()
|
||||||
{
|
{
|
||||||
if(m_attackingCreature) {
|
m_localPlayer->setAttackingCreature(nullptr);
|
||||||
m_protocolGame->sendAttack(0);
|
m_protocolGame->sendAttack(0);
|
||||||
m_attackingCreature->hideStaticSquare();
|
|
||||||
m_attackingCreature = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::follow(const CreaturePtr& creature)
|
void Game::follow(const CreaturePtr& creature)
|
||||||
|
@ -228,22 +224,17 @@ void Game::follow(const CreaturePtr& creature)
|
||||||
if(!m_online || !creature || !checkBotProtection())
|
if(!m_online || !creature || !checkBotProtection())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(m_followingCreature)
|
if(m_localPlayer->isAttacking())
|
||||||
m_followingCreature->hideStaticSquare();
|
cancelAttack();
|
||||||
|
|
||||||
creature->showStaticSquare(Fw::green);
|
|
||||||
m_followingCreature = creature;
|
|
||||||
|
|
||||||
|
m_localPlayer->setFollowingCreature(creature);
|
||||||
m_protocolGame->sendFollow(creature->getId());
|
m_protocolGame->sendFollow(creature->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::cancelFollow()
|
void Game::cancelFollow()
|
||||||
{
|
{
|
||||||
if(m_followingCreature) {
|
m_localPlayer->setFollowingCreature(nullptr);
|
||||||
m_protocolGame->sendFollow(0);
|
m_protocolGame->sendFollow(0);
|
||||||
m_followingCreature->hideStaticSquare();
|
|
||||||
m_followingCreature = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::rotate(const ThingPtr& thing)
|
void Game::rotate(const ThingPtr& thing)
|
||||||
|
|
|
@ -70,9 +70,6 @@ public:
|
||||||
|
|
||||||
bool checkBotProtection();
|
bool checkBotProtection();
|
||||||
|
|
||||||
CreaturePtr getAttackingCreature() { return m_attackingCreature; }
|
|
||||||
CreaturePtr getFollowingCreature() { return m_followingCreature; }
|
|
||||||
|
|
||||||
bool isOnline() { return m_online; }
|
bool isOnline() { return m_online; }
|
||||||
bool isDead() { return m_dead; }
|
bool isDead() { return m_dead; }
|
||||||
|
|
||||||
|
@ -89,7 +86,7 @@ private:
|
||||||
bool m_dead;
|
bool m_dead;
|
||||||
int m_serverBeat;
|
int m_serverBeat;
|
||||||
|
|
||||||
CreaturePtr m_attackingCreature, m_followingCreature;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Game g_game;
|
extern Game g_game;
|
||||||
|
|
|
@ -107,3 +107,29 @@ bool LocalPlayer::canWalk(Otc::Direction direction)
|
||||||
|
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,32 +30,37 @@ class LocalPlayer : public Player
|
||||||
public:
|
public:
|
||||||
LocalPlayer();
|
LocalPlayer();
|
||||||
|
|
||||||
void setDrawSpeed(uint16 drawSpeed) { m_drawSpeed = drawSpeed; }
|
|
||||||
uint16 getDrawSpeed() { return m_drawSpeed; }
|
|
||||||
|
|
||||||
void setCanReportBugs(uint8 canReportBugs) { m_canReportBugs = (canReportBugs != 0); }
|
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; }
|
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 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]; }
|
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 clientWalk(Otc::Direction direction);
|
||||||
void walk(const Position& position, bool inverse);
|
void walk(const Position& position, bool inverse);
|
||||||
void cancelWalk(Otc::Direction direction, bool force = false);
|
void cancelWalk(Otc::Direction direction, bool force = false);
|
||||||
bool canWalk(Otc::Direction direction);
|
bool canWalk(Otc::Direction direction);
|
||||||
Otc::Direction getNextWalkDirection() { return m_nextWalkDirection; }
|
|
||||||
|
|
||||||
LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); }
|
LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16 m_drawSpeed;
|
|
||||||
bool m_canReportBugs;
|
bool m_canReportBugs;
|
||||||
bool m_clientWalking;
|
bool m_clientWalking;
|
||||||
Otc::Direction m_nextWalkDirection;
|
Otc::Direction m_nextWalkDirection;
|
||||||
|
CreaturePtr m_attackingCreature, m_followingCreature;
|
||||||
|
int m_icons;
|
||||||
int m_skills[Otc::LastSkill][Otc::LastSkillType];
|
int m_skills[Otc::LastSkill][Otc::LastSkillType];
|
||||||
double m_statistics[Otc::LastStatistic];
|
double m_statistics[Otc::LastStatistic];
|
||||||
};
|
};
|
||||||
|
|
|
@ -84,7 +84,11 @@ void OTClient::registerLuaFunctions()
|
||||||
g_lua.bindClassMemberFunction<Creature>("setEmblemTexture", &Creature::setEmblemTexture);
|
g_lua.bindClassMemberFunction<Creature>("setEmblemTexture", &Creature::setEmblemTexture);
|
||||||
|
|
||||||
g_lua.registerClass<Player, Creature>();
|
g_lua.registerClass<Player, Creature>();
|
||||||
|
|
||||||
g_lua.registerClass<LocalPlayer, Player>();
|
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<Item, Thing>();
|
||||||
g_lua.registerClass<Tile>();
|
g_lua.registerClass<Tile>();
|
||||||
g_lua.registerClass<Map>();
|
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>("inviteToParty", std::bind(&Game::inviteToParty, &g_game, _1));
|
||||||
g_lua.bindClassStaticFunction<Game>("addVip", std::bind(&Game::addVip, &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>("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>("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>("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>("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.registerClass<UIItem, UIWidget>();
|
||||||
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); } );
|
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); } );
|
||||||
|
|
|
@ -265,13 +265,12 @@ void ProtocolGame::parseMessage(InputMessage& msg)
|
||||||
void ProtocolGame::parsePlayerLogin(InputMessage& msg)
|
void ProtocolGame::parsePlayerLogin(InputMessage& msg)
|
||||||
{
|
{
|
||||||
int playerId = msg.getU32();
|
int playerId = msg.getU32();
|
||||||
int playerDrawSpeed = msg.getU16();
|
int serverBeat = msg.getU16();
|
||||||
int playerCanReportBugs = msg.getU8();
|
int playerCanReportBugs = msg.getU8();
|
||||||
|
|
||||||
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
|
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
|
||||||
m_localPlayer->setId(playerId);
|
m_localPlayer->setId(playerId);
|
||||||
g_game.setServerBeat(playerDrawSpeed);
|
g_game.setServerBeat(serverBeat);
|
||||||
m_localPlayer->setDrawSpeed(playerDrawSpeed);
|
|
||||||
m_localPlayer->setCanReportBugs(playerCanReportBugs);
|
m_localPlayer->setCanReportBugs(playerCanReportBugs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,7 +535,6 @@ void ProtocolGame::parseMagicEffect(InputMessage& msg)
|
||||||
|
|
||||||
EffectPtr effect = EffectPtr(new Effect());
|
EffectPtr effect = EffectPtr(new Effect());
|
||||||
effect->setId(effectId);
|
effect->setId(effectId);
|
||||||
effect->setPos(pos);
|
|
||||||
|
|
||||||
g_map.addThing(effect, pos);
|
g_map.addThing(effect, pos);
|
||||||
}
|
}
|
||||||
|
@ -548,7 +546,6 @@ void ProtocolGame::parseAnimatedText(InputMessage& msg)
|
||||||
std::string text = msg.getString();
|
std::string text = msg.getString();
|
||||||
|
|
||||||
AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText);
|
AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText);
|
||||||
animatedText->setPos(position);
|
|
||||||
animatedText->setColor(color);
|
animatedText->setColor(color);
|
||||||
animatedText->setText(text);
|
animatedText->setText(text);
|
||||||
|
|
||||||
|
@ -731,7 +728,8 @@ void ProtocolGame::parsePlayerSkills(InputMessage& msg)
|
||||||
|
|
||||||
void ProtocolGame::parsePlayerIcons(InputMessage& msg)
|
void ProtocolGame::parsePlayerIcons(InputMessage& msg)
|
||||||
{
|
{
|
||||||
msg.getU16(); // icons
|
uint16 icons = msg.getU16();
|
||||||
|
m_localPlayer->setIcons(icons);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolGame::parsePlayerCancelAttack(InputMessage& msg)
|
void ProtocolGame::parsePlayerCancelAttack(InputMessage& msg)
|
||||||
|
|
|
@ -26,9 +26,8 @@
|
||||||
#include <framework/otml/otml.h>
|
#include <framework/otml/otml.h>
|
||||||
#include <framework/graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
#include <otclient/core/tile.h>
|
#include <otclient/core/tile.h>
|
||||||
#include <otclient/core/missile.h>
|
#include <otclient/core/localplayer.h>
|
||||||
#include <otclient/core/effect.h>
|
#include <otclient/core/effect.h>
|
||||||
#include <otclient/core/animatedtext.h>
|
|
||||||
|
|
||||||
UIMap::UIMap()
|
UIMap::UIMap()
|
||||||
{
|
{
|
||||||
|
@ -63,6 +62,9 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
||||||
|
|
||||||
// Get tile position
|
// Get tile position
|
||||||
Point relativeStretchMousePos = mousePos - m_mapRect.topLeft();
|
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);
|
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());
|
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) {
|
if(button == Fw::MouseLeftButton) {
|
||||||
g_game.look(tile->getTopLookThing());
|
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) {
|
else if(button == Fw::MouseRightButton) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue