00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "animatedsprite.h"
00023 #include "game.h"
00024 #ifdef TMWSERV_SUPPORT
00025 #include "guild.h"
00026 #endif
00027 #include "localplayer.h"
00028 #include "particle.h"
00029 #include "player.h"
00030 #include "text.h"
00031
00032 #include "gui/palette.h"
00033
00034 #include "resources/colordb.h"
00035 #include "resources/itemdb.h"
00036 #include "resources/iteminfo.h"
00037
00038 #include "utils/strprintf.h"
00039
00040 Player::Player(int id, int job, Map *map):
00041 Being(id, job, map)
00042 {
00043 mName = NULL;
00044 }
00045
00046 Player::~Player()
00047 {
00048 delete mName;
00049 }
00050
00051 void Player::setName(const std::string &name)
00052 {
00053 if (mName == NULL)
00054 {
00055 if (mIsGM)
00056 {
00057 mNameColor = &guiPalette->getColor(Palette::GM);
00058 mName = new FlashText("(GM) " + name,
00059 getPixelX(),
00060 getPixelY(),
00061 gcn::Graphics::CENTER,
00062 &guiPalette->getColor(Palette::GM_NAME));
00063 }
00064 else
00065 {
00066 mNameColor = &guiPalette->getColor(Palette::PLAYER);
00067 mName = new FlashText(name,
00068 getPixelX(),
00069 getPixelY(),
00070 gcn::Graphics::CENTER,
00071 (this == player_node) ?
00072 &guiPalette->getColor(Palette::SELF) :
00073 &guiPalette->getColor(Palette::PC));
00074 }
00075 Being::setName(name);
00076 }
00077 }
00078
00079 #ifdef EATHENA_SUPPORT
00080 void Player::logic()
00081 {
00082 switch (mAction)
00083 {
00084 case STAND:
00085 case SIT:
00086 case DEAD:
00087 case HURT:
00088 break;
00089
00090 case WALK:
00091 mFrame = (get_elapsed_time(mWalkTime) * 6) / getWalkSpeed();
00092 if (mFrame >= 6)
00093 nextStep();
00094 break;
00095
00096 case ATTACK:
00097 int rotation = 0;
00098 std::string particleEffect = "";
00099 int frames = 4;
00100
00101 if (mEquippedWeapon &&
00102 mEquippedWeapon->getAttackType() == ACTION_ATTACK_BOW)
00103 {
00104 frames = 5;
00105 }
00106
00107 mFrame = (get_elapsed_time(mWalkTime) * frames) / mAttackSpeed;
00108
00109
00110 if (mEquippedWeapon)
00111 particleEffect = mEquippedWeapon->getParticleEffect();
00112
00113 if (!particleEffect.empty() && mParticleEffects && mFrame == 1)
00114 {
00115 switch (mDirection)
00116 {
00117 case DOWN: rotation = 0; break;
00118 case LEFT: rotation = 90; break;
00119 case UP: rotation = 180; break;
00120 case RIGHT: rotation = 270; break;
00121 default: break;
00122 }
00123 Particle *p;
00124 p = particleEngine->addEffect("graphics/particles/" +
00125 particleEffect, 0, 0, rotation);
00126 controlParticle(p);
00127 }
00128
00129 if (mFrame >= frames)
00130 nextStep();
00131
00132 break;
00133 }
00134
00135 Being::logic();
00136 }
00137 #endif
00138
00139 Being::Type Player::getType() const
00140 {
00141 return PLAYER;
00142 }
00143
00144 void Player::flash(int time)
00145 {
00146 if (mName)
00147 mName->flash(time);
00148 }
00149
00150 void Player::setGender(Gender gender)
00151 {
00152 if (gender != mGender)
00153 {
00154 Being::setGender(gender);
00155
00156
00157
00158
00159
00160 setSprite(Being::BASE_SPRITE, -100);
00161
00162
00163 for (int i = 1; i < VECTOREND_SPRITE; i++)
00164 {
00165 if (mSpriteIDs.at(i) != 0)
00166 setSprite(i, mSpriteIDs.at(i), mSpriteColors.at(i));
00167 }
00168 }
00169 }
00170
00171 void Player::setHairStyle(int style, int color)
00172 {
00173 style = style < 0 ? mHairStyle : style % mNumberOfHairstyles;
00174 color = color < 0 ? mHairColor : color % ColorDB::size();
00175 if (style == mHairStyle && color == mHairColor) return;
00176
00177 Being::setHairStyle(style, color);
00178
00179 setSprite(HAIR_SPRITE, style * -1, ColorDB::get(color));
00180
00181 setAction(mAction);
00182 }
00183
00184 void Player::setSprite(int slot, int id, const std::string &color)
00185 {
00186
00187 if (id == 0)
00188 {
00189 delete mSprites[slot];
00190 mSprites[slot] = NULL;
00191
00192 #ifdef EATHENA_SUPPORT
00193 if (slot == WEAPON_SPRITE)
00194 mEquippedWeapon = NULL;
00195 #endif
00196 }
00197 else
00198 {
00199 std::string filename = ItemDB::get(id).getSprite(mGender);
00200 AnimatedSprite *equipmentSprite = NULL;
00201
00202 if (!filename.empty())
00203 {
00204 if (!color.empty())
00205 filename += "|" + color;
00206
00207 equipmentSprite = AnimatedSprite::load("graphics/sprites/" +
00208 filename);
00209 }
00210
00211 if (equipmentSprite)
00212 equipmentSprite->setDirection(getSpriteDirection());
00213
00214 delete mSprites[slot];
00215 mSprites[slot] = equipmentSprite;
00216
00217 if (slot == WEAPON_SPRITE)
00218 mEquippedWeapon = &ItemDB::get(id);
00219
00220 setAction(mAction);
00221 }
00222
00223 Being::setSprite(slot, id, color);
00224 }
00225
00226 void Player::updateCoords()
00227 {
00228 if (mName)
00229 mName->adviseXY(getPixelX(), getPixelY());
00230 }
00231
00232 #ifdef TMWSERV_SUPPORT
00233
00234 Guild* Player::addGuild(short guildId, short rights)
00235 {
00236 Guild *guild = new Guild(guildId, rights);
00237 mGuilds.insert(std::pair<int, Guild*>(guildId, guild));
00238 return guild;
00239 }
00240
00241 void Player::removeGuild(int id)
00242 {
00243 mGuilds.erase(id);
00244 }
00245
00246 Guild* Player::getGuild(const std::string &guildName)
00247 {
00248 std::map<int, Guild*>::iterator itr, itr_end = mGuilds.end();
00249 for (itr = mGuilds.begin(); itr != itr_end; ++itr)
00250 {
00251 Guild *guild = itr->second;
00252 if (guild->getName() == guildName)
00253 {
00254 return guild;
00255 }
00256 }
00257
00258 return NULL;
00259 }
00260
00261 Guild* Player::getGuild(int id)
00262 {
00263 std::map<int, Guild*>::iterator itr;
00264 itr = mGuilds.find(id);
00265 if (itr != mGuilds.end())
00266 {
00267 return itr->second;
00268 }
00269
00270 return NULL;
00271 }
00272
00273 short Player::getNumberOfGuilds()
00274 {
00275 return mGuilds.size();
00276 }
00277
00278 #endif
00279
00280 void Player::setInParty(bool value)
00281 {
00282 mInParty = value;
00283 }