diff --git a/crates/game-service/src/battle_session.rs b/crates/game-service/src/battle_session.rs index f49b44b..b11f2f1 100644 --- a/crates/game-service/src/battle_session.rs +++ b/crates/game-service/src/battle_session.rs @@ -4,7 +4,8 @@ pub const SNAPSHOT_INTERVAL_TICKS: i32 = 4; pub const MAX_CATCH_UP_TICKS: i32 = 40; use std::time::Instant; use logic::battle::{ - LogicGameMode, LogicGameObjectEntry, LogicVector2, BATTLE_TICKS_PER_SECOND, BATTLE_TYPE_PVP, + LogicGameMode, LogicGameObjectEntry, LogicGameObjectRef, LogicVector2, + BATTLE_TICKS_PER_SECOND, BATTLE_TYPE_PVP, CHARACTER_OBJECT_TYPE, }; use logic::battle::{verify_snapshot, LogicBattleEvent}; use logic::SectorStateMessage; @@ -58,21 +59,37 @@ impl BattleSession { pending_bot_play: None, } } - fn opening(&self) -> LogicGameMode { - let mut mode = self.mode.clone(); - let leaders = mode.battle.leaders; - mode.battle + fn reannounce(&mut self) { + let leaders = self.mode.battle.leaders; + let mut remap: Vec<(LogicGameObjectRef, LogicGameObjectRef)> = Vec::new(); + for entry in self.mode.battle.objects.objects.iter_mut() { + if leaders.contains(&entry.global_id) { + continue; + } + let fresh = LogicGameObjectRef::of(CHARACTER_OBJECT_TYPE + 1, self.next_instance); + self.next_instance += 1; + remap.push((entry.global_id, fresh)); + entry.global_id = fresh; + } + for towers in self.mode.battle.leader_towers.iter_mut() { + for tower in towers.iter_mut() { + if let Some((_, now)) = remap.iter().find(|(was, _)| was == tower) { + *tower = *now; + } + } + } + self.mode + .battle .objects .objects - .retain(|entry| leaders.contains(&entry.global_id)); - mode.battle.leader_towers = Default::default(); - mode + .sort_by_key(|entry| entry.global_id.0.map(|id| (id.class_id, id.instance_id))); } pub fn announce(&mut self) -> bool { if self.announced { return false; } self.announced = true; + self.reannounce(); self.next_snapshot = self.tick; true } @@ -146,11 +163,7 @@ impl BattleSession { }) } pub fn snapshot_message(&mut self) -> Option { - let snapshot = if self.announced { - self.mode.snapshot().ok()? - } else { - self.opening().snapshot().ok()? - }; + let snapshot = self.mode.snapshot().ok()?; let report = verify_snapshot(&snapshot); let unit = self .mode diff --git a/crates/game-service/src/service.rs b/crates/game-service/src/service.rs index 66ef95b..17a373c 100644 --- a/crates/game-service/src/service.rs +++ b/crates/game-service/src/service.rs @@ -161,7 +161,7 @@ impl GameService { opponent = %opponent_name, location = %location, objects, - "sending the opening sector state, objects follow once the client is up" + "sending the opening sector state, objects get new ids once the client is up" ); Ok(vec![message]) }