Skip to content

Commit 1defefb

Browse files
hex-agonPazaz
andauthored
feat: add support for damage2 (#2)
* feat: add support for damage2 * increase player/npc renderer cache sizes * add damage2 to player/npc compute functions * chore: Updated package version --------- Co-authored-by: Pazaz <[email protected]>
1 parent 1cbb2ce commit 1defefb

File tree

7 files changed

+65
-9
lines changed

7 files changed

+65
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@2004scape/rsbuf",
3-
"version": "225.1.7",
3+
"version": "244.1.0",
44
"description": "A RuneScape update info computer",
55
"main": "dist/rsbuf.js",
66
"types": "dist/rsbuf.d.ts",

src/info.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ impl PlayerInfo {
399399
)
400400
}
401401
}
402+
if masks & PlayerInfoProt::DAMAGE2 as u32 != 0 {
403+
renderer.write(&mut self.updates, other.pid, PlayerInfoProt::DAMAGE2);
404+
}
402405
}
403406

404407
#[inline]
@@ -677,6 +680,9 @@ impl NpcInfo {
677680
// ----
678681
// an optimization *could* be made where all of these are just 1 block of bytes...
679682
// the same could NOT be done for players bcuz of how exact_move works...
683+
if masks & NpcInfoProt::DAMAGE2 as u32 != 0 {
684+
renderer.write(&mut self.updates, nid, NpcInfoProt::DAMAGE2);
685+
}
680686
if masks & NpcInfoProt::ANIM as u32 != 0 {
681687
renderer.write(&mut self.updates, nid, NpcInfoProt::ANIM);
682688
}

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ pub unsafe fn compute_player(
6060
orientationZ: i32,
6161
damageTaken: i32,
6262
damageType: i32,
63+
damageTaken2: i32,
64+
damageType2: i32,
6365
currentHitpoints: i32,
6466
baseHitpoints: i32,
6567
animId: i32,
@@ -136,6 +138,8 @@ pub unsafe fn compute_player(
136138
player.orientation_z = orientationZ;
137139
player.damage_taken = damageTaken;
138140
player.damage_type = damageType;
141+
player.damage_taken2 = damageTaken2;
142+
player.damage_type2 = damageType2;
139143
player.current_hitpoints = currentHitpoints;
140144
player.base_hitpoints = baseHitpoints;
141145
player.anim_id = animId;
@@ -232,6 +236,8 @@ pub unsafe fn compute_npc(
232236
orientationZ: i32,
233237
damageTaken: i32,
234238
damageType: i32,
239+
damageTaken2: i32,
240+
damageType2: i32,
235241
currentHitpoints: i32,
236242
baseHitpoints: i32,
237243
animId: i32,
@@ -267,6 +273,8 @@ pub unsafe fn compute_npc(
267273
npc.orientation_z = orientationZ;
268274
npc.damage_taken = damageTaken;
269275
npc.damage_type = damageType;
276+
npc.damage_taken2 = damageTaken2;
277+
npc.damage_type2 = damageType2;
270278
npc.current_hitpoints = currentHitpoints;
271279
npc.base_hitpoints = baseHitpoints;
272280
npc.anim_id = animId;

src/npc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub struct Npc {
1717
pub orientation_z: i32,
1818
pub damage_taken: i32,
1919
pub damage_type: i32,
20+
pub damage_taken2: i32,
21+
pub damage_type2: i32,
2022
pub current_hitpoints: i32,
2123
pub base_hitpoints: i32,
2224
pub anim_id: i32,
@@ -47,6 +49,8 @@ impl Npc {
4749
orientation_z: -1,
4850
damage_taken: -1,
4951
damage_type: -1,
52+
damage_taken2: -1,
53+
damage_type2: -1,
5054
current_hitpoints: -1,
5155
base_hitpoints: -1,
5256
anim_id: -1,
@@ -72,6 +76,8 @@ impl Npc {
7276
// self.orientation_z = -1;
7377
self.damage_taken = -1;
7478
self.damage_type = -1;
79+
self.damage_taken2 = -1;
80+
self.damage_type2 = -1;
7581
self.current_hitpoints = -1;
7682
self.base_hitpoints = -1;
7783
self.anim_id = -1;

src/player.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub struct Player {
2424
pub orientation_z: i32,
2525
pub damage_taken: i32,
2626
pub damage_type: i32,
27+
pub damage_taken2: i32,
28+
pub damage_type2: i32,
2729
pub current_hitpoints: i32,
2830
pub base_hitpoints: i32,
2931
pub anim_id: i32,
@@ -79,6 +81,8 @@ impl Player {
7981
orientation_z: -1,
8082
damage_taken: -1,
8183
damage_type: -1,
84+
damage_taken2: -1,
85+
damage_type2: -1,
8286
current_hitpoints: -1,
8387
base_hitpoints: -1,
8488
anim_id: -1,
@@ -108,6 +112,8 @@ impl Player {
108112
// self.orientation_z = -1;
109113
self.damage_taken = -1;
110114
self.damage_type = -1;
115+
self.damage_taken2 = -1;
116+
self.damage_type2 = -1;
111117
self.current_hitpoints = -1;
112118
self.base_hitpoints = -1;
113119
self.anim_id = -1;

src/prot.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub enum PlayerInfoProt {
1616
BIG = 0x80,
1717
SPOT_ANIM = 0x100,
1818
EXACT_MOVE = 0x200,
19+
DAMAGE2 = 0x400,
1920
}
2021

2122
impl PlayerInfoProt {
@@ -28,9 +29,10 @@ impl PlayerInfoProt {
2829
PlayerInfoProt::FACE_ENTITY => 2,
2930
PlayerInfoProt::SAY => 3,
3031
PlayerInfoProt::DAMAGE => 4,
31-
PlayerInfoProt::FACE_COORD => 5,
32-
PlayerInfoProt::CHAT => 6,
33-
PlayerInfoProt::SPOT_ANIM => 7,
32+
PlayerInfoProt::DAMAGE2 => 5,
33+
PlayerInfoProt::FACE_COORD => 6,
34+
PlayerInfoProt::CHAT => 7,
35+
PlayerInfoProt::SPOT_ANIM => 8,
3436
PlayerInfoProt::BIG => 255, // unused
3537
PlayerInfoProt::EXACT_MOVE => 255, // unused
3638
}
@@ -41,6 +43,7 @@ impl PlayerInfoProt {
4143
#[derive(Eq, Hash, PartialEq)]
4244
#[wasm_bindgen]
4345
pub enum NpcInfoProt {
46+
DAMAGE2 = 0x1,
4447
ANIM = 0x2,
4548
FACE_ENTITY = 0x4,
4649
SAY = 0x8,
@@ -59,9 +62,10 @@ impl NpcInfoProt {
5962
NpcInfoProt::FACE_ENTITY => 1,
6063
NpcInfoProt::SAY => 2,
6164
NpcInfoProt::DAMAGE => 3,
62-
NpcInfoProt::CHANGE_TYPE => 4,
63-
NpcInfoProt::SPOT_ANIM => 5,
64-
NpcInfoProt::FACE_COORD => 6,
65+
NpcInfoProt::DAMAGE2 => 4,
66+
NpcInfoProt::CHANGE_TYPE => 5,
67+
NpcInfoProt::SPOT_ANIM => 6,
68+
NpcInfoProt::FACE_COORD => 7,
6569
}
6670
}
6771
}

src/renderer.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl PlayerRenderer {
1515
pub fn new() -> PlayerRenderer {
1616
// exact move does not get cached, that is built on demand.
1717
return PlayerRenderer {
18-
caches: vec![vec![None; 2048]; 8],
18+
caches: vec![vec![None; 2048]; 9],
1919
highs: [0; 2048],
2020
lows: [0; 2048],
2121
}
@@ -81,6 +81,18 @@ impl PlayerRenderer {
8181
PlayerInfoProt::DAMAGE,
8282
);
8383
}
84+
if masks & PlayerInfoProt::DAMAGE2 as u32 != 0 {
85+
highs += self.cache(
86+
pid,
87+
&PlayerInfoDamage::new(
88+
player.damage_taken2,
89+
player.damage_type2,
90+
player.current_hitpoints,
91+
player.base_hitpoints,
92+
),
93+
PlayerInfoProt::DAMAGE2,
94+
);
95+
}
8496
if masks & PlayerInfoProt::FACE_COORD as u32 != 0 {
8597
let len: usize = self.cache(
8698
pid,
@@ -196,6 +208,7 @@ impl PlayerRenderer {
196208
PlayerInfoProt::FACE_ENTITY.to_index(),
197209
PlayerInfoProt::SAY.to_index(),
198210
PlayerInfoProt::DAMAGE.to_index(),
211+
PlayerInfoProt::DAMAGE2.to_index(),
199212
PlayerInfoProt::FACE_COORD.to_index(),
200213
PlayerInfoProt::CHAT.to_index(),
201214
PlayerInfoProt::SPOT_ANIM.to_index(),
@@ -244,7 +257,7 @@ impl NpcRenderer {
244257
#[inline]
245258
pub fn new() -> NpcRenderer {
246259
return NpcRenderer {
247-
caches: vec![vec![None; 8192]; 7],
260+
caches: vec![vec![None; 8192]; 8],
248261
highs: [0; 8192],
249262
lows: [0; 8192],
250263
}
@@ -301,6 +314,18 @@ impl NpcRenderer {
301314
NpcInfoProt::DAMAGE,
302315
);
303316
}
317+
if masks & NpcInfoProt::DAMAGE2 as u32 != 0 {
318+
highs += self.cache(
319+
nid,
320+
&NpcInfoDamage::new(
321+
npc.damage_taken2,
322+
npc.damage_type2,
323+
npc.current_hitpoints,
324+
npc.base_hitpoints,
325+
),
326+
NpcInfoProt::DAMAGE2,
327+
);
328+
}
304329
if masks & NpcInfoProt::CHANGE_TYPE as u32 != 0 {
305330
highs += self.cache(
306331
nid,
@@ -385,6 +410,7 @@ impl NpcRenderer {
385410
NpcInfoProt::FACE_ENTITY.to_index(),
386411
NpcInfoProt::SAY.to_index(),
387412
NpcInfoProt::DAMAGE.to_index(),
413+
NpcInfoProt::DAMAGE2.to_index(),
388414
NpcInfoProt::CHANGE_TYPE.to_index(),
389415
NpcInfoProt::SPOT_ANIM.to_index(),
390416
NpcInfoProt::FACE_COORD.to_index(),

0 commit comments

Comments
 (0)