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

Fix : Laser attacks companion now #109

Open
wants to merge 53 commits into
base: tickNew
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b04d9e9
feat: new challenges migration, model and schema for new migration
thatchinkumar2005 Jan 29, 2025
2365730
feat(db): add is_mod column to user
thatchinkumar2005 Feb 1, 2025
c2ededc
feat: schema and model change
thatchinkumar2005 Feb 1, 2025
f1e0a64
feat: send is_mod to frontend in defense_base_fetch
thatchinkumar2005 Feb 1, 2025
e77a2d0
feat: challenge base save from mod account, new mod base json in serv…
thatchinkumar2005 Feb 1, 2025
2f36e03
feat: save admin base with map id, fetch admin base
thatchinkumar2005 Feb 1, 2025
7d06b1a
refactor: body to query parameters for get admin base
thatchinkumar2005 Feb 4, 2025
d50361c
feat: send challenge type along with initial base fetch
thatchinkumar2005 Feb 4, 2025
61e4e67
feat: new get_challenge_maps route
thatchinkumar2005 Feb 4, 2025
97cb8eb
feat: init challenge route, get challenge maps route
thatchinkumar2005 Feb 4, 2025
9f5758f
wip: socket handler for challenges
thatchinkumar2005 Feb 4, 2025
5745cc9
wip: get data for challenge validator from json, fetch_emp_type in de…
thatchinkumar2005 Feb 5, 2025
0019635
feat: socket handler for challenges
thatchinkumar2005 Feb 5, 2025
b3b47e1
feat: route for challenge socket handler
thatchinkumar2005 Feb 5, 2025
330971b
feat: send attacker_types, emp_types and max_bombs in challenge init …
thatchinkumar2005 Feb 5, 2025
f6e801e
feat: delete admin base route
thatchinkumar2005 Feb 5, 2025
d0f773c
feat(challenge): new challenge field in state
thatchinkumar2005 Jan 30, 2025
50145d7
feat: new challenge mods, maze logic
thatchinkumar2005 Jan 30, 2025
fd972b5
feat: challenge score to game logs, terminate challenges conditional
thatchinkumar2005 Jan 31, 2025
325e42c
feat: challenge terminate, new challenge response model
thatchinkumar2005 Feb 5, 2025
cf0a247
feat: completed field to challenge maps response
thatchinkumar2005 Feb 6, 2025
e1b142a
feat: remove maze.rs and handle maze logic in challenge mod.rs
thatchinkumar2005 Feb 6, 2025
2b047f7
wip: fallguys challenge, logic for range and frequency increase
thatchinkumar2005 Feb 6, 2025
645b3ba
fix: route order change
thatchinkumar2005 Feb 6, 2025
f7b8b2b
feat(maze) coin as a mine
thatchinkumar2005 Feb 7, 2025
179ebfb
feat: get challenge type in challenges socket handler
thatchinkumar2005 Feb 7, 2025
cd1bc22
feat: leaderboard routes for challenges
thatchinkumar2005 Feb 7, 2025
f301a55
feat: fallguys endtile validation
thatchinkumar2005 Feb 7, 2025
485834e
fix: attacker coin collided maze fix
thatchinkumar2005 Feb 7, 2025
09d7f45
fix: score fix for socket response, update state attacker position
thatchinkumar2005 Feb 7, 2025
1e24258
feat: attacker_type, bomb type, start tile and end tile in json for c…
thatchinkumar2005 Feb 8, 2025
9192068
refactor: instead of attacker_type and emp_type in json for challenge…
thatchinkumar2005 Feb 8, 2025
c7f7d84
feat: move start tile and endtile from maze and fallguys to challenge…
thatchinkumar2005 Feb 8, 2025
db5d34e
feat: fallguys score logic, fall guys game end logic
thatchinkumar2005 Feb 8, 2025
e5d3b7e
feat: send attacker type and bomb type from json for challenge init
thatchinkumar2005 Feb 8, 2025
aa093f9
fix: attacker speed set to 1
thatchinkumar2005 Feb 8, 2025
f6b6b67
feat: score for early completion of maze
thatchinkumar2005 Feb 8, 2025
6b77895
fix: challenge maps completed fix
thatchinkumar2005 Feb 8, 2025
986de0f
feat: socket response for invalidation messages
thatchinkumar2005 Feb 8, 2025
bb03afe
fix: remove validation
thatchinkumar2005 Feb 8, 2025
6797d69
feat: send challenge score after invalidation
thatchinkumar2005 Feb 9, 2025
4c634fd
fix: rebase fixes
thatchinkumar2005 Feb 9, 2025
af69b5e
chore: commented insignificant logs
thatchinkumar2005 Feb 9, 2025
59ca4de
fix: finally fixed idle companion. Was attacking dead defender
thatchinkumar2005 Feb 14, 2025
19f9f9a
feat: handle no companion for challenges
thatchinkumar2005 Feb 14, 2025
d19802e
fix: fix sending None for base_items_damaged in move_attacker if comp…
thatchinkumar2005 Feb 14, 2025
76f8373
feat: companion priority entirely based on shortest path distance, go…
thatchinkumar2005 Feb 14, 2025
81d35d4
fix: double artifacts
thatchinkumar2005 Feb 15, 2025
c0a5384
fix: is possible fix in get challenge maps
thatchinkumar2005 Feb 15, 2025
ea69562
fix: sentry working in challenges
thatchinkumar2005 Feb 15, 2025
748529d
fix: fixes
thatchinkumar2005 Feb 15, 2025
ee0a648
Fix: Ranged defender attacking companion
SK-47 Feb 16, 2025
9aba86b
Fix: Defender not dying bug
SaiSakthidar Feb 16, 2025
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
Binary file added .DS_Store
Binary file not shown.
34 changes: 0 additions & 34 deletions .env.example

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.78.0-slim AS base
FROM rust:1.82.0-slim AS base
WORKDIR /usr/src/aot-backend
RUN apt-get update -y && apt-get install -y \
libpq-dev \
Expand Down
2 changes: 1 addition & 1 deletion dummy_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ COPY public.levels_fixture FROM stdin;
\.

