Weakness Issue

Horyon

Пляшущий с бубном
Участник
Сообщения
210
Розыгрыши
0
Решения
4
Репутация
53
Реакции
73
Баллы
273
Хроники
  1. Master Class
Исходники
Присутствуют
Сборка
L2jMobius
Hello guys.

I'm working in one skill for make extra damage to Undeads only.

I follow Gladiator skills that grants extra dmg to bugs, plants, etc.

The problem is. UNDEAD_WEAKNESS are not working on undeads, BUT, BEAST are working in all type of mobs.

1717276855133.png

I find in server side the code i beliave be the responsable for all weakness in Formulas.java

Java:
public static double calcWeaknessBonus(Creature attacker, Creature target, TraitType traitType)
    {
        double result = 1;
        for (TraitType trait : TraitType.getAllWeakness())
        {
            if ((traitType != trait) && target.getStat().hasDefenceTrait(trait) && attacker.getStat().hasAttackTrait(trait) && !target.getStat().isInvulnerableTrait(traitType))
            {
                result *= Math.max(attacker.getStat().getAttackTrait(trait) - target.getStat().getDefenceTrait(trait), 0.05);
            }
        }
        return result;
    }

Any tip helps, ty for all.
 
2 questions:

1. Why do you only calculate when traitType != trait?
- Shouldn't this be taken out in a separate if, which will skip the execution of the rest of the code in the loop if the trait != traitType?
2. Why do you use 0.05 instead of 1?
- The way I understand it, you need the result to be 1 in all situations, including when target.getDefTrait is more than attacker.getAttackTrait, and except when attacker trait is more than def trait.
 
2 questions:

1. Why do you only calculate when traitType != trait? Shouldn't this be taken out in a separate if, which will skip the execution of the rest of the code if the trait != traitType?
2. Why do you use 0.05 instead of 1?

Mobius Source, i dont put a finger on it cause i dont understand this trait stuff enough to try something. Same u make the stuff to me long ago. Vanguard if i not wrong.
 
Mobius Source, i dont put a finger on it cause i dont understand this trait stuff enough to try something. Same u make the stuff to me long ago. Vanguard if i not wrong.

Well, try changing it in my way and see what happens. I'm fairly certain that it might, albeit miraculously, start working properly. :D

Example:
Код:
public static double calcWeaknessBonus(Creature attacker, Creature target, TraitType traitType)
    {
        double result = 1;
        for (TraitType trait : TraitType.getAllWeakness())
        {
            if (trait != traitType)
            {
                continue;
            }
        
            if (target.getStat().hasDefenceTrait(trait) && attacker.getStat().hasAttackTrait(trait) && !target.getStat().isInvulnerableTrait(traitType))
            {
                result *= Math.max(attacker.getStat().getAttackTrait(trait) - target.getStat().getDefenceTrait(trait), 1);
            }
        }
        return result;
    }

Keep in mind that you might want to leave the 0.05 instead of the 1 that I've put in if the idea is that when the target has more trait def than the attacker trait attack, then the attacker should deal much less than the original damage.
 
Последнее редактирование:
Well, try changing it in my way and see what happens. I'm fairly certain that it might, albeit miraculously, start working properly. :D

Example:
Код:
public static double calcWeaknessBonus(Creature attacker, Creature target, TraitType traitType)
    {
        double result = 1;
        for (TraitType trait : TraitType.getAllWeakness())
        {
            if (trait != traitType)
            {
                continue;
            }
       
            if (target.getStat().hasDefenceTrait(trait) && attacker.getStat().hasAttackTrait(trait) && !target.getStat().isInvulnerableTrait(traitType))
            {
                result *= Math.max(attacker.getStat().getAttackTrait(trait) - target.getStat().getDefenceTrait(trait), 1);
            }
        }
        return result;
    }

