use common::util; use data::tables; use proto::{DungeonInfo, DungeonItemData, FightSceneInfo, SceneInfo, WeatherPoolInfo}; use thiserror::Error; use crate::logic::{ELocalPlayType, ESceneType, TimePeriodType, WeatherType}; use super::NapGameMode; #[derive(Error, Debug)] pub enum HollowGameError { #[error("quest id is invalid: {0}")] InvalidQuestId(u32), } pub struct HollowGame { pub quest_id: u32, pub battle_event_id: u32, pub time_period: TimePeriodType, pub weather: WeatherType, pub play_type: ELocalPlayType, pub start_timestamp: i64, } impl HollowGame { pub fn create_training_game( training_quest_id: u32, play_type: ELocalPlayType, ) -> Result { let template = tables::training_quest_template_tb::iter() .find(|tmpl| tmpl.id == training_quest_id) .ok_or(HollowGameError::InvalidQuestId(training_quest_id))?; Ok(Self { quest_id: template.id, battle_event_id: template.battle_event_id, time_period: TimePeriodType::Morning, weather: WeatherType::SunShine, start_timestamp: util::cur_timestamp() as i64, play_type, }) } } impl NapGameMode for HollowGame { fn scene_type(&self) -> ESceneType { ESceneType::Fight } fn scene_info(&self) -> Option { Some(SceneInfo { scene_type: self.scene_type() as u32, battle_event_id: self.battle_event_id, play_type: self.play_type as u32, fight_scene_info: Some(FightSceneInfo { weather_pool: Some(WeatherPoolInfo { time_period: self.time_period.to_string(), weather: self.weather.to_string(), ..Default::default() }), ..Default::default() }), ..Default::default() }) } fn dungeon_info(&self) -> Option { Some(DungeonInfo { quest_id: self.quest_id, start_timestamp: self.start_timestamp, dungeon_item_data: Some(DungeonItemData::default()), ..Default::default() }) } }