COPY public.user FROM stdin;
1 Bot [email protected] bot true 0 0 1000 0 500
1 Bot [email protected] bot true 0 0 1000 0 500 false
\.

COPY public.map_layout FROM stdin;
Expand Down
5 changes: 5 additions & 0 deletions migrations/2025-01-29-161348_challenges_migration/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- This file should undo anything in `up.sql`
DROP TABLE IF EXISTS challenges;
DROP TABLE IF EXISTS challenge_maps;
DROP TABLE IF EXISTS challenges_responses;
ALTER TABLE "user" DROP COLUMN is_mod;
34 changes: 34 additions & 0 deletions migrations/2025-01-29-161348_challenges_migration/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Your SQL goes here
CREATE TABLE challenges
(
id SERIAL PRIMARY KEY,
"name" VARCHAR(255) NOT NULL,
"start" TIMESTAMP NOT NULL,
"end" TIMESTAMP NOT NULL
);

CREATE TABLE challenge_maps
(
id SERIAL PRIMARY KEY,
challenge_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
map_id INTEGER NOT NULL,
CONSTRAINT fk_chall_map_challenge FOREIGN KEY (challenge_id) REFERENCES challenges(id),
CONSTRAINT fk_chall_map_user FOREIGN KEY (user_id) REFERENCES "user"(id),
CONSTRAINT fk_chall_map_maplayout FOREIGN KEY (map_id) REFERENCES map_layout(id)
);

CREATE TABLE challenges_responses
(
id SERIAL PRIMARY KEY,
attacker_id INTEGER NOT NULL,
challenge_id INTEGER NOT NULL,
map_id INTEGER NOT NULL,
score INTEGER NOT NULL,
CONSTRAINT chall_response_attacker FOREIGN KEY (attacker_id) REFERENCES "user"(id),
CONSTRAINT chall_response_challenge FOREIGN KEY (challenge_id) REFERENCES challenges(id),
CONSTRAINT chall_response_mapid FOREIGN KEY (map_id) REFERENCES map_layout(id),
CONSTRAINT unique_attacker_challenge UNIQUE (attacker_id, challenge_id)
);

ALTER TABLE "user" ADD COLUMN is_mod BOOLEAN NOT NULL;
17 changes: 17 additions & 0 deletions src/api/attack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ async fn socket_handler(
nd: 0,
oa: 0,
od: 0,
sc: 0,
},
};