Keep in mind that you might want to leave the 0.05 instead of the 1 that I've put in if the idea is that when the target has more trait def than the attacker trait attack, then the attacker should deal much less than the original damage.
Java:
    public static double calcGeneralTraitBonus(Creature attacker, Creature target, TraitType traitType, boolean ignoreResistance)
    {
        if (traitType == TraitType.NONE)
        {
            return 1.0;
        }
        
        if (target.getStat().isInvulnerableTrait(traitType))
        {
            return 0;
        }
        
        switch (traitType.getType())
        {
            case 2:
            {
                if (!attacker.getStat().hasAttackTrait(traitType) || !target.getStat().hasDefenceTrait(traitType))
                {
                    return 1.0;
                }
                break;
            }
            case 3:
            {
                if (ignoreResistance)
                {
                    return 1.0;
                }
                break;
            }
            default:
            {
                return 1.0;
            }
        }
        
        return Math.max(attacker.getStat().getAttackTrait(traitType) - target.getStat().getDefenceTrait(traitType), 0.05);
    }
    
    public static double calcWeaknessBonus(Creature attacker, Creature target, TraitType traitType)
    {
        double result = 1;
        for (TraitType trait : TraitType.getAllWeakness())
        {
            if ((traitType != trait) && target.getStat().hasDefenceTrait(trait) && attacker.getStat().hasAttackTrait(trait) && !target.getStat().isInvulnerableTrait(traitType))
            {
                result *= Math.max(attacker.getStat().getAttackTrait(trait) - target.getStat().getDefenceTrait(trait), 1.0);
            }
        }
        return result;
    }
    
    public static double calcWeaponTraitBonus(Creature attacker, Creature target)
    {
        return Math.max(0.22, 1.0 - target.getStat().getDefenceTrait(attacker.getAttackType().getTraitType()));
    }
    
    public static double calcAttackTraitBonus(Creature attacker, Creature target)
    {
        final double weaponTraitBonus = calcWeaponTraitBonus(attacker, target);
        if (weaponTraitBonus == 0)
        {
            return 0;
        }
        
        double weaknessBonus = 1.0;
        for (TraitType traitType : TraitType.values())
        {
            if (traitType.getType() == 2)
            {
                weaknessBonus *= calcGeneralTraitBonus(attacker, target, traitType, true);
                if (weaknessBonus == 0)
                {
                    return 0;
                }
            }
        }
        
        return Math.max(weaponTraitBonus * weaknessBonus, 0.05);
    }

Maybe change this 2 others 0.05 to 1?

Well, try changing it in my way and see what happens. I'm fairly certain that it might, albeit miraculously, start working properly. :D

Example:
Код:
public static double calcWeaknessBonus(Creature attacker, Creature target, TraitType traitType)
    {
        double result = 1;
        for (TraitType trait : TraitType.getAllWeakness())
        {
            if (trait != traitType)
            {
                continue;
            }
       
            if (target.getStat().hasDefenceTrait(trait) && attacker.getStat().hasAttackTrait(trait) && !target.getStat().isInvulnerableTrait(traitType))
            {
                result *= Math.max(attacker.getStat().getAttackTrait(trait) - target.getStat().getDefenceTrait(trait), 1);
            }
        }
        return result;
    }

Keep in mind that you might want to leave the 0.05 instead of the 1 that I've put in if the idea is that when the target has more trait def than the attacker trait attack, then the attacker should deal much less than the original damage.
Sadly but the example dont work. Keep Beast given bonus and Undead dont.
 
Java:
    public static double calcWeaknessBonus(Creature attacker, Creature target, TraitType traitType)
    {
        double result = 1;
      
        for (TraitType trait : TraitType.getAllWeakness())
        {
            if (traitType == trait && target.getStat().hasDefenceTrait(trait) && attacker.getStat().hasAttackTrait(trait) && !target.getStat().isInvulnerableTrait(traitType))
            {
                result *= Math.max(attacker.getStat().getAttackTrait(trait) - target.getStat().getDefenceTrait(trait), 0.05);
                break;
            }
        }
      
        return result;
    }
 
Последнее редактирование:
Java:
    public static double calcWeaknessBonus(Creature attacker, Creature target, TraitType traitType)
    {
        double result = 1;
    
        for (TraitType trait : TraitType.getAllWeakness())
        {
            if (traitType == trait && target.getStat().hasDefenceTrait(trait) && attacker.getStat().hasAttackTrait(trait) && !target.getStat().isInvulnerableTrait(traitType))
            {
                result *= Math.max(attacker.getStat().getAttackTrait(trait) - target.getStat().getDefenceTrait(trait), 0.05);
                break;
            }
        }
    
        return result;
    }
No effect. Ty for try.

Maybe the problem is not on that part.

And this look super broken, BUG, BEAST work on all kind of mobs, UNDEAD in none.

Find one issue for tracking the problem.
1717355259918.png
The attack is working. When i try use the skill for reinforce Undead Bonus. So, no problem in attack.

But why with BEAST and BUG is working?

Dont matter what mob i hit, the return of defensor type is fix
1717355373403.png

BUG, ANIMAL, BEAS, PLANT...

The problem is in the info of defensor. Now get back to it and find where this info is collected.

Finally i hope i find the problem.

Someone have skill 4400-4499.xml correct?

The one i have, are completly wrong the values.
 
Последнее редактирование модератором:
Well i make it by me own.

And now i find the issue.

For a criature Undead, undead_weakness is -15, at race skill lvl 1 and all others weakness 0.

Even receiving 0 is add the others weakness to the array. So when u attack with others weakness even dont have negative parameters, the mob bugged receive the positive amount of attacker.

So far i saw, the add to array is here


Java:
package handlers.effecthandlers;

import java.util.EnumMap;
import java.util.Map;
import java.util.Map.Entry;

import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
import org.l2jmobius.gameserver.model.item.instance.Item;
import org.l2jmobius.gameserver.model.skill.Skill;
import org.l2jmobius.gameserver.model.stats.TraitType;

/**
 * Defence Trait effect implementation.
 * @author NosBit
 */
