void Character::respawn() { if (mAction != DEAD) { LOG_WARN("Character \"" << getName() << "\" tried to respawn without being dead"); return; } // Make it alive again setAction(STAND); // Reset target mTarget = NULL; // Execute respawn callback when set if (executeCallback(mDeathAcceptedCallback, this)) return; // No script respawn callback set - fall back to hardcoded logic mAttributes[ATTR_HP].setBase(mAttributes[ATTR_MAX_HP].getModifiedAttribute()); updateDerivedAttributes(ATTR_HP); // Warp back to spawn point. int spawnMap = Configuration::getValue("char_respawnMap", 1); int spawnX = Configuration::getValue("char_respawnX", 1024); int spawnY = Configuration::getValue("char_respawnY", 1024); GameState::enqueueWarp(this, MapManager::getMap(spawnMap), spawnX, spawnY); }
void Character::updateDerivedAttributes(unsigned int attr) { /* * `attr' has changed, perform updates accordingly. */ flagAttribute(attr); switch(attr) { case ATTR_STR: updateDerivedAttributes(ATTR_INV_CAPACITY); break; case ATTR_AGI: updateDerivedAttributes(ATTR_DODGE); updateDerivedAttributes(ATTR_MOVE_SPEED_TPS); break; case ATTR_VIT: updateDerivedAttributes(ATTR_MAX_HP); updateDerivedAttributes(ATTR_HP_REGEN); updateDerivedAttributes(ATTR_DEFENSE); break; case ATTR_INT: // TODO break; case ATTR_DEX: updateDerivedAttributes(ATTR_ACCURACY); break; case ATTR_WIL: // TODO break; default: Being::updateDerivedAttributes(attr); } }
void Character::modifiedAllAttribute() { LOG_DEBUG("Marking all attributes as changed, requiring recalculation."); for (AttributeMap::iterator it = mAttributes.begin(), it_end = mAttributes.end(); it != it_end; ++it) { recalculateBaseAttribute(it->first); updateDerivedAttributes(it->first); } }
AttribmodResponseCode Character::useCharacterPoint(size_t attribute) { if (!attributeManager->isAttributeDirectlyModifiable(attribute)) return ATTRIBMOD_INVALID_ATTRIBUTE; if (!mCharacterPoints) return ATTRIBMOD_NO_POINTS_LEFT; --mCharacterPoints; setAttribute(attribute, getAttribute(attribute) + 1); updateDerivedAttributes(attribute); return ATTRIBMOD_OK; }
bool Character::recalculateBaseAttribute(unsigned int attr) { /* * `attr' may or may not have changed. Recalculate the base value. */ LOG_DEBUG("Received update attribute recalculation request at Character " "for " << attr << "."); if (!mAttributes.count(attr)) return false; double newBase = getAttribute(attr); /* * Calculate new base. */ switch (attr) { case ATTR_ACCURACY: newBase = getModifiedAttribute(ATTR_DEX); // Provisional break; case ATTR_DEFENSE: newBase = 0.3 * getModifiedAttribute(ATTR_VIT); break; case ATTR_DODGE: newBase = getModifiedAttribute(ATTR_AGI); // Provisional break; case ATTR_MAGIC_DODGE: newBase = 1.0; // TODO break; case ATTR_MAGIC_DEFENSE: newBase = 0.0; // TODO break; case ATTR_BONUS_ASPD: newBase = 0.0; // TODO break; default: return Being::recalculateBaseAttribute(attr); } if (newBase != getAttribute(attr)) { setAttribute(attr, newBase); updateDerivedAttributes(attr); return true; } LOG_DEBUG("No changes to sync for attribute '" << attr << "'."); return false; }