103 spriteState.visibleId = 0;
104 spriteState.particles.clear();
123 int id = -100 - subtype;
204 if (dstX <= 0 || dstY <= 0)
210 if (!
mMap->
getWalk(dstX / tileWidth, dstY / tileHeight))
226 dest.
x = (dstX / tileWidth) * tileWidth + tileWidth / 2;
227 dest.
y = (dstY / tileHeight) * tileHeight + tileHeight / 2;
233 if (thisPath.empty())
237 if ((
int)
mPos.
x / tileWidth == dest.
x / tileWidth
238 && (int)
mPos.
y / tileHeight == dest.
y / tileHeight)
271 std::string::size_type start =
mSpeech.find(
'[');
272 std::string::size_type end =
mSpeech.find(
']', start);
274 while (start != std::string::npos && end != std::string::npos)
277 while ((
mSpeech.find(
'[', start + 1) != std::string::npos) &&
278 (
mSpeech.find(
'[', start + 1) < end))
280 start =
mSpeech.find(
'[', start + 1);
283 std::string::size_type position =
mSpeech.find(
'|');
287 mSpeech.erase(start, (position - start) + 1);
291 while (position != std::string::npos)
297 start =
mSpeech.find(
'[', start + 1);
298 end =
mSpeech.find(
']', start);
310 gcn::Graphics::CENTER,
320 std::string damage = amount ?
toString(amount)
321 : (type ==
FLEE ?
"dodge" :
"miss");
322 const gcn::Color *color;
391 const ItemInfo *attackerWeapon = attacker ?
466 mName = name.substr(0, name.find(
'#', 0));
484 Log::info(
"Got guild name \"%s\" for being %s(%i)", name.c_str(),
491 Log::info(
"Got guild position \"%s\" for being %s(%i)", pos.c_str(),
506 const auto it =
mGuilds.find(
id);
509 auto [
_, guild] = *it;
514 guild->removeMember(
mId);
521 if (guild->getName() == guildName)
543 guild->removeMember(
mId);
576 if (!victim || particle.empty())
601 if (active != wasActive)
618 if (
Particle *particle = effect->getParticle(newStatus))
626 std::string currentAction = SpriteAction::INVALID;
631 currentAction = SpriteAction::MOVE;
637 currentAction = SpriteAction::SIT;
675 currentAction = SpriteAction::DEAD;
680 currentAction = SpriteAction::STAND;
684 if (currentAction != SpriteAction::INVALID)
690 if (currentAction != SpriteAction::MOVE)
842 for (
auto &particle : spriteState.particles)
843 particle->moveTo(
mPos.
x, py);
846 p->moveTo(
mPos.
x, py);
870 if (dest.
x <= 0 || dest.
y <= 0)
884 const float distanceToDest = dir.
length();
893 const float distanceToMove = diff.
length();
896 if (distanceToMove > distanceToDest)
911 dt -= dt * (distanceToDest / distanceToMove);
934 const float dx = std::abs(dir.
x);
935 const float dy = std::abs(dir.
y);
940 direction |= (dir.
y > 0) ?
DOWN :
UP;
945 else if (!
mPath.empty())
997 gcn::Graphics::CENTER,
1037 std::string mDisplayName(
mName);
1044 mDisplayName +=
" \u2640";
1046 mDisplayName +=
" \u2642";
1065 gcn::Font *font =
nullptr;
1085 for (
const auto &particle : display.
particles)
1101 auto &itemInfo =
itemDb->
get(spriteState.id);
1165 if (!spriteState.id)
1168 auto &itemInfo =
itemDb->
get(spriteState.id);
1169 for (
const auto &replacement : itemInfo.replacements)
1171 if (replacement.direction !=
DIRECTION_ALL && replacement.direction != direction)
1176 if (replacement.items.empty())
1178 itemIDs.assign(itemIDs.size(), 0);
1182 for (
int &
id : itemIDs)
1184 for (
auto &item : replacement.items)
1185 if (!item.from ||
id == item.from)
1190 else if (replacement.sprite < itemIDs.size())
1192 int &
id = itemIDs[replacement.sprite];
1194 if (replacement.items.empty())
1200 for (
auto &item : replacement.items)
1201 if (!item.from ||
id == item.from)
1209 bool newSpriteSet =
false;
1216 if (spriteState.visibleId == itemIDs[i])
1219 spriteState.visibleId = itemIDs[i];
1221 if (spriteState.visibleId == 0)
1227 newSpriteSet =
true;
1229 auto &itemInfo =
itemDb->
get(spriteState.visibleId);
1231 Sprite *equipmentSprite =
nullptr;
1233 if (!filename.empty())
1235 if (!spriteState.color.empty())
1236 filename +=
"|" + spriteState.color;
1241 if (equipmentSprite)
1263 if (spriteState.id !=
id)
1264 spriteState.particles.clear();
1267 if (spriteState.color != color && spriteState.visibleId)
1269 spriteState.visibleId = 0;
1273 spriteState.id = id;
1274 spriteState.color = color;
1323 if (spriteState.visibleId)
1326 spriteState.visibleId = 0;
1374 if (
mId ==
event.getInt(
"beingId"))
1401 spriteState.particles.clear();
ActorSpriteManager * actorSpriteManager
An action consists of several animations, one for each direction.
void scheduleDelete(ActorSprite *actor)
Destroys the given ActorSprite at the end of ActorSpriteManager::logic.
void controlParticle(Particle *particle)
Take control of a particle.
void setMap(Map *map) override
void setupSpriteDisplay(const SpriteDisplay &display, bool forceDisplay=true)
std::vector< ParticleHandle > mChildParticleEffects
int getPixelX() const
Returns the pixels X coordinate of the actor.
int getPixelY() const
Returns the pixel Y coordinate of the actor.
virtual void setPosition(const Vector &pos)
Sets the pixel position of this actor.
Vector mPos
Position in pixels relative to map.
const Vector & getPosition() const
Returns the pixel position of this actor.
Holds information about a certain type of monster.
const Attack & getAttack(int id) const
ActorSprite::TargetCursorSize targetCursorSize
const std::string & getSound(SoundEvent event) const
void setPosition(const Vector &pos) final
Sets the pixel position of this actor.
void setStatusEffect(int id, bool active)
void event(Event::Channel channel, const Event &event) override
int mSubType
Subtype (graphical view, basically)
const ItemInfo * getEquippedWeapon() const
void setSprite(unsigned slot, int id, const std::string &color=std::string(), bool isWeapon=false)
Sets visible equipments for this being.
void setDestination(int ex, int ey)
Creates a path for the being from current position to ex and ey.
bool mRestoreParticlesOnLogic
void setGuildName(const std::string &name)
Sets the name of the primary guild the being is in.
TargetCursorSize getTargetCursorSize() const override
Returns the required size of a target cursor for this being.
void setShowName(bool doShowName)
void setMoveSpeed(const Vector &speed)
Sets the move speed.
void setDirection(uint8_t direction)
Sets the current direction.
void fireMissile(Being *target, const std::string &particle)
Shoots a missile particle from this being, to target being.
const BeingInfo & getInfo() const
void setMap(Map *map) final
Action mAction
Action the being is performing.
unsigned char getWalkMask() const
Gets the way the object is blocked by other objects.
int getIp() const
Returns the player's IP or an IP hash.
Type getType() const final
Returns the type of the ActorSprite.
uint8_t mSpriteDirection
Facing direction.
virtual void updateStatusEffect(int index, bool newStatus)
Notify self that a status effect has flipped.
std::vector< SpriteState > mSpriteStates
std::map< int, Guild * > mGuilds
std::string mName
Name of character.
SpriteDirection getSpriteDirection() const
Returns the direction the being is facing.
SpeechBubble * mSpeechBubble
Speech Bubble components.
bool drawnWhenBehind() const override
Determines wether the actor should be drawn translucent when behind another object.
void setPath(const Path &path)
Sets the new path for this being.
void setSpriteColor(unsigned slot, const std::string &color=std::string())
void lookAt(const Vector &destVec)
Make the being look at a given pixel position.
int getCollisionRadius() const
Returns the being's pixel radius used to detect collisions.
void drawSpeech(int offsetX, int offsetY)
Draws the speech text above the being.
void updateNamePosition()
Updates name's location.
const ItemInfo * mEquippedWeapon
Engine-related infos about weapon.
void setName(const std::string &name)
Sets the name for the being.
void setIp(int ip)
Sets the IP or an IP hash.
virtual void pathFinished()
Called when the being has reached the end of its path.
int getSpeechTextYPosition() const
Gets the advised Y chat text position.
Vector mDest
destination coordinates.
bool isAlive() const
Returns whether this being is still alive.
void setGM(bool gm)
Triggers whether or not to show the name as a GM name.
void setGuildPos(const std::string &pos)
virtual void setAction(Action action, int attackId=1)
Sets the current action.
Cursor getHoverCursor() const
void setType(Type type, int subtype)
Can be used to change the type of the being.
const gcn::Color * mNameColor
void setParty(Party *party)
Timer mSpeechTimer
Time until the last speech sentence disappears.
void logic() override
Performs being logic.
FlashText * mDispName
Holds a text object when the being displays its name, 0 otherwise.
void handleAttack(Being *victim, int damage, int attackId=1)
Handles an attack of another being by this being.
void setGender(Gender gender)
Sets the gender of this being.
Map::BlockType getBlockType() const override
Gets the way the monster blocks pathfinding for other objects.
Timer mActionTimer
Time spent in current action.
void addGuild(Guild *guild)
Adds a guild to the being.
void updatePlayerSprites()
Updates the visible sprite IDs of the player, taking into account the item replacements.
void removeGuild(int id)
Removers a guild from the being.
Vector mMoveSpeed
Walk speed for x and y movement values.
bool isTargetSelection() const
std::map< int, ParticleHandle > mStatusParticleEffects
Guild * getGuild(const std::string &guildName) const
Returns a pointer to the specified guild that the being is in.
uint8_t mDirection
Facing direction.
void death(const gcn::Event &event) override
void takeDamage(Being *attacker, int damage, AttackType type, int attackId=1)
Puts a damage bubble above this being.
Vector mSpeedPixelsPerSecond
Being speed in pixel per second.
void clearPath()
Removes all path nodes from this being.
void setSpriteID(unsigned slot, int id)
void setSpeech(const std::string &text, int time=5000)
Puts a "speech balloon" above this being for the specified amount of time.
Being(int id, Type type, int subtype, Map *map)
Constructor.
void addSpriteParticles(SpriteState &spriteState, const SpriteDisplay &display)
void restoreAllSpriteParticles()
std::set< int > mStatusEffects
set of active status effects
void clearGuilds()
Removes all guilds the being is in.
int getDamageTaken() const
int getNumberOfLayers() const
bool play(const std::string &action)
void ensureSize(size_t layerCount)
void set(int layer, Sprite *sprite)
bool setDirection(SpriteDirection direction)
int getMaxDuration() const
std::string getStringValue(const std::string &key) const
int getIntValue(const std::string &key) const
returns a value corresponding to the given key.
bool trigger(int id, Being *being, int rotation=0)
Triggers a effect with the id, at the specified being, and with the given rotation in degree: 0° = Do...
void listen(Event::Channel channel)
void flash(int time)
Flash the text for so many milliseconds.
static Game * instance()
Provides access to the game instance.
gcn::Font * getInfoParticleFont() const
Return the Font used for "Info Particles", i.e.
GuildMember * addMember(int id, const std::string &name)
Adds member to the list.
short getId() const
Get the id of the guild.
bool exists(int id) const
const ItemInfo & get(int id) const
Defines a class for storing generic item infos.
const std::string & getSprite(Gender gender, int race) const
std::string attackAction
Attack type, in case of weapon.
std::string missileParticleFile
Effects to be shown when weapon attacks - see also effects.xml.
const std::string & getSound(EquipmentSoundEvent event) const
Being * getTarget() const
Returns the current target of the player.
bool isPathSetByMouse() const
Tells if the path has been set by mouse.
Path findPixelPath(int startPixelX, int startPixelY, int destPixelX, int destPixelY, int radius, unsigned char walkmask, int maxCost=20)
Find a pixel path from one location to the next using free offsets.
int getTileHeight() const
Returns the tile height used by this map.
int getTileWidth() const
Returns the tile width of this map.
Position checkNodeOffsets(int radius, unsigned char walkMask, const Position &position) const
Check the current position against surrounding blocking tiles, and correct the position offset within...
bool getWalk(int x, int y, unsigned char walkmask=BLOCKMASK_WALL) const
Gets walkability for a tile with a blocking bitmask.
Path findTilePath(int startPixelX, int startPixelY, int endPixelX, int endPixelY, unsigned char walkMask, int maxCost=20)
Find a tile-centered path in pixel coordinates from one location to the next.
virtual void talk(int npcId)=0
virtual Vector getPixelsPerSecondMoveSpeed(const Vector &speed, Map *map=nullptr)=0
Convert the original server-dependant speed for internal use.
virtual Vector getDefaultMoveSpeed() const =0
Get the original default movement speed.
const gcn::Color & getColor(int type) const
Gets the color associated with the type.
A particle spawned by a ParticleEmitter.
void moveBy(const Vector &change)
Changes the particle position relative.
Particle * createChild()
Creates a blank particle as a child of the current particle Useful for creating target particles.
void setDieDistance(float dist)
Sets the distance in pixel the particle can come near the target particle before it is destroyed.
void setLifetime(int lifetime)
Sets the time in game ticks until the particle is destroyed.
void setDestination(Particle *target, float accel, float moment)
Makes the particle move toward another particle with a given acceleration and momentum.
Particle * addTextSplashEffect(const std::string &text, int x, int y, const gcn::Color *color, gcn::Font *font, bool outline=false)
Creates a standalone text particle.
Particle * addEffect(const std::string &particleEffectFile, int pixelX, int pixelY, int rotation=0)
Creates a child particle that hosts some emitters described in the particleEffectFile.
static bool enabled
true when non-crucial particle effects are disabled
void removeMember(PartyMember *member)
Removes a member from the party.
bool removeTab(Guild *guild)
bool addTab(Guild *guild)
void playSfx(const std::string &path, int x=0, int y=0)
Plays a sound at the specified location.
void setCaption(const std::string &name, const gcn::Color *color=&Theme::getThemeColor(Theme::TEXT))
Sets the name displayed for the speech bubble, and in what color.
void setText(const std::string &text, bool showName=true)
Sets the text to be displayed.
Animates a sprite by adding playback state.
static Sprite * load(const std::string &filename, int variant=0)
An helper function, which will request the sprite to animate from the resource manager.
bool setDirection(SpriteDirection direction)
Sets the direction.
static const StatusEffect * getStatusEffect(int id)
Retrieves a status effect.
bool persistentParticleEffect
Determines whether the particle effect should be restarted when the being changes maps.
void setColor(const gcn::Color *color)
void adviseXY(int x, int y)
Allows the originator of the text to specify the ideal coordinates.
static const gcn::Color & getThemeColor(int type)
Gets the color associated with the type in the default palette (0).
bool passed() const
Returns whether the timer has passed.
int32_t elapsed() const
Returns the number of milliseconds elapsed since the set time, or a negative value if the timer hasn'...
void set(uint32_t ms=0)
Sets the timer with an optional duration in milliseconds.
@ HIT_LOCAL_PLAYER_MONSTER
@ HIT_LOCAL_PLAYER_CRITICAL
float length() const
Returns the length of this vector.
Vector normalized() const
Returns a normalized version of this vector.
bool isNull() const
Returns true if all coordinates are set to 0, otherwise returns false.
Config config
Global settings (config.xml)
Configuration paths
XML default paths information reader.
UserPalette * userPalette
ItemDB * itemDb
Items info database.
EffectManager * effectManager
Particle * particleEngine
SocialWindow * socialWindow
gcn::Font * boldFont
Bolded text font.
Cursor
Cursors are in graphic order from left to right.
LocalPlayer * local_player
void info(const char *log_text,...) LOG_PRINTF_ATTR
ServerType getNetworkType()
GameHandler * getGameHandler()
CharHandler * getCharHandler()
PlayerHandler * getPlayerHandler()
NpcHandler * getNpcHandler()
float deltaTime()
The time in seconds since the last frame, but never more than 1.
std::list< Position > Path
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.
std::string & trim(std::string &str)
Trims spaces off the end and the beginning of the given string.
const char * ipToString(int address)
Converts the given IP address to a string.
std::string & removeColors(std::string &msg)
Removes colors from a string.
std::string toString(const T &arg)
Converts the given value to a string using std::stringstream.
std::string missileParticleFilename
std::vector< ParticleHandle > particles
bool showMonstersTakedDamage
A position along a being's path.
std::vector< std::string > particles