Author Topic: Fafurion Summon Cubic  (Read 618 times)

Offline akado

  • Heir
  • **
  • Posts: 21
Summon Cubic
« on: October 09, 2019, 05:57:14 PM »
- Summon cubics lvl1 not work. Only Cubics 2lvl + work ok. (Testing Elemental Summoner)

Code: [Select]
[09/10 20:51:56] PlayerInstance:Поняша[268489789] callSkill() failed.
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at handlers.effecthandlers.SummonCubic.instant(SummonCubic.java:98)
at org.l2jmobius.gameserver.model.skills.Skill.applyEffectScope(Skill.java:1234)
at org.l2jmobius.gameserver.model.skills.Skill.applyEffects(Skill.java:1328)
at org.l2jmobius.gameserver.model.skills.Skill.applyEffects(Skill.java:1280)
at org.l2jmobius.gameserver.model.skills.Skill.activateSkill(Skill.java:1485)
at org.l2jmobius.gameserver.model.skills.Skill.activateSkill(Skill.java:1441)
at org.l2jmobius.gameserver.model.skills.SkillCaster.callSkill(SkillCaster.java:604)
at org.l2jmobius.gameserver.model.skills.SkillCaster.finishSkill(SkillCaster.java:515)
at org.l2jmobius.gameserver.model.skills.SkillCaster.run(SkillCaster.java:212)
at org.l2jmobius.commons.concurrent.RunnableWrapper.run(RunnableWrapper.java:42)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:835)

Online Mobius

  • Administrator
  • Distinguished King
  • *****
  • Posts: 7342
Re: Summon Cubic
« Reply #1 on: October 09, 2019, 08:49:15 PM »
What level player and what skill id/level you used?

Online Mobius

  • Administrator
  • Distinguished King
  • *****
  • Posts: 7342
Re: Summon Cubic
« Reply #2 on: October 09, 2019, 09:07:15 PM »
Try this.
Code: [Select]
Index: dist/game/data/scripts/handlers/effecthandlers/SummonCubic.java
===================================================================
--- dist/game/data/scripts/handlers/effecthandlers/SummonCubic.java (revision 5990)
+++ dist/game/data/scripts/handlers/effecthandlers/SummonCubic.java (working copy)
@@ -18,7 +18,6 @@
 
 import java.util.logging.Logger;
 
-import org.l2jmobius.commons.util.Rnd;
 import org.l2jmobius.gameserver.data.xml.impl.CubicData;
 import org.l2jmobius.gameserver.model.StatsSet;
 import org.l2jmobius.gameserver.model.actor.Creature;
@@ -93,10 +92,9 @@
  final int allowedCubicCount = (int) effected.getActingPlayer().getStat().getValue(Stats.MAX_CUBIC, 1);
  final int currentCubicCount = player.getCubics().size();
  // Extra cubics are removed, one by one, randomly.
- for (int i = 0; i <= ((currentCubicCount + 1) - allowedCubicCount); i++)
+ if (currentCubicCount >= allowedCubicCount)
  {
- final int removedCubicId = (int) player.getCubics().keySet().toArray()[Rnd.get(currentCubicCount)];
- final CubicInstance removedCubic = player.getCubicById(removedCubicId);
+ final CubicInstance removedCubic = player.getCubicById(player.getCubics().values().stream().findAny().get().getTemplate().getId());
  removedCubic.deactivate();
  }
  }

Offline Edoo

  • Elder
  • ****
  • Posts: 199
Re: Summon Cubic
« Reply #3 on: October 10, 2019, 01:50:54 PM »
Try this.
Code: [Select]
Index: dist/game/data/scripts/handlers/effecthandlers/SummonCubic.java
===================================================================
--- dist/game/data/scripts/handlers/effecthandlers/SummonCubic.java (revision 5990)
+++ dist/game/data/scripts/handlers/effecthandlers/SummonCubic.java (working copy)
@@ -18,7 +18,6 @@
 
 import java.util.logging.Logger;
 
-import org.l2jmobius.commons.util.Rnd;
 import org.l2jmobius.gameserver.data.xml.impl.CubicData;
 import org.l2jmobius.gameserver.model.StatsSet;
 import org.l2jmobius.gameserver.model.actor.Creature;
