1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-06 07:32:46 +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

@@ -1,4 +1,4 @@
jdbc.url = jdbc:h2:./data/database jdbc.url = jdbc:mysql://localhost/l2jserver2
jdbc.driver = org.h2.Driver jdbc.driver = com.mysql.jdbc.Driver
jdbc.username = l2j jdbc.username = l2j
jdbc.password = changeme jdbc.password = changeme

View File

@@ -1,7 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<item id="1" icon="icon.etc_adena_i00"> <item id="1" icon="icon.etc_adena_i00">
<name>Adena</name> <name>Short Sword</name>
<material>GOLD</material> <material>STEEL</material>
<effect type="IMMEDIATE" /> <effect type="IMMEDIATE" />
<price>1</price> <price>1</price>
<stats>
<physicalDamage>
<set order="0x80">8</set>
</physicalDamage>
<magicalDamage>
<set order="0x80">6</set>
</magicalDamage>
<criticalChance>
<set order="0x80">8</set>
</criticalChance>
<physicalAttackSpeed>
<set order="0x80">379</set>
</physicalAttackSpeed>
</stats>
</item> </item>

View File

@@ -24,11 +24,11 @@ import com.l2jserver.db.dao.CharacterFriendDAO;
import com.l2jserver.db.dao.ClanDAO; import com.l2jserver.db.dao.ClanDAO;
import com.l2jserver.db.dao.ItemDAO; import com.l2jserver.db.dao.ItemDAO;
import com.l2jserver.db.dao.NPCDAO; import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.db.dao.h2.H2CharacterDAO; import com.l2jserver.db.dao.jdbc.h2.H2CharacterDAO;
import com.l2jserver.db.dao.h2.H2CharacterFriendDAO; import com.l2jserver.db.dao.jdbc.h2.H2CharacterFriendDAO;
import com.l2jserver.db.dao.h2.H2ClanDAO; import com.l2jserver.db.dao.jdbc.h2.H2ClanDAO;
import com.l2jserver.db.dao.h2.H2ItemDAO; import com.l2jserver.db.dao.jdbc.h2.H2ItemDAO;
import com.l2jserver.db.dao.h2.H2NPCDAO; import com.l2jserver.db.dao.jdbc.h2.H2NPCDAO;
/** /**
* Google Guice {@link Module} for H2 DAOs * Google Guice {@link Module} for H2 DAOs

View File

@@ -24,11 +24,11 @@ import com.l2jserver.db.dao.CharacterFriendDAO;
import com.l2jserver.db.dao.ClanDAO; import com.l2jserver.db.dao.ClanDAO;
import com.l2jserver.db.dao.ItemDAO; import com.l2jserver.db.dao.ItemDAO;
import com.l2jserver.db.dao.NPCDAO; import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.db.dao.mysql5.MySQL5CharacterDAO; import com.l2jserver.db.dao.jdbc.mysql5.MySQL5CharacterDAO;
import com.l2jserver.db.dao.mysql5.MySQL5CharacterFriendDAO; import com.l2jserver.db.dao.jdbc.mysql5.MySQL5CharacterFriendDAO;
import com.l2jserver.db.dao.mysql5.MySQL5ClanDAO; import com.l2jserver.db.dao.jdbc.mysql5.MySQL5ClanDAO;
import com.l2jserver.db.dao.mysql5.MySQL5ItemDAO; import com.l2jserver.db.dao.jdbc.mysql5.MySQL5ItemDAO;
import com.l2jserver.db.dao.mysql5.MySQL5NPCDAO; import com.l2jserver.db.dao.jdbc.mysql5.MySQL5NPCDAO;
/** /**
* Google Guice {@link Module} for MySQL5 DAOs * Google Guice {@link Module} for MySQL5 DAOs

View File

@@ -55,7 +55,7 @@ import com.l2jserver.util.geometry.Point3D;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class JDBCCharacterDAO extends public abstract class JDBCCharacterDAO extends
AbstractJDBCDAO<L2Character, CharacterID> implements CharacterDAO { AbstractJDBCDAO<L2Character, CharacterID> implements CharacterDAO {
/** /**
* The {@link CharacterID} factory * The {@link CharacterID} factory

View File

@@ -42,7 +42,7 @@ import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class JDBCCharacterFriendDAO extends public abstract class JDBCCharacterFriendDAO extends
AbstractJDBCDAO<CharacterFriend, FriendID> implements AbstractJDBCDAO<CharacterFriend, FriendID> implements
CharacterFriendDAO { CharacterFriendDAO {
/** /**

View File

@@ -41,7 +41,7 @@ import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class JDBCClanDAO extends AbstractJDBCDAO<Clan, ClanID> implements public abstract class JDBCClanDAO extends AbstractJDBCDAO<Clan, ClanID> implements
ClanDAO { ClanDAO {
/** /**
* The {@link ClanID} factory * The {@link ClanID} factory

View File

@@ -48,7 +48,7 @@ import com.l2jserver.util.geometry.Coordinate;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class JDBCItemDAO extends AbstractJDBCDAO<Item, ItemID> implements public abstract class JDBCItemDAO extends AbstractJDBCDAO<Item, ItemID> implements
ItemDAO { ItemDAO {
/** /**
* The {@link ItemID} factory * The {@link ItemID} factory

View File

@@ -46,7 +46,7 @@ import com.l2jserver.util.geometry.Point3D;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class JDBCNPCDAO extends AbstractJDBCDAO<NPC, NPCID> implements public abstract class JDBCNPCDAO extends AbstractJDBCDAO<NPC, NPCID> implements
NPCDAO { NPCDAO {
private final Logger log = LoggerFactory.getLogger(this.getClass()); private final Logger log = LoggerFactory.getLogger(this.getClass());

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.db.dao.h2; package com.l2jserver.db.dao.jdbc.h2;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterDAO; import com.l2jserver.db.dao.CharacterDAO;

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.db.dao.h2; package com.l2jserver.db.dao.jdbc.h2;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterFriendDAO; import com.l2jserver.db.dao.CharacterFriendDAO;

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.db.dao.h2; package com.l2jserver.db.dao.jdbc.h2;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterDAO; import com.l2jserver.db.dao.CharacterDAO;

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.db.dao.h2; package com.l2jserver.db.dao.jdbc.h2;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.l2jserver.db.dao.ItemDAO; import com.l2jserver.db.dao.ItemDAO;

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.db.dao.h2; package com.l2jserver.db.dao.jdbc.h2;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterDAO; import com.l2jserver.db.dao.CharacterDAO;

View File

@@ -14,8 +14,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.db.dao.mysql5; package com.l2jserver.db.dao.jdbc.mysql5;
import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterDAO; import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.jdbc.JDBCCharacterDAO; import com.l2jserver.db.dao.jdbc.JDBCCharacterDAO;
import com.l2jserver.model.id.object.provider.CharacterIDProvider; import com.l2jserver.model.id.object.provider.CharacterIDProvider;
@@ -31,6 +32,7 @@ import com.l2jserver.service.database.DatabaseService;
*/ */
public class MySQL5CharacterDAO extends JDBCCharacterDAO implements public class MySQL5CharacterDAO extends JDBCCharacterDAO implements
CharacterDAO { CharacterDAO {
@Inject
public MySQL5CharacterDAO(DatabaseService database, public MySQL5CharacterDAO(DatabaseService database,
CharacterIDProvider idFactory, CharacterIDProvider idFactory,
CharacterTemplateIDProvider templateIdFactory, CharacterTemplateIDProvider templateIdFactory,

View File

@@ -14,8 +14,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.db.dao.mysql5; package com.l2jserver.db.dao.jdbc.mysql5;
import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterFriendDAO; import com.l2jserver.db.dao.CharacterFriendDAO;
import com.l2jserver.db.dao.jdbc.JDBCCharacterFriendDAO; import com.l2jserver.db.dao.jdbc.JDBCCharacterFriendDAO;
import com.l2jserver.model.id.object.provider.CharacterIDProvider; import com.l2jserver.model.id.object.provider.CharacterIDProvider;
@@ -29,6 +30,7 @@ import com.l2jserver.service.database.DatabaseService;
*/ */
public class MySQL5CharacterFriendDAO extends JDBCCharacterFriendDAO implements public class MySQL5CharacterFriendDAO extends JDBCCharacterFriendDAO implements
CharacterFriendDAO { CharacterFriendDAO {
@Inject
public MySQL5CharacterFriendDAO(DatabaseService database, public MySQL5CharacterFriendDAO(DatabaseService database,
FriendIDProvider idProvider, CharacterIDProvider charIdProvider) { FriendIDProvider idProvider, CharacterIDProvider charIdProvider) {
super(database, idProvider, charIdProvider); super(database, idProvider, charIdProvider);

View File

@@ -14,8 +14,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.db.dao.mysql5; package com.l2jserver.db.dao.jdbc.mysql5;
import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterDAO; import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.ClanDAO; import com.l2jserver.db.dao.ClanDAO;
import com.l2jserver.db.dao.jdbc.JDBCClanDAO; import com.l2jserver.db.dao.jdbc.JDBCClanDAO;
@@ -29,6 +30,7 @@ import com.l2jserver.service.database.DatabaseService;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MySQL5ClanDAO extends JDBCClanDAO implements ClanDAO { public class MySQL5ClanDAO extends JDBCClanDAO implements ClanDAO {
@Inject
public MySQL5ClanDAO(DatabaseService database, public MySQL5ClanDAO(DatabaseService database,
ClanIDProvider clanIdFactory, CharacterIDProvider idFactory) { ClanIDProvider clanIdFactory, CharacterIDProvider idFactory) {
super(database, clanIdFactory, idFactory); super(database, clanIdFactory, idFactory);

View File

@@ -14,8 +14,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.db.dao.mysql5; package com.l2jserver.db.dao.jdbc.mysql5;
import com.google.inject.Inject;
import com.l2jserver.db.dao.ItemDAO; import com.l2jserver.db.dao.ItemDAO;
import com.l2jserver.db.dao.jdbc.JDBCItemDAO; import com.l2jserver.db.dao.jdbc.JDBCItemDAO;
import com.l2jserver.model.id.object.provider.CharacterIDProvider; import com.l2jserver.model.id.object.provider.CharacterIDProvider;
@@ -29,6 +30,7 @@ import com.l2jserver.service.database.DatabaseService;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MySQL5ItemDAO extends JDBCItemDAO implements ItemDAO { public class MySQL5ItemDAO extends JDBCItemDAO implements ItemDAO {
@Inject
public MySQL5ItemDAO(DatabaseService database, ItemIDProvider idFactory, public MySQL5ItemDAO(DatabaseService database, ItemIDProvider idFactory,
ItemTemplateIDProvider templateIdFactory, ItemTemplateIDProvider templateIdFactory,
CharacterIDProvider charIdFactory) { CharacterIDProvider charIdFactory) {

View File

@@ -14,8 +14,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.db.dao.mysql5; package com.l2jserver.db.dao.jdbc.mysql5;
import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterDAO; import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.NPCDAO; import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.db.dao.jdbc.JDBCNPCDAO; import com.l2jserver.db.dao.jdbc.JDBCNPCDAO;
@@ -29,6 +30,7 @@ import com.l2jserver.service.database.DatabaseService;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MySQL5NPCDAO extends JDBCNPCDAO implements NPCDAO { public class MySQL5NPCDAO extends JDBCNPCDAO implements NPCDAO {
@Inject
public MySQL5NPCDAO(DatabaseService database, NPCIDProvider idProvider, public MySQL5NPCDAO(DatabaseService database, NPCIDProvider idProvider,
NPCTemplateIDProvider templateIdProvider) { NPCTemplateIDProvider templateIdProvider) {
super(database, idProvider, templateIdProvider); super(database, idProvider, templateIdProvider);

View File

@@ -18,7 +18,7 @@ package com.l2jserver;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Module; import com.google.inject.Module;
import com.l2jserver.db.H2DAOModule; import com.l2jserver.db.MySQL5DAOModule;
import com.l2jserver.model.id.provider.IDProviderModule; import com.l2jserver.model.id.provider.IDProviderModule;
import com.l2jserver.service.ServiceModule; import com.l2jserver.service.ServiceModule;
@@ -32,6 +32,6 @@ public class GameServerModule extends AbstractModule {
protected void configure() { protected void configure() {
install(new ServiceModule()); install(new ServiceModule());
install(new IDProviderModule()); install(new IDProviderModule());
install(new H2DAOModule()); install(new MySQL5DAOModule());
} }
} }

View File

@@ -254,8 +254,7 @@ public class Lineage2Connection {
* has been written. * has been written.
*/ */
public ChannelFuture sendMessage(String message) { public ChannelFuture sendMessage(String message) {
return write(new SM_SYSTEM_MESSAGE(SystemMessage.S1) return write(new SM_SYSTEM_MESSAGE(SystemMessage.S1).addString(message));
.addString(message));
} }
/** /**
@@ -277,8 +276,8 @@ public class Lineage2Connection {
* the {@link SystemMessage} * the {@link SystemMessage}
* @param args * @param args
* the arguments of the message, they will be automatically * the arguments of the message, they will be automatically
* detected and inserted. See {@link SM_SYSTEM_MESSAGE} for * detected and inserted. See {@link SM_SYSTEM_MESSAGE} for more
* more about supported formats. * about supported formats.
* @return the {@link ChannelFuture} that will be notified once the packet * @return the {@link ChannelFuture} that will be notified once the packet
* has been written. * has been written.
* @see SM_SYSTEM_MESSAGE * @see SM_SYSTEM_MESSAGE
@@ -293,8 +292,10 @@ public class Lineage2Connection {
packet.addItem((ItemTemplate) obj); packet.addItem((ItemTemplate) obj);
else if (obj instanceof Item) else if (obj instanceof Item)
packet.addItem((Item) obj); packet.addItem((Item) obj);
else if (obj instanceof Number)
packet.addNumber((Integer) obj);
} }
return write(message.packet); return write(packet);
} }
/** /**

View File

@@ -54,6 +54,10 @@ public class SM_ATTACK extends AbstractServerPacket {
Collections.addAll(this.hits, hits); Collections.addAll(this.hits, hits);
} }
public SM_ATTACK(AttackHit... hits) {
this(hits[0].getAttacker(), hits);
}
@Override @Override
public void write(Lineage2Connection conn, ChannelBuffer buffer) { public void write(Lineage2Connection conn, ChannelBuffer buffer) {
buffer.writeInt(attacker.getID().getID()); buffer.writeInt(attacker.getID().getID());

View File

@@ -78,6 +78,22 @@ public class AttackHit {
} }
} }
/**
* Creates a new instance
*
* @param attacker
* the actor attacking <tt>target</tt>
* @param target
* the actor being attacked by <tt>attacker</tt>
* @param damage
* the damage issued in this hit
*/
public AttackHit(Actor attacker, Actor target, double damage) {
this.attacker = attacker;
this.target = target;
this.damage = damage;
}
/** /**
* Creates a new instance * Creates a new instance
* *

View File

@@ -0,0 +1,28 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.model.server.attack;
import com.l2jserver.util.calculator.SimpleCalculator;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class AttackCalculator extends SimpleCalculator<AttackCalculatorContext> {
public AttackCalculator(AttackCalculatorFunction... functions) {
super(functions);
}
}

View File

@@ -0,0 +1,33 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.model.server.attack;
import com.l2jserver.model.world.Actor;
import com.l2jserver.util.calculator.CalculatorContext;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class AttackCalculatorContext extends CalculatorContext {
public final Actor attacker;
public final Actor target;
public AttackCalculatorContext(Actor attacker, Actor target) {
this.attacker = attacker;
this.target = target;
}
}

View File

@@ -0,0 +1,37 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.model.server.attack;
import com.l2jserver.model.world.Actor;
import com.l2jserver.util.calculator.AbstractDoubleFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class AttackCalculatorFunction extends
AbstractDoubleFunction<AttackCalculatorContext> {
public AttackCalculatorFunction(int order) {
super(order);
}
@Override
public double calculate(AttackCalculatorContext ctx, double value) {
return calculate(ctx.attacker, ctx.target, value);
}
public abstract double calculate(Actor attacker, Actor target, double value);
}

View File

@@ -0,0 +1,45 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.model.server.attack;
import com.l2jserver.model.world.Actor;
/**
* Calculator used to calculate physical damage on each hit.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class PhysicalAttackCalculator extends AttackCalculator {
public PhysicalAttackCalculator() {
super(new AttackCalculatorFunction(0x000) {
@Override
public double calculate(Actor attacker, Actor target, double value) {
// TODO this is certainly not right!!!
// this is just an simple calculator for testing!
return attacker.getStats().getPhysicalAttack()
- target.getStats().getPhysicalDefense();
}
}, new AttackCalculatorFunction(Integer.MAX_VALUE) {
@Override
public double calculate(Actor attacker, Actor target, double value) {
if (value <= 0)
return 1;
return value;
}
});
}
}

View File

@@ -28,6 +28,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.l2jserver.model.id.template.ItemTemplateID; import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.calculator.ItemPhysicalDamageActorCalculator;
import com.l2jserver.model.world.Item; import com.l2jserver.model.world.Item;
import com.l2jserver.util.jaxb.ItemTemplateIDAdapter; import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
@@ -58,15 +59,26 @@ public class ItemTemplate extends AbstractTemplate<Item> {
protected int price = 0; protected int price = 0;
@XmlElement(name = "icon") @XmlElement(name = "icon")
protected String icon; protected String icon;
@XmlElement(name = "weight") @XmlElement(name = "effect")
protected EffectContainer effect; protected EffectContainer effect;
@XmlType(namespace = "item") @XmlType(namespace = "item")
private static class EffectContainer { private static class EffectContainer {
@XmlAttribute(name = "type") @XmlAttribute(name = "type")
protected EffectType effect = null; protected EffectType effect;
} }
@XmlType(namespace = "item")
protected static class StatsContainer {
@XmlElement(name = "physicalDamage")
protected StatAttribute physicalDamage;
@XmlElement(name = "magicalDamage")
protected StatAttribute magicalDamage;
}
@XmlElement(name = "stats")
protected StatsContainer stats;
protected ItemMaterial material; protected ItemMaterial material;
public enum ItemMaterial { public enum ItemMaterial {
@@ -77,6 +89,38 @@ public class ItemTemplate extends AbstractTemplate<Item> {
IMMEDIATE; IMMEDIATE;
} }
@XmlType(namespace = "item")
public static class StatAttribute {
@XmlElement(name = "set")
protected StatSet set;
public static class StatSet {
protected int order;
protected double value;
/**
* @return the order
*/
public int getOrder() {
return order;
}
/**
* @return the value
*/
public double getValue() {
return value;
}
}
/**
* @return the set
*/
public StatSet getSet() {
return set;
}
}
@Override @Override
public Item create() { public Item create() {
log.debug("Creating a new Item instance with template {}", this); log.debug("Creating a new Item instance with template {}", this);
@@ -125,6 +169,24 @@ public class ItemTemplate extends AbstractTemplate<Item> {
return material; return material;
} }
/**
* @return the physical damage
*/
public ItemPhysicalDamageActorCalculator getPhysicalDamage() {
if (stats == null)
return null;
return new ItemPhysicalDamageActorCalculator(stats.physicalDamage.set);
}
/**
* @return the magical damage
*/
public StatAttribute getMagicalDamage() {
if (stats == null)
return null;
return stats.magicalDamage;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *

View File

@@ -14,30 +14,24 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.model.world.npc.calculator.base; package com.l2jserver.model.template.calculator;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.template.ItemTemplate.StatAttribute.StatSet;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.actor.calculator.ActorCalculator;
import com.l2jserver.model.world.actor.calculator.ActorCalculatorFunction;
/** /**
* Calculates the character base accuracy.
*
* <pre>
* ctx.result = c.getTemplate().getBaseAccuracy();
* </pre>
*
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/ */
public class NPCBaseAttackAccuracyCalculator extends NPCCalculator { public class ItemPhysicalDamageActorCalculator extends ActorCalculator {
public NPCBaseAttackAccuracyCalculator() { public ItemPhysicalDamageActorCalculator(final StatSet set) {
super(new NPCCalculatorFunction(0x000) { super(new ActorCalculatorFunction(set.getOrder()) {
@Override @Override
protected double calculate(NPC c, NPCTemplate t, double value) { protected double calculate(Actor a, ActorTemplate<?> t, double value) {
// return t.getEvasion() return set.getValue();
// TODO
return value;
} }
}); });
} }

View File

@@ -30,8 +30,14 @@ import com.l2jserver.service.game.ai.AIScript;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPC extends Actor { public class NPC extends Actor {
private NPCStats stats; /**
* This NPC stats
*/
private final NPCStats stats = new NPCStats(this);
/**
* The npc state
*/
private NPCState state; private NPCState state;
public enum NPCState { public enum NPCState {
@@ -48,9 +54,7 @@ public class NPC extends Actor {
super(templateID); super(templateID);
} }
/** @Override
* @return the stats
*/
public NPCStats getStats() { public NPCStats getStats() {
return stats; return stats;
} }
@@ -91,6 +95,7 @@ public class NPC extends Actor {
this.state = state; this.state = state;
} }
// TEMPLATE WRAPPERS
@Override @Override
public ActorSex getSex() { public ActorSex getSex() {
return this.getTemplate().getSex(); return this.getTemplate().getSex();

View File

@@ -16,12 +16,12 @@
*/ */
package com.l2jserver.model.world.actor.calculator; package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.util.calculator.Calculator; import com.l2jserver.util.calculator.SimpleCalculator;
/** /**
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class ActorCalculator extends Calculator<ActorCalculatorContext> { public class ActorCalculator extends SimpleCalculator<ActorCalculatorContext> {
public ActorCalculator(ActorCalculatorFunction... functions) { public ActorCalculator(ActorCalculatorFunction... functions) {
super(functions); super(functions);
} }

View File

@@ -18,7 +18,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.util.calculator.AbstractFunction; import com.l2jserver.util.calculator.AbstractDoubleFunction;
/** /**
* An calculator for character formulas. * An calculator for character formulas.
@@ -26,7 +26,7 @@ import com.l2jserver.util.calculator.AbstractFunction;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public abstract class ActorCalculatorFunction extends public abstract class ActorCalculatorFunction extends
AbstractFunction<ActorCalculatorContext> { AbstractDoubleFunction<ActorCalculatorContext> {
public ActorCalculatorFunction(int order) { public ActorCalculatorFunction(int order) {
super(order); super(order);
} }

View File

@@ -16,11 +16,9 @@
*/ */
package com.l2jserver.model.world.actor.calculator; package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
/** /**
* Calculates the character base run speed * Calculates the character base run speed
@@ -31,12 +29,11 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class RunSpeedBonusCalculator extends CharacterCalculator { public class RunSpeedBonusCalculator extends ActorCalculator {
public RunSpeedBonusCalculator() { public RunSpeedBonusCalculator() {
super(new CharacterCalculatorFunction(0x300) { super(new ActorCalculatorFunction(0x300) {
@Override @Override
protected double calculate(L2Character c, CharacterTemplate t, protected double calculate(Actor c, ActorTemplate<?> t, double value) {
double value) {
return value return value
* BaseStats.DEX.calculateBonus(c.getStats() * BaseStats.DEX.calculateBonus(c.getStats()
.getDexterity()); .getDexterity());

View File

@@ -16,11 +16,9 @@
*/ */
package com.l2jserver.model.world.actor.calculator; package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
/** /**
* Calculates the character base walk speed * Calculates the character base walk speed
@@ -31,12 +29,11 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class WalkSpeedBonusCalculator extends CharacterCalculator { public class WalkSpeedBonusCalculator extends ActorCalculator {
public WalkSpeedBonusCalculator() { public WalkSpeedBonusCalculator() {
super(new CharacterCalculatorFunction(0x300) { super(new ActorCalculatorFunction(0x300) {
@Override @Override
protected double calculate(L2Character c, CharacterTemplate t, protected double calculate(Actor c, ActorTemplate<?> t, double value) {
double value) {
return value return value
* BaseStats.DEX.calculateBonus(c.getStats() * BaseStats.DEX.calculateBonus(c.getStats()
.getDexterity()); .getDexterity());

View File

@@ -0,0 +1,68 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* 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 <http://www.gnu.org/licenses/>.
*/
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.
* <p>
* Please note that the same event is dispatched for both attacker and attackee.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
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() };
}
}

View File

@@ -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.PhysicalDefenseBonusCalculator;
import com.l2jserver.model.world.actor.calculator.RunSpeedBonusCalculator; import com.l2jserver.model.world.actor.calculator.RunSpeedBonusCalculator;
import com.l2jserver.model.world.actor.calculator.WalkSpeedBonusCalculator; import com.l2jserver.model.world.actor.calculator.WalkSpeedBonusCalculator;
import com.l2jserver.util.calculator.Calculator; import com.l2jserver.util.calculator.SimpleCalculator;
/** /**
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -152,12 +152,12 @@ public abstract class ActorStats<T extends ActorCalculatorContext> {
* speed gain is much higher. * speed gain is much higher.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private final Calculator<T>[] calculators = new Calculator[StatType private final SimpleCalculator<T>[] calculators = new SimpleCalculator[StatType
.values().length]; .values().length];
public ActorStats() { public ActorStats() {
for (int i = 0; i < calculators.length; i++) { for (int i = 0; i < calculators.length; i++) {
calculators[i] = new Calculator<T>(); calculators[i] = new SimpleCalculator<T>();
} }
// bonuses // bonuses
@@ -334,7 +334,7 @@ public abstract class ActorStats<T extends ActorCalculatorContext> {
* calculator {@link StatType} * calculator {@link StatType}
* @return the calculator object associated with the given <tt>type</tt> * @return the calculator object associated with the given <tt>type</tt>
*/ */
protected Calculator<T> getCalculator(StatType type) { protected SimpleCalculator<T> getCalculator(StatType type) {
return calculators[type.ordinal()]; return calculators[type.ordinal()];
} }
@@ -350,5 +350,9 @@ public abstract class ActorStats<T extends ActorCalculatorContext> {
return getCalculator(type).calculate(ctx); return getCalculator(type).calculate(ctx);
} }
public void updateCalculators() {
}
protected abstract T createContext(); protected abstract T createContext();
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.character;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.stat.ActorStats; import com.l2jserver.model.world.actor.stat.ActorStats;
import com.l2jserver.model.world.actor.stat.StatType; 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.CharacterCalculator;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorContext; import com.l2jserver.model.world.character.calculator.CharacterCalculatorContext;
import com.l2jserver.model.world.character.calculator.MaximumCPAddCalculator; 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.CharacterBaseStrengthCalculator;
import com.l2jserver.model.world.character.calculator.base.CharacterBaseWalkSpeedCalculator; import com.l2jserver.model.world.character.calculator.base.CharacterBaseWalkSpeedCalculator;
import com.l2jserver.model.world.character.calculator.base.CharacterBaseWitnessCalculator; 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 * This class is responsible for calculating the real character stats. The real
* stats vary from the values from the templates, also, skills and items * 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 * equipped can change those values. Once an buff is applied, a new calculator
* is {@link Calculator#importFunctions(Calculator) imported} and their * is {@link SimpleCalculator#importFunctions(SimpleCalculator) imported} and
* functions are added to this class calculator. Once the skill effect has past * their functions are added to this class calculator. Once the skill effect has
* away, all the functions that were imported are now * 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
* return to its original state. * calculator return to its original state.
* <p> * <p>
* Another important note is that calculators should perform calculations as * Another important note is that calculators should perform calculations as
* fast as possible. * fast as possible.
@@ -320,6 +321,17 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
return (int) calc(StatType.MAX_LOAD); 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 @Override
protected CharacterCalculatorContext createContext() { protected CharacterCalculatorContext createContext() {
return new CharacterCalculatorContext(character); return new CharacterCalculatorContext(character);

View File

@@ -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.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.npc.calculator.NPCCalculator;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorContext; 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.NPCBaseAttackEvasionCalculator;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseConcentrationCalculator; import com.l2jserver.model.world.npc.calculator.base.NPCBaseConcentrationCalculator;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseDexterityCalculator; 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.NPCBaseStrengthCalculator;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseWalkSpeedCalculator; import com.l2jserver.model.world.npc.calculator.base.NPCBaseWalkSpeedCalculator;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseWitnessCalculator; 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 * 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 * 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 * 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 * are added to this class calculator. Once the skill effect has past away, all
* the functions that were imported are now * 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. * return to its original state.
* <p> * <p>
* Another important note is that calculators should perform calculations as * Another important note is that calculators should perform calculations as
@@ -192,13 +191,6 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
*/ */
private static final NPCCalculator BASE_MAGICAL_DEFENSE_CALCULATOR = new NPCBaseMagicalDefenseCalculator(); private static final NPCCalculator BASE_MAGICAL_DEFENSE_CALCULATOR = new NPCBaseMagicalDefenseCalculator();
/**
* The calculator base attack accuracy
* <p>
* <u>This calculator does not store any state and thus is safe to be
* shared.</u>
*/
private static final NPCCalculator BASE_ATTACK_ACCURACY_CALCULATOR = new NPCBaseAttackAccuracyCalculator();
/** /**
* The calculator base evasion * The calculator base evasion
* <p> * <p>
@@ -245,7 +237,6 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
add(StatType.MCRITICAL_RATE, BASE_MAGICAL_CRITICAL_RATE_CALCULATOR); add(StatType.MCRITICAL_RATE, BASE_MAGICAL_CRITICAL_RATE_CALCULATOR);
add(StatType.MAGIC_DEFENSE, BASE_MAGICAL_DEFENSE_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); add(StatType.EVASION_RATE, BASE_ATTACK_EVASION_CALCULATOR);
} }

View File

@@ -41,7 +41,9 @@ public class ServiceManager {
* The Guice Injector * The Guice Injector
*/ */
private final Injector injector; private final Injector injector;
/**
* List of all known services by this manager
*/
private final Set<Service> knownServices = CollectionFactory.newSet(); private final Set<Service> knownServices = CollectionFactory.newSet();
@Inject @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.core.vfs.VFSServiceImpl;
import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.JDBCDatabaseService; 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.CharacterService;
import com.l2jserver.service.game.character.CharacterServiceImpl; import com.l2jserver.service.game.character.CharacterServiceImpl;
import com.l2jserver.service.game.chat.ChatService; 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.game.world.event.WorldEventDispatcherImpl;
import com.l2jserver.service.network.NettyNetworkService; import com.l2jserver.service.network.NettyNetworkService;
import com.l2jserver.service.network.NetworkService; 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.BlowfishKeygenService;
import com.l2jserver.service.network.keygen.SecureBlowfishKeygenService; import com.l2jserver.service.network.keygen.SecureBlowfishKeygenService;
@@ -86,6 +90,8 @@ public class ServiceModule extends AbstractModule {
.in(Scopes.SINGLETON); .in(Scopes.SINGLETON);
bind(NetworkService.class).to(NettyNetworkService.class).in( bind(NetworkService.class).to(NettyNetworkService.class).in(
Scopes.SINGLETON); Scopes.SINGLETON);
bind(GameGuardService.class).to(GameGuardServiceImpl.class).in(
Scopes.SINGLETON);
bind(ScriptingService.class).to(ScriptingServiceImpl.class).in( bind(ScriptingService.class).to(ScriptingServiceImpl.class).in(
Scopes.SINGLETON); Scopes.SINGLETON);
bind(TemplateService.class).to(XMLTemplateService.class).in( bind(TemplateService.class).to(XMLTemplateService.class).in(
@@ -97,6 +103,8 @@ public class ServiceModule extends AbstractModule {
.in(Scopes.SINGLETON); .in(Scopes.SINGLETON);
bind(CharacterService.class).to(CharacterServiceImpl.class).in( bind(CharacterService.class).to(CharacterServiceImpl.class).in(
Scopes.SINGLETON); Scopes.SINGLETON);
bind(AttackService.class).to(AttackServiceImpl.class).in(
Scopes.SINGLETON);
bind(NPCService.class).to(NPCServiceImpl.class).in(Scopes.SINGLETON); bind(NPCService.class).to(NPCServiceImpl.class).in(Scopes.SINGLETON);
bind(WorldService.class).to(WorldServiceImpl.class) 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.common.base.Preconditions;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.l2jserver.model.server.AttackHit; 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;
import com.l2jserver.model.world.actor.event.ActorAttackHitEvent;
import com.l2jserver.service.AbstractService; import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.core.threading.AsyncFuture; import com.l2jserver.service.core.threading.AsyncFuture;
import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.core.threading.ThreadService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher; 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> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
@Depends({ ThreadService.class })
public class AttackServiceImpl extends AbstractService implements AttackService { 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 * 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 * The {@link WorldEventDispatcher} is used to dispatch attack events to the
* world * world
*/ */
@SuppressWarnings("unused")
private final WorldEventDispatcher eventDispatcher; private final WorldEventDispatcher eventDispatcher;
@Inject @Inject
@@ -67,12 +77,10 @@ public class AttackServiceImpl extends AbstractService implements AttackService
/** /**
* The attacker * The attacker
*/ */
@SuppressWarnings("unused")
private final Actor attacker; private final Actor attacker;
/** /**
* The target * The target
*/ */
@SuppressWarnings("unused")
private final Actor target; private final Actor target;
public AttackCallable(Actor attacker, Actor target) { public AttackCallable(Actor attacker, Actor target) {
@@ -82,8 +90,15 @@ public class AttackServiceImpl extends AbstractService implements AttackService
@Override @Override
public AttackHit call() throws Exception { public AttackHit call() throws Exception {
final double damage = PHYSICAL_ATTACK_CALCULATOR
.calculate(new AttackCalculatorContext(attacker, target));
// TODO calculate miss
// TODO calculate critical
// TODO calculate soulshot
return null; 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.db.dao.ItemDAO;
import com.l2jserver.game.net.Lineage2Connection; import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.SystemMessage; 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;
import com.l2jserver.game.net.packet.server.SM_CHAR_INFO_BROADCAST; import com.l2jserver.game.net.packet.server.SM_CHAR_INFO_BROADCAST;
import com.l2jserver.game.net.packet.server.SM_CHAR_INFO_EXTRA; 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_OBJECT_REMOVE;
import com.l2jserver.game.net.packet.server.SM_TARGET; import com.l2jserver.game.net.packet.server.SM_TARGET;
import com.l2jserver.model.id.object.CharacterID; import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.L2Character.CharacterMoveType; 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.NPC;
import com.l2jserver.model.world.PositionableObject; import com.l2jserver.model.world.PositionableObject;
import com.l2jserver.model.world.WorldObject; 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.CharacterEnterWorldEvent;
import com.l2jserver.model.world.character.event.CharacterEvent; import com.l2jserver.model.world.character.event.CharacterEvent;
import com.l2jserver.model.world.character.event.CharacterLeaveWorldEvent; 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.model.world.player.event.PlayerTeleportingEvent;
import com.l2jserver.service.AbstractService; import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends; 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.ChatChannel;
import com.l2jserver.service.game.chat.ChatChannelListener; import com.l2jserver.service.game.chat.ChatChannelListener;
import com.l2jserver.service.game.chat.ChatMessageDestination; 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> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
@Depends({ WorldService.class, ChatService.class, NetworkService.class, @Depends({ WorldService.class, ChatService.class, NetworkService.class,
SpawnService.class }) SpawnService.class, AttackService.class, GameGuardService.class })
public class CharacterServiceImpl extends AbstractService implements public class CharacterServiceImpl extends AbstractService implements
CharacterService { CharacterService {
/** /**
@@ -153,6 +155,9 @@ public class CharacterServiceImpl extends AbstractService implements
character.setOnline(true); character.setOnline(true);
// inventory interfere on calculators
character.getStats().updateCalculators();
// chat listener // chat listener
final ChatChannelListener globalChatListener = new ChatChannelListener() { final ChatChannelListener globalChatListener = new ChatChannelListener() {
@Override @Override
@@ -231,6 +236,11 @@ public class CharacterServiceImpl extends AbstractService implements
} else if (e instanceof PlayerTeleportedEvent } else if (e instanceof PlayerTeleportedEvent
|| e instanceof CharacterEnterWorldEvent) { || e instanceof CharacterEnterWorldEvent) {
broadcast(conn, character); 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 // keep listener alive
return true; return true;
@@ -369,10 +379,6 @@ public class CharacterServiceImpl extends AbstractService implements
// check if this Actor can be attacked // check if this Actor can be attacked
if (target instanceof NPC) { if (target instanceof NPC) {
final NPC npc = (NPC) target; 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 // first try to target this, if it is not already
target(character, target); target(character, target);

View File

@@ -27,9 +27,7 @@ import com.google.inject.Injector;
import com.l2jserver.db.dao.NPCDAO; import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.game.net.Lineage2Connection; import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.client.CM_CHAR_ACTION.CharacterAction; import com.l2jserver.game.net.packet.client.CM_CHAR_ACTION.CharacterAction;
import com.l2jserver.game.net.packet.server.SM_ATTACK; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.server.AttackHit;
import com.l2jserver.model.server.AttackHit.AttackHitFlag;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.NPC.NPCState; 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.AbstractService.Depends;
import com.l2jserver.service.core.threading.AsyncFuture; import com.l2jserver.service.core.threading.AsyncFuture;
import com.l2jserver.service.core.threading.ThreadService; 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.CannotSetTargetServiceException;
import com.l2jserver.service.game.character.CharacterService; import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException; 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> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
@Depends({ SpawnService.class, NetworkService.class, CharacterService.class, @Depends({ SpawnService.class, NetworkService.class, CharacterService.class,
ThreadService.class }) ThreadService.class, AttackService.class })
public class NPCServiceImpl extends AbstractService implements NPCService { public class NPCServiceImpl extends AbstractService implements NPCService {
/** /**
* The {@link SpawnService} used to spawn the {@link NPC} instances * The {@link SpawnService} used to spawn the {@link NPC} instances
@@ -72,6 +71,10 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
* The {@link ThreadService} * The {@link ThreadService}
*/ */
private final ThreadService threadService; private final ThreadService threadService;
/**
* The {@link AttackService}
*/
private final AttackService attackService;
/** /**
* The {@link NPCDAO} * The {@link NPCDAO}
@@ -93,11 +96,13 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
@Inject @Inject
public NPCServiceImpl(SpawnService spawnService, public NPCServiceImpl(SpawnService spawnService,
NetworkService networkService, CharacterService characterService, NetworkService networkService, CharacterService characterService,
ThreadService threadService, NPCDAO npcDao, Injector injector) { ThreadService threadService, AttackService attackService,
NPCDAO npcDao, Injector injector) {
this.spawnService = spawnService; this.spawnService = spawnService;
this.networkService = networkService; this.networkService = networkService;
this.characterService = characterService; this.characterService = characterService;
this.threadService = threadService; this.threadService = threadService;
this.attackService = attackService;
this.npcDao = npcDao; this.npcDao = npcDao;
this.injector = injector; this.injector = injector;
} }
@@ -183,9 +188,12 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
Preconditions.checkNotNull(conn, "conn"); Preconditions.checkNotNull(conn, "conn");
Preconditions.checkNotNull(attacker, "attacker"); Preconditions.checkNotNull(attacker, "attacker");
conn.write(new SM_ATTACK(conn.getCharacter(), new AttackHit( final NPCTemplate template = npc.getTemplate();
conn.getCharacter(), npc, AttackHitFlag.MISS, if (!template.isAttackable()) {
AttackHitFlag.SOULSHOT))); throw new NotAttackableNPCServiceException();
}
attackService.attack(attacker, npc);
} }
private NPCController getController(NPC npc) { private NPCController getController(NPC npc) {

View File

@@ -19,13 +19,14 @@ package com.l2jserver.service.network.gameguard;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import com.l2jserver.game.net.Lineage2Connection; import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.service.Service;
/** /**
* This service is responsible for querying and validating GameGuard packets * This service is responsible for querying and validating GameGuard packets
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public interface GameGuardService { public interface GameGuardService extends Service {
/** /**
* Queries the client GameGuard for an response * 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.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Future; 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.Lineage2Connection;
import com.l2jserver.game.net.packet.server.SM_GG_QUERY; import com.l2jserver.game.net.packet.server.SM_GG_QUERY;
import com.l2jserver.service.AbstractService; import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException; import com.l2jserver.service.ServiceStopException;
import com.l2jserver.service.network.NetworkService;
import com.l2jserver.util.factory.CollectionFactory; 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> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
@Depends({ NetworkService.class })
public class GameGuardServiceImpl extends AbstractService implements public class GameGuardServiceImpl extends AbstractService implements
GameGuardService { GameGuardService {
/** /**
@@ -106,9 +108,10 @@ public class GameGuardServiceImpl extends AbstractService implements
* @return true if key is valid * @return true if key is valid
*/ */
private boolean validate(Lineage2Connection conn, byte[] key) { private boolean validate(Lineage2Connection conn, byte[] key) {
synchronized (digester) { // synchronized (digester) {
return Arrays.equals(VALID_KEY_SHA1, digester.digest(key)); // return Arrays.equals(VALID_KEY_SHA1, digester.digest(key));
} // }
return true;
} }
@Override @Override

View File

@@ -74,6 +74,6 @@ public class XMLMappingTest {
final CharacterTemplate t = (CharacterTemplate) u.unmarshal(new File( final CharacterTemplate t = (CharacterTemplate) u.unmarshal(new File(
"data/templates/character/HumanFighter.xml")); "data/templates/character/HumanFighter.xml"));
System.out.println(t.getID()); System.out.println(t.getID());
System.out.println(t.getCharacterClass()); System.out.println(t.getBasePhysicalAttack());
} }
} }

View File

@@ -20,11 +20,11 @@ package com.l2jserver.util.calculator;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
* *
*/ */
public abstract class AbstractFunction<T extends CalculatorContext> implements public abstract class AbstractDoubleFunction<T extends CalculatorContext> implements
Function<T> { Function<T> {
private final int order; private final int order;
public AbstractFunction(int order) { public AbstractDoubleFunction(int order) {
this.order = order; this.order = order;
} }

View File

@@ -22,7 +22,7 @@ package com.l2jserver.util.calculator;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class DivisionFunction extends AbstractFunction<CalculatorContext> { public class DivisionFunction extends AbstractDoubleFunction<CalculatorContext> {
/** /**
* The value * The value
*/ */

View File

@@ -21,7 +21,7 @@ package com.l2jserver.util.calculator;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public interface Function<T extends CalculatorContext> { public interface Function<C extends CalculatorContext> {
/** /**
* Performs the operation in the calculation process. * Performs the operation in the calculation process.
* <p> * <p>
@@ -33,7 +33,7 @@ public interface Function<T extends CalculatorContext> {
* the input value * the input value
* @return the output 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 * @return the order this function will be executed

View File

@@ -22,7 +22,7 @@ package com.l2jserver.util.calculator;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class ModulusFunction extends AbstractFunction<CalculatorContext> { public class ModulusFunction extends AbstractDoubleFunction<CalculatorContext> {
public ModulusFunction(int order) { public ModulusFunction(int order) {
super(order); super(order);
} }

View File

@@ -22,7 +22,7 @@ package com.l2jserver.util.calculator;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MultiplicationFunction extends AbstractFunction<CalculatorContext> { public class MultiplicationFunction extends AbstractDoubleFunction<CalculatorContext> {
/** /**
* The value * The value
*/ */

View File

@@ -22,7 +22,7 @@ package com.l2jserver.util.calculator;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NegateFunction extends AbstractFunction<CalculatorContext> { public class NegateFunction extends AbstractDoubleFunction<CalculatorContext> {
public NegateFunction(int order) { public NegateFunction(int order) {
super(order); super(order);
} }

View File

@@ -21,7 +21,7 @@ package com.l2jserver.util.calculator;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class RoundFunction extends AbstractFunction<CalculatorContext> { public class RoundFunction extends AbstractDoubleFunction<CalculatorContext> {
public RoundFunction(int order) { public RoundFunction(int order) {
super(order); super(order);
} }

View File

@@ -21,7 +21,7 @@ package com.l2jserver.util.calculator;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class SetFunction extends AbstractFunction<CalculatorContext> { public class SetFunction extends AbstractDoubleFunction<CalculatorContext> {
/** /**
* The value * The value
*/ */

View File

@@ -16,11 +16,8 @@
*/ */
package com.l2jserver.util.calculator; package com.l2jserver.util.calculator;
import java.util.Collections; import java.util.Arrays;
import java.util.Comparator; 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 * 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 <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class Calculator<T extends CalculatorContext> extends public class SimpleCalculator<T extends CalculatorContext> extends
AbstractFunction<T> { AbstractDoubleFunction<T> {
/** /**
* List of operations in this calculator * List of operations in this calculator
*/ */
private final List<Function<? super T>> functions = CollectionFactory private Function<? super T>[] functions;
.newList();
/** /**
* Creates a new empty calculator. Functions can be add using * Creates a new empty calculator. Functions can be add using
* {@link #add(int, Function)}. * {@link #add(int, Function)}.
*/ */
public Calculator() { @SuppressWarnings("unchecked")
public SimpleCalculator() {
super(0x00); super(0x00);
functions = new Function[0];
} }
/** /**
@@ -51,11 +49,9 @@ public class Calculator<T extends CalculatorContext> extends
* @param functions * @param functions
* the calculator functions * the calculator functions
*/ */
public Calculator(Function<? super T>... functions) { public SimpleCalculator(Function<? super T>... functions) {
super(0x00); super(0x00);
for (final Function<? super T> func : functions) { this.functions = functions;
this.functions.add(func);
}
} }
/** /**
@@ -70,8 +66,9 @@ public class Calculator<T extends CalculatorContext> extends
* the operation * the operation
*/ */
public void add(Function<? super T> function) { public void add(Function<? super T> function) {
functions.add(function); functions = Arrays.copyOf(functions, functions.length + 1);
Collections.sort(functions, FunctionOrderComparator.SHARED_INSTANCE); functions[functions.length - 1] = function;
Arrays.sort(functions, FunctionOrderComparator.SHARED_INSTANCE);
} }
/** /**
@@ -84,12 +81,12 @@ public class Calculator<T extends CalculatorContext> extends
* @param calculator * @param calculator
* the 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) { for (final Function<? super T> function : calculator.functions) {
if (function instanceof Calculator) { if (function instanceof SimpleCalculator) {
importFunctions((Calculator<? super T>) function); importFunctions((SimpleCalculator<? super T>) function);
} else { } else {
functions.add(function); add(function);
} }
} }
} }
@@ -102,12 +99,13 @@ public class Calculator<T extends CalculatorContext> extends
* @param calculator * @param calculator
* the 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) { for (final Function<? super T> function : calculator.functions) {
if (function instanceof Calculator) { if (function instanceof SimpleCalculator) {
removeFunctions((Calculator<? super T>) function); removeFunctions((SimpleCalculator<? super T>) function);
} else { } else {
functions.remove(function); // TODO
// remove(function);
} }
} }
} }

View File

@@ -22,7 +22,7 @@ package com.l2jserver.util.calculator;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class SubtractFunction extends AbstractFunction<CalculatorContext> { public class SubtractFunction extends AbstractDoubleFunction<CalculatorContext> {
/** /**
* The value * The value
*/ */

View File

@@ -22,7 +22,7 @@ package com.l2jserver.util.calculator;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class SumFunction extends AbstractFunction<CalculatorContext> { public class SumFunction extends AbstractDoubleFunction<CalculatorContext> {
/** /**
* The value * The value
*/ */

View File

@@ -35,7 +35,6 @@ public class PrecompiledScriptCompilerTest {
// @Test // @Test
public void testCompileIterableOfFile() { public void testCompileIterableOfFile() {
final PrecompiledScriptCompiler compiler = new PrecompiledScriptCompiler(); final PrecompiledScriptCompiler compiler = new PrecompiledScriptCompiler();
@SuppressWarnings("unchecked")
final CompilationResult result = compiler.compile(FileUtils.listFiles( final CompilationResult result = compiler.compile(FileUtils.listFiles(
new File("target/scripts/script/template"), new File("target/scripts/script/template"),
new String[] { "class" }, true)); new String[] { "class" }, true));

View File

@@ -27,7 +27,7 @@ import org.junit.Test;
public class CalculatorTest { public class CalculatorTest {
@Test @Test
public void testSimple() { public void testSimple() {
final Calculator<CalculatorContext> calc = new Calculator<CalculatorContext>(); final SimpleCalculator<CalculatorContext> calc = new SimpleCalculator<CalculatorContext>();
calc.add(new SetFunction(0, 10)); calc.add(new SetFunction(0, 10));
calc.add(new MultiplicationFunction(1, 2)); calc.add(new MultiplicationFunction(1, 2));
@@ -39,7 +39,7 @@ public class CalculatorTest {
@Test @Test
public void testPercent() { public void testPercent() {
final Calculator<CalculatorContext> calc = new Calculator<CalculatorContext>(); final SimpleCalculator<CalculatorContext> calc = new SimpleCalculator<CalculatorContext>();
calc.add(new SetFunction(0, 10)); calc.add(new SetFunction(0, 10));
calc.add(new MultiplicationFunction(1, 2)); calc.add(new MultiplicationFunction(1, 2));
@@ -51,7 +51,7 @@ public class CalculatorTest {
@Test @Test
public void testComplex() { public void testComplex() {
final Calculator<CalculatorContext> calc = new Calculator<CalculatorContext>(); final SimpleCalculator<CalculatorContext> calc = new SimpleCalculator<CalculatorContext>();
calc.add(new SetFunction(0, 10)); calc.add(new SetFunction(0, 10));
calc.add(new MultiplicationFunction(1, 2)); calc.add(new MultiplicationFunction(1, 2));
@@ -66,7 +66,7 @@ public class CalculatorTest {
@Test @Test
public void testNesting() { public void testNesting() {
final Calculator<CalculatorContext> calc1 = new Calculator<CalculatorContext>(); final SimpleCalculator<CalculatorContext> calc1 = new SimpleCalculator<CalculatorContext>();
final CalculatorContext ctx1 = new CalculatorContext(); final CalculatorContext ctx1 = new CalculatorContext();
calc1.add(new SetFunction(0, 10)); calc1.add(new SetFunction(0, 10));
@@ -78,7 +78,7 @@ public class CalculatorTest {
Assert.assertEquals(5.0, calc1.calculate(ctx1)); Assert.assertEquals(5.0, calc1.calculate(ctx1));
final Calculator<CalculatorContext> calc2 = new Calculator<CalculatorContext>(); final SimpleCalculator<CalculatorContext> calc2 = new SimpleCalculator<CalculatorContext>();
final CalculatorContext ctx2 = new CalculatorContext(); final CalculatorContext ctx2 = new CalculatorContext();
calc2.add(new MultiplicationFunction(0, 2)); calc2.add(new MultiplicationFunction(0, 2));
@@ -89,7 +89,7 @@ public class CalculatorTest {
Assert.assertEquals(-2.5, calc2.calculate(ctx2)); Assert.assertEquals(-2.5, calc2.calculate(ctx2));
final Calculator<CalculatorContext> calc3 = new Calculator<CalculatorContext>(); final SimpleCalculator<CalculatorContext> calc3 = new SimpleCalculator<CalculatorContext>();
final CalculatorContext ctx3 = new CalculatorContext(); final CalculatorContext ctx3 = new CalculatorContext();
calc3.add(calc1); calc3.add(calc1);
calc3.add(calc2); calc3.add(calc2);
@@ -102,7 +102,7 @@ public class CalculatorTest {
@Test @Test
public void testImporting() { public void testImporting() {
final Calculator<CalculatorContext> calc1 = new Calculator<CalculatorContext>(); final SimpleCalculator<CalculatorContext> calc1 = new SimpleCalculator<CalculatorContext>();
final CalculatorContext ctx1 = new CalculatorContext(); final CalculatorContext ctx1 = new CalculatorContext();
calc1.add(new SetFunction(0, 10)); calc1.add(new SetFunction(0, 10));
@@ -114,7 +114,7 @@ public class CalculatorTest {
Assert.assertEquals(5.0, calc1.calculate(ctx1)); Assert.assertEquals(5.0, calc1.calculate(ctx1));
final Calculator<CalculatorContext> calc2 = new Calculator<CalculatorContext>(); final SimpleCalculator<CalculatorContext> calc2 = new SimpleCalculator<CalculatorContext>();
final CalculatorContext ctx2 = new CalculatorContext(); final CalculatorContext ctx2 = new CalculatorContext();
calc2.add(new MultiplicationFunction(1, 2)); calc2.add(new MultiplicationFunction(1, 2));
@@ -125,7 +125,7 @@ public class CalculatorTest {
Assert.assertEquals(-2.5, calc2.calculate(ctx2)); Assert.assertEquals(-2.5, calc2.calculate(ctx2));
final Calculator<CalculatorContext> calc3 = new Calculator<CalculatorContext>(); final SimpleCalculator<CalculatorContext> calc3 = new SimpleCalculator<CalculatorContext>();
final CalculatorContext ctx3 = new CalculatorContext(); final CalculatorContext ctx3 = new CalculatorContext();
calc3.importFunctions(calc1); calc3.importFunctions(calc1);
calc3.importFunctions(calc2); calc3.importFunctions(calc2);
@@ -138,7 +138,7 @@ public class CalculatorTest {
@Test @Test
public void testRounding() { public void testRounding() {
final Calculator<CalculatorContext> calc = new Calculator<CalculatorContext>(); final SimpleCalculator<CalculatorContext> calc = new SimpleCalculator<CalculatorContext>();
calc.add(new MultiplicationFunction(0, 2)); calc.add(new MultiplicationFunction(0, 2));
calc.add(new PercentFunction(1, 75)); calc.add(new PercentFunction(1, 75));

View File

@@ -87,7 +87,6 @@ public class NPCTemplateConverter {
private static Collection<File> htmlScannedFiles; private static Collection<File> htmlScannedFiles;
private static TeleportationTemplateContainer teleportation = new TeleportationTemplateContainer(); private static TeleportationTemplateContainer teleportation = new TeleportationTemplateContainer();
@SuppressWarnings("unchecked")
public static void main(String[] args) throws SQLException, IOException, public static void main(String[] args) throws SQLException, IOException,
ClassNotFoundException, JAXBException { ClassNotFoundException, JAXBException {
controllers.put("L2Teleporter", TeleporterController.class); controllers.put("L2Teleporter", TeleporterController.class);

View File

@@ -36,7 +36,6 @@ public class ItemTemplateConversor {
template = IOUtils.toString(ItemTemplateConversor.class template = IOUtils.toString(ItemTemplateConversor.class
.getResourceAsStream("ItemTemplateBase.txt")); .getResourceAsStream("ItemTemplateBase.txt"));
@SuppressWarnings("unchecked")
Collection<File> files = FileUtils Collection<File> files = FileUtils
.listFiles( .listFiles(
new File( new File(