RuneHive-Game
Loading...
Searching...
No Matches
DragonfireShield.java
Go to the documentation of this file.
1package com.runehive.content.itemaction.impl;
2
3import com.runehive.content.itemaction.ItemAction;
4import com.runehive.game.world.entity.combat.Combat;
5import com.runehive.game.world.entity.combat.strategy.player.custom.DragonfireShieldStrategy;
6import com.runehive.game.world.entity.mob.Mob;
7import com.runehive.game.world.entity.mob.player.Player;
8import com.runehive.game.world.items.Item;
9
10public class DragonfireShield extends ItemAction {
11
12 @Override
13 public String name() {
14 return "Dragonfire shield";
15 }
16
17 @Override
18 public boolean inventory(Player player, Item item, int opcode) {
19 if (opcode == 2) {
20 inspect(player);
21 } else if (opcode == 3) {
22 empty(player);
23 }
24 return true;
25 }
26
27 private void empty(Player player) {
28 if (player.dragonfireCharges > 0) {
29 player.dragonfireCharges = 0;
30 player.graphic(1160);
31 player.inventory.replace(11283, 11284, true);
32 player.message("You clear your remaining charges.");
33 } else {
34 player.message("You have no remaining charges.");
35 }
36 }
37
38 private void inspect(Player player) {
39 player.message("You have " + player.dragonfireCharges + " charges remaining.");
40 }
41
42 @Override
43 public boolean equipment(Player player, Item item, int opcode) {
44 if (opcode == 1) {
45 long remaining = System.currentTimeMillis() - player.dragonfireUsed;
46 if (remaining < 120_000) {
47 player.message("My shield still needs " + (120 - remaining / 1000) + " seconds to recharge.");
48 return true;
49 }
50 if (player.dragonfireCharges == 0) {
51 player.message("You have no charges to do this!");
52 return true;
53 }
54 Mob defender = player.getCombat().getDefender();
55 if (defender == null && player.getCombat().isAttacking()) {
56 defender = player.getCombat().getLastVictim();
57 }
58 if (defender == null && player.getCombat().isUnderAttack()) {
59 defender = player.getCombat().getLastAggressor();
60 }
61 if (defender == null) {
62 player.message("You are not in combat with anything...");
63 return true;
64 }
65 if (defender.isDead() || defender.getCurrentHealth() == 0) {
66 player.message("He dead tho...");
67 return true;
68 }
69 player.dragonfireUsed = System.currentTimeMillis();
70
71 final Combat<Player> combat = player.getCombat();
72 combat.performChecks(defender);
73 combat.submitStrategy(defender, DragonfireShieldStrategy.get());
74 }
75 return true;
76 }
77
78}
Handles executing an item action.
boolean equipment(Player player, Item item, int opcode)
boolean inventory(Player player, Item item, int opcode)
The execution method of the action.
Handles the mob class.
Definition Mob.java:66
Optional< Graphic > graphic
Definition Mob.java:91
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 boolean replace(int oldId, int newId, int index, boolean refresh)
Replaces the first occurrence of the Item having the identifier oldId with newId.