1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-10 09:22:49 +00:00

Semi-working attack service

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-30 20:02:19 -03:00
parent 52d4be0bf2
commit ae3007559f
61 changed files with 537 additions and 181 deletions

View File

@@ -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<Service> knownServices = CollectionFactory.newSet();
@Inject

View File

@@ -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)

View File

@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
*/
@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;
}
}
}

View File

@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
*/
@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);

View File

@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
*/
@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) {

View File

@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface GameGuardService {
public interface GameGuardService extends Service {
/**
* Queries the client GameGuard for an response
*

View File

@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
*/
@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