fix death issues, improve text messages

This commit is contained in:
Eduardo Bart
2012-01-25 12:56:17 -02:00
parent 29f99ee9b3
commit cfcc3fd428
13 changed files with 161 additions and 119 deletions

View File

@@ -261,7 +261,7 @@ public:
return tmp;
}
void bound(const TRect<T> &r) {
void bind(const TRect<T> &r) {
if(isNull() || r.isNull())
return;

View File

@@ -487,7 +487,7 @@ void UIWidget::bindRectToParent()
UIWidgetPtr parent = getParent();
if(parent) {
Rect parentRect = parent->getRect();
boundRect.bound(parentRect);
boundRect.bind(parentRect);
}
setRect(boundRect);

View File

@@ -146,10 +146,10 @@ void Creature::drawInformation(int x, int y, bool useGray, const Rect& visibleRe
// calculate main rects
Rect backgroundRect = Rect(x-(13.5), y, 27, 4);
backgroundRect.bound(visibleRect);
backgroundRect.bind(visibleRect);
Rect textRect = Rect(x - m_nameSize.width() / 2.0, y-12, m_nameSize);
textRect.bound(visibleRect);
textRect.bind(visibleRect);
// distance them
if(textRect.top() == visibleRect.top())

View File

@@ -100,9 +100,78 @@ void Game::processLogout()
void Game::processDeath()
{
m_dead = true;
m_localPlayer->stopWalk();
g_lua.callGlobalField("Game","onDeath");
}
void Game::processPlayerStats(double health, double maxHealth,
double freeCapacity, double experience,
double level, double levelPercent,
double mana, double maxMana,
double magicLevel, double magicLevelPercent,
double soul, double stamina)
{
if(m_localPlayer->getHealth() != health ||
m_localPlayer->getMaxHealth() != maxHealth) {
m_localPlayer->setStatistic(Otc::Health, health);
m_localPlayer->setStatistic(Otc::MaxHealth, maxHealth);
g_lua.callGlobalField("Game", "onHealthChange", health, maxHealth);
// cannot walk while dying
if(health == 0) {
if(m_localPlayer->isPreWalking())
m_localPlayer->stopWalk();
m_localPlayer->lockWalk();
}
}
if(m_localPlayer->getStatistic(Otc::FreeCapacity) != freeCapacity) {
m_localPlayer->setStatistic(Otc::FreeCapacity, freeCapacity);
g_lua.callGlobalField("Game", "onFreeCapacityChange", freeCapacity);
}
if(m_localPlayer->getStatistic(Otc::Experience) != experience) {
m_localPlayer->setStatistic(Otc::Experience, experience);
g_lua.callGlobalField("Game", "onExperienceChange", experience);
}
if(m_localPlayer->getStatistic(Otc::Level) != level ||
m_localPlayer->getStatistic(Otc::LevelPercent) != levelPercent) {
m_localPlayer->setStatistic(Otc::Level, level);
m_localPlayer->setStatistic(Otc::LevelPercent, levelPercent);
g_lua.callGlobalField("Game", "onLevelChange", level, levelPercent);
}
if(m_localPlayer->getStatistic(Otc::Mana) != mana ||
m_localPlayer->getStatistic(Otc::MaxMana) != maxMana) {
m_localPlayer->setStatistic(Otc::Mana, mana);
m_localPlayer->setStatistic(Otc::MaxMana, maxMana);
g_lua.callGlobalField("Game", "onManaChange", mana, maxMana);
}
if(m_localPlayer->getStatistic(Otc::MagicLevel) != magicLevel ||
m_localPlayer->getStatistic(Otc::MagicLevelPercent) != magicLevelPercent) {
m_localPlayer->setStatistic(Otc::MagicLevel, magicLevel);
m_localPlayer->setStatistic(Otc::MagicLevelPercent, magicLevelPercent);
g_lua.callGlobalField("Game", "onMagicLevelChange", magicLevel, magicLevelPercent);
}
if(m_localPlayer->getStatistic(Otc::Soul) != soul) {
m_localPlayer->setStatistic(Otc::Soul, soul);
g_lua.callGlobalField("Game", "onSoulChange", soul);
}
if(m_localPlayer->getStatistic(Otc::Stamina) != stamina) {
m_localPlayer->setStatistic(Otc::Stamina, stamina);
g_lua.callGlobalField("Game", "onStaminaChange", stamina);
}
}
void Game::processTextMessage(const std::string& type, const std::string& message)
{
g_lua.callGlobalField("Game","onTextMessage", type, message);
}
void Game::processCreatureSpeak(const std::string& name, int level, const std::string& type, const std::string& message, int channelId, const Position& creaturePos)
{
if(creaturePos.isValid() && (type == "say" || type == "whisper" || type == "yell" || type == "monsterSay" || type == "monsterYell")) {
@@ -114,11 +183,6 @@ void Game::processCreatureSpeak(const std::string& name, int level, const std::s
g_lua.callGlobalField("Game", "onCreatureSpeak", name, level, type, message, channelId, creaturePos);
}
void Game::processTextMessage(const std::string& type, const std::string& message)
{
g_lua.callGlobalField("Game","onTextMessage", type, message);
}
void Game::processContainerAddItem(int containerId, const ItemPtr& item)
{
if(item)
@@ -137,11 +201,9 @@ void Game::processInventoryChange(int slot, const ItemPtr& item)
void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos)
{
if(!oldPos.isInRange(newPos, 1, 1, 0))
logError("unexpected creature move");
// animate walk
creature->walk(oldPos, newPos);
if(oldPos.isInRange(newPos, 1, 1, 0))
creature->walk(oldPos, newPos);
}
void Game::processCreatureTeleport(const CreaturePtr& creature)

View File

@@ -45,7 +45,12 @@ public:
void processLogin(const LocalPlayerPtr& localPlayer, int serverBeat);
void processLogout();
void processDeath();
void processPlayerStats(double health, double maxHealth,
double freeCapacity, double experience,
double level, double levelPercent,
double mana, double maxMana,
double magicLevel, double magicLevelPercent,
double soul, double stamina);
void processTextMessage(const std::string& type, const std::string& message);
void processCreatureSpeak(const std::string& name, int level, const std::string& type, const std::string& message, int channelId, const Position& creaturePos);
void processContainerAddItem(int containerId, const ItemPtr& item);

View File

@@ -52,6 +52,7 @@ public:
bool isKnown() { return m_known; }
bool isAttacking() { return m_attackingCreature != nullptr; }
bool isFollowing() { return m_followingCreature != nullptr; }
bool isPreWalking() { return m_preWalking; }
void unlockWalk() { m_walkLocked = false; }
void lockWalk();

View File

@@ -33,11 +33,11 @@ StaticText::StaticText()
void StaticText::draw(const Point& p, const Rect& visibleRect)
{
if(m_font) {
Rect rect = Rect(p - Point(m_textSize.width() / 2, m_textSize.height()) + Point(20, 5), m_textSize);
if(visibleRect.contains(rect))
m_font->renderText(m_text, rect, Fw::AlignCenter, m_color);
}
Rect rect = Rect(p - Point(m_textSize.width() / 2, m_textSize.height()) + Point(20, 5), m_textSize);
Rect boundRect = rect;
boundRect.bind(visibleRect);
if((boundRect.center() - rect.center()).length() < visibleRect.width() / 15)
m_font->renderText(m_text, boundRect, Fw::AlignCenter, m_color);
}
bool StaticText::addMessage(const std::string& name, const std::string& type, const std::string& message)
@@ -59,7 +59,7 @@ bool StaticText::addMessage(const std::string& name, const std::string& type, co
auto self = asStaticText();
g_dispatcher.scheduleEvent([self]() {
self->removeMessage();
}, DURATION);
}, std::max<int>(DURATION_PER_CHARACTER * message.length(), MIN_DURATION));
return true;
}
@@ -71,9 +71,7 @@ void StaticText::removeMessage()
if(m_messages.empty()) {
// schedule removal
auto self = asStaticText();
g_dispatcher.scheduleEvent([self]() {
g_map.removeThing(self);
}, 0);
g_dispatcher.addEvent([self]() { g_map.removeThing(self); });
}
else
compose();
@@ -81,43 +79,43 @@ void StaticText::removeMessage()
void StaticText::compose()
{
m_text.clear();
std::string text;
text.clear();
if(m_messageType == "say") {
m_text += m_name;
m_text += " says:\n";
text += m_name;
text += " says:\n";
m_color = Color(239, 239, 0);
}
else if(m_messageType == "whisper") {
m_text += m_name;
m_text += " whispers:\n";
text += m_name;
text += " whispers:\n";
m_color = Color(239, 239, 0);
}
else if(m_messageType == "yell") {
m_text += m_name;
m_text += " yells:\n";
text += m_name;
text += " yells:\n";
m_color = Color(239, 239, 0);
}
else if(m_messageType == "monsterSay" || m_messageType == "monsterYell") {
m_color = Color(254, 101, 0);
}
else if(m_messageType == "npcToPlayer") {
m_text += m_name;
m_text += " says:\n";
text += m_name;
text += " says:\n";
m_color = Color(95, 247, 247);
}
else {
logWarning("unknown speak type: ", m_messageType);
}
// Todo: add break lines
for(uint i = 0; i < m_messages.size(); ++i) {
m_text += m_messages[i];
text += m_messages[i];
if(i < m_messages.size() - 1)
m_text += "\n";
text += "\n";
}
if(m_font)
m_textSize = m_font->calculateTextRectSize(m_text);
m_text = m_font->wrapText(text, 200);
m_textSize = m_font->calculateTextRectSize(m_text);
}

View File

@@ -30,7 +30,8 @@ class StaticText : public Thing
{
public:
enum {
DURATION = 3000
DURATION_PER_CHARACTER = 75,
MIN_DURATION = 3000
};
StaticText();

View File

@@ -687,54 +687,7 @@ void ProtocolGame::parsePlayerStats(InputMessage& msg)
double soul = msg.getU8();
double stamina = msg.getU16();
//TODO: move to game
if(m_localPlayer->getStatistic(Otc::Health) != health ||
m_localPlayer->getStatistic(Otc::MaxHealth) != maxHealth) {
m_localPlayer->setStatistic(Otc::Health, health);
m_localPlayer->setStatistic(Otc::MaxHealth, maxHealth);
g_lua.callGlobalField("Game", "onHealthChange", health, maxHealth);
}
if(m_localPlayer->getStatistic(Otc::FreeCapacity) != freeCapacity) {
m_localPlayer->setStatistic(Otc::FreeCapacity, freeCapacity);
g_lua.callGlobalField("Game", "onFreeCapacityChange", freeCapacity);
}
if(m_localPlayer->getStatistic(Otc::Experience) != experience) {
m_localPlayer->setStatistic(Otc::Experience, experience);
g_lua.callGlobalField("Game", "onExperienceChange", experience);
}
if(m_localPlayer->getStatistic(Otc::Level) != level ||
m_localPlayer->getStatistic(Otc::LevelPercent) != levelPercent) {
m_localPlayer->setStatistic(Otc::Level, level);
m_localPlayer->setStatistic(Otc::LevelPercent, levelPercent);
g_lua.callGlobalField("Game", "onLevelChange", level, levelPercent);
}
if(m_localPlayer->getStatistic(Otc::Mana) != mana ||
m_localPlayer->getStatistic(Otc::MaxMana) != maxMana) {
m_localPlayer->setStatistic(Otc::Mana, mana);
m_localPlayer->setStatistic(Otc::MaxMana, maxMana);
g_lua.callGlobalField("Game", "onManaChange", mana, maxMana);
}
if(m_localPlayer->getStatistic(Otc::MagicLevel) != magicLevel ||
m_localPlayer->getStatistic(Otc::MagicLevelPercent) != magicLevelPercent) {
m_localPlayer->setStatistic(Otc::MagicLevel, magicLevel);
m_localPlayer->setStatistic(Otc::MagicLevelPercent, magicLevelPercent);
g_lua.callGlobalField("Game", "onMagicLevelChange", magicLevel, magicLevelPercent);
}
if(m_localPlayer->getStatistic(Otc::Soul) != soul) {
m_localPlayer->setStatistic(Otc::Soul, soul);
g_lua.callGlobalField("Game", "onSoulChange", soul);
}
if(m_localPlayer->getStatistic(Otc::Stamina) != stamina) {
m_localPlayer->setStatistic(Otc::Stamina, stamina);
g_lua.callGlobalField("Game", "onStaminaChange", stamina);
}
g_game.processPlayerStats(health, maxHealth, freeCapacity, experience, level, levelPercent, mana, maxMana, magicLevel, magicLevelPercent, soul, stamina);
}
void ProtocolGame::parsePlayerSkills(InputMessage& msg)