You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.6 KiB
93 lines
2.6 KiB
mod chat;
|
|
mod chests;
|
|
mod combat;
|
|
mod commands;
|
|
mod game_state;
|
|
mod loot_tables;
|
|
mod player;
|
|
mod special;
|
|
mod tracing;
|
|
mod utils;
|
|
mod world;
|
|
|
|
use std::net::SocketAddr;
|
|
|
|
use std::sync::atomic::{AtomicI32, Ordering};
|
|
|
|
use bevy_time::fixed_timestep::FixedTime;
|
|
use commands::{handle_command_execution, CommandExecution};
|
|
use game_state::GameState;
|
|
use valence::{
|
|
ecs as bevy_ecs,
|
|
network::{async_trait, ServerListPing},
|
|
prelude::*,
|
|
};
|
|
|
|
pub static PLAYER_COUNT: AtomicI32 = AtomicI32::new(0);
|
|
|
|
struct MyCallbacks;
|
|
|
|
#[async_trait]
|
|
impl NetworkCallbacks for MyCallbacks {
|
|
async fn server_list_ping(
|
|
&self,
|
|
_shared: &SharedNetworkState,
|
|
_remote_addr: SocketAddr,
|
|
_protocol_version: i32,
|
|
) -> ServerListPing {
|
|
ServerListPing::Respond {
|
|
online_players: PLAYER_COUNT.load(Ordering::Relaxed),
|
|
max_players: 69420,
|
|
player_sample: vec![],
|
|
description: "Crazy! Insane! Et cetera!".into(),
|
|
favicon_png: include_bytes!("../assets/icon.png"),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Resource, Debug)]
|
|
pub struct MessageQueue(pub Vec<Text>);
|
|
|
|
#[derive(Resource, Debug)]
|
|
pub struct CurrentGameState(pub GameState, pub i64);
|
|
|
|
fn main() {
|
|
tracing_subscriber::fmt()
|
|
.event_format(tracing::Formatter)
|
|
.init();
|
|
|
|
App::new()
|
|
.insert_resource(NetworkSettings {
|
|
//connection_mode: valence::network::ConnectionMode::Offline,
|
|
callbacks: MyCallbacks.into(),
|
|
..Default::default()
|
|
})
|
|
.insert_resource(MessageQueue(vec![]))
|
|
.insert_resource(CurrentGameState(GameState::EarlyGame, 0))
|
|
.add_plugins(DefaultPlugins)
|
|
.add_plugin(bevy_time::TimePlugin)
|
|
.add_startup_system(world::setup)
|
|
.add_event::<CommandExecution>()
|
|
.add_system(game_state::game_state_update.in_schedule(CoreSchedule::FixedUpdate))
|
|
.insert_resource(FixedTime::new_from_secs(120.0))
|
|
.add_system(player::update_username_cache)
|
|
.add_system(handle_command_execution)
|
|
.add_systems(
|
|
(
|
|
chests::refill_chests_system,
|
|
chat::player_message_handler,
|
|
chests::open_chests,
|
|
commands::command_executor,
|
|
player::fall_damage,
|
|
combat::handle_combat_events,
|
|
player::death,
|
|
player::respawn,
|
|
chat::flush_message_queue,
|
|
)
|
|
.in_schedule(EventLoopSchedule),
|
|
)
|
|
.add_system(player::init_clients)
|
|
.add_system(player::despawn_disconnected_clients)
|
|
.run();
|
|
}
|