Removal of TaskZoneSettings class.

This commit is contained in:
MobiusDevelopment
2021-03-16 06:42:46 +00:00
parent d647af4b19
commit 44ffd64510
67 changed files with 1672 additions and 2881 deletions

View File

@@ -20,7 +20,6 @@ import java.util.concurrent.Future;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.zone.ZoneType;
/**
@@ -30,7 +29,10 @@ import org.l2jmobius.gameserver.model.zone.ZoneType;
public class DamageZone extends ZoneType
{
private int _damagePerSec;
private Future<?> _task;
private final int _startTask;
private final int _reuseTask;
private volatile Future<?> _task;
public DamageZone(int id)
{
@@ -38,6 +40,10 @@ public class DamageZone extends ZoneType
// Setup default damage
_damagePerSec = 100;
// Setup default start / reuse time
_startTask = 10;
_reuseTask = 5000;
}
@Override
@@ -56,16 +62,25 @@ public class DamageZone extends ZoneType
@Override
protected void onEnter(Creature creature)
{
if (_task == null)
Future<?> task = _task;
if ((task == null) && (_damagePerSec != 0))
{
_task = ThreadPool.scheduleAtFixedRate(new ApplyDamage(this), 10, 1000);
synchronized (this)
{
task = _task;
if (task == null)
{
_task = task = ThreadPool.scheduleAtFixedRate(new ApplyDamage(), _startTask, _reuseTask);
}
}
}
}
@Override
protected void onExit(Creature creature)
{
if (getCharactersInside().isEmpty())
if (getCharactersInside().isEmpty() && (_task != null))
{
_task.cancel(true);
_task = null;
@@ -77,23 +92,27 @@ public class DamageZone extends ZoneType
return _damagePerSec;
}
class ApplyDamage implements Runnable
private class ApplyDamage implements Runnable
{
private final DamageZone _dmgZone;
ApplyDamage(DamageZone zone)
protected ApplyDamage()
{
_dmgZone = zone;
}
@Override
public void run()
{
for (Creature temp : _dmgZone.getCharactersInside())
if (getCharactersInside().isEmpty())
{
if ((temp != null) && !temp.isDead() && (temp instanceof PlayerInstance))
_task.cancel(false);
_task = null;
return;
}
for (Creature character : getCharactersInside())
{
if ((character != null) && character.isPlayer() && !character.isDead())
{
temp.reduceCurrentHp(_dmgZone.getDamagePerSecond(), null);
character.reduceCurrentHp(getDamagePerSecond(), null);
}
}
}

View File

@@ -24,18 +24,15 @@ import java.util.logging.Logger;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.commons.util.StringUtil;
import org.l2jmobius.gameserver.data.SkillTable;
import org.l2jmobius.gameserver.model.Skill;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.zone.ZoneId;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.network.serverpackets.EtcStatusUpdate;
/**
* another type of damage zone with skills
* Another type of damage zone with skills.
* @author kerberos
*/
public class EffectZone extends ZoneType
@@ -47,8 +44,8 @@ public class EffectZone extends ZoneType
private int _reuse;
boolean _enabled;
private boolean _isShowDangerIcon;
private Future<?> _task;
protected Map<Integer, Integer> _skills;
private volatile Future<?> _task;
public EffectZone(int id)
{
@@ -75,14 +72,19 @@ public class EffectZone extends ZoneType
_initialDelay = Integer.parseInt(value);
break;
}
case "reuse":
{
_reuse = Integer.parseInt(value);
break;
}
case "defaultStatus":
{
_enabled = Boolean.parseBoolean(value);
break;
}
case "reuse":
case "showDangerIcon":
{
_reuse = Integer.parseInt(value);
_isShowDangerIcon = Boolean.parseBoolean(value);
break;
}
case "skillIdLvl":
@@ -94,7 +96,7 @@ public class EffectZone extends ZoneType
final String[] skillSplit = skill.split("-");
if (skillSplit.length != 2)
{
LOGGER.warning(StringUtil.concat(getClass().getSimpleName() + ": invalid config property -> skillsIdLvl \"", skill, "\""));
LOGGER.warning(getClass().getSimpleName() + ": invalid config property -> skillsIdLvl \"" + skill + "\"");
}
else
{
@@ -106,22 +108,16 @@ public class EffectZone extends ZoneType
{
if (!skill.isEmpty())
{
LOGGER.warning(StringUtil.concat(getClass().getSimpleName() + ": invalid config property -> skillsIdLvl \"", skillSplit[0], "\"", skillSplit[1]));
LOGGER.warning(getClass().getSimpleName() + ": invalid config property -> skillsIdLvl \"" + skillSplit[0] + "\"" + skillSplit[1]);
}
}
}
}
break;
}
case "showDangerIcon":
{
_isShowDangerIcon = Boolean.parseBoolean(value);
break;
}
default:
{
super.setParameter(name, value);
break;
}
}
}
@@ -129,33 +125,38 @@ public class EffectZone extends ZoneType
@Override
protected void onEnter(Creature creature)
{
if ((_skills != null) && (_task == null))
if (_skills != null)
{
synchronized (this)
Future<?> task = _task;
if (task == null)
{
if (_task == null)
synchronized (this)
{
_task = ThreadPool.scheduleAtFixedRate(new ApplySkill(), _initialDelay, _reuse);
task = _task;
if (task == null)
{
_task = task = ThreadPool.scheduleAtFixedRate(new ApplySkill(), _initialDelay, _reuse);
}
}
}
}
if ((creature instanceof PlayerInstance) && _isShowDangerIcon)
if (creature.isPlayer() && _isShowDangerIcon)
{
creature.setInsideZone(ZoneId.DANGER_AREA, true);
creature.sendPacket(new EtcStatusUpdate((PlayerInstance) creature));
creature.sendPacket(new EtcStatusUpdate(creature.getActingPlayer()));
}
}
@Override
protected void onExit(Creature creature)
{
if ((creature instanceof PlayerInstance) && _isShowDangerIcon)
if (creature.isPlayer() && _isShowDangerIcon)
{
creature.setInsideZone(ZoneId.DANGER_AREA, false);
if (!creature.isInsideZone(ZoneId.DANGER_AREA))
{
creature.sendPacket(new EtcStatusUpdate((PlayerInstance) creature));
creature.sendPacket(new EtcStatusUpdate(creature.getActingPlayer()));
}
}
@@ -166,11 +167,6 @@ public class EffectZone extends ZoneType
}
}
protected Skill getSkill(int skillId, int skillLevel)
{
return SkillTable.getInstance().getSkill(skillId, skillLevel);
}
public int getChance()
{
return _chance;
@@ -232,9 +228,9 @@ public class EffectZone extends ZoneType
_enabled = value;
}
class ApplySkill implements Runnable
private class ApplySkill implements Runnable
{
ApplySkill()
protected ApplySkill()
{
if (_skills == null)
{
@@ -245,35 +241,30 @@ public class EffectZone extends ZoneType
@Override
public void run()
{
if (_enabled)
if (!isEnabled())
{
for (Creature temp : getCharactersInside())
return;
}
if (getCharactersInside().isEmpty())
{
_task.cancel(false);
_task = null;
return;
}
for (Creature character : getCharactersInside())
{
if ((character != null) && character.isPlayer() && !character.isDead() && (Rnd.get(100) < _chance))
{
if ((temp != null) && !temp.isDead())
for (Entry<Integer, Integer> e : _skills.entrySet())
{
if (!(temp instanceof Playable))
final Skill skill = SkillTable.getInstance().getSkill(e.getKey().intValue(), e.getValue().intValue());
if ((skill != null) && skill.checkCondition(character, character, false))
{
continue;
}
if (Rnd.get(100) < _chance)
{
for (Entry<Integer, Integer> e : _skills.entrySet())
if (character.getFirstEffect(e.getKey()) == null)
{
final Skill skill = getSkill(e.getKey(), e.getValue());
if (skill == null)
{
LOGGER.warning("ATTENTION: Skill " + e.getKey() + " cannot be loaded.. Verify Skill definition into data/stats/skill folder...");
continue;
}
if (skill.checkCondition(temp, temp, false))
{
if (temp.getFirstEffect(e.getKey()) == null)
{
skill.getEffects(temp, temp);
}
}
skill.getEffects(character, character);
}
}
}