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) ||
|
if(((m_walkOffsetX == 0 && m_walkOffsetY == 0) && m_walkOffsetX != m_walkOffsetY) ||
|
||||||
((m_walkOffsetX == 0 || m_walkOffsetY == 0) && m_walkOffsetX == m_walkOffsetY)) {
|
((m_walkOffsetX == 0 || m_walkOffsetY == 0) && m_walkOffsetX == m_walkOffsetY)) {
|
||||||
m_walking = false;
|
cancelWalk(m_direction);
|
||||||
m_walkOffsetX = 0;
|
|
||||||
m_walkOffsetY = 0;
|
|
||||||
m_animation = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_lastTicks = g_platform.getTicks() - remainingTime;
|
m_lastTicks = g_platform.getTicks() - remainingTime;
|
||||||
|
@ -174,50 +171,44 @@ void Creature::walk(const Position& position)
|
||||||
m_walking = true;
|
m_walking = true;
|
||||||
m_walkOffsetX = 0;
|
m_walkOffsetX = 0;
|
||||||
m_walkOffsetY = 0;
|
m_walkOffsetY = 0;
|
||||||
m_walkingFromPosition = m_position;
|
|
||||||
int walkTimeFactor = 1;
|
int walkTimeFactor = 1;
|
||||||
|
|
||||||
// update map tiles
|
|
||||||
g_map.removeThingByPtr(asThing());
|
|
||||||
m_position = position;
|
|
||||||
g_map.addThing(asThing());
|
|
||||||
|
|
||||||
// set new direction
|
// 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_direction = Otc::North;
|
||||||
m_walkOffsetY = 32;
|
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_direction = Otc::East;
|
||||||
m_walkOffsetX = -32;
|
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_direction = Otc::South;
|
||||||
m_walkOffsetY = -32;
|
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_direction = Otc::West;
|
||||||
m_walkOffsetX = 32;
|
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_direction = Otc::NorthEast;
|
||||||
m_walkOffsetX = -32;
|
m_walkOffsetX = -32;
|
||||||
m_walkOffsetY = 32;
|
m_walkOffsetY = 32;
|
||||||
walkTimeFactor = 2;
|
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_direction = Otc::SouthEast;
|
||||||
m_walkOffsetX = -32;
|
m_walkOffsetX = -32;
|
||||||
m_walkOffsetY = -32;
|
m_walkOffsetY = -32;
|
||||||
walkTimeFactor = 2;
|
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_direction = Otc::SouthWest;
|
||||||
m_walkOffsetX = 32;
|
m_walkOffsetX = 32;
|
||||||
m_walkOffsetY = -32;
|
m_walkOffsetY = -32;
|
||||||
walkTimeFactor = 2;
|
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_direction = Otc::NorthWest;
|
||||||
m_walkOffsetX = 32;
|
m_walkOffsetX = 32;
|
||||||
m_walkOffsetY = 32;
|
m_walkOffsetY = 32;
|
||||||
|
@ -228,30 +219,46 @@ void Creature::walk(const Position& position)
|
||||||
m_walking = false;
|
m_walking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate xDiv
|
// update map tiles
|
||||||
if(m_direction >= 4) {
|
g_map.removeThingByPtr(asThing());
|
||||||
if(m_direction == Otc::NorthEast || m_direction == Otc::SouthEast)
|
m_position = position;
|
||||||
m_xDiv = Otc::East;
|
g_map.addThing(asThing());
|
||||||
else if(m_direction == Otc::NorthWest || m_direction == Otc::SouthWest)
|
|
||||||
m_xDiv = Otc::West;
|
if(m_walking) {
|
||||||
}
|
// Calculate xDiv
|
||||||
else {
|
if(m_direction >= 4) {
|
||||||
m_xDiv = m_direction;
|
if(m_direction == Otc::NorthEast || m_direction == Otc::SouthEast)
|
||||||
|
m_xDiv = Otc::East;
|
||||||
|
else if(m_direction == Otc::NorthWest || m_direction == Otc::SouthWest)
|
||||||
|
m_xDiv = Otc::West;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_xDiv = m_direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get walk speed
|
||||||
|
int groundSpeed = 0;
|
||||||
|
|
||||||
|
ThingPtr ground = g_map.getThing(m_position, 0);
|
||||||
|
if(ground)
|
||||||
|
groundSpeed = ground->getAttributes().speed;
|
||||||
|
|
||||||
|
float walkTime = walkTimeFactor * 1000.0 * (float)groundSpeed / m_speed;
|
||||||
|
walkTime = walkTime == 0 ? 1000 : walkTime;
|
||||||
|
|
||||||
|
m_walkTimePerPixel = walkTime / 32.0;
|
||||||
|
|
||||||
|
m_lastTicks = g_platform.getTicks();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get walk speed
|
void Creature::cancelWalk(Otc::Direction direction)
|
||||||
int groundSpeed = 0;
|
{
|
||||||
|
m_walking = false;
|
||||||
ThingPtr ground = g_map.getThing(m_position, 0);
|
m_walkOffsetX = 0;
|
||||||
if(ground)
|
m_walkOffsetY = 0;
|
||||||
groundSpeed = ground->getAttributes().speed;
|
m_animation = 0;
|
||||||
|
m_direction = direction;
|
||||||
float walkTime = walkTimeFactor * 1000.0 * (float)groundSpeed / m_speed;
|
|
||||||
walkTime = walkTime == 0 ? 1000 : walkTime;
|
|
||||||
|
|
||||||
m_walkTimePerPixel = walkTime / 32.0;
|
|
||||||
|
|
||||||
m_lastTicks = g_platform.getTicks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Creature::setHealthPercent(uint8 healthPercent)
|
void Creature::setHealthPercent(uint8 healthPercent)
|
||||||
|
|
|
@ -71,6 +71,7 @@ public:
|
||||||
void onHealthPercentChange(int);
|
void onHealthPercentChange(int);
|
||||||
|
|
||||||
void walk(const Position& position);
|
void walk(const Position& position);
|
||||||
|
void cancelWalk(Otc::Direction direction);
|
||||||
int getWalkOffsetX() { return m_walkOffsetX; }
|
int getWalkOffsetX() { return m_walkOffsetX; }
|
||||||
int getWalkOffsetY() { return m_walkOffsetY; }
|
int getWalkOffsetY() { return m_walkOffsetY; }
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ void Game::walk(Otc::Direction direction)
|
||||||
|
|
||||||
// TODO: check if we can walk.
|
// TODO: check if we can walk.
|
||||||
|
|
||||||
//m_localPlayer->setDirection(direction);
|
m_localPlayer->walk(direction);
|
||||||
|
|
||||||
switch(direction) {
|
switch(direction) {
|
||||||
case Otc::North:
|
case Otc::North:
|
||||||
|
|
|
@ -22,3 +22,9 @@
|
||||||
|
|
||||||
#include "localplayer.h"
|
#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; }
|
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]; }
|
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()); }
|
LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -34,7 +34,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
|
||||||
{
|
{
|
||||||
while(!msg.eof()) {
|
while(!msg.eof()) {
|
||||||
uint8 opt = msg.getU8();
|
uint8 opt = msg.getU8();
|
||||||
//dump << "protocol id:" << std::hex << (int)opt;
|
dump << "protocol id:" << std::hex << (int)opt;
|
||||||
|
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 0x0A:
|
case 0x0A:
|
||||||
|
@ -763,7 +763,7 @@ void ProtocolGame::parseTextMessage(InputMessage& msg)
|
||||||
void ProtocolGame::parseCancelWalk(InputMessage& msg)
|
void ProtocolGame::parseCancelWalk(InputMessage& msg)
|
||||||
{
|
{
|
||||||
Otc::Direction direction = (Otc::Direction)msg.getU8();
|
Otc::Direction direction = (Otc::Direction)msg.getU8();
|
||||||
g_game.getLocalPlayer()->setDirection(direction);
|
m_localPlayer->cancelWalk(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolGame::parseFloorChangeUp(InputMessage& msg)
|
void ProtocolGame::parseFloorChangeUp(InputMessage& msg)
|
||||||
|
@ -1008,6 +1008,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
|
||||||
creature->setShield(shield);
|
creature->setShield(shield);
|
||||||
creature->setEmblem(emblem);
|
creature->setEmblem(emblem);
|
||||||
creature->setImpassable(impassable);
|
creature->setImpassable(impassable);
|
||||||
|
creature->cancelWalk(direction);
|
||||||
|
|
||||||
thing = creature;
|
thing = creature;
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#ifndef POSITION_H
|
#ifndef POSITION_H
|
||||||
#define POSITION_H
|
#define POSITION_H
|
||||||
|
|
||||||
|
#include <otclient/const.h>
|
||||||
#include <framework/util/types.h>
|
#include <framework/util/types.h>
|
||||||
|
|
||||||
class Position
|
class Position
|
||||||
|
@ -31,6 +32,29 @@ public:
|
||||||
Position() : x(-1), y(-1), z(-1) { }
|
Position() : x(-1), y(-1), z(-1) { }
|
||||||
Position(int x, int y, int z) : x(x), y(y), z(z) { }
|
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; }
|
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); }
|
Position operator+(const Position& other) const { return Position(x + other.x, y + other.y, z + other.z); }
|
||||||
|
|
Loading…
Reference in New Issue