Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.prophanis.game.node.entity.joint.old_combat.battle.impl;
- import org.prophanis.game.node.entity.Entity;
- import org.prophanis.game.node.entity.joint.Animator.Priority;
- import org.prophanis.game.node.entity.joint.old_combat.CombatResource;
- import org.prophanis.game.node.entity.joint.old_combat.battle.BattleStyle;
- import org.prophanis.game.node.entity.joint.old_combat.hit.Hit;
- import org.prophanis.game.node.entity.npc.NPC;
- import org.prophanis.game.node.entity.player.Player;
- import org.prophanis.game.node.entity.player.joint.Equipment;
- import org.prophanis.game.node.entity.pulse.PulseEvent;
- import org.prophanis.game.node.entity.update.context.Animation;
- import org.prophanis.game.node.item.Item;
- /**
- * A class containing a melee attack singleton.
- * @author Displee
- */
- public class MeleeBattle extends BattleStyle {
- @Override
- public boolean canSwing(Entity entity, Entity victim) {
- final boolean inRange = entity.getCenterLocation().withinDistance(victim.getCenterLocation(), distance(entity, victim) + (entity.getSize() >> 1) + (victim.getSize() >> 1));
- return inRange;
- }
- @Override
- public int swing(Entity entity, Entity victim) {
- boolean face = true;
- if (victim.getAttributes().get("last_face_entity", -1) == entity.getClientIndex()) {
- face = false;
- }
- if (face) {
- victim.face(entity);
- }
- return 1;
- }
- @Override
- public void impact(Entity entity, Entity victim) {
- Hit[] hits = new Hit[1];
- final boolean special = entity instanceof Player && ((Player) entity).getVarpManager().get(301) == 1;
- if (super.handleSpecial(entity)) {
- if (entity instanceof Player) {
- hits = CombatResource.calculateSpecialHits(entity);
- } else {
- //NPC Specials?
- }
- entity.getAttributes().set("special_request", false);
- } else {
- if (special) {
- return;
- }
- entity.getAnimator().animate(new Animation(CombatResource.getAttackAnimation(entity), Priority.HIGH));
- hits[0] = CombatResource.calculateNormalHit(entity);
- }
- for (Hit hit : hits) {
- if (hit != null) {
- victim.getCombatManager().getHits().add(hit);
- }
- }
- }
- @Override
- public void visualizeImpact(Entity entity, Entity victim) {
- if (!victim.getCombatManager().getHits().isEmpty()) {
- for (int i = 0; i < 2; i++) {
- final Hit hit = victim.getCombatManager().getHits().poll();
- if (hit != null) {
- victim.impact(entity, hit);
- victim.onImpact(entity);
- }
- }
- if (!victim.getCombatManager().getHits().isEmpty()) {
- victim.getPulseManager().register(new PulseEvent<Entity>(2) {
- @Override
- public boolean handle(Entity node) {
- for (int i = 0; i < 2; i++) {
- final Hit hit = victim.getCombatManager().getHits().poll();
- if (hit != null) {
- victim.impact(entity, hit);
- }
- }
- return true;
- }
- });
- }
- victim.getAnimator().animate(new Animation(CombatResource.getDefenceAnimation(victim)));
- }
- }
- @Override
- public int interval(Entity entity, Entity victim) {
- if (entity instanceof Player) {
- final Player player = (Player) entity;
- final Item item = player.getEquipment().get(Equipment.SLOT_WEAPON);
- if (item != null) {
- return item.getDefinition().getAttackInterval();
- }
- return 3;
- } else {
- return ((NPC) entity).getDefinition().getAttackDelay();
- }
- }
- @Override
- public int distance(Entity entity, Entity victim) {
- if (entity instanceof Player) {
- final Item weapon = ((Player) entity).getEquipment().get(Equipment.SLOT_WEAPON);
- if (weapon != null && ((weapon.getId() >= 3190 && weapon.getId() <= 3204) || weapon.getId() == 6599)) {
- return 2;//Halberds
- }
- }
- return victim.getSize();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement