Disabled skills list now holds Skills instead of Integers.

This commit is contained in:
MobiusDevelopment
2019-05-27 20:53:53 +00:00
parent addd728f80
commit 2f76d3936b
6 changed files with 141 additions and 167 deletions

View File

@@ -196,7 +196,7 @@ public final class Augmentation
if (_skill.isActive() && (Config.ACTIVE_AUGMENTS_START_REUSE_TIME > 0)) if (_skill.isActive() && (Config.ACTIVE_AUGMENTS_START_REUSE_TIME > 0))
{ {
player.disableSkill(_skill, Config.ACTIVE_AUGMENTS_START_REUSE_TIME); player.disableSkill(_skill, Config.ACTIVE_AUGMENTS_START_REUSE_TIME);
player.addTimeStamp(_skill, Config.ACTIVE_AUGMENTS_START_REUSE_TIME); player.addTimestamp(_skill, Config.ACTIVE_AUGMENTS_START_REUSE_TIME);
} }
player.sendSkillList(); player.sendSkillList();

View File

@@ -429,7 +429,6 @@ public abstract class Skill
private final int _coolTime; private final int _coolTime;
private final int _reuseDelay; private final int _reuseDelay;
private final int _buffDuration; private final int _buffDuration;
private final int _reuseHashCode;
/** Target type of the skill : SELF, PARTY, CLAN, PET... */ /** Target type of the skill : SELF, PARTY, CLAN, PET... */
private final SkillTargetType _targetType; private final SkillTargetType _targetType;
@@ -669,8 +668,6 @@ public abstract class Skill
_singleEffect = set.getBool("singleEffect", false); _singleEffect = set.getBool("singleEffect", false);
_isDebuff = set.getBool("isDebuff", false); _isDebuff = set.getBool("isDebuff", false);
_reuseHashCode = SkillTable.getSkillHashCode(_id, _level);
} }
public abstract void useSkill(Creature caster, WorldObject[] targets); public abstract void useSkill(Creature caster, WorldObject[] targets);
@@ -3214,14 +3211,6 @@ public abstract class Skill
return _advancedMultiplier; return _advancedMultiplier;
} }
/**
* @return the _reuseHashCode
*/
public int getReuseHashCode()
{
return _reuseHashCode;
}
/** /**
* @return the _effectTemplates * @return the _effectTemplates
*/ */

View File

