Remove AtomicRefCell
This commit is contained in:
parent
7434dabceb
commit
650dab7606
16 changed files with 394 additions and 324 deletions
|
@ -8,7 +8,6 @@ version = "0.1.0"
|
|||
[workspace.dependencies]
|
||||
ansi_term = "0.12.1"
|
||||
anyhow = "1.0.81"
|
||||
atomic_refcell = "0.1.13"
|
||||
axum = "0.7.4"
|
||||
axum-server = "0.6.0"
|
||||
byteorder = "1.5.0"
|
||||
|
|
|
@ -6,7 +6,6 @@ version.workspace = true
|
|||
[dependencies]
|
||||
ansi_term.workspace = true
|
||||
anyhow.workspace = true
|
||||
atomic_refcell.workspace = true
|
||||
dirs.workspace = true
|
||||
env_logger.workspace = true
|
||||
hex.workspace = true
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use atomic_refcell::AtomicRefCell;
|
||||
use protocol::{PlayerInfo, PtcPlayerInfoChangedArg};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::net::NetworkSession;
|
||||
|
||||
|
@ -13,40 +13,29 @@ use super::manager::{
|
|||
|
||||
pub struct GameContext {
|
||||
#[allow(unused)]
|
||||
pub uid_manager: Arc<AtomicRefCell<UniqueIDManager>>,
|
||||
pub item_manager: Arc<AtomicRefCell<ItemManager>>,
|
||||
pub dungeon_manager: Arc<AtomicRefCell<DungeonManager>>,
|
||||
pub quest_manager: Arc<AtomicRefCell<QuestManager>>,
|
||||
pub scene_unit_manager: Arc<AtomicRefCell<SceneUnitManager>>,
|
||||
pub hollow_grid_manager: Arc<AtomicRefCell<HollowGridManager>>,
|
||||
pub unlock_manager: Arc<AtomicRefCell<UnlockManager>>,
|
||||
pub yorozuya_quest_manager: Arc<AtomicRefCell<YorozuyaQuestManager>>,
|
||||
pub uid_manager: Arc<UniqueIDManager>,
|
||||
pub item_manager: Arc<ItemManager>,
|
||||
pub dungeon_manager: Arc<DungeonManager>,
|
||||
pub quest_manager: Arc<QuestManager>,
|
||||
pub scene_unit_manager: Arc<SceneUnitManager>,
|
||||
pub hollow_grid_manager: Arc<HollowGridManager>,
|
||||
pub unlock_manager: Arc<UnlockManager>,
|
||||
pub yorozuya_quest_manager: Arc<YorozuyaQuestManager>,
|
||||
}
|
||||
|
||||
impl GameContext {
|
||||
pub fn new(player: Arc<AtomicRefCell<PlayerInfo>>) -> Self {
|
||||
let uid_manager = Arc::new(AtomicRefCell::new(UniqueIDManager::new()));
|
||||
pub fn new(player: Arc<RwLock<PlayerInfo>>) -> Self {
|
||||
let uid_manager = Arc::new(UniqueIDManager::new());
|
||||
|
||||
Self {
|
||||
uid_manager: uid_manager.clone(),
|
||||
item_manager: Arc::new(AtomicRefCell::new(ItemManager::new(
|
||||
uid_manager.clone(),
|
||||
player.clone(),
|
||||
))),
|
||||
dungeon_manager: Arc::new(AtomicRefCell::new(DungeonManager::new(
|
||||
uid_manager.clone(),
|
||||
player.clone(),
|
||||
))),
|
||||
quest_manager: Arc::new(AtomicRefCell::new(QuestManager::new(
|
||||
uid_manager.clone(),
|
||||
player.clone(),
|
||||
))),
|
||||
scene_unit_manager: Arc::new(AtomicRefCell::new(SceneUnitManager::new(uid_manager))),
|
||||
hollow_grid_manager: Arc::new(AtomicRefCell::new(HollowGridManager::new(
|
||||
player.clone(),
|
||||
))),
|
||||
unlock_manager: Arc::new(AtomicRefCell::new(UnlockManager::new(player.clone()))),
|
||||
yorozuya_quest_manager: Arc::new(AtomicRefCell::new(YorozuyaQuestManager::new(player))),
|
||||
item_manager: Arc::new(ItemManager::new(uid_manager.clone(), player.clone())),
|
||||
dungeon_manager: Arc::new(DungeonManager::new(uid_manager.clone(), player.clone())),
|
||||
quest_manager: Arc::new(QuestManager::new(uid_manager.clone(), player.clone())),
|
||||
scene_unit_manager: Arc::new(SceneUnitManager::new(uid_manager)),
|
||||
hollow_grid_manager: Arc::new(HollowGridManager::new(player.clone())),
|
||||
unlock_manager: Arc::new(UnlockManager::new(player.clone())),
|
||||
yorozuya_quest_manager: Arc::new(YorozuyaQuestManager::new(player)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +59,7 @@ where
|
|||
pub async fn send_changes(&mut self, session: &NetworkSession) -> Result<&T> {
|
||||
if self.player_info_changes.is_some() {
|
||||
let ptc_player_info_changed = PtcPlayerInfoChangedArg {
|
||||
player_uid: session.get_player_uid(),
|
||||
player_uid: session.get_player_uid().await,
|
||||
player_info: self.player_info_changes.take().unwrap(),
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use anyhow::{anyhow, bail, Result};
|
||||
use atomic_refcell::AtomicRefCell;
|
||||
use protocol::*;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::game::{manager::UniqueIDManager, util, PlayerOperationResult};
|
||||
use qwer::{
|
||||
|
@ -9,26 +9,23 @@ use qwer::{
|
|||
};
|
||||
|
||||
pub struct DungeonManager {
|
||||
uid_mgr: Arc<AtomicRefCell<UniqueIDManager>>,
|
||||
player: Arc<AtomicRefCell<PlayerInfo>>,
|
||||
scene_properties: AtomicRefCell<PropertyDoubleKeyHashMap<u64, u16, i32>>,
|
||||
uid_mgr: Arc<UniqueIDManager>,
|
||||
player: Arc<RwLock<PlayerInfo>>,
|
||||
scene_properties: RwLock<PropertyDoubleKeyHashMap<u64, u16, i32>>,
|
||||
}
|
||||
|
||||
impl DungeonManager {
|
||||
pub fn new(
|
||||
uid_mgr: Arc<AtomicRefCell<UniqueIDManager>>,
|
||||
player: Arc<AtomicRefCell<PlayerInfo>>,
|
||||
) -> Self {
|
||||
pub fn new(uid_mgr: Arc<UniqueIDManager>, player: Arc<RwLock<PlayerInfo>>) -> Self {
|
||||
Self {
|
||||
uid_mgr,
|
||||
player,
|
||||
scene_properties: AtomicRefCell::new(pdkhashmap![]),
|
||||
scene_properties: RwLock::new(pdkhashmap![]),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enter_main_city(&self) -> Result<PlayerOperationResult<PtcEnterSceneArg>> {
|
||||
pub async fn enter_main_city(&self) -> Result<PlayerOperationResult<PtcEnterSceneArg>> {
|
||||
let (player_uid, scene_position, scene_rotation) = {
|
||||
let player = self.player.borrow();
|
||||
let player = self.player.read().await;
|
||||
let pos_in_main_city = player.pos_in_main_city.as_ref().unwrap();
|
||||
|
||||
(
|
||||
|
@ -38,7 +35,7 @@ impl DungeonManager {
|
|||
)
|
||||
};
|
||||
|
||||
let mut player = self.player.borrow_mut();
|
||||
let mut player = self.player.write().await;
|
||||
let default_scene_uid = player
|
||||
.dungeon_collection
|
||||
.as_ref()
|
||||
|
@ -116,12 +113,12 @@ impl DungeonManager {
|
|||
))
|
||||
}
|
||||
|
||||
pub fn enter_scene_section(
|
||||
pub async fn enter_scene_section(
|
||||
&self,
|
||||
scene_uid: u64,
|
||||
section_id: i32,
|
||||
) -> PlayerOperationResult<PtcEnterSectionArg> {
|
||||
let mut player = self.player.borrow_mut();
|
||||
let mut player = self.player.write().await;
|
||||
let scene_info = player
|
||||
.dungeon_collection
|
||||
.as_mut()
|
||||
|
@ -148,9 +145,12 @@ impl DungeonManager {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn enter_scene(&self, scene_uid: u64) -> Result<PlayerOperationResult<PtcEnterSceneArg>> {
|
||||
pub async fn enter_scene(
|
||||
&self,
|
||||
scene_uid: u64,
|
||||
) -> Result<PlayerOperationResult<PtcEnterSceneArg>> {
|
||||
let (player_uid, prev_scene_uid) = {
|
||||
let player = self.player.borrow();
|
||||
let player = self.player.read().await;
|
||||
|
||||
(
|
||||
*player.uid.as_ref().unwrap(),
|
||||
|
@ -158,7 +158,7 @@ impl DungeonManager {
|
|||
)
|
||||
};
|
||||
|
||||
let mut player = self.player.borrow_mut();
|
||||
let mut player = self.player.write().await;
|
||||
player.scene_uid.replace(scene_uid);
|
||||
player.prev_scene_uid.replace(prev_scene_uid);
|
||||
let dungeon_collection = player.dungeon_collection.as_mut().unwrap();
|
||||
|
@ -248,10 +248,10 @@ impl DungeonManager {
|
|||
))
|
||||
}
|
||||
|
||||
pub fn hollow_finished(&self) -> PlayerOperationResult<u64> {
|
||||
let cur_scene_uid = self.get_cur_scene_uid();
|
||||
pub async fn hollow_finished(&self) -> PlayerOperationResult<u64> {
|
||||
let cur_scene_uid = self.get_cur_scene_uid().await;
|
||||
|
||||
let mut player = self.player.borrow_mut();
|
||||
let mut player = self.player.write().await;
|
||||
|
||||
let hollow_scene = player
|
||||
.dungeon_collection
|
||||
|
@ -313,9 +313,10 @@ impl DungeonManager {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn get_default_scene_uid(&self) -> u64 {
|
||||
pub async fn get_default_scene_uid(&self) -> u64 {
|
||||
self.player
|
||||
.borrow()
|
||||
.read()
|
||||
.await
|
||||
.dungeon_collection
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
|
@ -324,9 +325,10 @@ impl DungeonManager {
|
|||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_default_scene_uid_for_dungeon(&self, dungeon_uid: u64) -> u64 {
|
||||
pub async fn get_default_scene_uid_for_dungeon(&self, dungeon_uid: u64) -> u64 {
|
||||
self.player
|
||||
.borrow()
|
||||
.read()
|
||||
.await
|
||||
.dungeon_collection
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
|
@ -338,12 +340,12 @@ impl DungeonManager {
|
|||
.default_scene_uid
|
||||
}
|
||||
|
||||
pub fn get_cur_scene_uid(&self) -> u64 {
|
||||
self.player.borrow().scene_uid.unwrap()
|
||||
pub async fn get_cur_scene_uid(&self) -> u64 {
|
||||
self.player.read().await.scene_uid.unwrap()
|
||||
}
|
||||
|
||||
fn add_default_hollow_properties(&self, scene_uid: u64) {
|
||||
let mut props = self.scene_properties.borrow_mut();
|
||||
async fn add_default_hollow_properties(&self, scene_uid: u64) {
|
||||
let mut props = self.scene_properties.write().await;
|
||||
|
||||
for (sub_key, value) in &[
|
||||
(1001, 0),
|
||||
|
@ -378,11 +380,11 @@ impl DungeonManager {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn leave_battle(&self) -> Result<PlayerOperationResult<PtcEnterSceneArg>> {
|
||||
let back_scene_uid = self.get_back_scene_uid();
|
||||
pub async fn leave_battle(&self) -> Result<PlayerOperationResult<PtcEnterSceneArg>> {
|
||||
let back_scene_uid = self.get_back_scene_uid().await;
|
||||
|
||||
{
|
||||
let mut player = self.player.borrow_mut();
|
||||
let mut player = self.player.write().await;
|
||||
|
||||
let hollow_scene = player
|
||||
.dungeon_collection
|
||||
|
@ -402,11 +404,11 @@ impl DungeonManager {
|
|||
}
|
||||
}
|
||||
|
||||
self.enter_scene(back_scene_uid)
|
||||
self.enter_scene(back_scene_uid).await
|
||||
}
|
||||
|
||||
fn get_back_scene_uid(&self) -> u64 {
|
||||
let player = self.player.borrow();
|
||||
async fn get_back_scene_uid(&self) -> u64 {
|
||||
let player = self.player.read().await;
|
||||
let fight_scene_uid = player.scene_uid.as_ref().unwrap();
|
||||
let fight_scene = player
|
||||
.dungeon_collection
|
||||
|
@ -421,12 +423,14 @@ impl DungeonManager {
|
|||
fight_scene.get_back_scene_uid()
|
||||
}
|
||||
|
||||
pub fn enter_battle(&self, scene_uid: u64) -> PlayerOperationResult<PtcEnterSceneArg> {
|
||||
let hollow_scene_uid = *self.player.borrow().scene_uid.as_ref().unwrap();
|
||||
let hollow_scene = self.set_cur_hollow_battle(scene_uid, hollow_scene_uid);
|
||||
let ptc_enter_scene = self.enter_scene(scene_uid).unwrap().unwrap().clone();
|
||||
pub async fn enter_battle(&self, scene_uid: u64) -> PlayerOperationResult<PtcEnterSceneArg> {
|
||||
let hollow_scene_uid = *self.player.read().await.scene_uid.as_ref().unwrap();
|
||||
let hollow_scene = self
|
||||
.set_cur_hollow_battle(scene_uid, hollow_scene_uid)
|
||||
.await;
|
||||
let ptc_enter_scene = self.enter_scene(scene_uid).await.unwrap().unwrap().clone();
|
||||
|
||||
let player = self.player.borrow();
|
||||
let player = self.player.read().await;
|
||||
let dungeon_collection = player.dungeon_collection.as_ref().unwrap();
|
||||
let fight_scene = dungeon_collection
|
||||
.scenes
|
||||
|
@ -455,8 +459,8 @@ impl DungeonManager {
|
|||
)
|
||||
}
|
||||
|
||||
fn set_cur_hollow_battle(&self, scene_uid: u64, hollow_scene_uid: u64) -> SceneInfo {
|
||||
let mut player = self.player.borrow_mut();
|
||||
async fn set_cur_hollow_battle(&self, scene_uid: u64, hollow_scene_uid: u64) -> SceneInfo {
|
||||
let mut player = self.player.write().await;
|
||||
let hollow_scene = player
|
||||
.dungeon_collection
|
||||
.as_mut()
|
||||
|
@ -481,13 +485,13 @@ impl DungeonManager {
|
|||
hollow_scene.clone()
|
||||
}
|
||||
|
||||
pub fn create_fight(&self, id: i32, hollow_scene_uid: u64) -> PlayerOperationResult<u64> {
|
||||
let mut player = self.player.borrow_mut();
|
||||
pub async fn create_fight(&self, id: i32, hollow_scene_uid: u64) -> PlayerOperationResult<u64> {
|
||||
let mut player = self.player.write().await;
|
||||
let dungeon_collection = player.dungeon_collection.as_mut().unwrap();
|
||||
let scenes = dungeon_collection.scenes.as_mut().unwrap();
|
||||
let hollow_scene = scenes.get_mut(&hollow_scene_uid).unwrap();
|
||||
|
||||
let fight_scene_uid = self.uid_mgr.borrow().next();
|
||||
let fight_scene_uid = self.uid_mgr.next();
|
||||
let fight_scene = SceneInfo::Fight {
|
||||
uid: fight_scene_uid,
|
||||
id,
|
||||
|
@ -522,10 +526,10 @@ impl DungeonManager {
|
|||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn is_in_tutorial(&self) -> bool {
|
||||
let cur_scene_uid = self.get_cur_scene_uid();
|
||||
pub async fn is_in_tutorial(&self) -> bool {
|
||||
let cur_scene_uid = self.get_cur_scene_uid().await;
|
||||
|
||||
let player = self.player.borrow();
|
||||
let player = self.player.read().await;
|
||||
let cur_scene = player
|
||||
.dungeon_collection
|
||||
.as_ref()
|
||||
|
@ -539,29 +543,31 @@ impl DungeonManager {
|
|||
matches!(cur_scene, SceneInfo::Fresh { .. })
|
||||
}
|
||||
|
||||
pub fn create_hollow(
|
||||
pub async fn create_hollow(
|
||||
&self,
|
||||
id: i32,
|
||||
world_quest_id: i32,
|
||||
avatar_uids: &[u64],
|
||||
) -> PlayerOperationResult<(u64, u64)> {
|
||||
let back_scene_uid = self.get_default_scene_uid();
|
||||
let back_scene_uid = self.get_default_scene_uid().await;
|
||||
|
||||
let mut dungeon = self.create_base_dungeon(id, back_scene_uid, world_quest_id);
|
||||
let mut dungeon = self
|
||||
.create_base_dungeon(id, back_scene_uid, world_quest_id)
|
||||
.await;
|
||||
dungeon.hollow_event_version = 526;
|
||||
|
||||
let scene_uid = self.uid_mgr.borrow().next();
|
||||
let scene_uid = self.uid_mgr.next();
|
||||
dungeon.default_scene_uid = scene_uid;
|
||||
dungeon.scene_properties_uid = scene_uid;
|
||||
|
||||
self.add_default_hollow_properties(scene_uid);
|
||||
self.add_default_hollow_properties(scene_uid).await;
|
||||
|
||||
for (index, avatar_uid) in avatar_uids.iter().enumerate() {
|
||||
dungeon.avatar_map.insert(
|
||||
index.try_into().unwrap(),
|
||||
AvatarUnitInfo {
|
||||
uid: *avatar_uid,
|
||||
properties_uid: self.uid_mgr.borrow().next(),
|
||||
properties_uid: self.uid_mgr.next(),
|
||||
is_banned: false,
|
||||
modified_property: pdkhashmap![],
|
||||
hp_add_hollow: 0,
|
||||
|
@ -636,10 +642,10 @@ impl DungeonManager {
|
|||
};
|
||||
|
||||
{
|
||||
let mut player = self.player.borrow_mut();
|
||||
let mut player = self.player.write().await;
|
||||
player
|
||||
.scene_properties
|
||||
.replace(self.scene_properties.borrow().clone());
|
||||
.replace(self.scene_properties.read().await.clone());
|
||||
|
||||
let dungeon_collection = player.dungeon_collection.as_mut().unwrap();
|
||||
|
||||
|
@ -654,7 +660,7 @@ impl DungeonManager {
|
|||
.unwrap()
|
||||
.insert(scene_uid, scene.clone());
|
||||
}
|
||||
let mut player = self.player.borrow_mut();
|
||||
let mut player = self.player.write().await;
|
||||
let items = player.items.as_mut().unwrap();
|
||||
|
||||
let mut updated_items = Vec::new();
|
||||
|
@ -668,7 +674,7 @@ impl DungeonManager {
|
|||
}
|
||||
|
||||
let mut prop_changes = Vec::new();
|
||||
for (key, sub_key, value) in &*self.scene_properties.borrow_mut() {
|
||||
for (key, sub_key, value) in &*self.scene_properties.write().await {
|
||||
prop_changes.push((*key, *sub_key, *value));
|
||||
}
|
||||
|
||||
|
@ -699,11 +705,11 @@ impl DungeonManager {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn create_hall(&self, id: i32) -> PlayerOperationResult<u64> {
|
||||
let mut dungeon = self.create_base_dungeon(id, 0, 0);
|
||||
pub async fn create_hall(&self, id: i32) -> PlayerOperationResult<u64> {
|
||||
let mut dungeon = self.create_base_dungeon(id, 0, 0).await;
|
||||
let dungeon_uid = dungeon.uid;
|
||||
|
||||
let scene_uid = self.uid_mgr.borrow().next();
|
||||
let scene_uid = self.uid_mgr.next();
|
||||
let hall_scene_info = SceneInfo::Hall {
|
||||
uid: scene_uid,
|
||||
id,
|
||||
|
@ -720,7 +726,7 @@ impl DungeonManager {
|
|||
|
||||
dungeon.default_scene_uid = scene_uid;
|
||||
|
||||
let mut player = self.player.borrow_mut();
|
||||
let mut player = self.player.write().await;
|
||||
let dungeon_collection = player.dungeon_collection.as_mut().unwrap();
|
||||
|
||||
dungeon_collection
|
||||
|
@ -756,11 +762,11 @@ impl DungeonManager {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn create_fresh(&self) -> PlayerOperationResult<u64> {
|
||||
let mut dungeon = self.create_base_dungeon(2, 0, 0);
|
||||
pub async fn create_fresh(&self) -> PlayerOperationResult<u64> {
|
||||
let mut dungeon = self.create_base_dungeon(2, 0, 0).await;
|
||||
let dungeon_uid = dungeon.uid;
|
||||
|
||||
let scene_uid = self.uid_mgr.borrow().next();
|
||||
let scene_uid = self.uid_mgr.next();
|
||||
let fresh_scene_info = SceneInfo::Fresh {
|
||||
uid: scene_uid,
|
||||
id: 2,
|
||||
|
@ -777,7 +783,7 @@ impl DungeonManager {
|
|||
|
||||
dungeon.default_scene_uid = scene_uid;
|
||||
|
||||
let mut player = self.player.borrow_mut();
|
||||
let mut player = self.player.write().await;
|
||||
let dungeon_collection = player.dungeon_collection.as_mut().unwrap();
|
||||
|
||||
dungeon_collection
|
||||
|
@ -811,14 +817,14 @@ impl DungeonManager {
|
|||
)
|
||||
}
|
||||
|
||||
fn create_base_dungeon(
|
||||
async fn create_base_dungeon(
|
||||
&self,
|
||||
id: i32,
|
||||
back_scene_uid: u64,
|
||||
world_quest_id: i32,
|
||||
) -> DungeonInfo {
|
||||
let player = self.player.borrow();
|
||||
let uid = self.uid_mgr.borrow().next();
|
||||
let player = self.player.read().await;
|
||||
let uid = self.uid_mgr.next();
|
||||
|
||||
DungeonInfo {
|
||||
uid,
|
||||
|
|
|
@ -4,43 +4,44 @@ use std::{
|
|||
};
|
||||
|
||||
use crate::game::data;
|
||||
use atomic_refcell::AtomicRefCell;
|
||||
use protocol::*;
|
||||
use qwer::{phashmap, phashset, PropertyHashMap, PropertyHashSet};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub struct HollowGridManager {
|
||||
player: Arc<AtomicRefCell<PlayerInfo>>,
|
||||
map: AtomicRefCell<Option<HollowGridMapProtocolInfo>>,
|
||||
events: AtomicRefCell<HashMap<u64, EventInfo>>,
|
||||
player: Arc<RwLock<PlayerInfo>>,
|
||||
map: RwLock<Option<HollowGridMapProtocolInfo>>,
|
||||
events: RwLock<HashMap<u64, EventInfo>>,
|
||||
}
|
||||
|
||||
impl HollowGridManager {
|
||||
pub fn new(player: Arc<AtomicRefCell<PlayerInfo>>) -> Self {
|
||||
pub fn new(player: Arc<RwLock<PlayerInfo>>) -> Self {
|
||||
Self {
|
||||
player,
|
||||
map: AtomicRefCell::new(None),
|
||||
events: AtomicRefCell::new(HashMap::new()),
|
||||
map: RwLock::new(None),
|
||||
events: RwLock::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_cur_position_in_hollow(&self) -> u16 {
|
||||
self.map.borrow().as_ref().unwrap().start_grid
|
||||
pub async fn get_cur_position_in_hollow(&self) -> u16 {
|
||||
self.map.read().await.as_ref().unwrap().start_grid
|
||||
}
|
||||
|
||||
pub fn move_to(
|
||||
pub async fn move_to(
|
||||
&self,
|
||||
destination_grid: u16,
|
||||
scene_uid: u64,
|
||||
) -> (PtcHollowGridArg, Option<PtcSyncHollowEventInfoArg>) {
|
||||
let mut map = self.map.borrow_mut();
|
||||
let mut map = self.map.write().await;
|
||||
let map = map.as_mut().unwrap();
|
||||
|
||||
map.start_grid = destination_grid;
|
||||
let grid = map.grids.get_mut(&destination_grid).unwrap();
|
||||
|
||||
self.update_position_to_scene(scene_uid, destination_grid);
|
||||
self.update_position_to_scene(scene_uid, destination_grid)
|
||||
.await;
|
||||
|
||||
let mut events = self.events.borrow_mut();
|
||||
let mut events = self.events.write().await;
|
||||
let sync_event_info =
|
||||
if let Entry::Vacant(entry) = events.entry(u64::from(destination_grid)) {
|
||||
let event_info = EventInfo {
|
||||
|
@ -81,7 +82,7 @@ impl HollowGridManager {
|
|||
|
||||
(
|
||||
PtcHollowGridArg {
|
||||
player_uid: self.player.borrow().uid.unwrap(),
|
||||
player_uid: self.player.read().await.uid.unwrap(),
|
||||
is_partial: true,
|
||||
scene_uid,
|
||||
hollow_level: 1,
|
||||
|
@ -91,8 +92,8 @@ impl HollowGridManager {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn battle_finished(&self) -> (PtcSyncHollowEventInfoArg, bool) {
|
||||
let map = self.map.borrow();
|
||||
pub async fn battle_finished(&self) -> (PtcSyncHollowEventInfoArg, bool) {
|
||||
let map = self.map.read().await;
|
||||
let map = map.as_ref().unwrap();
|
||||
let cur_grid = map.grids.get(&map.start_grid).unwrap();
|
||||
|
||||
|
@ -129,16 +130,16 @@ impl HollowGridManager {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn get_cur_event_template_id(&self) -> i32 {
|
||||
let map = self.map.borrow();
|
||||
pub async fn get_cur_event_template_id(&self) -> i32 {
|
||||
let map = self.map.read().await;
|
||||
let map = map.as_ref().unwrap();
|
||||
let cur_grid = map.grids.get(&map.start_grid).unwrap();
|
||||
|
||||
cur_grid.grid.event_graph_info.hollow_event_template_id
|
||||
}
|
||||
|
||||
fn update_position_to_scene(&self, scene_uid: u64, pos: u16) {
|
||||
let mut player = self.player.borrow_mut();
|
||||
async fn update_position_to_scene(&self, scene_uid: u64, pos: u16) {
|
||||
let mut player = self.player.write().await;
|
||||
let scene = player
|
||||
.dungeon_collection
|
||||
.as_mut()
|
||||
|
@ -165,7 +166,7 @@ impl HollowGridManager {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn run_event_graph(
|
||||
pub async fn run_event_graph(
|
||||
&self,
|
||||
event_graph_uid: u64,
|
||||
_event_id: i32,
|
||||
|
@ -177,12 +178,12 @@ impl HollowGridManager {
|
|||
bool,
|
||||
) {
|
||||
let (player_uid, scene_uid) = {
|
||||
let player = self.player.borrow();
|
||||
let player = self.player.read().await;
|
||||
|
||||
(player.uid.unwrap(), player.scene_uid.unwrap())
|
||||
};
|
||||
|
||||
let mut map = self.map.borrow_mut();
|
||||
let mut map = self.map.write().await;
|
||||
let map = map.as_mut().unwrap();
|
||||
|
||||
let mut trigger_battle_id = None;
|
||||
|
@ -216,6 +217,7 @@ impl HollowGridManager {
|
|||
if let Some(action) = actions.get(index as usize) {
|
||||
last_exec_type = action["$type"].as_str().unwrap();
|
||||
|
||||
// ugly, we have to parse these configs properly
|
||||
match action["$type"].as_str().unwrap() {
|
||||
"Share.CConfigSetMapState" => {
|
||||
let x = action["X"].as_i64().unwrap() as u16;
|
||||
|
@ -320,19 +322,23 @@ impl HollowGridManager {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn sync_hollow_maps(&self, player_uid: u64, scene_uid: u64) -> PtcSyncHollowGridMapsArg {
|
||||
pub async fn sync_hollow_maps(
|
||||
&self,
|
||||
player_uid: u64,
|
||||
scene_uid: u64,
|
||||
) -> PtcSyncHollowGridMapsArg {
|
||||
PtcSyncHollowGridMapsArg {
|
||||
player_uid,
|
||||
scene_uid,
|
||||
hollow_level: 1,
|
||||
main_map: self.map.borrow().clone().unwrap(),
|
||||
main_map: self.map.read().await.clone().unwrap(),
|
||||
time_period: TimePeriodType::Random,
|
||||
weather: WeatherType::Random,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_default_map(&self) {
|
||||
*self.map.borrow_mut() = Some(HollowGridMapProtocolInfo {
|
||||
pub async fn init_default_map(&self) {
|
||||
*self.map.write().await = Some(HollowGridMapProtocolInfo {
|
||||
row: 5,
|
||||
col: 11,
|
||||
start_grid: 22,
|
||||
|
|
|
@ -1,30 +1,27 @@
|
|||
use atomic_refcell::AtomicRefCell;
|
||||
use protocol::{ItemInfo, PlayerInfo};
|
||||
use qwer::{phashmap, PropertyHashMap};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::game::{util, PlayerOperationResult};
|
||||
|
||||
use super::UniqueIDManager;
|
||||
|
||||
pub struct ItemManager {
|
||||
uid_mgr: Arc<AtomicRefCell<UniqueIDManager>>,
|
||||
player_info: Arc<AtomicRefCell<PlayerInfo>>,
|
||||
uid_mgr: Arc<UniqueIDManager>,
|
||||
player_info: Arc<RwLock<PlayerInfo>>,
|
||||
}
|
||||
|
||||
impl ItemManager {
|
||||
pub fn new(
|
||||
uid_mgr: Arc<AtomicRefCell<UniqueIDManager>>,
|
||||
player_info: Arc<AtomicRefCell<PlayerInfo>>,
|
||||
) -> Self {
|
||||
pub fn new(uid_mgr: Arc<UniqueIDManager>, player_info: Arc<RwLock<PlayerInfo>>) -> Self {
|
||||
Self {
|
||||
uid_mgr,
|
||||
player_info,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_resource(&self, currency_id: i32, amount: i32) -> PlayerOperationResult<i32> {
|
||||
let mut player_info = self.player_info.borrow_mut();
|
||||
pub async fn add_resource(&self, currency_id: i32, amount: i32) -> PlayerOperationResult<i32> {
|
||||
let mut player_info = self.player_info.write().await;
|
||||
|
||||
for (uid, item) in player_info.items.as_mut().unwrap() {
|
||||
if let ItemInfo::Resource { id, count, .. } = item {
|
||||
|
@ -45,7 +42,7 @@ impl ItemManager {
|
|||
}
|
||||
}
|
||||
|
||||
let uid = self.uid_mgr.borrow().next();
|
||||
let uid = self.uid_mgr.next();
|
||||
let item = ItemInfo::Resource {
|
||||
uid,
|
||||
id: currency_id,
|
||||
|
@ -69,8 +66,8 @@ impl ItemManager {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn unlock_avatar(&self, id: i32) -> PlayerOperationResult<u64> {
|
||||
let uid = self.uid_mgr.borrow().next();
|
||||
pub async fn unlock_avatar(&self, id: i32) -> PlayerOperationResult<u64> {
|
||||
let uid = self.uid_mgr.next();
|
||||
|
||||
let avatar = ItemInfo::Avatar {
|
||||
uid,
|
||||
|
@ -89,10 +86,10 @@ impl ItemManager {
|
|||
};
|
||||
|
||||
// Unlock & equip default weapon
|
||||
let weapon_uid = *self.unlock_weapon(10012).unwrap();
|
||||
self.equip_weapon(weapon_uid, uid);
|
||||
let weapon_uid = *self.unlock_weapon(10012).await.unwrap();
|
||||
self.equip_weapon(weapon_uid, uid).await;
|
||||
|
||||
let mut player_info = self.player_info.borrow_mut();
|
||||
let mut player_info = self.player_info.write().await;
|
||||
let items = player_info.items.as_mut().unwrap();
|
||||
items.insert(uid, avatar.clone());
|
||||
|
||||
|
@ -111,11 +108,11 @@ impl ItemManager {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn unlock_weapon(&self, id: i32) -> PlayerOperationResult<u64> {
|
||||
let mut player_info = self.player_info.borrow_mut();
|
||||
pub async fn unlock_weapon(&self, id: i32) -> PlayerOperationResult<u64> {
|
||||
let mut player_info = self.player_info.write().await;
|
||||
let items = player_info.items.as_mut().unwrap();
|
||||
|
||||
let uid = self.uid_mgr.borrow().next();
|
||||
let uid = self.uid_mgr.next();
|
||||
|
||||
let weapon = ItemInfo::Weapon {
|
||||
uid,
|
||||
|
@ -144,12 +141,12 @@ impl ItemManager {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn equip_weapon(
|
||||
pub async fn equip_weapon(
|
||||
&self,
|
||||
weapon_uid: u64,
|
||||
equip_avatar_uid: u64,
|
||||
) -> PlayerOperationResult<bool> {
|
||||
let mut player_info = self.player_info.borrow_mut();
|
||||
let mut player_info = self.player_info.write().await;
|
||||
let items = player_info.items.as_mut().unwrap();
|
||||
|
||||
let Some(ItemInfo::Weapon { avatar_uid, .. }) = items.get_mut(&weapon_uid) else {
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
use atomic_refcell::AtomicRefCell;
|
||||
use protocol::{AccountInfo, PlayerInfo, PropertyBlob};
|
||||
use qwer::OctData;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
const CLIENT_PROP_FLAG: u16 = 1;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct PropertyManager {
|
||||
pub account_info: Arc<AtomicRefCell<AccountInfo>>,
|
||||
pub player_info: Arc<AtomicRefCell<PlayerInfo>>,
|
||||
pub account_info: Arc<RwLock<AccountInfo>>,
|
||||
pub player_info: Arc<RwLock<PlayerInfo>>,
|
||||
}
|
||||
|
||||
impl PropertyManager {
|
||||
pub fn serialize_account_info(&self) -> PropertyBlob {
|
||||
Self::serialize_property(&*self.account_info.borrow()).unwrap()
|
||||
pub async fn serialize_account_info(&self) -> PropertyBlob {
|
||||
Self::serialize_property(&*self.account_info.read().await).unwrap()
|
||||
}
|
||||
|
||||
pub fn serialize_player_info(&self) -> PropertyBlob {
|
||||
Self::serialize_property(&*self.player_info.borrow()).unwrap()
|
||||
pub async fn serialize_player_info(&self) -> PropertyBlob {
|
||||
Self::serialize_property(&*self.player_info.read().await).unwrap()
|
||||
}
|
||||
|
||||
pub fn serialize_property(prop: &impl OctData) -> Result<PropertyBlob, std::io::Error> {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use atomic_refcell::AtomicRefCell;
|
||||
use qwer::PropertyDoubleKeyHashMap;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::game::PlayerOperationResult;
|
||||
|
||||
|
@ -9,22 +9,20 @@ use super::UniqueIDManager;
|
|||
use protocol::*;
|
||||
|
||||
pub struct QuestManager {
|
||||
uid_mgr: Arc<AtomicRefCell<UniqueIDManager>>,
|
||||
player: Arc<AtomicRefCell<PlayerInfo>>,
|
||||
uid_mgr: Arc<UniqueIDManager>,
|
||||
player: Arc<RwLock<PlayerInfo>>,
|
||||
}
|
||||
|
||||
impl QuestManager {
|
||||
pub fn new(
|
||||
uid_mgr: Arc<AtomicRefCell<UniqueIDManager>>,
|
||||
player: Arc<AtomicRefCell<PlayerInfo>>,
|
||||
) -> Self {
|
||||
pub fn new(uid_mgr: Arc<UniqueIDManager>, player: Arc<RwLock<PlayerInfo>>) -> Self {
|
||||
Self { uid_mgr, player }
|
||||
}
|
||||
|
||||
pub fn add_world_quest(&self, quest: QuestInfo) -> PlayerOperationResult<u64> {
|
||||
pub async fn add_world_quest(&self, quest: QuestInfo) -> PlayerOperationResult<u64> {
|
||||
let mut world_quest_collection_uid = self
|
||||
.player
|
||||
.borrow()
|
||||
.read()
|
||||
.await
|
||||
.quest_data
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
|
@ -32,9 +30,10 @@ impl QuestManager {
|
|||
.unwrap();
|
||||
|
||||
if world_quest_collection_uid == 0 {
|
||||
world_quest_collection_uid = self.uid_mgr.borrow().next();
|
||||
world_quest_collection_uid = self.uid_mgr.next();
|
||||
self.player
|
||||
.borrow_mut()
|
||||
.write()
|
||||
.await
|
||||
.quest_data
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
|
@ -43,14 +42,15 @@ impl QuestManager {
|
|||
}
|
||||
|
||||
self.add_quest_to_collection(world_quest_collection_uid, quest)
|
||||
.await
|
||||
}
|
||||
|
||||
pub fn add_quest_to_collection(
|
||||
pub async fn add_quest_to_collection(
|
||||
&self,
|
||||
collection_uid: u64,
|
||||
mut quest: QuestInfo,
|
||||
) -> PlayerOperationResult<u64> {
|
||||
let mut player = self.player.borrow_mut();
|
||||
let mut player = self.player.write().await;
|
||||
let quest_data = player.quest_data.as_mut().unwrap();
|
||||
quest.set_collection_uid(collection_uid);
|
||||
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use atomic_refcell::AtomicRefCell;
|
||||
use protocol::*;
|
||||
use qwer::{phashmap, PropertyHashMap};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::UniqueIDManager;
|
||||
|
||||
pub struct SceneUnitManager {
|
||||
uid_mgr: Arc<AtomicRefCell<UniqueIDManager>>,
|
||||
units: AtomicRefCell<HashMap<u64, SceneUnitProtocolInfo>>,
|
||||
uid_mgr: Arc<UniqueIDManager>,
|
||||
units: RwLock<HashMap<u64, SceneUnitProtocolInfo>>,
|
||||
}
|
||||
|
||||
impl SceneUnitManager {
|
||||
pub fn new(uid_mgr: Arc<AtomicRefCell<UniqueIDManager>>) -> Self {
|
||||
pub fn new(uid_mgr: Arc<UniqueIDManager>) -> Self {
|
||||
Self {
|
||||
uid_mgr,
|
||||
units: AtomicRefCell::new(HashMap::new()),
|
||||
units: RwLock::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_npc(
|
||||
pub async fn create_npc(
|
||||
&self,
|
||||
id: i32,
|
||||
tag: i32,
|
||||
quest_id: i32,
|
||||
interacts_info: PropertyHashMap<i32, InteractInfo>,
|
||||
) -> u64 {
|
||||
let uid = self.uid_mgr.borrow().next();
|
||||
let uid = self.uid_mgr.next();
|
||||
|
||||
self.units.borrow_mut().insert(
|
||||
self.units.write().await.insert(
|
||||
uid,
|
||||
SceneUnitProtocolInfo::NpcProtocolInfo {
|
||||
uid,
|
||||
|
@ -42,11 +42,11 @@ impl SceneUnitManager {
|
|||
uid
|
||||
}
|
||||
|
||||
pub fn get(&self, uid: u64) -> SceneUnitProtocolInfo {
|
||||
self.units.borrow().get(&uid).unwrap().clone()
|
||||
pub async fn get(&self, uid: u64) -> SceneUnitProtocolInfo {
|
||||
self.units.read().await.get(&uid).unwrap().clone()
|
||||
}
|
||||
|
||||
pub fn sync(&self, scene_uid: u64, section_id: i32) -> PtcSyncSceneUnitArg {
|
||||
pub async fn sync(&self, scene_uid: u64, section_id: i32) -> PtcSyncSceneUnitArg {
|
||||
PtcSyncSceneUnitArg {
|
||||
scene_uid,
|
||||
section_id,
|
||||
|
@ -54,7 +54,8 @@ impl SceneUnitManager {
|
|||
removed_scene_units: Vec::new(),
|
||||
scene_units: self
|
||||
.units
|
||||
.borrow()
|
||||
.read()
|
||||
.await
|
||||
.iter()
|
||||
.map(|(_, unit)| unit.clone())
|
||||
.collect(),
|
||||
|
@ -64,7 +65,7 @@ impl SceneUnitManager {
|
|||
// TODO: partial_sync for newly added/removed units
|
||||
|
||||
// currently hardcoded for Main City section 2
|
||||
pub fn add_default_units(&self) {
|
||||
pub async fn add_default_units(&self) {
|
||||
self.create_npc(
|
||||
100171011,
|
||||
3,
|
||||
|
@ -83,7 +84,8 @@ impl SceneUnitManager {
|
|||
phashmap![(0, String::new())]
|
||||
)
|
||||
)],
|
||||
);
|
||||
)
|
||||
.await;
|
||||
|
||||
self.create_npc(
|
||||
100171011,
|
||||
|
@ -103,7 +105,8 @@ impl SceneUnitManager {
|
|||
phashmap![(0, String::new())]
|
||||
)
|
||||
)],
|
||||
);
|
||||
)
|
||||
.await;
|
||||
|
||||
self.create_npc(
|
||||
100171011,
|
||||
|
@ -123,7 +126,8 @@ impl SceneUnitManager {
|
|||
phashmap![(0, String::new())]
|
||||
)
|
||||
)],
|
||||
);
|
||||
)
|
||||
.await;
|
||||
|
||||
self.create_npc(
|
||||
100171011,
|
||||
|
@ -143,7 +147,8 @@ impl SceneUnitManager {
|
|||
phashmap![(1001, String::from("A"))]
|
||||
)
|
||||
)],
|
||||
);
|
||||
)
|
||||
.await;
|
||||
|
||||
self.create_npc(
|
||||
100171011,
|
||||
|
@ -163,7 +168,8 @@ impl SceneUnitManager {
|
|||
phashmap![(1005, String::from("A"))]
|
||||
)
|
||||
)],
|
||||
);
|
||||
)
|
||||
.await;
|
||||
|
||||
self.create_npc(
|
||||
100173001,
|
||||
|
@ -183,7 +189,8 @@ impl SceneUnitManager {
|
|||
phashmap![(2028, String::from("A"))]
|
||||
)
|
||||
)],
|
||||
);
|
||||
)
|
||||
.await;
|
||||
|
||||
self.create_npc(
|
||||
100172011,
|
||||
|
@ -203,9 +210,10 @@ impl SceneUnitManager {
|
|||
phashmap![(2000, String::from("A")), (2052, String::from("B"))]
|
||||
)
|
||||
)],
|
||||
);
|
||||
)
|
||||
.await;
|
||||
|
||||
self.create_npc(100172081, 2052, 0, phashmap![]);
|
||||
self.create_npc(100172081, 2052, 0, phashmap![]).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use atomic_refcell::AtomicRefCell;
|
||||
use protocol::*;
|
||||
use qwer::PropertyHashSet;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::game::PlayerOperationResult;
|
||||
|
||||
pub struct UnlockManager {
|
||||
player: Arc<AtomicRefCell<PlayerInfo>>,
|
||||
player: Arc<RwLock<PlayerInfo>>,
|
||||
}
|
||||
|
||||
impl UnlockManager {
|
||||
pub fn new(player: Arc<AtomicRefCell<PlayerInfo>>) -> Self {
|
||||
pub fn new(player: Arc<RwLock<PlayerInfo>>) -> Self {
|
||||
Self { player }
|
||||
}
|
||||
|
||||
pub fn unlock(&self, unlock_id: i32) -> PlayerOperationResult<PtcUnlockArg> {
|
||||
let mut player = self.player.borrow_mut();
|
||||
pub async fn unlock(&self, unlock_id: i32) -> PlayerOperationResult<PtcUnlockArg> {
|
||||
let mut player = self.player.write().await;
|
||||
let unlock_info = player.unlock_info.as_mut().unwrap();
|
||||
|
||||
unlock_info
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use atomic_refcell::AtomicRefCell;
|
||||
use qwer::{PropertyDoubleKeyHashMap, PropertyHashSet};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::game::PlayerOperationResult;
|
||||
|
||||
use protocol::*;
|
||||
|
||||
pub struct YorozuyaQuestManager {
|
||||
player: Arc<AtomicRefCell<PlayerInfo>>,
|
||||
player: Arc<RwLock<PlayerInfo>>,
|
||||
}
|
||||
|
||||
impl YorozuyaQuestManager {
|
||||
pub fn new(player: Arc<AtomicRefCell<PlayerInfo>>) -> Self {
|
||||
pub fn new(player: Arc<RwLock<PlayerInfo>>) -> Self {
|
||||
Self { player }
|
||||
}
|
||||
|
||||
pub fn add_hollow_quest(
|
||||
pub async fn add_hollow_quest(
|
||||
&self,
|
||||
yorozuya_collection_id: i32,
|
||||
hollow_quest_type: HollowQuestType,
|
||||
id: i32,
|
||||
) -> PlayerOperationResult<i32> {
|
||||
let mut player = self.player.borrow_mut();
|
||||
let mut player = self.player.write().await;
|
||||
let yorozuya = player.yorozuya_info.as_mut().unwrap();
|
||||
let hollow_quests = yorozuya.hollow_quests.as_mut().unwrap();
|
||||
|
||||
|
|
|
@ -13,11 +13,19 @@ pub async fn on_rpc_hollow_move(
|
|||
tracing::info!("Hollow movement {:?}", &arg);
|
||||
|
||||
let destination_pos = *arg.positions.last().unwrap();
|
||||
let scene_uid = session.get_player().scene_uid.unwrap();
|
||||
let scene_uid = session
|
||||
.ns_prop_mgr
|
||||
.player_info
|
||||
.read()
|
||||
.await
|
||||
.scene_uid
|
||||
.unwrap();
|
||||
|
||||
let hollow_grid_manager = session.context.hollow_grid_manager.borrow();
|
||||
let (ptc_hollow_grid, ptc_sync_hollow_event) =
|
||||
hollow_grid_manager.move_to(destination_pos, scene_uid);
|
||||
let (ptc_hollow_grid, ptc_sync_hollow_event) = session
|
||||
.context
|
||||
.hollow_grid_manager
|
||||
.move_to(destination_pos, scene_uid)
|
||||
.await;
|
||||
|
||||
session
|
||||
.send_rpc_arg(PTC_HOLLOW_GRID_ID, &ptc_hollow_grid)
|
||||
|
@ -50,19 +58,19 @@ pub async fn on_rpc_end_battle(
|
|||
) -> Result<RpcEndBattleRet> {
|
||||
tracing::info!("RpcEndBattle: {:?}", &arg);
|
||||
|
||||
let player_uid = session.get_player_uid();
|
||||
let hollow_grid_manager = session.context.hollow_grid_manager.borrow();
|
||||
|
||||
let (sync_event, hollow_finished) = hollow_grid_manager.battle_finished();
|
||||
let player_uid = session.get_player_uid().await;
|
||||
let (sync_event, hollow_finished) = session.context.hollow_grid_manager.battle_finished().await;
|
||||
|
||||
if !hollow_finished {
|
||||
session
|
||||
.send_rpc_arg(PTC_SYNC_HOLLOW_EVENT_INFO_ID, &sync_event)
|
||||
.await?;
|
||||
} else {
|
||||
let dungeon_manager = session.context.dungeon_manager.borrow();
|
||||
let _ = *dungeon_manager
|
||||
let _ = *session
|
||||
.context
|
||||
.dungeon_manager
|
||||
.hollow_finished()
|
||||
.await
|
||||
.send_changes(session)
|
||||
.await?;
|
||||
|
||||
|
@ -79,9 +87,11 @@ pub async fn on_rpc_end_battle(
|
|||
.await?;
|
||||
}
|
||||
|
||||
let dungeon_manager = session.context.dungeon_manager.borrow();
|
||||
let ptc_enter_scene = dungeon_manager
|
||||
let ptc_enter_scene = session
|
||||
.context
|
||||
.dungeon_manager
|
||||
.leave_battle()
|
||||
.await
|
||||
.unwrap()
|
||||
.send_changes(session)
|
||||
.await?
|
||||
|
@ -90,14 +100,25 @@ pub async fn on_rpc_end_battle(
|
|||
session
|
||||
.send_rpc_arg(
|
||||
PTC_SYNC_HOLLOW_GRID_MAPS_ID,
|
||||
&hollow_grid_manager.sync_hollow_maps(player_uid, dungeon_manager.get_cur_scene_uid()),
|
||||
&session
|
||||
.context
|
||||
.hollow_grid_manager
|
||||
.sync_hollow_maps(
|
||||
player_uid,
|
||||
session.context.dungeon_manager.get_cur_scene_uid().await,
|
||||
)
|
||||
.await,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let ptc_position_in_hollow_changed = PtcPositionInHollowChangedArg {
|
||||
player_uid,
|
||||
hollow_level: 1,
|
||||
position: hollow_grid_manager.get_cur_position_in_hollow(),
|
||||
position: session
|
||||
.context
|
||||
.hollow_grid_manager
|
||||
.get_cur_position_in_hollow()
|
||||
.await,
|
||||
};
|
||||
|
||||
session
|
||||
|
@ -112,7 +133,11 @@ pub async fn on_rpc_end_battle(
|
|||
.await?;
|
||||
|
||||
Ok(RpcEndBattleRet::new(
|
||||
hollow_grid_manager.get_cur_event_template_id(),
|
||||
session
|
||||
.context
|
||||
.hollow_grid_manager
|
||||
.get_cur_event_template_id()
|
||||
.await,
|
||||
HashMap::new(),
|
||||
))
|
||||
}
|
||||
|
@ -123,7 +148,13 @@ pub async fn on_rpc_run_hollow_event_graph(
|
|||
) -> Result<RpcRunHollowEventGraphRet> {
|
||||
tracing::info!("Run hollow event graph {:?}", arg);
|
||||
|
||||
let scene_uid = session.get_player().scene_uid.unwrap();
|
||||
let scene_uid = session
|
||||
.ns_prop_mgr
|
||||
.player_info
|
||||
.read()
|
||||
.await
|
||||
.scene_uid
|
||||
.unwrap();
|
||||
|
||||
if arg.event_graph_uid == 3405096459205834 {
|
||||
// Perform (cutscene)
|
||||
|
@ -148,8 +179,11 @@ pub async fn on_rpc_run_hollow_event_graph(
|
|||
.send_rpc_arg(PTC_SYNC_HOLLOW_EVENT_INFO_ID, &finish_perform)
|
||||
.await?;
|
||||
|
||||
let hollow_grid_manager = session.context.hollow_grid_manager.borrow();
|
||||
let (ptc_hollow_grid, ptc_sync_hollow_event) = hollow_grid_manager.move_to(22, scene_uid);
|
||||
let (ptc_hollow_grid, ptc_sync_hollow_event) = session
|
||||
.context
|
||||
.hollow_grid_manager
|
||||
.move_to(22, scene_uid)
|
||||
.await;
|
||||
|
||||
session
|
||||
.send_rpc_arg(PTC_HOLLOW_GRID_ID, &ptc_hollow_grid)
|
||||
|
@ -160,13 +194,11 @@ pub async fn on_rpc_run_hollow_event_graph(
|
|||
.await?;
|
||||
}
|
||||
} else {
|
||||
let hollow_grid_manager = session.context.hollow_grid_manager.borrow();
|
||||
let (sync_hollow_event, hollow_grid, trigger_battle_id, hollow_finished) =
|
||||
hollow_grid_manager.run_event_graph(
|
||||
arg.event_graph_uid,
|
||||
arg.event_id,
|
||||
arg.move_path.clone(),
|
||||
);
|
||||
let (sync_hollow_event, hollow_grid, trigger_battle_id, hollow_finished) = session
|
||||
.context
|
||||
.hollow_grid_manager
|
||||
.run_event_graph(arg.event_graph_uid, arg.event_id, arg.move_path.clone())
|
||||
.await;
|
||||
|
||||
if !hollow_finished {
|
||||
session
|
||||
|
@ -178,9 +210,11 @@ pub async fn on_rpc_run_hollow_event_graph(
|
|||
.await?;
|
||||
|
||||
if hollow_finished {
|
||||
let dungeon_manager = session.context.dungeon_manager.borrow();
|
||||
let _ = *dungeon_manager
|
||||
let _ = *session
|
||||
.context
|
||||
.dungeon_manager
|
||||
.hollow_finished()
|
||||
.await
|
||||
.send_changes(session)
|
||||
.await?;
|
||||
|
||||
|
@ -198,17 +232,30 @@ pub async fn on_rpc_run_hollow_event_graph(
|
|||
}
|
||||
|
||||
if let Some(trigger_battle_id) = trigger_battle_id {
|
||||
let dungeon_manager = session.context.dungeon_manager.borrow();
|
||||
let hollow_uid = *session.get_player().scene_uid.as_ref().unwrap();
|
||||
let battle_scene_uid = *dungeon_manager
|
||||
let hollow_uid = *session
|
||||
.ns_prop_mgr
|
||||
.player_info
|
||||
.read()
|
||||
.await
|
||||
.scene_uid
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
let battle_scene_uid = *session
|
||||
.context
|
||||
.dungeon_manager
|
||||
.create_fight(trigger_battle_id, hollow_uid)
|
||||
.await
|
||||
.send_changes(session)
|
||||
.await?;
|
||||
|
||||
let ptc_position_in_hollow_changed = PtcPositionInHollowChangedArg {
|
||||
player_uid: 1337,
|
||||
hollow_level: 1,
|
||||
position: hollow_grid_manager.get_cur_position_in_hollow(),
|
||||
position: session
|
||||
.context
|
||||
.hollow_grid_manager
|
||||
.get_cur_position_in_hollow()
|
||||
.await,
|
||||
};
|
||||
|
||||
session
|
||||
|
@ -221,8 +268,11 @@ pub async fn on_rpc_run_hollow_event_graph(
|
|||
session
|
||||
.send_rpc_arg(
|
||||
PTC_ENTER_SCENE_ID,
|
||||
dungeon_manager
|
||||
session
|
||||
.context
|
||||
.dungeon_manager
|
||||
.enter_battle(battle_scene_uid)
|
||||
.await
|
||||
.send_changes(session)
|
||||
.await?,
|
||||
)
|
||||
|
@ -241,7 +291,7 @@ pub async fn on_rpc_start_hollow_quest(
|
|||
|
||||
// Set avatar HP properties
|
||||
for (_idx, avatar_uid) in &arg.avatar_map {
|
||||
let player_info = session.get_player();
|
||||
let player_info = session.ns_prop_mgr.player_info.read().await;
|
||||
let items = player_info.items.as_ref().unwrap();
|
||||
let Some(ItemInfo::Avatar { id, .. }) = items
|
||||
.iter()
|
||||
|
@ -269,21 +319,23 @@ pub async fn on_rpc_start_hollow_quest(
|
|||
.await?;
|
||||
}
|
||||
|
||||
let dungeon_manager = session.context.dungeon_manager.borrow();
|
||||
|
||||
let avatars = arg
|
||||
.avatar_map
|
||||
.iter()
|
||||
.sorted_by_key(|kv| kv.0)
|
||||
.map(|(_idx, uid)| *uid)
|
||||
.collect::<Vec<_>>();
|
||||
let (dungeon_uid, scene_uid) = *dungeon_manager
|
||||
let (dungeon_uid, scene_uid) = *session
|
||||
.context
|
||||
.dungeon_manager
|
||||
.create_hollow(10001, 10010001, &avatars)
|
||||
.await
|
||||
.send_changes(session)
|
||||
.await?;
|
||||
|
||||
let quest_manager = session.context.quest_manager.borrow();
|
||||
quest_manager
|
||||
session
|
||||
.context
|
||||
.quest_manager
|
||||
.add_quest_to_collection(
|
||||
dungeon_uid,
|
||||
QuestInfo::DungeonInner {
|
||||
|
@ -298,29 +350,40 @@ pub async fn on_rpc_start_hollow_quest(
|
|||
sort_id: 2000,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.send_changes(session)
|
||||
.await?;
|
||||
|
||||
let ptc_enter_scene = dungeon_manager
|
||||
.enter_scene(scene_uid)?
|
||||
let ptc_enter_scene = session
|
||||
.context
|
||||
.dungeon_manager
|
||||
.enter_scene(scene_uid)
|
||||
.await?
|
||||
.send_changes(session)
|
||||
.await?
|
||||
.clone();
|
||||
|
||||
let hollow_grid_manager = session.context.hollow_grid_manager.borrow();
|
||||
hollow_grid_manager.init_default_map();
|
||||
session.context.hollow_grid_manager.init_default_map().await;
|
||||
|
||||
session
|
||||
.send_rpc_arg(
|
||||
PTC_SYNC_HOLLOW_GRID_MAPS_ID,
|
||||
&hollow_grid_manager.sync_hollow_maps(session.get_player_uid(), scene_uid),
|
||||
&session
|
||||
.context
|
||||
.hollow_grid_manager
|
||||
.sync_hollow_maps(session.get_player_uid().await, scene_uid)
|
||||
.await,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let ptc_position_in_hollow_changed = PtcPositionInHollowChangedArg {
|
||||
player_uid: 1337,
|
||||
hollow_level: 1,
|
||||
position: hollow_grid_manager.get_cur_position_in_hollow(),
|
||||
position: session
|
||||
.context
|
||||
.hollow_grid_manager
|
||||
.get_cur_position_in_hollow()
|
||||
.await,
|
||||
};
|
||||
|
||||
session
|
||||
|
|
|
@ -7,10 +7,11 @@ const DEFAULT_ACCOUNT_ID: u64 = 1337;
|
|||
|
||||
pub async fn on_rpc_login(session: &NetworkSession, arg: &RpcLoginArg) -> Result<RpcLoginRet> {
|
||||
tracing::info!("Received rpc login arg: {}", arg.account_name);
|
||||
*session.get_account_mut() = util::create_default_account(DEFAULT_ACCOUNT_ID);
|
||||
*session.ns_prop_mgr.account_info.write().await =
|
||||
util::create_default_account(DEFAULT_ACCOUNT_ID);
|
||||
|
||||
Ok(RpcLoginRet::new(
|
||||
session.ns_prop_mgr.serialize_account_info(),
|
||||
session.ns_prop_mgr.serialize_account_info().await,
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ pub async fn on_rpc_mod_nick_name(
|
|||
) -> Result<RpcModNickNameRet> {
|
||||
tracing::info!("creating character");
|
||||
|
||||
let mut player = session.get_player_mut();
|
||||
let mut player = session.ns_prop_mgr.player_info.write().await;
|
||||
player.nick_name.replace(arg.nick_name.clone());
|
||||
player.avatar_id.replace(arg.avatar_id);
|
||||
|
||||
|
|
|
@ -14,8 +14,7 @@ pub async fn on_rpc_run_event_graph(
|
|||
) -> Result<RpcRunEventGraphRet> {
|
||||
tracing::info!("RunEventGraph requested");
|
||||
|
||||
let scene_unit_mgr = session.context.scene_unit_manager.borrow();
|
||||
let unit = scene_unit_mgr.get(arg.owner_uid);
|
||||
let unit = session.context.scene_unit_manager.get(arg.owner_uid).await;
|
||||
|
||||
let SceneUnitProtocolInfo::NpcProtocolInfo { tag, id, .. } = unit;
|
||||
let main_city_object = data::get_main_city_object(tag, id).unwrap();
|
||||
|
@ -90,8 +89,7 @@ pub async fn on_rpc_interact_with_unit(
|
|||
) -> Result<RpcInteractWithUnitRet> {
|
||||
tracing::info!("InteractWithUnit");
|
||||
|
||||
let scene_unit_mgr = session.context.scene_unit_manager.borrow();
|
||||
let unit = scene_unit_mgr.get(arg.unit_uid);
|
||||
let unit = session.context.scene_unit_manager.get(arg.unit_uid).await;
|
||||
|
||||
let SceneUnitProtocolInfo::NpcProtocolInfo { tag, id, .. } = unit;
|
||||
let main_city_object = data::get_main_city_object(tag, id).unwrap();
|
||||
|
@ -170,16 +168,20 @@ fn create_player(id: u64) -> PlayerInfo {
|
|||
}
|
||||
|
||||
pub async fn enter_main_city(session: &NetworkSession) -> Result<()> {
|
||||
let dungeon_manager = session.context.dungeon_manager.borrow();
|
||||
let scene_unit_mgr = session.context.scene_unit_manager.borrow();
|
||||
|
||||
let hall_scene_uid = dungeon_manager.get_default_scene_uid();
|
||||
let hall_scene_uid = session
|
||||
.context
|
||||
.dungeon_manager
|
||||
.get_default_scene_uid()
|
||||
.await;
|
||||
|
||||
session
|
||||
.send_rpc_arg(
|
||||
PTC_ENTER_SECTION_ID,
|
||||
dungeon_manager
|
||||
session
|
||||
.context
|
||||
.dungeon_manager
|
||||
.enter_scene_section(hall_scene_uid, 2)
|
||||
.await
|
||||
.unwrap(),
|
||||
)
|
||||
.await?;
|
||||
|
@ -187,15 +189,22 @@ pub async fn enter_main_city(session: &NetworkSession) -> Result<()> {
|
|||
session
|
||||
.send_rpc_arg(
|
||||
PTC_SYNC_SCENE_UNIT_ID,
|
||||
&scene_unit_mgr.sync(hall_scene_uid, 2),
|
||||
&session
|
||||
.context
|
||||
.scene_unit_manager
|
||||
.sync(hall_scene_uid, 2)
|
||||
.await,
|
||||
)
|
||||
.await?;
|
||||
|
||||
session
|
||||
.send_rpc_arg(
|
||||
PTC_ENTER_SCENE_ID,
|
||||
dungeon_manager
|
||||
.enter_main_city()?
|
||||
session
|
||||
.context
|
||||
.dungeon_manager
|
||||
.enter_main_city()
|
||||
.await?
|
||||
.send_changes(session)
|
||||
.await?,
|
||||
)
|
||||
|
@ -206,76 +215,87 @@ pub async fn on_rpc_enter_world(
|
|||
session: &NetworkSession,
|
||||
_arg: &RpcEnterWorldArg,
|
||||
) -> Result<RpcEnterWorldRet> {
|
||||
let account = session.get_account();
|
||||
let account = session.ns_prop_mgr.account_info.read().await;
|
||||
|
||||
let id = *account.players.as_ref().unwrap().first().unwrap(); // get first id from list
|
||||
*session.get_player_mut() = create_player(id);
|
||||
*session.ns_prop_mgr.player_info.write().await = create_player(id);
|
||||
|
||||
let item_manager = session.context.item_manager.borrow();
|
||||
|
||||
item_manager.add_resource(501, 120);
|
||||
item_manager.add_resource(10, 228);
|
||||
item_manager.add_resource(100, 1337);
|
||||
let item_manager = &session.context.item_manager;
|
||||
item_manager.add_resource(501, 120).await;
|
||||
item_manager.add_resource(10, 228).await;
|
||||
item_manager.add_resource(100, 1337).await;
|
||||
|
||||
for avatar_id in data::iter_avatar_config_collection()
|
||||
.filter(|c| c.camp != 0)
|
||||
.map(|c| c.id)
|
||||
{
|
||||
item_manager.unlock_avatar(avatar_id);
|
||||
item_manager.unlock_avatar(avatar_id).await;
|
||||
}
|
||||
|
||||
let unlock_manager = session.context.unlock_manager.borrow();
|
||||
for unlock_id in data::iter_unlock_config_collection().map(|c| c.id) {
|
||||
unlock_manager.unlock(unlock_id);
|
||||
session.context.unlock_manager.unlock(unlock_id).await;
|
||||
}
|
||||
|
||||
let dungeon_manager = session.context.dungeon_manager.borrow();
|
||||
dungeon_manager.create_hall(1);
|
||||
let scene_unit_mgr = session.context.scene_unit_manager.borrow();
|
||||
scene_unit_mgr.add_default_units();
|
||||
session.context.dungeon_manager.create_hall(1).await;
|
||||
session.context.scene_unit_manager.add_default_units().await;
|
||||
|
||||
let quest_manager = session.context.quest_manager.borrow();
|
||||
quest_manager.add_world_quest(QuestInfo::MainCity {
|
||||
id: 10020002,
|
||||
finished_count: 0,
|
||||
collection_uid: 0,
|
||||
progress: 0,
|
||||
parent_quest_id: 0,
|
||||
state: QuestState::InProgress,
|
||||
finish_condition_progress: phashmap![],
|
||||
progress_time: 2111012,
|
||||
sort_id: 1000,
|
||||
bound_npc_and_interact: phashmap![],
|
||||
});
|
||||
let quest_manager = session.context.quest_manager.clone();
|
||||
quest_manager
|
||||
.add_world_quest(QuestInfo::MainCity {
|
||||
id: 10020002,
|
||||
finished_count: 0,
|
||||
collection_uid: 0,
|
||||
progress: 0,
|
||||
parent_quest_id: 0,
|
||||
state: QuestState::InProgress,
|
||||
finish_condition_progress: phashmap![],
|
||||
progress_time: 2111012,
|
||||
sort_id: 1000,
|
||||
bound_npc_and_interact: phashmap![],
|
||||
})
|
||||
.await;
|
||||
|
||||
quest_manager.add_world_quest(QuestInfo::Hollow {
|
||||
id: 10010002,
|
||||
finished_count: 0,
|
||||
collection_uid: 3405096459205774,
|
||||
progress: 0,
|
||||
parent_quest_id: 0,
|
||||
state: QuestState::Ready,
|
||||
sort_id: 1001,
|
||||
statistics: phashmap![],
|
||||
statistics_ext: pdkhashmap![],
|
||||
acquired_hollow_challenge_reward: 0,
|
||||
progress_time: 0,
|
||||
finish_condition_progress: phashmap![],
|
||||
dungeon_uid: 0,
|
||||
});
|
||||
quest_manager
|
||||
.add_world_quest(QuestInfo::Hollow {
|
||||
id: 10010002,
|
||||
finished_count: 0,
|
||||
collection_uid: 3405096459205774,
|
||||
progress: 0,
|
||||
parent_quest_id: 0,
|
||||
state: QuestState::Ready,
|
||||
sort_id: 1001,
|
||||
statistics: phashmap![],
|
||||
statistics_ext: pdkhashmap![],
|
||||
acquired_hollow_challenge_reward: 0,
|
||||
progress_time: 0,
|
||||
finish_condition_progress: phashmap![],
|
||||
dungeon_uid: 0,
|
||||
})
|
||||
.await;
|
||||
|
||||
let yorozuya_quest_manager = session.context.yorozuya_quest_manager.borrow();
|
||||
yorozuya_quest_manager.add_hollow_quest(102, HollowQuestType::SideQuest, 10010002);
|
||||
session
|
||||
.context
|
||||
.yorozuya_quest_manager
|
||||
.add_hollow_quest(102, HollowQuestType::SideQuest, 10010002)
|
||||
.await;
|
||||
|
||||
if CONFIGURATION.skip_tutorial {
|
||||
Box::pin(enter_main_city(session)).await?;
|
||||
} else {
|
||||
let fresh_scene_uid = *dungeon_manager.create_fresh().unwrap();
|
||||
let fresh_scene_uid = *session
|
||||
.context
|
||||
.dungeon_manager
|
||||
.create_fresh()
|
||||
.await
|
||||
.unwrap();
|
||||
session
|
||||
.send_rpc_arg(
|
||||
PTC_ENTER_SCENE_ID,
|
||||
dungeon_manager
|
||||
session
|
||||
.context
|
||||
.dungeon_manager
|
||||
.enter_scene(fresh_scene_uid)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap(),
|
||||
)
|
||||
|
@ -293,6 +313,6 @@ pub async fn on_rpc_enter_world(
|
|||
.await?;
|
||||
|
||||
Ok(RpcEnterWorldRet::new(
|
||||
session.ns_prop_mgr.serialize_player_info(),
|
||||
session.ns_prop_mgr.serialize_player_info().await,
|
||||
))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
use anyhow::Result;
|
||||
use atomic_refcell::{AtomicRef, AtomicRefMut};
|
||||
use protocol::*;
|
||||
use qwer::{OctData, ProtocolHeader};
|
||||
use std::io::Cursor;
|
||||
use std::sync::Arc;
|
||||
|
@ -37,24 +35,8 @@ impl NetworkSession {
|
|||
self.client_socket.lock().await
|
||||
}
|
||||
|
||||
pub fn get_player_uid(&self) -> u64 {
|
||||
self.get_player().uid.unwrap()
|
||||
}
|
||||
|
||||
pub fn get_account(&self) -> AtomicRef<AccountInfo> {
|
||||
self.ns_prop_mgr.account_info.borrow()
|
||||
}
|
||||
|
||||
pub fn get_player(&self) -> AtomicRef<PlayerInfo> {
|
||||
self.ns_prop_mgr.player_info.borrow()
|
||||
}
|
||||
|
||||
pub fn get_account_mut(&self) -> AtomicRefMut<'_, AccountInfo> {
|
||||
self.ns_prop_mgr.account_info.try_borrow_mut().unwrap()
|
||||
}
|
||||
|
||||
pub fn get_player_mut(&self) -> AtomicRefMut<'_, PlayerInfo> {
|
||||
self.ns_prop_mgr.player_info.try_borrow_mut().unwrap()
|
||||
pub async fn get_player_uid(&self) -> u64 {
|
||||
self.ns_prop_mgr.player_info.read().await.uid.unwrap()
|
||||
}
|
||||
|
||||
pub async fn run(&mut self) -> Result<()> {
|
||||
|
|
Loading…
Reference in a new issue