浏览代码

BETA: Fixing issue with "over time" skills lasting longer than they should.
* Pre-implementation of proper tick system.

Reported by: Zoey76, nBd, blacksea

Zoey76 12 年之前
父节点
当前提交
6df013429c

+ 9 - 6
L2J_Server_BETA/java/com/l2jserver/gameserver/engines/DocumentBase.java

@@ -141,7 +141,7 @@ public abstract class DocumentBase
 	
 	public Document parse()
 	{
-		Document doc;
+		Document doc = null;
 		try
 		{
 			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@@ -153,7 +153,6 @@ public abstract class DocumentBase
 		catch (Exception e)
 		{
 			_log.log(Level.SEVERE, "Error loading file " + _file, e);
-			return null;
 		}
 		return doc;
 	}
@@ -291,10 +290,14 @@ public abstract class DocumentBase
 		final NamedNodeMap attrs = n.getAttributes();
 		final String name = getValue(attrs.getNamedItem("name").getNodeValue().intern(), template);
 		
-		int count = 1;
-		if (attrs.getNamedItem("count") != null)
+		int ticks = 1;
+		if (attrs.getNamedItem("count") != null) // TODO: Change to ticks when Datapack part is done.
 		{
-			count = Integer.decode(getValue(attrs.getNamedItem("count").getNodeValue(), template));
+			ticks = Integer.decode(getValue(attrs.getNamedItem("ticks").getNodeValue(), template));
+			if (ticks < 0)
+			{
+				ticks = Integer.MAX_VALUE; // -1 ticks means "infinite" time.
+			}
 		}
 		
 		int abnormalTime = 0;
@@ -411,7 +414,7 @@ public abstract class DocumentBase
 			throw new NoSuchElementException("Invalid chance condition: " + chanceCond + " " + activationChance);
 		}
 		
-		final EffectTemplate lt = new EffectTemplate(attachCond, applayCond, name, lambda, count, abnormalTime, abnormalVisualEffect, special, event, icon, effectPower, trigId, trigLvl, chance);
+		final EffectTemplate lt = new EffectTemplate(attachCond, applayCond, name, lambda, ticks, abnormalTime, abnormalVisualEffect, special, event, icon, effectPower, trigId, trigLvl, chance);
 		parseTemplate(n, lt);
 		if (template instanceof L2Item)
 		{

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java

@@ -8309,7 +8309,7 @@ public final class L2PcInstance extends L2Playable
 						statement.setInt(1, getObjectId());
 						statement.setInt(2, skill.getId());
 						statement.setInt(3, skill.getLevel());
-						statement.setInt(4, effect.getCount());
+						statement.setInt(4, effect.getTickCount());
 						statement.setInt(5, effect.getTime());
 						
 						if (_reuseTimeStampsSkills.containsKey(skill.getReuseHashCode()))

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PetInstance.java

@@ -1108,7 +1108,7 @@ public class L2PetInstance extends L2Summon
 						ps2.setInt(1, getControlObjectId());
 						ps2.setInt(2, skill.getId());
 						ps2.setInt(3, skill.getLevel());
-						ps2.setInt(4, effect.getCount());
+						ps2.setInt(4, effect.getTickCount());
 						ps2.setInt(5, effect.getTime());
 						ps2.setInt(6, ++buff_index);
 						ps2.execute();
@@ -1118,7 +1118,7 @@ public class L2PetInstance extends L2Summon
 							SummonEffectsTable.getInstance().getPetEffects().put(getControlObjectId(), new FastList<SummonEffect>());
 						}
 						
-						SummonEffectsTable.getInstance().getPetEffects().get(getControlObjectId()).add(SummonEffectsTable.getInstance().new SummonEffect(skill, effect.getCount(), effect.getTime()));
+						SummonEffectsTable.getInstance().getPetEffects().get(getControlObjectId()).add(SummonEffectsTable.getInstance().new SummonEffect(skill, effect.getTickCount(), effect.getTime()));
 					}
 				}
 			}

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2ServitorInstance.java

@@ -404,7 +404,7 @@ public class L2ServitorInstance extends L2Summon
 							ps2.setInt(3, getReferenceSkill());
 							ps2.setInt(4, skill.getId());
 							ps2.setInt(5, skill.getLevel());
-							ps2.setInt(6, effect.getCount());
+							ps2.setInt(6, effect.getTickCount());
 							ps2.setInt(7, effect.getTime());
 							ps2.setInt(8, ++buff_index);
 							ps2.execute();
