Compare commits

...

2 Commits

Author SHA1 Message Date
6284c49bb9 Add kill command 2026-07-29 20:07:30 +03:00
05584b9d28 Attempt to fix double goals 2026-07-29 19:51:10 +03:00
5 changed files with 70 additions and 2 deletions

View File

@ -61,6 +61,10 @@ impl ChatMessage {
add_player(&mut label, &player);
label.append_text(&kind.as_kill_text());
}
DamageSource::God => {
add_player(&mut label, &player);
label.append_text(" was removed from the world by godly forces");
}
}
}
}

View File

@ -29,7 +29,7 @@ use crate::{
},
replay::{ReplayEvent, ReplayPlayback, ReplayRecorder},
team_resource::TeamResource,
ui::cli::{Command, CommandLinePanel},
ui::cli::{CliColor, Command, CommandLinePanel},
};
pub const GAME_MANAGER_GLOBAL: &str = "GameManagerGlobal";
@ -248,6 +248,45 @@ impl Command for RespawnBallCommand {
}
}
pub struct ListPlayersCommand;
impl Command for ListPlayersCommand {
fn execute(&self, cli: &mut CommandLinePanel, _: &[&str]) {
if let Some(game) = &mut Game::singleton() {
for player in &game.bind().players {
cli.publish_message(
format!(" - {} ({})", player.data.name, player.id()),
CliColor::Info,
);
}
}
}
fn help(&self) -> &str {
"lists all players"
}
}
pub struct KillCommand;
impl Command for KillCommand {
fn execute(&self, cli: &mut CommandLinePanel, args: &[&str]) {
if let Some(player_str) = args.first() {
if let Ok(player_id) = player_str.parse() {
if let Some(game) = &mut Game::singleton() {
game.bind_mut().kill_player(player_id);
}
} else {
cli.publish_message("Invalid player id".to_string(), CliColor::Error);
}
} else {
cli.publish_message("Usage: kill [player_id]".to_string(), CliColor::Error);
}
}
fn help(&self) -> &str {
"kills given player"
}
}
#[derive(GodotClass)]
#[class(base=Node, init)]
pub struct Game {
@ -483,6 +522,10 @@ impl Game {
let mut cli = CommandLinePanel::singleton();
cli.bind_mut()
.register_command("respawn_ball".to_string(), Box::new(RespawnBallCommand));
cli.bind_mut()
.register_command("players".to_string(), Box::new(ListPlayersCommand));
cli.bind_mut()
.register_command("kill".to_string(), Box::new(KillCommand));
}
}
});
@ -553,6 +596,8 @@ impl Game {
let mut cli = CommandLinePanel::singleton();
cli.bind_mut()
.unregister_command("respawn_ball".to_string());
cli.bind_mut().unregister_command("players".to_string());
cli.bind_mut().unregister_command("kill".to_string());
}
pub fn change_option(&mut self, opt: GameOption, value: GameOptionValue) {
@ -1287,6 +1332,17 @@ impl Game {
}
}
// Used to kill the player from the serverside via a command
pub fn kill_player(&mut self, target_player_id: u16) {
if let Some(player) = self.find_player_mut(target_player_id)
&& let Some(character) = &mut player.character
{
character
.dyn_bind_mut()
.take_damage(DamageSource::God, 1000, true);
}
}
pub fn recorder(&mut self) -> &mut Option<Gd<ReplayRecorder>> {
&mut self.replay_recorder
}

View File

@ -38,7 +38,10 @@ impl IArea3D for Goal {
impl Goal {
fn on_enter(&self, node: Gd<Node3D>) {
if let Ok(_) = node.try_cast::<Ball>() {
if let Ok(mut ball) = node.try_cast::<Ball>()
&& !ball.bind().entered_goal
{
ball.bind_mut().entered_goal = true;
if let Some(mut game) = Game::singleton() {
let teams = game
.bind()

View File

@ -12,6 +12,7 @@ use crate::{
#[class(base=RigidBody3D, init)]
pub struct Ball {
pub dropper: Option<u16>,
pub entered_goal: bool,
alive_for: f64,

View File

@ -316,6 +316,7 @@ impl<T: IPlayer + ICharacterBody3D + WithBaseField> PlayerCommon for T {
pub enum DamageSource {
Player(u16),
Killbox(KillboxKind),
God,
}
impl DamageSource {
@ -323,6 +324,7 @@ impl DamageSource {
match self {
DamageSource::Player(id) => (DamageSourceSignal::Player, *id, KillboxKind::default()),
DamageSource::Killbox(kind) => (DamageSourceSignal::Killbox, 0, *kind),
DamageSource::God => (DamageSourceSignal::God, 0, KillboxKind::default()),
}
}
@ -330,6 +332,7 @@ impl DamageSource {
match signal {
DamageSourceSignal::Player => DamageSource::Player(player),
DamageSourceSignal::Killbox => DamageSource::Killbox(kind),
DamageSourceSignal::God => DamageSource::God,
}
}
}
@ -339,4 +342,5 @@ impl DamageSource {
pub enum DamageSourceSignal {
Player,
Killbox,
God,
}