mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-24 08:07:45 +00:00
Store zone id and position in the World database
This isn't updated by the server yet, but will be soon in the future.
This commit is contained in:
parent
4b740068d4
commit
fb05caaa31
2 changed files with 49 additions and 18 deletions
|
@ -241,9 +241,7 @@ async fn main() {
|
||||||
let chara_details = database
|
let chara_details = database
|
||||||
.find_chara_make(connection.player_data.content_id);
|
.find_chara_make(connection.player_data.content_id);
|
||||||
|
|
||||||
let zone_id = determine_initial_starting_zone(
|
let zone_id = chara_details.zone_id;
|
||||||
chara_details.city_state,
|
|
||||||
);
|
|
||||||
|
|
||||||
connection.zone = Some(Zone::load(zone_id));
|
connection.zone = Some(Zone::load(zone_id));
|
||||||
|
|
||||||
|
@ -743,6 +741,7 @@ async fn main() {
|
||||||
name,
|
name,
|
||||||
chara_make_json,
|
chara_make_json,
|
||||||
city_state,
|
city_state,
|
||||||
|
determine_initial_starting_zone(city_state),
|
||||||
);
|
);
|
||||||
|
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
|
|
|
@ -4,7 +4,7 @@ use rusqlite::Connection;
|
||||||
|
|
||||||
use crate::lobby::{CharaMake, ClientSelectData, ipc::CharacterDetails};
|
use crate::lobby::{CharaMake, ClientSelectData, ipc::CharacterDetails};
|
||||||
|
|
||||||
use super::PlayerData;
|
use super::{PlayerData, ipc::Position};
|
||||||
|
|
||||||
pub struct WorldDatabase {
|
pub struct WorldDatabase {
|
||||||
connection: Mutex<Connection>,
|
connection: Mutex<Connection>,
|
||||||
|
@ -14,6 +14,8 @@ pub struct CharacterData {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub chara_make: CharaMake, // probably not the ideal way to store this?
|
pub chara_make: CharaMake, // probably not the ideal way to store this?
|
||||||
pub city_state: u8,
|
pub city_state: u8,
|
||||||
|
pub position: Position,
|
||||||
|
pub zone_id: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorldDatabase {
|
impl WorldDatabase {
|
||||||
|
@ -28,7 +30,7 @@ impl WorldDatabase {
|
||||||
|
|
||||||
// Create characters data table
|
// Create characters data table
|
||||||
{
|
{
|
||||||
let query = "CREATE TABLE IF NOT EXISTS character_data (content_id INTEGER PRIMARY KEY, name STRING, chara_make STRING, city_state INTEGER);";
|
let query = "CREATE TABLE IF NOT EXISTS character_data (content_id INTEGER PRIMARY KEY, name STRING, chara_make STRING, city_state INTEGER, zone_id INTEGER, pos_x REAL, pos_y REAL, pos_z REAL);";
|
||||||
connection.execute(query, ()).unwrap();
|
connection.execute(query, ()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,16 +96,18 @@ impl WorldDatabase {
|
||||||
let mut characters = Vec::new();
|
let mut characters = Vec::new();
|
||||||
|
|
||||||
for (index, (content_id, actor_id)) in content_actor_ids.iter().enumerate() {
|
for (index, (content_id, actor_id)) in content_actor_ids.iter().enumerate() {
|
||||||
dbg!(content_id);
|
|
||||||
|
|
||||||
let mut stmt = connection
|
let mut stmt = connection
|
||||||
.prepare("SELECT name, chara_make FROM character_data WHERE content_id = ?1")
|
.prepare(
|
||||||
|
"SELECT name, chara_make, zone_id FROM character_data WHERE content_id = ?1",
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let result: Result<(String, String), rusqlite::Error> =
|
let result: Result<(String, String, u16), rusqlite::Error> = stmt
|
||||||
stmt.query_row((content_id,), |row| Ok((row.get(0)?, row.get(1)?)));
|
.query_row((content_id,), |row| {
|
||||||
|
Ok((row.get(0)?, row.get(1)?, row.get(2)?))
|
||||||
|
});
|
||||||
|
|
||||||
if let Ok((name, chara_make)) = result {
|
if let Ok((name, chara_make, zone_id)) = result {
|
||||||
let chara_make = CharaMake::from_json(&chara_make);
|
let chara_make = CharaMake::from_json(&chara_make);
|
||||||
|
|
||||||
let select_data = ClientSelectData {
|
let select_data = ClientSelectData {
|
||||||
|
@ -118,7 +122,7 @@ impl WorldDatabase {
|
||||||
guardian: chara_make.guardian,
|
guardian: chara_make.guardian,
|
||||||
unk8: 0,
|
unk8: 0,
|
||||||
unk9: 0,
|
unk9: 0,
|
||||||
zone_id: 130 as i32,
|
zone_id: zone_id as i32,
|
||||||
unk11: 0,
|
unk11: 0,
|
||||||
customize: chara_make.customize,
|
customize: chara_make.customize,
|
||||||
unk12: 0,
|
unk12: 0,
|
||||||
|
@ -163,7 +167,13 @@ impl WorldDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gives (content_id, actor_id)
|
/// Gives (content_id, actor_id)
|
||||||
pub fn create_player_data(&self, name: &str, chara_make: &str, city_state: u8) -> (u64, u32) {
|
pub fn create_player_data(
|
||||||
|
&self,
|
||||||
|
name: &str,
|
||||||
|
chara_make: &str,
|
||||||
|
city_state: u8,
|
||||||
|
zone_id: u16,
|
||||||
|
) -> (u64, u32) {
|
||||||
let content_id = Self::generate_content_id();
|
let content_id = Self::generate_content_id();
|
||||||
let actor_id = Self::generate_actor_id();
|
let actor_id = Self::generate_actor_id();
|
||||||
|
|
||||||
|
@ -180,8 +190,8 @@ impl WorldDatabase {
|
||||||
// insert char data
|
// insert char data
|
||||||
connection
|
connection
|
||||||
.execute(
|
.execute(
|
||||||
"INSERT INTO character_data VALUES (?1, ?2, ?3, ?4);",
|
"INSERT INTO character_data VALUES (?1, ?2, ?3, ?4, ?5, 0.0, 0.0, 0.0);",
|
||||||
(content_id, name, chara_make, city_state),
|
(content_id, name, chara_make, city_state, zone_id),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -204,12 +214,28 @@ impl WorldDatabase {
|
||||||
|
|
||||||
let mut stmt = connection
|
let mut stmt = connection
|
||||||
.prepare(
|
.prepare(
|
||||||
"SELECT name, chara_make, city_state FROM character_data WHERE content_id = ?1",
|
"SELECT name, chara_make, city_state, zone_id, pos_x, pos_y, pos_z FROM character_data WHERE content_id = ?1",
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let (name, chara_make_json, city_state): (String, String, u8) = stmt
|
let (name, chara_make_json, city_state, zone_id, pos_x, pos_y, pos_z): (
|
||||||
|
String,
|
||||||
|
String,
|
||||||
|
u8,
|
||||||
|
u16,
|
||||||
|
f32,
|
||||||
|
f32,
|
||||||
|
f32,
|
||||||
|
) = stmt
|
||||||
.query_row((content_id,), |row| {
|
.query_row((content_id,), |row| {
|
||||||
Ok((row.get(0)?, row.get(1)?, row.get(2)?))
|
Ok((
|
||||||
|
row.get(0)?,
|
||||||
|
row.get(1)?,
|
||||||
|
row.get(2)?,
|
||||||
|
row.get(3)?,
|
||||||
|
row.get(4)?,
|
||||||
|
row.get(5)?,
|
||||||
|
row.get(6)?,
|
||||||
|
))
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -217,6 +243,12 @@ impl WorldDatabase {
|
||||||
name,
|
name,
|
||||||
chara_make: CharaMake::from_json(&chara_make_json),
|
chara_make: CharaMake::from_json(&chara_make_json),
|
||||||
city_state,
|
city_state,
|
||||||
|
zone_id,
|
||||||
|
position: Position {
|
||||||
|
x: pos_x,
|
||||||
|
y: pos_y,
|
||||||
|
z: pos_z,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue