Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added Laser Validation and UAV threshold check #89

Open
wants to merge 10 commits into
base: aor25
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/api/attack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,14 @@ async fn socket_handler(
if session_clone1.text(response_json).await.is_err() {
return;
}
} else if response.result_type == ResultType::BulletHit {
if session_clone1.text(response_json).await.is_err() {
return;
}
} else if response.result_type == ResultType::UAV {
if session_clone1.text(response_json).await.is_err() {
return;
}
} else if response.result_type == ResultType::DefendersTriggered
{
if session_clone1.text(response_json).await.is_err() {
Expand Down Expand Up @@ -589,6 +597,8 @@ async fn socket_handler(
is_sync: false,
is_game_over: true,
message: Some("Connection timed out".to_string()),
bullet_hits: Some(Vec::new()),
revealed_mines: None,
})
.unwrap();
if session_clone2.text(response_json).await.is_err() {
Expand Down
21 changes: 17 additions & 4 deletions src/api/attack/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct SocketRequest {
pub is_game_over: Option<bool>,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct SocketResponse {
pub frame_number: i32,
pub result_type: ResultType,
Expand All @@ -33,6 +33,8 @@ pub struct SocketResponse {
// pub state: Option<GameStateResponse>,
pub is_game_over: bool,
pub message: Option<String>,
pub bullet_hits: Option<Vec<BulletHit>>,
pub revealed_mines: Option<Vec<MineDetails>>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
Expand All @@ -44,6 +46,8 @@ pub enum ActionType {
Idle,
Terminate,
SelfDestruct,
CheckBullets,
UavStatus,
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
Expand All @@ -54,18 +58,20 @@ pub enum ResultType {
BuildingsDamaged,
GameOver,
PlacedAttacker,
BulletHit,
Nothing,
UAV,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct MineResponse {
pub id: i32,
pub position: Coords,
pub damage: i32,
pub radius: i32,
}

#[derive(Serialize, Deserialize, Clone, Copy)]
#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
pub struct DefenderResponse {
pub id: i32,
pub position: Coords,
Expand All @@ -85,8 +91,15 @@ pub struct ArtifactsResponse {
pub building_id: i32,
pub amount: i32,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct BulletHit {
pub defender_id: i32,
pub target_id: i32,
pub damage: i32,
pub position: Coords,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct GameStateResponse {
pub frame_no: i32,
pub attacker_user_id: i32,
Expand Down
Loading