mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-11 09:42:54 +00:00
@@ -1,8 +1,10 @@
|
||||
package com.l2jserver.model.world;
|
||||
|
||||
import com.l2jserver.model.id.object.ActorID;
|
||||
import com.l2jserver.model.template.SkillTemplate;
|
||||
import com.l2jserver.model.template.capability.Attackable;
|
||||
import com.l2jserver.model.world.actor.ActorEffects;
|
||||
import com.l2jserver.model.world.actor.ActorSkillContainer;
|
||||
import com.l2jserver.model.world.capability.Actor;
|
||||
import com.l2jserver.model.world.capability.Attacker;
|
||||
import com.l2jserver.model.world.capability.Castable;
|
||||
@@ -31,15 +33,25 @@ public abstract class AbstractActor extends AbstractObject implements Actor {
|
||||
HUMAN(0x00), ELF(0x01), DARK_ELF(0x02), ORC(0x03), DWARF(0x04), KAMAEL(
|
||||
0x05);
|
||||
|
||||
public final int option;
|
||||
/**
|
||||
* The numeric ID representing this race
|
||||
*/
|
||||
public final int id;
|
||||
|
||||
Race(int option) {
|
||||
this.option = option;
|
||||
Race(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static Race fromOption(int option) {
|
||||
/**
|
||||
* Finds the race based on the <tt>id</tt>
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
* @return the race constant
|
||||
*/
|
||||
public static Race fromOption(int id) {
|
||||
for (final Race race : values()) {
|
||||
if (race.option == option)
|
||||
if (race.id == id)
|
||||
return race;
|
||||
}
|
||||
return null;
|
||||
@@ -91,6 +103,10 @@ public abstract class AbstractActor extends AbstractObject implements Actor {
|
||||
* The currently effects active on the actor
|
||||
*/
|
||||
protected final ActorEffects effects = new ActorEffects(this);
|
||||
/**
|
||||
* The skills learned by this actor
|
||||
*/
|
||||
protected final ActorSkillContainer skills = new ActorSkillContainer(this);
|
||||
|
||||
@Override
|
||||
public void receiveDamage(int damage) {
|
||||
@@ -212,6 +228,11 @@ public abstract class AbstractActor extends AbstractObject implements Actor {
|
||||
return effects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActorSkillContainer getSkills() {
|
||||
return skills;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die(WorldObject killer) {
|
||||
// TODO
|
||||
@@ -247,4 +268,9 @@ public abstract class AbstractActor extends AbstractObject implements Actor {
|
||||
public void equip(Equiper equiper) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActorID<?> getID() {
|
||||
return (ActorID<?>) super.getID();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.l2jserver.model.world.character.CharacterCalculatedAttributes;
|
||||
import com.l2jserver.model.world.character.CharacterClass;
|
||||
import com.l2jserver.model.world.character.CharacterFriendList;
|
||||
import com.l2jserver.model.world.character.CharacterInventory;
|
||||
import com.l2jserver.model.world.character.CharacterShortcutContainer;
|
||||
|
||||
/**
|
||||
* This class represents a playable character in Lineage II world.
|
||||
@@ -69,6 +70,11 @@ public class L2Character extends Player {
|
||||
* The list of friend of this character
|
||||
*/
|
||||
private final CharacterFriendList friendList = new CharacterFriendList(this);
|
||||
/**
|
||||
* The shortcut container of this character
|
||||
*/
|
||||
private final CharacterShortcutContainer shortcuts = new CharacterShortcutContainer(
|
||||
this);
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
@@ -239,6 +245,13 @@ public class L2Character extends Player {
|
||||
return friendList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the shortcuts
|
||||
*/
|
||||
public CharacterShortcutContainer getShortcuts() {
|
||||
return shortcuts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharacterID getID() {
|
||||
return (CharacterID) super.getID();
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.l2jserver.model.world.actor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jserver.model.game.Skill;
|
||||
import com.l2jserver.model.id.template.SkillTemplateID;
|
||||
import com.l2jserver.model.template.SkillTemplate;
|
||||
import com.l2jserver.model.world.capability.Actor;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
* The Skill container will manage all learned skills by an actor. This class
|
||||
* can also create the {@link Skill} object if an actor is learning a new skill.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class ActorSkillContainer implements Iterable<Skill> {
|
||||
/**
|
||||
* The actor
|
||||
*/
|
||||
private final Actor actor;
|
||||
/**
|
||||
* The learned skill list
|
||||
*/
|
||||
private List<Skill> skills = CollectionFactory.newList(Skill.class);
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param actor
|
||||
* the actor
|
||||
*/
|
||||
public ActorSkillContainer(Actor actor) {
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Learns a new skill
|
||||
*
|
||||
* @param template
|
||||
* the skill to be learned
|
||||
* @param level
|
||||
* the skill level
|
||||
* @return the created skill object, null if skill existed or could not be
|
||||
* learned.
|
||||
*/
|
||||
public Skill learn(SkillTemplate template, int level) {
|
||||
if (hasSkill(template.getID()) != null)
|
||||
return null;
|
||||
if (level > template.getMaximumLevel())
|
||||
level = template.getMaximumLevel();
|
||||
final Skill newSkill = template.create();
|
||||
newSkill.setLevel(level);
|
||||
if (skills.add(newSkill))
|
||||
return newSkill;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Learns a new skill. The skill <tt>level</tt> will be 1.
|
||||
*
|
||||
* @param template
|
||||
* the skill to be learned
|
||||
* @return the created skill object, null if skill existed or could not be
|
||||
* learned.
|
||||
* @see ActorSkillContainer#learn(SkillTemplate, int)
|
||||
*/
|
||||
public Skill learn(SkillTemplate template) {
|
||||
return learn(template, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Learns a new skill
|
||||
*
|
||||
* @param skill
|
||||
* the skill to be learned
|
||||
* @param level
|
||||
* the skill level
|
||||
* @return the created skill object, null if skill existed or could not be
|
||||
* learned.
|
||||
* @see ActorSkillContainer#learn(SkillTemplate, int)
|
||||
*/
|
||||
public Skill learn(SkillTemplateID skill, int level) {
|
||||
return learn(skill.getTemplate(), level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Learns a new skill. The skill <tt>level</tt> will be 1.
|
||||
*
|
||||
* @param skill
|
||||
* the skill to be learned
|
||||
* @return the created skill object, null if skill existed or could not be
|
||||
* learned.
|
||||
* @see ActorSkillContainer#learn(SkillTemplate, int)
|
||||
*/
|
||||
public Skill learn(SkillTemplateID skill) {
|
||||
return learn(skill, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test is the actor knows the given <tt>skillTemplate</tt>
|
||||
*
|
||||
* @param skillTemplate
|
||||
* the skill
|
||||
* @return return the learned skill or null if does not learned skill
|
||||
*/
|
||||
public Skill hasSkill(SkillTemplateID skillTemplate) {
|
||||
for (final Skill skill : this.skills) {
|
||||
if (skill.getSkillTemplateID().equals(skillTemplate))
|
||||
return skill;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all skills in the {@link Collection} to this container
|
||||
*
|
||||
* @param skills
|
||||
* the skill collection
|
||||
*/
|
||||
public void load(Collection<Skill> skills) {
|
||||
this.skills.addAll(skills);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Skill> iterator() {
|
||||
return skills.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actor
|
||||
*/
|
||||
public Actor getActor() {
|
||||
return actor;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.l2jserver.model.world.capability;
|
||||
|
||||
import com.l2jserver.model.id.object.ActorID;
|
||||
import com.l2jserver.model.world.AbstractObject;
|
||||
import com.l2jserver.model.world.actor.ActorEffects;
|
||||
import com.l2jserver.model.world.actor.ActorEvent;
|
||||
import com.l2jserver.model.world.actor.ActorListener;
|
||||
import com.l2jserver.model.world.actor.ActorSkillContainer;
|
||||
|
||||
/**
|
||||
* Defines an {@link AbstractObject} that defines an Actor (NPC, player, pet,
|
||||
@@ -14,5 +16,16 @@ import com.l2jserver.model.world.actor.ActorListener;
|
||||
public interface Actor extends Listenable<ActorListener, ActorEvent>,
|
||||
Spawnable, Pointable, Damagable, Attackable, Attacker, Castable,
|
||||
Caster, Levelable, Killable, Equiper, Equipable {
|
||||
/**
|
||||
* @return the actor effects
|
||||
*/
|
||||
ActorEffects getEffects();
|
||||
|
||||
/**
|
||||
* @return the actor skills
|
||||
*/
|
||||
ActorSkillContainer getSkills();
|
||||
|
||||
@Override
|
||||
ActorID<?> getID();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ public enum CharacterClass {
|
||||
KNIGHT), ROGUE(0x07, HUMAN_FIGHTER), TREASURE_HUNTER(0x08, ROGUE), HAWKEYE(
|
||||
0x09, ROGUE),
|
||||
// 3rd classes
|
||||
DUELIST(0x58, GLADIATOR), DREADNOUGHT(0x59, WARLORD), phoenixKnight(0x5a,
|
||||
PALADIN), hellKnight(0x5b, DARK_AVENGER), sagittarius(0x5c, HAWKEYE), adventurer(
|
||||
DUELIST(0x58, GLADIATOR), DREADNOUGHT(0x59, WARLORD), PHOENIX_KNIGHT(0x5a,
|
||||
PALADIN), HELL_KNIGHT(0x5b, DARK_AVENGER), SAGITTARIUS(0x5c, HAWKEYE), ADVENTURER(
|
||||
0x5d, TREASURE_HUNTER),
|
||||
|
||||
/**
|
||||
@@ -61,8 +61,8 @@ public enum CharacterClass {
|
||||
0x22, PALUS_KNIGHT), ASSASSIN(0x23, DARK_FIGHTER), ABYSS_WALKER(
|
||||
0x24, ASSASSIN), PHANTOM_RANGER(0x25, ASSASSIN),
|
||||
// 3rd classes
|
||||
SHILLIEN_TEMPLAR(0x6a, SHILLIEN_KNIGHT), spectralDancer(0x6b, BLADEDANCER), ghostHunter(
|
||||
0x6c, ABYSS_WALKER), ghostSentinel(0x6d, PHANTOM_RANGER),
|
||||
SHILLIEN_TEMPLAR(0x6a, SHILLIEN_KNIGHT), spectralDancer(0x6b, BLADEDANCER), GHOST_HUNTER(
|
||||
0x6c, ABYSS_WALKER), GHOST_SENTINEL(0x6d, PHANTOM_RANGER),
|
||||
|
||||
/**
|
||||
* Dark elf mystic
|
||||
|
||||
@@ -46,10 +46,10 @@ public class CharacterInventory implements Iterable<Item> {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the character
|
||||
* @return the amount if items in inventory
|
||||
*/
|
||||
public L2Character getCharacter() {
|
||||
return character;
|
||||
public int getItemCount() {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,4 +85,11 @@ public class CharacterInventory implements Iterable<Item> {
|
||||
public enum InventoryPaperdoll {
|
||||
UNDERWEAR, HEAD, HAIR1, HAIR2, NECK, RIGHT_HAND, LEFT_HAND, RIGHT_EAR, LEFT_EAR, GLOVES, LEGS, LEFT_FEET, RIGHT_FEET, RIGHT_FINGER, LEFT_FINGER, LEFT_BRACELET, RIGHT_BRACELET, DECORATION_1, DECOREATION_2, DECORATION_3, DECORATION_4, DECORATION_5, DECORATION_6, CLOAK, BELT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the character
|
||||
*/
|
||||
public L2Character getCharacter() {
|
||||
return character;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.l2jserver.model.world.character;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jserver.model.game.CharacterShortcut;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
* Container that controls shortcut for character instances
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CharacterShortcutContainer implements Iterable<CharacterShortcut> {
|
||||
/**
|
||||
* The character
|
||||
*/
|
||||
private final L2Character character;
|
||||
/**
|
||||
* The shortcut list
|
||||
*/
|
||||
private List<CharacterShortcut> shortcuts = CollectionFactory
|
||||
.newList(CharacterShortcut.class);
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param character
|
||||
* the character
|
||||
*/
|
||||
public CharacterShortcutContainer(L2Character character) {
|
||||
this.character = character;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new shortcut to this container
|
||||
*
|
||||
* @param shortcut
|
||||
* the shortcut to be added
|
||||
*/
|
||||
public void register(CharacterShortcut shortcut) {
|
||||
shortcuts.add(shortcut);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters the given shortcut from this container
|
||||
*
|
||||
* @param shortcut
|
||||
* the shortcut to be removed
|
||||
*/
|
||||
public void unregister(CharacterShortcut shortcut) {
|
||||
shortcuts.remove(shortcut);
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap two shortcuts between them. Once swap is complete,
|
||||
* <tt>shortcut1</tt> will be in the place of <tt>shortcut2</tt>, and
|
||||
* <tt>shortcut2</tt> in <tt>shortcut1</tt>.
|
||||
*
|
||||
* @param shortcut1
|
||||
* the first shortcut
|
||||
* @param shortcut2
|
||||
* the second shortcut
|
||||
*/
|
||||
public void swap(CharacterShortcut shortcut1, CharacterShortcut shortcut2) {
|
||||
// only swap if is registered already
|
||||
if (!shortcuts.contains(shortcut1) || !shortcuts.contains(shortcut2))
|
||||
return;
|
||||
|
||||
final int slot1 = shortcut1.getSlot();
|
||||
final int page1 = shortcut1.getPage();
|
||||
shortcut1.setSlot(shortcut2.getSlot());
|
||||
shortcut1.setPage(shortcut2.getPage());
|
||||
shortcut2.setSlot(slot1);
|
||||
shortcut2.setPage(page1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if container is full
|
||||
*/
|
||||
public boolean isFull() {
|
||||
return shortcuts.size() >= 12 * 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if there is not shortcut registered
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return shortcuts.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all shortcuts in the given {@link Collection}. This method is
|
||||
* normally called from a DAO.
|
||||
*
|
||||
* @param shortcuts
|
||||
* the collection of shortcuts
|
||||
*/
|
||||
public void load(Collection<CharacterShortcut> shortcuts) {
|
||||
this.shortcuts.addAll(shortcuts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<CharacterShortcut> iterator() {
|
||||
return shortcuts.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the character
|
||||
*/
|
||||
public L2Character getCharacter() {
|
||||
return character;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user