mirror of
https://github.com/RustySamovar/RustySamovar.git
synced 2024-11-24 03:13:32 +00:00
Load reliquaries, materials & weapons data
This commit is contained in:
parent
06c10924d9
commit
2135b8baa8
@ -4,9 +4,15 @@ use std::collections::{HashMap, BTreeMap};
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use rand::{seq::IteratorRandom, thread_rng};
|
||||
|
||||
use crate::jsonmanager::gather::Gather;
|
||||
use crate::jsonmanager::material::Material;
|
||||
use crate::jsonmanager::reliquary::{Reliquary, ReliquaryAffix, ReliquaryMainProp};
|
||||
use crate::jsonmanager::shop_goods::ShopGoods;
|
||||
use crate::jsonmanager::shop_rotate::ShopRotate;
|
||||
use crate::jsonmanager::weapon::Weapon;
|
||||
|
||||
use super::avatar_skill_depot::AvatarSkillDepot;
|
||||
use super::entity_curve::EntityCurve;
|
||||
@ -41,6 +47,13 @@ pub struct JsonManager {
|
||||
pub gathers: HashMap<u32, Gather>,
|
||||
pub shop_goods: HashMap<u32, Vec<ShopGoods>>,
|
||||
pub shop_rotate: HashMap<u32, Vec<ShopRotate>>,
|
||||
pub weapons: HashMap<u32, Weapon>,
|
||||
pub reliquaries: HashMap<u32, Reliquary>,
|
||||
|
||||
pub reliquary_main_prop_depot: HashMap<u32, Vec<ReliquaryMainProp>>,
|
||||
pub reliquary_affixes: HashMap<u32, Vec<ReliquaryAffix>>,
|
||||
|
||||
pub materials: HashMap<u32, Material>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for JsonManager { // TODO: fucking hack!
|
||||
@ -62,6 +75,14 @@ impl JsonManager {
|
||||
let gathers: Vec<Gather> = reader.read_json_list("Gather");
|
||||
let shop_goods: Vec<ShopGoods> = reader.read_json_list("ShopGoods");
|
||||
let shop_rotate: Vec<ShopRotate> = reader.read_json_list("ShopRotate");
|
||||
let weapons: Vec<Weapon> = reader.read_json_list("Weapon");
|
||||
|
||||
let reliquaries: Vec<Reliquary> = reader.read_json_list("Reliquary");
|
||||
|
||||
let reliquary_main_prop_depot : Vec<ReliquaryMainProp> = reader.read_json_list("ReliquaryMainProp");
|
||||
let reliquary_affixes : Vec<ReliquaryAffix> = reader.read_json_list("ReliquaryAffix");
|
||||
|
||||
let materials: Vec<Material> = reader.read_json_list("Material");
|
||||
|
||||
return JsonManager {
|
||||
reader: reader,
|
||||
@ -76,8 +97,52 @@ impl JsonManager {
|
||||
.collect(),
|
||||
shop_rotate: group_nonconsec_by(shop_rotate, |sr| sr.rotate_id).into_iter() // TODO: we're grouping by rotate_id, not by ID!
|
||||
.collect(),
|
||||
weapons: weapons.into_iter().map(|w| (w.id, w)).collect(),
|
||||
reliquaries: reliquaries.into_iter().map(|r| (r.id, r)).collect(),
|
||||
|
||||
reliquary_main_prop_depot: group_nonconsec_by(reliquary_main_prop_depot, |mp| mp.prop_depot_id).into_iter()
|
||||
.collect(), // TODO: we're grouping by depot_id!
|
||||
reliquary_affixes: group_nonconsec_by(reliquary_affixes, |a| a.depot_id).into_iter()
|
||||
.collect(), // TODO: we're grouping by depot_id!
|
||||
|
||||
materials: materials.into_iter().map(|m| (m.id, m)).collect(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn is_item_weapon(&self, item_id: u32) -> bool {
|
||||
return self.weapons.contains_key(&item_id)
|
||||
}
|
||||
|
||||
pub fn is_item_reliquary(&self, item_id: u32) -> bool {
|
||||
return self.reliquaries.contains_key(&item_id)
|
||||
}
|
||||
|
||||
pub fn is_item_material(&self, item_id: u32) -> bool {
|
||||
return self.materials.contains_key(&item_id)
|
||||
}
|
||||
|
||||
// TODO: I'm not sure those two methods should belongs here!
|
||||
pub fn roll_reliquary_stats_by_item_id(&self, item_id: u32) -> (u32, Vec<u32>) {
|
||||
let reliquary = match self.reliquaries.get(&item_id) {
|
||||
None => panic!("Rolling for stats of item {} which is not in reliquary dict!", item_id),
|
||||
Some(reliquary) => reliquary,
|
||||
};
|
||||
|
||||
return self.roll_reliquary_stats(reliquary.main_prop_depot_id, reliquary.append_prop_depot_id, reliquary.append_prop_num);
|
||||
}
|
||||
|
||||
pub fn roll_reliquary_stats(&self, main_depot_id: u32, affix_depot_id: u32, num_affices: usize) -> (u32, Vec<u32>) {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let main_depot = &self.reliquary_main_prop_depot[&main_depot_id];
|
||||
let affix_depot = &self.reliquary_affixes[&affix_depot_id];
|
||||
|
||||
let main_stat = main_depot.iter().choose(&mut rng).unwrap().id;
|
||||
|
||||
let sub_stats: Vec<u32> = affix_depot.iter().choose_multiple(&mut rng, num_affices).iter().map(|a| a.id).collect(); // TODO: roll without weights!
|
||||
|
||||
return (main_stat, sub_stats);
|
||||
}
|
||||
}
|
||||
|
||||
impl JsonReader {
|
||||
|
@ -0,0 +1,30 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[serde(rename_all="PascalCase")]
|
||||
pub struct MaterialUseParam {
|
||||
pub use_op: Option<String>, // TODO: that's an enum!
|
||||
pub use_param: Vec<String>, // Most of the time they are integers tho
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[serde(rename_all="PascalCase")]
|
||||
pub struct Material {
|
||||
pub id: u32,
|
||||
#[serde(default)]
|
||||
pub no_first_get_hint: bool,
|
||||
pub rank: Option<u32>,
|
||||
pub rank_level: Option<u32>,
|
||||
pub stack_limit: Option<u32>,
|
||||
pub max_use_count: Option<u32>,
|
||||
pub gadget_id: Option<u32>,
|
||||
|
||||
#[serde(default)]
|
||||
pub use_on_gain: bool,
|
||||
pub item_use: Vec<MaterialUseParam>,
|
||||
pub use_target: Option<String>, // TODO: that's an enum!
|
||||
|
||||
/*
|
||||
Misc fields omitted
|
||||
*/
|
||||
}
|
@ -10,6 +10,9 @@ mod gadget_prop;
|
||||
mod gather;
|
||||
mod shop_goods;
|
||||
mod shop_rotate;
|
||||
mod weapon;
|
||||
mod reliquary;
|
||||
mod material;
|
||||
|
||||
pub use entity_curve::{CurveInfo,EntityCurve};
|
||||
pub use shop_goods::ShopGoods;
|
37
src/jsonmanager/reliquary.rs
Normal file
37
src/jsonmanager/reliquary.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[serde(rename_all="PascalCase")]
|
||||
pub struct Reliquary {
|
||||
pub id: u32,
|
||||
pub main_prop_depot_id: u32,
|
||||
pub append_prop_depot_id: u32,
|
||||
#[serde(default)]
|
||||
pub append_prop_num: usize,
|
||||
pub set_id: Option<u32>,
|
||||
/*
|
||||
Other fields omitted
|
||||
*/
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[serde(rename_all="PascalCase")]
|
||||
pub struct ReliquaryMainProp {
|
||||
pub id: u32,
|
||||
pub prop_depot_id: u32,
|
||||
pub prop_type: proto::FightPropType,
|
||||
pub affix_name: String,
|
||||
//pub weight: u32, // TODO: removed in 2.5.0!
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[serde(rename_all="PascalCase")]
|
||||
pub struct ReliquaryAffix {
|
||||
pub id: u32,
|
||||
pub depot_id: u32,
|
||||
pub group_id: u32,
|
||||
pub prop_type: proto::FightPropType,
|
||||
pub prop_value: f32,
|
||||
//pub weight: u32, // TODO: removed in 2.5.0!
|
||||
//pub upgrade_weight: u32, // TODO: removed in 2.5.0!
|
||||
}
|
32
src/jsonmanager/weapon.rs
Normal file
32
src/jsonmanager/weapon.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[serde(rename_all="PascalCase")]
|
||||
pub struct WeaponProp {
|
||||
pub r#type: proto::GrowCurveType,
|
||||
// These two fields is missing sometimes
|
||||
#[serde(default)]
|
||||
pub init_value: f32,
|
||||
#[serde(default)]
|
||||
pub prop_type: proto::FightPropType,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[serde(rename_all="PascalCase")]
|
||||
pub struct Weapon {
|
||||
pub id: u32,
|
||||
|
||||
pub weapon_type: String, // TODO: that's an enum!
|
||||
pub rank_level: u32,
|
||||
pub skill_affix: Vec<u32>,
|
||||
pub weapon_prop: Vec<WeaponProp>,
|
||||
pub weapon_promote_id: u32,
|
||||
pub story_id: Option<u32>,
|
||||
pub awaken_costs: Vec<u32>,
|
||||
#[serde(default)]
|
||||
pub destroy_rule: String, // TODO: that's an enum!
|
||||
pub destroy_return_material: Vec<u32>,
|
||||
pub destroy_return_material_count: Vec<u32>,
|
||||
pub weight: u32,
|
||||
pub gadget_id: u32,
|
||||
}
|
Loading…
Reference in New Issue
Block a user