aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/Cargo.toml1
-rw-r--r--server/src/commands.rs58
-rw-r--r--server/src/entity/tag_minigame.rs30
3 files changed, 61 insertions, 28 deletions
diff --git a/server/Cargo.toml b/server/Cargo.toml
index 6da63fcb..1a0cc523 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -42,3 +42,4 @@ register = ["dep:reqwest"]
upnp = ["dep:igd", "dep:get_if_addrs"]
debug_events = ["hurrycurry-bot/debug_events"]
fast_recipes = ["hurrycurry-data/fast_recipes"]
+cheats = []
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(())
}
diff --git a/server/src/entity/tag_minigame.rs b/server/src/entity/tag_minigame.rs
index a2b4da92..e45422b7 100644
--- a/server/src/entity/tag_minigame.rs
+++ b/server/src/entity/tag_minigame.rs
@@ -17,7 +17,7 @@
*/
use super::{Entity, EntityContext};
use anyhow::Result;
-use hurrycurry_game_core::{Item, Tile};
+use hurrycurry_game_core::Item;
use hurrycurry_locale::TrError;
use hurrycurry_protocol::{
Hand, ItemIndex, ItemLocation, Message, PacketC, PlayerID, TileIndex, glam::IVec2,
@@ -100,19 +100,7 @@ impl Entity for TagMinigame {
.filter(|(_, v)| **v <= 0.)
.for_each(|(&pos, _)| {
self.wall_remove_timeouts.insert(pos, 3.);
- c.game.walkable.remove(&pos);
- c.game.tiles.insert(
- pos,
- Tile {
- kind: self.blocker_tile,
- item: None,
- },
- );
- c.packet_out.push_back(PacketC::UpdateMap {
- tile: pos,
- kind: Some(self.blocker_tile),
- neighbors: [None; 4],
- });
+ c.game.set_tile(pos, Some(self.blocker_tile));
});
self.wall_place_delays.retain(|_, v| *v > 0.);
@@ -124,19 +112,7 @@ impl Entity for TagMinigame {
.filter(|(_, v)| **v <= 0.)
.for_each(|(&pos, _)| {
if let Some(&(tile, _)) = c.serverdata.initial_map.get(&pos) {
- c.game.walkable.insert(pos);
- c.game.tiles.insert(
- pos,
- Tile {
- kind: tile,
- item: None,
- },
- );
- c.packet_out.push_back(PacketC::UpdateMap {
- tile: pos,
- kind: Some(tile),
- neighbors: [None; 4],
- });
+ c.game.set_tile(pos, Some(tile));
}
});
self.wall_remove_timeouts.retain(|_, v| *v > 0.);