Tons of fixes

Added movement updates
Updated how entities are checked
Events sending between packet service all the way to the logic service
This commit is contained in:
2025-06-25 12:30:07 -04:00
parent f75782885b
commit d906cd8d64
34 changed files with 3550 additions and 186 deletions

View File

@@ -5,27 +5,52 @@ use std::sync::{Arc, Mutex};
use tonic::{Request, Response, Status};
use tonic::metadata::MetadataMap;
use tracing::debug;
use crate::entity_system::{EntitySystem, EntityType};
pub mod game_logic {
tonic::include_proto!("game_logic");
}
use game_logic::game_logic_service_server::GameLogicService;
use crate::game_logic_service::game_logic::{NearbyObjectsRequest, NearbyObjectsResponse};
use crate::game_logic_service::game_logic::{NearbyObjectsRequest, NearbyObjectsResponse, Object};
pub struct MyGameLogicService {
pub map_id: u32,
pub entity_system: Arc<EntitySystem>,
}
#[tonic::async_trait]
impl GameLogicService for MyGameLogicService {
async fn get_nearby_objects(&self, request: Request<NearbyObjectsRequest>) -> Result<Response<NearbyObjectsResponse>, Status> {
let req = request.into_inner();
debug!("{:?}", req);
debug!("GetNearbyObjects request: {:?}", req);
let response = NearbyObjectsResponse {
objects: vec![],
};
// Get nearby entities from the entity system
let entity_infos = self.entity_system.get_nearby_objects_for_client(
req.client_id as u16,
req.x,
req.y,
req.z,
req.map_id as u16,
);
// Convert EntityInfo to proto Object
let objects: Vec<Object> = entity_infos
.into_iter()
.map(|info| Object {
id: info.id,
r#type: info.entity_type as i32,
x: info.x,
y: info.y,
z: info.z,
hp: info.hp,
max_hp: info.max_hp,
})
.collect();
debug!("Returning {} nearby objects", objects.len());
let response = NearbyObjectsResponse { objects };
Ok(Response::new(response))
}
}