Removal of func result conversions to arrays.

This commit is contained in:
MobiusDevelopment
2021-04-21 21:37:09 +00:00
parent fc1e82d451
commit 7fe7f49ab3
15 changed files with 179 additions and 221 deletions

View File

@@ -237,15 +237,11 @@ public class Continuous implements ISkillHandler
final DuelManager dm = DuelManager.getInstance();
if (dm != null)
{
final Effect[] effects = skill.applyEffects(creature, target, ss, sps, bss);
if (effects != null)
for (Effect buff : skill.applyEffects(creature, target, ss, sps, bss))
{
for (Effect buff : effects)
if (buff != null)
{
if (buff != null)
{
dm.onBuff(((PlayerInstance) target), buff);
}
dm.onBuff(((PlayerInstance) target), buff);
}
}
}

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -104,8 +105,6 @@ public abstract class Effect
NEGATE
}
private static final Func[] _emptyFunctionSet = new Func[0];
// member _effector is the instance of Creature that cast/used the spell/skill that is causing this effect. Do not confuse with the instance of Creature that is being affected by this effect.
private final Creature _effector;
@@ -538,12 +537,13 @@ public abstract class Effect
}
}
public Func[] getStatFuncs()
public List<Func> getStatFuncs()
{
if (_funcTemplates == null)
{
return _emptyFunctionSet;
return Collections.emptyList();
}
final List<Func> funcs = new ArrayList<>();
for (FuncTemplate t : _funcTemplates)
{
@@ -557,11 +557,8 @@ public abstract class Effect
funcs.add(f);
}
}
if (funcs.isEmpty())
{
return _emptyFunctionSet;
}
return funcs.toArray(new Func[funcs.size()]);
return funcs;
}
public void addIcon(MagicEffectIcons mi)

View File

@@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
import java.util.logging.Logger;
@@ -381,9 +382,6 @@ public abstract class Skill
public static final int COND_GRADED = 0x080000;
public static final int COND_GRADES = 0x100000;
private static final Func[] _emptyFunctionSet = new Func[0];
private static final Effect[] _emptyEffectSet = new Effect[0];
// these two build the primary key
private final int _id;
private final int _level;
@@ -2620,16 +2618,16 @@ public abstract class Skill
return targets.get(0);
}
public Func[] getStatFuncs(Effect effect, Creature creature)
public List<Func> getStatFuncs(Effect effect, Creature creature)
{
if (!(creature instanceof PlayerInstance) && !(creature instanceof Attackable) && !(creature instanceof Summon))
{
return _emptyFunctionSet;
return Collections.emptyList();
}
if (_funcTemplates == null)
{
return _emptyFunctionSet;
return Collections.emptyList();
}
final List<Func> funcs = new ArrayList<>();
@@ -2644,12 +2642,8 @@ public abstract class Skill
funcs.add(f);
}
}
if (funcs.isEmpty())
{
return _emptyFunctionSet;
}
return funcs.toArray(new Func[funcs.size()]);
return funcs;
}
public boolean hasEffects()
@@ -2657,31 +2651,31 @@ public abstract class Skill
return (_effectTemplates != null) && (_effectTemplates.length > 0);
}
public Effect[] applyEffects(Creature effector, Creature effected)
public List<Effect> applyEffects(Creature effector, Creature effected)
{
return applyEffects(effector, effected, false, false, false);
}
public Effect[] applyEffects(Creature effector, Creature effected, boolean ss, boolean sps, boolean bss)
public List<Effect> applyEffects(Creature effector, Creature effected, boolean ss, boolean sps, boolean bss)
{
if (isPassive())
{
return _emptyEffectSet;
return Collections.emptyList();
}
if (_effectTemplates == null)
{
return _emptyEffectSet;
return Collections.emptyList();
}
if ((effector != effected) && effected.isInvul())
{
return _emptyEffectSet;
return Collections.emptyList();
}
if ((_skillType == SkillType.BUFF) && effected.isBlockBuff())
{
return _emptyEffectSet;
return Collections.emptyList();
}
final List<Effect> effects = new ArrayList<>();
@@ -2715,24 +2709,19 @@ public abstract class Skill
}
}
if (effects.isEmpty())
{
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]);
return effects;
}
public Effect[] applySelfEffects(Creature effector)
public List<Effect> applySelfEffects(Creature effector)
{
if (isPassive())
{
return _emptyEffectSet;
return Collections.emptyList();
}
if (_effectTemplatesSelf == null)
{
return _emptyEffectSet;
return Collections.emptyList();
}
final List<Effect> effects = new ArrayList<>();
@@ -2777,12 +2766,8 @@ public abstract class Skill
}
}
}
if (effects.isEmpty())
{
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]);
return effects;
}
public void attach(FuncTemplate f)