Expand Down Expand Up @@ -424,6 +425,7 @@ async fn socket_handler(
hut_defenders,
mines,
buildings,
None,
);
game_state.set_total_hp_buildings();
game_state.get_sentries();
Expand Down Expand Up @@ -545,6 +547,15 @@ 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::Nothing
&& session_clone1.text(response_json).await.is_err()
{
Expand Down Expand Up @@ -581,6 +592,9 @@ async fn socket_handler(
}
}
Message::Close(_s) => {
if game_logs.d.is_pragyan {
//challenge game terminate
}
if util::terminate_game(
game_logs,
&mut conn,
Expand Down Expand Up @@ -643,6 +657,9 @@ async fn socket_handler(
is_game_over: true,
message: Some("Connection timed out".to_string()),
companion: None,
challenge: None,
bullet_hits: None,
revealed_mines: None,
})
.unwrap();
if session_clone2.text(response_json).await.is_err() {
Expand Down
19 changes: 19 additions & 0 deletions src/api/attack/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ pub struct SocketResponse {
pub message: Option<String>,
pub shoot_bullets: Option<Vec<BulletSpawnResponse>>,
pub companion: Option<CompanionResult>,
pub challenge: Option<ChallengeResponse>,
pub bullet_hits: Option<Vec<BulletHit>>,
pub revealed_mines: Option<Vec<MineDetails>>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ChallengeResponse {
pub score: i32,
}

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

#[derive(Debug, Serialize, Deserialize, PartialEq)]
Expand All @@ -65,6 +74,8 @@ pub enum ResultType {
PlacedAttacker,
PlacedCompanion,
Nothing,
BulletHit,
UAV,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -125,3 +136,11 @@ pub struct GameStateResponse {
pub buildings: Vec<BuildingDetails>,
pub total_hp_buildings: i32,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct BulletHit {
pub defender_id: i32,
pub target_id: i32,
pub damage: i32,
pub position: Coords,
}
49 changes: 48 additions & 1 deletion src/api/attack/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::models::{
};
use crate::schema::{block_type, building_type, defender_type, map_layout, map_spaces, prop, user};
use crate::util::function;
use crate::validator::util::Coords;
use crate::validator::util::{BombType, BuildingDetails, DefenderDetails, MineDetails};
use crate::validator::util::{Coords, HutDefenderDetails};
use ::serde::{Deserialize, Serialize};
use anyhow::Result;
use chrono;
Expand Down Expand Up @@ -91,6 +91,7 @@ pub struct ResultResponse {
pub nd: i32, //new_defender_trophies
pub oa: i32, //old_attacker_trophies
pub od: i32, //old_defender_trophies
pub sc: i32, //challenge_score
}

#[derive(Serialize, Clone)]
Expand Down Expand Up @@ -553,6 +554,7 @@ pub fn get_mines(conn: &mut PgConnection, map_id: i32) -> Result<Vec<MineDetails
x: map_space.x_coordinate,
y: map_space.y_coordinate,
},
name: mine_type.name,
})
.collect();

Expand Down Expand Up @@ -650,6 +652,9 @@ pub fn get_defenders(
level: defender.level,
current_health: defender.max_health,
max_health: defender.max_health,
range: prop.range,
frequency: prop.frequency,
last_attack: 0,
})
}
// Sorted to handle multiple defenders attack same attacker at same frame
Expand Down Expand Up @@ -732,6 +737,9 @@ pub fn get_hut_defender(
level: defender_type.level,
current_health: defender_type.max_health,
max_health: defender_type.max_health,
range: 0,
frequency: 0,
last_attack:0 ,
});
log::info!("hut_defenders {:?}", i);
}
Expand Down Expand Up @@ -767,6 +775,45 @@ pub fn get_hut_defender(
Ok(hut_defenders_res)
}

pub fn get_hut_defender_types(conn: &mut PgConnection) -> Result<Vec<DefenderDetails>> {
let joined_table = block_type::table
.inner_join(defender_type::table)
.inner_join(prop::table.on(defender_type::prop_id.eq(prop::id)))
.filter(defender_type::name.eq("Hut_Defender"));
let hut_defenders = joined_table
.load::<(BlockType, DefenderType, Prop)>(conn)
.map_err(|err| DieselError {
table: "defender_type",
function: function!(),
error: err,
})?
.into_iter();
let mut hut_defender_array: Vec<DefenderDetails> = Vec::new();
for (i, (block_type, defender_type, prop)) in hut_defenders.enumerate() {
hut_defender_array.push(DefenderDetails {
map_space_id: -1,
name: defender_type.name.clone(),
radius: prop.range,
speed: defender_type.speed,
damage: defender_type.damage,
defender_pos: Coords { x: 0, y: 0 },
is_alive: true,
damage_dealt: false,
target_id: None,
path_in_current_frame: Vec::new(),
block_id: block_type.id,
level: defender_type.level,
current_health: defender_type.max_health,
max_health: defender_type.max_health,
frequency: prop.frequency,
range: prop.range,
last_attack: 0,
});
log::info!("hut_defenders {:?}", i);
}
Ok(hut_defender_array)
}

pub fn get_bomb_types(conn: &mut PgConnection) -> Result<Vec<BombType>> {
use crate::schema::emp_type::dsl::*;
let bomb_types = emp_type
Expand Down
2 changes: 2 additions & 0 deletions src/api/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct LoginResponse {
pub artifacts: i32,
pub email: String,
pub token: Option<String>,
pub is_mod: bool,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -158,6 +159,7 @@ async fn login(
artifacts: user.artifacts,
email: user.email,
token: Some(token),
is_mod: user.is_mod,
})))
}

Expand Down
Loading