Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion integration-harness/tests/party_hunting.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Parties: inviting, joining, party HP bars, a mob's HP bar from a
//! member's hit, sharing a kill's EXP on Snail Hunting Ground I (40000),
//! and its drops, party chat, and disbanding.
//! and its drops, a dead member's lost share, party chat, and disbanding.

use integration_harness::hunting::{attack, pickup};
use integration_harness::login_to_world_session;
Expand Down Expand Up @@ -37,6 +37,20 @@ fn accept(party_id: i32) -> Packet {
p
}

/// TAKE_DAMAGE: mob `mob_id` touched this player for `damage`.
fn touched(damage: i32, mob_id: i32) -> Packet {
let mut p = Packet::new_empty();
p.write_short(RecvOpcode::TakeDamage as i16).unwrap();
p.write_int(0).unwrap();
p.write_byte(-1i8 as u8).unwrap();
p.write_byte(0).unwrap();
p.write_int(damage).unwrap();
p.write_int(mob_id).unwrap();
p.write_int(0).unwrap();
p.write_byte(0).unwrap();
p
}

fn party_chat(recipient: i32, text: &str) -> Packet {
let mut p = Packet::new_empty();
p.write_short(RecvOpcode::MultiChat as i16).unwrap();
Expand Down Expand Up @@ -132,6 +146,28 @@ async fn a_party_shares_hp_bars_exp_and_chat() {
[Some(member.character_id)]
);

// A member dead when the next snail falls gets nothing, as in Cosmic,
// though the split still counts them: the leader's share stays 2.
const HP: i32 = 0x400;
for _ in 0..30 {
for _ in 0..10 {
send(&mut member.connection, touched(1, SNAIL)).await;
}
read_for(&mut member.connection, &mut m, 150).await;
if m.stat(HP) == Some(0) {
break;
}
}
assert_eq!(m.stat(HP), Some(0));
let gains = m.gains.len();
let snail = l.field.alive(SNAIL)[0];
send(&mut leader.connection, attack(snail, 4)).await;
send(&mut leader.connection, attack(snail, 4)).await;
until(&mut leader.connection, &mut l, |t| t.gains.len() > 1).await;
assert_eq!(l.gains[1], 2);
read_for(&mut member.connection, &mut m, 600).await;
assert_eq!(m.gains.len(), gains, "{:?}", m.gains);

// Party chat reaches the others, not the speaker.
send(
&mut member.connection,
Expand Down
14 changes: 12 additions & 2 deletions runtime/src/actor/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1899,8 +1899,18 @@ impl ClientActor {
y,
showdown,
} => {
self.mob_killed(mob_id, exp, party_bonus).await?;
self.count_quest_kill(mob_id).await?;
// Cosmic's giveExpToCharacter: a player dead when it falls
// gets neither its EXP nor its quest count, though their
// party's split still counts them and the loot still drops.
// A last hit sent just before dying lands after the death.
if self
.game
.as_ref()
.is_some_and(|game| game.player.stats.hp > 0)
{
self.mob_killed(mob_id, exp, party_bonus).await?;
self.count_quest_kill(mob_id).await?;
}
if looter {
self.earn_nx_for_kill();
self.drop_loot(mob_id, showdown, object_id, x, y).await?
Expand Down
Loading