L2JMobius

C6 Buffs in random positions

krzdev · 10 · 3079

Offline krzdev

  • Vassal
  • *
    • Posts: 5
The buffs are in random positions, no matter what order you choose the buffs. they always go to random locations. not sure if this is a bug, i believe it is, sorry if i'm wrong.

demo video: https://youtu.be/vtJEtHvTgPo


Offline ver

  • Knight
  • ***
    • Posts: 70
Yes, the position seems to be random...
Have you found out why? Maybe even fixed?


Offline krzdev

  • Vassal
  • *
    • Posts: 5
Yes, the position seems to be random...
Have you found out why? Maybe even fixed?

I would like to warn you that I'm not experienced with Java, I'm starting now, I could probably be doing something stupid and this is not the best solution for this, but it was the solution I found.

I found on line 3042 in Creature.java the following:
Code: [Select]
// Add the Effect to all effect in progress on the Creature
// if (!newEffect.getSkill().isToggle())
// {
// int pos = 0;
// for (int i = 0; i < _effects.size(); i++)
// {
// if (_effects.get(i) != null)
// {
// final int skillId = _effects.get(i).getSkill().getId();
// if (!_effects.get(i).getSkill().isToggle() && ((skillId <= 4360) || (skillId >= 4367)))
// {
// pos++;
// }
// }
// else
// {
// break;
// }
// }
// _effects.add(pos, newEffect);
// }
// else
// {
_effects.add(newEffect);
// }

I realized that this could sort the buffs, so I removed the comments, but on line 3061:
Code: [Select]
_effects.add(pos, newEffect);doesn't work as _effects is a set and it doesn't allow to add a new effect in the chosen position (i believe that the set is used because it does not accept duplicate elements)

so i changed the _effects to a List

Line 2938 in Creature.java:
before:
Code: [Select]
private final Set<Effect> _effects = ConcurrentHashMap.newKeySet();after:
Code: [Select]
private final List<Effect> _effects = new ArrayList<>();
I also needed to make some changes where _effects appears in the code, because as it is no longer a Set, some things stopped working correctly.

for example, some for loops
Code: [Select]
for (Effect effect : _effects)have the line effect.exit(false); inside them and this causes an exception as the for loop cannot remove an element which is currently being iterated over.

So I modified them to:
Code: [Select]
for (int i = 0; i < _effects.size(); i++)
and where was:
Code: [Select]
effect.exit(false);
i changed to:
Code: [Select]
_effects.get(i).exit(false);
i--;

it was also necessary to modify all effect variables inside inside the loop to _effects.get(i)

this works for me, hope i helped!


Online Mobius

  • Distinguished King
  • *****
    • Posts: 16047
Based on what you wrote.
Code: [Select]
Index: java/org/l2jmobius/gameserver/model/actor/Creature.java
===================================================================
--- java/org/l2jmobius/gameserver/model/actor/Creature.java (revision 9990)
+++ java/org/l2jmobius/gameserver/model/actor/Creature.java (working copy)
@@ -2977,12 +2977,12 @@
  }
 
  /** Map 32 bits (0x0000) containing all abnormal effect in progress. */
- private int _AbnormalEffects;
+ private int _abnormalEffects;
 
  /**
- * Set containing all active skills effects in progress of a Creature.
+ * List containing all active skills effects in progress of a Creature.
  */
- private final Set<Effect> _effects = ConcurrentHashMap.newKeySet();
+ private final List<Effect> _effects = new ArrayList<>();
 
  /** The table containing the List of all stacked effect in progress for each Stack group Identifier. */
  protected Map<String, List<Effect>> _stackedEffects = new HashMap<>();
@@ -3087,30 +3087,26 @@
  }
 
  // Add the Effect to all effect in progress on the Creature
