RuneHive-Game
Loading...
Searching...
No Matches
PlayerMeleeStrategy.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.player;
2
3
4import com.runehive.content.activity.Activity;
5import com.runehive.content.activity.impl.duelarena.DuelArenaActivity;
6import com.runehive.content.activity.impl.duelarena.DuelRule;
7import com.runehive.content.itemaction.impl.ViggorasChainmace;
8import com.runehive.game.Animation;
9import com.runehive.game.UpdatePriority;
10import com.runehive.game.world.entity.combat.CombatType;
11import com.runehive.game.world.entity.combat.attack.FightType;
12import com.runehive.game.world.entity.combat.effect.impl.CombatPoisonEffect;
13import com.runehive.game.world.entity.combat.hit.CombatHit;
14import com.runehive.game.world.entity.combat.hit.Hit;
15import com.runehive.game.world.entity.combat.strategy.basic.MeleeStrategy;
16import com.runehive.game.world.entity.mob.Mob;
17import com.runehive.game.world.entity.mob.player.Player;
18import com.runehive.game.world.entity.mob.player.PlayerRight;
19import com.runehive.game.world.items.Item;
20import com.runehive.game.world.items.containers.equipment.Equipment;
21import com.runehive.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
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) {
50 if(weapon != null) {
51 switch(weapon.getId()) {
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
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
137 return CombatType.MELEE;
138 }
139
140 public static PlayerMeleeStrategy get() {
141 return INSTANCE;
142 }
143
144}
A Activity object constructs an in-game activity and sequences it through the start() and finish() me...
Definition Activity.java:31
static< T extends Activity > Optional< T > search(Player player, Class< T > clazz)
Definition Activity.java:60
final DuelRules rules
The duel rules for this duel session.
Class that models a single animation used by an entity.
The combat effect applied when a character needs to be poisoned.
static Optional< PoisonType > getPoisonType(Item item)
Gets the PoisonType for item wrapped in an optional.
A wrapper for a Hit object, adding additional variables for hit and hitsplat delays.
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
int getAttackDelay(Player attacker, Mob defender, FightType fightType)
Handles the mob class.
Definition Mob.java:66
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
This class represents a character controlled by a player.
Definition Player.java:125
Combat< Player > getCombat()
The combat of the mob.
Definition Player.java:759
The container class that represents an item that can be interacted with.
Definition Item.java:21
final Item get(int index)
Gets the Item located on index.
The container that manages the equipment for a player.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Represents different priorities for updating.
The enumerated type whose elements represent the fighting types.
final int getAnimation()
Gets the animation executed when this type is active.
void drain(Player player)
Drains the special bar for player.
static boolean isIronman(Player player)
Checks if the player is an ironman.