From dbc3b324a0c5dcb1a0ee29b289e71423a06e85fd Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 8 Jun 2012 00:43:48 +0300 Subject: Add to npc option targetSelection to allow/disallow npc selection. --- src/actorspritemanager.cpp | 19 +++++++++++++++++++ src/resources/beinginfo.cpp | 21 ++++++++++++--------- src/resources/beinginfo.h | 7 +++++++ src/resources/npcdb.cpp | 8 ++++++++ 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index dbd9c6692..4d4511476 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -44,6 +44,8 @@ #include "net/net.h" #include "net/playerhandler.h" +#include "resources/beinginfo.h" + #include #include @@ -348,6 +350,9 @@ Being *ActorSpriteManager::findBeingByPixel(int x, int y, Being *being = static_cast(*it); + if (being->getInfo() && !being->getInfo()->isTargetSelection()) + continue; + if ((being->isAlive() || (targetDead && being->getType() == Being::PLAYER)) && (allPlayers || being != player_node)) @@ -392,6 +397,9 @@ Being *ActorSpriteManager::findBeingByPixel(int x, int y, Being *being = static_cast(*it); + if (being->getInfo() && !being->getInfo()->isTargetSelection()) + continue; + if ((being->getPixelX() - 16 <= x) && (being->getPixelX() + 16 > x) && (being->getPixelY() - 32 <= y) && @@ -422,6 +430,10 @@ void ActorSpriteManager::findBeingsByPixel(std::vector &beings, continue; Being *being = dynamic_cast(*it); + + if (being->getInfo() && !being->getInfo()->isTargetSelection()) + continue; + ActorSprite *actor = *it; if ((being && (being->isAlive() @@ -905,6 +917,10 @@ Being *ActorSpriteManager::findNearestLivingBeing(Being *aroundBeing, continue; } } + + if (being->getInfo() && !being->getInfo()->isTargetSelection()) + continue; + if (validateBeing(aroundBeing, being, type, nullptr, maxDist)) { if (being != excluded) @@ -997,6 +1013,9 @@ Being *ActorSpriteManager::findNearestLivingBeing(Being *aroundBeing, } } + if (being->getInfo() && !being->getInfo()->isTargetSelection()) + continue; + // Being *being = (*i); bool valid = validateBeing(aroundBeing, being, type, excluded, 50); diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 9c8799bc0..1f2bd3e9a 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -32,15 +32,18 @@ BeingInfo *BeingInfo::unknown = nullptr; Attack *BeingInfo::empty = new Attack(SpriteAction::ATTACK, "", ""); -BeingInfo::BeingInfo(): - mName(_("unnamed")), - mTargetCursorSize(ActorSprite::TC_MEDIUM), - mWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER - | Map::BLOCKMASK_MONSTER | Map::BLOCKMASK_AIR - | Map::BLOCKMASK_WATER), - mBlockType(Map::BLOCKTYPE_CHARACTER), - mTargetOffsetX(0), mTargetOffsetY(0), - mMaxHP(0), mStaticMaxHP(false) +BeingInfo::BeingInfo() : + mName(_("unnamed")), + mTargetCursorSize(ActorSprite::TC_MEDIUM), + mWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER + | Map::BLOCKMASK_MONSTER | Map::BLOCKMASK_AIR + | Map::BLOCKMASK_WATER), + mBlockType(Map::BLOCKTYPE_CHARACTER), + mTargetOffsetX(0), + mTargetOffsetY(0), + mMaxHP(0), + mStaticMaxHP(false), + mTargetSelection(true) { SpriteDisplay display; display.sprites.push_back(SpriteReference::Empty); diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index 4aa8f96c8..227bc686e 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -146,6 +146,12 @@ class BeingInfo void setStaticMaxHP(bool n) { mStaticMaxHP = n; } + void setTargetSelection(bool n) + { mTargetSelection = n; } + + bool isTargetSelection() const + { return mTargetSelection; } + static void clear(); private: @@ -160,6 +166,7 @@ class BeingInfo int mTargetOffsetY; int mMaxHP; bool mStaticMaxHP; + bool mTargetSelection; }; typedef std::map BeingInfos; diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index 832fa26d6..26f5e53cb 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -38,6 +38,8 @@ namespace bool mLoaded = false; } +extern int serverVersion; + void NPCDB::load() { if (mLoaded) @@ -70,6 +72,12 @@ void NPCDB::load() BeingInfo *currentInfo = new BeingInfo; + if (serverVersion > 0) + { + currentInfo->setTargetSelection(XML::getProperty( + npcNode, "targetSelection", true)); + } + currentInfo->setTargetCursorSize(XML::getProperty(npcNode, "targetCursor", "medium")); -- cgit v1.2.3-60-g2f50