@@ -19,12 +19,12 @@ package org.l2jmobius.gameserver.model.actor;
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK; import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -1868,9 +1868,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
} }
// Skill reuse check // Skill reuse check
if (reuseDelay > 30000) if ((reuseDelay > 30000) && isPlayer())
{ {
addTimeStamp(skill, reuseDelay); getActingPlayer().addTimestamp(skill, reuseDelay);
} }
// Check if this skill consume mp on start casting // Check if this skill consume mp on start casting
@@ -1966,23 +1966,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
}); });
} }
/**
* Index according to skill id the current timestamp of use.<br>
* @param skill the s
* @param r the r
*/
public void addTimeStamp(Skill skill, int r)
{
}
/**
* Index according to skill id the current timestamp of use.<br>
* @param _skill the s
*/
public void removeTimeStamp(Skill _skill)
{
}
/** /**
* Starts a force buff on target.<br> * Starts a force buff on target.<br>
* @param target the target * @param target the target
@@ -3037,15 +3020,18 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
*/ */
class EnableSkill implements Runnable class EnableSkill implements Runnable
{ {
Skill _skillId; Creature _creature;
Skill _skill;
/** /**
* Instantiates a new enable skill. * Instantiates a new enable skill.
* @param creature
* @param skill the skill * @param skill the skill
*/ */
public EnableSkill(Skill skill) public EnableSkill(Creature creature, Skill skill)
{ {
_skillId = skill; _creature = creature;
_skill = skill;
} }
@Override @Override
@@ -3053,7 +3039,10 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
{ {
try try
{ {
enableSkill(_skillId); if (_creature != null)
{
_creature.enableSkill(_skill);
}
} }
catch (Throwable e) catch (Throwable e)
{ {
@@ -4745,7 +4734,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
public int geoPathGty; public int geoPathGty;
} }
protected List<Integer> _disabledSkills; protected List<Skill> _disabledSkills = new CopyOnWriteArrayList<>();
private boolean _allSkillsDisabled; private boolean _allSkillsDisabled;
protected MoveData _move; protected MoveData _move;
private boolean _cursorKeyMovement = false; private boolean _cursorKeyMovement = false;
@@ -8262,40 +8251,15 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
* <BR> * <BR>
* All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the Creature <BR> * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the Creature <BR>
* <BR> * <BR>
* @param _skill * @param skill
*/ */
public void enableSkill(Skill _skill) public void enableSkill(Skill skill)
{ {
if (_disabledSkills == null) _disabledSkills.remove(skill);
if (isPlayer())
{ {
return; getActingPlayer().removeTimestamp(skill);
} }
_disabledSkills.remove(_skill.getReuseHashCode());
if (this instanceof PlayerInstance)
{
removeTimeStamp(_skill);
}
}
/**
* Disable a skill (add it to _disabledSkills of the Creature).<BR>
* <BR>
* <B><U> Concept</U> :</B><BR>
* <BR>
* All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the Creature <BR>
* <BR>
* @param skill The identifier of the Skill to disable
*/
public void disableSkill(Skill skill)
{
if (_disabledSkills == null)
{
_disabledSkills = Collections.synchronizedList(new ArrayList<Integer>());
}
_disabledSkills.add(skill.getReuseHashCode());
} }
/** /**
@@ -8310,11 +8274,14 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
return; return;
} }
disableSkill(skill); if (!_disabledSkills.contains(skill))
{
_disabledSkills.add(skill);
}
if (delay > 10) if (delay > 10)
{ {
ThreadPool.schedule(new EnableSkill(skill), delay); ThreadPool.schedule(new EnableSkill(this, skill), delay);
} }
} }
@@ -8325,21 +8292,19 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
* <BR> * <BR>
* All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the Creature <BR> * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the Creature <BR>
* <BR> * <BR>
* @param _skill the skill to know if its disabled * @param skill the skill to know if its disabled
* @return true, if is skill disabled * @return true, if is skill disabled
*/ */
public boolean isSkillDisabled(Skill _skill) public boolean isSkillDisabled(Skill skill)
{ {
final Skill skill = _skill;
if (isAllSkillsDisabled() && !skill.isPotion()) if (isAllSkillsDisabled() && !skill.isPotion())
{ {
return true; return true;
} }
if (this instanceof PlayerInstance) if (isPlayer())
{ {
final PlayerInstance activeChar = (PlayerInstance) this; final PlayerInstance activeChar = getActingPlayer();
if (((skill.getSkillType() == SkillType.FISHING) || (skill.getSkillType() == SkillType.REELING) || (skill.getSkillType() == SkillType.PUMPING)) && !activeChar.isFishing() && ((activeChar.getActiveWeaponItem() != null) && (activeChar.getActiveWeaponItem().getItemType() != WeaponType.ROD))) if (((skill.getSkillType() == SkillType.FISHING) || (skill.getSkillType() == SkillType.REELING) || (skill.getSkillType() == SkillType.PUMPING)) && !activeChar.isFishing() && ((activeChar.getActiveWeaponItem() != null) && (activeChar.getActiveWeaponItem().getItemType() != WeaponType.ROD)))
{ {
@@ -8392,19 +8357,14 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
return true; return true;
} }
if (activeChar.isHero() && HeroSkillTable.isHeroSkill(_skill.getId()) && activeChar.isInOlympiadMode() && activeChar.isOlympiadStart()) if (activeChar.isHero() && HeroSkillTable.isHeroSkill(skill.getId()) && activeChar.isInOlympiadMode() && activeChar.isOlympiadStart())
{ {
activeChar.sendMessage("You can't use Hero skills during Olympiad match."); activeChar.sendMessage("You can't use Hero skills during Olympiad match.");
return true; return true;
} }
} }
if (_disabledSkills == null) return _disabledSkills.contains(skill);
{
return false;
}
return _disabledSkills.contains(_skill.getReuseHashCode());
} }
/** /**

View File

@@ -151,6 +151,7 @@ import org.l2jmobius.gameserver.model.entity.siege.Siege;
import org.l2jmobius.gameserver.model.entity.siege.clanhalls.DevastatedCastle; import org.l2jmobius.gameserver.model.entity.siege.clanhalls.DevastatedCastle;
import org.l2jmobius.gameserver.model.extender.BaseExtender.EventType; import org.l2jmobius.gameserver.model.extender.BaseExtender.EventType;
import org.l2jmobius.gameserver.model.holders.PlayerStatsHolder; import org.l2jmobius.gameserver.model.holders.PlayerStatsHolder;
import org.l2jmobius.gameserver.model.holders.TimestampHolder;
import org.l2jmobius.gameserver.model.quest.Quest; import org.l2jmobius.gameserver.model.quest.Quest;
import org.l2jmobius.gameserver.model.quest.QuestState; import org.l2jmobius.gameserver.model.quest.QuestState;
import org.l2jmobius.gameserver.model.quest.State; import org.l2jmobius.gameserver.model.quest.State;
@@ -535,7 +536,7 @@ public final class PlayerInstance extends Playable
private final List<Integer> _selectedBlocksList = new ArrayList<>(); // Related to CB. private final List<Integer> _selectedBlocksList = new ArrayList<>(); // Related to CB.
private int _mailPosition; private int _mailPosition;
private FishData _fish; private FishData _fish;
private final Map<Integer, TimeStamp> ReuseTimeStamps = new ConcurrentHashMap<>(); private final Map<Integer, TimestampHolder> _reuseTimestamps = new ConcurrentHashMap<>();
boolean _gmStatus = true; // true by default since this is used by GMS boolean _gmStatus = true; // true by default since this is used by GMS
public WorldObject _saymode = null; public WorldObject _saymode = null;
String Dropzor = "Coin of Luck"; String Dropzor = "Coin of Luck";
@@ -9925,9 +9926,9 @@ public final class PlayerInstance extends Playable
statement.setInt(3, effect.getSkill().getLevel()); statement.setInt(3, effect.getSkill().getLevel());
statement.setInt(4, effect.getCount()); statement.setInt(4, effect.getCount());
statement.setInt(5, effect.getTime()); statement.setInt(5, effect.getTime());
if (ReuseTimeStamps.containsKey(effect.getSkill().getReuseHashCode())) if (_reuseTimestamps.containsKey(effect.getSkill().getId()))
{ {
final TimeStamp t = ReuseTimeStamps.get(effect.getSkill().getReuseHashCode()); final TimestampHolder t = _reuseTimestamps.get(effect.getSkill().getId());
statement.setLong(6, t.hasNotPassed() ? t.getReuse() : 0); statement.setLong(6, t.hasNotPassed() ? t.getReuse() : 0);
statement.setLong(7, t.hasNotPassed() ? t.getStamp() : 0); statement.setLong(7, t.hasNotPassed() ? t.getStamp() : 0);
} }
@@ -9943,12 +9944,12 @@ public final class PlayerInstance extends Playable
} }
} }
// Store the reuse delays of remaining skills which lost effect but still under reuse delay. 'restore_type' 1. // Store the reuse delays of remaining skills which lost effect but still under reuse delay. 'restore_type' 1.
for (TimeStamp t : ReuseTimeStamps.values()) for (TimestampHolder t : _reuseTimestamps.values())
{ {
if (t.hasNotPassed()) if (t.hasNotPassed())
{ {
final int skillId = t.getSkill().getId(); final int skillId = t.getSkillId();
final int skillLvl = t.getSkill().getLevel(); final int skillLvl = t.getSkillLevel();
if (storedSkills.contains(skillId)) if (storedSkills.contains(skillId))
{ {
continue; continue;
@@ -10399,7 +10400,7 @@ public final class PlayerInstance extends Playable
} }
disableSkill(skill, remainingTime); disableSkill(skill, remainingTime);
addTimeStamp(new TimeStamp(skill, reuseDelay, systime)); addTimestamp(new TimestampHolder(skill, reuseDelay, systime));
} }
} }
rset.close(); rset.close();
@@ -10429,7 +10430,7 @@ public final class PlayerInstance extends Playable
} }
disableSkill(skill, remainingTime); disableSkill(skill, remainingTime);
addTimeStamp(new TimeStamp(skill, reuseDelay, systime)); addTimestamp(new TimestampHolder(skill, reuseDelay, systime));
} }
} }
rset.close(); rset.close();
@@ -16461,100 +16462,49 @@ public final class PlayerInstance extends Playable
sendPacket(new EtcStatusUpdate(this)); sendPacket(new EtcStatusUpdate(this));
} }
public static class TimeStamp
{
public long getStamp()
{
return stamp;
}
public Skill getSkill()
{
return skill;
}
public long getReuse()
{
return reuse;
}
public long getRemaining()
{
return Math.max(stamp - System.currentTimeMillis(), 0);
}
protected boolean hasNotPassed()
{
return System.currentTimeMillis() < stamp;
}
private final Skill skill;
private final long reuse;
private final long stamp;
protected TimeStamp(Skill _skill, long _reuse)
{
skill = _skill;
reuse = _reuse;
stamp = System.currentTimeMillis() + reuse;
}
protected TimeStamp(Skill _skill, long _reuse, long _systime)
{
skill = _skill;
reuse = _reuse;
stamp = _systime;
}
}
/** /**
* Index according to skill id the current timestamp of use. * Index according to skill id the current timestamp of use.
* @param s the s * @param s the s
* @param r the r * @param r the r
*/ */
@Override public void addTimestamp(Skill s, int r)
public void addTimeStamp(Skill s, int r)
{ {
ReuseTimeStamps.put(s.getReuseHashCode(), new TimeStamp(s, r)); _reuseTimestamps.put(s.getId(), new TimestampHolder(s, r));
} }
/** /**
* Index according to skill this TimeStamp instance for restoration purposes only. * Index according to skill this TimeStamp instance for restoration purposes only.
* @param T the t * @param t the t
*/ */
private void addTimeStamp(TimeStamp T) private void addTimestamp(TimestampHolder t)
{ {
ReuseTimeStamps.put(T.getSkill().getReuseHashCode(), T); _reuseTimestamps.put(t.getSkillId(), t);
} }
/** /**
* Index according to skill id the current timestamp of use. * Index according to skill id the current timestamp of use.
* @param s the s * @param skill the skill
*/ */
@Override public void removeTimestamp(Skill skill)
public void removeTimeStamp(Skill s)
{ {
ReuseTimeStamps.remove(s.getReuseHashCode()); _reuseTimestamps.remove(skill.getId());
} }
public Collection<TimeStamp> getReuseTimeStamps() public Collection<TimestampHolder> getReuseTimeStamps()
{ {
return ReuseTimeStamps.values(); return _reuseTimestamps.values();
} }
public void resetSkillTime(boolean ssl) public void resetSkillTime(boolean sendSkillList)
{ {
final Skill arr$[] = getAllSkills(); for (Skill skill : getAllSkills())
for (Skill skill : arr$)
{ {
if ((skill != null) && skill.isActive() && (skill.getId() != 1324)) if ((skill != null) && skill.isActive() && (skill.getId() != 1324))
{ {
enableSkill(skill); enableSkill(skill);
} }
} }
if (sendSkillList)
if (ssl)
{ {
sendSkillList(); sendSkillList();
} }

View File

@@ -0,0 +1,78 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.model.holders;
import org.l2jmobius.gameserver.model.Skill;
/**
* @author Mobius
*/
public class TimestampHolder
{
private final Skill _skill;
private final long _reuse;
private final long _stamp;
public TimestampHolder(Skill skill, long reuse)
{
_skill = skill;
_reuse = reuse;
_stamp = System.currentTimeMillis() + _reuse;
}
public TimestampHolder(Skill skill, long reuse, long stamp)
{
_skill = skill;
_reuse = reuse;
_stamp = stamp;
}
public long getStamp()
{
return _stamp;
}
public Skill getSkill()
{
return _skill;
}
public int getSkillId()
{
return _skill.getId();
}
public int getSkillLevel()
{
return _skill.getLevel();
}
public long getReuse()
{
return _reuse;
}
public long getRemaining()
{
return Math.max(_stamp - System.currentTimeMillis(), 0);
}
public boolean hasNotPassed()
{
return System.currentTimeMillis() < _stamp;
}
}

View File

@@ -17,21 +17,19 @@
package org.l2jmobius.gameserver.network.serverpackets; package org.l2jmobius.gameserver.network.serverpackets;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance; import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.holders.TimestampHolder;
public class SkillCoolTime extends GameServerPacket public class SkillCoolTime extends GameServerPacket
{ {
@SuppressWarnings("rawtypes") public Collection<TimestampHolder> _reuseTimestamps;
public Collection _reuseTimeStamps;
public SkillCoolTime(PlayerInstance player) public SkillCoolTime(PlayerInstance player)
{ {
_reuseTimeStamps = player.getReuseTimeStamps(); _reuseTimestamps = player.getReuseTimeStamps();
} }
@SuppressWarnings("rawtypes")
@Override @Override
protected final void writeImpl() protected final void writeImpl()
{ {
@@ -40,15 +38,14 @@ public class SkillCoolTime extends GameServerPacket
{ {
return; return;
} }
writeC(193); writeC(0xc1);
writeD(_reuseTimeStamps.size()); writeD(_reuseTimestamps.size());
PlayerInstance.TimeStamp ts; for (TimestampHolder reuseTimestamp : _reuseTimestamps)
for (Iterator i$ = _reuseTimeStamps.iterator(); i$.hasNext(); writeD((int) ts.getRemaining() / 1000))
{ {
ts = (PlayerInstance.TimeStamp) i$.next(); writeD(reuseTimestamp.getSkillId());
writeD(ts.getSkill().getId()); writeD(reuseTimestamp.getSkillLevel());
writeD(0); writeD((int) reuseTimestamp.getReuse() / 1000);
writeD((int) ts.getReuse() / 1000); writeD((int) reuseTimestamp.getRemaining() / 1000);
} }
} }
} }