diff options
-rw-r--r-- | src/gui/magic.cpp | 39 | ||||
-rw-r--r-- | src/gui/magic.h | 13 | ||||
-rw-r--r-- | src/localplayer.cpp | 26 | ||||
-rw-r--r-- | src/localplayer.h | 14 | ||||
-rw-r--r-- | src/net/tmwserv/inventoryhandler.cpp | 6 | ||||
-rw-r--r-- | src/net/tmwserv/playerhandler.cpp | 14 | ||||
-rw-r--r-- | src/net/tmwserv/protocol.h | 3 |
7 files changed, 103 insertions, 12 deletions
diff --git a/src/gui/magic.cpp b/src/gui/magic.cpp index 0906566b..c47faa18 100644 --- a/src/gui/magic.cpp +++ b/src/gui/magic.cpp @@ -36,17 +36,19 @@ MagicDialog::MagicDialog(): setSaveVisible(true); setDefaultSize(255, 30, 175, 225); - gcn::Button *spellButton1 = new Button(_("Cast Test Spell 1"), "spell_1", this); - gcn::Button *spellButton2 = new Button(_("Cast Test Spell 2"), "spell_2", this); - gcn::Button *spellButton3 = new Button(_("Cast Test Spell 3"), "spell_3", this); + mSpellButtons.resize(4); - spellButton1->setPosition(10, 30); - spellButton2->setPosition(10, 60); - spellButton3->setPosition(10, 90); + mSpellButtons[1] = new Button(_("Spell 1"), "spell_1", this); + mSpellButtons[2] = new Button(_("Spell 2"), "spell_2", this); + mSpellButtons[3] = new Button(_("Spell 3"), "spell_3", this); - add(spellButton1); - add(spellButton2); - add(spellButton3); + mSpellButtons[1]->setPosition(10, 60); + mSpellButtons[2]->setPosition(10, 90); + mSpellButtons[3]->setPosition(10, 120); + + add(mSpellButtons[1]); + add(mSpellButtons[2]); + add(mSpellButtons[3]); update(); @@ -87,4 +89,23 @@ void MagicDialog::draw(gcn::Graphics *g) void MagicDialog::update() { + std::map<int, Special> specials = player_node->getSpecialStatus(); + + for (size_t i = 1; i < mSpellButtons.size(); i++) + { + if (specials.find(i) != specials.end()) + { + std::stringstream s; + s << + "Spell" << + i << + " (" << + specials[i].currentMana << + "/" << + specials[i].neededMana << + ")"; + mSpellButtons[i]->setCaption(s.str()); + mSpellButtons[i]->adjustSize(); + } + } } diff --git a/src/gui/magic.h b/src/gui/magic.h index 734ad799..44a1a6fc 100644 --- a/src/gui/magic.h +++ b/src/gui/magic.h @@ -22,6 +22,8 @@ #ifndef MAGIC_H #define MAGIC_H +#include <vector> + #include "gui/widgets/window.h" #include "guichanfwd.h" @@ -29,7 +31,13 @@ #include <guichan/actionlistener.hpp> /** - * The skill dialog. + * The magic interface. + * + * This window is hacked together quickly to test the spell + * recharge netcode. + * It does in no way represent how the interface is going to + * look in the final version. Optimization / cleanup is + * pointless, as it will be redesigned from scratch. * * \ingroup Interface */ @@ -54,6 +62,9 @@ class MagicDialog : public Window, public gcn::ActionListener * Draw this window. */ void draw(gcn::Graphics *g); + + private: + std::vector<gcn::Button *> mSpellButtons; }; extern MagicDialog *magicDialog; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 2f8761e7..241cfe99 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -28,6 +28,7 @@ #include "graphics.h" #include "inventory.h" #include "item.h" +#include "log.h" #include "map.h" #include "monster.h" #include "particle.h" @@ -183,6 +184,23 @@ void LocalPlayer::logic() } mExpMessageTime--; } + + if ((mSpecialRechargeUpdateNeeded%11) == 0) + { + mSpecialRechargeUpdateNeeded = 0; + for (std::map<int, Special>::iterator i = mSpecials.begin(); + i != mSpecials.end(); + i++) + { + i->second.currentMana += i->second.recharge; + if (i->second.currentMana > i->second.neededMana) + { + i->second.currentMana = i->second.neededMana; + } + } + } + mSpecialRechargeUpdateNeeded++; + #else // Targeting allowed 4 times a second if (get_elapsed_time(mLastTarget) >= 250) @@ -669,6 +687,14 @@ void LocalPlayer::useSpecial(int special) Net::GameServer::Player::useSpecial(special); } +void LocalPlayer::setSpecialStatus(int id, int current, int max, int recharge) +{ + logger->log("SpecialUpdate Skill #%d -- (%d/%d) -> %d", id, current, max, recharge); + mSpecials[id].currentMana = current; + mSpecials[id].neededMana = max; + mSpecials[id].recharge = recharge; +} + #endif void LocalPlayer::attack(Being *target, bool keep) diff --git a/src/localplayer.h b/src/localplayer.h index 85681e03..0a3f742b 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -36,6 +36,13 @@ class Map; #ifdef TMWSERV_SUPPORT +struct Special +{ + int currentMana; + int neededMana; + int recharge; +}; + /** * Attributes used during combat. Available to all the beings. */ @@ -215,6 +222,11 @@ class LocalPlayer : public Player #ifdef TMWSERV_SUPPORT void useSpecial(int id); + + void setSpecialStatus(int id, int current, int max, int recharge); + + const std::map<int, Special> &getSpecialStatus() const + { return mSpecials; } #endif void attack(Being *target = NULL, bool keep = false); @@ -450,6 +462,8 @@ class LocalPlayer : public Player int mCharacterPoints; int mCorrectionPoints; int mLevelProgress; + std::map<int, Special> mSpecials; + char mSpecialRechargeUpdateNeeded; #endif int mLevel; int mMoney; diff --git a/src/net/tmwserv/inventoryhandler.cpp b/src/net/tmwserv/inventoryhandler.cpp index 8110fdd2..6993167c 100644 --- a/src/net/tmwserv/inventoryhandler.cpp +++ b/src/net/tmwserv/inventoryhandler.cpp @@ -40,6 +40,8 @@ #include "resources/iteminfo.h" +#include "log.h" // <<< REMOVE ME! + Net::InventoryHandler *inventoryHandler; namespace TmwServ { @@ -102,7 +104,9 @@ void InventoryHandler::unequipItem(const Item *item) Net::GameServer::connection->send(msg); // Tidy equipment directly to avoid weapon still shown bug, for instance - player_node->mEquipment->setEquipment(item->getInvIndex(), 0); + int equipSlot = item->getInvIndex(); + logger->log("Unequipping %d", equipSlot); + player_node->mEquipment->setEquipment(equipSlot, 0); } void InventoryHandler::useItem(const Item *item) diff --git a/src/net/tmwserv/playerhandler.cpp b/src/net/tmwserv/playerhandler.cpp index 69a2bdb4..bbc73b7c 100644 --- a/src/net/tmwserv/playerhandler.cpp +++ b/src/net/tmwserv/playerhandler.cpp @@ -106,6 +106,7 @@ PlayerHandler::PlayerHandler() GPMSG_LEVEL_PROGRESS, GPMSG_RAISE_ATTRIBUTE_RESPONSE, GPMSG_LOWER_ATTRIBUTE_RESPONSE, + GPMSG_SPECIAL_STATUS, 0 }; handledMessages = _messages; @@ -277,6 +278,19 @@ void PlayerHandler::handleMessage(MessageIn &msg) } } break; + + case GPMSG_SPECIAL_STATUS : + { + while (msg.getUnreadLength()) + { + // { B specialID, L current, L max, L recharge } + int id = msg.readInt8(); + int current = msg.readInt32(); + int max = msg.readInt32(); + int recharge = msg.readInt32(); + player_node->setSpecialStatus(id, current, max, recharge); + } + } break; /* case SMSG_PLAYER_ARROW_MESSAGE: { diff --git a/src/net/tmwserv/protocol.h b/src/net/tmwserv/protocol.h index e9fc5b8a..2f1ea885 100644 --- a/src/net/tmwserv/protocol.h +++ b/src/net/tmwserv/protocol.h @@ -107,8 +107,9 @@ enum { GPMSG_BEINGS_MOVE = 0x0280, // { W being id, B flags [, C position, B speed] [, W*2 destination] }* GPMSG_ITEMS = 0x0281, // { W item id, W*2 position }* PGMSG_ATTACK = 0x0290, // W being id - PGMSG_USE_SPECIAL = 0x0292, // B specialID GPMSG_BEING_ATTACK = 0x0291, // W being id + PGMSG_USE_SPECIAL = 0x0292, // B specialID + GPMSG_SPECIAL_STATUS = 0x0293, // { B specialID, L current, L max, L recharge } PGMSG_SAY = 0x02A0, // S text GPMSG_SAY = 0x02A1, // W being id, S text GPMSG_NPC_CHOICE = 0x02B0, // W being id, { S text }* |