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
2 changes: 2 additions & 0 deletions game-data/placeholder_text.toml
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@
"medal.explorer.earned_info" = "[placeholder] The {name} title is yours; Dalair keeps its medal for you."
"portal.disguise.occupied" = "[placeholder] Someone else is searching that forest."
"portal.disguise.already_found" = "[placeholder] You found him already; tell the Chief Knight."
"disguise.not_here" = "[placeholder] #h #, you're searching too? The intruder isn't here; I've searched this forest already."
"disguise.found_out" = "[placeholder] You found me out! Then we fight, as the Black Wings do!"
"portal.mysterious_force" = "[placeholder] Something keeps you out."
"portal.minar_elli.spent" = "[placeholder] A Magic Seed is used up and the portal carries you away."
"portal.minar_elli.no_seed" = "[placeholder] This portal only works with a Magic Seed."
Expand Down
1 change: 1 addition & 0 deletions game-data/reward_overrides.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,7 @@ add = [{ item = 4032518, prob = 0.4, quest = 3743 }] # The New and Improved, Ob
[mobs.9001009]
# Master of Disguise.
add = [
{ item = 4032101, prob = 0.7, quest = 20301 }, # The Master of Disguise
{ item = 4032102, prob = 0.7, quest = 20302 }, # The Master of Disguise
{ item = 4032103, prob = 0.7, quest = 20303 }, # The Master of Disguise
{ item = 4032104, prob = 0.7, quest = 20304 }, # The Master of Disguise
Expand Down
2 changes: 2 additions & 0 deletions game-data/server_content.toml
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ unsourced = [
"medal.explorer.earned_info",
"portal.disguise.occupied",
"portal.disguise.already_found",
"disguise.not_here",
"disguise.found_out",
"portal.mysterious_force",
"portal.earth.no_card",
"portal.ariant_palace.intruder",
Expand Down
6 changes: 6 additions & 0 deletions game-data/src/server_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,10 @@ pub mod keys {
/// else is searching, or he has already been found.
pub const DISGUISE_FOREST_OCCUPIED: &str = "portal.disguise.occupied";
pub const DISGUISE_ALREADY_FOUND: &str = "portal.disguise.already_found";
/// A forest's Chief Knight (1104100 to 1104104): to a Knight of another
/// line, nobody is hiding here; to the Knight's own, found out.
pub const DISGUISE_NOT_HERE: &str = "disguise.not_here";
pub const DISGUISE_FOUND_OUT: &str = "disguise.found_out";
/// Ways a quest has yet to open (`tristanEnter`, `s4resur_enter`,
/// `s4rush`).
pub const MYSTERIOUS_FORCE: &str = "portal.mysterious_force";
Expand Down Expand Up @@ -4650,6 +4654,8 @@ mod tests {
keys::MEDAL_EARNED_INFO,
keys::DISGUISE_FOREST_OCCUPIED,
keys::DISGUISE_ALREADY_FOUND,
keys::DISGUISE_NOT_HERE,
keys::DISGUISE_FOUND_OUT,
keys::MYSTERIOUS_FORCE,
keys::MAGIC_SEED_SPENT,
keys::MAGIC_SEED_NEEDED,
Expand Down
3 changes: 3 additions & 0 deletions net/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,9 @@ pub enum FieldRequest {
/// A script brings out NPC `npc_id` on the ground below `at`, unless
/// it is here already.
BringOutNpc { npc_id: i32, at: (i16, i16) },
/// A script has NPC `npc_id` here go and a `mob_id` come out where it
/// stood, unless one is out already (`scripts::Effect::Unmask`).
Unmask { npc_id: i32, mob_id: i32 },
/// A script brings out a `mob_id` on the ground below each of `at`.
BringOutMobs { mob_id: i32, at: Vec<(i16, i16)> },
/// A script puts the reactors named `name` here in `state`
Expand Down
58 changes: 58 additions & 0 deletions net/src/npc_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,9 @@ impl NpcScript {
if npc_id == OPENING_NEINHEART {
return Some(opening_neinheart());
}
if (scripts::DISGUISED_KNIGHTS..scripts::DISGUISED_KNIGHTS + 5).contains(&npc_id) {
return Some(disguised_knight(npc_id, player));
}
if let Some(&(_, mob_id, ask, notice)) = BOSS_SWITCHES.iter().find(|s| s.0 == npc_id) {
return Some(boss_switch(npc_id, mob_id, ask, notice));
}
Expand Down Expand Up @@ -6567,6 +6570,23 @@ fn violetta_found() -> NpcScript {
script
}

/// The Chief Knight a searcher finds in one of the Master of Disguise's
/// forests (1104100 to 1104104, Cosmic `1104100.js` on): to a Knight of
/// another line, they have searched there already; to their own line's
/// Knight, he is found out, and once that is read he fights.
fn disguised_knight(npc_id: i32, player: &Player) -> NpcScript {
let line = 11 + (npc_id - scripts::DISGUISED_KNIGHTS);
if i32::from(player.stats.job) / 100 != line {
return NpcScript::new(npc_id, vec![Page::Say(text(keys::DISGUISE_NOT_HERE))]);
}
let mut script = NpcScript::new(npc_id, vec![Page::Say(text(keys::DISGUISE_FOUND_OUT))]);
script.on_end = vec![Effect::Unmask {
npc_id,
mob_id: scripts::MASTER_OF_DISGUISE,
}];
script
}

/// `q2333s`, The Story of Betrayal: Violetta asks for help, names the
/// Prime Minister, and he comes out (Cosmic `2333.js` and
/// `MK_PrimeMinister`).
Expand Down Expand Up @@ -20002,6 +20022,44 @@ mod tests {
(npc, end.effects)
}

#[test]
fn a_forests_chief_knight_is_the_master_of_disguise_only_to_his_own_line() {
let knight = |job: i16| {
let mut player = player(50);
player.stats.job = job;
player
};
// Hawkeye (1104104) in the Drill Hall's entrance unmasks for a
// Thunder Breaker, through the dispatcher as the client asks.
let hawkeye = scripts::DISGUISED_KNIGHTS + 4;
let found = NpcScript::for_npc(hawkeye, &knight(1510)).unwrap();
assert_eq!(
read_through(found),
(
hawkeye,
vec![Effect::Unmask {
npc_id: hawkeye,
mob_id: scripts::MASTER_OF_DISGUISE
}]
)
);
// Mihile (1104100) does for a Dawn Warrior but not a Blaze Wizard.
let mihile = scripts::DISGUISED_KNIGHTS;
assert!(!read_through(disguised_knight(mihile, &knight(1110)))
.1
.is_empty());
assert_eq!(
read_through(disguised_knight(mihile, &knight(1210))),
(mihile, vec![])
);
assert_eq!(
read_through(disguised_knight(mihile, &knight(1111)))
.1
.len(),
1
);
}

#[test]
fn the_trash_can_holds_jms_list_from_5_to_8_pm() {
let list = Effect::GiveItem {
Expand Down
75 changes: 73 additions & 2 deletions net/src/scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,14 @@ const DISGUISE_WAYS: [(i32, &str); 5] = [
];
const DISGUISE_FORESTS: i32 = 108010600;
const DISGUISE_PROOF: i32 = 4032101;
/// The Chief Knight each forest's searcher finds there (Mihile, Oz, Irena,
/// Eckhart and Hawkeye, 1104100 on), and where. The forests' data places
/// nobody, so they come out for a searcher on the way in; the Knight's own
/// Chief is the Master of Disguise (`npc_scripts`, Cosmic `1104100.js`).
pub const DISGUISED_KNIGHTS: i32 = 1104100;
const DISGUISED_KNIGHTS_AT: [(i16, i16); 5] =
[(2250, 60), (3750, 60), (-400, 60), (-1700, 60), (650, 60)];
pub const MASTER_OF_DISGUISE: i32 = 9001009;
/// Ariant's Treasure Room of Queen (`skyrom`), which one player at a time
/// searches for the jewel quest 3935 is after.
const QUEENS_TREASURE_ROOM: i32 = 926000010;
Expand Down Expand Up @@ -1164,6 +1172,14 @@ pub enum Effect {
npc_id: i32,
at: (i16, i16),
},
/// NPC `npc_id` on the player's map goes, and `mob_id` comes out on
/// the ground where it stood unless one is out already, as the Master
/// of Disguise drops his disguise (Cosmic's `spawnMonsterOnGroundBelow`
/// at the NPC, then `destroyNPC`).
Unmask {
npc_id: i32,
mob_id: i32,
},
/// Bring out `each` of `mob_id` on the ground below each point of `at`
/// in the player's map, as the Magic Library's black shadow sets Blue
/// Mushrooms on the player. They never respawn.
Expand Down Expand Up @@ -1363,6 +1379,14 @@ const STRANGE_INFORMATION_RECORD: i16 = 21762;
/// beaten yet (Cosmic `enterInfo`). His fall sets 21733's record
/// (`crate::quests::kill_records`).
pub fn unscripted_map_enter(player: &Player) -> Vec<Effect> {
if let Some(at) = disguise_forest(player.stats.map_id) {
let npc_id = DISGUISED_KNIGHTS + (player.stats.map_id - DISGUISE_FORESTS) / 10;
return if disguise_searching(player) {
vec![Effect::BringOutNpc { npc_id, at }]
} else {
Vec::new()
};
}
match player.stats.map_id {
PUPPETEERS_HIDEOUT => hunted_puppeteer(player)
.map(|mob_id| Effect::BringOutMob {
Expand Down Expand Up @@ -3420,11 +3444,28 @@ fn elevator(map_id: i32, t: i64) -> ScriptOutcome {
}
}

/// Whether `player` is on one of the Master of Disguise quests.
fn disguise_searching(player: &Player) -> bool {
(20301..=20305).any(|id| player.quests.state(id) == QuestState::Started)
}

/// Where the Chief Knight stands in `map`, if it is one of the Master of
/// Disguise's forests.
fn disguise_forest(map: i32) -> Option<(i16, i16)> {
let n = map.checked_sub(DISGUISE_FORESTS)?;
(n % 10 == 0)
.then(|| {
DISGUISED_KNIGHTS_AT
.get(usize::try_from(n / 10).ok()?)
.copied()
})
.flatten()
}

/// Ereve's Training Forest way on for the Knight `job` (0 to 4); see
/// `DISGUISE_WAYS`.
fn disguise(player: &Player, job: usize) -> ScriptOutcome {
let searching = (20301..=20305).any(|id| player.quests.state(id) == QuestState::Started);
if !searching {
if !disguise_searching(player) {
let (map, portal) = DISGUISE_WAYS[job];
return through(Effect::WarpToPortal(map, named(map, portal)));
}
Expand Down Expand Up @@ -7550,6 +7591,36 @@ mod tests {
assert_eq!(super::portal("enterDisguise6", &fresh), None);
}

#[test]
fn each_forest_shows_a_searcher_its_chief_knight_standing_on_its_ground() {
let data = crate::get_game_data().unwrap();
let quest = [(20301, QuestState::Started)];
for (n, at) in DISGUISED_KNIGHTS_AT.into_iter().enumerate() {
let map = DISGUISE_FORESTS + 10 * n as i32;
let mut searcher = player_with(&quest);
searcher.stats.map_id = map;
assert_eq!(
unscripted_map_enter(&searcher),
[Effect::BringOutNpc {
npc_id: DISGUISED_KNIGHTS + n as i32,
at
}]
);
// Nobody waits for one who isn't searching.
let mut passer = player_with(&[]);
passer.stats.map_id = map;
assert!(unscripted_map_enter(&passer).is_empty());
// The forest's floor is under the spot.
let field = data.field(map).unwrap();
assert_eq!(field.footholds.ground_below(at.0, at.1), Some(88), "{map}");
}
// The forest after them is no forest of his.
let mut beyond = player_with(&quest);
beyond.stats.map_id = DISGUISE_FORESTS + 50;
assert!(disguise_forest(beyond.stats.map_id).is_none());
assert!(disguise_forest(DISGUISE_FORESTS + 5).is_none());
}

#[test]
fn a_magic_seed_carries_the_player_between_ellinia_and_leafre() {
assert!(pink(&portal("minar_elli", &player_with(&[])).unwrap()));
Expand Down
4 changes: 4 additions & 0 deletions runtime/src/actor/client/npc_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ impl ClientActor {
npc_id: *npc_id,
at: *at,
}),
Effect::Unmask { npc_id, mob_id } => to_field.push(FieldRequest::Unmask {
npc_id: *npc_id,
mob_id: *mob_id,
}),
Effect::BringOutMobs { mob_id, at, each } => {
to_field.push(FieldRequest::BringOutMobs {
mob_id: *mob_id,
Expand Down
19 changes: 19 additions & 0 deletions runtime/src/actor/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,7 @@ impl FieldActor {
self.appear(npc_id, at);
}
}
FieldRequest::Unmask { npc_id, mob_id } => self.unmask(from, npc_id, mob_id),
FieldRequest::OpenReactor { name } => self.open_reactor(name),
FieldRequest::NpcSpecialAction { npc_id, action } => {
self.npc_special_action(npc_id, action)
Expand Down Expand Up @@ -3717,6 +3718,24 @@ impl FieldActor {
}
}

/// NPC `npc_id` goes from here, and a `mob_id` comes out where it stood
/// unless one is out already (`scripts::Effect::Unmask`).
fn unmask(&mut self, from: ClientId, npc_id: i32, mob_id: i32) {
let Some(index) = self.map_npcs.iter().position(|npc| npc.npc_id == npc_id) else {
return;
};
let npc = self.map_npcs.remove(index);
for packet in [
build_uncontrol_npc(npc.object_id),
build_remove_npc(npc.object_id),
] {
if let Ok(packet) = packet {
self.broadcast(None, packet);
}
}
self.handle_bring_out_mob(from, mob_id, (npc.x, npc.y));
}

/// Bring out NPC `npc_id` on the ground below (x, y), there until the
/// field closes, and hand it to the NPCs' controller.
fn appear(&mut self, npc_id: i32, (x, y): (i16, i16)) {
Expand Down
Loading