View File

@@ -4493,7 +4493,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
* <li>Use an active skill</li><br>
* @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
*/
public synchronized void addStatFuncs(Func[] funcs)
public synchronized void addStatFuncs(List<Func> funcs)
{
final List<Stat> modifiedStats = new ArrayList<>();
for (Func f : funcs)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.model.items;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.l2jmobius.gameserver.data.SkillTable;
@@ -147,26 +148,29 @@ public class Armor extends Item
* Returns array of Func objects containing the list of functions used by the armor
* @param instance : ItemInstance pointing out the armor
* @param creature : Creature pointing out the player
* @return Func[] : array of functions
* @return List<Func> : List of functions
*/
@Override
public Func[] getStatFuncs(ItemInstance instance, Creature creature)
public List<Func> getStatFuncs(ItemInstance instance, Creature creature)
{
final List<Func> funcs = new ArrayList<>();
if (_funcTemplates != null)
if (_funcTemplates == null)
{
for (FuncTemplate t : _funcTemplates)
return Collections.emptyList();
}
final List<Func> funcs = new ArrayList<>();
for (FuncTemplate t : _funcTemplates)
{
final Env env = new Env();
env.player = creature;
env.item = instance;
final Func f = t.getFunc(env, instance);
if (f != null)
{
final Env env = new Env();
env.player = creature;
env.item = instance;
final Func f = t.getFunc(env, instance);
if (f != null)
{
funcs.add(f);
}
funcs.add(f);
}
}
return funcs.toArray(new Func[funcs.size()]);
return funcs;
}
}

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.model.items;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.l2jmobius.Config;
@@ -140,9 +141,6 @@ public abstract class Item
protected EffectTemplate[] _effectTemplates;
protected Skill[] _skills;
private static final Func[] _emptyFunctionSet = new Func[0];
protected static final Effect[] _emptyEffectSet = new Effect[0];
/**
* Constructor of the Item that fill class variables.<br>
* <u><i>Variables filled :</i></u><br>
@@ -507,14 +505,15 @@ public abstract class Item
* Returns array of Func objects containing the list of functions used by the item
* @param instance : ItemInstance pointing out the item
* @param creature : Creature pointing out the player
* @return Func[] : array of functions
* @return List<Func> : List of functions
*/
public Func[] getStatFuncs(ItemInstance instance, Creature creature)
public List<Func> getStatFuncs(ItemInstance instance, Creature creature)
{
if (_funcTemplates == null)
{
return _emptyFunctionSet;
return Collections.emptyList();
}
final List<Func> funcs = new ArrayList<>();
for (FuncTemplate t : _funcTemplates)
{
@@ -528,25 +527,23 @@ public abstract class Item
funcs.add(f);
}
}
if (funcs.isEmpty())
{
return _emptyFunctionSet;
}
return funcs.toArray(new Func[funcs.size()]);
return funcs;
}
/**
* Returns the effects associated with the item.
* @param instance : ItemInstance pointing out the item
* @param creature : Creature pointing out the player
* @return Effect[] : array of effects generated by the item
* @return List<Effect> : List of effects generated by the item
*/
public Effect[] getEffects(ItemInstance instance, Creature creature)
public List<Effect> getEffects(ItemInstance instance, Creature creature)
{
if (_effectTemplates == null)
{
return _emptyEffectSet;
return Collections.emptyList();
}
final List<Effect> effects = new ArrayList<>();
for (EffectTemplate et : _effectTemplates)
{
@@ -560,25 +557,23 @@ public abstract class Item
effects.add(e);
}
}
if (effects.isEmpty())
{
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]);
return effects;
}
/**
* Returns effects of skills associated with the item.
* @param caster : Creature pointing out the caster
* @param target : Creature pointing out the target
* @return Effect[] : array of effects generated by the skill
* @return List<Effect> : List of effects generated by the skill
*/
public Effect[] getSkillEffects(Creature caster, Creature target)
public List<Effect> getSkillEffects(Creature caster, Creature target)
{
if (_skills == null)
{
return _emptyEffectSet;
return Collections.emptyList();
}
final List<Effect> effects = new ArrayList<>();
for (Skill skill : _skills)
{
@@ -596,11 +591,8 @@ public abstract class Item
effects.add(e);
}
}
if (effects.isEmpty())
{
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]);
return effects;
}
/**

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.model.items;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.l2jmobius.gameserver.data.SkillTable;
@@ -290,27 +291,30 @@ public class Weapon extends Item
* Returns array of Func objects containing the list of functions used by the weapon
* @param instance : ItemInstance pointing out the weapon
* @param creature : Creature pointing out the player
* @return Func[] : array of functions
* @return List<Func> : List of functions
*/
@Override
public Func[] getStatFuncs(ItemInstance instance, Creature creature)
public List<Func> getStatFuncs(ItemInstance instance, Creature creature)
{
final List<Func> funcs = new ArrayList<>();
if (_funcTemplates != null)
if (_funcTemplates == null)
{
for (FuncTemplate t : _funcTemplates)
return Collections.emptyList();
}
final List<Func> funcs = new ArrayList<>();
for (FuncTemplate t : _funcTemplates)
{
final Env env = new Env();
env.player = creature;
env.item = instance;
final Func f = t.getFunc(env, instance);
if (f != null)
{
final Env env = new Env();
env.player = creature;
env.item = instance;
final Func f = t.getFunc(env, instance);
if (f != null)
{
funcs.add(f);
}
funcs.add(f);
}
}
return funcs.toArray(new Func[funcs.size()]);
return funcs;
}
/**
@@ -318,14 +322,15 @@ public class Weapon extends Item
* @param caster : Creature pointing out the caster
* @param target : Creature pointing out the target
* @param crit : boolean tells whether the hit was critical
* @return Effect[] : array of effects generated by the skill
* @return List<Effect> : List of effects generated by the skill
*/
public Effect[] getSkillEffects(Creature caster, Creature target, boolean crit)
public List<Effect> getSkillEffects(Creature caster, Creature target, boolean crit)
{
if ((_skillsOnCrit == null) || !crit)
{
return _emptyEffectSet;
return Collections.emptyList();
}
final List<Effect> effects = new ArrayList<>();
for (Skill skill : _skillsOnCrit)
{
@@ -348,11 +353,8 @@ public class Weapon extends Item
effects.add(e);
}
}
if (effects.isEmpty())
{
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]);
return effects;
}
/**
@@ -360,7 +362,7 @@ public class Weapon extends Item
* @param caster : Creature pointing out the caster
* @param target : Creature pointing out the target
* @param trigger : Skill pointing out the skill triggering this action
* @return Effect[] : array of effects generated by the skill
* @return List<Effect> : List of effects generated by the skill
*/
public boolean getSkillEffects(Creature caster, Creature target, Skill trigger)
{

View File

@@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model.items.instance;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level;
import java.util.logging.LogRecord;
@@ -918,9 +919,9 @@ public class ItemInstance extends WorldObject
/**
* This function basically returns a set of functions from Item/Armor/Weapon, but may add additional functions, if this particular item instance is enhanched for a particular player.
* @param creature : Creature designating the player
* @return Func[]
* @return List<Func>
*/
public Func[] getStatFuncs(Creature creature)
public List<Func> getStatFuncs(Creature creature)
{
return _item.getStatFuncs(this, creature);
}