Sfoglia il codice sorgente

fix(ticks): Made game ticks usage relative to ticks per second

Noe Caratini 2 anni fa
parent
commit
06b41fe650

+ 4 - 2
src/main/java/com/l2jserver/gameserver/GameTimeController.java

@@ -42,6 +42,8 @@ public final class GameTimeController extends Thread {
 	public static final int SECONDS_PER_IG_DAY = MILLIS_PER_IG_DAY / 1000;
 	public static final int MINUTES_PER_IG_DAY = SECONDS_PER_IG_DAY / 60;
 	public static final int TICKS_PER_IG_DAY = SECONDS_PER_IG_DAY * TICKS_PER_SECOND;
+	public static final int TICKS_PER_IG_HOUR = TICKS_PER_IG_DAY / 24;
+	public static final int TICKS_PER_IG_MINUTE = TICKS_PER_IG_HOUR / 60;
 	public static final int TICKS_SUN_STATE_CHANGE = TICKS_PER_IG_DAY / 4;
 	
 	private static GameTimeController _instance;
@@ -69,7 +71,7 @@ public final class GameTimeController extends Thread {
 	}
 	
 	public int getGameTime() {
-		return (getGameTicks() % TICKS_PER_IG_DAY) / MILLIS_IN_TICK;
+		return (getGameTicks() % TICKS_PER_IG_DAY) / TICKS_PER_IG_MINUTE;
 	}
 	
 	public int getGameHour() {
@@ -136,7 +138,7 @@ public final class GameTimeController extends Thread {
 		}
 		
 		while (true) {
-			nextTickTime = ((System.currentTimeMillis() / MILLIS_IN_TICK) * MILLIS_IN_TICK) + 100;
+			nextTickTime = System.currentTimeMillis() + MILLIS_IN_TICK;
 			
 			try {
 				moveObjects();

+ 5 - 4
src/main/java/com/l2jserver/gameserver/ai/L2AttackableAI.java

@@ -104,7 +104,7 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable {
 	protected static final int FEAR_TICKS = 5;
 	private static final int RANDOM_WALK_RATE = 30; // confirmed
 	// private static final int MAX_DRIFT_RANGE = 300;
-	private static final int MAX_ATTACK_TIMEOUT = 1200; // int ticks, i.e. 2min
+	private static final int MAX_ATTACK_TIMEOUT = 120 * GameTimeController.TICKS_PER_SECOND; // int ticks, i.e. 2min
 	/** The L2Attackable AI task executed every 1s (call onEvtThink method). */
 	private Future<?> _aiTask;
 	/** The delay after which the attacked is stopped. */
@@ -356,10 +356,11 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable {
 	@Override
 	protected void onIntentionAttack(L2Character target) {
 		// Calculate the attack timeout
-		_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getInstance().getGameTicks();
+		final int currentTick = GameTimeController.getInstance().getGameTicks();
+		_attackTimeout = MAX_ATTACK_TIMEOUT + currentTick;
 		
 		// self and buffs
-		if ((_lastBuffTick + 30) < GameTimeController.getInstance().getGameTicks()) {
+		if ((_lastBuffTick + 3 * GameTimeController.TICKS_PER_SECOND) < currentTick) {
 			for (Skill buff : getActiveChar().getTemplate().getAISkills(AISkillScope.BUFF)) {
 				if (checkSkillCastConditions(getActiveChar(), buff)) {
 					if (!_actor.isAffectedBySkill(buff.getId())) {
@@ -371,7 +372,7 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable {
 					}
 				}
 			}
-			_lastBuffTick = GameTimeController.getInstance().getGameTicks();
+			_lastBuffTick = currentTick;
 		}
 		
 		// Manage the Attack Intention : Stop current Attack (if necessary), Start a new Attack and Launch Think Event

+ 1 - 1
src/main/java/com/l2jserver/gameserver/ai/L2FortSiegeGuardAI.java

@@ -48,7 +48,7 @@ import com.l2jserver.gameserver.util.Util;
  * Fort siege guards AI.
  */
 public class L2FortSiegeGuardAI extends L2CharacterAI implements Runnable {
-	private static final int MAX_ATTACK_TIMEOUT = 300; // int ticks, i.e. 30 seconds
+	private static final int MAX_ATTACK_TIMEOUT = 30 * GameTimeController.TICKS_PER_SECOND; // 30s converted to ticks
 	
 	/** The L2Attackable AI task executed every 1s (call onEvtThink method) */
 	private Future<?> _aiTask;

+ 1 - 1
src/main/java/com/l2jserver/gameserver/ai/L2SiegeGuardAI.java

@@ -47,7 +47,7 @@ import com.l2jserver.gameserver.util.Util;
  * Siege guard AI.
  */
 public class L2SiegeGuardAI extends L2CharacterAI implements Runnable {
-	private static final int MAX_ATTACK_TIMEOUT = 300; // int ticks, i.e. 30 seconds
+	private static final int MAX_ATTACK_TIMEOUT = 30 * GameTimeController.TICKS_PER_SECOND; // 30s converted to ticks
 	
 	/** The L2Attackable AI task executed every 1s (call onEvtThink method) */
 	private Future<?> _aiTask;

+ 4 - 2
src/main/java/com/l2jserver/gameserver/model/actor/L2Character.java

@@ -1514,7 +1514,9 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
 			setLastSimultaneousSkillCast(skill);
 		} else {
 			setIsCastingNow(true);
-			_castInterruptTime = -2 + GameTimeController.getInstance().getGameTicks() + ((int) skillAnimTime / GameTimeController.MILLIS_IN_TICK);
+			_castInterruptTime = (-200 / GameTimeController.MILLIS_IN_TICK) // 200ms converted to ticks
+					+ GameTimeController.getInstance().getGameTicks()
+					+ ((int) skillAnimTime / GameTimeController.MILLIS_IN_TICK);
 			setLastSkillCast(skill);
 		}
 		
@@ -5033,7 +5035,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
 	public final void forceIsCasting(int newSkillCastEndTick) {
 		setIsCastingNow(true);
 		// for interrupt -400 ms
-		_castInterruptTime = newSkillCastEndTick - 4;
+		_castInterruptTime = newSkillCastEndTick - (400 / GameTimeController.MILLIS_IN_TICK);
 	}
 	
 	private boolean _AIdisabled = false;

+ 2 - 2
src/main/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java

@@ -5298,8 +5298,8 @@ public final class L2PcInstance extends L2Playable {
 				arrows.changeCountWithoutTrace(-1, this, null);
 				arrows.setLastChange(L2ItemInstance.MODIFIED);
 				
-				// could do also without saving, but let's save approx 1 of 10
-				if ((GameTimeController.getInstance().getGameTicks() % 10) == 0) {
+				// could do also without saving, but let's save approx once per second
+				if ((GameTimeController.getInstance().getGameTicks() % GameTimeController.TICKS_PER_SECOND) == 0) {
 					arrows.updateDatabase();
 				}
 				_inventory.refreshWeight();

+ 3 - 3
src/main/java/com/l2jserver/gameserver/model/itemcontainer/ItemContainer.java

@@ -211,7 +211,7 @@ public abstract class ItemContainer {
 			float adenaRate = rates().getDropAmountMultiplierByItemId().getOrDefault(Inventory.ADENA_ID, 1f);
 			if ((item.getId() == Inventory.ADENA_ID) && (count < (10000 * adenaRate))) {
 				// Small adena changes won't be saved to database all the time
-				if ((GameTimeController.getInstance().getGameTicks() % 5) == 0) {
+				if ((GameTimeController.getInstance().getGameTicks() % (GameTimeController.TICKS_PER_SECOND / 2)) == 0) {
 					item.updateDatabase();
 				}
 			} else {
@@ -285,7 +285,7 @@ public abstract class ItemContainer {
 			float adenaRate = rates().getDropAmountMultiplierByItemId().getOrDefault(Inventory.ADENA_ID, 1f);
 			if ((itemId == Inventory.ADENA_ID) && (count < (10000 * adenaRate))) {
 				// Small adena changes won't be saved to database all the time
-				if ((GameTimeController.getInstance().getGameTicks() % 5) == 0) {
+				if ((GameTimeController.getInstance().getGameTicks() % (GameTimeController.TICKS_PER_SECOND / 2)) == 0) {
 					item.updateDatabase();
 				}
 			} else {
@@ -424,7 +424,7 @@ public abstract class ItemContainer {
 				item.setLastChange(L2ItemInstance.MODIFIED);
 				
 				// don't update often for untraced items
-				if ((process != null) || ((GameTimeController.getInstance().getGameTicks() % 10) == 0)) {
+				if ((process != null) || ((GameTimeController.getInstance().getGameTicks() % GameTimeController.TICKS_PER_SECOND) == 0)) {
 					item.updateDatabase();
 				}