kubernik
Active Member
- Joined
- Jul 4, 2014
- Messages
- 99
- Solutions
- 7
- Reaction score
- 38
Hello i trying to add this monster level system to tfs 0.3.6, but my compilator spits with error:
Code in spoiler
C++:
map.cpp
monster->name = monster->getName() + " [" + itoa(level, buffer, 10) + "]";
‘itoa’ was not declared in this scope
Code in spoiler
monsters.h
Replace with:
Search for:
Replace with:
monsters.cpp
monster.h
monster.cpp
map.cpp
configmanager.h
configmanager.cpp
C++:
bool isSummonable, isIllusionable, isConvinceable, isAttackable, isHostile, isLureable,
isWalkable, canPushItems, canPushCreatures, pushable, hideName, hideHealth;
Replace with:
C++:
bool isSummonable, isIllusionable, isConvinceable, isAttackable, isHostile, isLureable,
isWalkable, canPushItems, canPushCreatures, pushable, hideName, hideHealth, hideLevel;
Search for:
C++:
int32_t defense, armor, health, healthMax, baseSpeed, lookCorpse, corpseUnique, corpseAction,
maxSummons, targetDistance, runAwayHealth, conditionImmunities, damageImmunities,
lightLevel, lightColor, changeTargetSpeed, changeTargetChance;
Replace with:
C++:
int32_t defense, armor, health, healthMax, baseSpeed, lookCorpse, corpseUnique, corpseAction,
maxSummons, targetDistance, runAwayHealth, conditionImmunities, damageImmunities,
lightLevel, lightColor, changeTargetSpeed, changeTargetChance, levelMin, levelMax;
monsters.cpp
Search for:
Replace with:
Search for:
Below, add:
Find it:
Inside the function, look for:
Below, add:
Search for:
Below, add:
C++:
canPushItems = canPushCreatures = isSummonable = isIllusionable = isConvinceable = isLureable = isWalkable = hideName = hideHealth = false;
Replace with:
C++:
canPushItems = canPushCreatures = isSummonable = isIllusionable = isConvinceable = isLureable = isWalkable = hideName = hideHealth = hideLevel = false;
Search for:
C++:
baseSpeed = 200;
Below, add:
C++:
levelMin = levelMax = 1;
Find it:
C++:
bool Monsters :: loadMonster
Inside the function, look for:
C++:
for(xmlNodePtr p = root->children; p; p = p->next)
{
if(p->type != XML_ELEMENT_NODE)
continue;
if(!xmlStrcmp(p->name, (const xmlChar*)"health"))
{
if(!readXMLInteger(p, "max", intValue))
{
SHOW_XML_ERROR("Missing health.max");
monsterLoad = false;
break;
}
mType->healthMax = intValue;
if(!readXMLInteger(p, "now", intValue))
mType->health = mType->healthMax;
else
mType->health = intValue;
}
Below, add:
C++:
else if(!xmlStrcmp(p->name, (const xmlChar*)"level"))
{
if(!readXMLInteger(p, "max", intValue))
mType->levelMax = 1;
else
mType->levelMax = intValue;
if(!readXMLInteger(p, "min", intValue))
mType->levelMin = mType->levelMax;
else
mType->levelMin = intValue;
}
C++:
if(readXMLString(tmpNode, "emblem", strValue))
mType->guildEmblem = getEmblems(strValue);
Below, add:
C++:
if(readXMLString(tmpNode, "hidelevel", strValue))
mType->hideLevel = booleanString(strValue);
monster.h
Find it:
Just below:
Add:
Replace:
Per:
C++:
class Monster : public Creature
{
Just below:
C++:
public:
#ifdef __ENABLE_SERVER_DIAGNOSTIC__
static uint32_t monsterCount;
#endif
virtual ~Monster();
Add:
C++:
std::string name, nameDescription;
int32_t level;
double bonusAttack, bonusDefense;
Replace:
C++:
virtual const std::string& getName() const {return mType->name;}
virtual const std::string& getNameDescription() const {return mType->nameDescription;}
virtual std::string getDescription(int32_t) const {return mType->nameDescription + ".";}
Per:
C++:
virtual const std::string& getName() const {return name;}
virtual const std::string& getNameDescription() const {return nameDescription;}
virtual std::string getDescription(int32_t) const {return nameDescription + ".";}
monster.cpp
Search for:
Just below:
Add:
Search for:
Replace the entire function with:
Replace all:
Per:
Replace all:
Per:
Code:
Monster::Monster(MonsterType* _mType):
Just below:
C++:
isIdle = true;
Add:
C++:
name = _mType->name;
nameDescription = _mType->nameDescription;
level = (int32_t)random_range(_mType->levelMin, _mType->levelMax, DISTRO_NORMAL);
bonusAttack = 1.0;
bonusDefense = 1.0;
Search for:
C++:
Monster :: onCreatureAppear
Replace the entire function with:
C++:
void Monster::onCreatureAppear(const Creature* creature)
{
Creature::onCreatureAppear(creature);
if(creature == this)
{
//We just spawned lets look around to see who is there.
if(isSummon())
{
std::string value;
this->master->getStorage((std::string)"monster_level", value);
uint8_t intValue = atoi(value.c_str());
if(intValue || value == "0")
level = intValue;
else
level = 1;
isMasterInRange = canSee(master->getPosition());
}
if(g_config.getBool(ConfigManager::MONSTER_HAS_LEVEL))
{
this->healthMax = std::floor(this->getMaxHealth() * (1. + (0.1 * (level - 1))));
this->health = this->healthMax;
this->bonusAttack += (0.01 * (level - 1));
this->bonusDefense += (0.005 * (level - 1));
}
updateTargetList();
updateIdleStatus();
}
else
onCreatureEnter(const_cast<Creature*>(creature));
}
Replace all:
C++:
g_config.getDouble(ConfigManager::RATE_MONSTER_DEFENSE)
Per:
C++:
g_config.getDouble(ConfigManager::RATE_MONSTER_DEFENSE) * bonusDefense
Replace all:
C++:
g_config.getDouble(ConfigManager::RATE_MONSTER_ATTACK)
Per:
C++:
g_config.getDouble(ConfigManager::RATE_MONSTER_ATTACK) * bonusAttack
map.cpp
Search for:
Add:
Search for:
Add below:
Look for the function:
Add shortly after:
C++:
#include "game.h"
Add:
C++:
#include "configmanager.h"
Search for:
C++:
extern Game g_game;
Add below:
C++:
extern ConfigManager g_config;
Look for the function:
C++:
bool Map::placeCreature
{
Add shortly after:
C++:
Monster* monster = creature->getMonster();
if(monster && g_config.getBool(ConfigManager::MONSTER_HAS_LEVEL))
{
uint8_t level;
if(!monster->getMonsterType()->hideLevel)
{
if(monster->isSummon())
{
std::string value;
monster->getMaster()->getStorage((std::string)"monster_level", value);
uint8_t intValue = atoi(value.c_str());
if(intValue || value == "0")
level = intValue;
else
level = 1;
}
else
level = monster->level;
char buffer [10];
monster->name = monster->getName() + " [" + itoa(level, buffer, 10) + "]";
}
}
configmanager.h
Search for:
And add below:
C++:
MONSTER_SPAWN_WALKBACK,
And add below:
C++:
MONSTER_HAS_LEVEL,
configmanager.cpp
Search for:
Add a little earlier:
C++:
m_loaded = true;
Add a little earlier:
C++:
m_confBool[MONSTER_HAS_LEVEL] = getGlobalBool("monsterHasLevel", true);