- // if (!newEffect.getSkill().isToggle())
- // {
- // int pos = 0;
- // for (int i = 0; i < _effects.size(); i++)
- // {
- // if (_effects.get(i) != null)
- // {
- // final int skillId = _effects.get(i).getSkill().getId();
- // if (!_effects.get(i).getSkill().isToggle() && ((skillId <= 4360) || (skillId >= 4367)))
- // {
- // pos++;
- // }
- // }
- // else
- // {
- // break;
- // }
- // }
- // _effects.add(pos, newEffect);
- // }
- // else
- // {
- _effects.add(newEffect);
- // }
+ synchronized (_effects)
+ {
+ if (!newEffect.getSkill().isToggle())
+ {
+ int pos = 0;
+ for (Effect effect : _effects)
+ {
+ final int skillId = effect.getSkill().getId();
+ if (!effect.getSkill().isToggle() && ((skillId <= 4360) || (skillId >= 4367)))
+ {
+ pos++;
+ }
+ }
+ _effects.add(pos, newEffect);
+ }
+ else
+ {
+ _effects.add(newEffect);
+ }
+ }
 
  // Check if a stack group is defined for this effect
  if (newEffect.getStackType().equals("none"))
@@ -3200,7 +3196,10 @@
  // skill.exit() could be used, if the users don't wish to see "effect removed" always when a timer goes off, even if the buff isn't active any more (has been replaced). but then check e.g. npc hold and raid petrify.
  if (Config.EFFECT_CANCELING && !newStackedEffect.isHerbEffect() && (stackQueue.size() > 1))
  {
- _effects.remove(stackQueue.get(1));
+ synchronized (_effects)
+ {
+ _effects.remove(stackQueue.get(1));
+ }
  stackQueue.remove(1);
  }
 
@@ -3283,8 +3282,11 @@
  }
  }
 
- // Remove the active skill L2effect from _effects of the Creature
- _effects.remove(effect);
+ // Remove the active skill effect from _effects of the Creature
+ synchronized (_effects)
+ {
+ _effects.remove(effect);
+ }
 
  // Update active skills in progress (In Use and Not In Use because stacked) icones on client
  updateEffectIcons();
@@ -3296,7 +3298,7 @@
  */
  public void startAbnormalEffect(int mask)
  {
- _AbnormalEffects |= mask;
+ _abnormalEffects |= mask;
  updateAbnormalEffect();
  }
 
@@ -3445,7 +3447,7 @@
  */
  public void stopAbnormalEffect(int mask)
  {
- _AbnormalEffects &= ~mask;
+ _abnormalEffects &= ~mask;
  updateAbnormalEffect();
  }
 
