mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-07 16:03:10 +00:00
Several performance improvements, monster template and xml updates and
fixed bug while logging-in Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
@@ -81,7 +81,6 @@ public class CM_ENTER_WORLD extends AbstractClientPacket {
|
||||
try {
|
||||
characterService.enterWorld(id.getObject());
|
||||
} catch (SpawnPointNotFoundServiceException e) {
|
||||
|
||||
} catch (AlreadySpawnedServiceException e) {
|
||||
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class CM_PROTOCOL_VERSION extends AbstractClientPacket {
|
||||
log.debug("Client protocol version: {}", version);
|
||||
conn.setVersion(version);
|
||||
if (L2JConstant.SUPPORTED_PROTOCOL != version) {
|
||||
log.info("Incorrect protocol version: {}. Only {} is supported.",
|
||||
log.warn("Incorrect protocol version: {}. Only {} is supported.",
|
||||
version, L2JConstant.SUPPORTED_PROTOCOL);
|
||||
// notify wrong protocol and close connection
|
||||
conn.write(new SM_KEY(inKey, false)).addListener(
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
*/
|
||||
package com.l2jserver.model.id;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.SoftReference;
|
||||
|
||||
import com.l2jserver.model.template.Template;
|
||||
|
||||
/**
|
||||
@@ -25,6 +28,8 @@ import com.l2jserver.model.template.Template;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public abstract class TemplateID<T extends Template<?>, I> extends ID<I> {
|
||||
private Reference<T> cached;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
@@ -40,5 +45,16 @@ public abstract class TemplateID<T extends Template<?>, I> extends ID<I> {
|
||||
*
|
||||
* @return the {@link Template} if existent, <tt>null</tt> otherwise
|
||||
*/
|
||||
public abstract T getTemplate();
|
||||
public T getTemplate() {
|
||||
if (cached == null || cached.get() == null)
|
||||
cached = new SoftReference<T>(loadTemplate());
|
||||
return cached.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Template} associated with this {@link ID}
|
||||
*
|
||||
* @return the {@link Template} if existent, <tt>null</tt> otherwise
|
||||
*/
|
||||
protected abstract T loadTemplate();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ActorTemplateID<T extends ActorTemplate<?>> extends
|
||||
|
||||
@Override
|
||||
@XmlTransient
|
||||
public T getTemplate() {
|
||||
public T loadTemplate() {
|
||||
return templateService.getTemplate(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ItemTemplateID extends TemplateID<ItemTemplate, Integer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemTemplate getTemplate() {
|
||||
public ItemTemplate loadTemplate() {
|
||||
return templateService.getTemplate(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SkillTemplateID extends TemplateID<SkillTemplate, Integer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SkillTemplate getTemplate() {
|
||||
public SkillTemplate loadTemplate() {
|
||||
return templateService.getTemplate(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class TeleportationTemplateID extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public TeleportationTemplate getTemplate() {
|
||||
public TeleportationTemplate loadTemplate() {
|
||||
return templateService.getTemplate(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.l2jserver.game.net.packet.server.SM_STATUS_UPDATE.Stat;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.service.game.character.CharacterService;
|
||||
import com.l2jserver.service.game.npc.NPCService;
|
||||
import com.l2jserver.util.exception.L2Exception;
|
||||
|
||||
/**
|
||||
@@ -36,13 +37,23 @@ public class MonsterController extends BaseNPCController {
|
||||
*/
|
||||
@Inject
|
||||
protected CharacterService charService;
|
||||
/**
|
||||
* The {@link NPCService}
|
||||
*/
|
||||
@Inject
|
||||
protected NPCService npcService;
|
||||
|
||||
@Override
|
||||
public void action(NPC npc, Lineage2Connection conn, L2Character character,
|
||||
public void action(NPC mob, Lineage2Connection conn, L2Character character,
|
||||
String... args) throws L2Exception {
|
||||
// send hp update
|
||||
conn.write(new SM_STATUS_UPDATE(npc).add(Stat.MAX_HP,
|
||||
(int) npc.getTemplate().getMaximumHP()).add(Stat.HP,
|
||||
(int) npc.getHP()));
|
||||
if (mob.getID().equals(character.getTargetID())) {
|
||||
charService.attack(character, mob);
|
||||
} else {
|
||||
charService.target(character, mob);
|
||||
conn.write(new SM_STATUS_UPDATE(mob).add(Stat.MAX_HP,
|
||||
(int) mob.getTemplate().getMaximumHP()).add(Stat.HP,
|
||||
(int) mob.getHP()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Scopes;
|
||||
import com.l2jserver.service.cache.CacheService;
|
||||
import com.l2jserver.service.cache.EhCacheService;
|
||||
import com.l2jserver.service.cache.SoftCacheService;
|
||||
import com.l2jserver.service.configuration.ConfigurationService;
|
||||
import com.l2jserver.service.configuration.ProxyConfigurationService;
|
||||
import com.l2jserver.service.core.Log4JLoggingService;
|
||||
@@ -78,7 +78,8 @@ public class ServiceModule extends AbstractModule {
|
||||
Scopes.SINGLETON);
|
||||
bind(ConfigurationService.class).to(ProxyConfigurationService.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
bind(CacheService.class).to(EhCacheService.class).in(Scopes.SINGLETON);
|
||||
bind(CacheService.class).to(SoftCacheService.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
|
||||
bind(DatabaseService.class).to(JDBCDatabaseService.class).in(
|
||||
Scopes.SINGLETON);
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.l2jserver.service.cache;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -31,7 +30,7 @@ import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
|
||||
/**
|
||||
* This {@link Cache} service implementation uses a {@link SoftReference} to
|
||||
* This {@link Cache} service implementation uses a {@link WeakReference} to
|
||||
* store values.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
|
||||
@@ -162,9 +162,6 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
}
|
||||
};
|
||||
|
||||
// start broadcasting -- will broadcast all nearby objects
|
||||
broadcastService.broadcast(conn);
|
||||
|
||||
// leave world event
|
||||
eventDispatcher.addListener(id, new CharacterListener() {
|
||||
@Override
|
||||
@@ -205,6 +202,9 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
conn.sendMessage("This an an development version for l2jserver 2.0");
|
||||
conn.sendMessage("Please note that many of the features are not yet implemented.");
|
||||
|
||||
// start broadcasting -- will broadcast all nearby objects
|
||||
broadcastService.broadcast(conn);
|
||||
|
||||
// characters start in run mode
|
||||
try {
|
||||
run(character);
|
||||
@@ -282,9 +282,12 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
// check if this Actor can be attacked
|
||||
if (target instanceof NPC) {
|
||||
final NPC npc = (NPC) target;
|
||||
// first try to target this, if it is not already
|
||||
target(character, target);
|
||||
|
||||
// first try to target this, if it is not already
|
||||
if (!npc.getID().equals(character.getTargetID()))
|
||||
target(character, target);
|
||||
|
||||
// now attack the npc
|
||||
npcService.attack(npc, conn, character);
|
||||
} else {
|
||||
// TODO throw an exception
|
||||
|
||||
@@ -115,9 +115,6 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
Preconditions.checkNotNull(action, "action");
|
||||
|
||||
if (npc.getTemplate().isTargetable())
|
||||
characterService.target(character, npc);
|
||||
|
||||
final Lineage2Connection conn = networkService.discover(character
|
||||
.getID());
|
||||
try {
|
||||
@@ -136,9 +133,6 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
|
||||
if (args == null)
|
||||
args = new String[0];
|
||||
|
||||
if (npc.getTemplate().isTargetable())
|
||||
characterService.target(character, npc);
|
||||
|
||||
final Lineage2Connection conn = networkService.discover(character
|
||||
.getID());
|
||||
try {
|
||||
|
||||
@@ -33,7 +33,7 @@ public class RangeFilter implements WorldObjectFilter<PositionableObject> {
|
||||
/**
|
||||
* The desired maximum distance of the object
|
||||
*/
|
||||
private final int range;
|
||||
private final double range;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
@@ -47,13 +47,14 @@ public class RangeFilter implements WorldObjectFilter<PositionableObject> {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
Preconditions.checkState(range >= 0, "range < 0");
|
||||
this.object = object;
|
||||
this.range = range;
|
||||
this.range = Math.pow(range, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(PositionableObject other) {
|
||||
if (other == null)
|
||||
return false;
|
||||
return other.getPosition().getDistance(object.getPosition()) <= range;
|
||||
|
||||
return other.getPosition().getDistanceSquared(object.getPosition()) <= range;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
*/
|
||||
package com.l2jserver.service.game.world.filter.impl;
|
||||
|
||||
import org.apache.commons.math.util.FastMath;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.l2jserver.model.world.PositionableObject;
|
||||
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
|
||||
@@ -34,7 +36,11 @@ public class RangePointFilter implements WorldObjectFilter<PositionableObject> {
|
||||
/**
|
||||
* The desired maximum distance of the object
|
||||
*/
|
||||
private final int range;
|
||||
private final double range;
|
||||
/**
|
||||
* The <tt>range</tt> multiplied by two
|
||||
*/
|
||||
private final double doubleRange;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
@@ -48,13 +54,25 @@ public class RangePointFilter implements WorldObjectFilter<PositionableObject> {
|
||||
Preconditions.checkNotNull(point, "point");
|
||||
Preconditions.checkState(range >= 0, "range < 0");
|
||||
this.point = point;
|
||||
this.range = range;
|
||||
this.range = Math.pow(range, 2);
|
||||
this.doubleRange = range * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(PositionableObject other) {
|
||||
if (other == null)
|
||||
return false;
|
||||
return other.getPosition().getDistance(point.getCoordinate()) <= range;
|
||||
final double dx = FastMath.abs(point.getX() - other.getPoint().getX());
|
||||
final double dy = FastMath.abs(point.getY() - other.getPoint().getY());
|
||||
final double dz = FastMath.abs(point.getZ() - other.getPoint().getZ());
|
||||
|
||||
if (dx > doubleRange)
|
||||
return false;
|
||||
if (dy > doubleRange)
|
||||
return false;
|
||||
if (dz > doubleRange)
|
||||
return false;
|
||||
|
||||
return ((dx * dx) + (dy * dy) + (dz * dz)) <= range;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class BroadcastServiceImpl extends AbstractService implements
|
||||
final CharacterID id = character.getID();
|
||||
|
||||
// broadcast everything nearby
|
||||
broadcast(conn);
|
||||
//broadcast(conn);
|
||||
|
||||
// event broadcast listener
|
||||
// this listener will be filtered so that only interesting events are
|
||||
|
||||
@@ -71,6 +71,19 @@ public class Coordinate {
|
||||
return Vector3D.distance(vector, other.vector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the squared distance between <tt>this</tt> coordinate and
|
||||
* <tt>other</tt>. This method is slighter faster then
|
||||
* {@link #getDistance(Coordinate)}.
|
||||
*
|
||||
* @param other
|
||||
* the other coordinate
|
||||
* @return the calculated distance
|
||||
*/
|
||||
public double getDistanceSquared(Coordinate other) {
|
||||
return Vector3D.distanceSq(vector, other.vector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance from the 3 points
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user