aboutsummaryrefslogtreecommitdiff
path: root/server/src/commands.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-10-30 12:40:12 +0100
committermetamuffin <metamuffin@disroot.org>2025-10-30 12:40:12 +0100
commitd238e7a3250791e43d1e26e009f5d56cfd200e08 (patch)
tree5243bb2a52d32beb0a7001e4a742727050a1e5a1 /server/src/commands.rs
parent9e8896fac575186bdd2a5b22d832a53af2771bb5 (diff)
downloadhurrycurry-d238e7a3250791e43d1e26e009f5d56cfd200e08.tar
hurrycurry-d238e7a3250791e43d1e26e009f5d56cfd200e08.tar.bz2
hurrycurry-d238e7a3250791e43d1e26e009f5d56cfd200e08.tar.zst
add set-item and set-tile cheats
Diffstat (limited to 'server/src/commands.rs')
-rw-r--r--server/src/commands.rs58
1 files changed, 57 insertions, 1 deletions
diff --git a/server/src/commands.rs b/server/src/commands.rs
index bc4696ae..5eed1109 100644
--- a/server/src/commands.rs
+++ b/server/src/commands.rs
@@ -24,7 +24,9 @@ use clap::{Parser, ValueEnum};
use hurrycurry_bot::algos::ALGO_CONSTRUCTORS;
use hurrycurry_locale::{TrError, tre, trm};
use hurrycurry_protocol::{Character, Menu, Message, PacketC, PlayerClass, PlayerID};
-use std::{fmt::Write, time::Duration};
+use std::fmt::Write;
+#[cfg(feature = "cheats")]
+use std::time::Duration;
#[derive(Parser)]
#[clap(multicall = true)]
@@ -41,6 +43,7 @@ enum Command {
skip_announce: bool,
/// Duration in seconds
+ #[cfg(feature = "cheats")]
timer: Option<u64>,
},
/// Shows the best entries of the scoreboard for this map.
@@ -109,6 +112,14 @@ enum Command {
Edit,
#[clap(hide = true)]
SetEditorAddress { url: String },
+ /// Set your players hand item (CHEAT)
+ #[cfg(feature = "cheats")]
+ #[clap(alias = "give")]
+ SetItem { name: String },
+ /// Set the tile under your player (CHEAT)
+ #[cfg(feature = "cheats")]
+ #[clap(alias = "setblock")]
+ SetTile { name: String },
}
#[derive(ValueEnum, Clone)]
@@ -147,6 +158,7 @@ impl Server {
match command {
Command::Start {
spec,
+ #[cfg(feature = "cheats")]
timer,
skip_announce,
} => {
@@ -171,7 +183,10 @@ impl Server {
.index
.generate_with_book(&spec)
.map_err(|e| TrError::Plain(e.to_string()))?;
+ #[cfg(feature = "cheats")]
self.load(data, timer.map(Duration::from_secs));
+ #[cfg(not(feature = "cheats"))]
+ self.load(data, None);
if skip_announce {
self.announce_state = AnnounceState::Done
}
@@ -402,6 +417,47 @@ impl Server {
error: false,
});
}
+ #[cfg(feature = "cheats")]
+ Command::SetItem { name } => {
+ use hurrycurry_game_core::Item;
+ use hurrycurry_protocol::{Hand, ItemLocation};
+
+ let item = self
+ .game
+ .data
+ .get_item_by_name(&name)
+ .ok_or(tre!("s.error.item_not_found", s = name))?;
+ let player_data = self
+ .game
+ .players
+ .get_mut(&player)
+ .ok_or(tre!("s.error.no_player"))?;
+ player_data.items[0] = Some(Item {
+ active: None,
+ kind: item,
+ });
+ self.game.events.push_back(PacketC::SetItem {
+ location: ItemLocation::Player(player, Hand(0)),
+ item: Some(item),
+ });
+ }
+ #[cfg(feature = "cheats")]
+ Command::SetTile { name } => {
+ let tile = self
+ .game
+ .data
+ .get_tile_by_name(&name)
+ .ok_or(tre!("s.error.no_tile", s = name))?;
+ let pos = self
+ .game
+ .players
+ .get(&player)
+ .ok_or(tre!("s.error.no_player"))?
+ .movement
+ .position
+ .as_ivec2();
+ self.game.set_tile(pos, Some(tile));
+ }
}
Ok(())
}