@@ -93,10 +92,9 @@
  final int allowedCubicCount = (int) effected.getActingPlayer().getStat().getValue(Stats.MAX_CUBIC, 1);
  final int currentCubicCount = player.getCubics().size();
  // Extra cubics are removed, one by one, randomly.
- for (int i = 0; i <= ((currentCubicCount + 1) - allowedCubicCount); i++)
+ if (currentCubicCount >= allowedCubicCount)
  {
- final int removedCubicId = (int) player.getCubics().keySet().toArray()[Rnd.get(currentCubicCount)];
- final CubicInstance removedCubic = player.getCubicById(removedCubicId);
+ final CubicInstance removedCubic = player.getCubicById(player.getCubics().values().stream().findAny().get().getTemplate().getId());
  removedCubic.deactivate();
  }
  }
tested Mobius with your patch, everything works fine.
I apologize for my English, I write through Google translator.

Online Mobius

  • Administrator
  • Distinguished King
  • *****
  • Posts: 7342
Re: Summon Cubic
« Reply #4 on: October 10, 2019, 06:27:44 PM »
Improved version.
Need to remove random cubic.

Code: [Select]
Index: dist/game/data/scripts/handlers/effecthandlers/SummonCubic.java
===================================================================
--- dist/game/data/scripts/handlers/effecthandlers/SummonCubic.java (revision 5990)
+++ dist/game/data/scripts/handlers/effecthandlers/SummonCubic.java (working copy)
@@ -90,14 +90,12 @@
  {
  // If maximum amount is reached, random cubic is removed.
  // Players with no mastery can have only one cubic.
- final int allowedCubicCount = (int) effected.getActingPlayer().getStat().getValue(Stats.MAX_CUBIC, 1);
+ final double allowedCubicCount = effected.getActingPlayer().getStat().getValue(Stats.MAX_CUBIC, 0);
  final int currentCubicCount = player.getCubics().size();
  // Extra cubics are removed, one by one, randomly.
- for (int i = 0; i <= ((currentCubicCount + 1) - allowedCubicCount); i++)
+ if (currentCubicCount >= allowedCubicCount)
  {
- final int removedCubicId = (int) player.getCubics().keySet().toArray()[Rnd.get(currentCubicCount)];
- final CubicInstance removedCubic = player.getCubicById(removedCubicId);
- removedCubic.deactivate();
+ player.getCubics().values().stream().skip((int) (currentCubicCount * Rnd.nextDouble())).findAny().get().deactivate();
  }
  }
 

Offline Edoo

  • Elder
  • ****
  • Posts: 199
Re: Summon Cubic
« Reply #5 on: October 10, 2019, 11:48:55 PM »
Improved version.
Need to remove random cubic.

Code: [Select]
Index: dist/game/data/scripts/handlers/effecthandlers/SummonCubic.java
===================================================================
--- dist/game/data/scripts/handlers/effecthandlers/SummonCubic.java (revision 5990)
+++ dist/game/data/scripts/handlers/effecthandlers/SummonCubic.java (working copy)
@@ -90,14 +90,12 @@
  {
  // If maximum amount is reached, random cubic is removed.
  // Players with no mastery can have only one cubic.
- final int allowedCubicCount = (int) effected.getActingPlayer().getStat().getValue(Stats.MAX_CUBIC, 1);
+ final double allowedCubicCount = effected.getActingPlayer().getStat().getValue(Stats.MAX_CUBIC, 0);
  final int currentCubicCount = player.getCubics().size();
  // Extra cubics are removed, one by one, randomly.
- for (int i = 0; i <= ((currentCubicCount + 1) - allowedCubicCount); i++)
+ if (currentCubicCount >= allowedCubicCount)
  {
- final int removedCubicId = (int) player.getCubics().keySet().toArray()[Rnd.get(currentCubicCount)];
- final CubicInstance removedCubic = player.getCubicById(removedCubicId);
- removedCubic.deactivate();
+ player.getCubics().values().stream().skip((int) (currentCubicCount * Rnd.nextDouble())).findAny().get().deactivate();
  }
  }
 

Tested, everything works fine.
I apologize for my English, I write through Google translator.

Online Mobius

  • Administrator
  • Distinguished King
  • *****
  • Posts: 7342
Re: Summon Cubic
« Reply #6 on: October 11, 2019, 12:59:54 AM »
Fixed with revision 6014.