map position, skills

master
Henrique 13 years ago
parent 00484b96c8
commit 33573e957d

@ -75,6 +75,23 @@ namespace Otc
SpriteNoMask = 255 SpriteNoMask = 255
}; };
enum Skill {
Fist = 0,
Club,
Sword,
Axe,
Distance,
Shielding,
Fishing,
LastSkill
};
enum SkillType {
SkillLevel,
SkillPercent,
LastSkillType
};
enum Direction { enum Direction {
North = 0, North = 0,
East, East,

@ -36,11 +36,16 @@ public:
void setCanReportBugs(uint8 canReportBugs) { m_canReportBugs = (canReportBugs != 0); } void setCanReportBugs(uint8 canReportBugs) { m_canReportBugs = (canReportBugs != 0); }
bool getCanReportBugs() { return m_canReportBugs; } 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]; }
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; uint16 m_drawSpeed;
bool m_canReportBugs; bool m_canReportBugs;
int m_skills[Otc::LastSkill][Otc::LastSkillType];
}; };
#endif #endif

@ -38,14 +38,13 @@ void Map::draw(const Rect& rect)
m_framebuffer->bind(); m_framebuffer->bind();
LocalPlayerPtr player = g_game.getLocalPlayer(); LocalPlayerPtr player = g_game.getLocalPlayer();
Position playerPos = player->getPosition();
int walkOffsetX = player->getWalkOffsetX(); int walkOffsetX = player->getWalkOffsetX();
int walkOffsetY = player->getWalkOffsetY(); int walkOffsetY = player->getWalkOffsetY();
// player is above 7 // player is above 7
int drawFloorStop = 0; int drawFloorStop = 0;
if(playerPos.z <= 7) { if(m_centralPosition.z <= 7) {
// player pos it 8-6. check if we can draw upper floors. // player pos it 8-6. check if we can draw upper floors.
@ -64,9 +63,9 @@ void Map::draw(const Rect& rect)
// if we have something covering us, dont show floors above. // if we have something covering us, dont show floors above.
for(int jz = 6; jz >= 0; --jz) { for(int jz = 6; jz >= 0; --jz) {
Position coverPos = Position(playerPos.x+(7-jz)-1, playerPos.y+(7-jz)-1, jz); Position coverPos = Position(m_centralPosition.x+(7-jz)-1, m_centralPosition.y+(7-jz)-1, jz);
if(const TilePtr& tile = m_tiles[coverPos]) { if(const TilePtr& tile = m_tiles[coverPos]) {
if(tile->getStackSize(3) > 0 && jz < playerPos.z) { if(tile->getStackSize(3) > 0 && jz < m_centralPosition.z) {
drawFloorStop = jz; drawFloorStop = jz;
break; break;
} }
@ -80,11 +79,11 @@ void Map::draw(const Rect& rect)
// +1 in draws cause 64x64 items may affect view. // +1 in draws cause 64x64 items may affect view.
for(int step = 0; step < 2; ++step) { for(int step = 0; step < 2; ++step) {
for(int ix = -8+(playerPos.z-iz); ix < + 8+7; ++ix) { for(int ix = -8+(m_centralPosition.z-iz); ix < + 8+7; ++ix) {
for(int iy = -6+(playerPos.z-iz); iy < + 6+7; ++iy) { for(int iy = -6+(m_centralPosition.z-iz); iy < + 6+7; ++iy) {
Position itemPos = Position(playerPos.x + ix, playerPos.y + iy, iz); Position itemPos = Position(m_centralPosition.x + ix, m_centralPosition.y + iy, iz);
if(const TilePtr& tile = m_tiles[itemPos]) if(const TilePtr& tile = m_tiles[itemPos])
tile->draw((ix + 7 - (playerPos.z-iz))*32 - walkOffsetX, (iy + 5 - (playerPos.z-iz))*32 - walkOffsetY, step); tile->draw((ix + 7 - (m_centralPosition.z-iz))*32 - walkOffsetX, (iy + 5 - (m_centralPosition.z-iz))*32 - walkOffsetY, step);
} }
} }
} }
@ -107,7 +106,7 @@ void Map::draw(const Rect& rect)
// draw player names and health bars // draw player names and health bars
for(int ix = -7; ix <= 7; ++ix) { for(int ix = -7; ix <= 7; ++ix) {
for(int iy = -5; iy <= 5; ++iy) { for(int iy = -5; iy <= 5; ++iy) {
Position itemPos = Position(playerPos.x + ix, playerPos.y + iy, playerPos.z); Position itemPos = Position(m_centralPosition.x + ix, m_centralPosition.y + iy, m_centralPosition.z);
if(const TilePtr& tile = m_tiles[itemPos]) { if(const TilePtr& tile = m_tiles[itemPos]) {
auto& creatures = tile->getCreatures(); auto& creatures = tile->getCreatures();
for(auto it = creatures.rbegin(), end = creatures.rend(); it != end; ++it) { for(auto it = creatures.rbegin(), end = creatures.rend(); it != end; ++it) {
@ -125,7 +124,7 @@ void Map::draw(const Rect& rect)
// TODO: create isCovered function. // TODO: create isCovered function.
bool useGray = (drawFloorStop != playerPos.z-1); bool useGray = (drawFloorStop != m_centralPosition.z-1);
creature->drawInformation(x*horizontalStretchFactor, y*verticalStretchFactor, useGray); creature->drawInformation(x*horizontalStretchFactor, y*verticalStretchFactor, useGray);
} }

@ -42,6 +42,9 @@ public:
void setLight(const Light& light) { m_light = light; } void setLight(const Light& light) { m_light = light; }
Light getLight() { return m_light; } Light getLight() { return m_light; }
void setCentralPosition(const Position& centralPosition) { m_centralPosition = centralPosition; }
Position getCentralPosition() { return m_centralPosition; }
CreaturePtr getCreatureById(uint32 id); CreaturePtr getCreatureById(uint32 id);
void removeCreatureById(uint32 id); void removeCreatureById(uint32 id);
@ -50,6 +53,7 @@ private:
std::map<uint32, CreaturePtr> m_creatures; std::map<uint32, CreaturePtr> m_creatures;
Light m_light; Light m_light;
Position m_centralPosition;
FrameBufferPtr m_framebuffer; FrameBufferPtr m_framebuffer;

@ -307,32 +307,44 @@ void ProtocolGame::parseCanReportBugs(InputMessage& msg)
void ProtocolGame::parseMapDescription(InputMessage& msg) void ProtocolGame::parseMapDescription(InputMessage& msg)
{ {
Position pos = parsePosition(msg); Position pos = parsePosition(msg);
m_localPlayer->setPosition(pos); g_map.setCentralPosition(pos);
setMapDescription(msg, pos.x - 8, pos.y - 6, pos.z, 18, 14); setMapDescription(msg, pos.x - 8, pos.y - 6, pos.z, 18, 14);
} }
void ProtocolGame::parseMoveNorth(InputMessage& msg) void ProtocolGame::parseMoveNorth(InputMessage& msg)
{ {
Position pos = m_localPlayer->getPosition(); Position pos = g_map.getCentralPosition();
pos.y--;
setMapDescription(msg, pos.x - 8, pos.y - 6, pos.z, 18, 1); setMapDescription(msg, pos.x - 8, pos.y - 6, pos.z, 18, 1);
g_map.setCentralPosition(pos);
} }
void ProtocolGame::parseMoveEast(InputMessage& msg) void ProtocolGame::parseMoveEast(InputMessage& msg)
{ {
Position pos = m_localPlayer->getPosition(); Position pos = g_map.getCentralPosition();
pos.x++;
setMapDescription(msg, pos.x + 9, pos.y - 6, pos.z, 1, 14); setMapDescription(msg, pos.x + 9, pos.y - 6, pos.z, 1, 14);
g_map.setCentralPosition(pos);
} }
void ProtocolGame::parseMoveSouth(InputMessage& msg) void ProtocolGame::parseMoveSouth(InputMessage& msg)
{ {
Position pos = m_localPlayer->getPosition(); Position pos = g_map.getCentralPosition();
pos.y++;
setMapDescription(msg, pos.x - 8, pos.y + 7, pos.z, 18, 1); setMapDescription(msg, pos.x - 8, pos.y + 7, pos.z, 18, 1);
g_map.setCentralPosition(pos);
} }
void ProtocolGame::parseMoveWest(InputMessage& msg) void ProtocolGame::parseMoveWest(InputMessage& msg)
{ {
Position pos = m_localPlayer->getPosition(); Position pos = g_map.getCentralPosition();
pos.x--;
setMapDescription(msg, pos.x - 8, pos.y - 6, pos.z, 1, 14); setMapDescription(msg, pos.x - 8, pos.y - 6, pos.z, 1, 14);
g_map.setCentralPosition(pos);
} }
void ProtocolGame::parseUpdateTile(InputMessage& msg) void ProtocolGame::parseUpdateTile(InputMessage& msg)
@ -640,26 +652,9 @@ void ProtocolGame::parsePlayerStats(InputMessage& msg)
void ProtocolGame::parsePlayerSkills(InputMessage& msg) void ProtocolGame::parsePlayerSkills(InputMessage& msg)
{ {
msg.getU8(); // fist skill for(int skill = 0; skill < Otc::LastSkill; skill++)
msg.getU8(); // fist percent for(int skillType = 0; skillType < Otc::LastSkillType; skillType++)
m_localPlayer->setSkill((Otc::Skill)skill, (Otc::SkillType)skillType, msg.getU8());
msg.getU8(); // club skill
msg.getU8(); // club percent
msg.getU8(); // sword skill
msg.getU8(); // sword percent
msg.getU8(); // axe skill
msg.getU8(); // axe percent
msg.getU8(); // distance skill
msg.getU8(); // distance percent
msg.getU8(); // shielding skill
msg.getU8(); // shielding percent
msg.getU8(); // fishing skill
msg.getU8(); // fishing percent
} }
void ProtocolGame::parsePlayerIcons(InputMessage& msg) void ProtocolGame::parsePlayerIcons(InputMessage& msg)
@ -773,25 +768,29 @@ void ProtocolGame::parseCancelWalk(InputMessage& msg)
void ProtocolGame::parseFloorChangeUp(InputMessage& msg) void ProtocolGame::parseFloorChangeUp(InputMessage& msg)
{ {
Position pos = m_localPlayer->getPosition(); logDebug("[ProtocolGame::parseFloorChangeUp]: This function has never been tested.");
Position pos = g_map.getCentralPosition();
pos.z--; pos.z--;
int32 skip = 0; int32 skip = 0;
if(m_localPlayer->getPosition().z == 7) if(pos.z == 7)
for(int32 i = 5; i >= 0; i--) for(int32 i = 5; i >= 0; i--)
setFloorDescription(msg, pos.x - 8, pos.y - 6, i, 18, 14, 8 - i, &skip); setFloorDescription(msg, pos.x - 8, pos.y - 6, i, 18, 14, 8 - i, &skip);
else if(m_localPlayer->getPosition().z > 7) else if(pos.z > 7)
setFloorDescription(msg, pos.x - 8, pos.y - 6, pos.z - 2, 18, 14, 3, &skip); setFloorDescription(msg, pos.x - 8, pos.y - 6, pos.z - 2, 18, 14, 3, &skip);
//pos.x++; pos.x++;
//pos.y++; pos.y++;
//m_localPlayer->setPosition(pos); g_map.setCentralPosition(pos);
} }
void ProtocolGame::parseFloorChangeDown(InputMessage& msg) void ProtocolGame::parseFloorChangeDown(InputMessage& msg)
{ {
Position pos = m_localPlayer->getPosition(); logDebug("[ProtocolGame::parseFloorChangeDown]: This function has never been tested.");
//pos.z++;
Position pos = g_map.getCentralPosition();
pos.z++;
int skip = 0; int skip = 0;
if(pos.z == 8) { if(pos.z == 8) {
@ -802,9 +801,9 @@ void ProtocolGame::parseFloorChangeDown(InputMessage& msg)
else if(pos.z > 8 && pos.z < 14) else if(pos.z > 8 && pos.z < 14)
setFloorDescription(msg, pos.x - 8, pos.y - 6, pos.z + 2, 18, 14, -3, &skip); setFloorDescription(msg, pos.x - 8, pos.y - 6, pos.z + 2, 18, 14, -3, &skip);
//pos.x--; pos.x--;
//pos.y--; pos.y--;
//m_localPlayer->setPosition(pos); g_map.setCentralPosition(pos);
} }
void ProtocolGame::parseOutfitWindow(InputMessage& msg) void ProtocolGame::parseOutfitWindow(InputMessage& msg)

Loading…
Cancel
Save