Reworked GameTime task manager.
This commit is contained in:
parent
beb1aa0b77
commit
b4b76176de
@ -175,7 +175,6 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("HealOverTime", HealOverTime::new);
|
||||
EffectHandler.getInstance().registerHandler("HealPercent", HealPercent::new);
|
||||
EffectHandler.getInstance().registerHandler("Hide", Hide::new);
|
||||
EffectHandler.getInstance().registerHandler("HitAtNight", HitAtNight::new);
|
||||
EffectHandler.getInstance().registerHandler("HitNumber", HitNumber::new);
|
||||
EffectHandler.getInstance().registerHandler("Hp", Hp::new);
|
||||
EffectHandler.getInstance().registerHandler("HpByLevel", HpByLevel::new);
|
||||
@ -333,6 +332,7 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("SpModify", SpModify::new);
|
||||
EffectHandler.getInstance().registerHandler("Spoil", Spoil::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForLevel", StatAddForLevel::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForNight", StatAddForNight::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSkillCritical", StatBonusSkillCritical::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSpeed", StatBonusSpeed::new);
|
||||
EffectHandler.getInstance().registerHandler("StatByMoveType", StatByMoveType::new);
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class HitAtNight extends AbstractStatEffect
|
||||
{
|
||||
public HitAtNight(StatSet params)
|
||||
{
|
||||
super(params, Stat.HIT_AT_NIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().addShadowSenseCharacter(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().removeShadowSenseCharacter(effected);
|
||||
}
|
||||
}
|
130
L2J_Mobius_01.0_Ertheia/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
130
L2J_Mobius_01.0_Ertheia/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.l2jmobius.gameserver.enums.StatModifierType;
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
|
||||
import org.l2jmobius.gameserver.model.events.Containers;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.ListenersContainer;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class StatAddForNight extends AbstractEffect
|
||||
{
|
||||
private static final AtomicBoolean DAY_TIME = new AtomicBoolean(GameTimeTaskManager.getInstance().isNight());
|
||||
private static final Set<Creature> NIGHT_STAT_CHARACTERS = ConcurrentHashMap.newKeySet();
|
||||
private static final int SHADOW_SENSE = 294;
|
||||
|
||||
private final Stat _stat;
|
||||
private final int _amount;
|
||||
protected final StatModifierType _mode;
|
||||
|
||||
public StatAddForNight(StatSet params)
|
||||
{
|
||||
_stat = params.getEnum("stat", Stat.class);
|
||||
_amount = params.getInt("amount");
|
||||
_mode = params.getEnum("mode", StatModifierType.class, StatModifierType.DIFF);
|
||||
|
||||
// Init a global day-night change listener.
|
||||
final ListenersContainer container = Containers.Global();
|
||||
container.addListener(new ConsumerEventListener(container, EventType.ON_DAY_NIGHT_CHANGE, (OnDayNightChange event) -> onDayNightChange(event), this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.add(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.remove(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pump(Creature effected, Skill skill)
|
||||
{
|
||||
// Not night.
|
||||
if (!GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply stat.
|
||||
switch (_mode)
|
||||
{
|
||||
case DIFF:
|
||||
{
|
||||
effected.getStat().mergeAdd(_stat, _amount);
|
||||
break;
|
||||
}
|
||||
case PER:
|
||||
{
|
||||
effected.getStat().mergeMul(_stat, (_amount / 100) + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDayNightChange(OnDayNightChange event)
|
||||
{
|
||||
synchronized (DAY_TIME)
|
||||
{
|
||||
final boolean isNight = event.isNight();
|
||||
|
||||
// Run only once per daytime change.
|
||||
if (isNight == DAY_TIME.get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
DAY_TIME.set(isNight);
|
||||
|
||||
// System message for Shadow Sense.
|
||||
final SystemMessage msg = new SystemMessage(isNight ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE);
|
||||
|
||||
for (Creature creature : NIGHT_STAT_CHARACTERS)
|
||||
{
|
||||
// Pump again.
|
||||
creature.getStat().recalculateStats(true);
|
||||
|
||||
// Send Shadow Sense message when player has skill.
|
||||
if (creature.getKnownSkill(SHADOW_SENSE) != null)
|
||||
{
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6458,9 +6458,9 @@
|
||||
<operateType>P</operateType>
|
||||
<magicCriticalRate>5</magicCriticalRate>
|
||||
<effects>
|
||||
<effect name="HitAtNight">
|
||||
<effect name="StatAddForNight">
|
||||
<stat>ACCURACY_COMBAT</stat>
|
||||
<amount>3</amount>
|
||||
<mode>DIFF</mode>
|
||||
</effect>
|
||||
</effects>
|
||||
</skill>
|
||||
|
@ -146,7 +146,6 @@ Heal: Increases current HP by a given amount.
|
||||
HealOverTime: Increases current HP by a given amount over time.
|
||||
HealPercent: Increases current HP by a given percentage amount.
|
||||
Hide: Hide effect.
|
||||
HitAtNight: Used by Shadow Sense to modify Accuracy at night. (l2jmobius)
|
||||
HitNumber: Polearm attack max hit creatures.
|
||||
HpByLevel: recovers certain amount of HP, but current implementation is wrong... final amount should be computed from skill power and character level difference
|
||||
HpCpHealCritical: HpCp heal effects always trigger Magic Critical Hit.
|
||||
@ -302,6 +301,7 @@ SpeedLimit: Increase a character's max Speed limit. (l2jmobius)
|
||||
SpModify: Bonus SP stat.
|
||||
Spoil: Spoils a mob activating its extra sweep drop.
|
||||
StatAddForLevel: Adds a fixed amount of a Stat for a specific player level. (l2jmobius)
|
||||
StatAddForNight: Modify a specific stat at night time. (l2jmobius)
|
||||
StatBonusSkillCritical: Changes skill critical rate to depend on the specified base stat.
|
||||
StatBonusSpeed: Changes Speed stat to depend on the specified base stat.
|
||||
StatByMoveType: Adds stat based on your movement type (standing, running, walking).
|
||||
|
@ -208,6 +208,9 @@ public class GameServer
|
||||
printSection("ThreadPool");
|
||||
ThreadPool.init();
|
||||
|
||||
// Start game time task manager early
|
||||
GameTimeTaskManager.getInstance();
|
||||
|
||||
printSection("IdManager");
|
||||
IdManager.getInstance();
|
||||
if (!IdManager.hasInitialized())
|
||||
@ -216,7 +219,6 @@ public class GameServer
|
||||
throw new Exception("Could not initialize the ID factory!");
|
||||
}
|
||||
|
||||
// load script engines
|
||||
printSection("Scripting Engine");
|
||||
EventDispatcher.getInstance();
|
||||
ScriptEngineManager.getInstance();
|
||||
@ -225,8 +227,6 @@ public class GameServer
|
||||
TelnetServer.getInstance();
|
||||
|
||||
printSection("World");
|
||||
// Start game time task manager early.
|
||||
GameTimeTaskManager.getInstance();
|
||||
World.getInstance();
|
||||
MapRegionManager.getInstance();
|
||||
ZoneManager.getInstance();
|
||||
|
@ -48,6 +48,7 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
|
||||
/**
|
||||
@ -144,10 +145,21 @@ public class Shutdown extends Thread
|
||||
}
|
||||
|
||||
// ensure all services are stopped
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().stopTimer();
|
||||
LOGGER.info("Game Time Controller: Timer stopped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
MovementTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Game Time Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
@ -166,6 +166,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
|
||||
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.CreatureSeeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
@ -2772,7 +2773,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
case MAGIC_ATTACK:
|
||||
case MAGIC_ATTACK_SPEED:
|
||||
case MAGICAL_DEFENCE:
|
||||
case HIT_AT_NIGHT:
|
||||
{
|
||||
info.addComponentType(UserInfoType.STATS);
|
||||
break;
|
||||
@ -3600,9 +3600,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the MovementTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
@ -3679,9 +3679,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the GameTimeTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
|
@ -41,6 +41,7 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
/**
|
||||
@ -165,7 +166,7 @@ public abstract class Vehicle extends Creature
|
||||
|
||||
m._moveStartTime = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
_move = m;
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Make sure vehicle is not stuck.
|
||||
if (_monitorTask == null)
|
||||
|
@ -42,7 +42,7 @@ public class WarnUserTakeBreakTask implements Runnable
|
||||
{
|
||||
if (_player.isOnline())
|
||||
{
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime());
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime() + 60000);
|
||||
_player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_PLAYED_FOR_S1_HOUR_S_PLEASE_TAKE_A_BREAK).addLong(hours));
|
||||
}
|
||||
else
|
||||
|
@ -161,7 +161,6 @@ public enum Stat
|
||||
MAGIC_ATTACK_RANGE("mAtkRange"),
|
||||
ATTACK_COUNT_MAX("atkCountMax"),
|
||||
PHYSICAL_POLEARM_TARGET_SINGLE("polearmSingleTarget"),
|
||||
HIT_AT_NIGHT("hitAtNight"),
|
||||
|
||||
// Run speed, walk & escape speed are calculated proportionally, magic speed is a buff
|
||||
MOVE_SPEED("moveSpeed"),
|
||||
|
@ -22,7 +22,6 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.ItemTemplate;
|
||||
import org.l2jmobius.gameserver.model.stats.IStatFunction;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
@ -70,12 +69,6 @@ public class PAccuracyFinalizer implements IStatFunction
|
||||
baseValue += calcEnchantBodyPart(creature, ItemTemplate.SLOT_GLOVES);
|
||||
}
|
||||
|
||||
// Shadow sense
|
||||
if (GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
baseValue += creature.getStat().getAdd(Stat.HIT_AT_NIGHT, 0);
|
||||
}
|
||||
|
||||
return Stat.defaultValue(creature, stat, baseValue);
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@ public class ClientSetTime implements IClientOutgoingPacket
|
||||
public boolean write(PacketWriter packet)
|
||||
{
|
||||
OutgoingPackets.CLIENT_SET_TIME.writeId(packet);
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // time in client minutes
|
||||
packet.writeD(6); // constant to match the server time( this determines the speed of the client clock)
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // Time in client minutes.
|
||||
packet.writeD(GameTimeTaskManager.IG_DAYS_PER_DAY); // Constant to match the server time. This determines the speed of the client clock.
|
||||
return true;
|
||||
}
|
||||
}
|
@ -17,42 +17,35 @@
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
/**
|
||||
* Game Time task manager class.
|
||||
* @author Forsaiken
|
||||
* GameTime task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(GameTimeTaskManager.class.getName());
|
||||
|
||||
public static final int TICKS_PER_SECOND = 10; // not able to change this without checking through code
|
||||
public static final int TICKS_PER_SECOND = 10; // Not able to change this without checking through code.
|
||||
public static final int MILLIS_IN_TICK = 1000 / TICKS_PER_SECOND;
|
||||
public static final int IG_DAYS_PER_DAY = 6;
|
||||
public static final int MILLIS_PER_IG_DAY = (3600000 * 24) / IG_DAYS_PER_DAY;
|
||||
public static final int SECONDS_PER_IG_DAY = MILLIS_PER_IG_DAY / 1000;
|
||||
public static final int TICKS_PER_IG_DAY = SECONDS_PER_IG_DAY * TICKS_PER_SECOND;
|
||||
private static final int SHADOW_SENSE_ID = 294;
|
||||
|
||||
private static final Set<Creature> _movingObjects = ConcurrentHashMap.newKeySet();
|
||||
private static final Set<Creature> _shadowSenseCharacters = ConcurrentHashMap.newKeySet();
|
||||
private final long _referenceTime;
|
||||
private boolean _isNight;
|
||||
|
||||
protected GameTimeTaskManager()
|
||||
{
|
||||
super("GameTimeTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.setPriority(NORM_PRIORITY);
|
||||
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||
@ -64,6 +57,41 @@ public class GameTimeTaskManager extends Thread
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if ((getGameHour() < 6) != _isNight)
|
||||
{
|
||||
_isNight = !_isNight;
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(_isNight));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
{
|
||||
return _isNight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actual GameTime tick. Directly taken from current time.
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
public int getGameTime()
|
||||
{
|
||||
return (getGameTicks() % TICKS_PER_IG_DAY) / MILLIS_IN_TICK;
|
||||
@ -79,134 +107,6 @@ public class GameTimeTaskManager extends Thread
|
||||
return getGameTime() % 60;
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
{
|
||||
return getGameHour() < 6;
|
||||
}
|
||||
|
||||
/**
|
||||
* The true GameTime tick. Directly taken from current time. This represents the tick of the time.
|
||||
* @return
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to movingObjects of GameTimeTaskManager.
|
||||
* @param creature The Creature to add to movingObjects of GameTimeTaskManager
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_movingObjects.add(creature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move all Creatures contained in movingObjects of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Concept</u>:</b><br>
|
||||
* <br>
|
||||
* All Creature in movement are identified in <b>movingObjects</b> of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Actions</u>:</b><br>
|
||||
* <ul>
|
||||
* <li>Update the position of each Creature</li>
|
||||
* <li>If movement is finished, the Creature is removed from movingObjects</li>
|
||||
* <li>Create a task to update the _knownObject and _knowPlayers of each Creature that finished its movement and of their already known WorldObject then notify AI with EVT_ARRIVED</li>
|
||||
* </ul>
|
||||
*/
|
||||
private void moveObjects()
|
||||
{
|
||||
_movingObjects.removeIf(Creature::updatePosition);
|
||||
}
|
||||
|
||||
public void stopTimer()
|
||||
{
|
||||
super.interrupt();
|
||||
LOGGER.info(getClass().getSimpleName() + ": Stopped.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
LOGGER.info(getClass().getSimpleName() + ": Started.");
|
||||
|
||||
long nextTickTime;
|
||||
long sleepTime;
|
||||
boolean isNight = isNight();
|
||||
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(isNight));
|
||||
|
||||
while (true)
|
||||
{
|
||||
nextTickTime = ((System.currentTimeMillis() / MILLIS_IN_TICK) * MILLIS_IN_TICK) + 100;
|
||||
|
||||
try
|
||||
{
|
||||
moveObjects();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
|
||||
sleepTime = nextTickTime - System.currentTimeMillis();
|
||||
if (sleepTime > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(sleepTime);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (isNight() != isNight)
|
||||
{
|
||||
isNight = !isNight;
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(isNight));
|
||||
notifyShadowSense();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addShadowSenseCharacter(Creature creature)
|
||||
{
|
||||
if (!_shadowSenseCharacters.contains(creature))
|
||||
{
|
||||
_shadowSenseCharacters.add(creature);
|
||||
if (isNight())
|
||||
{
|
||||
final SystemMessage msg = new SystemMessage(SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT);
|
||||
msg.addSkillName(SHADOW_SENSE_ID);
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeShadowSenseCharacter(Creature creature)
|
||||
{
|
||||
_shadowSenseCharacters.remove(creature);
|
||||
}
|
||||
|
||||
private void notifyShadowSense()
|
||||
{
|
||||
final SystemMessage msg = new SystemMessage(isNight() ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE_ID);
|
||||
for (Creature creature : _shadowSenseCharacters)
|
||||
{
|
||||
creature.getStat().recalculateStats(true);
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static final GameTimeTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
@ -216,4 +116,4 @@ public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
protected static final GameTimeTaskManager INSTANCE = new GameTimeTaskManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.taskmanager;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
|
||||
/**
|
||||
* Movement task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class MovementTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(MovementTaskManager.class.getName());
|
||||
|
||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
||||
|
||||
protected MovementTaskManager()
|
||||
{
|
||||
super("MovementTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to moving objects of MovementTaskManager.
|
||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MOVING_OBJECTS.add(creature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final MovementTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final MovementTaskManager INSTANCE = new MovementTaskManager();
|
||||
}
|
||||
}
|
@ -175,7 +175,6 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("HealOverTime", HealOverTime::new);
|
||||
EffectHandler.getInstance().registerHandler("HealPercent", HealPercent::new);
|
||||
EffectHandler.getInstance().registerHandler("Hide", Hide::new);
|
||||
EffectHandler.getInstance().registerHandler("HitAtNight", HitAtNight::new);
|
||||
EffectHandler.getInstance().registerHandler("HitNumber", HitNumber::new);
|
||||
EffectHandler.getInstance().registerHandler("Hp", Hp::new);
|
||||
EffectHandler.getInstance().registerHandler("HpByLevel", HpByLevel::new);
|
||||
@ -333,6 +332,7 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("SpModify", SpModify::new);
|
||||
EffectHandler.getInstance().registerHandler("Spoil", Spoil::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForLevel", StatAddForLevel::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForNight", StatAddForNight::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSkillCritical", StatBonusSkillCritical::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSpeed", StatBonusSpeed::new);
|
||||
EffectHandler.getInstance().registerHandler("StatByMoveType", StatByMoveType::new);
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class HitAtNight extends AbstractStatEffect
|
||||
{
|
||||
public HitAtNight(StatSet params)
|
||||
{
|
||||
super(params, Stat.HIT_AT_NIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().addShadowSenseCharacter(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().removeShadowSenseCharacter(effected);
|
||||
}
|
||||
}
|
130
L2J_Mobius_02.5_Underground/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
130
L2J_Mobius_02.5_Underground/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.l2jmobius.gameserver.enums.StatModifierType;
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
|
||||
import org.l2jmobius.gameserver.model.events.Containers;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.ListenersContainer;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class StatAddForNight extends AbstractEffect
|
||||
{
|
||||
private static final AtomicBoolean DAY_TIME = new AtomicBoolean(GameTimeTaskManager.getInstance().isNight());
|
||||
private static final Set<Creature> NIGHT_STAT_CHARACTERS = ConcurrentHashMap.newKeySet();
|
||||
private static final int SHADOW_SENSE = 294;
|
||||
|
||||
private final Stat _stat;
|
||||
private final int _amount;
|
||||
protected final StatModifierType _mode;
|
||||
|
||||
public StatAddForNight(StatSet params)
|
||||
{
|
||||
_stat = params.getEnum("stat", Stat.class);
|
||||
_amount = params.getInt("amount");
|
||||
_mode = params.getEnum("mode", StatModifierType.class, StatModifierType.DIFF);
|
||||
|
||||
// Init a global day-night change listener.
|
||||
final ListenersContainer container = Containers.Global();
|
||||
container.addListener(new ConsumerEventListener(container, EventType.ON_DAY_NIGHT_CHANGE, (OnDayNightChange event) -> onDayNightChange(event), this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.add(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.remove(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pump(Creature effected, Skill skill)
|
||||
{
|
||||
// Not night.
|
||||
if (!GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply stat.
|
||||
switch (_mode)
|
||||
{
|
||||
case DIFF:
|
||||
{
|
||||
effected.getStat().mergeAdd(_stat, _amount);
|
||||
break;
|
||||
}
|
||||
case PER:
|
||||
{
|
||||
effected.getStat().mergeMul(_stat, (_amount / 100) + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDayNightChange(OnDayNightChange event)
|
||||
{
|
||||
synchronized (DAY_TIME)
|
||||
{
|
||||
final boolean isNight = event.isNight();
|
||||
|
||||
// Run only once per daytime change.
|
||||
if (isNight == DAY_TIME.get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
DAY_TIME.set(isNight);
|
||||
|
||||
// System message for Shadow Sense.
|
||||
final SystemMessage msg = new SystemMessage(isNight ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE);
|
||||
|
||||
for (Creature creature : NIGHT_STAT_CHARACTERS)
|
||||
{
|
||||
// Pump again.
|
||||
creature.getStat().recalculateStats(true);
|
||||
|
||||
// Send Shadow Sense message when player has skill.
|
||||
if (creature.getKnownSkill(SHADOW_SENSE) != null)
|
||||
{
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6456,9 +6456,9 @@
|
||||
<operateType>P</operateType>
|
||||
<magicCriticalRate>5</magicCriticalRate>
|
||||
<effects>
|
||||
<effect name="HitAtNight">
|
||||
<effect name="StatAddForNight">
|
||||
<stat>ACCURACY_COMBAT</stat>
|
||||
<amount>3</amount>
|
||||
<mode>DIFF</mode>
|
||||
</effect>
|
||||
</effects>
|
||||
</skill>
|
||||
|
@ -146,7 +146,6 @@ Heal: Increases current HP by a given amount.
|
||||
HealOverTime: Increases current HP by a given amount over time.
|
||||
HealPercent: Increases current HP by a given percentage amount.
|
||||
Hide: Hide effect.
|
||||
HitAtNight: Used by Shadow Sense to modify Accuracy at night. (l2jmobius)
|
||||
HitNumber: Polearm attack max hit creatures.
|
||||
HpByLevel: recovers certain amount of HP, but current implementation is wrong... final amount should be computed from skill power and character level difference
|
||||
HpCpHealCritical: HpCp heal effects always trigger Magic Critical Hit.
|
||||
@ -302,6 +301,7 @@ SpeedLimit: Increase a character's max Speed limit. (l2jmobius)
|
||||
SpModify: Bonus SP stat.
|
||||
Spoil: Spoils a mob activating its extra sweep drop.
|
||||
StatAddForLevel: Adds a fixed amount of a Stat for a specific player level. (l2jmobius)
|
||||
StatAddForNight: Modify a specific stat at night time. (l2jmobius)
|
||||
StatBonusSkillCritical: Changes skill critical rate to depend on the specified base stat.
|
||||
StatBonusSpeed: Changes Speed stat to depend on the specified base stat.
|
||||
StatByMoveType: Adds stat based on your movement type (standing, running, walking).
|
||||
|
@ -212,6 +212,9 @@ public class GameServer
|
||||
printSection("ThreadPool");
|
||||
ThreadPool.init();
|
||||
|
||||
// Start game time task manager early
|
||||
GameTimeTaskManager.getInstance();
|
||||
|
||||
printSection("IdManager");
|
||||
IdManager.getInstance();
|
||||
if (!IdManager.hasInitialized())
|
||||
@ -220,7 +223,6 @@ public class GameServer
|
||||
throw new Exception("Could not initialize the ID factory!");
|
||||
}
|
||||
|
||||
// load script engines
|
||||
printSection("Scripting Engine");
|
||||
EventDispatcher.getInstance();
|
||||
ScriptEngineManager.getInstance();
|
||||
@ -229,8 +231,6 @@ public class GameServer
|
||||
TelnetServer.getInstance();
|
||||
|
||||
printSection("World");
|
||||
// Start game time task manager early.
|
||||
GameTimeTaskManager.getInstance();
|
||||
World.getInstance();
|
||||
MapRegionManager.getInstance();
|
||||
ZoneManager.getInstance();
|
||||
|
@ -48,6 +48,7 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
|
||||
/**
|
||||
@ -144,10 +145,21 @@ public class Shutdown extends Thread
|
||||
}
|
||||
|
||||
// ensure all services are stopped
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().stopTimer();
|
||||
LOGGER.info("Game Time Controller: Timer stopped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
MovementTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Game Time Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
@ -166,6 +166,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
|
||||
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.CreatureSeeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
@ -2772,7 +2773,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
case MAGIC_ATTACK:
|
||||
case MAGIC_ATTACK_SPEED:
|
||||
case MAGICAL_DEFENCE:
|
||||
case HIT_AT_NIGHT:
|
||||
{
|
||||
info.addComponentType(UserInfoType.STATS);
|
||||
break;
|
||||
@ -3600,9 +3600,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the MovementTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
@ -3679,9 +3679,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the GameTimeTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
|
@ -41,6 +41,7 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
/**
|
||||
@ -165,7 +166,7 @@ public abstract class Vehicle extends Creature
|
||||
|
||||
m._moveStartTime = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
_move = m;
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Make sure vehicle is not stuck.
|
||||
if (_monitorTask == null)
|
||||
|
@ -42,7 +42,7 @@ public class WarnUserTakeBreakTask implements Runnable
|
||||
{
|
||||
if (_player.isOnline())
|
||||
{
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime());
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime() + 60000);
|
||||
_player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_PLAYED_FOR_S1_HOUR_S_PLEASE_TAKE_A_BREAK).addLong(hours));
|
||||
}
|
||||
else
|
||||
|
@ -161,7 +161,6 @@ public enum Stat
|
||||
MAGIC_ATTACK_RANGE("mAtkRange"),
|
||||
ATTACK_COUNT_MAX("atkCountMax"),
|
||||
PHYSICAL_POLEARM_TARGET_SINGLE("polearmSingleTarget"),
|
||||
HIT_AT_NIGHT("hitAtNight"),
|
||||
|
||||
// Run speed, walk & escape speed are calculated proportionally, magic speed is a buff
|
||||
MOVE_SPEED("moveSpeed"),
|
||||
|
@ -22,7 +22,6 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.ItemTemplate;
|
||||
import org.l2jmobius.gameserver.model.stats.IStatFunction;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
@ -70,12 +69,6 @@ public class PAccuracyFinalizer implements IStatFunction
|
||||
baseValue += calcEnchantBodyPart(creature, ItemTemplate.SLOT_GLOVES);
|
||||
}
|
||||
|
||||
// Shadow sense
|
||||
if (GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
baseValue += creature.getStat().getAdd(Stat.HIT_AT_NIGHT, 0);
|
||||
}
|
||||
|
||||
return Stat.defaultValue(creature, stat, baseValue);
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@ public class ClientSetTime implements IClientOutgoingPacket
|
||||
public boolean write(PacketWriter packet)
|
||||
{
|
||||
OutgoingPackets.CLIENT_SET_TIME.writeId(packet);
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // time in client minutes
|
||||
packet.writeD(6); // constant to match the server time( this determines the speed of the client clock)
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // Time in client minutes.
|
||||
packet.writeD(GameTimeTaskManager.IG_DAYS_PER_DAY); // Constant to match the server time. This determines the speed of the client clock.
|
||||
return true;
|
||||
}
|
||||
}
|
@ -17,42 +17,35 @@
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
/**
|
||||
* Game Time task manager class.
|
||||
* @author Forsaiken
|
||||
* GameTime task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(GameTimeTaskManager.class.getName());
|
||||
|
||||
public static final int TICKS_PER_SECOND = 10; // not able to change this without checking through code
|
||||
public static final int TICKS_PER_SECOND = 10; // Not able to change this without checking through code.
|
||||
public static final int MILLIS_IN_TICK = 1000 / TICKS_PER_SECOND;
|
||||
public static final int IG_DAYS_PER_DAY = 6;
|
||||
public static final int MILLIS_PER_IG_DAY = (3600000 * 24) / IG_DAYS_PER_DAY;
|
||||
public static final int SECONDS_PER_IG_DAY = MILLIS_PER_IG_DAY / 1000;
|
||||
public static final int TICKS_PER_IG_DAY = SECONDS_PER_IG_DAY * TICKS_PER_SECOND;
|
||||
private static final int SHADOW_SENSE_ID = 294;
|
||||
|
||||
private static final Set<Creature> _movingObjects = ConcurrentHashMap.newKeySet();
|
||||
private static final Set<Creature> _shadowSenseCharacters = ConcurrentHashMap.newKeySet();
|
||||
private final long _referenceTime;
|
||||
private boolean _isNight;
|
||||
|
||||
protected GameTimeTaskManager()
|
||||
{
|
||||
super("GameTimeTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.setPriority(NORM_PRIORITY);
|
||||
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||
@ -64,6 +57,41 @@ public class GameTimeTaskManager extends Thread
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if ((getGameHour() < 6) != _isNight)
|
||||
{
|
||||
_isNight = !_isNight;
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(_isNight));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
{
|
||||
return _isNight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actual GameTime tick. Directly taken from current time.
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
public int getGameTime()
|
||||
{
|
||||
return (getGameTicks() % TICKS_PER_IG_DAY) / MILLIS_IN_TICK;
|
||||
@ -79,134 +107,6 @@ public class GameTimeTaskManager extends Thread
|
||||
return getGameTime() % 60;
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
{
|
||||
return getGameHour() < 6;
|
||||
}
|
||||
|
||||
/**
|
||||
* The true GameTime tick. Directly taken from current time. This represents the tick of the time.
|
||||
* @return
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to movingObjects of GameTimeTaskManager.
|
||||
* @param creature The Creature to add to movingObjects of GameTimeTaskManager
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_movingObjects.add(creature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move all Creatures contained in movingObjects of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Concept</u>:</b><br>
|
||||
* <br>
|
||||
* All Creature in movement are identified in <b>movingObjects</b> of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Actions</u>:</b><br>
|
||||
* <ul>
|
||||
* <li>Update the position of each Creature</li>
|
||||
* <li>If movement is finished, the Creature is removed from movingObjects</li>
|
||||
* <li>Create a task to update the _knownObject and _knowPlayers of each Creature that finished its movement and of their already known WorldObject then notify AI with EVT_ARRIVED</li>
|
||||
* </ul>
|
||||
*/
|
||||
private void moveObjects()
|
||||
{
|
||||
_movingObjects.removeIf(Creature::updatePosition);
|
||||
}
|
||||
|
||||
public void stopTimer()
|
||||
{
|
||||
super.interrupt();
|
||||
LOGGER.info(getClass().getSimpleName() + ": Stopped.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
LOGGER.info(getClass().getSimpleName() + ": Started.");
|
||||
|
||||
long nextTickTime;
|
||||
long sleepTime;
|
||||
boolean isNight = isNight();
|
||||
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(isNight));
|
||||
|
||||
while (true)
|
||||
{
|
||||
nextTickTime = ((System.currentTimeMillis() / MILLIS_IN_TICK) * MILLIS_IN_TICK) + 100;
|
||||
|
||||
try
|
||||
{
|
||||
moveObjects();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
|
||||
sleepTime = nextTickTime - System.currentTimeMillis();
|
||||
if (sleepTime > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(sleepTime);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (isNight() != isNight)
|
||||
{
|
||||
isNight = !isNight;
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(isNight));
|
||||
notifyShadowSense();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addShadowSenseCharacter(Creature creature)
|
||||
{
|
||||
if (!_shadowSenseCharacters.contains(creature))
|
||||
{
|
||||
_shadowSenseCharacters.add(creature);
|
||||
if (isNight())
|
||||
{
|
||||
final SystemMessage msg = new SystemMessage(SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT);
|
||||
msg.addSkillName(SHADOW_SENSE_ID);
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeShadowSenseCharacter(Creature creature)
|
||||
{
|
||||
_shadowSenseCharacters.remove(creature);
|
||||
}
|
||||
|
||||
private void notifyShadowSense()
|
||||
{
|
||||
final SystemMessage msg = new SystemMessage(isNight() ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE_ID);
|
||||
for (Creature creature : _shadowSenseCharacters)
|
||||
{
|
||||
creature.getStat().recalculateStats(true);
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static final GameTimeTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
@ -216,4 +116,4 @@ public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
protected static final GameTimeTaskManager INSTANCE = new GameTimeTaskManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.taskmanager;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
|
||||
/**
|
||||
* Movement task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class MovementTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(MovementTaskManager.class.getName());
|
||||
|
||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
||||
|
||||
protected MovementTaskManager()
|
||||
{
|
||||
super("MovementTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to moving objects of MovementTaskManager.
|
||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MOVING_OBJECTS.add(creature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final MovementTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final MovementTaskManager INSTANCE = new MovementTaskManager();
|
||||
}
|
||||
}
|
@ -175,7 +175,6 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("HealOverTime", HealOverTime::new);
|
||||
EffectHandler.getInstance().registerHandler("HealPercent", HealPercent::new);
|
||||
EffectHandler.getInstance().registerHandler("Hide", Hide::new);
|
||||
EffectHandler.getInstance().registerHandler("HitAtNight", HitAtNight::new);
|
||||
EffectHandler.getInstance().registerHandler("HitNumber", HitNumber::new);
|
||||
EffectHandler.getInstance().registerHandler("Hp", Hp::new);
|
||||
EffectHandler.getInstance().registerHandler("HpByLevel", HpByLevel::new);
|
||||
@ -333,6 +332,7 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("SpModify", SpModify::new);
|
||||
EffectHandler.getInstance().registerHandler("Spoil", Spoil::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForLevel", StatAddForLevel::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForNight", StatAddForNight::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSkillCritical", StatBonusSkillCritical::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSpeed", StatBonusSpeed::new);
|
||||
EffectHandler.getInstance().registerHandler("StatByMoveType", StatByMoveType::new);
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class HitAtNight extends AbstractStatEffect
|
||||
{
|
||||
public HitAtNight(StatSet params)
|
||||
{
|
||||
super(params, Stat.HIT_AT_NIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().addShadowSenseCharacter(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().removeShadowSenseCharacter(effected);
|
||||
}
|
||||
}
|
130
L2J_Mobius_03.0_Helios/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
130
L2J_Mobius_03.0_Helios/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.l2jmobius.gameserver.enums.StatModifierType;
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
|
||||
import org.l2jmobius.gameserver.model.events.Containers;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.ListenersContainer;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class StatAddForNight extends AbstractEffect
|
||||
{
|
||||
private static final AtomicBoolean DAY_TIME = new AtomicBoolean(GameTimeTaskManager.getInstance().isNight());
|
||||
private static final Set<Creature> NIGHT_STAT_CHARACTERS = ConcurrentHashMap.newKeySet();
|
||||
private static final int SHADOW_SENSE = 294;
|
||||
|
||||
private final Stat _stat;
|
||||
private final int _amount;
|
||||
protected final StatModifierType _mode;
|
||||
|
||||
public StatAddForNight(StatSet params)
|
||||
{
|
||||
_stat = params.getEnum("stat", Stat.class);
|
||||
_amount = params.getInt("amount");
|
||||
_mode = params.getEnum("mode", StatModifierType.class, StatModifierType.DIFF);
|
||||
|
||||
// Init a global day-night change listener.
|
||||
final ListenersContainer container = Containers.Global();
|
||||
container.addListener(new ConsumerEventListener(container, EventType.ON_DAY_NIGHT_CHANGE, (OnDayNightChange event) -> onDayNightChange(event), this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.add(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.remove(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pump(Creature effected, Skill skill)
|
||||
{
|
||||
// Not night.
|
||||
if (!GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply stat.
|
||||
switch (_mode)
|
||||
{
|
||||
case DIFF:
|
||||
{
|
||||
effected.getStat().mergeAdd(_stat, _amount);
|
||||
break;
|
||||
}
|
||||
case PER:
|
||||
{
|
||||
effected.getStat().mergeMul(_stat, (_amount / 100) + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDayNightChange(OnDayNightChange event)
|
||||
{
|
||||
synchronized (DAY_TIME)
|
||||
{
|
||||
final boolean isNight = event.isNight();
|
||||
|
||||
// Run only once per daytime change.
|
||||
if (isNight == DAY_TIME.get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
DAY_TIME.set(isNight);
|
||||
|
||||
// System message for Shadow Sense.
|
||||
final SystemMessage msg = new SystemMessage(isNight ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE);
|
||||
|
||||
for (Creature creature : NIGHT_STAT_CHARACTERS)
|
||||
{
|
||||
// Pump again.
|
||||
creature.getStat().recalculateStats(true);
|
||||
|
||||
// Send Shadow Sense message when player has skill.
|
||||
if (creature.getKnownSkill(SHADOW_SENSE) != null)
|
||||
{
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6456,9 +6456,9 @@
|
||||
<operateType>P</operateType>
|
||||
<magicCriticalRate>5</magicCriticalRate>
|
||||
<effects>
|
||||
<effect name="HitAtNight">
|
||||
<effect name="StatAddForNight">
|
||||
<stat>ACCURACY_COMBAT</stat>
|
||||
<amount>3</amount>
|
||||
<mode>DIFF</mode>
|
||||
</effect>
|
||||
</effects>
|
||||
</skill>
|
||||
|
@ -146,7 +146,6 @@ Heal: Increases current HP by a given amount.
|
||||
HealOverTime: Increases current HP by a given amount over time.
|
||||
HealPercent: Increases current HP by a given percentage amount.
|
||||
Hide: Hide effect.
|
||||
HitAtNight: Used by Shadow Sense to modify Accuracy at night. (l2jmobius)
|
||||
HitNumber: Polearm attack max hit creatures.
|
||||
HpByLevel: recovers certain amount of HP, but current implementation is wrong... final amount should be computed from skill power and character level difference
|
||||
HpCpHealCritical: HpCp heal effects always trigger Magic Critical Hit.
|
||||
@ -302,6 +301,7 @@ SpeedLimit: Increase a character's max Speed limit. (l2jmobius)
|
||||
SpModify: Bonus SP stat.
|
||||
Spoil: Spoils a mob activating its extra sweep drop.
|
||||
StatAddForLevel: Adds a fixed amount of a Stat for a specific player level. (l2jmobius)
|
||||
StatAddForNight: Modify a specific stat at night time. (l2jmobius)
|
||||
StatBonusSkillCritical: Changes skill critical rate to depend on the specified base stat.
|
||||
StatBonusSpeed: Changes Speed stat to depend on the specified base stat.
|
||||
StatByMoveType: Adds stat based on your movement type (standing, running, walking).
|
||||
|
@ -212,6 +212,9 @@ public class GameServer
|
||||
printSection("ThreadPool");
|
||||
ThreadPool.init();
|
||||
|
||||
// Start game time task manager early
|
||||
GameTimeTaskManager.getInstance();
|
||||
|
||||
printSection("IdManager");
|
||||
IdManager.getInstance();
|
||||
if (!IdManager.hasInitialized())
|
||||
@ -220,7 +223,6 @@ public class GameServer
|
||||
throw new Exception("Could not initialize the ID factory!");
|
||||
}
|
||||
|
||||
// load script engines
|
||||
printSection("Scripting Engine");
|
||||
EventDispatcher.getInstance();
|
||||
ScriptEngineManager.getInstance();
|
||||
@ -229,8 +231,6 @@ public class GameServer
|
||||
TelnetServer.getInstance();
|
||||
|
||||
printSection("World");
|
||||
// Start game time task manager early.
|
||||
GameTimeTaskManager.getInstance();
|
||||
World.getInstance();
|
||||
MapRegionManager.getInstance();
|
||||
ZoneManager.getInstance();
|
||||
|
@ -48,6 +48,7 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
|
||||
/**
|
||||
@ -144,10 +145,21 @@ public class Shutdown extends Thread
|
||||
}
|
||||
|
||||
// ensure all services are stopped
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().stopTimer();
|
||||
LOGGER.info("Game Time Controller: Timer stopped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
MovementTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Game Time Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
@ -166,6 +166,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
|
||||
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.CreatureSeeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
@ -2772,7 +2773,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
case MAGIC_ATTACK:
|
||||
case MAGIC_ATTACK_SPEED:
|
||||
case MAGICAL_DEFENCE:
|
||||
case HIT_AT_NIGHT:
|
||||
{
|
||||
info.addComponentType(UserInfoType.STATS);
|
||||
break;
|
||||
@ -3600,9 +3600,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the MovementTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
@ -3679,9 +3679,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the GameTimeTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
|
@ -41,6 +41,7 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
/**
|
||||
@ -165,7 +166,7 @@ public abstract class Vehicle extends Creature
|
||||
|
||||
m._moveStartTime = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
_move = m;
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Make sure vehicle is not stuck.
|
||||
if (_monitorTask == null)
|
||||
|
@ -42,7 +42,7 @@ public class WarnUserTakeBreakTask implements Runnable
|
||||
{
|
||||
if (_player.isOnline())
|
||||
{
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime());
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime() + 60000);
|
||||
_player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_PLAYED_FOR_S1_HOUR_S_PLEASE_TAKE_A_BREAK).addLong(hours));
|
||||
}
|
||||
else
|
||||
|
@ -161,7 +161,6 @@ public enum Stat
|
||||
MAGIC_ATTACK_RANGE("mAtkRange"),
|
||||
ATTACK_COUNT_MAX("atkCountMax"),
|
||||
PHYSICAL_POLEARM_TARGET_SINGLE("polearmSingleTarget"),
|
||||
HIT_AT_NIGHT("hitAtNight"),
|
||||
|
||||
// Run speed, walk & escape speed are calculated proportionally, magic speed is a buff
|
||||
MOVE_SPEED("moveSpeed"),
|
||||
|
@ -22,7 +22,6 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.ItemTemplate;
|
||||
import org.l2jmobius.gameserver.model.stats.IStatFunction;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
@ -70,12 +69,6 @@ public class PAccuracyFinalizer implements IStatFunction
|
||||
baseValue += calcEnchantBodyPart(creature, ItemTemplate.SLOT_GLOVES);
|
||||
}
|
||||
|
||||
// Shadow sense
|
||||
if (GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
baseValue += creature.getStat().getAdd(Stat.HIT_AT_NIGHT, 0);
|
||||
}
|
||||
|
||||
return Stat.defaultValue(creature, stat, baseValue);
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@ public class ClientSetTime implements IClientOutgoingPacket
|
||||
public boolean write(PacketWriter packet)
|
||||
{
|
||||
OutgoingPackets.CLIENT_SET_TIME.writeId(packet);
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // time in client minutes
|
||||
packet.writeD(6); // constant to match the server time( this determines the speed of the client clock)
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // Time in client minutes.
|
||||
packet.writeD(GameTimeTaskManager.IG_DAYS_PER_DAY); // Constant to match the server time. This determines the speed of the client clock.
|
||||
return true;
|
||||
}
|
||||
}
|
@ -17,42 +17,35 @@
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
/**
|
||||
* Game Time task manager class.
|
||||
* @author Forsaiken
|
||||
* GameTime task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(GameTimeTaskManager.class.getName());
|
||||
|
||||
public static final int TICKS_PER_SECOND = 10; // not able to change this without checking through code
|
||||
public static final int TICKS_PER_SECOND = 10; // Not able to change this without checking through code.
|
||||
public static final int MILLIS_IN_TICK = 1000 / TICKS_PER_SECOND;
|
||||
public static final int IG_DAYS_PER_DAY = 6;
|
||||
public static final int MILLIS_PER_IG_DAY = (3600000 * 24) / IG_DAYS_PER_DAY;
|
||||
public static final int SECONDS_PER_IG_DAY = MILLIS_PER_IG_DAY / 1000;
|
||||
public static final int TICKS_PER_IG_DAY = SECONDS_PER_IG_DAY * TICKS_PER_SECOND;
|
||||
private static final int SHADOW_SENSE_ID = 294;
|
||||
|
||||
private static final Set<Creature> _movingObjects = ConcurrentHashMap.newKeySet();
|
||||
private static final Set<Creature> _shadowSenseCharacters = ConcurrentHashMap.newKeySet();
|
||||
private final long _referenceTime;
|
||||
private boolean _isNight;
|
||||
|
||||
protected GameTimeTaskManager()
|
||||
{
|
||||
super("GameTimeTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.setPriority(NORM_PRIORITY);
|
||||
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||
@ -64,6 +57,41 @@ public class GameTimeTaskManager extends Thread
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if ((getGameHour() < 6) != _isNight)
|
||||
{
|
||||
_isNight = !_isNight;
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(_isNight));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
{
|
||||
return _isNight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actual GameTime tick. Directly taken from current time.
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
public int getGameTime()
|
||||
{
|
||||
return (getGameTicks() % TICKS_PER_IG_DAY) / MILLIS_IN_TICK;
|
||||
@ -79,134 +107,6 @@ public class GameTimeTaskManager extends Thread
|
||||
return getGameTime() % 60;
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
{
|
||||
return getGameHour() < 6;
|
||||
}
|
||||
|
||||
/**
|
||||
* The true GameTime tick. Directly taken from current time. This represents the tick of the time.
|
||||
* @return
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to movingObjects of GameTimeTaskManager.
|
||||
* @param creature The Creature to add to movingObjects of GameTimeTaskManager
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_movingObjects.add(creature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move all Creatures contained in movingObjects of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Concept</u>:</b><br>
|
||||
* <br>
|
||||
* All Creature in movement are identified in <b>movingObjects</b> of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Actions</u>:</b><br>
|
||||
* <ul>
|
||||
* <li>Update the position of each Creature</li>
|
||||
* <li>If movement is finished, the Creature is removed from movingObjects</li>
|
||||
* <li>Create a task to update the _knownObject and _knowPlayers of each Creature that finished its movement and of their already known WorldObject then notify AI with EVT_ARRIVED</li>
|
||||
* </ul>
|
||||
*/
|
||||
private void moveObjects()
|
||||
{
|
||||
_movingObjects.removeIf(Creature::updatePosition);
|
||||
}
|
||||
|
||||
public void stopTimer()
|
||||
{
|
||||
super.interrupt();
|
||||
LOGGER.info(getClass().getSimpleName() + ": Stopped.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
LOGGER.info(getClass().getSimpleName() + ": Started.");
|
||||
|
||||
long nextTickTime;
|
||||
long sleepTime;
|
||||
boolean isNight = isNight();
|
||||
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(isNight));
|
||||
|
||||
while (true)
|
||||
{
|
||||
nextTickTime = ((System.currentTimeMillis() / MILLIS_IN_TICK) * MILLIS_IN_TICK) + 100;
|
||||
|
||||
try
|
||||
{
|
||||
moveObjects();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
|
||||
sleepTime = nextTickTime - System.currentTimeMillis();
|
||||
if (sleepTime > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(sleepTime);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (isNight() != isNight)
|
||||
{
|
||||
isNight = !isNight;
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(isNight));
|
||||
notifyShadowSense();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addShadowSenseCharacter(Creature creature)
|
||||
{
|
||||
if (!_shadowSenseCharacters.contains(creature))
|
||||
{
|
||||
_shadowSenseCharacters.add(creature);
|
||||
if (isNight())
|
||||
{
|
||||
final SystemMessage msg = new SystemMessage(SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT);
|
||||
msg.addSkillName(SHADOW_SENSE_ID);
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeShadowSenseCharacter(Creature creature)
|
||||
{
|
||||
_shadowSenseCharacters.remove(creature);
|
||||
}
|
||||
|
||||
private void notifyShadowSense()
|
||||
{
|
||||
final SystemMessage msg = new SystemMessage(isNight() ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE_ID);
|
||||
for (Creature creature : _shadowSenseCharacters)
|
||||
{
|
||||
creature.getStat().recalculateStats(true);
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static final GameTimeTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
@ -216,4 +116,4 @@ public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
protected static final GameTimeTaskManager INSTANCE = new GameTimeTaskManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.taskmanager;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
|
||||
/**
|
||||
* Movement task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class MovementTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(MovementTaskManager.class.getName());
|
||||
|
||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
||||
|
||||
protected MovementTaskManager()
|
||||
{
|
||||
super("MovementTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to moving objects of MovementTaskManager.
|
||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MOVING_OBJECTS.add(creature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final MovementTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final MovementTaskManager INSTANCE = new MovementTaskManager();
|
||||
}
|
||||
}
|
@ -179,7 +179,6 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("HealOverTime", HealOverTime::new);
|
||||
EffectHandler.getInstance().registerHandler("HealPercent", HealPercent::new);
|
||||
EffectHandler.getInstance().registerHandler("Hide", Hide::new);
|
||||
EffectHandler.getInstance().registerHandler("HitAtNight", HitAtNight::new);
|
||||
EffectHandler.getInstance().registerHandler("HitNumber", HitNumber::new);
|
||||
EffectHandler.getInstance().registerHandler("Hp", Hp::new);
|
||||
EffectHandler.getInstance().registerHandler("HpByLevel", HpByLevel::new);
|
||||
@ -338,6 +337,7 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("SpModify", SpModify::new);
|
||||
EffectHandler.getInstance().registerHandler("Spoil", Spoil::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForLevel", StatAddForLevel::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForNight", StatAddForNight::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSkillCritical", StatBonusSkillCritical::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSpeed", StatBonusSpeed::new);
|
||||
EffectHandler.getInstance().registerHandler("StatByMoveType", StatByMoveType::new);
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class HitAtNight extends AbstractStatEffect
|
||||
{
|
||||
public HitAtNight(StatSet params)
|
||||
{
|
||||
super(params, Stat.HIT_AT_NIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().addShadowSenseCharacter(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().removeShadowSenseCharacter(effected);
|
||||
}
|
||||
}
|
130
L2J_Mobius_04.0_GrandCrusade/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
130
L2J_Mobius_04.0_GrandCrusade/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.l2jmobius.gameserver.enums.StatModifierType;
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
|
||||
import org.l2jmobius.gameserver.model.events.Containers;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.ListenersContainer;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class StatAddForNight extends AbstractEffect
|
||||
{
|
||||
private static final AtomicBoolean DAY_TIME = new AtomicBoolean(GameTimeTaskManager.getInstance().isNight());
|
||||
private static final Set<Creature> NIGHT_STAT_CHARACTERS = ConcurrentHashMap.newKeySet();
|
||||
private static final int SHADOW_SENSE = 294;
|
||||
|
||||
private final Stat _stat;
|
||||
private final int _amount;
|
||||
protected final StatModifierType _mode;
|
||||
|
||||
public StatAddForNight(StatSet params)
|
||||
{
|
||||
_stat = params.getEnum("stat", Stat.class);
|
||||
_amount = params.getInt("amount");
|
||||
_mode = params.getEnum("mode", StatModifierType.class, StatModifierType.DIFF);
|
||||
|
||||
// Init a global day-night change listener.
|
||||
final ListenersContainer container = Containers.Global();
|
||||
container.addListener(new ConsumerEventListener(container, EventType.ON_DAY_NIGHT_CHANGE, (OnDayNightChange event) -> onDayNightChange(event), this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.add(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.remove(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pump(Creature effected, Skill skill)
|
||||
{
|
||||
// Not night.
|
||||
if (!GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply stat.
|
||||
switch (_mode)
|
||||
{
|
||||
case DIFF:
|
||||
{
|
||||
effected.getStat().mergeAdd(_stat, _amount);
|
||||
break;
|
||||
}
|
||||
case PER:
|
||||
{
|
||||
effected.getStat().mergeMul(_stat, (_amount / 100) + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDayNightChange(OnDayNightChange event)
|
||||
{
|
||||
synchronized (DAY_TIME)
|
||||
{
|
||||
final boolean isNight = event.isNight();
|
||||
|
||||
// Run only once per daytime change.
|
||||
if (isNight == DAY_TIME.get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
DAY_TIME.set(isNight);
|
||||
|
||||
// System message for Shadow Sense.
|
||||
final SystemMessage msg = new SystemMessage(isNight ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE);
|
||||
|
||||
for (Creature creature : NIGHT_STAT_CHARACTERS)
|
||||
{
|
||||
// Pump again.
|
||||
creature.getStat().recalculateStats(true);
|
||||
|
||||
// Send Shadow Sense message when player has skill.
|
||||
if (creature.getKnownSkill(SHADOW_SENSE) != null)
|
||||
{
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6484,9 +6484,9 @@
|
||||
<operateType>P</operateType>
|
||||
<magicCriticalRate>5</magicCriticalRate>
|
||||
<effects>
|
||||
<effect name="HitAtNight">
|
||||
<effect name="StatAddForNight">
|
||||
<stat>ACCURACY_COMBAT</stat>
|
||||
<amount>3</amount>
|
||||
<mode>DIFF</mode>
|
||||
</effect>
|
||||
</effects>
|
||||
</skill>
|
||||
|
@ -150,7 +150,6 @@ Heal: Increases current HP by a given amount.
|
||||
HealOverTime: Increases current HP by a given amount over time.
|
||||
HealPercent: Increases current HP by a given percentage amount.
|
||||
Hide: Hide effect.
|
||||
HitAtNight: Used by Shadow Sense to modify Accuracy at night. (l2jmobius)
|
||||
HitNumber: Polearm attack max hit creatures.
|
||||
HpByLevel: recovers certain amount of HP, but current implementation is wrong... final amount should be computed from skill power and character level difference
|
||||
HpCpHealCritical: HpCp heal effects always trigger Magic Critical Hit.
|
||||
@ -307,6 +306,7 @@ SpeedLimit: Increase a character's max Speed limit. (l2jmobius)
|
||||
SpModify: Bonus SP stat.
|
||||
Spoil: Spoils a mob activating its extra sweep drop.
|
||||
StatAddForLevel: Adds a fixed amount of a Stat for a specific player level. (l2jmobius)
|
||||
StatAddForNight: Modify a specific stat at night time. (l2jmobius)
|
||||
StatBonusSkillCritical: Changes skill critical rate to depend on the specified base stat.
|
||||
StatBonusSpeed: Changes Speed stat to depend on the specified base stat.
|
||||
StatByMoveType: Adds stat based on your movement type (standing, running, walking).
|
||||
|
@ -212,6 +212,9 @@ public class GameServer
|
||||
printSection("ThreadPool");
|
||||
ThreadPool.init();
|
||||
|
||||
// Start game time task manager early
|
||||
GameTimeTaskManager.getInstance();
|
||||
|
||||
printSection("IdManager");
|
||||
IdManager.getInstance();
|
||||
if (!IdManager.hasInitialized())
|
||||
@ -220,7 +223,6 @@ public class GameServer
|
||||
throw new Exception("Could not initialize the ID factory!");
|
||||
}
|
||||
|
||||
// load script engines
|
||||
printSection("Scripting Engine");
|
||||
EventDispatcher.getInstance();
|
||||
ScriptEngineManager.getInstance();
|
||||
@ -229,8 +231,6 @@ public class GameServer
|
||||
TelnetServer.getInstance();
|
||||
|
||||
printSection("World");
|
||||
// Start game time task manager early.
|
||||
GameTimeTaskManager.getInstance();
|
||||
World.getInstance();
|
||||
MapRegionManager.getInstance();
|
||||
ZoneManager.getInstance();
|
||||
|
@ -48,6 +48,7 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
|
||||
/**
|
||||
@ -144,10 +145,21 @@ public class Shutdown extends Thread
|
||||
}
|
||||
|
||||
// ensure all services are stopped
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().stopTimer();
|
||||
LOGGER.info("Game Time Controller: Timer stopped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
MovementTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Game Time Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
@ -166,6 +166,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
|
||||
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.CreatureSeeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
@ -2772,7 +2773,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
case MAGIC_ATTACK:
|
||||
case MAGIC_ATTACK_SPEED:
|
||||
case MAGICAL_DEFENCE:
|
||||
case HIT_AT_NIGHT:
|
||||
{
|
||||
info.addComponentType(UserInfoType.STATS);
|
||||
break;
|
||||
@ -3600,9 +3600,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the MovementTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
@ -3679,9 +3679,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the GameTimeTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
|
@ -41,6 +41,7 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
/**
|
||||
@ -165,7 +166,7 @@ public abstract class Vehicle extends Creature
|
||||
|
||||
m._moveStartTime = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
_move = m;
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Make sure vehicle is not stuck.
|
||||
if (_monitorTask == null)
|
||||
|
@ -42,7 +42,7 @@ public class WarnUserTakeBreakTask implements Runnable
|
||||
{
|
||||
if (_player.isOnline())
|
||||
{
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime());
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime() + 60000);
|
||||
_player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_PLAYED_FOR_S1_HOUR_S_PLEASE_TAKE_A_BREAK).addLong(hours));
|
||||
}
|
||||
else
|
||||
|
@ -161,7 +161,6 @@ public enum Stat
|
||||
MAGIC_ATTACK_RANGE("mAtkRange"),
|
||||
ATTACK_COUNT_MAX("atkCountMax"),
|
||||
PHYSICAL_POLEARM_TARGET_SINGLE("polearmSingleTarget"),
|
||||
HIT_AT_NIGHT("hitAtNight"),
|
||||
|
||||
// Run speed, walk & escape speed are calculated proportionally, magic speed is a buff
|
||||
MOVE_SPEED("moveSpeed"),
|
||||
|
@ -22,7 +22,6 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.ItemTemplate;
|
||||
import org.l2jmobius.gameserver.model.stats.IStatFunction;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
@ -70,12 +69,6 @@ public class PAccuracyFinalizer implements IStatFunction
|
||||
baseValue += calcEnchantBodyPart(creature, ItemTemplate.SLOT_GLOVES);
|
||||
}
|
||||
|
||||
// Shadow sense
|
||||
if (GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
baseValue += creature.getStat().getAdd(Stat.HIT_AT_NIGHT, 0);
|
||||
}
|
||||
|
||||
return Stat.defaultValue(creature, stat, baseValue);
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@ public class ClientSetTime implements IClientOutgoingPacket
|
||||
public boolean write(PacketWriter packet)
|
||||
{
|
||||
OutgoingPackets.CLIENT_SET_TIME.writeId(packet);
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // time in client minutes
|
||||
packet.writeD(6); // constant to match the server time( this determines the speed of the client clock)
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // Time in client minutes.
|
||||
packet.writeD(GameTimeTaskManager.IG_DAYS_PER_DAY); // Constant to match the server time. This determines the speed of the client clock.
|
||||
return true;
|
||||
}
|
||||
}
|
@ -17,42 +17,35 @@
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
/**
|
||||
* Game Time task manager class.
|
||||
* @author Forsaiken
|
||||
* GameTime task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(GameTimeTaskManager.class.getName());
|
||||
|
||||
public static final int TICKS_PER_SECOND = 10; // not able to change this without checking through code
|
||||
public static final int TICKS_PER_SECOND = 10; // Not able to change this without checking through code.
|
||||
public static final int MILLIS_IN_TICK = 1000 / TICKS_PER_SECOND;
|
||||
public static final int IG_DAYS_PER_DAY = 6;
|
||||
public static final int MILLIS_PER_IG_DAY = (3600000 * 24) / IG_DAYS_PER_DAY;
|
||||
public static final int SECONDS_PER_IG_DAY = MILLIS_PER_IG_DAY / 1000;
|
||||
public static final int TICKS_PER_IG_DAY = SECONDS_PER_IG_DAY * TICKS_PER_SECOND;
|
||||
private static final int SHADOW_SENSE_ID = 294;
|
||||
|
||||
private static final Set<Creature> _movingObjects = ConcurrentHashMap.newKeySet();
|
||||
private static final Set<Creature> _shadowSenseCharacters = ConcurrentHashMap.newKeySet();
|
||||
private final long _referenceTime;
|
||||
private boolean _isNight;
|
||||
|
||||
protected GameTimeTaskManager()
|
||||
{
|
||||
super("GameTimeTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.setPriority(NORM_PRIORITY);
|
||||
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||
@ -64,6 +57,41 @@ public class GameTimeTaskManager extends Thread
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if ((getGameHour() < 6) != _isNight)
|
||||
{
|
||||
_isNight = !_isNight;
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(_isNight));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
{
|
||||
return _isNight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actual GameTime tick. Directly taken from current time.
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
public int getGameTime()
|
||||
{
|
||||
return (getGameTicks() % TICKS_PER_IG_DAY) / MILLIS_IN_TICK;
|
||||
@ -79,134 +107,6 @@ public class GameTimeTaskManager extends Thread
|
||||
return getGameTime() % 60;
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
{
|
||||
return getGameHour() < 6;
|
||||
}
|
||||
|
||||
/**
|
||||
* The true GameTime tick. Directly taken from current time. This represents the tick of the time.
|
||||
* @return
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to movingObjects of GameTimeTaskManager.
|
||||
* @param creature The Creature to add to movingObjects of GameTimeTaskManager
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_movingObjects.add(creature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move all Creatures contained in movingObjects of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Concept</u>:</b><br>
|
||||
* <br>
|
||||
* All Creature in movement are identified in <b>movingObjects</b> of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Actions</u>:</b><br>
|
||||
* <ul>
|
||||
* <li>Update the position of each Creature</li>
|
||||
* <li>If movement is finished, the Creature is removed from movingObjects</li>
|
||||
* <li>Create a task to update the _knownObject and _knowPlayers of each Creature that finished its movement and of their already known WorldObject then notify AI with EVT_ARRIVED</li>
|
||||
* </ul>
|
||||
*/
|
||||
private void moveObjects()
|
||||
{
|
||||
_movingObjects.removeIf(Creature::updatePosition);
|
||||
}
|
||||
|
||||
public void stopTimer()
|
||||
{
|
||||
super.interrupt();
|
||||
LOGGER.info(getClass().getSimpleName() + ": Stopped.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
LOGGER.info(getClass().getSimpleName() + ": Started.");
|
||||
|
||||
long nextTickTime;
|
||||
long sleepTime;
|
||||
boolean isNight = isNight();
|
||||
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(isNight));
|
||||
|
||||
while (true)
|
||||
{
|
||||
nextTickTime = ((System.currentTimeMillis() / MILLIS_IN_TICK) * MILLIS_IN_TICK) + 100;
|
||||
|
||||
try
|
||||
{
|
||||
moveObjects();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
|
||||
sleepTime = nextTickTime - System.currentTimeMillis();
|
||||
if (sleepTime > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(sleepTime);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (isNight() != isNight)
|
||||
{
|
||||
isNight = !isNight;
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(isNight));
|
||||
notifyShadowSense();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addShadowSenseCharacter(Creature creature)
|
||||
{
|
||||
if (!_shadowSenseCharacters.contains(creature))
|
||||
{
|
||||
_shadowSenseCharacters.add(creature);
|
||||
if (isNight())
|
||||
{
|
||||
final SystemMessage msg = new SystemMessage(SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT);
|
||||
msg.addSkillName(SHADOW_SENSE_ID);
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeShadowSenseCharacter(Creature creature)
|
||||
{
|
||||
_shadowSenseCharacters.remove(creature);
|
||||
}
|
||||
|
||||
private void notifyShadowSense()
|
||||
{
|
||||
final SystemMessage msg = new SystemMessage(isNight() ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE_ID);
|
||||
for (Creature creature : _shadowSenseCharacters)
|
||||
{
|
||||
creature.getStat().recalculateStats(true);
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static final GameTimeTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
@ -216,4 +116,4 @@ public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
protected static final GameTimeTaskManager INSTANCE = new GameTimeTaskManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.taskmanager;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
|
||||
/**
|
||||
* Movement task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class MovementTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(MovementTaskManager.class.getName());
|
||||
|
||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
||||
|
||||
protected MovementTaskManager()
|
||||
{
|
||||
super("MovementTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to moving objects of MovementTaskManager.
|
||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MOVING_OBJECTS.add(creature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final MovementTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final MovementTaskManager INSTANCE = new MovementTaskManager();
|
||||
}
|
||||
}
|
@ -182,7 +182,6 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("HealOverTime", HealOverTime::new);
|
||||
EffectHandler.getInstance().registerHandler("HealPercent", HealPercent::new);
|
||||
EffectHandler.getInstance().registerHandler("Hide", Hide::new);
|
||||
EffectHandler.getInstance().registerHandler("HitAtNight", HitAtNight::new);
|
||||
EffectHandler.getInstance().registerHandler("HitNumber", HitNumber::new);
|
||||
EffectHandler.getInstance().registerHandler("Hp", Hp::new);
|
||||
EffectHandler.getInstance().registerHandler("HpByLevel", HpByLevel::new);
|
||||
@ -343,6 +342,7 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("SpModify", SpModify::new);
|
||||
EffectHandler.getInstance().registerHandler("Spoil", Spoil::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForLevel", StatAddForLevel::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForNight", StatAddForNight::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSkillCritical", StatBonusSkillCritical::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSpeed", StatBonusSpeed::new);
|
||||
EffectHandler.getInstance().registerHandler("StatByMoveType", StatByMoveType::new);
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class HitAtNight extends AbstractStatEffect
|
||||
{
|
||||
public HitAtNight(StatSet params)
|
||||
{
|
||||
super(params, Stat.HIT_AT_NIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().addShadowSenseCharacter(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().removeShadowSenseCharacter(effected);
|
||||
}
|
||||
}
|
130
L2J_Mobius_05.0_Salvation/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
130
L2J_Mobius_05.0_Salvation/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.l2jmobius.gameserver.enums.StatModifierType;
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
|
||||
import org.l2jmobius.gameserver.model.events.Containers;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.ListenersContainer;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class StatAddForNight extends AbstractEffect
|
||||
{
|
||||
private static final AtomicBoolean DAY_TIME = new AtomicBoolean(GameTimeTaskManager.getInstance().isNight());
|
||||
private static final Set<Creature> NIGHT_STAT_CHARACTERS = ConcurrentHashMap.newKeySet();
|
||||
private static final int SHADOW_SENSE = 294;
|
||||
|
||||
private final Stat _stat;
|
||||
private final int _amount;
|
||||
protected final StatModifierType _mode;
|
||||
|
||||
public StatAddForNight(StatSet params)
|
||||
{
|
||||
_stat = params.getEnum("stat", Stat.class);
|
||||
_amount = params.getInt("amount");
|
||||
_mode = params.getEnum("mode", StatModifierType.class, StatModifierType.DIFF);
|
||||
|
||||
// Init a global day-night change listener.
|
||||
final ListenersContainer container = Containers.Global();
|
||||
container.addListener(new ConsumerEventListener(container, EventType.ON_DAY_NIGHT_CHANGE, (OnDayNightChange event) -> onDayNightChange(event), this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.add(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.remove(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pump(Creature effected, Skill skill)
|
||||
{
|
||||
// Not night.
|
||||
if (!GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply stat.
|
||||
switch (_mode)
|
||||
{
|
||||
case DIFF:
|
||||
{
|
||||
effected.getStat().mergeAdd(_stat, _amount);
|
||||
break;
|
||||
}
|
||||
case PER:
|
||||
{
|
||||
effected.getStat().mergeMul(_stat, (_amount / 100) + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDayNightChange(OnDayNightChange event)
|
||||
{
|
||||
synchronized (DAY_TIME)
|
||||
{
|
||||
final boolean isNight = event.isNight();
|
||||
|
||||
// Run only once per daytime change.
|
||||
if (isNight == DAY_TIME.get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
DAY_TIME.set(isNight);
|
||||
|
||||
// System message for Shadow Sense.
|
||||
final SystemMessage msg = new SystemMessage(isNight ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE);
|
||||
|
||||
for (Creature creature : NIGHT_STAT_CHARACTERS)
|
||||
{
|
||||
// Pump again.
|
||||
creature.getStat().recalculateStats(true);
|
||||
|
||||
// Send Shadow Sense message when player has skill.
|
||||
if (creature.getKnownSkill(SHADOW_SENSE) != null)
|
||||
{
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6484,9 +6484,9 @@
|
||||
<operateType>P</operateType>
|
||||
<magicCriticalRate>5</magicCriticalRate>
|
||||
<effects>
|
||||
<effect name="HitAtNight">
|
||||
<effect name="StatAddForNight">
|
||||
<stat>ACCURACY_COMBAT</stat>
|
||||
<amount>3</amount>
|
||||
<mode>DIFF</mode>
|
||||
</effect>
|
||||
</effects>
|
||||
</skill>
|
||||
|
@ -153,7 +153,6 @@ Heal: Increases current HP by a given amount.
|
||||
HealOverTime: Increases current HP by a given amount over time.
|
||||
HealPercent: Increases current HP by a given percentage amount.
|
||||
Hide: Hide effect.
|
||||
HitAtNight: Used by Shadow Sense to modify Accuracy at night. (l2jmobius)
|
||||
HitNumber: Polearm attack max hit creatures.
|
||||
HpByLevel: recovers certain amount of HP, but current implementation is wrong... final amount should be computed from skill power and character level difference
|
||||
HpCpHealCritical: HpCp heal effects always trigger Magic Critical Hit.
|
||||
@ -312,6 +311,7 @@ SpeedLimit: Increase a character's max Speed limit. (l2jmobius)
|
||||
SpModify: Bonus SP stat.
|
||||
Spoil: Spoils a mob activating its extra sweep drop.
|
||||
StatAddForLevel: Adds a fixed amount of a Stat for a specific player level. (l2jmobius)
|
||||
StatAddForNight: Modify a specific stat at night time. (l2jmobius)
|
||||
StatBonusSkillCritical: Changes skill critical rate to depend on the specified base stat.
|
||||
StatBonusSpeed: Changes Speed stat to depend on the specified base stat.
|
||||
StatByMoveType: Adds stat based on your movement type (standing, running, walking).
|
||||
|
@ -214,6 +214,9 @@ public class GameServer
|
||||
printSection("ThreadPool");
|
||||
ThreadPool.init();
|
||||
|
||||
// Start game time task manager early
|
||||
GameTimeTaskManager.getInstance();
|
||||
|
||||
printSection("IdManager");
|
||||
IdManager.getInstance();
|
||||
if (!IdManager.hasInitialized())
|
||||
@ -222,7 +225,6 @@ public class GameServer
|
||||
throw new Exception("Could not initialize the ID factory!");
|
||||
}
|
||||
|
||||
// load script engines
|
||||
printSection("Scripting Engine");
|
||||
EventDispatcher.getInstance();
|
||||
ScriptEngineManager.getInstance();
|
||||
@ -231,8 +233,6 @@ public class GameServer
|
||||
TelnetServer.getInstance();
|
||||
|
||||
printSection("World");
|
||||
// Start game time task manager early.
|
||||
GameTimeTaskManager.getInstance();
|
||||
World.getInstance();
|
||||
MapRegionManager.getInstance();
|
||||
ZoneManager.getInstance();
|
||||
|
@ -48,6 +48,7 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
|
||||
/**
|
||||
@ -144,10 +145,21 @@ public class Shutdown extends Thread
|
||||
}
|
||||
|
||||
// ensure all services are stopped
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().stopTimer();
|
||||
LOGGER.info("Game Time Controller: Timer stopped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
MovementTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Game Time Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
@ -166,6 +166,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
|
||||
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.CreatureSeeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
@ -2772,7 +2773,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
case MAGIC_ATTACK:
|
||||
case MAGIC_ATTACK_SPEED:
|
||||
case MAGICAL_DEFENCE:
|
||||
case HIT_AT_NIGHT:
|
||||
{
|
||||
info.addComponentType(UserInfoType.STATS);
|
||||
break;
|
||||
@ -3600,9 +3600,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the MovementTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
@ -3679,9 +3679,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the GameTimeTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
|
@ -41,6 +41,7 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
/**
|
||||
@ -165,7 +166,7 @@ public abstract class Vehicle extends Creature
|
||||
|
||||
m._moveStartTime = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
_move = m;
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Make sure vehicle is not stuck.
|
||||
if (_monitorTask == null)
|
||||
|
@ -42,7 +42,7 @@ public class WarnUserTakeBreakTask implements Runnable
|
||||
{
|
||||
if (_player.isOnline())
|
||||
{
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime());
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime() + 60000);
|
||||
_player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_PLAYED_FOR_S1_HR_PLEASE_TAKE_A_BREAK).addLong(hours));
|
||||
}
|
||||
else
|
||||
|
@ -164,7 +164,6 @@ public enum Stat
|
||||
MAGIC_ATTACK_RANGE("mAtkRange"),
|
||||
ATTACK_COUNT_MAX("atkCountMax"),
|
||||
PHYSICAL_POLEARM_TARGET_SINGLE("polearmSingleTarget"),
|
||||
HIT_AT_NIGHT("hitAtNight"),
|
||||
|
||||
// Run speed, walk & escape speed are calculated proportionally, magic speed is a buff
|
||||
MOVE_SPEED("moveSpeed"),
|
||||
|
@ -22,7 +22,6 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.ItemTemplate;
|
||||
import org.l2jmobius.gameserver.model.stats.IStatFunction;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
@ -70,12 +69,6 @@ public class PAccuracyFinalizer implements IStatFunction
|
||||
baseValue += calcEnchantBodyPart(creature, ItemTemplate.SLOT_GLOVES);
|
||||
}
|
||||
|
||||
// Shadow sense
|
||||
if (GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
baseValue += creature.getStat().getAdd(Stat.HIT_AT_NIGHT, 0);
|
||||
}
|
||||
|
||||
return Stat.defaultValue(creature, stat, baseValue);
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@ public class ClientSetTime implements IClientOutgoingPacket
|
||||
public boolean write(PacketWriter packet)
|
||||
{
|
||||
OutgoingPackets.CLIENT_SET_TIME.writeId(packet);
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // time in client minutes
|
||||
packet.writeD(6); // constant to match the server time( this determines the speed of the client clock)
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // Time in client minutes.
|
||||
packet.writeD(GameTimeTaskManager.IG_DAYS_PER_DAY); // Constant to match the server time. This determines the speed of the client clock.
|
||||
return true;
|
||||
}
|
||||
}
|
@ -17,42 +17,35 @@
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
/**
|
||||
* Game Time task manager class.
|
||||
* @author Forsaiken
|
||||
* GameTime task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(GameTimeTaskManager.class.getName());
|
||||
|
||||
public static final int TICKS_PER_SECOND = 10; // not able to change this without checking through code
|
||||
public static final int TICKS_PER_SECOND = 10; // Not able to change this without checking through code.
|
||||
public static final int MILLIS_IN_TICK = 1000 / TICKS_PER_SECOND;
|
||||
public static final int IG_DAYS_PER_DAY = 6;
|
||||
public static final int MILLIS_PER_IG_DAY = (3600000 * 24) / IG_DAYS_PER_DAY;
|
||||
public static final int SECONDS_PER_IG_DAY = MILLIS_PER_IG_DAY / 1000;
|
||||
public static final int TICKS_PER_IG_DAY = SECONDS_PER_IG_DAY * TICKS_PER_SECOND;
|
||||
private static final int SHADOW_SENSE_ID = 294;
|
||||
|
||||
private static final Set<Creature> _movingObjects = ConcurrentHashMap.newKeySet();
|
||||
private static final Set<Creature> _shadowSenseCharacters = ConcurrentHashMap.newKeySet();
|
||||
private final long _referenceTime;
|
||||
private boolean _isNight;
|
||||
|
||||
protected GameTimeTaskManager()
|
||||
{
|
||||
super("GameTimeTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.setPriority(NORM_PRIORITY);
|
||||
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||
@ -64,6 +57,41 @@ public class GameTimeTaskManager extends Thread
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if ((getGameHour() < 6) != _isNight)
|
||||
{
|
||||
_isNight = !_isNight;
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(_isNight));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
{
|
||||
return _isNight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actual GameTime tick. Directly taken from current time.
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
public int getGameTime()
|
||||
{
|
||||
return (getGameTicks() % TICKS_PER_IG_DAY) / MILLIS_IN_TICK;
|
||||
@ -79,134 +107,6 @@ public class GameTimeTaskManager extends Thread
|
||||
return getGameTime() % 60;
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
{
|
||||
return getGameHour() < 6;
|
||||
}
|
||||
|
||||
/**
|
||||
* The true GameTime tick. Directly taken from current time. This represents the tick of the time.
|
||||
* @return
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to movingObjects of GameTimeTaskManager.
|
||||
* @param creature The Creature to add to movingObjects of GameTimeTaskManager
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_movingObjects.add(creature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move all Creatures contained in movingObjects of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Concept</u>:</b><br>
|
||||
* <br>
|
||||
* All Creature in movement are identified in <b>movingObjects</b> of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Actions</u>:</b><br>
|
||||
* <ul>
|
||||
* <li>Update the position of each Creature</li>
|
||||
* <li>If movement is finished, the Creature is removed from movingObjects</li>
|
||||
* <li>Create a task to update the _knownObject and _knowPlayers of each Creature that finished its movement and of their already known WorldObject then notify AI with EVT_ARRIVED</li>
|
||||
* </ul>
|
||||
*/
|
||||
private void moveObjects()
|
||||
{
|
||||
_movingObjects.removeIf(Creature::updatePosition);
|
||||
}
|
||||
|
||||
public void stopTimer()
|
||||
{
|
||||
super.interrupt();
|
||||
LOGGER.info(getClass().getSimpleName() + ": Stopped.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
LOGGER.info(getClass().getSimpleName() + ": Started.");
|
||||
|
||||
long nextTickTime;
|
||||
long sleepTime;
|
||||
boolean isNight = isNight();
|
||||
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(isNight));
|
||||
|
||||
while (true)
|
||||
{
|
||||
nextTickTime = ((System.currentTimeMillis() / MILLIS_IN_TICK) * MILLIS_IN_TICK) + 100;
|
||||
|
||||
try
|
||||
{
|
||||
moveObjects();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
|
||||
sleepTime = nextTickTime - System.currentTimeMillis();
|
||||
if (sleepTime > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(sleepTime);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (isNight() != isNight)
|
||||
{
|
||||
isNight = !isNight;
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(isNight));
|
||||
notifyShadowSense();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addShadowSenseCharacter(Creature creature)
|
||||
{
|
||||
if (!_shadowSenseCharacters.contains(creature))
|
||||
{
|
||||
_shadowSenseCharacters.add(creature);
|
||||
if (isNight())
|
||||
{
|
||||
final SystemMessage msg = new SystemMessage(SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT);
|
||||
msg.addSkillName(SHADOW_SENSE_ID);
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeShadowSenseCharacter(Creature creature)
|
||||
{
|
||||
_shadowSenseCharacters.remove(creature);
|
||||
}
|
||||
|
||||
private void notifyShadowSense()
|
||||
{
|
||||
final SystemMessage msg = new SystemMessage(isNight() ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE_ID);
|
||||
for (Creature creature : _shadowSenseCharacters)
|
||||
{
|
||||
creature.getStat().recalculateStats(true);
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static final GameTimeTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
@ -216,4 +116,4 @@ public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
protected static final GameTimeTaskManager INSTANCE = new GameTimeTaskManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.taskmanager;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
|
||||
/**
|
||||
* Movement task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class MovementTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(MovementTaskManager.class.getName());
|
||||
|
||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
||||
|
||||
protected MovementTaskManager()
|
||||
{
|
||||
super("MovementTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to moving objects of MovementTaskManager.
|
||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MOVING_OBJECTS.add(creature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final MovementTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final MovementTaskManager INSTANCE = new MovementTaskManager();
|
||||
}
|
||||
}
|
@ -183,7 +183,6 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("HealOverTime", HealOverTime::new);
|
||||
EffectHandler.getInstance().registerHandler("HealPercent", HealPercent::new);
|
||||
EffectHandler.getInstance().registerHandler("Hide", Hide::new);
|
||||
EffectHandler.getInstance().registerHandler("HitAtNight", HitAtNight::new);
|
||||
EffectHandler.getInstance().registerHandler("HitNumber", HitNumber::new);
|
||||
EffectHandler.getInstance().registerHandler("Hp", Hp::new);
|
||||
EffectHandler.getInstance().registerHandler("HpByLevel", HpByLevel::new);
|
||||
@ -344,6 +343,7 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("SpModify", SpModify::new);
|
||||
EffectHandler.getInstance().registerHandler("Spoil", Spoil::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForLevel", StatAddForLevel::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForNight", StatAddForNight::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSkillCritical", StatBonusSkillCritical::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSpeed", StatBonusSpeed::new);
|
||||
EffectHandler.getInstance().registerHandler("StatByMoveType", StatByMoveType::new);
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class HitAtNight extends AbstractStatEffect
|
||||
{
|
||||
public HitAtNight(StatSet params)
|
||||
{
|
||||
super(params, Stat.HIT_AT_NIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().addShadowSenseCharacter(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().removeShadowSenseCharacter(effected);
|
||||
}
|
||||
}
|
130
L2J_Mobius_05.5_EtinasFate/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
130
L2J_Mobius_05.5_EtinasFate/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.l2jmobius.gameserver.enums.StatModifierType;
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
|
||||
import org.l2jmobius.gameserver.model.events.Containers;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.ListenersContainer;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class StatAddForNight extends AbstractEffect
|
||||
{
|
||||
private static final AtomicBoolean DAY_TIME = new AtomicBoolean(GameTimeTaskManager.getInstance().isNight());
|
||||
private static final Set<Creature> NIGHT_STAT_CHARACTERS = ConcurrentHashMap.newKeySet();
|
||||
private static final int SHADOW_SENSE = 294;
|
||||
|
||||
private final Stat _stat;
|
||||
private final int _amount;
|
||||
protected final StatModifierType _mode;
|
||||
|
||||
public StatAddForNight(StatSet params)
|
||||
{
|
||||
_stat = params.getEnum("stat", Stat.class);
|
||||
_amount = params.getInt("amount");
|
||||
_mode = params.getEnum("mode", StatModifierType.class, StatModifierType.DIFF);
|
||||
|
||||
// Init a global day-night change listener.
|
||||
final ListenersContainer container = Containers.Global();
|
||||
container.addListener(new ConsumerEventListener(container, EventType.ON_DAY_NIGHT_CHANGE, (OnDayNightChange event) -> onDayNightChange(event), this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.add(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.remove(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pump(Creature effected, Skill skill)
|
||||
{
|
||||
// Not night.
|
||||
if (!GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply stat.
|
||||
switch (_mode)
|
||||
{
|
||||
case DIFF:
|
||||
{
|
||||
effected.getStat().mergeAdd(_stat, _amount);
|
||||
break;
|
||||
}
|
||||
case PER:
|
||||
{
|
||||
effected.getStat().mergeMul(_stat, (_amount / 100) + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDayNightChange(OnDayNightChange event)
|
||||
{
|
||||
synchronized (DAY_TIME)
|
||||
{
|
||||
final boolean isNight = event.isNight();
|
||||
|
||||
// Run only once per daytime change.
|
||||
if (isNight == DAY_TIME.get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
DAY_TIME.set(isNight);
|
||||
|
||||
// System message for Shadow Sense.
|
||||
final SystemMessage msg = new SystemMessage(isNight ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE);
|
||||
|
||||
for (Creature creature : NIGHT_STAT_CHARACTERS)
|
||||
{
|
||||
// Pump again.
|
||||
creature.getStat().recalculateStats(true);
|
||||
|
||||
// Send Shadow Sense message when player has skill.
|
||||
if (creature.getKnownSkill(SHADOW_SENSE) != null)
|
||||
{
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6484,9 +6484,9 @@
|
||||
<operateType>P</operateType>
|
||||
<magicCriticalRate>5</magicCriticalRate>
|
||||
<effects>
|
||||
<effect name="HitAtNight">
|
||||
<effect name="StatAddForNight">
|
||||
<stat>ACCURACY_COMBAT</stat>
|
||||
<amount>3</amount>
|
||||
<mode>DIFF</mode>
|
||||
</effect>
|
||||
</effects>
|
||||
</skill>
|
||||
|
@ -154,7 +154,6 @@ Heal: Increases current HP by a given amount.
|
||||
HealOverTime: Increases current HP by a given amount over time.
|
||||
HealPercent: Increases current HP by a given percentage amount.
|
||||
Hide: Hide effect.
|
||||
HitAtNight: Used by Shadow Sense to modify Accuracy at night. (l2jmobius)
|
||||
HitNumber: Polearm attack max hit creatures.
|
||||
HpByLevel: recovers certain amount of HP, but current implementation is wrong... final amount should be computed from skill power and character level difference
|
||||
HpCpHealCritical: HpCp heal effects always trigger Magic Critical Hit.
|
||||
@ -313,6 +312,7 @@ SpeedLimit: Increase a character's max Speed limit. (l2jmobius)
|
||||
SpModify: Bonus SP stat.
|
||||
Spoil: Spoils a mob activating its extra sweep drop.
|
||||
StatAddForLevel: Adds a fixed amount of a Stat for a specific player level. (l2jmobius)
|
||||
StatAddForNight: Modify a specific stat at night time. (l2jmobius)
|
||||
StatBonusSkillCritical: Changes skill critical rate to depend on the specified base stat.
|
||||
StatBonusSpeed: Changes Speed stat to depend on the specified base stat.
|
||||
StatByMoveType: Adds stat based on your movement type (standing, running, walking).
|
||||
|
@ -214,6 +214,9 @@ public class GameServer
|
||||
printSection("ThreadPool");
|
||||
ThreadPool.init();
|
||||
|
||||
// Start game time task manager early
|
||||
GameTimeTaskManager.getInstance();
|
||||
|
||||
printSection("IdManager");
|
||||
IdManager.getInstance();
|
||||
if (!IdManager.hasInitialized())
|
||||
@ -222,7 +225,6 @@ public class GameServer
|
||||
throw new Exception("Could not initialize the ID factory!");
|
||||
}
|
||||
|
||||
// load script engines
|
||||
printSection("Scripting Engine");
|
||||
EventDispatcher.getInstance();
|
||||
ScriptEngineManager.getInstance();
|
||||
@ -231,8 +233,6 @@ public class GameServer
|
||||
TelnetServer.getInstance();
|
||||
|
||||
printSection("World");
|
||||
// Start game time task manager early.
|
||||
GameTimeTaskManager.getInstance();
|
||||
World.getInstance();
|
||||
MapRegionManager.getInstance();
|
||||
ZoneManager.getInstance();
|
||||
|
@ -48,6 +48,7 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
|
||||
/**
|
||||
@ -144,10 +145,21 @@ public class Shutdown extends Thread
|
||||
}
|
||||
|
||||
// ensure all services are stopped
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().stopTimer();
|
||||
LOGGER.info("Game Time Controller: Timer stopped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
MovementTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Game Time Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
@ -166,6 +166,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
|
||||
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.CreatureSeeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
@ -2772,7 +2773,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
case MAGIC_ATTACK:
|
||||
case MAGIC_ATTACK_SPEED:
|
||||
case MAGICAL_DEFENCE:
|
||||
case HIT_AT_NIGHT:
|
||||
{
|
||||
info.addComponentType(UserInfoType.STATS);
|
||||
break;
|
||||
@ -3600,9 +3600,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the MovementTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
@ -3679,9 +3679,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the GameTimeTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
|
@ -41,6 +41,7 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
/**
|
||||
@ -165,7 +166,7 @@ public abstract class Vehicle extends Creature
|
||||
|
||||
m._moveStartTime = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
_move = m;
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Make sure vehicle is not stuck.
|
||||
if (_monitorTask == null)
|
||||
|
@ -42,7 +42,7 @@ public class WarnUserTakeBreakTask implements Runnable
|
||||
{
|
||||
if (_player.isOnline())
|
||||
{
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime());
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime() + 60000);
|
||||
_player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_PLAYED_FOR_S1_HOUR_S_PLEASE_TAKE_A_BREAK).addLong(hours));
|
||||
}
|
||||
else
|
||||
|
@ -164,7 +164,6 @@ public enum Stat
|
||||
MAGIC_ATTACK_RANGE("mAtkRange"),
|
||||
ATTACK_COUNT_MAX("atkCountMax"),
|
||||
PHYSICAL_POLEARM_TARGET_SINGLE("polearmSingleTarget"),
|
||||
HIT_AT_NIGHT("hitAtNight"),
|
||||
|
||||
// Run speed, walk & escape speed are calculated proportionally, magic speed is a buff
|
||||
MOVE_SPEED("moveSpeed"),
|
||||
|
@ -22,7 +22,6 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.ItemTemplate;
|
||||
import org.l2jmobius.gameserver.model.stats.IStatFunction;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
@ -70,12 +69,6 @@ public class PAccuracyFinalizer implements IStatFunction
|
||||
baseValue += calcEnchantBodyPart(creature, ItemTemplate.SLOT_GLOVES);
|
||||
}
|
||||
|
||||
// Shadow sense
|
||||
if (GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
baseValue += creature.getStat().getAdd(Stat.HIT_AT_NIGHT, 0);
|
||||
}
|
||||
|
||||
return Stat.defaultValue(creature, stat, baseValue);
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@ public class ClientSetTime implements IClientOutgoingPacket
|
||||
public boolean write(PacketWriter packet)
|
||||
{
|
||||
OutgoingPackets.CLIENT_SET_TIME.writeId(packet);
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // time in client minutes
|
||||
packet.writeD(6); // constant to match the server time( this determines the speed of the client clock)
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // Time in client minutes.
|
||||
packet.writeD(GameTimeTaskManager.IG_DAYS_PER_DAY); // Constant to match the server time. This determines the speed of the client clock.
|
||||
return true;
|
||||
}
|
||||
}
|
@ -17,42 +17,35 @@
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
/**
|
||||
* Game Time task manager class.
|
||||
* @author Forsaiken
|
||||
* GameTime task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(GameTimeTaskManager.class.getName());
|
||||
|
||||
public static final int TICKS_PER_SECOND = 10; // not able to change this without checking through code
|
||||
public static final int TICKS_PER_SECOND = 10; // Not able to change this without checking through code.
|
||||
public static final int MILLIS_IN_TICK = 1000 / TICKS_PER_SECOND;
|
||||
public static final int IG_DAYS_PER_DAY = 6;
|
||||
public static final int MILLIS_PER_IG_DAY = (3600000 * 24) / IG_DAYS_PER_DAY;
|
||||
public static final int SECONDS_PER_IG_DAY = MILLIS_PER_IG_DAY / 1000;
|
||||
public static final int TICKS_PER_IG_DAY = SECONDS_PER_IG_DAY * TICKS_PER_SECOND;
|
||||
private static final int SHADOW_SENSE_ID = 294;
|
||||
|
||||
private static final Set<Creature> _movingObjects = ConcurrentHashMap.newKeySet();
|
||||
private static final Set<Creature> _shadowSenseCharacters = ConcurrentHashMap.newKeySet();
|
||||
private final long _referenceTime;
|
||||
private boolean _isNight;
|
||||
|
||||
protected GameTimeTaskManager()
|
||||
{
|
||||
super("GameTimeTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.setPriority(NORM_PRIORITY);
|
||||
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||
@ -64,6 +57,41 @@ public class GameTimeTaskManager extends Thread
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if ((getGameHour() < 6) != _isNight)
|
||||
{
|
||||
_isNight = !_isNight;
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(_isNight));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
{
|
||||
return _isNight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The actual GameTime tick. Directly taken from current time.
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
public int getGameTime()
|
||||
{
|
||||
return (getGameTicks() % TICKS_PER_IG_DAY) / MILLIS_IN_TICK;
|
||||
@ -79,134 +107,6 @@ public class GameTimeTaskManager extends Thread
|
||||
return getGameTime() % 60;
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
{
|
||||
return getGameHour() < 6;
|
||||
}
|
||||
|
||||
/**
|
||||
* The true GameTime tick. Directly taken from current time. This represents the tick of the time.
|
||||
* @return
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to movingObjects of GameTimeTaskManager.
|
||||
* @param creature The Creature to add to movingObjects of GameTimeTaskManager
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_movingObjects.add(creature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move all Creatures contained in movingObjects of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Concept</u>:</b><br>
|
||||
* <br>
|
||||
* All Creature in movement are identified in <b>movingObjects</b> of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Actions</u>:</b><br>
|
||||
* <ul>
|
||||
* <li>Update the position of each Creature</li>
|
||||
* <li>If movement is finished, the Creature is removed from movingObjects</li>
|
||||
* <li>Create a task to update the _knownObject and _knowPlayers of each Creature that finished its movement and of their already known WorldObject then notify AI with EVT_ARRIVED</li>
|
||||
* </ul>
|
||||
*/
|
||||
private void moveObjects()
|
||||
{
|
||||
_movingObjects.removeIf(Creature::updatePosition);
|
||||
}
|
||||
|
||||
public void stopTimer()
|
||||
{
|
||||
super.interrupt();
|
||||
LOGGER.info(getClass().getSimpleName() + ": Stopped.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
LOGGER.info(getClass().getSimpleName() + ": Started.");
|
||||
|
||||
long nextTickTime;
|
||||
long sleepTime;
|
||||
boolean isNight = isNight();
|
||||
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(isNight));
|
||||
|
||||
while (true)
|
||||
{
|
||||
nextTickTime = ((System.currentTimeMillis() / MILLIS_IN_TICK) * MILLIS_IN_TICK) + 100;
|
||||
|
||||
try
|
||||
{
|
||||
moveObjects();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
|
||||
sleepTime = nextTickTime - System.currentTimeMillis();
|
||||
if (sleepTime > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(sleepTime);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (isNight() != isNight)
|
||||
{
|
||||
isNight = !isNight;
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnDayNightChange(isNight));
|
||||
notifyShadowSense();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addShadowSenseCharacter(Creature creature)
|
||||
{
|
||||
if (!_shadowSenseCharacters.contains(creature))
|
||||
{
|
||||
_shadowSenseCharacters.add(creature);
|
||||
if (isNight())
|
||||
{
|
||||
final SystemMessage msg = new SystemMessage(SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT);
|
||||
msg.addSkillName(SHADOW_SENSE_ID);
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeShadowSenseCharacter(Creature creature)
|
||||
{
|
||||
_shadowSenseCharacters.remove(creature);
|
||||
}
|
||||
|
||||
private void notifyShadowSense()
|
||||
{
|
||||
final SystemMessage msg = new SystemMessage(isNight() ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE_ID);
|
||||
for (Creature creature : _shadowSenseCharacters)
|
||||
{
|
||||
creature.getStat().recalculateStats(true);
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static final GameTimeTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
@ -216,4 +116,4 @@ public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
protected static final GameTimeTaskManager INSTANCE = new GameTimeTaskManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.taskmanager;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
|
||||
/**
|
||||
* Movement task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class MovementTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(MovementTaskManager.class.getName());
|
||||
|
||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
||||
|
||||
protected MovementTaskManager()
|
||||
{
|
||||
super("MovementTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to moving objects of MovementTaskManager.
|
||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MOVING_OBJECTS.add(creature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final MovementTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final MovementTaskManager INSTANCE = new MovementTaskManager();
|
||||
}
|
||||
}
|
@ -183,7 +183,6 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("HealOverTime", HealOverTime::new);
|
||||
EffectHandler.getInstance().registerHandler("HealPercent", HealPercent::new);
|
||||
EffectHandler.getInstance().registerHandler("Hide", Hide::new);
|
||||
EffectHandler.getInstance().registerHandler("HitAtNight", HitAtNight::new);
|
||||
EffectHandler.getInstance().registerHandler("HitNumber", HitNumber::new);
|
||||
EffectHandler.getInstance().registerHandler("Hp", Hp::new);
|
||||
EffectHandler.getInstance().registerHandler("HpByLevel", HpByLevel::new);
|
||||
@ -344,6 +343,7 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("SpModify", SpModify::new);
|
||||
EffectHandler.getInstance().registerHandler("Spoil", Spoil::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForLevel", StatAddForLevel::new);
|
||||
EffectHandler.getInstance().registerHandler("StatAddForNight", StatAddForNight::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSkillCritical", StatBonusSkillCritical::new);
|
||||
EffectHandler.getInstance().registerHandler("StatBonusSpeed", StatBonusSpeed::new);
|
||||
EffectHandler.getInstance().registerHandler("StatByMoveType", StatByMoveType::new);
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class HitAtNight extends AbstractStatEffect
|
||||
{
|
||||
public HitAtNight(StatSet params)
|
||||
{
|
||||
super(params, Stat.HIT_AT_NIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().addShadowSenseCharacter(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
GameTimeTaskManager.getInstance().removeShadowSenseCharacter(effected);
|
||||
}
|
||||
}
|
130
L2J_Mobius_06.0_Fafurion/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
130
L2J_Mobius_06.0_Fafurion/dist/game/data/scripts/handlers/effecthandlers/StatAddForNight.java
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.l2jmobius.gameserver.enums.StatModifierType;
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
|
||||
import org.l2jmobius.gameserver.model.events.Containers;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.ListenersContainer;
|
||||
import org.l2jmobius.gameserver.model.events.impl.OnDayNightChange;
|
||||
import org.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
import org.l2jmobius.gameserver.model.stats.Stat;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class StatAddForNight extends AbstractEffect
|
||||
{
|
||||
private static final AtomicBoolean DAY_TIME = new AtomicBoolean(GameTimeTaskManager.getInstance().isNight());
|
||||
private static final Set<Creature> NIGHT_STAT_CHARACTERS = ConcurrentHashMap.newKeySet();
|
||||
private static final int SHADOW_SENSE = 294;
|
||||
|
||||
private final Stat _stat;
|
||||
private final int _amount;
|
||||
protected final StatModifierType _mode;
|
||||
|
||||
public StatAddForNight(StatSet params)
|
||||
{
|
||||
_stat = params.getEnum("stat", Stat.class);
|
||||
_amount = params.getInt("amount");
|
||||
_mode = params.getEnum("mode", StatModifierType.class, StatModifierType.DIFF);
|
||||
|
||||
// Init a global day-night change listener.
|
||||
final ListenersContainer container = Containers.Global();
|
||||
container.addListener(new ConsumerEventListener(container, EventType.ON_DAY_NIGHT_CHANGE, (OnDayNightChange event) -> onDayNightChange(event), this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.add(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
NIGHT_STAT_CHARACTERS.remove(effected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pump(Creature effected, Skill skill)
|
||||
{
|
||||
// Not night.
|
||||
if (!GameTimeTaskManager.getInstance().isNight())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply stat.
|
||||
switch (_mode)
|
||||
{
|
||||
case DIFF:
|
||||
{
|
||||
effected.getStat().mergeAdd(_stat, _amount);
|
||||
break;
|
||||
}
|
||||
case PER:
|
||||
{
|
||||
effected.getStat().mergeMul(_stat, (_amount / 100) + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDayNightChange(OnDayNightChange event)
|
||||
{
|
||||
synchronized (DAY_TIME)
|
||||
{
|
||||
final boolean isNight = event.isNight();
|
||||
|
||||
// Run only once per daytime change.
|
||||
if (isNight == DAY_TIME.get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
DAY_TIME.set(isNight);
|
||||
|
||||
// System message for Shadow Sense.
|
||||
final SystemMessage msg = new SystemMessage(isNight ? SystemMessageId.IT_IS_NOW_MIDNIGHT_AND_THE_EFFECT_OF_S1_CAN_BE_FELT : SystemMessageId.IT_IS_DAWN_AND_THE_EFFECT_OF_S1_WILL_NOW_DISAPPEAR);
|
||||
msg.addSkillName(SHADOW_SENSE);
|
||||
|
||||
for (Creature creature : NIGHT_STAT_CHARACTERS)
|
||||
{
|
||||
// Pump again.
|
||||
creature.getStat().recalculateStats(true);
|
||||
|
||||
// Send Shadow Sense message when player has skill.
|
||||
if (creature.getKnownSkill(SHADOW_SENSE) != null)
|
||||
{
|
||||
creature.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6507,9 +6507,9 @@
|
||||
<operateType>P</operateType>
|
||||
<magicCriticalRate>5</magicCriticalRate>
|
||||
<effects>
|
||||
<effect name="HitAtNight">
|
||||
<effect name="StatAddForNight">
|
||||
<stat>ACCURACY_COMBAT</stat>
|
||||
<amount>3</amount>
|
||||
<mode>DIFF</mode>
|
||||
</effect>
|
||||
</effects>
|
||||
</skill>
|
||||
|
@ -154,7 +154,6 @@ Heal: Increases current HP by a given amount.
|
||||
HealOverTime: Increases current HP by a given amount over time.
|
||||
HealPercent: Increases current HP by a given percentage amount.
|
||||
Hide: Hide effect.
|
||||
HitAtNight: Used by Shadow Sense to modify Accuracy at night. (l2jmobius)
|
||||
HitNumber: Polearm attack max hit creatures.
|
||||
HpByLevel: recovers certain amount of HP, but current implementation is wrong... final amount should be computed from skill power and character level difference
|
||||
HpCpHealCritical: HpCp heal effects always trigger Magic Critical Hit.
|
||||
@ -313,6 +312,7 @@ SpeedLimit: Increase a character's max Speed limit. (l2jmobius)
|
||||
SpModify: Bonus SP stat.
|
||||
Spoil: Spoils a mob activating its extra sweep drop.
|
||||
StatAddForLevel: Adds a fixed amount of a Stat for a specific player level. (l2jmobius)
|
||||
StatAddForNight: Modify a specific stat at night time. (l2jmobius)
|
||||
StatBonusSkillCritical: Changes skill critical rate to depend on the specified base stat.
|
||||
StatBonusSpeed: Changes Speed stat to depend on the specified base stat.
|
||||
StatByMoveType: Adds stat based on your movement type (standing, running, walking).
|
||||
|
@ -215,6 +215,9 @@ public class GameServer
|
||||
printSection("ThreadPool");
|
||||
ThreadPool.init();
|
||||
|
||||
// Start game time task manager early
|
||||
GameTimeTaskManager.getInstance();
|
||||
|
||||
printSection("IdManager");
|
||||
IdManager.getInstance();
|
||||
if (!IdManager.hasInitialized())
|
||||
@ -223,7 +226,6 @@ public class GameServer
|
||||
throw new Exception("Could not initialize the ID factory!");
|
||||
}
|
||||
|
||||
// load script engines
|
||||
printSection("Scripting Engine");
|
||||
EventDispatcher.getInstance();
|
||||
ScriptEngineManager.getInstance();
|
||||
@ -232,8 +234,6 @@ public class GameServer
|
||||
TelnetServer.getInstance();
|
||||
|
||||
printSection("World");
|
||||
// Start game time task manager early.
|
||||
GameTimeTaskManager.getInstance();
|
||||
World.getInstance();
|
||||
MapRegionManager.getInstance();
|
||||
ZoneManager.getInstance();
|
||||
|
@ -48,6 +48,7 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
|
||||
/**
|
||||
@ -144,10 +145,21 @@ public class Shutdown extends Thread
|
||||
}
|
||||
|
||||
// ensure all services are stopped
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().stopTimer();
|
||||
LOGGER.info("Game Time Controller: Timer stopped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
MovementTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Game Time Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
@ -166,6 +166,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
|
||||
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.CreatureSeeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
@ -2772,7 +2773,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
case MAGIC_ATTACK:
|
||||
case MAGIC_ATTACK_SPEED:
|
||||
case MAGICAL_DEFENCE:
|
||||
case HIT_AT_NIGHT:
|
||||
{
|
||||
info.addComponentType(UserInfoType.STATS);
|
||||
break;
|
||||
@ -3600,9 +3600,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the MovementTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
@ -3679,9 +3679,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the GameTimeTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
|
@ -41,6 +41,7 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
/**
|
||||
@ -165,7 +166,7 @@ public abstract class Vehicle extends Creature
|
||||
|
||||
m._moveStartTime = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
_move = m;
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Make sure vehicle is not stuck.
|
||||
if (_monitorTask == null)
|
||||
|
@ -42,7 +42,7 @@ public class WarnUserTakeBreakTask implements Runnable
|
||||
{
|
||||
if (_player.isOnline())
|
||||
{
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime());
|
||||
final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime() + 60000);
|
||||
_player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_PLAYED_FOR_S1_HOUR_S_PLEASE_TAKE_A_BREAK).addLong(hours));
|
||||
}
|
||||
else
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user