• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ I need to adapt system

kikinsio

New Member
Joined
Mar 16, 2013
Messages
5
Reaction score
0
Can anyone help me adapt this to TFS 1.3?

monsters.h
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:
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;
        }
Search for:
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:
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:
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:
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:
C++:
MONSTER_SPAWN_WALKBACK,

And add below:
C++:
MONSTER_HAS_LEVEL,

configmanager.cpp
Search for:
C++:
m_loaded = true;

Add a little earlier:
C++:
m_confBool[MONSTER_HAS_LEVEL] = getGlobalBool("monsterHasLevel", true);
 
Back
Top