@@ -3530,14 +3532,8 @@
  {
  for (Effect effect : _effects)
  {
- if (effect.getSkill() == null)
+ if ((effect.getSkill() != null) && (effect.getSkill().getId() == skillId))
  {
- _effects.remove(effect);
- continue;
- }
-
- if (effect.getSkill().getId() == skillId)
- {
  effect.exit(true);
  }
  }
@@ -3580,14 +3576,8 @@
  {
  for (Effect effect : _effects)
  {
- if (effect.getSkill() == null)
+ if ((effect.getSkill() != null) && (effect.getSkill().getSkillType() == skillType) && ((power == 0) || (effect.getSkill().getPower() <= power)))
  {
- _effects.remove(effect);
- continue;
- }
-
- if ((effect.getSkill().getSkillType() == skillType) && ((power == 0) || (effect.getSkill().getPower() <= power)))
- {
  effect.exit(true);
  }
  }
@@ -3868,7 +3858,7 @@
  {
  if (effect.getSkill() == null)
  {
- _effects.remove(effect);
+ // _effects.remove(effect);
  continue;
  }
 
@@ -3950,36 +3940,36 @@
  */
  public int getAbnormalEffect()
  {
- int ae = _AbnormalEffects;
+ int mask = _abnormalEffects;
  if (_isStunned)
  {
- ae |= ABNORMAL_EFFECT_STUN;
+ mask |= ABNORMAL_EFFECT_STUN;
  }
  if (_isRooted)
  {
- ae |= ABNORMAL_EFFECT_ROOT;
+ mask |= ABNORMAL_EFFECT_ROOT;
  }
  if (_isSleeping)
  {
- ae |= ABNORMAL_EFFECT_SLEEP;
+ mask |= ABNORMAL_EFFECT_SLEEP;
  }
  if (_isConfused)
  {
- ae |= ABNORMAL_EFFECT_CONFUSED;
+ mask |= ABNORMAL_EFFECT_CONFUSED;
  }
  if (_isMuted)
  {
- ae |= ABNORMAL_EFFECT_MUTED;
+ mask |= ABNORMAL_EFFECT_MUTED;
  }
  if (_isAfraid)
  {
- ae |= ABNORMAL_EFFECT_AFRAID;
+ mask |= ABNORMAL_EFFECT_AFRAID;
  }
  if (_isPhysicalMuted)
  {
- ae |= ABNORMAL_EFFECT_MUTED;
+ mask |= ABNORMAL_EFFECT_MUTED;
  }
- return ae;
+ return mask;
  }
 
  /**


Offline ver

  • Knight
  • ***
    • Posts: 70
Great, the ordering is correct! Buffs appear one after another as they suppose to.

However if you try to buff with buff you already have the exception appears:

Error creating new instance of Class class org.l2jmobius.gameserver.model.skill.effects.EffectBuff Exception was: java.lang.reflect.InvocationTargetException

and buff is dissapearing.




Online Mobius

  • Distinguished King
  • *****
    • Posts: 16047

Offline ver

  • Knight
  • ***
    • Posts: 70
Yes.

Code: [Select]

2022.03.28 21:04:20,359 WARNING 50      org.l2jmobius.gameserver.model.skill.effects.EffectTemplate     Error creating new instance of Class class org.l2jmobius.gameserver.model.skill.effects.EffectBuff Exception was: java.lang.reflect.InvocationTargetException
2022.03.28 21:04:21,010 WARNING 50      org.l2jmobius.gameserver.model.skill.effects.EffectTemplate     Error creating new instance of Class class org.l2jmobius.gameserver.model.skill.effects.EffectBuff Exception was: java.lang.reflect.InvocationTargetException
2022.03.28 21:04:21,661 WARNING 50      org.l2jmobius.gameserver.model.skill.effects.EffectTemplate     Error creating new instance of Class class org.l2jmobius.gameserver.model.skill.effects.EffectBuff Exception was: java.lang.reflect.InvocationTargetException
2022.03.28 21:04:22,313 WARNING 50      org.l2jmobius.gameserver.model.skill.effects.EffectTemplate     Error creating new instance of Class class org.l2jmobius.gameserver.model.skill.effects.EffectBuff Exception was: java.lang.reflect.InvocationTargetException
2022.03.28 21:04:22,964 WARNING 50      org.l2jmobius.gameserver.model.skill.effects.EffectTemplate     Error creating new instance of Class class org.l2jmobius.gameserver.model.skill.effects.EffectBuff Exception was: java.lang.reflect.InvocationTargetException
2022.03.28 21:04:23,616 WARNING 50      org.l2jmobius.gameserver.model.skill.effects.EffectTemplate     Error creating new instance of Class class org.l2jmobius.gameserver.model.skill.effects.EffectBuff Exception was: java.lang.reflect.InvocationTargetException
2022.03.28 21:04:40,872 WARNING 50      org.l2jmobius.gameserver.model.skill.effects.EffectTemplate     Error creating new instance of Class class org.l2jmobius.gameserver.model.skill.effects.EffectNoblesseBless Exception was: java.lang.reflect.InvocationTargetException




Online Mobius

  • Distinguished King
  • *****
    • Posts: 16047
I do not like this, but whatever...
Code: [Select]
Index: java/org/l2jmobius/gameserver/model/actor/Creature.java
===================================================================
--- java/org/l2jmobius/gameserver/model/actor/Creature.java (revision 9990)
+++ java/org/l2jmobius/gameserver/model/actor/Creature.java (working copy)
@@ -26,6 +26,7 @@
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.Future;
 import java.util.logging.Logger;
 
@@ -1876,7 +1877,7 @@
  ((Player) this).reviveRequest(((Player) this), null, false);
  }
 
- // Update active skills in progress (In Use and Not In Use because stacked) icones on client
+ // Update active skills in progress (In Use and Not In Use because stacked) icons on client
  updateEffectIcons();
 
  // Custom boss announcements configuration.
@@ -2977,12 +2978,12 @@
  }
 
  /** Map 32 bits (0x0000) containing all abnormal effect in progress. */
- private int _AbnormalEffects;
+ private int _abnormalEffects;
 
  /**
- * Set containing all active skills effects in progress of a Creature.
+ * List containing all active skills effects in progress of a Creature.
  */
- private final Set<Effect> _effects = ConcurrentHashMap.newKeySet();
+ private final List<Effect> _effects = new CopyOnWriteArrayList<>();
 
  /** The table containing the List of all stacked effect in progress for each Stack group Identifier. */
  protected Map<String, List<Effect>> _stackedEffects = new HashMap<>();
@@ -3028,7 +3029,7 @@
  * <li>If this effect doesn't belong to a Stack Group, add its Funcs to the Calculator set of the Creature (remove the old one if necessary)</li>
  * <li>If this effect has higher priority in its Stack Group, add its Funcs to the Calculator set of the Creature (remove previous stacked effect Funcs if necessary)</li>
  * <li>If this effect has NOT higher priority in its Stack Group, set the effect to Not In Use</li>
- * <li>Update active skills in progress icones on player client</li><br>
+ * <li>Update active skills in progress icons on player client</li><br>
  * @param newEffect the new effect
  */
  public synchronized void addEffect(Effect newEffect)
@@ -3087,30 +3088,29 @@
  }
 
  // Add the Effect to all effect in progress on the Creature
- // if (!newEffect.getSkill().isToggle())
- // {
- // int pos = 0;
- // for (int i = 0; i < _effects.size(); i++)
- // {
- // if (_effects.get(i) != null)
- // {
- // final int skillId = _effects.get(i).getSkill().getId();
- // if (!_effects.get(i).getSkill().isToggle() && ((skillId <= 4360) || (skillId >= 4367)))
- // {
- // pos++;
- // }
- // }
- // else
- // {
- // break;
- // }
- // }
- // _effects.add(pos, newEffect);
- // }
- // else
- // {
- _effects.add(newEffect);
- // }
+ if (!newEffect.getSkill().isToggle())
+ {
+ int pos = 0;
+ for (Effect effect : _effects)
+ {
+ if (effect == null)
+ {
+ break;
+ }
+
+ final int skillId = effect.getSkill().getId();
+ if (!effect.getSkill().isToggle() && ((skillId <= 4360) || (skillId >= 4367)))
+ {
+ pos++;
+ }
+ }
+
+ _effects.add(pos, newEffect);
+ }
+ else
+ {
+ _effects.add(newEffect);
+ }
 
  // Check if a stack group is defined for this effect
  if (newEffect.getStackType().equals("none"))
@@ -3121,7 +3121,7 @@
  // Add Funcs of this effect to the Calculator set of the Creature
  addStatFuncs(newEffect.getStatFuncs());
 
- // Update active skills in progress icones on player client
+ // Update active skills in progress icons on player client
  updateEffectIcons();
  return;
  }
@@ -3163,7 +3163,7 @@
  addStatFuncs(stackQueue.get(0).getStatFuncs());
  }
 
