• 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!

Feature TFS 0.3.6 Load Vocations from lua

Union_

Banned User
Joined
Jan 4, 2017
Messages
21
Reaction score
6
Code:
bool Vocations::reload()
{
    clear();
    return loadFromXml();
}

static struct v {
    const char* name;
    int type;
}
vocation[] = {
    {"id", LUA_TNUMBER},
    {"name", LUA_TSTRING },
    {"description", LUA_TSTRING },
    {"needpremium", LUA_TNUMBER},
    {"gaincap", LUA_TNUMBER},
    {"gainhp", LUA_TNUMBER},
    {"gainmana", LUA_TNUMBER},
    {"gainhpticks", LUA_TNUMBER},
    {"gainhpamount", LUA_TNUMBER},
    {"gainmanaticks", LUA_TNUMBER},
    {"gainmanaamount", LUA_TNUMBER},
    {"manamultiplier", LUA_TNUMBER},
    {"attackspeed", LUA_TNUMBER},
    {"soulmax", LUA_TNUMBER},
    {"gainsoulamount", LUA_TNUMBER},
    {"gainsoulticks", LUA_TNUMBER},
    {"fromvoc", LUA_TNUMBER},
    {"attackable", LUA_TNUMBER},
    {"formula", LUA_TTABLE},
    {"skill", LUA_TTABLE},
    {"absorb", LUA_TTABLE},
    {"reflect", LUA_TTABLE},
    { NULL, 0 }
},
formula[] = {
    {"melee", LUA_TNUMBER},
    {"distance", LUA_TNUMBER},
    {"wand", LUA_TNUMBER},
    {"magic", LUA_TNUMBER},
    {"healing", LUA_TNUMBER},
    {"defense", LUA_TNUMBER},
    {"magicDefense", LUA_TNUMBER},
    {"armor", LUA_TNUMBER},
    { NULL, 0 }
},
skill[] = {
    {"fist", LUA_TNUMBER},
    {"fistBase", LUA_TNUMBER},
    {"club", LUA_TNUMBER},
    {"clubBase", LUA_TNUMBER},
    {"sword", LUA_TNUMBER},
    {"swordBase", LUA_TNUMBER},
    {"axe", LUA_TNUMBER},
    {"axeBase", LUA_TNUMBER},
    {"dist", LUA_TNUMBER},
    {"distBase", LUA_TNUMBER},
    {"shield", LUA_TNUMBER},
    {"shieldBase", LUA_TNUMBER},
    {"fish", LUA_TNUMBER},
    {"fishBase", LUA_TNUMBER},
    {"experience", LUA_TNUMBER},
    { NULL, 0 }
},
absorb[] = {
    {"percentAll", LUA_TNUMBER},
    {"percentElements", LUA_TNUMBER},
    {"percentMagic", LUA_TNUMBER},
    {"percentEnergy", LUA_TNUMBER},
    {"percentFire", LUA_TNUMBER},
    {"percentPoison", LUA_TNUMBER},
    {"percentIce", LUA_TNUMBER},
    {"percentHoly", LUA_TNUMBER},
    {"percentDeath", LUA_TNUMBER},
    {"percentLifeDrain", LUA_TNUMBER},
    {"percentManaDrain", LUA_TNUMBER},
    {"percentDrown", LUA_TNUMBER},
    {"percentPhysical", LUA_TNUMBER},
    {"percentHealing", LUA_TNUMBER},
    {"percentUndefined", LUA_TNUMBER},
    { NULL, 0 }
},
reflect[] = {
    {"percentAll", LUA_TNUMBER},
    {"percentElements", LUA_TNUMBER},
    {"percentMagic", LUA_TNUMBER},
    {"percentEnergy", LUA_TNUMBER},
    {"percentFire", LUA_TNUMBER},
    {"percentPoison", LUA_TNUMBER},
    {"percentIce", LUA_TNUMBER},
    {"percentHoly", LUA_TNUMBER},
    {"percentDeath", LUA_TNUMBER},
    {"percentLifeDrain", LUA_TNUMBER},
    {"percentManaDrain", LUA_TNUMBER},
    {"percentDrown", LUA_TNUMBER},
    {"percentPhysical", LUA_TNUMBER},
    {"percentHealing", LUA_TNUMBER},
    {"percentUndefined", LUA_TNUMBER},
    {"chanceAll", LUA_TNUMBER},
    {"chanceElements", LUA_TNUMBER},
    {"chanceMagic", LUA_TNUMBER},
    {"chanceEnergy", LUA_TNUMBER},
    {"chanceFire", LUA_TNUMBER},
    {"chancePoison", LUA_TNUMBER},
    {"chanceIce", LUA_TNUMBER},
    {"chanceHoly", LUA_TNUMBER},
    {"chanceDeath", LUA_TNUMBER},
    {"chanceLifeDrain", LUA_TNUMBER},
    {"chanceManaDrain", LUA_TNUMBER},
    {"chanceDrown", LUA_TNUMBER},
    {"chancePhysical", LUA_TNUMBER},
    {"chanceHealing", LUA_TNUMBER},
    {"chanceUndefined", LUA_TNUMBER},
    { NULL, 0 }
};



bool Vocations::loadFromXml()
{
    lua_State *L = luaL_newstate();
    std::string str;
    int32_t id = 0;

    if (!L) {
        throw std::runtime_error("Failed to allocate memory in vocations");
    }

    luaL_openlibs(L);

    if (luaL_dofile(L, "data/lua/vocations.lua")) {
        std::cout << "[Error - Vocations] " << lua_tostring(L, -1) << std::endl;
        lua_close(L);
        return false;
    }

    lua_getglobal(L, "vocations");

    for (int i = 1; ; i++) {
        lua_rawgeti(L, -1, i);
        if (lua_isnil(L, -1)) {
            lua_pop(L, 1);
            break;
        }
        //std::cout << i << std::endl;
        luaL_checktype(L, -1, LUA_TTABLE);
        //id = (int32_t)i;
        Vocation* voc = new Vocation(id);
        id++;
        for (int fields = 0; vocation[fields].name != NULL; fields++) {
            lua_getfield(L, -1, vocation[fields].name);
            luaL_checktype(L, -1, vocation[fields].type);
            str = vocation[fields].name;
            //std::cout << str << std::endl;
            if (lua_isnumber(L, -1)) {
                if (str == "id") {
                }
                else if (str == "needpremium") {
                    voc->setNeedPremium((lua_tonumber(L, -1) != 0));
                }
                else if (str == "gaincap") {
                    voc->setGainCap((int32_t)lua_tonumber(L, -1));
                }
                else if (str == "gainhp") {
                    voc->setGain(GAIN_HEALTH, (uint32_t)lua_tonumber(L, -1));
                }
                else if (str == "gainmana") {
                    voc->setGain(GAIN_MANA, (uint32_t)lua_tonumber(L, -1));
                }
                else if (str == "gainhpticks") {
                    voc->setGainTicks(GAIN_HEALTH, (uint32_t)lua_tonumber(L, -1));
                }
                else if (str == "gainhpamount") {
                    voc->setGainAmount(GAIN_HEALTH, (uint32_t)lua_tonumber(L, -1));
                }
                else if (str == "gainmanaticks") {
                    voc->setGainTicks(GAIN_MANA, (uint32_t)lua_tonumber(L, -1));
                }
                else if (str == "gainmanaamount") {
                    voc->setGainAmount(GAIN_MANA, (uint32_t)lua_tonumber(L, -1));
                }
                else if (str == "manamultiplier") {
                    voc->setMultiplier(MULTIPLIER_MANA, (float)lua_tonumber(L, -1));
                }
                else if (str == "attackspeed") {
                    voc->setAttackSpeed((uint32_t)lua_tonumber(L, -1));
                }
                else if (str == "basespeed") {
                    voc->setBaseSpeed((uint32_t)lua_tonumber(L, -1));
                }
                else if (str == "soulmax") {
                    voc->setGain(GAIN_SOUL, (uint32_t)lua_tonumber(L, -1));
                }
                else if (str == "gainsoulamount") {
                    voc->setGainAmount(GAIN_SOUL, (uint32_t)lua_tonumber(L, -1));
                }
                else if (str == "gainsoulticks") {
                    voc->setGainTicks(GAIN_SOUL, (uint32_t)lua_tonumber(L, -1));
                }
                else if (str == "attackable") {
                    voc->setAttackable((lua_tonumber(L, -1) != 0));
                }
                else if (str == "fromvoc") {
                    voc->setFromVocation((int32_t)lua_tonumber(L, -1));
                }
                else if (str == "lessloss") {
                    voc->setLessLoss((int32_t)lua_tonumber(L, -1));
                }
            }

            if (lua_isstring(L, -1)) {
                if (str == "name") {
                    voc->setName(lua_tostring(L, -1));
                }
                else if (str == "description") {
                    voc->setDescription(lua_tostring(L, -1));
                }
            }
            if (lua_istable(L, -1)) {
                if (str == "formula") {
                    std::string formstr;
                    for (int n = 0; formula[n].name != NULL; n++) {
                        lua_getfield(L, -1, formula[n].name);
                        luaL_checktype(L, -1, formula[n].type);
                        formstr = formula[n].name;
                        switch (lua_type(L, -1)) {
                        case LUA_TNUMBER:
                            if (formstr == "melee") {
                                voc->setMultiplier(MULTIPLIER_MELEE, (float)lua_tonumber(L, -1));
                            }
                            else if (formstr == "distance") {
                                voc->setMultiplier(MULTIPLIER_DISTANCE, (float)lua_tonumber(L, -1));
                            }
                            else if (formstr == "wand") {
                                voc->setMultiplier(MULTIPLIER_WAND, (float)lua_tonumber(L, -1));
                            }
                            else if (formstr == "magic") {
                                voc->setMultiplier(MULTIPLIER_MAGIC, (float)lua_tonumber(L, -1));
                            }
                            else if (formstr == "healing") {
                                voc->setMultiplier(MULTIPLIER_HEALING, (float)lua_tonumber(L, -1));
                            }
                            else if (formstr == "defense") {
                                voc->setMultiplier(MULTIPLIER_DEFENSE, (float)lua_tonumber(L, -1));
                            }
                            else if (formstr == "magicDefense") {
                                voc->setMultiplier(MULTIPLIER_MAGICDEFENSE, (float)lua_tonumber(L, -1));
                            }
                            else if (formstr == "armor") {
                                voc->setMultiplier(MULTIPLIER_ARMOR, (float)lua_tonumber(L, -1));
                            }else{
                                std::cout << "[Error - Parsing Formula]  (" << formstr << ") is not a valid skill." << std::endl;
                            }
                            break;
                        }
                        lua_pop(L, 1);
                    }
                }
                else if (str == "skill") {
                    std::string skillstr;
                    for (int x = 0; skill[x].name != NULL; x++) {
                        lua_getfield(L, -1, skill[x].name);
                        luaL_checktype(L, -1, skill[x].type);
                        skillstr = skill[x].name;
                        switch (lua_type(L, -1)) {
                        case LUA_TNUMBER:
                            if (skillstr == "fist") {
                                voc->setSkillMultiplier(SKILL_FIST, (float)lua_tonumber(L, -1));
                            }
                            else if(skillstr == "fistBase"){
                                voc->setSkillBase(SKILL_FIST, (uint32_t)lua_tonumber(L, -1));
                            }
                            else if (skillstr == "club") {
                                voc->setSkillMultiplier(SKILL_CLUB, (float)lua_tonumber(L, -1));
                            }
                            else if(skillstr == "clubBase"){
                                voc->setSkillBase(SKILL_CLUB, (uint32_t)lua_tonumber(L, -1));
                            }
                            else if (skillstr == "sword") {
                                voc->setSkillMultiplier(SKILL_SWORD, (float)lua_tonumber(L, -1));
                            }
                            else if(skillstr == "swordBase"){
                                voc->setSkillBase(SKILL_SWORD, (uint32_t)lua_tonumber(L, -1));
                            }
                            else if (skillstr == "axe") {
                                voc->setSkillMultiplier(SKILL_AXE, (float)lua_tonumber(L, -1));
                            }
                            else if(skillstr == "axeBase"){
                                voc->setSkillBase(SKILL_AXE, (uint32_t)lua_tonumber(L, -1));
                            }
                            else if (skillstr == "dist") {
                                voc->setSkillMultiplier(SKILL_DIST, (float)lua_tonumber(L, -1));
                            }
                            else if(skillstr == "distBase"){
                                voc->setSkillBase(SKILL_DIST, (uint32_t)lua_tonumber(L, -1));
                            }
                            else if (skillstr == "shield") {
                                voc->setSkillMultiplier(SKILL_SHIELD, (float)lua_tonumber(L, -1));
                            }
                            else if(skillstr == "shieldBase"){
                                voc->setSkillBase(SKILL_SHIELD, (uint32_t)lua_tonumber(L, -1));
                            }
                            else if (skillstr == "fish") {
                                voc->setSkillMultiplier(SKILL_FISH, (float)lua_tonumber(L, -1));
                            }
                            else if(skillstr == "fishBase"){
                                voc->setSkillBase(SKILL_FISH, (uint32_t)lua_tonumber(L, -1));
                            }
                            else if(skillstr == "experience"){
                                voc->setSkillMultiplier(SKILL__LEVEL, (float)lua_tonumber(L, -1));
                            }else{
                                std::cout << "[Error - Parsing Skills]  (" << skillstr << ") is not a valid skill." << std::endl;
                            }
                            break;
                        }
                        lua_pop(L, 1);
                    }
                }
                else if (str == "absorb") {
                    std::string absorbstr;
                    int16_t intValue = 0;
                    for (int a = 0; absorb[a].name != NULL; a++) {
                        lua_getfield(L, -1, absorb[a].name);
                        luaL_checktype(L, -1, absorb[a].type);
                        absorbstr = absorb[a].name;
                        switch (lua_type(L, -1)) {
                        case LUA_TNUMBER:
                            if (absorbstr == "percentAll") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                for(int32_t i = COMBAT_FIRST; i <= COMBAT_LAST; i++){
                                    voc->increaseAbsorb((CombatType_t)i, intValue);
                                }
                            }
                            else if(absorbstr == "percentElements"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_ENERGYDAMAGE, intValue);
                                voc->increaseAbsorb(COMBAT_FIREDAMAGE, intValue);
                                voc->increaseAbsorb(COMBAT_EARTHDAMAGE, intValue);
                                voc->increaseAbsorb(COMBAT_ICEDAMAGE, intValue);
                            }
                            else if (absorbstr == "percentMagic") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_ENERGYDAMAGE, intValue);
                                voc->increaseAbsorb(COMBAT_FIREDAMAGE, intValue);
                                voc->increaseAbsorb(COMBAT_EARTHDAMAGE, intValue);
                                voc->increaseAbsorb(COMBAT_ICEDAMAGE, intValue);
                                voc->increaseAbsorb(COMBAT_HOLYDAMAGE, intValue);
                                voc->increaseAbsorb(COMBAT_DEATHDAMAGE, intValue);
                            }
                            else if(absorbstr == "percentEnergy"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_ENERGYDAMAGE, intValue);
                            }
                            else if (absorbstr == "percentFire") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_FIREDAMAGE, intValue);
                            }
                            else if(absorbstr == "percentPoison"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_EARTHDAMAGE, intValue);
                            }
                            else if (absorbstr == "percentIce") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_ICEDAMAGE, intValue);
                            }
                            else if(absorbstr == "percentHoly"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_HOLYDAMAGE, intValue);
                            }
                            else if (absorbstr == "percentDeath") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_DEATHDAMAGE, intValue);
                            }
                            else if(absorbstr == "percentLifeDrain"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_LIFEDRAIN, intValue);
                            }
                            else if (absorbstr == "percentManaDrain") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_MANADRAIN, intValue);
                            }
                            else if(absorbstr == "percentDrown"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_DROWNDAMAGE, intValue);
                            }
                            else if (absorbstr == "percentPhysical") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_PHYSICALDAMAGE, intValue);
                            }
                            else if(absorbstr == "percentHealing"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_HEALING, intValue);
                            }
                            else if(absorbstr == "percentUndefined"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseAbsorb(COMBAT_UNDEFINEDDAMAGE, intValue);
                            }else{
                                std::cout << "[Error - Parsing Absorb]  (" << absorbstr << ") is not a valid skill." << std::endl;
 
Code:
 }
                            break;
                        }
                        lua_pop(L, 1);
                    }
                }
                else if (str == "reflect") {
                    std::string reflectstr;
                    int16_t intValue = 0;
                    for (int r = 0; reflect[r].name != NULL; r++) {
                        lua_getfield(L, -1, reflect[r].name);
                        luaL_checktype(L, -1, reflect[r].type);
                        reflectstr = reflect[r].name;
                        switch (lua_type(L, -1)) {
                        case LUA_TNUMBER:
                            if (reflectstr == "percentAll") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                for(int32_t i = COMBAT_FIRST; i <= COMBAT_LAST; i++){
                                    voc->increaseReflect(REFLECT_PERCENT, (CombatType_t)i, intValue);
                                }
                            }
                            else if(reflectstr == "percentElements"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_ENERGYDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_FIREDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_EARTHDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_ICEDAMAGE, intValue);
                            }
                            else if (reflectstr == "percentMagic") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_ENERGYDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_FIREDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_EARTHDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_ICEDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_HOLYDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_DEATHDAMAGE, intValue);
                            }
                            else if(reflectstr == "percentEnergy"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_ENERGYDAMAGE, intValue);
                            }
                            else if (reflectstr == "percentFire") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_FIREDAMAGE, intValue);
                            }
                            else if(reflectstr == "percentPoison"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_EARTHDAMAGE, intValue);
                            }
                            else if (reflectstr == "percentIce") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_ICEDAMAGE, intValue);
                            }
                            else if(reflectstr == "percentHoly"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_HOLYDAMAGE, intValue);
                            }
                            else if (reflectstr == "percentDeath") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_DEATHDAMAGE, intValue);
                            }
                            else if(reflectstr == "percentLifeDrain"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_LIFEDRAIN, intValue);
                            }
                            else if (reflectstr == "percentManaDrain") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_MANADRAIN, intValue);
                            }
                            else if(reflectstr == "percentDrown"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_DROWNDAMAGE, intValue);
                            }
                            else if (reflectstr == "percentPhysical") {
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_PHYSICALDAMAGE, intValue);
                            }
                            else if(reflectstr == "percentHealing"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_HEALING, intValue);
                            }
                            else if(reflectstr == "percentUndefined"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_PERCENT, COMBAT_UNDEFINEDDAMAGE, intValue);
                            }
                            else if(reflectstr == "chanceAll"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                for(int32_t i = COMBAT_FIRST; i <= COMBAT_LAST; i++){
                                    voc->increaseReflect(REFLECT_CHANCE, (CombatType_t)i, intValue);
                                }
                            }
                            else if(reflectstr == "chanceElements"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_ENERGYDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_FIREDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_EARTHDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_ICEDAMAGE, intValue);
                            }
                            else if(reflectstr == "chanceMagic"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_ENERGYDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_FIREDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_EARTHDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_ICEDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_HOLYDAMAGE, intValue);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_DEATHDAMAGE, intValue);
                            }
                            else if(reflectstr == "chanceEnergy"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_ENERGYDAMAGE, intValue);
                            }
                            else if(reflectstr == "chanceFire"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_FIREDAMAGE, intValue);
                            }
                            else if(reflectstr == "chancePoison"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_EARTHDAMAGE, intValue);
                            }
                            else if(reflectstr == "chanceIce"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_ICEDAMAGE, intValue);
                            }
                            else if(reflectstr == "chanceHoly"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_HOLYDAMAGE, intValue);
                            }
                            else if(reflectstr == "chanceDeath"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_DEATHDAMAGE, intValue);
                            }
                            else if(reflectstr == "chanceLifeDrain"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_LIFEDRAIN, intValue);
                            }
                            else if(reflectstr == "chanceManaDrain"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_MANADRAIN, intValue);
                            }
                            else if(reflectstr == "chanceDrown"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_DROWNDAMAGE, intValue);
                            }
                            else if(reflectstr == "chancePhysical"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_PHYSICALDAMAGE, intValue);
                            }
                            else if(reflectstr == "chanceHealing"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_HEALING, intValue);
                            }
                            else if(reflectstr == "chanceUndefined"){
                                intValue = (int16_t)lua_tonumber(L, -1);
                                voc->increaseReflect(REFLECT_CHANCE, COMBAT_UNDEFINEDDAMAGE, intValue);
                            }
                            else{
                                std::cout << "[Error - Parsing Reflect]  (" << reflectstr << ") is not a valid skill." << std::endl;
                            }
                            break;
                        }
                        lua_pop(L, 1);
                    }
                }
            }
            lua_pop(L, 1);
        }
        lua_pop(L, 1);
        vocationsMap[voc->getId()] = voc;
    }
    lua_close(L);
    
    return true;
}
 
