35 #include "gui/viewport.h"
61 #include "resources/map/map.h"
75 #define for_actors for (ActorSpritesConstIterator it = mActors.begin(), \
76 it_fend = mActors.end(); it != it_fend; ++it)
78 #define for_actorsm for (ActorSpritesIterator it = mActors.begin(), \
79 it_fend = mActors.end(); it != it_fend; ++it)
90 if ((actor ==
nullptr)
96 const Being *
const b =
static_cast<const Being *
>(actor);
98 const unsigned other_y =
y
119 bool operator() (const
Being *const being)
const
121 if ((being ==
nullptr) || (
findBeing ==
nullptr))
134 bool operator() (const
Being *const being1,
135 const
Being *const being2)
const
137 if ((being1 ==
nullptr) || (being2 ==
nullptr))
156 if (being1->getDistance() != being2->getDistance())
160 && being2->getDistance() > 2)
166 && being1->getDistance() > 2)
170 return being1->getDistance() < being2->getDistance();
173 const int d1 = abs(being1->getTileX() -
x)
174 + abs(being1->getTileY() -
y);
175 const int d2 = abs(being2->getTileX() -
x)
176 + abs(being2->getTileY() -
y);
197 return being1->getName() < being2->getName();
218 mSpellHeal1(
serverConfig.getValue(
"spellHeal1",
"#lum")),
219 mSpellHeal2(
serverConfig.getValue(
"spellHeal2",
"#inma")),
220 mSpellItenplz(
serverConfig.getValue(
"spellItenplz",
"#itenplz")),
222 mTargetDeadPlayers(
config.getBoolValue(
"targetDeadPlayers")),
223 mTargetOnlyReachable(
config.getBoolValue(
"targetOnlyReachable")),
224 mCyclePlayers(
config.getBoolValue(
"cyclePlayers")),
225 mCycleMonsters(
config.getBoolValue(
"cycleMonsters")),
226 mCycleNPC(
config.getBoolValue(
"cycleNPC")),
227 mExtMouseTargeting(
config.getBoolValue(
"extMouseTargeting")),
228 mEnableIdCollecting(
config.getBoolValue(
"enableIdCollecting")),
229 mPriorityAttackMobs(),
230 mPriorityAttackMobsSet(),
231 mPriorityAttackMobsMap(),
236 mIgnoreAttackMobsSet(),
240 mIgnorePickupItems(),
241 mIgnorePickupItemsSet()
354 const int x,
const int y,
361 const int subX,
const int subY,
362 const int *
const cards)
429 if ((actor !=
nullptr) &&
430 actor->
getId() ==
id &&
433 return static_cast<Being*
>(actor);
445 if ((actor !=
nullptr) &&
446 actor->
getId() ==
id)
479 Being *tempBeing =
nullptr;
510 Being *
const being =
static_cast<Being*
>(*it);
512 if (being->
getInfo() !=
nullptr &&
537 if (tempBeing !=
nullptr)
561 Being *
const being =
static_cast<Being*
>(*it);
563 if (being->
getInfo() !=
nullptr &&
583 const int x,
const int y,
616 beings.push_back(actor);
628 const Being *
const being =
static_cast<const Being*
>(*it);
629 if (being ==
nullptr)
631 if ((being->
getInfo() !=
nullptr) &&
647 beings.push_back(actor);
670 Being *
const being =
static_cast<Being*
>(*it);
686 if (actor->
getId() ==
id &&
703 if ((*it)->getTileX() ==
x && (*it)->getTileY() ==
y &&
714 const int x2,
const int y2,
715 const bool serverBuggy)
const
732 && ((*it)->getTileX() >= x1 && (*it)->getTileX() <= x2)
733 && ((*it)->getTileY() >= y1 && (*it)->getTileY() <= y2))
760 unsigned cnt = 65535;
768 && ((*it)->getTileX() >= x1 && (*it)->getTileX() <= x2)
769 && ((*it)->getTileY() >= y1 && (*it)->getTileY() <= y2))
819 maxdist = maxdist * maxdist;
838 if ((d < dist || closestItem ==
nullptr) &&
864 if ((closestItem !=
nullptr) && dist <= maxdist)
885 Being *
const being =
static_cast<Being*
>(*it);
886 if (being->
getName() == name &&
902 Being* closestBeing =
nullptr;
918 Being *
const being =
static_cast<Being*
>(*it);
920 if ((being !=
nullptr) && being->
getName() == name &&
931 && (d < dist || closestBeing ==
nullptr))
934 closestBeing = being;
969 const Being *
const being =
static_cast<const Being*
>(actor);
990 if (actor !=
nullptr)
994 if (itr !=
mActorsIdMap.end() && (*itr).second == actor)
1043 if (game ==
nullptr)
1051 Being *target =
nullptr;
1052 int minDistSquared = 20000;
1059 Being *
const being =
static_cast<Being*
>(*it);
1070 if (!((mapPvpMode != 0) || (teamId != 0)))
1078 const int distSquared = dx * dx + dy * dy;
1079 if (distSquared < minDistSquared)
1081 minDistSquared = distSquared;
1091 const int maxTileDist,
1093 const Being *
const excluded)
const
1109 if (aroundBeing ==
nullptr)
1124 const int x,
const int y,
1125 const Being *
const excluded,
1128 if ((aroundBeing ==
nullptr) || (
localPlayer ==
nullptr))
1131 std::set<std::string> attackMobs;
1132 std::set<std::string> priorityMobs;
1133 std::set<std::string> ignoreAttackMobs;
1136 int defaultAttackIndex = 10000;
1137 int defaultPriorityIndex = 10000;
1140 bool specialDistance =
false;
1144 specialDistance =
true;
1147 maxDist = maxDist * maxDist;
1160 bool ignoreDefault =
false;
1172 if (ignoreAttackMobs.find(std::string()) != ignoreAttackMobs.end())
1173 ignoreDefault =
true;
1175 if (itr != attackMobsMap.end())
1176 defaultAttackIndex = (*itr).second;
1177 itr = priorityMobsMap.find(std::string());
1178 if (itr != priorityMobsMap.end())
1179 defaultPriorityIndex = (*itr).second;
1184 STD_VECTOR<Being*> sortedBeings;
1198 Being *
const being =
static_cast<Being*
>(*i);
1202 if (ignoreAttackMobs.find(being->
getName())
1203 != ignoreAttackMobs.end())
1207 if (ignoreDefault && attackMobs.find(being->
getName())
1208 == attackMobs.end() && priorityMobs.find(being->
getName())
1209 == priorityMobs.end())
1215 if ((being->
getInfo() !=
nullptr)
1221 if (
validateBeing(aroundBeing, being, type,
nullptr, maxDist))
1223 if (being != excluded)
1224 sortedBeings.push_back(being);
1229 if (sortedBeings.empty())
1255 Being *
const target = sortedBeings.at(0);
1267 STD_VECTOR<Being*>::const_iterator i = std::find_if(
1270 if (i == sortedBeings.end() || ++i == sortedBeings.end())
1273 return sortedBeings.at(0);
1281 int index = defaultPriorityIndex;
1282 Being *closestBeing =
nullptr;
1295 Being *
const being =
static_cast<Being*
>(*i);
1299 if (ignoreAttackMobs.find(being->
getName())
1300 != ignoreAttackMobs.end())
1304 if (ignoreDefault && attackMobs.find(being->
getName())
1305 == attackMobs.end() && priorityMobs.find(being->
getName())
1306 == priorityMobs.end())
1312 if ((being->
getInfo() !=
nullptr)
1319 type, excluded, 50);
1341 if (!filtered && (d <= dist || (closestBeing ==
nullptr)))
1344 closestBeing = being;
1348 int w2 = defaultPriorityIndex;
1349 if (closestBeing !=
nullptr)
1353 if (it2 != priorityMobsMap.end())
1359 closestBeing = being;
1363 if (w2 == index && d <= dist)
1366 closestBeing = being;
1372 if (closestBeing ==
nullptr)
1375 closestBeing = being;
1378 if (it1 != priorityMobsMap.end())
1379 index = (*it1).second;
1381 index = defaultPriorityIndex;
1385 return (maxDist >= dist) ? closestBeing :
nullptr;
1391 const Being*
const excluded,
1392 const int maxCost)
const
1396 return (being !=
nullptr) && ((being->
getType() == type
1399 && being != aroundBeing) && being != excluded
1427 if (target !=
nullptr &&
1445 if (target !=
nullptr &&
1467 target !=
nullptr &&
1506 int maxDamageTaken = 0;
1507 Being *target =
nullptr;
1514 Being *
const being =
static_cast<Being*
>(*it);
1516 if ((being ==
nullptr) || !being->
isAlive() ||
1526 const int distance =
fastSqrtInt(dx * dx + dy * dy);
1528 if (distance > maxTileDist)
1615 const Being *
const being =
static_cast<const Being*
>(*it);
1636 if (actor ==
nullptr)
1638 if (actor->
getId() != (*itr).first)
1649 if ((*it)->getId() == actor->
getId())
1661 const std::string &header)
1675 FOR_EACH (STD_VECTOR<Being*>::const_iterator, i, beings)
1680 const Being *
const being = *i;
1712 const Being *
const being =
static_cast<const Being*
>(*it);
1718 names.push_back(being->
getName());
1739 const Being *
const being =
static_cast<const Being*
>(*it);
1743 names.push_back(being->
getName());
1762 Being *
const being =
static_cast<Being*
>(*it);
1783 Being *
const being =
static_cast<Being*
>(*it);
1803 Being *
const being =
static_cast<Being*
>(*it);
1812 levels.append(
", ");
1814 const std::string brkEnd(
"), ");
1815 size_t pos = levels.find(brkEnd, f);
1817 while (pos != std::string::npos)
1819 std::string part = levels.substr(f, pos - f);
1822 const size_t bktPos = part.rfind(
'(');
1823 if (bktPos != std::string::npos)
1827 if (being !=
nullptr)
1829 being->
setLevel(atoi(part.substr(bktPos + 1).c_str()));
1834 pos = levels.find(brkEnd, f);
1842 if (name ==
"targetDeadPlayers")
1844 else if (name ==
"targetOnlyReachable")
1846 else if (name ==
"cyclePlayers")
1848 else if (name ==
"cycleMonsters")
1850 else if (name ==
"cycleNPC")
1852 else if (name ==
"extMouseTargeting")
1854 else if (name ==
"showBadges" || name ==
"visiblenamespos")
1856 else if (name ==
"enableIdCollecting")
1883 #define addMobToList(name, mob) \
1885 const int sz = get##mob##sSize();\
1888 const int idx = get##mob##Index("");\
1891 std::list<std::string>::iterator itr = m##mob##s.end();\
1893 m##mob##s.insert(itr, name);\
1897 m##mob##s.push_back(name);\
1902 m##mob##s.push_back(name);\
1904 m##mob##sSet.insert(name);\
1908 #define rebuildMobsList(mob) \
1910 m##mob##sMap.clear();\
1911 std::list<std::string>::const_iterator i = m##mob##s.begin();\
1913 while (i != m##mob##s.end())\
1915 m##mob##sMap[*i] = cnt;\
1998 #define loadList(key, mob) \
2000 list = unpackList(serverConfig.getValue(key, ""));\
2002 i_end = list.end();\
2007 m##mob##s.push_back(*i);\
2008 m##mob##sSet.insert(*i);\
2016 std::list<std::string> list;
2017 std::list<std::string>::const_iterator i;
2018 std::list<std::string>::const_iterator i_end;
2020 loadList(
"attackPriorityMobs", PriorityAttackMob)
2022 loadList(
"ignoreAttackMobs", IgnoreAttackMob)
2030 loadList(
"pickupItems", PickupItem)
2031 loadList(
"ignorePickupItems", IgnorePickupItem)
2077 const std::set<BeingTypeId> &removeEffects)
2087 Being *
const being =
static_cast<Being*
>(*it);
2089 if (removeEffects.find(type) != removeEffects.end())
2091 const std::map<BeingTypeId, int>::const_iterator
2092 idAdd = addEffects.find(type);
2093 if (idAdd != addEffects.end())
2099 const int dx,
const int dy,
2107 if (dstBeing ==
nullptr)
2116 for (
int slot = 0; slot < sz; slot ++)
2125 const int hairStyle = -srcBeing->
getSpriteID(hairSlot);
2131 ItemDB::get(-hairStyle).getDyeColorsString(hairColor));
2154 Being *
const being =
static_cast<Being*
>(actor);
2176 mIdName[beingId].insert(name);
2177 const std::string idStr =
toString(
id);
2187 (name +
"\n").append(dateStr));
2194 (name +
"\n").append(idStr).append(
"\n").append(dateStr));
2204 FOR_EACH (std::set<std::string>::const_iterator, it, onlinePlayers)
2206 const std::string name = *it;
2215 return std::string();
2220 if (!it->second.empty())
2221 return *(it->second.begin());
2223 return std::string();
2233 Being *
const being =
static_cast<Being*
>(actor);
2235 if ((chat !=
nullptr) && chat->
chatId == chatId)
2245 if (newChat ==
nullptr)
2253 const Being *
const being =
static_cast<const Being*
>(actor);
2255 if ((chat !=
nullptr) && chat->
chatId == newChat->
chatId)
2268 const std::map<int32_t, std::string>::const_iterator it =
mChars.find(
id);
2270 return std::string();
2271 return (*it).second;
2275 const std::string &name)
2285 if (
guild !=
nullptr)
2288 if (member !=
nullptr)
class SortBeingFunctor beingActorSorter
#define loadList(key, mob)
class FindBeingFunctor beingActorFinder
class FindBeingEqualFunctor beingEqualActorFinder
#define rebuildMobsList(mob)
ActorManager * actorManager
#define addMobToList(name, mob)
std::set< ActorSprite * > ActorSprites
IdNameMapping::const_iterator IdNameMappingCIter
ActorSprites::const_iterator ActorSpritesConstIterator
ActorSpritesMap::iterator ActorSpritesMapIterator
ActorSpritesMap::const_iterator ActorSpritesMapConstIterator
const bool AllowSort_true
const bool AllPlayers_true
Net::BeingHandler * beingHandler
const BeingId BeingId_zero
Net::CharServerHandler * charServerHandler
#define returnNullptrV(val)
#define reportAlways(...)
#define returnNullptr(ret, val)
std::string findCharById(const int32_t id)
int getPriorityAttackMobIndex(const std::string &name) const
void updatePlayerColors() const
void setPlayer(LocalPlayer *const player)
ActorSprites mDeleteActors
bool pickUpAll(const int x1, const int y1, const int x2, const int y2, const bool serverBuggy) const
Being * findPortalByTile(const int x, const int y) const
Being * findNearestLivingBeing(const int x, const int y, int maxTileDist, const ActorTypeT type, const Being *const excluded) const
std::set< std::string > mIgnoreAttackMobsSet
void findBeingsByPixel(std::vector< ActorSprite * > &beings, const int x, const int y, const AllPlayers allPlayers) const
bool hasActorSprite(const ActorSprite *const actor) const
Being * findMostDamagedPlayer(const int maxTileDist) const
Being * findBeing(const BeingId id) const
void updateRoom(const ChatObject *const newChat)
std::list< std::string > mIgnorePickupItems
void parseLevels(std::string levels) const
void updateBadges() const
Being * findNearestPvpPlayer() const
void heal(const Being *const target) const
static Being * cloneBeing(const Being *const srcBeing, const int dx, const int dy, const int id)
bool mTargetOnlyReachable
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
bool checkDefaultPickup() const
void addAttackMob(const std::string &name)
void destroy(ActorSprite *const actor)
void addIgnorePickupItem(const std::string &name)
void getMobNames(StringVect &names) const
void rebuildPickupItems()
void addChar(const int32_t id, const std::string &name)
void undelete(const ActorSprite *const actor)
std::list< std::string > mPickupItems
void addIgnoreAttackMob(const std::string &name)
void addBlock(const BeingId id)
void setMap(Map *const map)
std::string getSeenPlayerById(const BeingId id) const
void updateNameId(const std::string &name, const BeingId beingId)
std::set< std::string > mIgnorePickupItemsSet
void removeAttackMob(const std::string &name)
std::list< std::string > mAttackMobs
void optionChanged(const std::string &name)
std::string mSpellItenplz
void updateEffects(const std::map< BeingTypeId, int > &addEffects, const std::set< BeingTypeId > &removeEffects) const
void removeRoom(const int chatId)
ActorSprite * findActor(const BeingId id) const
std::list< std::string > mIgnoreAttackMobs
std::set< std::string > mPriorityAttackMobsSet
void updatePlayerNames() const
void rebuildPriorityAttackMobs()
StringIntMap mAttackMobsMap
void addPickupItem(const std::string &name)
void storeAttackList() const
int getPickupItemIndex(const std::string &name) const
std::set< std::string > mPickupItemsSet
void updatePlayerGuild() const
FloorItem * findItem(const BeingId id) const
Being * findNearestByName(const std::string &name, const ActorTypeT &type) const
std::set< BeingId > mBlockedBeings
bool validateBeing(const Being *const aroundBeing, Being *const being, const ActorTypeT &type, const Being *const excluded, const int maxCost) const
std::list< std::string > mPriorityAttackMobs
void deleteBlock(const BeingId id)
bool isBlocked(const BeingId id) const
Being * createBeing(const BeingId id, const ActorTypeT type, const BeingTypeId subtype)
void removePickupItem(const std::string &name)
bool checkForPickup(const FloorItem *const item) const
std::set< std::string > mAttackMobsSet
void addPriorityAttackMob(const std::string &name)
Being * findBeingByPixel(const int x, const int y, const AllPlayers allPlayers) const
const ActorSprites & getAll() const A_CONST
FloorItem * createItem(const BeingId id, const int itemId, const int x, const int y, const ItemTypeT itemType, const int amount, const int refine, const ItemColor color, const Identified identified, const Damaged damaged, const int subX, const int subY, const int *const cards)
StringIntMap mPriorityAttackMobsMap
void printBeingsToChat(const std::string &header) const
ActorSpritesMap mActorsIdMap
int getAttackMobIndex(const std::string &name) const
StringIntMap mPickupItemsMap
void erase(ActorSprite *const actor)
bool pickUpNearest(const int x, const int y, int maxdist) const
void getPlayerNames(StringVect &names, const NpcNames npcNames) const
void updateSeenPlayers(const std::set< std::string > &onlinePlayers)
std::map< int32_t, std::string > mChars
static int getIndexByName(const std::string &name, const StringIntMap &map)
virtual ActorTypeT getType() const
virtual int getPixelY() const
const Vector & getPixelPositionF() const
void setName(const std::string &name)
bool isTargetSelection() const
virtual void setDirection(const uint8_t direction)
virtual void setAction(const BeingActionT &action, const int attackId)
const Guild * getGuild(const std::string &guildName) const
virtual void setTileCoords(const int x, const int y)
void showBadges(const bool show)
uint16_t getTeamId() const
uint8_t getDirection() const
static BadgeDrawType::Type mShowBadges
BeingTypeId getSubType() const
void setLevel(const int n)
void setChat(ChatObject *const obj)
int getSpriteID(const int slot) const
static VisibleNamePos::Type mVisibleNamePos
ItemColor getHairColor() const
ChatObject * getChat() const
void setName(const std::string &name)
void removeSpecialEffect()
void setHairColor(const unsigned int slot, const ItemColor color)
const std::string & getName() const
virtual void setGender(const GenderT gender)
void setGoodStatus(const int n)
void unSetSprite(const unsigned int slot)
BeingActionT getCurrentAction() const
GenderT getGender() const
ActorTypeT getType() const
ItemColor getSpriteColor(const int slot) const
const BeingInfo * getInfo() const
void addSpecialEffect(const int effect)
static Being * createBeing(const BeingId id, const ActorTypeT type, const BeingTypeId subtype, Map *const map)
void setSpriteColor(const unsigned int slot, const int id, const std::string &color)
void setSpriteColorId(const unsigned int slot, const int id, ItemColor colorId)
int getDamageTaken() const
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
void localChatInput(const std::string &msg) const
std::vector< Sprite * > mSprites
bool getBoolValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
void setValue(const std::string &key, const std::string &value)
void removeListeners(ConfigListener *const listener)
int getIntValue(const std::string &key) const
void setBeing(Being *const being)
void resetBeing(const Being *const being)
unsigned getPickupCount() const
std::string getName() const
void postInit(Map *const map, int subX, int subY)
Map * getCurrentMap() const
static bool checAttackPermissions(const Being *const target)
void setMap(Map *const map)
void setTarget(Being *const target)
Being * getTarget() const
int getAttackRange() const
void checkNewName(Being *const being)
bool isReachable(Being *const being, const int maxCost)
bool pickUp(FloorItem *const item)
const FloorItem * getPickUpTarget() const
virtual void requestNameById(const BeingId id) const =0
virtual unsigned int hairSprite() const =0
virtual bool canUseMagic() const =0
virtual bool haveServerWarpNames() const =0
RelationT getRelation(const std::string &name) const
void addEffect(Being *const being)
unsigned int pvpAttackType
unsigned int moveToTargetType
void updatePickupFilter()
void updateAttackFilter()
StringIntMap * priorityBeings
StringIntMap * attackBeings
void clearHover(const ActorSprite *const actor)
Clears any matching hovers.
Configuration serverConfig
static const int mapTileSize
EquipmentWindow * beingEquipmentWindow
#define FOR_EACH(type, iter, array)
const bool IgnoreRecord_false
#define fromInt(val, name)
#define A_DEFAULT_COPY(func)
LocalPlayer * localPlayer
int fastSqrtInt(const unsigned int n)
std::string toString(T const &value)
converts any type to a string
void saveTextFile(const std::string &path, const std::string &name, const std::string &text)
const ItemInfo & get(const int id)
ServerTypeT getNetworkType()
bool checkPackets(const PacketTypeT type)
bool limitPackets(const PacketTypeT type)
int32_t getAttribute(const AttributesT id)
int getSkillLevel(const int id)
Net::ServerFeatures * serverFeatures
Net::PlayerHandler * playerHandler
#define BLOCK_START(name)
PlayerRelationsManager playerRelations
QuestsWindow * questsWindow
SocialWindow * socialWindow
std::map< std::string, int > StringIntMap
StringIntMap::const_iterator StringIntMapCIter
std::string packList(const std::list< std::string > &list)
std::string stringToHexPath(const std::string &str)
std::string strprintf(const char *const format,...)
std::string getDateTimeString()
std::string pathJoin(std::string str1, const std::string &str2)
std::vector< std::string > StringVect
const bool TryRemoveColors_true