walk changes, not done yet
This commit is contained in:
parent
b6b823aa9c
commit
4d90b674ac
|
@ -136,10 +136,7 @@ void Creature::draw(int x, int y)
|
|||
|
||||
if(((m_walkOffsetX == 0 && m_walkOffsetY == 0) && m_walkOffsetX != m_walkOffsetY) ||
|
||||
((m_walkOffsetX == 0 || m_walkOffsetY == 0) && m_walkOffsetX == m_walkOffsetY)) {
|
||||
m_walking = false;
|
||||
m_walkOffsetX = 0;
|
||||
m_walkOffsetY = 0;
|
||||
m_animation = 0;
|
||||
cancelWalk(m_direction);
|
||||
}
|
||||
|
||||
m_lastTicks = g_platform.getTicks() - remainingTime;
|
||||
|
@ -174,50 +171,44 @@ void Creature::walk(const Position& position)
|
|||
m_walking = true;
|
||||
m_walkOffsetX = 0;
|
||||
m_walkOffsetY = 0;
|
||||
m_walkingFromPosition = m_position;
|
||||
int walkTimeFactor = 1;
|
||||
|
||||
// update map tiles
|
||||
g_map.removeThingByPtr(asThing());
|
||||
m_position = position;
|
||||
g_map.addThing(asThing());
|
||||
|
||||
// set new direction
|
||||
if(m_walkingFromPosition + Position(0, -1, 0) == m_position) {
|
||||
if(m_position + Position(0, -1, 0) == position) {
|
||||
m_direction = Otc::North;
|
||||
m_walkOffsetY = 32;
|
||||
}
|
||||
else if(m_walkingFromPosition + Position(1, 0, 0) == m_position) {
|
||||
else if(m_position + Position(1, 0, 0) == position) {
|
||||
m_direction = Otc::East;
|
||||
m_walkOffsetX = -32;
|
||||
}
|
||||
else if(m_walkingFromPosition + Position(0, 1, 0) == m_position) {
|
||||
else if(m_position + Position(0, 1, 0) == position) {
|
||||
m_direction = Otc::South;
|
||||
m_walkOffsetY = -32;
|
||||
}
|
||||
else if(m_walkingFromPosition + Position(-1, 0, 0) == m_position) {
|
||||
else if(m_position + Position(-1, 0, 0) == position) {
|
||||
m_direction = Otc::West;
|
||||
m_walkOffsetX = 32;
|
||||
}
|
||||
else if(m_walkingFromPosition + Position(1, -1, 0) == m_position) {
|
||||
else if(m_position + Position(1, -1, 0) == position) {
|
||||
m_direction = Otc::NorthEast;
|
||||
m_walkOffsetX = -32;
|
||||
m_walkOffsetY = 32;
|
||||
walkTimeFactor = 2;
|
||||
}
|
||||
else if(m_walkingFromPosition + Position(1, 1, 0) == m_position) {
|
||||
else if(m_position + Position(1, 1, 0) == position) {
|
||||
m_direction = Otc::SouthEast;
|
||||
m_walkOffsetX = -32;
|
||||
m_walkOffsetY = -32;
|
||||
walkTimeFactor = 2;
|
||||
}
|
||||
else if(m_walkingFromPosition + Position(-1, 1, 0) == m_position) {
|
||||
else if(m_position + Position(-1, 1, 0) == position) {
|
||||
m_direction = Otc::SouthWest;
|
||||
m_walkOffsetX = 32;
|
||||
m_walkOffsetY = -32;
|
||||
walkTimeFactor = 2;
|
||||
}
|
||||
else if(m_walkingFromPosition + Position(-1, -1, 0) == m_position) {
|
||||
else if(m_position + Position(-1, -1, 0) == position) {
|
||||
m_direction = Otc::NorthWest;
|
||||
m_walkOffsetX = 32;
|
||||
m_walkOffsetY = 32;
|
||||
|
@ -228,6 +219,12 @@ void Creature::walk(const Position& position)
|
|||
m_walking = false;
|
||||
}
|
||||
|
||||
// update map tiles
|
||||
g_map.removeThingByPtr(asThing());
|
||||
m_position = position;
|
||||
g_map.addThing(asThing());
|
||||
|
||||
if(m_walking) {
|
||||
// Calculate xDiv
|
||||
if(m_direction >= 4) {
|
||||
if(m_direction == Otc::NorthEast || m_direction == Otc::SouthEast)
|
||||
|
@ -253,6 +250,16 @@ void Creature::walk(const Position& position)
|
|||
|
||||
m_lastTicks = g_platform.getTicks();
|
||||
}
|
||||
}
|
||||
|
||||
void Creature::cancelWalk(Otc::Direction direction)
|
||||
{
|
||||
m_walking = false;
|
||||
m_walkOffsetX = 0;
|
||||
m_walkOffsetY = 0;
|
||||
m_animation = 0;
|
||||
m_direction = direction;
|
||||
}
|
||||
|
||||
void Creature::setHealthPercent(uint8 healthPercent)
|
||||
{
|
||||
|
|
|
@ -71,6 +71,7 @@ public:
|
|||
void onHealthPercentChange(int);
|
||||
|
||||
void walk(const Position& position);
|
||||
void cancelWalk(Otc::Direction direction);
|
||||
int getWalkOffsetX() { return m_walkOffsetX; }
|
||||
int getWalkOffsetY() { return m_walkOffsetY; }
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ void Game::walk(Otc::Direction direction)
|
|||
|
||||
// TODO: check if we can walk.
|
||||
|
||||
//m_localPlayer->setDirection(direction);
|
||||
m_localPlayer->walk(direction);
|
||||
|
||||
switch(direction) {
|
||||
case Otc::North:
|
||||
|
|
|
@ -22,3 +22,9 @@
|
|||
|
||||
#include "localplayer.h"
|
||||
|
||||
void LocalPlayer::walk(Otc::Direction direction)
|
||||
{
|
||||
//Position newPos = m_position + Position::getPositionFromDirection(direction);
|
||||
|
||||
//asCreature()->walk(newPos);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ public:
|
|||
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 walk(Otc::Direction direction);
|
||||
|
||||
LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); }
|
||||
|
||||
private:
|
||||
|
|
|
@ -34,7 +34,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
|
|||
{
|
||||
while(!msg.eof()) {
|
||||
uint8 opt = msg.getU8();
|
||||
//dump << "protocol id:" << std::hex << (int)opt;
|
||||
dump << "protocol id:" << std::hex << (int)opt;
|
||||
|
||||
switch(opt) {
|
||||
case 0x0A:
|
||||
|
@ -763,7 +763,7 @@ void ProtocolGame::parseTextMessage(InputMessage& msg)
|
|||
void ProtocolGame::parseCancelWalk(InputMessage& msg)
|
||||
{
|
||||
Otc::Direction direction = (Otc::Direction)msg.getU8();
|
||||
g_game.getLocalPlayer()->setDirection(direction);
|
||||
m_localPlayer->cancelWalk(direction);
|
||||
}
|
||||
|
||||
void ProtocolGame::parseFloorChangeUp(InputMessage& msg)
|
||||
|
@ -1008,6 +1008,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
|
|||
creature->setShield(shield);
|
||||
creature->setEmblem(emblem);
|
||||
creature->setImpassable(impassable);
|
||||
creature->cancelWalk(direction);
|
||||
|
||||
thing = creature;
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#ifndef POSITION_H
|
||||
#define POSITION_H
|
||||
|
||||
#include <otclient/const.h>
|
||||
#include <framework/util/types.h>
|
||||
|
||||
class Position
|
||||
|
@ -31,6 +32,29 @@ public:
|
|||
Position() : x(-1), y(-1), z(-1) { }
|
||||
Position(int x, int y, int z) : x(x), y(y), z(z) { }
|
||||
|
||||
static Position getPositionFromDirection(Otc::Direction direction) {
|
||||
switch(direction) {
|
||||
case Otc::North:
|
||||
return Position( 0, -1, 0);
|
||||
case Otc::East:
|
||||
return Position( 1, 0, 0);
|
||||
case Otc::South:
|
||||
return Position( 0, 1, 0);
|
||||
case Otc::West:
|
||||
return Position(-1, 0, 0);
|
||||
case Otc::NorthEast:
|
||||
return Position( 1, -1, 0);
|
||||
case Otc::SouthEast:
|
||||
return Position( 1, 1, 0);
|
||||
case Otc::SouthWest:
|
||||
return Position(-1, 1, 0);
|
||||
case Otc::NorthWest:
|
||||
return Position(-1, -1, 0);
|
||||
default:
|
||||
return Position();
|
||||
}
|
||||
}
|
||||
|
||||
bool isValid() const { return x >= 0 && y >= 0 && z >= 0 && x < 65536 && y < 65536 && z < 15; }
|
||||
|
||||
Position operator+(const Position& other) const { return Position(x + other.x, y + other.y, z + other.z); }
|
||||
|
|
Loading…
Reference in New Issue