- // Update active skills in progress (In Use and Not In Use because stacked) icones on client
+ // Update active skills in progress (In Use and Not In Use because stacked) icons on client
  updateEffectIcons();
  }
 
@@ -3220,7 +3220,7 @@
  * <li>Remove Func added by this effect from the Creature Calculator (Stop Effect)</li>
  * <li>If the Effect belongs to a not empty Stack Group, replace theses Funcs by next stacked effect Funcs</li>
  * <li>Remove the Effect from _effects of the Creature</li>
- * <li>Update active skills in progress icones on player client</li><br>
+ * <li>Update active skills in progress icons on player client</li><br>
  * @param effect the effect
  */
  public void removeEffect(Effect effect)
@@ -3283,10 +3283,10 @@
  }
  }
 
- // Remove the active skill L2effect from _effects of the Creature
+ // Remove the active skill effect from _effects of the Creature
  _effects.remove(effect);
 
- // Update active skills in progress (In Use and Not In Use because stacked) icones on client
+ // Update active skills in progress (In Use and Not In Use because stacked) icons on client
  updateEffectIcons();
  }
 
@@ -3296,7 +3296,7 @@
  */
  public void startAbnormalEffect(int mask)
  {
- _AbnormalEffects |= mask;
+ _abnormalEffects |= mask;
  updateAbnormalEffect();
  }
 
