1package com.osroyale.game.world.entity.combat.strategy.player;
4import com.osroyale.content.activity.Activity;
5import com.osroyale.content.activity.impl.duelarena.DuelArenaActivity;
6import com.osroyale.content.activity.impl.duelarena.DuelRule;
7import com.osroyale.content.itemaction.impl.ViggorasChainmace;
8import com.osroyale.game.Animation;
9import com.osroyale.game.UpdatePriority;
10import com.osroyale.game.world.entity.combat.CombatType;
11import com.osroyale.game.world.entity.combat.attack.FightType;
12import com.osroyale.game.world.entity.combat.effect.impl.CombatPoisonEffect;
13import com.osroyale.game.world.entity.combat.hit.CombatHit;
14import com.osroyale.game.world.entity.combat.hit.Hit;
15import com.osroyale.game.world.entity.combat.strategy.basic.MeleeStrategy;
16import com.osroyale.game.world.entity.mob.Mob;
17import com.osroyale.game.world.entity.mob.player.Player;
18import com.osroyale.game.world.entity.mob.player.PlayerRight;
19import com.osroyale.game.world.items.Item;
20import com.osroyale.game.world.items.containers.equipment.Equipment;
21import com.osroyale.net.packet.out.SendMessage;
23public class PlayerMeleeStrategy
extends MeleeStrategy<Player> {
24 private static final PlayerMeleeStrategy INSTANCE =
new PlayerMeleeStrategy();
26 protected PlayerMeleeStrategy() {
30 public boolean canAttack(Player attacker, Mob defender) {
31 if (Activity.search(attacker, DuelArenaActivity.class).isPresent()) {
32 DuelArenaActivity activity = Activity.search(attacker, DuelArenaActivity.class).get();
33 return !activity.rules.contains(DuelRule.NO_MELEE);
37 Item weapon = attacker.equipment.get(Equipment.WEAPON_SLOT);
38 if(weapon !=
null && weapon.getId() == ViggorasChainmace.VIGGORAS_CHAINMACE_CHARGED_ID && attacker.viggorasChainmaceCharges < 1) {
39 attacker.send(
new SendMessage(
"Your Viggora's chainmace is out of charges!"));
40 attacker.getCombat().reset();
48 public void attack(Player attacker, Mob defender, Hit hit) {
49 Item weapon = attacker.equipment.get(Equipment.WEAPON_SLOT);
51 switch(weapon.getId()) {
52 case ViggorasChainmace.VIGGORAS_CHAINMACE_CHARGED_ID -> {
53 attacker.viggorasChainmaceCharges--;
60 public void start(Player attacker, Mob defender, Hit[] hits) {
61 if (attacker.isSpecialActivated()) {
62 attacker.getCombatSpecial().drain(attacker);
65 attacker.animate(getAttackAnimation(attacker, defender),
true);
67 if (!defender.isPlayer() || !PlayerRight.isIronman(attacker))
68 addCombatExperience(attacker, hits);
72 public void hit(Player attacker, Mob defender, Hit hit) {
73 if (hit.getDamage() < 1) {
77 CombatPoisonEffect.getPoisonType(attacker.equipment.getWeapon()).ifPresent(defender::poison);
81 public CombatHit[] getHits(Player attacker, Mob defender) {
82 return new CombatHit[]{nextMeleeHit(attacker, defender)};
86 public int getAttackDelay(Player attacker, Mob defender, FightType fightType) {
87 return attacker.getCombat().getFightType().getDelay();
91 public int getAttackDistance(Player attacker, FightType fightType) {
92 return fightType.getDistance();
96 public Animation getAttackAnimation(Player attacker, Mob defender) {
97 int animation = attacker.getCombat().getFightType().getAnimation();
99 if (attacker.equipment.hasShield()) {
100 Item weapon = attacker.equipment.getShield();
101 FightType fightType = attacker.getCombat().getFightType();
102 animation = weapon.getAttackAnimation(fightType).orElse(animation);
105 if (attacker.equipment.hasWeapon()) {
106 Item weapon = attacker.equipment.getWeapon();
107 FightType fightType = attacker.getCombat().getFightType();
108 animation = weapon.getAttackAnimation(fightType).orElse(animation);
111 if (attacker.overrides.hasOverride(Equipment.WEAPON_SLOT)) {
112 final var item = attacker.overrides.get(Equipment.WEAPON_SLOT);
113 animation = attacker.overrides.getFightType(item).getAnimation();
116 return new Animation(animation, UpdatePriority.HIGH);
136 public CombatType getCombatType() {
137 return CombatType.MELEE;
140 public static PlayerMeleeStrategy
get() {