Code:
local classes = {
    [1] = {
        id = 0,
        name = "", -- vocation name
        description = "", -- vocation description
        needpremium = 0, -- do they need to be premium to use this vocation
        gaincap = 5, -- cap gained per level
        gainhp = 5, -- hp gain per level
        gainmana = 5, -- mana gain per level
        gainhpticks = 1, -- hp ticks
        gainhpamount = 5, -- hp amount gained per tick
        gainmanaticks = 1, -- mana ticks
        gainmanaamount = 5, -- mana gained per tick
        manamultiplier = 4.0, --
        attackspeed = 2000,
        soulmax = 200,
        gainsoulamount = 5,
        gainsoulticks = 120,
        fromvoc = 0,
        attackable = 1,
        formula = {
            melee = 1.0,
            distance = 1.0,
            wand = 1.0,
            magic = 1.0,
            healing = 1.0,
            defense = 1.0,
            magicDefense = 1.0,
            armor = 1.0,
        },
        skill = {
            fist = 2.0,
            fistBase = 2.0,
            club = 2.0,
            clubBase = 2.0,
            sword = 2.0,
            swordBase = 2.0,
            axe = 2.0,
            axeBase = 2.0,
            dist = 2.0,
            distBase = 2.0,
            shield = 2.0,
            shieldBase = 2.0,
            fish = 2.0,
            fishBase = 2.0,
            experience = 1.0,
        },
        absorb = {
            percentAll = 0,
            percentElements = 0,
            percentMagic = 0,
            percentEnergy = 0,
            percentFire = 0,
            percentPoison = 0,
            percentIce = 0,
            percentHoly = 0,
            percentDeath = 0,
            percentLifeDrain = 0,
            percentManaDrain = 0,
            percentDrown = 0,
            percentPhysical = 0,
            percentHealing = 0,
            percentUndefined = 0,
        },
        reflect = {
            percentAll = 100,
            percentElements = 0,
            percentMagic = 0,
            percentEnergy = 0,
            percentFire = 0,
            percentPoison = 0,
            percentIce = 0,
            percentHoly = 0,
            percentDeath = 0,
            percentLifeDrain = 0,
            percentManaDrain = 0,
            percentDrown = 0,
            percentPhysical = 0,
            percentHealing = 0,
            percentUndefined = 0,
            chanceAll = 0,
            chanceElements = 0,
            chanceMagic = 0,
            chanceEnergy = 0,
            chanceFire = 0,
            chancePoison = 0,
            chanceIce = 0,
            chanceHoly = 0,
            chanceDeath = 0,
            chanceLifeDrain = 0,
            chanceManaDrain = 0,
            chanceDrown = 0,
            chancePhysical = 0,
            chanceHealing = 100,
            chanceUndefined = 0,
        }
    }
}


vocations = classes
 
Last edited:
I recompiled the sources with minor changes. Although id is never assigned directly from lua I still added it for legacy and organization purposes. Idealistically you can either manually copy the 1st index table of the classes table or dynamically add in additional vocations as needed.

I was going over some other code and discovered we don't need to increment id we could assign it a value directly or assign a value to it as a reference. 0 would be a default value because this vocation is created in the source.
 
Last edited:
Sometime in the future I will be releasing a complete version of tfs for both 0.3.6 and tfs 1.x to otx 3 which relies on nothing but lua rather than xml. I will be using codeblocks 16.01 and cmake 3.7.1
 
As an example to reference this table for basic information.
Code:
function getCustomVocationInfo(id, info)
    local voc = classes[id+1]
    if voc then
        return voc[info] and voc[info] or nil
    end
    return nil
end
 
Back
Top