@@ -422,7 +422,7 @@ public class L2ServitorInstance extends L2Summon
 								SummonEffectsTable.getInstance().getServitorEffects(getOwner()).put(getReferenceSkill(), new FastList<SummonEffect>());
 							}
 							
-							SummonEffectsTable.getInstance().getServitorEffects(getOwner()).get(getReferenceSkill()).add(SummonEffectsTable.getInstance().new SummonEffect(skill, effect.getCount(), effect.getTime()));
+							SummonEffectsTable.getInstance().getServitorEffects(getOwner()).get(getReferenceSkill()).add(SummonEffectsTable.getInstance().new SummonEffect(skill, effect.getTickCount(), effect.getTime()));
 						}
 					}
 				}

+ 5 - 5
L2J_Server_BETA/java/com/l2jserver/gameserver/model/effects/EffectTemplate.java

@@ -45,7 +45,7 @@ public class EffectTemplate
 	private final Condition _attachCond;
 	// private final Condition _applyCond; // TODO: Use or cleanup.
 	private final Lambda _lambda;
-	private final int _totalCount;
+	private final int _totalTickCount;
 	/** Custom abnormal time. */
 	private final int _customAbnormalTime;
 	private final AbnormalEffect _abnormalEffect;
@@ -59,12 +59,12 @@ public class EffectTemplate
 	private final int _triggeredLevel;
 	private final ChanceCondition _chanceCondition;
 	
-	public EffectTemplate(Condition attachCond, Condition applyCond, String func, Lambda lambda, int totalCount, int abnormalTime, AbnormalEffect abnormalEffect, AbnormalEffect[] specialEffect, AbnormalEffect eventEffect, boolean showIcon, double power, int trigId, int trigLvl, ChanceCondition chanceCond)
+	public EffectTemplate(Condition attachCond, Condition applyCond, String func, Lambda lambda, int totalTickCount, int abnormalTime, AbnormalEffect abnormalEffect, AbnormalEffect[] specialEffect, AbnormalEffect eventEffect, boolean showIcon, double power, int trigId, int trigLvl, ChanceCondition chanceCond)
 	{
 		_attachCond = attachCond;
 		// _applyCond = applyCond;
 		_lambda = lambda;
-		_totalCount = totalCount;
+		_totalTickCount = totalTickCount;
 		_customAbnormalTime = abnormalTime;
 		_abnormalEffect = abnormalEffect;
 		_specialEffect = specialEffect;
@@ -180,9 +180,9 @@ public class EffectTemplate
 		return _lambda;
 	}
 	
-	public int getTotalCount()
+	public int getTotalTickCount()
 	{
-		return _totalCount;
+		return _totalTickCount;
 	}
 	
 	public int getCustomAbnormalTime()

+ 20 - 20
L2J_Server_BETA/java/com/l2jserver/gameserver/model/effects/L2Effect.java

@@ -68,8 +68,8 @@ public abstract class L2Effect implements IChanceSkillTrigger
 	protected int _periodFirstTime;
 	/** The effect template. */
 	private final EffectTemplate _template;
-	/** Effect count. */
-	private int _count;
+	/** Effect tick count. */
+	private int _tickCount;
 	/** Effect's abnormal time. */
 	private final int _abnormalTime;
 	/** If {@code true} then it's a self-effect. */
@@ -112,7 +112,7 @@ public abstract class L2Effect implements IChanceSkillTrigger
 		_effected = env.getTarget();
 		_effector = env.getCharacter();
 		_lambda = template.getLambda();
-		_count = template.getTotalCount(); // Initial count is total count.
+		_tickCount = template.getTotalTickCount(); // Initial tick count is total tick count.
 		_abnormalTime = Formulas.calcEffectAbnormalTime(env, template);
 		_periodStartTicks = GameTimeController.getInstance().getGameTicks();
 		_periodFirstTime = 0;
@@ -132,25 +132,25 @@ public abstract class L2Effect implements IChanceSkillTrigger
 		_effected = env.getTarget();
 		_effector = env.getCharacter();
 		_lambda = _template.getLambda();
-		_count = effect.getCount();
+		_tickCount = effect.getTickCount();
 		_abnormalTime = effect.getAbnormalTime();
 		_periodStartTicks = effect.getPeriodStartTicks();
 		_periodFirstTime = effect.getTime();
 	}
 	
-	public int getCount()
+	public int getTickCount()
 	{
-		return _count;
+		return _tickCount;
 	}
 	
