RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
PlayerMeleeStrategy.java
1package com.osroyale.game.world.entity.combat.strategy.player;
2
3
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;
22
23public class PlayerMeleeStrategy extends MeleeStrategy<Player> {
24 private static final PlayerMeleeStrategy INSTANCE = new PlayerMeleeStrategy();
25
26 protected PlayerMeleeStrategy() {
27 }
28
29 @Override
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);
34 }
35
36
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();
41 return false;
42 }
43
44 return true;
45 }
46
47 @Override
48 public void attack(Player attacker, Mob defender, Hit hit) {
49 Item weapon = attacker.equipment.get(Equipment.WEAPON_SLOT);
50 if(weapon != null) {
51 switch(weapon.getId()) {
52 case ViggorasChainmace.VIGGORAS_CHAINMACE_CHARGED_ID -> {
53 attacker.viggorasChainmaceCharges--;
54 }
55 }
56 }
57 }
58
59 @Override
60 public void start(Player attacker, Mob defender, Hit[] hits) {
61 if (attacker.isSpecialActivated()) {
62 attacker.getCombatSpecial().drain(attacker);
63 }
64
65 attacker.animate(getAttackAnimation(attacker, defender), true);
66
67 if (!defender.isPlayer() || !PlayerRight.isIronman(attacker))
68 addCombatExperience(attacker, hits);
69 }
70
71 @Override
72 public void hit(Player attacker, Mob defender, Hit hit) {
73 if (hit.getDamage() < 1) {
74 return;
75 }
76
77 CombatPoisonEffect.getPoisonType(attacker.equipment.getWeapon()).ifPresent(defender::poison);
78 }
79
80 @Override
81 public CombatHit[] getHits(Player attacker, Mob defender) {
82 return new CombatHit[]{nextMeleeHit(attacker, defender)};
83 }
84
85 @Override
86 public int getAttackDelay(Player attacker, Mob defender, FightType fightType) {
87 return attacker.getCombat().getFightType().getDelay();
88 }
89
90 @Override
91 public int getAttackDistance(Player attacker, FightType fightType) {
92 return fightType.getDistance();
93 }
94
95 @Override
96 public Animation getAttackAnimation(Player attacker, Mob defender) {
97 int animation = attacker.getCombat().getFightType().getAnimation();
98
99 if (attacker.equipment.hasShield()) {
100 Item weapon = attacker.equipment.getShield();
101 FightType fightType = attacker.getCombat().getFightType();
102 animation = weapon.getAttackAnimation(fightType).orElse(animation);
103 }
104
105 if (attacker.equipment.hasWeapon()) {
106 Item weapon = attacker.equipment.getWeapon();
107 FightType fightType = attacker.getCombat().getFightType();
108 animation = weapon.getAttackAnimation(fightType).orElse(animation);
109 }
110
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();
114 }
115
116 return new Animation(animation, UpdatePriority.HIGH);
117 }
118
119 /*@Override
120 public int modifyAccuracy(Player attacker, Mob defender, int roll) {
121 if (CombatUtil.isFullVoid(attacker) && attacker.equipment.contains(11665)) {
122 roll *= 1.10;
123 }
124 return roll;
125 }
126
127 @Override
128 public int modifyAggressive(Player attacker, Mob defender, int roll) {
129 if (CombatUtil.isFullVoid(attacker) && attacker.equipment.contains(11665)) {
130 roll *= 1.10;
131 }
132 return roll;
133 }*/
134
135 @Override
136 public CombatType getCombatType() {
137 return CombatType.MELEE;
138 }
139
140 public static PlayerMeleeStrategy get() {
141 return INSTANCE;
142 }
143
144}