Defence/Immunity as a Skill - TFS 1.3

PuszekLDZ

Member
Joined
Jan 2, 2020
Messages
148
Solutions
1
Reaction score
24
Location
Lodz
Hello.

I wonder is there a chance, to do a new skill like a immunity to e.g energy.
Also every energy attack thick will rise Your skill.
Like a shielding for e.g Energy

How should it work:
Energy fiels takes from you 20 HP points. (1 lvl skill)

You got skill "Resist Energy" on 1 lvl = enegry attack takes form You 20 HP
When you get 10 skill lvl - energy field will take just 18 HP (10 lvl = 10%)
etc..

I have done so far, just a new skill and get it into client - but I dont have it "linked/writed" to train that resist and decreasing energy attacks.
What to look for in the code, what to change to make it work?
Is it in C++ of server or it could be done just with LUA? Maybe both... ?
 
Solution
Hi again - i found that lines that goes to game.cpp

Maybe someone could check it and make it works on TFS 1.3?

C++:
bool Game::combatChangeHealth(CombatType_t combatType, Creature* attacker, Creature* target, int32_t healthChange,
    MagicEffect_t hitEffect/* = MAGIC_EFFECT_UNKNOWN*/, TextColor_t hitColor/* = TEXTCOLOR_UNKNOWN*/, bool force/* = false*/)
{   
    const Position& targetPos = target->getPosition();
    if(healthChange > 0)
    {
        if(!force && target->getHealth() <= 0)
            return false;

        bool deny = false;
        CreatureEventList statsChangeEvents = target->getCreatureEvents(CREATURE_EVENT_STATSCHANGE);
        for(CreatureEventList::iterator it = statsChangeEvents.begin(); it !=...
OP
PuszekLDZ

PuszekLDZ

Member
Joined
Jan 2, 2020
Messages
148
Solutions
1
Reaction score
24
Location
Lodz
is that code (0.4) good for base for TFS 1.3
I mean could someone teke that to TFS 1.3 version?

FIREDAMAGE - to Energy
SKILL_FISH - to SKILL_RESISTENERGY

C++:
if(params.combatType == COMBAT_FIREDAMAGE && target && target->getPlayer())
            {
                double damageChange = 0;
                int32_t skillFish = target->getPlayer()->getSkill(SKILL_FISH, SKILL_LEVEL);
 
                if(skillFish >= 10)
                    damageChange = std::ceil(skillFish * 0.1 * damage / 100);
 
                if((int32_t)damageChange != 0)
                {
                    damage -= (int32_t)damageChange;
                    char buffer[150];
                    sprintf(buffer, "%d hitpoint%s has been absorbed by your resistance.", (int32_t)damageChange, ((int32_t)damageChange == 1 ? "" : "s"));
 
                    target->getPlayer()->addSkillAdvance(SKILL_FISH, 1, true);
                    target->getPlayer()->sendTextMessage(MSG_EVENT_DEFAULT, buffer);
                }
            }
 
OP
PuszekLDZ

PuszekLDZ

Member
Joined
Jan 2, 2020
Messages
148
Solutions
1
Reaction score
24
Location
Lodz
Hi again - i found that lines that goes to game.cpp

Maybe someone could check it and make it works on TFS 1.3?

C++:
bool Game::combatChangeHealth(CombatType_t combatType, Creature* attacker, Creature* target, int32_t healthChange,
    MagicEffect_t hitEffect/* = MAGIC_EFFECT_UNKNOWN*/, TextColor_t hitColor/* = TEXTCOLOR_UNKNOWN*/, bool force/* = false*/)
{   
    const Position& targetPos = target->getPosition();
    if(healthChange > 0)
    {
        if(!force && target->getHealth() <= 0)
            return false;

        bool deny = false;
        CreatureEventList statsChangeEvents = target->getCreatureEvents(CREATURE_EVENT_STATSCHANGE);
        for(CreatureEventList::iterator it = statsChangeEvents.begin(); it != statsChangeEvents.end(); ++it)
        {
            if(!(*it)->executeStatsChange(target, attacker, STATSCHANGE_HEALTHGAIN, combatType, healthChange))
                deny = true;
        }

        if(deny)
            return false;

        target->gainHealth(attacker, healthChange);
        if(g_config.getBool(ConfigManager::SHOW_HEALING_DAMAGE) && !target->isGhost() &&
            (g_config.getBool(ConfigManager::SHOW_HEALING_DAMAGE_MONSTER) || !target->getMonster()))
        {
            char buffer[20];
            sprintf(buffer, "+%d", healthChange);

            const SpectatorVec& list = getSpectators(targetPos);
            if(combatType != COMBAT_HEALING)
                addMagicEffect(list, targetPos, MAGIC_EFFECT_WRAPS_BLUE);

            addAnimatedText(list, targetPos, g_config.getNumber(ConfigManager::HEALTH_HEALING_COLOR), buffer);
        }
    }
    else
    {
        const SpectatorVec& list = getSpectators(targetPos);
        if(!target->isAttackable() || Combat::canDoCombat(attacker, target) != RET_NOERROR)
        {
            addMagicEffect(list, targetPos, MAGIC_EFFECT_POFF);
            return true;
        }

        int32_t damage = -healthChange;
        if(damage != 0)
        {


if(!combatType == COMBAT_PHYSICALDAMAGE && target && target->getPlayer())
            {
                double damageChange = 0;
                int32_t skillFish = target->getPlayer()->getSkill(SKILL_FISH, SKILL_LEVEL);
                
                if(skillFish >= 10)
                    damageChange = std::ceil(skillFish * 0.1 * damage / 100);

                if((int32_t)damageChange != 0)
                {
                    damage -= (int32_t)damageChange;
                    char buffer[150];
                    sprintf(buffer, "%d hitpoint%s has been absorbed by your resistance.", (int32_t)damageChange, ((int32_t)damageChange == 1 ? "" : "s"));

                    target->getPlayer()->addSkillAdvance(SKILL_FISH, 1, true);
                    target->getPlayer()->sendTextMessage(MSG_EVENT_DEFAULT, buffer);
                }
            }



            if(target->hasCondition(CONDITION_MANASHIELD) && combatType != COMBAT_UNDEFINEDDAMAGE)
            {
                int32_t manaDamage = std::min(target->getMana(), damage);
                damage = std::max((int32_t)0, damage - manaDamage);
                if(manaDamage != 0)
                {
                    bool deny = false;
                    CreatureEventList statsChangeEvents = target->getCreatureEvents(CREATURE_EVENT_STATSCHANGE);
                    for(CreatureEventList::iterator it = statsChangeEvents.begin(); it != statsChangeEvents.end(); ++it)
                    {
                        if(!(*it)->executeStatsChange(target, attacker, STATSCHANGE_MANALOSS, combatType, manaDamage))
                            deny = true;
                    }

                    if(deny)
                        return false;

                    target->drainMana(attacker, combatType, manaDamage);
                    char buffer[20];
                    sprintf(buffer, "%d", manaDamage);

                    addMagicEffect(list, targetPos, MAGIC_EFFECT_LOSE_ENERGY);
                    addAnimatedText(list, targetPos, TEXTCOLOR_BLUE, buffer);
                }
            }

            damage = std::min(target->getHealth(), damage);
            if(damage > 0)
            {
                bool deny = false;
                CreatureEventList statsChangeEvents = target->getCreatureEvents(CREATURE_EVENT_STATSCHANGE);
                for(CreatureEventList::iterator it = statsChangeEvents.begin(); it != statsChangeEvents.end(); ++it)
                {
                    if(!(*it)->executeStatsChange(target, attacker, STATSCHANGE_HEALTHLOSS, combatType, damage))
                        deny = true;
                }

                if(deny)
                    return false;

                target->drainHealth(attacker, combatType, damage);
                addCreatureHealth(list, target);

                TextColor_t textColor = TEXTCOLOR_NONE;
                MagicEffect_t magicEffect = MAGIC_EFFECT_NONE;
                switch(combatType)
                {
                    case COMBAT_PHYSICALDAMAGE:
                    {
                        Item* splash = NULL;
                        switch(target->getRace())
                        {
                            case RACE_VENOM:
                                textColor = TEXTCOLOR_LIGHTGREEN;
                                magicEffect = MAGIC_EFFECT_POISON;
                                splash = Item::CreateItem(ITEM_SMALLSPLASH, FLUID_GREEN);
                                break;

                            case RACE_BLOOD:
                                textColor = TEXTCOLOR_RED;
                                magicEffect = MAGIC_EFFECT_DRAW_BLOOD;
                                splash = Item::CreateItem(ITEM_SMALLSPLASH, FLUID_BLOOD);
                                break;

                            case RACE_UNDEAD:
                                textColor = TEXTCOLOR_GREY;
                                magicEffect = MAGIC_EFFECT_HIT_AREA;
                                break;

                            case RACE_FIRE:
                                textColor = TEXTCOLOR_ORANGE;
                                magicEffect = MAGIC_EFFECT_DRAW_BLOOD;
                                break;

                            case RACE_ENERGY:
                                textColor = TEXTCOLOR_PURPLE;
                                magicEffect = MAGIC_EFFECT_PURPLEENERGY;
                                break;

                            default:
                                break;
                        }

                        if(splash)
                        {
                            internalAddItem(NULL, target->getTile(), splash, INDEX_WHEREEVER, FLAG_NOLIMIT);
                            startDecay(splash);
                        }
                        break;
                    }

                    case COMBAT_ENERGYDAMAGE:
                    {
                        textColor = TEXTCOLOR_PURPLE;
                        magicEffect = MAGIC_EFFECT_ENERGY_DAMAGE;
                        break;
                    }

                    case COMBAT_EARTHDAMAGE:
                    {
                        textColor = TEXTCOLOR_LIGHTGREEN;
                        magicEffect = MAGIC_EFFECT_POISON_RINGS;
                        break;
                    }

                    case COMBAT_DROWNDAMAGE:
                    {
                        textColor = TEXTCOLOR_LIGHTBLUE;
                        magicEffect = MAGIC_EFFECT_LOSE_ENERGY;
                        break;
                    }

                    case COMBAT_FIREDAMAGE:
                    {
                        textColor = TEXTCOLOR_ORANGE;
                        magicEffect = MAGIC_EFFECT_HITBY_FIRE;
                        break;
                    }

                    case COMBAT_ICEDAMAGE:
                    {
                        textColor = TEXTCOLOR_TEAL;
                        magicEffect = MAGIC_EFFECT_ICEATTACK;
                        break;
                    }

                    case COMBAT_HOLYDAMAGE:
                    {
                        textColor = TEXTCOLOR_YELLOW;
                        magicEffect = MAGIC_EFFECT_HOLYDAMAGE;
                        break;
                    }

                    case COMBAT_DEATHDAMAGE:
                    {
                        textColor = TEXTCOLOR_DARKRED;
                        magicEffect = MAGIC_EFFECT_SMALLCLOUDS;
                        break;
                    }

                    case COMBAT_LIFEDRAIN:
                    {
                        textColor = TEXTCOLOR_RED;
                        magicEffect = MAGIC_EFFECT_WRAPS_RED;
                        break;
                    }

                    default:
                        break;
                }
                

                if(hitEffect != MAGIC_EFFECT_UNKNOWN)
                    magicEffect = hitEffect;

                if(hitColor != TEXTCOLOR_UNKNOWN)
                    textColor = hitColor;

                if(textColor < TEXTCOLOR_NONE && magicEffect < MAGIC_EFFECT_NONE)
                {
                    char buffer[20];
                    sprintf(buffer, "%d", damage);

                    addMagicEffect(list, targetPos, magicEffect);
                    addAnimatedText(list, targetPos, textColor, buffer);
                }
            }
        }
    }
    
    return true;
}
 
Solution
Top