-	public int getTotalCount()
+	public int getTotalTickCount()
 	{
-		return _template.getTotalCount();
+		return _template.getTotalTickCount();
 	}
 	
-	public void setCount(int newcount)
+	public void setCount(int newTickCount)
 	{
-		_count = Math.min(newcount, _template.getTotalCount());
+		_tickCount = Math.min(newTickCount, _template.getTotalTickCount());
 	}
 	
 	public void setFirstTime(int newFirstTime)
@@ -186,11 +186,11 @@ public abstract class L2Effect implements IChanceSkillTrigger
 	 */
 	public int getTaskTime()
 	{
-		if (_count == _template.getTotalCount())
+		if (_tickCount == _template.getTotalTickCount())
 		{
 			return 0;
 		}
-		return Math.abs(((_count - _template.getTotalCount()) + 1) * _abnormalTime) + getTime() + 1;
+		return Math.abs(((_tickCount - _template.getTotalTickCount()) + 1) * _abnormalTime) + getTime() + 1;
 	}
 	
 	/**
@@ -267,7 +267,7 @@ public abstract class L2Effect implements IChanceSkillTrigger
 		{
 			stopEffectTask();
 			final int initialDelay = Math.max((_abnormalTime - _periodFirstTime) * 1000, 5);
-			if (_count > 1)
+			if (_tickCount > 1)
 			{
 				_currentFuture = ThreadPoolManager.getInstance().scheduleEffectAtFixedRate(new EffectTask(), initialDelay, _abnormalTime * 1000);
 			}
@@ -396,18 +396,18 @@ public abstract class L2Effect implements IChanceSkillTrigger
 			}
 			case ACTING:
 			{
-				if (_count > 0)
+				if (_tickCount > 0)
 				{
-					_count--;
+					_tickCount--;
 					if (isInUse())
 					{
 						// effect has to be in use
-						if (onActionTime() && _startConditionsCorrect && (_count >= 0))
+						if (onActionTime() && _startConditionsCorrect && (_tickCount >= 0))
 						{
 							return; // false causes effect to finish right away
 						}
 					}
-					else if (_count > 0)
+					else if (_tickCount > 0)
 					{
 						// do not finish it yet, in case reactivated
 						return;
@@ -418,7 +418,7 @@ public abstract class L2Effect implements IChanceSkillTrigger
 			case FINISHING:
 			{
 				// If the time left is equal to zero, send the message
-				if ((_count == 0) && isIconDisplay() && getEffected().isPlayer())
+				if ((_tickCount == 0) && isIconDisplay() && getEffected().isPlayer())
 				{
 					SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HAS_WORN_OFF);
 					sm.addSkillName(_skill);
@@ -435,7 +435,7 @@ public abstract class L2Effect implements IChanceSkillTrigger
 				stopEffectTask();
 				
 				// Cancel the effect in the the abnormal effect map of the L2Character
-				if (isInUse() || !((_count > 1) || (_abnormalTime > 0)))
+				if (isInUse() || !((_tickCount > 1) || (_abnormalTime > 0)))
 				{
 					if (_startConditionsCorrect)
 					{
@@ -489,7 +489,7 @@ public abstract class L2Effect implements IChanceSkillTrigger
 		
 		final ScheduledFuture<?> future = _currentFuture;
 		final L2Skill sk = getSkill();
-		if (_template.getTotalCount() > 1)
+		if (_template.getTotalTickCount() > 1)
 		{
 			if (sk.isStatic())
 			{

+ 7 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/stats/Formulas.java

@@ -2391,6 +2391,12 @@ public final class Formulas
 	 */
 	public static int calcEffectAbnormalTime(Env env, EffectTemplate template)
 	{
+		// TODO: Uncomment when ticks Datapack part is done.
+		// if (template.getTotalTickCount() > 1)
+		// {
+		// return template.getTotalTickCount();
+		// }
+		
 		final L2Skill skill = env.getSkill();
 		final L2Character effected = env.getTarget();
 		int time = (template.getCustomAbnormalTime() != 0) || (skill == null) ? template.getCustomAbnormalTime() : !skill.isPassive() ? skill.getAbnormalTime() : -1;
@@ -2407,6 +2413,6 @@ public final class Formulas
 		{
 			time *= 2;
 		}
-		return time;
+		return time / template.getTotalTickCount(); // TODO: Replace with return time; when ticks Datapack part is done.
 	}
 }