mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-08 08:23:11 +00:00
Initial work in the attack service
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
150
src/main/java/com/l2jserver/model/server/AttackHit.java
Normal file
150
src/main/java/com/l2jserver/model/server/AttackHit.java
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
* This class represents an attack hit.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class AttackHit {
|
||||
/**
|
||||
* The actor attacking <tt>target</tt>
|
||||
*/
|
||||
private final Actor attacker;
|
||||
/**
|
||||
* The actor being attacked by <tt>attacker</tt>
|
||||
*/
|
||||
private final Actor target;
|
||||
/**
|
||||
* The damage dealt by this hit
|
||||
*/
|
||||
private double damage;
|
||||
/**
|
||||
* This hit flags (i.e. critical)
|
||||
*/
|
||||
private List<AttackHitFlag> flags = CollectionFactory.newList();
|
||||
|
||||
/**
|
||||
* An enumeration containing all possible attack flags
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public enum AttackHitFlag {
|
||||
/**
|
||||
* The hit used soulshot
|
||||
*/
|
||||
SOULSHOT((byte) 0x10),
|
||||
/**
|
||||
* The attack dealt critical damage
|
||||
*/
|
||||
CRITICAL((byte) 0x20),
|
||||
/**
|
||||
* The shield blocked this hit
|
||||
*/
|
||||
SHIELD_BLOCKED((byte) 0x40),
|
||||
/**
|
||||
* The <tt>attacker</tt> missed the hit
|
||||
*/
|
||||
MISS((byte) 0x80);
|
||||
|
||||
/**
|
||||
* The byte value of the flag
|
||||
*/
|
||||
public final byte flag;
|
||||
|
||||
AttackHitFlag(byte flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param attacker
|
||||
* the actor attacking <tt>target</tt>
|
||||
* @param target
|
||||
* the actor being attacked by <tt>attacker</tt>
|
||||
*/
|
||||
public AttackHit(Actor attacker, Actor target) {
|
||||
this.attacker = attacker;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param attacker
|
||||
* the actor attacking <tt>target</tt>
|
||||
* @param target
|
||||
* the actor being attacked by <tt>attacker</tt>
|
||||
* @param flags
|
||||
* the hit flags
|
||||
*/
|
||||
public AttackHit(Actor attacker, Actor target, AttackHitFlag... flags) {
|
||||
this.attacker = attacker;
|
||||
this.target = target;
|
||||
Collections.addAll(this.flags, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the attacker
|
||||
*/
|
||||
public Actor getAttacker() {
|
||||
return attacker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the target
|
||||
*/
|
||||
public Actor getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the damage
|
||||
*/
|
||||
public double getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the flags
|
||||
*/
|
||||
public List<AttackHitFlag> getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the flags as a byte value
|
||||
*/
|
||||
public byte getFlagsByte() {
|
||||
byte flags = 0;
|
||||
for (final AttackHitFlag flag : this.flags) {
|
||||
if (flag == AttackHitFlag.MISS)
|
||||
return AttackHitFlag.MISS.flag;
|
||||
flags |= flag.flag;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import com.l2jserver.model.id.template.ItemTemplateID;
|
||||
import com.l2jserver.model.id.template.NPCTemplateID;
|
||||
import com.l2jserver.model.world.Actor.ActorSex;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.controller.NPCController;
|
||||
import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
|
||||
import com.l2jserver.util.jaxb.NPCTemplateIDAdapter;
|
||||
|
||||
@@ -47,8 +48,8 @@ public class NPCTemplate extends ActorTemplate<NPC> {
|
||||
@XmlAttribute(name = "id")
|
||||
@XmlJavaTypeAdapter(value = NPCTemplateIDAdapter.class)
|
||||
protected NPCTemplateID id = null;
|
||||
@XmlAttribute(name = "type")
|
||||
protected String type = null;
|
||||
@XmlAttribute(name = "controller")
|
||||
protected Class<? extends NPCController> controller;
|
||||
|
||||
@XmlElement(name = "info")
|
||||
protected NPCInformationMetadata info = null;
|
||||
@@ -274,10 +275,10 @@ public class NPCTemplate extends ActorTemplate<NPC> {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
* @return the controller class
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
public Class<? extends NPCController> getControllerClass() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.character.event;
|
||||
|
||||
import com.l2jserver.model.id.ObjectID;
|
||||
import com.l2jserver.model.server.AttackHit;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.Player;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
|
||||
/**
|
||||
* Event triggered once a character attacks something
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CharacterAttackEvent implements CharacterEvent {
|
||||
/**
|
||||
* The character that is attacking
|
||||
*/
|
||||
private final L2Character character;
|
||||
/**
|
||||
* The character that is being attacked
|
||||
*/
|
||||
private final L2Character target;
|
||||
/**
|
||||
* The {@link AttackHit} object for this attack
|
||||
*/
|
||||
private final AttackHit hit;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param character
|
||||
* the character
|
||||
* @param point
|
||||
* the character being attacked
|
||||
*/
|
||||
public CharacterAttackEvent(L2Character character, L2Character target,
|
||||
AttackHit hit) {
|
||||
this.character = character;
|
||||
this.target = target;
|
||||
this.hit = hit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the target
|
||||
*/
|
||||
public L2Character getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the hit
|
||||
*/
|
||||
public AttackHit getHit() {
|
||||
return hit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return character;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Actor getActor() {
|
||||
return character;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldObject getObject() {
|
||||
return character;
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2Character getCharacter() {
|
||||
return character;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectID<?>[] getDispatchableObjects() {
|
||||
return new ObjectID<?>[] { character.getID(), target.getID() };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.npc.calculator;
|
||||
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.util.calculator.Calculator;
|
||||
import com.l2jserver.util.calculator.Function;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class NPCCalculator extends Calculator<L2Character> {
|
||||
public NPCCalculator(
|
||||
Function<L2Character>... functions) {
|
||||
super(functions);
|
||||
}
|
||||
}
|
||||
@@ -31,32 +31,38 @@ import com.l2jserver.util.html.markup.HtmlTemplate;
|
||||
import com.l2jserver.util.html.markup.MarkupTag;
|
||||
|
||||
/**
|
||||
* The {@link AbstractNPCController} handful methods for controlling NPCs.
|
||||
* The {@link BaseNPCController} handful methods for controlling NPCs. This
|
||||
* implementation is also used for {@link NPC NPCs} that don't have any special
|
||||
* behavior.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class AbstractNPCController implements NPCController {
|
||||
public class BaseNPCController implements NPCController {
|
||||
@Override
|
||||
public void action(NPC npc, Lineage2Connection conn, L2Character character,
|
||||
String... args) throws L2Exception {
|
||||
final String... args) throws L2Exception {
|
||||
if (args.length == 2) {
|
||||
if (args[0].equals("Chat")) {
|
||||
talk(npc, conn, character,
|
||||
Arrays.copyOfRange(args, 1, args.length));
|
||||
return;
|
||||
if (talk(npc, conn, character,
|
||||
Arrays.copyOfRange(args, 1, args.length)))
|
||||
return;
|
||||
}
|
||||
} else if (args.length == 0 || args.length == 1) {
|
||||
talk(npc, conn, character, new String[0]);
|
||||
return;
|
||||
} else {
|
||||
final HtmlTemplate template = new HtmlTemplate() {
|
||||
@Override
|
||||
protected void build(MarkupTag body) {
|
||||
body.text("Sorry ${name}, but you cannot interact with me yet!");
|
||||
}
|
||||
}.register("name", character.getName());
|
||||
conn.write(new NPCHtmlMessagePacket(npc, template));
|
||||
// default action is talk
|
||||
if (talk(npc, conn, character, new String[0]))
|
||||
return;
|
||||
}
|
||||
// action not handled message
|
||||
final HtmlTemplate template = new HtmlTemplate() {
|
||||
@Override
|
||||
protected void build(MarkupTag body) {
|
||||
body.text(
|
||||
"Sorry ${name}, but the action you have requested is not yet implemented.")
|
||||
.p();
|
||||
body.text("Arguments: " + Arrays.toString(args));
|
||||
}
|
||||
}.register("name", character.getName());
|
||||
conn.write(new NPCHtmlMessagePacket(npc, template));
|
||||
conn.sendActionFailed();
|
||||
}
|
||||
|
||||
@@ -71,16 +77,21 @@ public class AbstractNPCController implements NPCController {
|
||||
* the interacting character
|
||||
* @param args
|
||||
* the action arguments
|
||||
* @return true if chat message was sent
|
||||
* @throws L2Exception
|
||||
*/
|
||||
protected void talk(NPC npc, Lineage2Connection conn,
|
||||
protected boolean talk(NPC npc, Lineage2Connection conn,
|
||||
L2Character character, String... args) throws L2Exception {
|
||||
String id = null;
|
||||
if (args.length >= 1) {
|
||||
id = args[0];
|
||||
}
|
||||
conn.write(new NPCHtmlMessagePacket(npc, getHTML(npc, id)));
|
||||
final String html = getHTML(npc, id);
|
||||
if (html == null)
|
||||
return false;
|
||||
conn.write(new NPCHtmlMessagePacket(npc, html));
|
||||
conn.sendActionFailed();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.npc.controller;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.packet.server.ActorStatusUpdatePacket;
|
||||
import com.l2jserver.game.net.packet.server.ActorStatusUpdatePacket.Stat;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.service.game.character.CharacterService;
|
||||
import com.l2jserver.util.exception.L2Exception;
|
||||
|
||||
/**
|
||||
* This controller is used to control teleporters (e.g. gatekeepers)
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class MonsterController extends BaseNPCController {
|
||||
/**
|
||||
* The {@link CharacterService}
|
||||
*/
|
||||
@Inject
|
||||
protected CharacterService charService;
|
||||
|
||||
@Override
|
||||
public void action(NPC npc, Lineage2Connection conn, L2Character character,
|
||||
String... args) throws L2Exception {
|
||||
// send hp update
|
||||
conn.write(new ActorStatusUpdatePacket(npc).add(Stat.MAX_HP,
|
||||
(int) npc.getTemplate().getMaximumHP()).add(Stat.HP,
|
||||
(int) npc.getHP()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.npc.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.packet.server.NPCHtmlMessagePacket;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.util.exception.L2Exception;
|
||||
import com.l2jserver.util.html.markup.HtmlTemplate;
|
||||
import com.l2jserver.util.html.markup.MarkupTag;
|
||||
|
||||
/**
|
||||
* This is a pseudo-controller used as an placeholder for controllers that were
|
||||
* not yet implemented.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class NotImplementedNPCController extends BaseNPCController {
|
||||
@Override
|
||||
public void action(NPC npc, Lineage2Connection conn, L2Character character,
|
||||
final String... args) throws L2Exception {
|
||||
// action not handled
|
||||
final HtmlTemplate template = new HtmlTemplate() {
|
||||
@Override
|
||||
protected void build(MarkupTag body) {
|
||||
body.text(
|
||||
"Sorry ${name}, but the action you have requested is not yet implemented.")
|
||||
.p();
|
||||
body.text("Arguments: " + Arrays.toString(args));
|
||||
}
|
||||
}.register("name", character.getName());
|
||||
conn.write(new NPCHtmlMessagePacket(npc, template));
|
||||
conn.sendActionFailed();
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import com.l2jserver.util.exception.L2Exception;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class TeleporterController extends AbstractNPCController {
|
||||
public class TeleporterController extends BaseNPCController {
|
||||
/**
|
||||
* The {@link SpawnService}
|
||||
*/
|
||||
@@ -47,11 +47,13 @@ public class TeleporterController extends AbstractNPCController {
|
||||
final TeleportationTemplate tele = teleportationIdProvider
|
||||
.createID(Integer.parseInt(args[1])).getTemplate();
|
||||
if (tele == null) {
|
||||
// TODO chat
|
||||
// TODO notify user that his destination is invalid
|
||||
conn.sendActionFailed();
|
||||
return;
|
||||
} else {
|
||||
// TODO remove items from character inventory
|
||||
spawnService.teleport(character, tele.getCoordinate());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user