@@ -3445,7 +3445,7 @@
  */
  public void stopAbnormalEffect(int mask)
  {
- _AbnormalEffects &= ~mask;
+ _abnormalEffects &= ~mask;
  updateAbnormalEffect();
  }
 
@@ -3553,7 +3553,7 @@
  * <b><u>Actions</u>:</b><br>
  * <li>Remove Func added by this effect from the Creature Calculator (Stop Effect)</li>
  * <li>Remove the Effect from _effects of the Creature</li>
- * <li>Update active skills in progress icones on player client</li><br>
+ * <li>Update active skills in progress icons on player client</li><br>
  * @param type The type of effect to stop ((ex : BUFF, DMG_OVER_TIME...)
  */
  public void stopEffects(EffectType type)
@@ -3799,7 +3799,7 @@
  public abstract void updateAbnormalEffect();
 
  /**
- * Update active skills in progress (In Use and Not In Use because stacked) icones on client.<br>
+ * Update active skills in progress (In Use and Not In Use because stacked) icons on client.<br>
  * <br>
  * <b><u>Concept</u>:</b><br>
  * <br>
@@ -3950,36 +3950,36 @@
  */
  public int getAbnormalEffect()
  {
- int ae = _AbnormalEffects;
+ int mask = _abnormalEffects;
  if (_isStunned)
  {
- ae |= ABNORMAL_EFFECT_STUN;
+ mask |= ABNORMAL_EFFECT_STUN;
  }
  if (_isRooted)
  {
- ae |= ABNORMAL_EFFECT_ROOT;
+ mask |= ABNORMAL_EFFECT_ROOT;
  }
  if (_isSleeping)
  {
- ae |= ABNORMAL_EFFECT_SLEEP;
+ mask |= ABNORMAL_EFFECT_SLEEP;
  }
  if (_isConfused)
  {
- ae |= ABNORMAL_EFFECT_CONFUSED;
+ mask |= ABNORMAL_EFFECT_CONFUSED;
  }
  if (_isMuted)
  {
- ae |= ABNORMAL_EFFECT_MUTED;
+ mask |= ABNORMAL_EFFECT_MUTED;
  }
  if (_isAfraid)
  {
- ae |= ABNORMAL_EFFECT_AFRAID;
+ mask |= ABNORMAL_EFFECT_AFRAID;
  }
  if (_isPhysicalMuted)
  {
- ae |= ABNORMAL_EFFECT_MUTED;
+ mask |= ABNORMAL_EFFECT_MUTED;
  }
- return ae;
+ return mask;
  }
 
  /**


Offline ver

  • Knight
  • ***
    • Posts: 70
It might be looking ugly, but it works ;)
Thanks!