Add LootTable component
This commit is contained in:
parent
c9b35e2710
commit
0c09f52eb6
@ -337,6 +337,11 @@ pub struct NaturalAttackDefense {
|
|||||||
pub attacks: Vec<NaturalAttack>,
|
pub attacks: Vec<NaturalAttack>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct LootTable {
|
||||||
|
pub table: String,
|
||||||
|
}
|
||||||
|
|
||||||
// Serialization helper code. We need to implement ConvertSaveLoad for each type that contains an
|
// Serialization helper code. We need to implement ConvertSaveLoad for each type that contains an
|
||||||
// Entity.
|
// Entity.
|
||||||
|
|
||||||
|
@ -539,6 +539,7 @@ fn main() -> ::rltk::BError {
|
|||||||
Skills,
|
Skills,
|
||||||
Pools,
|
Pools,
|
||||||
NaturalAttackDefense,
|
NaturalAttackDefense,
|
||||||
|
LootTable,
|
||||||
);
|
);
|
||||||
|
|
||||||
gs.ecs.insert(SimpleMarkerAllocator::<SerializeMe>::new());
|
gs.ecs.insert(SimpleMarkerAllocator::<SerializeMe>::new());
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
mod item_structs;
|
mod item_structs;
|
||||||
|
mod loot_structs;
|
||||||
mod mob_structs;
|
mod mob_structs;
|
||||||
mod prop_structs;
|
mod prop_structs;
|
||||||
mod rawmaster;
|
mod rawmaster;
|
||||||
@ -9,6 +10,7 @@ use std::sync::Mutex;
|
|||||||
use ::rltk::{embedded_resource, link_resource};
|
use ::rltk::{embedded_resource, link_resource};
|
||||||
use ::serde::Deserialize;
|
use ::serde::Deserialize;
|
||||||
use item_structs::*;
|
use item_structs::*;
|
||||||
|
use loot_structs::*;
|
||||||
use mob_structs::*;
|
use mob_structs::*;
|
||||||
use prop_structs::*;
|
use prop_structs::*;
|
||||||
pub use rawmaster::*;
|
pub use rawmaster::*;
|
||||||
@ -20,6 +22,7 @@ pub struct Raws {
|
|||||||
pub mobs: Vec<Mob>,
|
pub mobs: Vec<Mob>,
|
||||||
pub props: Vec<Prop>,
|
pub props: Vec<Prop>,
|
||||||
pub spawn_table: Vec<SpawnTableEntry>,
|
pub spawn_table: Vec<SpawnTableEntry>,
|
||||||
|
pub loot_tables: Vec<LootTable>,
|
||||||
}
|
}
|
||||||
|
|
||||||
embedded_resource!(RAW_FILE, "../raws/spawns.json");
|
embedded_resource!(RAW_FILE, "../raws/spawns.json");
|
||||||
|
13
src/raws/loot_structs.rs
Normal file
13
src/raws/loot_structs.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct LootTable {
|
||||||
|
pub name: String,
|
||||||
|
pub drops: Vec<LootDrop>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct LootDrop {
|
||||||
|
pub name: String,
|
||||||
|
pub weight: i32,
|
||||||
|
}
|
@ -19,6 +19,7 @@ pub struct Mob {
|
|||||||
pub mana: Option<i32>,
|
pub mana: Option<i32>,
|
||||||
pub equipped: Option<Vec<String>>,
|
pub equipped: Option<Vec<String>>,
|
||||||
pub natural: Option<MobNatural>,
|
pub natural: Option<MobNatural>,
|
||||||
|
pub loot_table: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
|
@ -43,6 +43,7 @@ pub struct RawMaster {
|
|||||||
item_index: HashMap<String, usize>,
|
item_index: HashMap<String, usize>,
|
||||||
mob_index: HashMap<String, usize>,
|
mob_index: HashMap<String, usize>,
|
||||||
prop_index: HashMap<String, usize>,
|
prop_index: HashMap<String, usize>,
|
||||||
|
loot_index: HashMap<String, usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RawMaster {
|
impl RawMaster {
|
||||||
@ -53,10 +54,12 @@ impl RawMaster {
|
|||||||
mobs: Vec::new(),
|
mobs: Vec::new(),
|
||||||
props: Vec::new(),
|
props: Vec::new(),
|
||||||
spawn_table: Vec::new(),
|
spawn_table: Vec::new(),
|
||||||
|
loot_tables: Vec::new(),
|
||||||
},
|
},
|
||||||
item_index: HashMap::new(),
|
item_index: HashMap::new(),
|
||||||
mob_index: HashMap::new(),
|
mob_index: HashMap::new(),
|
||||||
prop_index: HashMap::new(),
|
prop_index: HashMap::new(),
|
||||||
|
loot_index: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +106,10 @@ impl RawMaster {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i, loot) in self.raws.loot_tables.iter().enumerate() {
|
||||||
|
self.loot_index.insert(loot.name.clone(), i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,6 +411,12 @@ pub fn spawn_named_mob(
|
|||||||
eb = eb.with(nature);
|
eb = eb.with(nature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(loot) = &mob_template.loot_table {
|
||||||
|
eb = eb.with(LootTable {
|
||||||
|
table: loot.clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let new_mob = eb.build();
|
let new_mob = eb.build();
|
||||||
|
|
||||||
// Are they weilding anything?
|
// Are they weilding anything?
|
||||||
|
@ -95,6 +95,7 @@ pub fn save_game(ecs: &mut World) {
|
|||||||
Skills,
|
Skills,
|
||||||
Pools,
|
Pools,
|
||||||
NaturalAttackDefense,
|
NaturalAttackDefense,
|
||||||
|
LootTable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,6 +193,7 @@ pub fn load_game(ecs: &mut World) {
|
|||||||
Skills,
|
Skills,
|
||||||
Pools,
|
Pools,
|
||||||
NaturalAttackDefense,
|
NaturalAttackDefense,
|
||||||
|
LootTable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user