diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-07-05 03:41:13 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-07-05 03:41:13 +0300 |
commit | d0571ca16bb4ef11a718cfa78dc29b57080fcc72 (patch) | |
tree | add362fa6b01bb83c608a78b3a56bf8b52136767 /src | |
parent | 0202b0b4cdac57a04a3765f6bca893bd3b5c9812 (diff) | |
download | plus-d0571ca16bb4ef11a718cfa78dc29b57080fcc72.tar.gz plus-d0571ca16bb4ef11a718cfa78dc29b57080fcc72.tar.bz2 plus-d0571ca16bb4ef11a718cfa78dc29b57080fcc72.tar.xz plus-d0571ca16bb4ef11a718cfa78dc29b57080fcc72.zip |
Add ability to send client states to other clients.
Using for this emotes.
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 43 | ||||
-rw-r--r-- | src/being.h | 28 | ||||
-rw-r--r-- | src/defaults.cpp | 1 | ||||
-rw-r--r-- | src/game.cpp | 6 | ||||
-rw-r--r-- | src/gui/beingpopup.cpp | 10 | ||||
-rw-r--r-- | src/gui/popupmenu.cpp | 41 | ||||
-rw-r--r-- | src/gui/setup_other.cpp | 3 | ||||
-rw-r--r-- | src/gui/theme.cpp | 3 | ||||
-rw-r--r-- | src/gui/theme.h | 1 | ||||
-rw-r--r-- | src/localplayer.cpp | 40 | ||||
-rw-r--r-- | src/localplayer.h | 10 | ||||
-rw-r--r-- | src/net/ea/beinghandler.cpp | 13 | ||||
-rw-r--r-- | src/net/tmwa/specialhandler.cpp | 7 |
13 files changed, 180 insertions, 26 deletions
diff --git a/src/being.cpp b/src/being.cpp index f26b2c245..acfe9e445 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -153,6 +153,12 @@ class BeingCacheEntry void setIp(std::string ip) { mIp = ip; } + bool isAdvanced() const + { return mIsAdvanced; } + + void setAdvanced(bool a) + { mIsAdvanced = a; } + protected: int mId; /**< Unique sprite id */ std::string mName; /**< Name of character */ @@ -161,6 +167,7 @@ class BeingCacheEntry unsigned int mPvpRank; int mTime; std::string mIp; + bool mIsAdvanced; }; @@ -218,7 +225,11 @@ Being::Being(int id, Type type, Uint16 subtype, Map *map): mCriticalHit(0), mPvpRank(0), mComment(""), - mGotComment(false) + mGotComment(false), + mAdvanced(false), + mShop(false), + mAway(false), + mInactive(false) { mSpriteRemap = new int[20]; mSpriteHide = new int[20]; @@ -1718,14 +1729,17 @@ void Being::reReadConfig() bool Being::updateFromCache() { BeingCacheEntry *entry = Being::getCacheEntry(getId()); - if (entry && !entry->getName().empty() - && entry->getTime() + 120 < cur_time) + + if (entry && entry->getTime() + 120 >= cur_time) { - setName(entry->getName()); + if (!entry->getName().empty()) + setName(entry->getName()); setPartyName(entry->getPartyName()); setLevel(entry->getLevel()); setPvpRank(entry->getPvpRank()); setIp(entry->getIp()); + + setAdvanced(entry->isAdvanced()); if (mType == PLAYER) updateColors(); return true; @@ -1747,12 +1761,16 @@ void Being::addToCache() beingInfoCache.pop_back(); } } + if (!mLowTraffic) + return; + entry->setName(getName()); entry->setLevel(getLevel()); entry->setPartyName(getPartyName()); entry->setTime(cur_time); entry->setPvpRank(getPvpRank()); entry->setIp(getIp()); + entry->setAdvanced(isAdvanced()); } BeingCacheEntry* Being::getCacheEntry(int id) @@ -2292,6 +2310,23 @@ void Being::saveComment(const std::string &name, resman->saveTextFile(dir, "comment.txt", name + "\n" + comment); } +void Being::setEmote(Uint8 emotion, int emote_time) +{ + if (emotion & FLAG_SPECIAL) + { + mAdvanced = true; + mShop = (emotion & FLAG_SHOP); + mAway = (emotion & FLAG_AWAY); + mInactive = (emotion & FLAG_INACTIVE); +// logger->log("flags: %d", emotion - FLAG_SPECIAL); + } + else + { + mEmotion = emotion; + mEmotionTime = emote_time; + } +} + BeingEquipBackend::BeingEquipBackend(Being *being): mBeing(being) { diff --git a/src/being.h b/src/being.h index b34773ab2..54d922279 100644 --- a/src/being.h +++ b/src/being.h @@ -78,6 +78,7 @@ enum Gender GENDER_UNSPECIFIED = 2 }; + class BeingEquipBackend : public Equipment::Backend { public: @@ -102,6 +103,14 @@ class Being : public ActorSprite, public ConfigListener friend class BeingEquipBackend; friend class LocalPlayer; + enum FLAGS + { + FLAG_SHOP = 1, + FLAG_AWAY = 2, + FLAG_INACTIVE = 4, + FLAG_SPECIAL = 128 + 64 + }; + /** * Action the being is currently performing * WARNING: Has to be in sync with the same enum in the Being class @@ -541,11 +550,7 @@ class Being : public ActorSprite, public ConfigListener * Set the Emoticon type and time displayed above * the being. */ - void setEmote(Uint8 emotion, int emote_time) - { - mEmotion = emotion; - mEmotionTime = emote_time; - } + void setEmote(Uint8 emotion, int emote_time); /** * Get the current Emoticon type displayed above @@ -741,6 +746,15 @@ class Being : public ActorSprite, public ConfigListener static void saveComment(const std::string &name, const std::string &comment); + bool isAdvanced() + { return mAdvanced; } + + void setAdvanced(bool n) + { mAdvanced = n; } + + bool isShopEnabled() + { return mShop; } + protected: /** * Sets the new path for this being. @@ -874,6 +888,10 @@ class Being : public ActorSprite, public ConfigListener int *mSpriteHide; std::string mComment; bool mGotComment; + bool mAdvanced; + bool mShop; + bool mAway; + bool mInactive; }; extern std::list<BeingCacheEntry*> beingInfoCache; diff --git a/src/defaults.cpp b/src/defaults.cpp index 222b73766..2f505502e 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -205,6 +205,7 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "currentTip", 0); AddDEF(configData, "showDidYouKnow", true); AddDEF(configData, "useLocalTime", false); + AddDEF(configData, "enableAdvert", true); return configData; } diff --git a/src/game.cpp b/src/game.cpp index 2d204499d..21f03d42c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1084,13 +1084,19 @@ void Game::handleInput() { // window restore Client::setIsMinimized(false); if (player_node && !player_node->getAwayMode()) + { fpsLimit = config.getIntValue("fpslimit"); + player_node->setHalfAway(false); + } } else { // window minimisation Client::setIsMinimized(true); if (player_node && !player_node->getAwayMode()) + { fpsLimit = config.getIntValue("altfpslimit"); + player_node->setHalfAway(true); + } } Client::setFramerate(fpsLimit); } diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp index 2ba79d1a1..e5dc602a0 100644 --- a/src/gui/beingpopup.cpp +++ b/src/gui/beingpopup.cpp @@ -28,6 +28,7 @@ #include "gui/gui.h" #include "gui/palette.h" +#include "gui/theme.h" #include "gui/widgets/label.h" @@ -96,6 +97,15 @@ void BeingPopup::show(int x, int y, Being *b) else mBeingName->setFont(gui->getSecureFont()); } + if (b->isAdvanced()) + { + mBeingName->setForegroundColor(Theme::getThemeColor( + Theme::PLAYER_ADVANCED)); + } + else + { + mBeingName->setForegroundColor(Theme::getThemeColor(Theme::TEXT)); + } mBeingName->adjustSize(); label1->setCaption(""); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 0ede3d122..ad62f79a8 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -248,8 +248,23 @@ void PopupMenu::showPopup(int x, int y, Being *being) if (player_relations.getDefault() & PlayerRelation::TRADE) { mBrowserBox->addRow("##3---"); - mBrowserBox->addRow(strprintf("@@buy|%s@@", _("Buy"))); - mBrowserBox->addRow(strprintf("@@sell|%s@@", _("Sell"))); + if (being->isAdvanced()) + { + if (being->isShopEnabled()) + { + mBrowserBox->addRow(strprintf( + "@@buy|%s@@", _("Buy"))); + mBrowserBox->addRow(strprintf( + "@@sell|%s@@", _("Sell"))); + } + } + else + { + mBrowserBox->addRow(strprintf( + "@@buy|%s@@", _("Buy (?)"))); + mBrowserBox->addRow(strprintf( + "@@sell|%s@@", _("Sell (?)"))); + } } } break; @@ -428,8 +443,8 @@ void PopupMenu::showPlayerPopup(int x, int y, std::string nick) mBrowserBox->addRow("##3---"); if (player_relations.getDefault() & PlayerRelation::TRADE) { - mBrowserBox->addRow(strprintf("@@buy|%s@@", _("Buy"))); - mBrowserBox->addRow(strprintf("@@sell|%s@@", _("Sell"))); + mBrowserBox->addRow(strprintf("@@buy|%s@@", _("Buy (?)"))); + mBrowserBox->addRow(strprintf("@@sell|%s@@", _("Sell (?)"))); } mBrowserBox->addRow(strprintf("@@name|%s@@", _("Add name to chat"))); @@ -652,8 +667,22 @@ void PopupMenu::showChatPopup(int x, int y, ChatTab *tab) if (player_relations.getDefault() & PlayerRelation::TRADE) { mBrowserBox->addRow("##3---"); - mBrowserBox->addRow(strprintf("@@buy|%s@@", _("Buy"))); - mBrowserBox->addRow(strprintf("@@sell|%s@@", _("Sell"))); + if (being->isAdvanced()) + { + if (being->isShopEnabled()) + { + mBrowserBox->addRow(strprintf( + "@@buy|%s@@", _("Buy"))); + mBrowserBox->addRow(strprintf( + "@@sell|%s@@", _("Sell"))); + } + } + else + { + mBrowserBox->addRow(strprintf("@@buy|%s@@", _("Buy (?)"))); + mBrowserBox->addRow(strprintf( + "@@sell|%s@@", _("Sell (?)"))); + } } mBrowserBox->addRow("##3---"); diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index 0cad07bc1..ca70133a2 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -127,6 +127,9 @@ Setup_Other::Setup_Other() new SetupItemCheckBox(_("Enable attack filter"), "", "enableAttackFilter", this, "enableAttackFilterEvent"); + new SetupItemCheckBox(_("Enable advert protocol"), "", + "enableAdvert", this, "enableAdvertEvent"); + new SetupItemLabel(_("Shop"), "", this); diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 0817df564..92613a3b3 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -638,7 +638,8 @@ static int readColorType(const std::string &type) "AMMO", "SERVER_VERSION_NOT_SUPPORTED", "WARNING", - "CHARM" + "CHARM", + "PLAYER_ADVANCED" }; if (type.empty()) diff --git a/src/gui/theme.h b/src/gui/theme.h index e483bff69..120214232 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -183,6 +183,7 @@ class Theme : public Palette, public ConfigListener SERVER_VERSION_NOT_SUPPORTED, WARNING, CHARM, + PLAYER_ADVANCED, THEME_COLORS_END }; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index ecd75594b..49a475122 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -113,6 +113,7 @@ LocalPlayer::LocalPlayer(int id, int subtype): mAwayDialog(0), mAfkTime(0), mAwayMode(false), + mHalfAwayMode(false), mShowNavigePath(false), mDrawPath(false), mActivityTime(0), @@ -122,13 +123,17 @@ LocalPlayer::LocalPlayer(int id, int subtype): mOldX(0), mOldY(0), mOldTileX(0), mOldTileY(0), mLastHitFrom(""), - mWaitFor("") + mWaitFor(""), + mAdvertTime(0), + mBlockAdvert(false) { logger->log1("LocalPlayer::LocalPlayer"); listen(Mana::CHANNEL_ATTRIBUTES); mLevel = 1; + mAdvanced = true; + mAwayListener = new AwayListener(); mUpdateName = true; @@ -160,6 +165,8 @@ LocalPlayer::LocalPlayer(int id, int subtype): mServerAttack = config.getBoolValue("serverAttack"); mAttackMoving = config.getBoolValue("attackMoving"); mShowJobExp = config.getBoolValue("showJobExp"); + mEnableAdvert = config.getBoolValue("enableAdvert"); + mTradebot = config.getBoolValue("tradebot"); mPingSendTick = 0; mWaitPing = false; @@ -179,6 +186,8 @@ LocalPlayer::LocalPlayer(int id, int subtype): config.addListener("serverAttack", this); config.addListener("attackMoving", this); config.addListener("showJobExp", this); + config.addListener("enableAdvert", this); + config.addListener("tradebot", this); setShowName(config.getBoolValue("showownname")); } @@ -194,6 +203,8 @@ LocalPlayer::~LocalPlayer() config.removeListener("serverAttack", this); config.removeListener("attackMoving", this); config.removeListener("showJobExp", this); + config.removeListener("enableAdvert", this); + config.removeListener("tradebot", this); delete mAwayDialog; mAwayDialog = 0; @@ -331,6 +342,23 @@ void LocalPlayer::logic() } } + if (mEnableAdvert && !mBlockAdvert && mAdvertTime < cur_time) + { + Uint8 smile = FLAG_SPECIAL; + if (mTradebot) + smile += FLAG_SHOP; + + if (mAwayMode) + smile += FLAG_AWAY; + + if (mHalfAwayMode) + smile += FLAG_INACTIVE; + + if (emote(smile)) + mAdvertTime = cur_time + 60; + else + mAdvertTime = cur_time + 30; + } Being::logic(); } @@ -1589,6 +1617,10 @@ void LocalPlayer::optionChanged(const std::string &value) mAttackMoving = config.getBoolValue("attackMoving"); else if (value == "showJobExp") mShowJobExp = config.getBoolValue("showJobExp"); + else if (value == "enableAdvert") + mEnableAdvert = config.getBoolValue("enableAdvert"); + else if (value == "tradebot") + mTradebot = config.getBoolValue("tradebot"); } void LocalPlayer::event(Mana::Channels channel, const Mana::Event &event) @@ -3128,6 +3160,7 @@ void LocalPlayer::changeAwayMode() { mAwayMode = !mAwayMode; mAfkTime = 0; + mHalfAwayMode = false; if (miniStatusWindow) miniStatusWindow->updateStatus(); if (mAwayMode) @@ -3864,6 +3897,11 @@ void LocalPlayer::removeHome() mHomes.erase(key); } +void LocalPlayer::stopAdvert() +{ + mBlockAdvert = true; +} + void AwayListener::action(const gcn::ActionEvent &event) { if (event.getId() == "ok" && player_node && player_node->getAwayMode()) diff --git a/src/localplayer.h b/src/localplayer.h index a5d5563cf..d067237e1 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -331,6 +331,9 @@ class LocalPlayer : public Being, public ActorSpriteListener, void setAway(const std::string &message); + void setHalfAway(bool n) + { mHalfAwayMode = n; } + void afkRespond(ChatTab *tab, const std::string &nick); bool navigateTo(int x, int y); @@ -463,6 +466,8 @@ class LocalPlayer : public Being, public ActorSpriteListener, void removeHome(); + void stopAdvert(); + protected: /** Whether or not the name settings have changed */ bool mUpdateName; @@ -563,6 +568,7 @@ class LocalPlayer : public Being, public ActorSpriteListener, int mPingTime; int mAfkTime; bool mAwayMode; + bool mHalfAwayMode; bool mShowNavigePath; bool mIsServerBuggy; @@ -586,6 +592,10 @@ class LocalPlayer : public Being, public ActorSpriteListener, bool mServerAttack; std::string mLastHitFrom; std::string mWaitFor; + int mAdvertTime; + bool mBlockAdvert; + bool mEnableAdvert; + bool mTradebot; }; extern LocalPlayer *player_node; diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 6875a067e..2da19ad36 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -82,15 +82,10 @@ Being *BeingHandler::createBeing(int id, short job) if (type == ActorSprite::PLAYER || type == ActorSprite::NPC) { - if (!being->updateFromCache()) - { - requestNameById(id); - } - else - { - if (player_node) - player_node->checkNewName(being); - } + being->updateFromCache(); + requestNameById(id); + if (player_node) + player_node->checkNewName(being); } if (type == Being::PLAYER) { diff --git a/src/net/tmwa/specialhandler.cpp b/src/net/tmwa/specialhandler.cpp index 19713a0bf..1e6249a51 100644 --- a/src/net/tmwa/specialhandler.cpp +++ b/src/net/tmwa/specialhandler.cpp @@ -23,6 +23,7 @@ #include "net/tmwa/specialhandler.h" #include "log.h" +#include "localplayer.h" #include "playerinfo.h" #include "gui/skilldialog.h" @@ -152,6 +153,12 @@ void SpecialHandler::handleMessage(Net::MessageIn &msg) std::string msg; if (success == SKILL_FAILED && skillId == SKILL_BASIC) { + if (player_node && bskill == BSKILL_EMOTE + && reason == RFAIL_SKILLDEP) + { + player_node->stopAdvert(); + } + switch (bskill) { case BSKILL_TRADE: |