public class DefenceTrait extends AbstractEffect
{
    private final Map<TraitType, Float> _defenceTraits = new EnumMap<>(TraitType.class);
    
    public DefenceTrait(StatSet params)
    {
        if (params.isEmpty())
        {
            LOGGER.warning(getClass().getSimpleName() + ": must have parameters.");
            return;
        }
        
        for (Entry<String, Object> param : params.getSet().entrySet())
        {
            _defenceTraits.put(TraitType.valueOf(param.getKey()), Float.parseFloat((String) param.getValue()) / 100);
        }
    }
    
    @Override
    public void onStart(Creature effector, Creature effected, Skill skill, Item item)
    {
        for (Entry<TraitType, Float> trait : _defenceTraits.entrySet())
        {
            if (trait.getValue().floatValue() < 1.0f)
            {
                effected.getStat().mergeDefenceTrait(trait.getKey(), trait.getValue().floatValue());
            }
            else
            {
                effected.getStat().mergeInvulnerableTrait(trait.getKey());
            }
        }
    }
    
    @Override
    public void onExit(Creature effector, Creature effected, Skill skill)
    {
        for (Entry<TraitType, Float> trait : _defenceTraits.entrySet())
        {
            if (trait.getValue().floatValue() < 1.0f)
            {
                effected.getStat().removeDefenceTrait(trait.getKey(), trait.getValue().floatValue());
            }
            else
            {
                effected.getStat().removeInvulnerableTrait(trait.getKey());
            }
        }
    }
}

but this part i really dont move further. My small knowledge dont let me find a solution. So i keep asking for help to try understand why this is add wrong values to the array.

ty
 
Well i make it by me own.

And now i find the issue.

For a criature Undead, undead_weakness is -15, at race skill lvl 1 and all others weakness 0.

Even receiving 0 is add the others weakness to the array. So when u attack with others weakness even dont have negative parameters, the mob bugged receive the positive amount of attacker.

So far i saw, the add to array is here


Java:
package handlers.effecthandlers;

import java.util.EnumMap;
import java.util.Map;
import java.util.Map.Entry;

import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
import org.l2jmobius.gameserver.model.item.instance.Item;
import org.l2jmobius.gameserver.model.skill.Skill;
import org.l2jmobius.gameserver.model.stats.TraitType;

/**
 * Defence Trait effect implementation.
 * @author NosBit
 */
public class DefenceTrait extends AbstractEffect
{
    private final Map<TraitType, Float> _defenceTraits = new EnumMap<>(TraitType.class);
  
    public DefenceTrait(StatSet params)
    {
        if (params.isEmpty())
        {
            LOGGER.warning(getClass().getSimpleName() + ": must have parameters.");
            return;
        }
      
        for (Entry<String, Object> param : params.getSet().entrySet())
        {
            _defenceTraits.put(TraitType.valueOf(param.getKey()), Float.parseFloat((String) param.getValue()) / 100);
        }
    }
  
    @Override
    public void onStart(Creature effector, Creature effected, Skill skill, Item item)
    {
        for (Entry<TraitType, Float> trait : _defenceTraits.entrySet())
        {
            if (trait.getValue().floatValue() < 1.0f)
            {
                effected.getStat().mergeDefenceTrait(trait.getKey(), trait.getValue().floatValue());
            }
            else
            {
                effected.getStat().mergeInvulnerableTrait(trait.getKey());
            }
        }
    }
  
    @Override
    public void onExit(Creature effector, Creature effected, Skill skill)
    {
        for (Entry<TraitType, Float> trait : _defenceTraits.entrySet())
        {
            if (trait.getValue().floatValue() < 1.0f)
            {
                effected.getStat().removeDefenceTrait(trait.getKey(), trait.getValue().floatValue());
            }
            else
            {
                effected.getStat().removeInvulnerableTrait(trait.getKey());
            }
        }
    }
}

but this part i really dont move further. My small knowledge dont let me find a solution. So i keep asking for help to try understand why this is add wrong values to the array.

ty
Just another update in the investigation.

In XML, if i just wite the effect like

UNDEAD_WEAKNESS, ANIMAL_WEAKNESS, etc... every mob will receive this weakness, so a gremlin has UNDEAD_WEAKNESS, and all others. And dont make sence. Even if values are 0 in xml, he add the weakness to the mob weakness list. And this make wrong interactions, like is happening to me.

I have Extra DMG to UNDEAD, even gremlin as that is aFAIRY, he will receive UNDEAD_WEAKNESS with 0 value.

The test will find the weakness and will add the Extra DMG and the fairy will take undead extra dmg.

The normal behavior i think is not add the weakness list if values are 0. But is happening.

Any tip helps solve this DefenseTrait who are add wrong stuff.

Ty in advance.

PS: If u are using mobius u have the same issue and maybe dont even know weakness are not working properly.
 
Gremlin is a fairy?? No way... My world never be the same again...
 
Назад
Сверху Снизу