.
+ *
+ * l2jserver 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.
+ *
+ * l2jserver 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 l2jserver. If not, see .
+ */
+package com.l2jserver.model.world.actor.event;
+
+import com.l2jserver.model.id.ObjectID;
+import com.l2jserver.model.server.AttackHit;
+import com.l2jserver.model.world.Actor;
+import com.l2jserver.model.world.WorldObject;
+
+/**
+ * Event dispatcher once an actor has received/dealt an attack hit.
+ *
+ * Please note that the same event is dispatched for both attacker and attackee.
+ *
+ * @author Rogiel
+ */
+public class ActorAttackHitEvent implements ActorEvent {
+ /**
+ * The spawned player
+ */
+ private final AttackHit hit;
+
+ /**
+ * Creates a new instance
+ *
+ * @param hit
+ * the attack hit
+ */
+ public ActorAttackHitEvent(AttackHit hit) {
+ this.hit = hit;
+ }
+
+ @Override
+ public WorldObject getObject() {
+ return hit.getAttacker();
+ }
+
+ @Override
+ public Actor getActor() {
+ return hit.getAttacker();
+ }
+
+ /**
+ * @return the attack hit
+ */
+ public AttackHit getHit() {
+ return hit;
+ }
+
+ @Override
+ public ObjectID>[] getDispatchableObjects() {
+ return new ObjectID>[] { hit.getAttacker().getID() };
+ }
+}
diff --git a/src/main/java/com/l2jserver/model/world/actor/stat/ActorStats.java b/src/main/java/com/l2jserver/model/world/actor/stat/ActorStats.java
index 0373bbb19..015d8ea50 100644
--- a/src/main/java/com/l2jserver/model/world/actor/stat/ActorStats.java
+++ b/src/main/java/com/l2jserver/model/world/actor/stat/ActorStats.java
@@ -32,7 +32,7 @@ import com.l2jserver.model.world.actor.calculator.PhysicalCriticalRateBonusCalcu
import com.l2jserver.model.world.actor.calculator.PhysicalDefenseBonusCalculator;
import com.l2jserver.model.world.actor.calculator.RunSpeedBonusCalculator;
import com.l2jserver.model.world.actor.calculator.WalkSpeedBonusCalculator;
-import com.l2jserver.util.calculator.Calculator;
+import com.l2jserver.util.calculator.SimpleCalculator;
/**
* @author Rogiel
@@ -152,12 +152,12 @@ public abstract class ActorStats {
* speed gain is much higher.
*/
@SuppressWarnings("unchecked")
- private final Calculator[] calculators = new Calculator[StatType
+ private final SimpleCalculator[] calculators = new SimpleCalculator[StatType
.values().length];
public ActorStats() {
for (int i = 0; i < calculators.length; i++) {
- calculators[i] = new Calculator();
+ calculators[i] = new SimpleCalculator();
}
// bonuses
@@ -334,7 +334,7 @@ public abstract class ActorStats {
* calculator {@link StatType}
* @return the calculator object associated with the given type
*/
- protected Calculator getCalculator(StatType type) {
+ protected SimpleCalculator getCalculator(StatType type) {
return calculators[type.ordinal()];
}
@@ -350,5 +350,9 @@ public abstract class ActorStats {
return getCalculator(type).calculate(ctx);
}
+ public void updateCalculators() {
+
+ }
+
protected abstract T createContext();
}
diff --git a/src/main/java/com/l2jserver/model/world/character/CharacterStats.java b/src/main/java/com/l2jserver/model/world/character/CharacterStats.java
index c5b64a6ef..139e00e15 100644
--- a/src/main/java/com/l2jserver/model/world/character/CharacterStats.java
+++ b/src/main/java/com/l2jserver/model/world/character/CharacterStats.java
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.character;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.stat.ActorStats;
import com.l2jserver.model.world.actor.stat.StatType;
+import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorContext;
import com.l2jserver.model.world.character.calculator.MaximumCPAddCalculator;
@@ -46,17 +47,17 @@ import com.l2jserver.model.world.character.calculator.base.CharacterBaseRunSpeed
import com.l2jserver.model.world.character.calculator.base.CharacterBaseStrengthCalculator;
import com.l2jserver.model.world.character.calculator.base.CharacterBaseWalkSpeedCalculator;
import com.l2jserver.model.world.character.calculator.base.CharacterBaseWitnessCalculator;
-import com.l2jserver.util.calculator.Calculator;
+import com.l2jserver.util.calculator.SimpleCalculator;
/**
* This class is responsible for calculating the real character stats. The real
* stats vary from the values from the templates, also, skills and items
* equipped can change those values. Once an buff is applied, a new calculator
- * is {@link Calculator#importFunctions(Calculator) imported} and their
- * functions are added to this class calculator. Once the skill effect has past
- * away, all the functions that were imported are now
- * {@link Calculator#removeFunctions(Calculator) removed} and the calculator
- * return to its original state.
+ * is {@link SimpleCalculator#importFunctions(SimpleCalculator) imported} and
+ * their functions are added to this class calculator. Once the skill effect has
+ * past away, all the functions that were imported are now
+ * {@link SimpleCalculator#removeFunctions(SimpleCalculator) removed} and the
+ * calculator return to its original state.
*
* Another important note is that calculators should perform calculations as
* fast as possible.
@@ -219,7 +220,7 @@ public class CharacterStats extends ActorStats {
* shared.
*/
private static final CharacterCalculator BASE_ATTACK_EVASION_CALCULATOR = new CharacterBaseAttackEvasionCalculator();
-
+
// BONUS
/**
* The calculator for CP bonus
@@ -228,7 +229,7 @@ public class CharacterStats extends ActorStats {
* shared.
*/
private static final CharacterCalculator CP_BONUS_CALCULATOR = new MaximumCPBonusCalculator();
-
+
// ADD
/**
* The calculator for HP add
@@ -299,10 +300,10 @@ public class CharacterStats extends ActorStats {
add(StatType.MAX_HP, HP_ADD_CALCULATOR);
add(StatType.MAX_MP, MP_ADD_CALCULATOR);
add(StatType.MAX_CP, CP_ADD_CALCULATOR);
-
+
// bonus
add(StatType.MAX_CP, CP_BONUS_CALCULATOR);
-
+
// TODO henna stats calculators
}
@@ -320,6 +321,17 @@ public class CharacterStats extends ActorStats {
return (int) calc(StatType.MAX_LOAD);
}
+ @Override
+ public void updateCalculators() {
+ super.updateCalculators();
+ if (character.getInventory().has(InventoryPaperdoll.RIGHT_HAND)) {
+ add(StatType.POWER_ATTACK,
+ character.getInventory()
+ .getItem(InventoryPaperdoll.RIGHT_HAND)
+ .getTemplateID().getTemplate().getPhysicalDamage());
+ }
+ }
+
@Override
protected CharacterCalculatorContext createContext() {
return new CharacterCalculatorContext(character);
diff --git a/src/main/java/com/l2jserver/model/world/npc/NPCStats.java b/src/main/java/com/l2jserver/model/world/npc/NPCStats.java
index 5c08d2e28..ff2f6a506 100644
--- a/src/main/java/com/l2jserver/model/world/npc/NPCStats.java
+++ b/src/main/java/com/l2jserver/model/world/npc/NPCStats.java
@@ -21,7 +21,6 @@ import com.l2jserver.model.world.actor.stat.ActorStats;
import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorContext;
-import com.l2jserver.model.world.npc.calculator.base.NPCBaseAttackAccuracyCalculator;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseAttackEvasionCalculator;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseConcentrationCalculator;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseDexterityCalculator;
@@ -41,16 +40,16 @@ import com.l2jserver.model.world.npc.calculator.base.NPCBaseRunSpeedCalculator;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseStrengthCalculator;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseWalkSpeedCalculator;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseWitnessCalculator;
-import com.l2jserver.util.calculator.Calculator;
+import com.l2jserver.util.calculator.SimpleCalculator;
/**
* This class is responsible for calculating the real NPC stats. The real stats
* vary from the values from the templates, also, skills and items equipped can
* change those values. Once an buff is applied, a new calculator is
- * {@link Calculator#importFunctions(Calculator) imported} and their functions
+ * {@link SimpleCalculator#importFunctions(SimpleCalculator) imported} and their functions
* are added to this class calculator. Once the skill effect has past away, all
* the functions that were imported are now
- * {@link Calculator#removeFunctions(Calculator) removed} and the calculator
+ * {@link SimpleCalculator#removeFunctions(SimpleCalculator) removed} and the calculator
* return to its original state.
*
* Another important note is that calculators should perform calculations as
@@ -192,13 +191,6 @@ public class NPCStats extends ActorStats {
*/
private static final NPCCalculator BASE_MAGICAL_DEFENSE_CALCULATOR = new NPCBaseMagicalDefenseCalculator();
- /**
- * The calculator base attack accuracy
- *
- * This calculator does not store any state and thus is safe to be
- * shared.
- */
- private static final NPCCalculator BASE_ATTACK_ACCURACY_CALCULATOR = new NPCBaseAttackAccuracyCalculator();
/**
* The calculator base evasion
*
@@ -245,7 +237,6 @@ public class NPCStats extends ActorStats {
add(StatType.MCRITICAL_RATE, BASE_MAGICAL_CRITICAL_RATE_CALCULATOR);
add(StatType.MAGIC_DEFENSE, BASE_MAGICAL_DEFENSE_CALCULATOR);
- add(StatType.ACCURACY_COMBAT, BASE_ATTACK_ACCURACY_CALCULATOR);
add(StatType.EVASION_RATE, BASE_ATTACK_EVASION_CALCULATOR);
}
diff --git a/src/main/java/com/l2jserver/service/ServiceManager.java b/src/main/java/com/l2jserver/service/ServiceManager.java
index d1c15b125..eef3e8746 100644
--- a/src/main/java/com/l2jserver/service/ServiceManager.java
+++ b/src/main/java/com/l2jserver/service/ServiceManager.java
@@ -41,7 +41,9 @@ public class ServiceManager {
* The Guice Injector
*/
private final Injector injector;
-
+ /**
+ * List of all known services by this manager
+ */
private final Set knownServices = CollectionFactory.newSet();
@Inject
diff --git a/src/main/java/com/l2jserver/service/ServiceModule.java b/src/main/java/com/l2jserver/service/ServiceModule.java
index ca507949b..fbf4bb02f 100644
--- a/src/main/java/com/l2jserver/service/ServiceModule.java
+++ b/src/main/java/com/l2jserver/service/ServiceModule.java
@@ -31,6 +31,8 @@ import com.l2jserver.service.core.vfs.VFSService;
import com.l2jserver.service.core.vfs.VFSServiceImpl;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.JDBCDatabaseService;
+import com.l2jserver.service.game.AttackService;
+import com.l2jserver.service.game.AttackServiceImpl;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.character.CharacterServiceImpl;
import com.l2jserver.service.game.chat.ChatService;
@@ -53,6 +55,8 @@ import com.l2jserver.service.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.game.world.event.WorldEventDispatcherImpl;
import com.l2jserver.service.network.NettyNetworkService;
import com.l2jserver.service.network.NetworkService;
+import com.l2jserver.service.network.gameguard.GameGuardService;
+import com.l2jserver.service.network.gameguard.GameGuardServiceImpl;
import com.l2jserver.service.network.keygen.BlowfishKeygenService;
import com.l2jserver.service.network.keygen.SecureBlowfishKeygenService;
@@ -86,6 +90,8 @@ public class ServiceModule extends AbstractModule {
.in(Scopes.SINGLETON);
bind(NetworkService.class).to(NettyNetworkService.class).in(
Scopes.SINGLETON);
+ bind(GameGuardService.class).to(GameGuardServiceImpl.class).in(
+ Scopes.SINGLETON);
bind(ScriptingService.class).to(ScriptingServiceImpl.class).in(
Scopes.SINGLETON);
bind(TemplateService.class).to(XMLTemplateService.class).in(
@@ -97,6 +103,8 @@ public class ServiceModule extends AbstractModule {
.in(Scopes.SINGLETON);
bind(CharacterService.class).to(CharacterServiceImpl.class).in(
Scopes.SINGLETON);
+ bind(AttackService.class).to(AttackServiceImpl.class).in(
+ Scopes.SINGLETON);
bind(NPCService.class).to(NPCServiceImpl.class).in(Scopes.SINGLETON);
bind(WorldService.class).to(WorldServiceImpl.class)
diff --git a/src/main/java/com/l2jserver/service/game/AttackServiceImpl.java b/src/main/java/com/l2jserver/service/game/AttackServiceImpl.java
index 0fc1d3f1c..ac35a3fa6 100644
--- a/src/main/java/com/l2jserver/service/game/AttackServiceImpl.java
+++ b/src/main/java/com/l2jserver/service/game/AttackServiceImpl.java
@@ -21,8 +21,13 @@ import java.util.concurrent.Callable;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.l2jserver.model.server.AttackHit;
+import com.l2jserver.model.server.attack.AttackCalculator;
+import com.l2jserver.model.server.attack.AttackCalculatorContext;
+import com.l2jserver.model.server.attack.PhysicalAttackCalculator;
import com.l2jserver.model.world.Actor;
+import com.l2jserver.model.world.actor.event.ActorAttackHitEvent;
import com.l2jserver.service.AbstractService;
+import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.core.threading.AsyncFuture;
import com.l2jserver.service.core.threading.ThreadService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
@@ -30,7 +35,13 @@ import com.l2jserver.service.game.world.event.WorldEventDispatcher;
/**
* @author Rogiel
*/
+@Depends({ ThreadService.class })
public class AttackServiceImpl extends AbstractService implements AttackService {
+ /**
+ * Calculator used to compute physical attacks
+ */
+ private static final AttackCalculator PHYSICAL_ATTACK_CALCULATOR = new PhysicalAttackCalculator();
+
/**
* The {@link ThreadService} is used to schedule asynchronous attacks
*/
@@ -39,7 +50,6 @@ public class AttackServiceImpl extends AbstractService implements AttackService
* The {@link WorldEventDispatcher} is used to dispatch attack events to the
* world
*/
- @SuppressWarnings("unused")
private final WorldEventDispatcher eventDispatcher;
@Inject
@@ -67,12 +77,10 @@ public class AttackServiceImpl extends AbstractService implements AttackService
/**
* The attacker
*/
- @SuppressWarnings("unused")
private final Actor attacker;
/**
* The target
*/
- @SuppressWarnings("unused")
private final Actor target;
public AttackCallable(Actor attacker, Actor target) {
@@ -82,8 +90,15 @@ public class AttackServiceImpl extends AbstractService implements AttackService
@Override
public AttackHit call() throws Exception {
-
- return null;
+ final double damage = PHYSICAL_ATTACK_CALCULATOR
+ .calculate(new AttackCalculatorContext(attacker, target));
+ // TODO calculate miss
+ // TODO calculate critical
+ // TODO calculate soulshot
+
+ final AttackHit hit = new AttackHit(attacker, target, damage);
+ eventDispatcher.dispatch(new ActorAttackHitEvent(hit));
+ return hit;
}
}
}
diff --git a/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java b/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java
index 9c8d32ad7..47856ab01 100644
--- a/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java
+++ b/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java
@@ -21,6 +21,7 @@ import com.google.inject.Inject;
import com.l2jserver.db.dao.ItemDAO;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.SystemMessage;
+import com.l2jserver.game.net.packet.server.SM_ATTACK;
import com.l2jserver.game.net.packet.server.SM_CHAR_INFO;
import com.l2jserver.game.net.packet.server.SM_CHAR_INFO_BROADCAST;
import com.l2jserver.game.net.packet.server.SM_CHAR_INFO_EXTRA;
@@ -32,7 +33,6 @@ import com.l2jserver.game.net.packet.server.SM_NPC_INFO;
import com.l2jserver.game.net.packet.server.SM_OBJECT_REMOVE;
import com.l2jserver.game.net.packet.server.SM_TARGET;
import com.l2jserver.model.id.object.CharacterID;
-import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.L2Character.CharacterMoveType;
@@ -40,6 +40,7 @@ import com.l2jserver.model.world.L2Character.CharacterState;
import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.PositionableObject;
import com.l2jserver.model.world.WorldObject;
+import com.l2jserver.model.world.actor.event.ActorAttackHitEvent;
import com.l2jserver.model.world.character.event.CharacterEnterWorldEvent;
import com.l2jserver.model.world.character.event.CharacterEvent;
import com.l2jserver.model.world.character.event.CharacterLeaveWorldEvent;
@@ -54,6 +55,7 @@ import com.l2jserver.model.world.player.event.PlayerTeleportedEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportingEvent;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
+import com.l2jserver.service.game.AttackService;
import com.l2jserver.service.game.chat.ChatChannel;
import com.l2jserver.service.game.chat.ChatChannelListener;
import com.l2jserver.service.game.chat.ChatMessageDestination;
@@ -83,7 +85,7 @@ import com.l2jserver.util.geometry.Point3D;
* @author Rogiel
*/
@Depends({ WorldService.class, ChatService.class, NetworkService.class,
- SpawnService.class })
+ SpawnService.class, AttackService.class, GameGuardService.class })
public class CharacterServiceImpl extends AbstractService implements
CharacterService {
/**
@@ -152,6 +154,9 @@ public class CharacterServiceImpl extends AbstractService implements
itemDao.loadInventory(character);
character.setOnline(true);
+
+ // inventory interfere on calculators
+ character.getStats().updateCalculators();
// chat listener
final ChatChannelListener globalChatListener = new ChatChannelListener() {
@@ -231,6 +236,11 @@ public class CharacterServiceImpl extends AbstractService implements
} else if (e instanceof PlayerTeleportedEvent
|| e instanceof CharacterEnterWorldEvent) {
broadcast(conn, character);
+ } else if (e instanceof ActorAttackHitEvent) {
+ conn.write(new SM_ATTACK(((ActorAttackHitEvent) e).getHit()));
+ conn.sendSystemMessage(SystemMessage.YOU_DID_S1_DMG,
+ (int) ((ActorAttackHitEvent) e).getHit()
+ .getDamage());
}
// keep listener alive
return true;
@@ -369,10 +379,6 @@ public class CharacterServiceImpl extends AbstractService implements
// check if this Actor can be attacked
if (target instanceof NPC) {
final NPC npc = (NPC) target;
- final NPCTemplate template = npc.getTemplate();
- if (!template.isAttackable()) {
- throw new ActorIsNotAttackableServiceException();
- }
// first try to target this, if it is not already
target(character, target);
diff --git a/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java b/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java
index f102e64db..154969660 100644
--- a/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java
+++ b/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java
@@ -27,9 +27,7 @@ import com.google.inject.Injector;
import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.client.CM_CHAR_ACTION.CharacterAction;
-import com.l2jserver.game.net.packet.server.SM_ATTACK;
-import com.l2jserver.model.server.AttackHit;
-import com.l2jserver.model.server.AttackHit.AttackHitFlag;
+import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.NPC.NPCState;
@@ -38,6 +36,7 @@ import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.core.threading.AsyncFuture;
import com.l2jserver.service.core.threading.ThreadService;
+import com.l2jserver.service.game.AttackService;
import com.l2jserver.service.game.character.CannotSetTargetServiceException;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException;
@@ -54,7 +53,7 @@ import com.l2jserver.util.geometry.Point3D;
* @author Rogiel
*/
@Depends({ SpawnService.class, NetworkService.class, CharacterService.class,
- ThreadService.class })
+ ThreadService.class, AttackService.class })
public class NPCServiceImpl extends AbstractService implements NPCService {
/**
* The {@link SpawnService} used to spawn the {@link NPC} instances
@@ -72,6 +71,10 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
* The {@link ThreadService}
*/
private final ThreadService threadService;
+ /**
+ * The {@link AttackService}
+ */
+ private final AttackService attackService;
/**
* The {@link NPCDAO}
@@ -93,11 +96,13 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
@Inject
public NPCServiceImpl(SpawnService spawnService,
NetworkService networkService, CharacterService characterService,
- ThreadService threadService, NPCDAO npcDao, Injector injector) {
+ ThreadService threadService, AttackService attackService,
+ NPCDAO npcDao, Injector injector) {
this.spawnService = spawnService;
this.networkService = networkService;
this.characterService = characterService;
this.threadService = threadService;
+ this.attackService = attackService;
this.npcDao = npcDao;
this.injector = injector;
}
@@ -183,9 +188,12 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
Preconditions.checkNotNull(conn, "conn");
Preconditions.checkNotNull(attacker, "attacker");
- conn.write(new SM_ATTACK(conn.getCharacter(), new AttackHit(
- conn.getCharacter(), npc, AttackHitFlag.MISS,
- AttackHitFlag.SOULSHOT)));
+ final NPCTemplate template = npc.getTemplate();
+ if (!template.isAttackable()) {
+ throw new NotAttackableNPCServiceException();
+ }
+
+ attackService.attack(attacker, npc);
}
private NPCController getController(NPC npc) {
diff --git a/src/main/java/com/l2jserver/service/network/gameguard/GameGuardService.java b/src/main/java/com/l2jserver/service/network/gameguard/GameGuardService.java
index 8c352397d..c8cfbf9de 100644
--- a/src/main/java/com/l2jserver/service/network/gameguard/GameGuardService.java
+++ b/src/main/java/com/l2jserver/service/network/gameguard/GameGuardService.java
@@ -19,13 +19,14 @@ package com.l2jserver.service.network.gameguard;
import java.util.concurrent.Future;
import com.l2jserver.game.net.Lineage2Connection;
+import com.l2jserver.service.Service;
/**
* This service is responsible for querying and validating GameGuard packets
*
* @author Rogiel
*/
-public interface GameGuardService {
+public interface GameGuardService extends Service {
/**
* Queries the client GameGuard for an response
*
diff --git a/src/main/java/com/l2jserver/service/network/gameguard/GameGuardServiceImpl.java b/src/main/java/com/l2jserver/service/network/gameguard/GameGuardServiceImpl.java
index be117a4ba..a60026bde 100644
--- a/src/main/java/com/l2jserver/service/network/gameguard/GameGuardServiceImpl.java
+++ b/src/main/java/com/l2jserver/service/network/gameguard/GameGuardServiceImpl.java
@@ -18,7 +18,6 @@ package com.l2jserver.service.network.gameguard;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.Future;
@@ -29,8 +28,10 @@ import com.google.common.util.concurrent.AbstractFuture;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.server.SM_GG_QUERY;
import com.l2jserver.service.AbstractService;
+import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
+import com.l2jserver.service.network.NetworkService;
import com.l2jserver.util.factory.CollectionFactory;
/**
@@ -38,6 +39,7 @@ import com.l2jserver.util.factory.CollectionFactory;
*
* @author Rogiel
*/
+@Depends({ NetworkService.class })
public class GameGuardServiceImpl extends AbstractService implements
GameGuardService {
/**
@@ -106,9 +108,10 @@ public class GameGuardServiceImpl extends AbstractService implements
* @return true if key is valid
*/
private boolean validate(Lineage2Connection conn, byte[] key) {
- synchronized (digester) {
- return Arrays.equals(VALID_KEY_SHA1, digester.digest(key));
- }
+ // synchronized (digester) {
+ // return Arrays.equals(VALID_KEY_SHA1, digester.digest(key));
+ // }
+ return true;
}
@Override
diff --git a/src/main/java/com/l2jserver/test/XMLMappingTest.java b/src/main/java/com/l2jserver/test/XMLMappingTest.java
index 2995f022d..e5222b0a9 100644
--- a/src/main/java/com/l2jserver/test/XMLMappingTest.java
+++ b/src/main/java/com/l2jserver/test/XMLMappingTest.java
@@ -74,6 +74,6 @@ public class XMLMappingTest {
final CharacterTemplate t = (CharacterTemplate) u.unmarshal(new File(
"data/templates/character/HumanFighter.xml"));
System.out.println(t.getID());
- System.out.println(t.getCharacterClass());
+ System.out.println(t.getBasePhysicalAttack());
}
}
diff --git a/src/main/java/com/l2jserver/util/calculator/AbstractFunction.java b/src/main/java/com/l2jserver/util/calculator/AbstractDoubleFunction.java
similarity index 87%
rename from src/main/java/com/l2jserver/util/calculator/AbstractFunction.java
rename to src/main/java/com/l2jserver/util/calculator/AbstractDoubleFunction.java
index 72d66dcfa..675f865ac 100644
--- a/src/main/java/com/l2jserver/util/calculator/AbstractFunction.java
+++ b/src/main/java/com/l2jserver/util/calculator/AbstractDoubleFunction.java
@@ -20,11 +20,11 @@ package com.l2jserver.util.calculator;
* @author Rogiel
*
*/
-public abstract class AbstractFunction implements
+public abstract class AbstractDoubleFunction implements
Function {
private final int order;
- public AbstractFunction(int order) {
+ public AbstractDoubleFunction(int order) {
this.order = order;
}
diff --git a/src/main/java/com/l2jserver/util/calculator/DivisionFunction.java b/src/main/java/com/l2jserver/util/calculator/DivisionFunction.java
index 3ab1598fe..e76e765b6 100644
--- a/src/main/java/com/l2jserver/util/calculator/DivisionFunction.java
+++ b/src/main/java/com/l2jserver/util/calculator/DivisionFunction.java
@@ -22,7 +22,7 @@ package com.l2jserver.util.calculator;
*
* @author Rogiel
*/
-public class DivisionFunction extends AbstractFunction {
+public class DivisionFunction extends AbstractDoubleFunction {
/**
* The value
*/
diff --git a/src/main/java/com/l2jserver/util/calculator/Function.java b/src/main/java/com/l2jserver/util/calculator/Function.java
index d0cb337c6..102a2b31c 100644
--- a/src/main/java/com/l2jserver/util/calculator/Function.java
+++ b/src/main/java/com/l2jserver/util/calculator/Function.java
@@ -21,7 +21,7 @@ package com.l2jserver.util.calculator;
*
* @author Rogiel
*/
-public interface Function {
+public interface Function {
/**
* Performs the operation in the calculation process.
*
@@ -33,7 +33,7 @@ public interface Function {
* the input value
* @return the output value
*/
- double calculate(T ctx, double value);
+ double calculate(C ctx, double value);
/**
* @return the order this function will be executed
diff --git a/src/main/java/com/l2jserver/util/calculator/ModulusFunction.java b/src/main/java/com/l2jserver/util/calculator/ModulusFunction.java
index 8f1a06f8e..40b51fda2 100644
--- a/src/main/java/com/l2jserver/util/calculator/ModulusFunction.java
+++ b/src/main/java/com/l2jserver/util/calculator/ModulusFunction.java
@@ -22,7 +22,7 @@ package com.l2jserver.util.calculator;
*
* @author Rogiel
*/
-public class ModulusFunction extends AbstractFunction {
+public class ModulusFunction extends AbstractDoubleFunction {
public ModulusFunction(int order) {
super(order);
}
diff --git a/src/main/java/com/l2jserver/util/calculator/MultiplicationFunction.java b/src/main/java/com/l2jserver/util/calculator/MultiplicationFunction.java
index b946fc96c..cc91efe5f 100644
--- a/src/main/java/com/l2jserver/util/calculator/MultiplicationFunction.java
+++ b/src/main/java/com/l2jserver/util/calculator/MultiplicationFunction.java
@@ -22,7 +22,7 @@ package com.l2jserver.util.calculator;
*
* @author Rogiel
*/
-public class MultiplicationFunction extends AbstractFunction {
+public class MultiplicationFunction extends AbstractDoubleFunction {
/**
* The value
*/
diff --git a/src/main/java/com/l2jserver/util/calculator/NegateFunction.java b/src/main/java/com/l2jserver/util/calculator/NegateFunction.java
index 9981b598f..18208a1ec 100644
--- a/src/main/java/com/l2jserver/util/calculator/NegateFunction.java
+++ b/src/main/java/com/l2jserver/util/calculator/NegateFunction.java
@@ -22,7 +22,7 @@ package com.l2jserver.util.calculator;
*
* @author Rogiel
*/
-public class NegateFunction extends AbstractFunction {
+public class NegateFunction extends AbstractDoubleFunction {
public NegateFunction(int order) {
super(order);
}
diff --git a/src/main/java/com/l2jserver/util/calculator/RoundFunction.java b/src/main/java/com/l2jserver/util/calculator/RoundFunction.java
index fc1bfb8a0..e2a861591 100644
--- a/src/main/java/com/l2jserver/util/calculator/RoundFunction.java
+++ b/src/main/java/com/l2jserver/util/calculator/RoundFunction.java
@@ -21,7 +21,7 @@ package com.l2jserver.util.calculator;
*
* @author Rogiel
*/
-public class RoundFunction extends AbstractFunction {
+public class RoundFunction extends AbstractDoubleFunction {
public RoundFunction(int order) {
super(order);
}
diff --git a/src/main/java/com/l2jserver/util/calculator/SetFunction.java b/src/main/java/com/l2jserver/util/calculator/SetFunction.java
index d29620a54..65448abe9 100644
--- a/src/main/java/com/l2jserver/util/calculator/SetFunction.java
+++ b/src/main/java/com/l2jserver/util/calculator/SetFunction.java
@@ -21,7 +21,7 @@ package com.l2jserver.util.calculator;
*
* @author Rogiel
*/
-public class SetFunction extends AbstractFunction {
+public class SetFunction extends AbstractDoubleFunction {
/**
* The value
*/
diff --git a/src/main/java/com/l2jserver/util/calculator/Calculator.java b/src/main/java/com/l2jserver/util/calculator/SimpleCalculator.java
similarity index 76%
rename from src/main/java/com/l2jserver/util/calculator/Calculator.java
rename to src/main/java/com/l2jserver/util/calculator/SimpleCalculator.java
index 7c9021c46..72be07bee 100644
--- a/src/main/java/com/l2jserver/util/calculator/Calculator.java
+++ b/src/main/java/com/l2jserver/util/calculator/SimpleCalculator.java
@@ -16,11 +16,8 @@
*/
package com.l2jserver.util.calculator;
-import java.util.Collections;
+import java.util.Arrays;
import java.util.Comparator;
-import java.util.List;
-
-import com.l2jserver.util.factory.CollectionFactory;
/**
* An calculator is used to compute data and outputs its result. Note also, that
@@ -28,20 +25,21 @@ import com.l2jserver.util.factory.CollectionFactory;
*
* @author Rogiel
*/
-public class Calculator extends
- AbstractFunction {
+public class SimpleCalculator extends
+ AbstractDoubleFunction {
/**
* List of operations in this calculator
*/
- private final List> functions = CollectionFactory
- .newList();
+ private Function super T>[] functions;
/**
* Creates a new empty calculator. Functions can be add using
* {@link #add(int, Function)}.
*/
- public Calculator() {
+ @SuppressWarnings("unchecked")
+ public SimpleCalculator() {
super(0x00);
+ functions = new Function[0];
}
/**
@@ -51,11 +49,9 @@ public class Calculator extends
* @param functions
* the calculator functions
*/
- public Calculator(Function super T>... functions) {
+ public SimpleCalculator(Function super T>... functions) {
super(0x00);
- for (final Function super T> func : functions) {
- this.functions.add(func);
- }
+ this.functions = functions;
}
/**
@@ -70,8 +66,9 @@ public class Calculator extends
* the operation
*/
public void add(Function super T> function) {
- functions.add(function);
- Collections.sort(functions, FunctionOrderComparator.SHARED_INSTANCE);
+ functions = Arrays.copyOf(functions, functions.length + 1);
+ functions[functions.length - 1] = function;
+ Arrays.sort(functions, FunctionOrderComparator.SHARED_INSTANCE);
}
/**
@@ -84,12 +81,12 @@ public class Calculator extends
* @param calculator
* the calculator
*/
- public void importFunctions(Calculator super T> calculator) {
+ public void importFunctions(SimpleCalculator super T> calculator) {
for (final Function super T> function : calculator.functions) {
- if (function instanceof Calculator) {
- importFunctions((Calculator super T>) function);
+ if (function instanceof SimpleCalculator) {
+ importFunctions((SimpleCalculator super T>) function);
} else {
- functions.add(function);
+ add(function);
}
}
}
@@ -102,12 +99,13 @@ public class Calculator extends
* @param calculator
* the calculator
*/
- public void removeFunctions(Calculator super T> calculator) {
+ public void removeFunctions(SimpleCalculator super T> calculator) {
for (final Function super T> function : calculator.functions) {
- if (function instanceof Calculator) {
- removeFunctions((Calculator super T>) function);
+ if (function instanceof SimpleCalculator) {
+ removeFunctions((SimpleCalculator super T>) function);
} else {
- functions.remove(function);
+ // TODO
+ // remove(function);
}
}
}
diff --git a/src/main/java/com/l2jserver/util/calculator/SubtractFunction.java b/src/main/java/com/l2jserver/util/calculator/SubtractFunction.java
index dc20a7c0d..17faa1602 100644
--- a/src/main/java/com/l2jserver/util/calculator/SubtractFunction.java
+++ b/src/main/java/com/l2jserver/util/calculator/SubtractFunction.java
@@ -22,7 +22,7 @@ package com.l2jserver.util.calculator;
*
* @author Rogiel
*/
-public class SubtractFunction extends AbstractFunction {
+public class SubtractFunction extends AbstractDoubleFunction {
/**
* The value
*/
diff --git a/src/main/java/com/l2jserver/util/calculator/SumFunction.java b/src/main/java/com/l2jserver/util/calculator/SumFunction.java
index c1d00089f..141fc4c38 100644
--- a/src/main/java/com/l2jserver/util/calculator/SumFunction.java
+++ b/src/main/java/com/l2jserver/util/calculator/SumFunction.java
@@ -22,7 +22,7 @@ package com.l2jserver.util.calculator;
*
* @author Rogiel
*/
-public class SumFunction extends AbstractFunction {
+public class SumFunction extends AbstractDoubleFunction {
/**
* The value
*/
diff --git a/src/test/java/com/l2jserver/service/game/scripting/impl/compiled/PrecompiledScriptCompilerTest.java b/src/test/java/com/l2jserver/service/game/scripting/impl/compiled/PrecompiledScriptCompilerTest.java
index 145cfe07d..38d1959d5 100644
--- a/src/test/java/com/l2jserver/service/game/scripting/impl/compiled/PrecompiledScriptCompilerTest.java
+++ b/src/test/java/com/l2jserver/service/game/scripting/impl/compiled/PrecompiledScriptCompilerTest.java
@@ -35,7 +35,6 @@ public class PrecompiledScriptCompilerTest {
// @Test
public void testCompileIterableOfFile() {
final PrecompiledScriptCompiler compiler = new PrecompiledScriptCompiler();
- @SuppressWarnings("unchecked")
final CompilationResult result = compiler.compile(FileUtils.listFiles(
new File("target/scripts/script/template"),
new String[] { "class" }, true));
diff --git a/src/test/java/com/l2jserver/util/calculator/CalculatorTest.java b/src/test/java/com/l2jserver/util/calculator/CalculatorTest.java
index 62894ed3c..3c9972a3e 100644
--- a/src/test/java/com/l2jserver/util/calculator/CalculatorTest.java
+++ b/src/test/java/com/l2jserver/util/calculator/CalculatorTest.java
@@ -27,7 +27,7 @@ import org.junit.Test;
public class CalculatorTest {
@Test
public void testSimple() {
- final Calculator calc = new Calculator();
+ final SimpleCalculator calc = new SimpleCalculator();
calc.add(new SetFunction(0, 10));
calc.add(new MultiplicationFunction(1, 2));
@@ -39,7 +39,7 @@ public class CalculatorTest {
@Test
public void testPercent() {
- final Calculator calc = new Calculator();
+ final SimpleCalculator calc = new SimpleCalculator();
calc.add(new SetFunction(0, 10));
calc.add(new MultiplicationFunction(1, 2));
@@ -51,7 +51,7 @@ public class CalculatorTest {
@Test
public void testComplex() {
- final Calculator calc = new Calculator();
+ final SimpleCalculator calc = new SimpleCalculator();
calc.add(new SetFunction(0, 10));
calc.add(new MultiplicationFunction(1, 2));
@@ -66,7 +66,7 @@ public class CalculatorTest {
@Test
public void testNesting() {
- final Calculator calc1 = new Calculator();
+ final SimpleCalculator calc1 = new SimpleCalculator();
final CalculatorContext ctx1 = new CalculatorContext();
calc1.add(new SetFunction(0, 10));
@@ -78,7 +78,7 @@ public class CalculatorTest {
Assert.assertEquals(5.0, calc1.calculate(ctx1));
- final Calculator calc2 = new Calculator();
+ final SimpleCalculator calc2 = new SimpleCalculator();
final CalculatorContext ctx2 = new CalculatorContext();
calc2.add(new MultiplicationFunction(0, 2));
@@ -89,7 +89,7 @@ public class CalculatorTest {
Assert.assertEquals(-2.5, calc2.calculate(ctx2));
- final Calculator calc3 = new Calculator();
+ final SimpleCalculator calc3 = new SimpleCalculator();
final CalculatorContext ctx3 = new CalculatorContext();
calc3.add(calc1);
calc3.add(calc2);
@@ -102,7 +102,7 @@ public class CalculatorTest {
@Test
public void testImporting() {
- final Calculator calc1 = new Calculator();
+ final SimpleCalculator calc1 = new SimpleCalculator();
final CalculatorContext ctx1 = new CalculatorContext();
calc1.add(new SetFunction(0, 10));
@@ -114,7 +114,7 @@ public class CalculatorTest {
Assert.assertEquals(5.0, calc1.calculate(ctx1));
- final Calculator calc2 = new Calculator();
+ final SimpleCalculator calc2 = new SimpleCalculator();
final CalculatorContext ctx2 = new CalculatorContext();
calc2.add(new MultiplicationFunction(1, 2));
@@ -125,7 +125,7 @@ public class CalculatorTest {
Assert.assertEquals(-2.5, calc2.calculate(ctx2));
- final Calculator calc3 = new Calculator();
+ final SimpleCalculator calc3 = new SimpleCalculator();
final CalculatorContext ctx3 = new CalculatorContext();
calc3.importFunctions(calc1);
calc3.importFunctions(calc2);
@@ -138,7 +138,7 @@ public class CalculatorTest {
@Test
public void testRounding() {
- final Calculator calc = new Calculator();
+ final SimpleCalculator calc = new SimpleCalculator();
calc.add(new MultiplicationFunction(0, 2));
calc.add(new PercentFunction(1, 75));
diff --git a/src/tool/java/com/l2jserver/model/template/NPCTemplateConverter.java b/src/tool/java/com/l2jserver/model/template/NPCTemplateConverter.java
index e0107ecab..e5c7b0342 100644
--- a/src/tool/java/com/l2jserver/model/template/NPCTemplateConverter.java
+++ b/src/tool/java/com/l2jserver/model/template/NPCTemplateConverter.java
@@ -87,7 +87,6 @@ public class NPCTemplateConverter {
private static Collection htmlScannedFiles;
private static TeleportationTemplateContainer teleportation = new TeleportationTemplateContainer();
- @SuppressWarnings("unchecked")
public static void main(String[] args) throws SQLException, IOException,
ClassNotFoundException, JAXBException {
controllers.put("L2Teleporter", TeleporterController.class);
diff --git a/src/tool/java/com/l2jserver/tool/conversor/itemtemplate/ItemTemplateConversor.java b/src/tool/java/com/l2jserver/tool/conversor/itemtemplate/ItemTemplateConversor.java
index 0c421e0b9..be6d185d5 100644
--- a/src/tool/java/com/l2jserver/tool/conversor/itemtemplate/ItemTemplateConversor.java
+++ b/src/tool/java/com/l2jserver/tool/conversor/itemtemplate/ItemTemplateConversor.java
@@ -36,7 +36,6 @@ public class ItemTemplateConversor {
template = IOUtils.toString(ItemTemplateConversor.class
.getResourceAsStream("ItemTemplateBase.txt"));
- @SuppressWarnings("unchecked")
Collection files = FileUtils
.listFiles(
new File(