mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-06 15:33:00 +00:00
Change-Id: Ia0d07d075e9feeb872124348948d8664364d1c8a
This commit is contained in:
21
data/script/template/script/template/DisabledTemplate.java
Normal file
21
data/script/template/script/template/DisabledTemplate.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package script.template;
|
||||
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.ElementType;
|
||||
|
||||
|
||||
/**
|
||||
* Marker annotation that is used to mark disabled DAO's so they will be ignored by {@link TemplateLoader}
|
||||
*
|
||||
* @author SoulKeeper
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface DisabledTemplate
|
||||
{
|
||||
}
|
||||
86
data/script/template/script/template/TemplateLoader.java
Normal file
86
data/script/template/script/template/TemplateLoader.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package script.template;/*
|
||||
* This file is part of aion-emu <aion-emu.com>.
|
||||
*
|
||||
* aion-emu 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.
|
||||
*
|
||||
* aion-emu 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 aion-emu. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.model.template.Template;
|
||||
import com.l2jserver.service.game.scripting.classlistener.Loader;
|
||||
import com.l2jserver.service.game.scripting.classlistener.Unloader;
|
||||
import com.l2jserver.service.game.template.StaticTemplateService;
|
||||
import com.l2jserver.service.game.template.TemplateService;
|
||||
import com.l2jserver.util.ClassUtils;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
* Utility class that loads all Template's in classPath of this script context.<br>
|
||||
* Template should be public, not abstract, not interface, must have default
|
||||
* no-arg public constructor.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class TemplateLoader implements Loader, Unloader {
|
||||
private final StaticTemplateService templateService;
|
||||
|
||||
@Inject
|
||||
public TemplateLoader(TemplateService templateService) {
|
||||
this.templateService = (StaticTemplateService) templateService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Class<?>[] classes) {
|
||||
for (final Class<? extends Template> template : getSuitableClasses(classes)) {
|
||||
templateService.addTemplate(template);
|
||||
System.out.println("Loading template: " + template);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(Class<?>[] classes) {
|
||||
for (final Class<? extends Template> template : getSuitableClasses(classes)) {
|
||||
System.out.println("Unloading template: " + template);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of suitable Template classes to load/unload
|
||||
*
|
||||
* @return list of Template classes to load/unload
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
private static Set<Class<? extends Template>> getSuitableClasses(
|
||||
Class<?>[] classes) {
|
||||
final Set<Class<? extends Template>> suitable = CollectionFactory
|
||||
.newSet(null);
|
||||
for (Class<?> clazz : classes) {
|
||||
if (!ClassUtils.isSubclass(clazz, Template.class))
|
||||
continue;
|
||||
if (Modifier.isAbstract(clazz.getModifiers())
|
||||
|| Modifier.isInterface(clazz.getModifiers()))
|
||||
continue;
|
||||
if (!Modifier.isPublic(clazz.getModifiers()))
|
||||
continue;
|
||||
if (clazz.isAnnotationPresent(DisabledTemplate.class))
|
||||
continue;
|
||||
|
||||
suitable.add((Class<? extends Template>) clazz);
|
||||
}
|
||||
|
||||
return suitable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package script.template.armor;
|
||||
|
||||
import com.l2jserver.model.id.TemplateID;
|
||||
import com.l2jserver.model.template.ArmorTemplate;
|
||||
import com.l2jserver.model.template.capability.Enchantable;
|
||||
import com.l2jserver.model.template.capability.Penalty;
|
||||
import com.l2jserver.model.world.capability.Castable;
|
||||
import com.l2jserver.model.world.capability.Equiper;
|
||||
import com.l2jserver.model.world.capability.Levelable;
|
||||
|
||||
public abstract class AbstractGradeAArmorTemplate extends ArmorTemplate
|
||||
implements Enchantable, Penalty {
|
||||
public AbstractGradeAArmorTemplate(TemplateID id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enchant(com.l2jserver.model.world.capability.Enchantable target) {
|
||||
target.setEnchantLevel(target.getEnchantLevel() + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void penalty(Equiper user) {
|
||||
if (!(user instanceof Levelable) && !(user instanceof Castable) && !(user instanceof Equiper))
|
||||
return;
|
||||
final Levelable levelable = (Levelable) user;
|
||||
final Castable castable = (Castable) user;
|
||||
if (levelable.getLevel() < 20) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package script.template.armor;
|
||||
|
||||
import com.l2jserver.model.id.TemplateID;
|
||||
import com.l2jserver.model.template.ArmorTemplate;
|
||||
|
||||
public abstract class AbstractNoGradeArmorTemplate extends ArmorTemplate {
|
||||
public AbstractNoGradeArmorTemplate(TemplateID id) {
|
||||
super(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package script.template.armor;
|
||||
|
||||
import com.l2jserver.model.world.capability.Attackable;
|
||||
import com.l2jserver.model.world.capability.Attacker;
|
||||
import com.l2jserver.model.world.capability.Damagable;
|
||||
import com.l2jserver.model.world.capability.Enchantable;
|
||||
|
||||
public class Dummy2ArmorTemplate extends AbstractGradeAArmorTemplate {
|
||||
private static final int REDUCED_DAMAGE_PHYSICAL = 10;
|
||||
private static final int REDUCED_DAMAGE_MAGICAL = 10;
|
||||
private static final int MAX_ENCHANT = 10;
|
||||
|
||||
public Dummy2ArmorTemplate() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend(Attacker source, Attackable target) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interceptIncomingDamage(Damagable target) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enchant(Enchantable target) {
|
||||
if (target.getEnchantLevel() >= MAX_ENCHANT)
|
||||
return;
|
||||
super.enchant(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPhysicalDefense() {
|
||||
return REDUCED_DAMAGE_PHYSICAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMagicalDefense() {
|
||||
return REDUCED_DAMAGE_MAGICAL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package script.template.armor;
|
||||
|
||||
import com.l2jserver.model.world.capability.Attackable;
|
||||
import com.l2jserver.model.world.capability.Attacker;
|
||||
import com.l2jserver.model.world.capability.Damagable;
|
||||
|
||||
public class DummyArmorTemplate extends AbstractNoGradeArmorTemplate {
|
||||
private static final int REDUCED_DAMAGE_PHYSICAL = 10;
|
||||
private static final int REDUCED_DAMAGE_MAGICAL = 10;
|
||||
|
||||
public DummyArmorTemplate() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend(Attacker source, Attackable target) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interceptIncomingDamage(Damagable target) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPhysicalDefense() {
|
||||
return REDUCED_DAMAGE_PHYSICAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMagicalDefense() {
|
||||
return REDUCED_DAMAGE_MAGICAL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package script.template.item;
|
||||
|
||||
import com.l2jserver.model.id.TemplateID;
|
||||
import com.l2jserver.model.template.ItemTemplate;
|
||||
|
||||
public class AdenaItemTemplate extends ItemTemplate {
|
||||
public static final TemplateID ID = new TemplateID(57);
|
||||
|
||||
public AdenaItemTemplate() {
|
||||
super(ID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package script.template.item;
|
||||
|
||||
import com.l2jserver.model.template.PotionTemplate;
|
||||
import com.l2jserver.model.world.capability.Attackable;
|
||||
import com.l2jserver.model.world.capability.Attacker;
|
||||
|
||||
public class TestPotionTemplate extends PotionTemplate {
|
||||
public TestPotionTemplate() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consume(Attacker source, Attackable target) {
|
||||
//TODO consume item
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package script.template.skill;
|
||||
|
||||
import com.l2jserver.model.template.SkillTemplate;
|
||||
import com.l2jserver.model.world.capability.Castable;
|
||||
import com.l2jserver.model.world.capability.Caster;
|
||||
|
||||
public class TestSkillTemplate extends SkillTemplate {
|
||||
public TestSkillTemplate() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cast(Caster caster, Castable target) {
|
||||
// TODO do casting
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package script.template.weapon;
|
||||
|
||||
import com.l2jserver.model.template.WeaponTemplate;
|
||||
import com.l2jserver.model.world.capability.Attackable;
|
||||
import com.l2jserver.model.world.capability.Attacker;
|
||||
|
||||
public class TestWeaponTemplate extends WeaponTemplate {
|
||||
private static final int DAMAGE_PHYSICAL = 10;
|
||||
private static final int DAMAGE_MAGICAL = 10;
|
||||
private static final int MAX_ENCHANT_LEVEL = 10;
|
||||
|
||||
public TestWeaponTemplate() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Attacker source, Attackable target) {
|
||||
source.attack(target, this);
|
||||
target.receiveAttack(source, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPhysicalDamage() {
|
||||
return DAMAGE_PHYSICAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMagicalDamage() {
|
||||
return DAMAGE_MAGICAL;
|
||||
}
|
||||
}
|
||||
23
data/script/template/template.xml
Normal file
23
data/script/template/template.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version='1.0' encoding='UTF-8' ?>
|
||||
|
||||
<!--
|
||||
~ This file is part of l2jserver.
|
||||
~
|
||||
~ 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/>.
|
||||
-->
|
||||
|
||||
<scriptlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../contexts.xsd">
|
||||
<scriptinfo root="./data/script/template"/>
|
||||
</scriptlist>
|
||||
Reference in New Issue
Block a user