RuneHive-Game
Loading...
Searching...
No Matches
CombatProjectile.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.projectile;
2
3import com.runehive.game.Animation;
4import com.runehive.game.Graphic;
5import com.runehive.game.Projectile;
6import com.runehive.game.engine.GameEngine;
7import com.runehive.game.world.World;
8import com.runehive.game.world.entity.combat.CombatImpact;
9import com.runehive.game.world.entity.mob.Mob;
10
11import java.util.HashMap;
12import java.util.Map;
13import java.util.Optional;
14import java.util.OptionalInt;
15
16public final class CombatProjectile {
17
18 public static final Map<String, CombatProjectile> definitions = new HashMap<>();
19
20 private final String name;
21 private final int maxHit;
22 private final CombatImpact effect;
23 private final Animation animation;
24 private final Graphic start;
25 private final Graphic end;
26 private final Projectile projectile;
27
28 private final int hitDelay;
29 private final int hitsplatDelay;
30
32 this.name = name;
33 this.maxHit = maxHit;
34 this.effect = effect;
35 this.animation = animation;
36 this.start = start;
37 this.end = end;
38 this.projectile = projectile;
39 this.hitDelay = hitDelay;
40 this.hitsplatDelay = hitsplatDelay;
41 }
42
46
47/* public static int getProjectileDuration(int distance, int delay) {
48 return delay + (distance * 10);
49 }
50
51 public static int getProjectileDuration(Position from, Position to, int delay) {
52 return getProjectileDuration(from.getChebyshevDistance(to), delay);
53 }
54
55 public static int getProjectileDuration(Mob attacker, Mob defender, int delay) {
56 return getProjectileDuration(attacker.getPosition(), defender.getPosition(), delay);
57 }
58
59 public int getProjectileDelay() {
60 return projectile == null ? 0 : projectile.getDelay();
61 }*/
62
63/* public int getProjectileDuration(int distance) {
64 return getProjectileDuration(distance, getProjectileDelay());
65 }
66
67 public int getProjectileDuration(Position from, Position to) {
68 return getProjectileDuration(from, to, getProjectileDelay());
69 }
70
71 public int getProjectileDuration(Mob attacker, Mob defender) {
72 return getProjectileDuration(attacker, defender, getProjectileDelay());
73 }*/
74
75 public int getClientTicks() {
76 return projectile == null ? 0 : projectile.getClientTicks();
77 }
78
82
83 public int sendProjectile(Mob attacker, Mob defender) {
84 if (projectile == null) return 0;
85
86 /*final Projectile copy = projectile.copy();
87 final int duration = getProjectileDuration(attacker, defender);
88 copy.setDuration(duration);*/
89
90 final String name = getName();
91 if ("Ice Barrage".equals(name) || "Ice Burst".equals(name)
92 || "Smoke Barrage".equals(name) || "Smoke Burst".equals(name)) {
93 // special case: these are sent from defender pos to defender rather than normal!
94 World.sendProjectile(defender.getPosition(), defender, projectile);
95 } else {
96 projectile.send(attacker, defender);
97 }
98
99 return getClientTicks();
100 }
101
102 public static CombatProjectile getDefinition(String name) {
103 return definitions.get(name);
104 }
105
106 public String getName() {
107 return name;
108 }
109
110 public int getMaxHit() {
111 return maxHit;
112 }
113
114 public Optional<CombatImpact> getEffect() {
115 return Optional.ofNullable(effect);
116 }
117
118 public Optional<Animation> getAnimation() {
119 return Optional.ofNullable(animation);
120 }
121
122 public Optional<Graphic> getStart() {
123 return Optional.ofNullable(start);
124 }
125
126 public Optional<Graphic> getEnd() {
127 return Optional.ofNullable(end);
128 }
129
130 public OptionalInt getHitDelay() {
131 if (hitDelay == -1) {
132 return OptionalInt.empty();
133 }
134 return OptionalInt.of(hitDelay);
135 }
136
137 public OptionalInt getHitsplatDelay() {
138 if (hitsplatDelay == -1) {
139 return OptionalInt.empty();
140 }
141 return OptionalInt.of(hitsplatDelay);
142 }
143
144 public Optional<Projectile> getProjectile() {
145 return Optional.ofNullable(projectile);
146 }
147
148 public static final class ProjectileBuilder {
149 public short id;
150 public byte delay;
151 public byte speed;
152 public byte startHeight;
153 public byte endHeight;
154 }
155
156}
Class that models a single animation used by an entity.
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
static int clientTicksToServerTicks(final int clientTicks)
Represents the game world.
Definition World.java:46
static void sendProjectile(Projectile projectile, Position position, int instance, int lock, byte offsetX, byte offsetY)
Sends a world projectile.
Definition World.java:295
CombatProjectile(String name, int maxHit, CombatImpact effect, Animation animation, Graphic start, Graphic end, Projectile projectile)
CombatProjectile(String name, int maxHit, CombatImpact effect, Animation animation, Graphic start, Graphic end, Projectile projectile, int hitDelay, int hitsplatDelay)
Handles the mob class.
Definition Mob.java:66
Represents a combat impact hit effect.