Enable TP point unlocking

This commit is contained in:
Nobody 2022-04-04 22:57:05 +05:00
parent a62fbbdaa8
commit 8a3ac5e8d3
6 changed files with 87 additions and 5 deletions

View File

@ -5,6 +5,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
raw_packet_dump = []
[dependencies] [dependencies]
kcp = { path = "../kcp" } kcp = { path = "../kcp" }
mhycrypt = { path = "../mhycrypt" } mhycrypt = { path = "../mhycrypt" }

View File

@ -73,6 +73,9 @@ use super::reliquary_prop::Entity as ReliquaryPropEntity;
pub use super::furniture_info::Model as FurnitureInfo; pub use super::furniture_info::Model as FurnitureInfo;
use super::furniture_info::Entity as FurnitureInfoEntity; use super::furniture_info::Entity as FurnitureInfoEntity;
pub use super::trans_point::Model as TransPoint;
use super::trans_point::Entity as TransPointEntity;
/* /*
This is used to convert async operations into sync ones This is used to convert async operations into sync ones
*/ */
@ -1050,6 +1053,32 @@ impl DatabaseManager {
// No assert here // No assert here
} }
pub fn get_scene_trans_points(&self, user_id: u32, scene_id: u32) -> Vec<u32> {
let points = match TransPointEntity::find()
.filter(
Condition::all()
.add(super::trans_point::Column::Uid.eq(user_id))
.add(super::trans_point::Column::SceneId.eq(scene_id))
)
.all(&self.db).wait()
{
Err(_) => { panic!("DB ERROR!") },
Ok(points) => points.iter().map(|x| x.point_id).collect(),
};
return points;
}
pub fn add_scene_trans_point(&self, user_id: u32, scene_id: u32, point_id: u32) {
let point = super::trans_point::ActiveModel {
uid: ActiveValue::Set(user_id),
scene_id: ActiveValue::Set(scene_id),
point_id: ActiveValue::Set(point_id),
};
let point: TransPoint = point.put(&self.db).unwrap();
}
pub const SPOOFED_AVATAR_ID: u32 = 1; pub const SPOOFED_AVATAR_ID: u32 = 1;
pub const SPOOFED_WEAPON_ID: u32 = 2; pub const SPOOFED_WEAPON_ID: u32 = 2;
const SPOOFED_SCENE_ID: u32 = 3; // TODO: that's a different kind of ID! const SPOOFED_SCENE_ID: u32 = 3; // TODO: that's a different kind of ID!

View File

@ -20,4 +20,5 @@ mod equip_info;
mod item_info; mod item_info;
mod weapon_affix_info; mod weapon_affix_info;
mod reliquary_prop; mod reliquary_prop;
mod furniture_info; mod furniture_info;
mod trans_point;

View File

@ -0,0 +1,26 @@
// Database Manager
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "trans_point")]
pub struct Model {
#[sea_orm(primary_key, autoincrement = false)]
pub uid: u32,
pub scene_id: u32,
pub point_id: u32,
}
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
_ => panic!("Unknown relation type!"),
}
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -23,13 +23,15 @@ GetScenePointReq,
)] )]
pub struct SceneSubsystem { pub struct SceneSubsystem {
packets_to_send_tx: Sender<IpcMessage>, packets_to_send_tx: Sender<IpcMessage>,
db: Arc<DatabaseManager>,
} }
impl SceneSubsystem { impl SceneSubsystem {
pub fn new(packets_to_send_tx: Sender<IpcMessage>) -> Self { pub fn new(db: Arc<DatabaseManager>, packets_to_send_tx: Sender<IpcMessage>) -> Self {
let mut scs = Self { let mut scs = Self {
packets_to_send_tx: packets_to_send_tx, packets_to_send_tx: packets_to_send_tx,
packet_callbacks: HashMap::new(), packet_callbacks: HashMap::new(),
db: db,
}; };
scs.register(); scs.register();
@ -49,10 +51,16 @@ impl SceneSubsystem {
} }
fn process_get_scene_point(&self, user_id: u32, metadata: &proto::PacketHead, req: &proto::GetScenePointReq, rsp: &mut proto::GetScenePointRsp) { fn process_get_scene_point(&self, user_id: u32, metadata: &proto::PacketHead, req: &proto::GetScenePointReq, rsp: &mut proto::GetScenePointRsp) {
rsp.scene_id = req.scene_id; let scene_id = req.scene_id;
rsp.scene_id = scene_id;
// TODO: implemented but for the sake of debugging we hardcode it for now
rsp.unlocked_point_list = (1..300).collect();
//rsp.unlocked_point_list = self.db.get_scene_trans_points(user_id, scene_id);
// TODO: hardcoded data! // TODO: hardcoded data!
rsp.unlocked_point_list = (1..250).collect(); rsp.unlock_area_list = (1..20).collect();
rsp.unlock_area_list = (1..11).collect();
//locked_point_list=vec![]; //locked_point_list=vec![];
} }

View File

@ -21,6 +21,7 @@ use crate::utils::{IdManager, TimeManager};
#[packet_processor( #[packet_processor(
SceneTransToPointReq, SceneTransToPointReq,
UnlockTransPointReq,
)] )]
pub struct TeleportSubsystem { pub struct TeleportSubsystem {
packets_to_send_tx: Sender<IpcMessage>, packets_to_send_tx: Sender<IpcMessage>,
@ -75,4 +76,18 @@ impl TeleportSubsystem {
self.em.player_teleported(user_id, pos, s_id, scene_info.scene_token, &proto::EnterType::EnterGoto); self.em.player_teleported(user_id, pos, s_id, scene_info.scene_token, &proto::EnterType::EnterGoto);
} }
pub fn process_unlock_trans_point(&self, user_id: u32, metadata: &proto::PacketHead, req: &proto::UnlockTransPointReq, rsp: &mut proto::UnlockTransPointRsp) {
let scene_id = req.scene_id;
let point_id = req.point_id;
self.db.add_scene_trans_point(user_id, scene_id, point_id);
// TODO: for unknown points we can just use player's position and add them to our collection
build_and_send!(self, user_id, metadata, ScenePointUnlockNotify {
scene_id: scene_id,
point_list: vec![point_id],
});
}
} }