RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
CombatProjectile.java
1package com.osroyale.game.world.entity.combat.projectile;
2
3import com.osroyale.game.Animation;
4import com.osroyale.game.Graphic;
5import com.osroyale.game.Projectile;
6import com.osroyale.game.engine.GameEngine;
7import com.osroyale.game.world.World;
8import com.osroyale.game.world.entity.combat.CombatImpact;
9import com.osroyale.game.world.entity.mob.Mob;
10
11import java.util.HashMap;
12import java.util.Map;
13import java.util.Optional;
14import java.util.OptionalInt;
15
52
53public final class CombatProjectile {
54
55 public static final Map<String, CombatProjectile> definitions = new HashMap<>();
56
57 private final String name;
58 private final int maxHit;
59 private final CombatImpact effect;
60 private final Animation animation;
61 private final Graphic start;
62 private final Graphic end;
63 private final Projectile projectile;
64
65 private final int hitDelay;
66 private final int hitsplatDelay;
67
68 public CombatProjectile(String name, int maxHit, CombatImpact effect, Animation animation, Graphic start, Graphic end, Projectile projectile, int hitDelay, int hitsplatDelay) {
69 this.name = name;
70 this.maxHit = maxHit;
71 this.effect = effect;
72 this.animation = animation;
73 this.start = start;
74 this.end = end;
75 this.projectile = projectile;
76 this.hitDelay = hitDelay;
77 this.hitsplatDelay = hitsplatDelay;
78 }
79
80 public CombatProjectile(String name, int maxHit, CombatImpact effect, Animation animation, Graphic start, Graphic end, Projectile projectile) {
81 this(name, maxHit, effect, animation, start, end, projectile, -1, -1);
82 }
83
84/* public static int getProjectileDuration(int distance, int delay) {
85 return delay + (distance * 10);
86 }
87
88 public static int getProjectileDuration(Position from, Position to, int delay) {
89 return getProjectileDuration(from.getChebyshevDistance(to), delay);
90 }
91
92 public static int getProjectileDuration(Mob attacker, Mob defender, int delay) {
93 return getProjectileDuration(attacker.getPosition(), defender.getPosition(), delay);
94 }
95
96 public int getProjectileDelay() {
97 return projectile == null ? 0 : projectile.getDelay();
98 }*/
99
100/* public int getProjectileDuration(int distance) {
101 return getProjectileDuration(distance, getProjectileDelay());
102 }
103
104 public int getProjectileDuration(Position from, Position to) {
105 return getProjectileDuration(from, to, getProjectileDelay());
106 }
107
108 public int getProjectileDuration(Mob attacker, Mob defender) {
109 return getProjectileDuration(attacker, defender, getProjectileDelay());
110 }*/
111
112 public int getClientTicks() {
113 return projectile == null ? 0 : projectile.getClientTicks();
114 }
115
116 public int getServerTicks() {
117 return GameEngine.clientTicksToServerTicks(getClientTicks());
118 }
119
120 public int sendProjectile(Mob attacker, Mob defender) {
121 if (projectile == null) return 0;
122
123 /*final Projectile copy = projectile.copy();
124 final int duration = getProjectileDuration(attacker, defender);
125 copy.setDuration(duration);*/
126
127 final String name = getName();
128 if ("Ice Barrage".equals(name) || "Ice Burst".equals(name)
129 || "Smoke Barrage".equals(name) || "Smoke Burst".equals(name)) {
130 // special case: these are sent from defender pos to defender rather than normal!
131 World.sendProjectile(defender.getPosition(), defender, projectile);
132 } else {
133 projectile.send(attacker, defender);
134 }
135
136 return getClientTicks();
137 }
138
139 public static CombatProjectile getDefinition(String name) {
140 return definitions.get(name);
141 }
142
143 public String getName() {
144 return name;
145 }
146
147 public int getMaxHit() {
148 return maxHit;
149 }
150
151 public Optional<CombatImpact> getEffect() {
152 return Optional.ofNullable(effect);
153 }
154
155 public Optional<Animation> getAnimation() {
156 return Optional.ofNullable(animation);
157 }
158
159 public Optional<Graphic> getStart() {
160 return Optional.ofNullable(start);
161 }
162
163 public Optional<Graphic> getEnd() {
164 return Optional.ofNullable(end);
165 }
166
167 public OptionalInt getHitDelay() {
168 if (hitDelay == -1) {
169 return OptionalInt.empty();
170 }
171 return OptionalInt.of(hitDelay);
172 }
173
174 public OptionalInt getHitsplatDelay() {
175 if (hitsplatDelay == -1) {
176 return OptionalInt.empty();
177 }
178 return OptionalInt.of(hitsplatDelay);
179 }
180
181 public Optional<Projectile> getProjectile() {
182 return Optional.ofNullable(projectile);
183 }
184
185 public static final class ProjectileBuilder {
186 public short id;
187 public byte delay;
188 public byte speed;
189 public byte startHeight;
190 public byte endHeight;
191 }
192
193}
static void sendProjectile(Projectile projectile, Position position, int instance, int lock, byte offsetX, byte offsetY)
Definition World.java:332