jake
4 years ago
7 changed files with 1045 additions and 0 deletions
-
219data/shops/barrier.toml
-
251data/shops/frame.toml
-
300data/shops/unit.toml
-
259src/ship/shops/armor.rs
-
1src/ship/shops/mod.rs
-
8src/ship/shops/tool.rs
-
7src/ship/shops/weapon.rs
@ -0,0 +1,219 @@ |
|||
[[barrier]] |
|||
level = 0 |
|||
[[barrier.item]] |
|||
item = "Barrier" |
|||
probability = 34 |
|||
|
|||
[[barrier.item]] |
|||
item = "Shield" |
|||
probability = 34 |
|||
|
|||
[[barrier.item]] |
|||
item = "CoreShield" |
|||
probability = 15 |
|||
|
|||
[[barrier.item]] |
|||
item = "GigaShield" |
|||
probability = 15 |
|||
|
|||
[[barrier.item]] |
|||
item = "BraveBarrier" |
|||
probability = 2 |
|||
|
|||
|
|||
[[barrier]] |
|||
level = 10 |
|||
[[barrier.item]] |
|||
item = "Barrier" |
|||
probability = 5 |
|||
|
|||
[[barrier.item]] |
|||
item = "Shield" |
|||
probability = 10 |
|||
|
|||
[[barrier.item]] |
|||
item = "CoreShield" |
|||
probability = 14 |
|||
|
|||
[[barrier.item]] |
|||
item = "GigaShield" |
|||
probability = 18 |
|||
|
|||
[[barrier.item]] |
|||
item = "SoulBarrier" |
|||
probability = 18 |
|||
|
|||
[[barrier.item]] |
|||
item = "HardShield" |
|||
probability = 14 |
|||
|
|||
[[barrier.item]] |
|||
item = "BraveBarrier" |
|||
probability = 10 |
|||
|
|||
[[barrier.item]] |
|||
item = "SolidShield" |
|||
probability = 5 |
|||
|
|||
[[barrier.item]] |
|||
item = "FlameBarrier" |
|||
probability = 2 |
|||
|
|||
[[barrier.item]] |
|||
item = "PlasmaBarrier" |
|||
probability = 2 |
|||
|
|||
[[barrier.item]] |
|||
item = "FreezeBarrier" |
|||
probability = 2 |
|||
|
|||
|
|||
[[barrier]] |
|||
level = 25 |
|||
[[barrier.item]] |
|||
item = "GigaShield" |
|||
probability = 6 |
|||
|
|||
[[barrier.item]] |
|||
item = "SoulBarrier" |
|||
probability = 10 |
|||
|
|||
[[barrier.item]] |
|||
item = "HardShield" |
|||
probability = 15 |
|||
|
|||
[[barrier.item]] |
|||
item = "BraveBarrier" |
|||
probability = 19 |
|||
|
|||
[[barrier.item]] |
|||
item = "SolidShield" |
|||
probability = 18 |
|||
|
|||
[[barrier.item]] |
|||
item = "FlameBarrier" |
|||
probability = 14 |
|||
|
|||
[[barrier.item]] |
|||
item = "PlasmaBarrier" |
|||
probability = 9 |
|||
|
|||
[[barrier.item]] |
|||
item = "FreezeBarrier" |
|||
probability = 4 |
|||
|
|||
[[barrier.item]] |
|||
item = "PsychicBarrier" |
|||
probability = 3 |
|||
|
|||
[[barrier.item]] |
|||
item = "ProtectBarrier" |
|||
probability = 2 |
|||
|
|||
|
|||
[[barrier]] |
|||
level = 42 |
|||
[[barrier.item]] |
|||
item = "SoulBarrier" |
|||
probability = 5 |
|||
|
|||
[[barrier.item]] |
|||
item = "HardShield" |
|||
probability = 5 |
|||
|
|||
[[barrier.item]] |
|||
item = "BraveBarrier" |
|||
probability = 5 |
|||
|
|||
[[barrier.item]] |
|||
item = "SolidShield" |
|||
probability = 10 |
|||
|
|||
[[barrier.item]] |
|||
item = "FlameBarrier" |
|||
probability = 14 |
|||
|
|||
[[barrier.item]] |
|||
item = "PlasmaBarrier" |
|||
probability = 15 |
|||
|
|||
[[barrier.item]] |
|||
item = "FreezeBarrier" |
|||
probability = 14 |
|||
|
|||
[[barrier.item]] |
|||
item = "PsychicBarrier" |
|||
probability = 11 |
|||
|
|||
[[barrier.item]] |
|||
item = "GeneralShield" |
|||
probability = 9 |
|||
|
|||
[[barrier.item]] |
|||
item = "ProtectBarrier" |
|||
probability = 6 |
|||
|
|||
[[barrier.item]] |
|||
item = "GloriousShield" |
|||
probability = 4 |
|||
|
|||
[[barrier.item]] |
|||
item = "GuardianShield" |
|||
probability = 2 |
|||
|
|||
|
|||
[[barrier]] |
|||
level = 60 |
|||
[[barrier.item]] |
|||
item = "HardShield" |
|||
probability = 4 |
|||
|
|||
[[barrier.item]] |
|||
item = "BraveBarrier" |
|||
probability = 5 |
|||
|
|||
[[barrier.item]] |
|||
item = "SolidShield" |
|||
probability = 5 |
|||
|
|||
[[barrier.item]] |
|||
item = "FlameBarrier" |
|||
probability = 8 |
|||
|
|||
[[barrier.item]] |
|||
item = "PlasmaBarrier" |
|||
probability = 11 |
|||
|
|||
[[barrier.item]] |
|||
item = "FreezeBarrier" |
|||
probability = 13 |
|||
|
|||
[[barrier.item]] |
|||
item = "PsychicBarrier" |
|||
probability = 13 |
|||
|
|||
[[barrier.item]] |
|||
item = "GeneralShield" |
|||
probability = 14 |
|||
|
|||
[[barrier.item]] |
|||
item = "ProtectBarrier" |
|||
probability = 14 |
|||
|
|||
[[barrier.item]] |
|||
item = "GloriousShield" |
|||
probability = 9 |
|||
|
|||
[[barrier.item]] |
|||
item = "ImperialBarrier" |
|||
probability = 2 |
|||
|
|||
[[barrier.item]] |
|||
item = "GuardianShield" |
|||
probability = 1 |
|||
|
|||
[[barrier.item]] |
|||
item = "DivinityBarrier" |
|||
probability = 1 |
|||
|
|||
|
@ -0,0 +1,251 @@ |
|||
[[frame]] |
|||
level = 0 |
|||
[[frame.item]] |
|||
item = "Frame" |
|||
probability = 33 |
|||
|
|||
[[frame.item]] |
|||
item = "Armor" |
|||
probability = 33 |
|||
|
|||
[[frame.item]] |
|||
item = "PsyArmor" |
|||
probability = 15 |
|||
|
|||
[[frame.item]] |
|||
item = "GigaFrame" |
|||
probability = 10 |
|||
|
|||
[[frame.item]] |
|||
item = "SoulFrame" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "SolidFrame" |
|||
probability = 4 |
|||
|
|||
|
|||
[[frame]] |
|||
level = 10 |
|||
[[frame.item]] |
|||
item = "Frame" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "Armor" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "PsyArmor" |
|||
probability = 10 |
|||
|
|||
[[frame.item]] |
|||
item = "GigaFrame" |
|||
probability = 15 |
|||
|
|||
[[frame.item]] |
|||
item = "SoulFrame" |
|||
probability = 19 |
|||
|
|||
[[frame.item]] |
|||
item = "CrossArmor" |
|||
probability = 19 |
|||
|
|||
[[frame.item]] |
|||
item = "SolidFrame" |
|||
probability = 10 |
|||
|
|||
[[frame.item]] |
|||
item = "BraveArmor" |
|||
probability = 10 |
|||
|
|||
[[frame.item]] |
|||
item = "HyperFrame" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "KingsFrame" |
|||
probability = 2 |
|||
|
|||
|
|||
[[frame]] |
|||
level = 25 |
|||
[[frame.item]] |
|||
item = "SoulFrame" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "CrossArmor" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "SolidFrame" |
|||
probability = 10 |
|||
|
|||
[[frame.item]] |
|||
item = "BraveArmor" |
|||
probability = 15 |
|||
|
|||
[[frame.item]] |
|||
item = "HyperFrame" |
|||
probability = 19 |
|||
|
|||
[[frame.item]] |
|||
item = "GrandArmor" |
|||
probability = 19 |
|||
|
|||
[[frame.item]] |
|||
item = "ShockFrame" |
|||
probability = 10 |
|||
|
|||
[[frame.item]] |
|||
item = "KingsFrame" |
|||
probability = 10 |
|||
|
|||
[[frame.item]] |
|||
item = "DragonFrame" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "GeneralArmor" |
|||
probability = 2 |
|||
|
|||
|
|||
[[frame]] |
|||
level = 42 |
|||
[[frame.item]] |
|||
item = "SolidFrame" |
|||
probability = 2 |
|||
|
|||
[[frame.item]] |
|||
item = "BraveArmor" |
|||
probability = 4 |
|||
|
|||
[[frame.item]] |
|||
item = "HyperFrame" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "GrandArmor" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "ShockFrame" |
|||
probability = 10 |
|||
|
|||
[[frame.item]] |
|||
item = "KingsFrame" |
|||
probability = 12 |
|||
|
|||
[[frame.item]] |
|||
item = "DragonFrame" |
|||
probability = 14 |
|||
|
|||
[[frame.item]] |
|||
item = "AbsorbArmor" |
|||
probability = 14 |
|||
|
|||
[[frame.item]] |
|||
item = "ProtectFrame" |
|||
probability = 10 |
|||
|
|||
[[frame.item]] |
|||
item = "GeneralArmor" |
|||
probability = 9 |
|||
|
|||
[[frame.item]] |
|||
item = "PerfectFrame" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "ValiantFrame" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "ImperialArmor" |
|||
probability = 3 |
|||
|
|||
[[frame.item]] |
|||
item = "HolinessArmor" |
|||
probability = 2 |
|||
|
|||
|
|||
[[frame]] |
|||
level = 60 |
|||
[[frame.item]] |
|||
item = "BraveArmor" |
|||
probability = 2 |
|||
|
|||
[[frame.item]] |
|||
item = "HyperFrame" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "GrandArmor" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "ShockFrame" |
|||
probability = 5 |
|||
|
|||
[[frame.item]] |
|||
item = "KingsFrame" |
|||
probability = 6 |
|||
|
|||
[[frame.item]] |
|||
item = "DragonFrame" |
|||
probability = 10 |
|||
|
|||
[[frame.item]] |
|||
item = "AbsorbArmor" |
|||
probability = 13 |
|||
|
|||
[[frame.item]] |
|||
item = "ProtectFrame" |
|||
probability = 14 |
|||
|
|||
[[frame.item]] |
|||
item = "GeneralArmor" |
|||
probability = 14 |
|||
|
|||
[[frame.item]] |
|||
item = "PerfectFrame" |
|||
probability = 14 |
|||
|
|||
[[frame.item]] |
|||
item = "ValiantFrame" |
|||
probability = 7 |
|||
|
|||
[[frame.item]] |
|||
item = "ImperialArmor" |
|||
probability = 3 |
|||
|
|||
[[frame.item]] |
|||
item = "HolinessArmor" |
|||
probability = 1 |
|||
|
|||
[[frame.item]] |
|||
item = "GuardianArmor" |
|||
probability = 1 |
|||
|
|||
|
|||
[[slot_rate]] |
|||
slot = 0 |
|||
probability = 75 |
|||
|
|||
[[slot_rate]] |
|||
slot = 1 |
|||
probability = 18 |
|||
|
|||
[[slot_rate]] |
|||
slot = 2 |
|||
probability = 6 |
|||
|
|||
[[slot_rate]] |
|||
slot = 3 |
|||
probability = 1 |
|||
|
|||
[[slot_rate]] |
|||
slot = 4 |
|||
probability = 0 |
|||
|
@ -0,0 +1,300 @@ |
|||
[[unit]] |
|||
level = 10 |
|||
[[unit.item]] |
|||
item = "KnightPower" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "PriestMind" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "MarksmanArm" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "ThiefLegs" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "DiggerHp" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "WarriorBody" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistFire" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistCold" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistShock" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistLight" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistDark" |
|||
probability = 5 |
|||
|
|||
|
|||
[[unit]] |
|||
level = 25 |
|||
[[unit.item]] |
|||
item = "KnightPower" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "PriestMind" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "MarksmanArm" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "ThiefLegs" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "DiggerHp" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "WarriorBody" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistFire" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistCold" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistShock" |
|||
probability = 10 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistLight" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistDark" |
|||
probability = 5 |
|||
|
|||
|
|||
[[unit]] |
|||
level = 42 |
|||
[[unit.item]] |
|||
item = "KnightPower" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "PriestMind" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "MarksmanArm" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "ThiefLegs" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "DiggerHp" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "WarriorBody" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistFire" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistCold" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistShock" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistLight" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistDark" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "GeneralPower" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "GeneralMind" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "GeneralArm" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "GeneralLegs" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "GeneralHp" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "GeneralBody" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistFlame" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistFreeze" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistThunder" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistSaint" |
|||
probability = 3 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistEvil" |
|||
probability = 3 |
|||
|
|||
[[unit.item]] |
|||
item = "HpRestorate" |
|||
probability = 1 |
|||
|
|||
[[unit.item]] |
|||
item = "TpRestorate" |
|||
probability = 1 |
|||
|
|||
[[unit.item]] |
|||
item = "PbAmplifier" |
|||
probability = 1 |
|||
|
|||
|
|||
[[unit]] |
|||
level = 60 |
|||
[[unit.item]] |
|||
item = "KnightPower" |
|||
probability = 3 |
|||
|
|||
[[unit.item]] |
|||
item = "PriestMind" |
|||
probability = 3 |
|||
|
|||
[[unit.item]] |
|||
item = "MarksmanArm" |
|||
probability = 3 |
|||
|
|||
[[unit.item]] |
|||
item = "ThiefLegs" |
|||
probability = 3 |
|||
|
|||
[[unit.item]] |
|||
item = "DiggerHp" |
|||
probability = 3 |
|||
|
|||
[[unit.item]] |
|||
item = "WarriorBody" |
|||
probability = 3 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistFire" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistCold" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistShock" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistLight" |
|||
probability = 4 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistDark" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "GeneralPower" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "GeneralMind" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "GeneralArm" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "GeneralLegs" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "GeneralHp" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "GeneralBody" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistFlame" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistFreeze" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistThunder" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistSaint" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "ResistEvil" |
|||
probability = 5 |
|||
|
|||
[[unit.item]] |
|||
item = "HpRestorate" |
|||
probability = 2 |
|||
|
|||
[[unit.item]] |
|||
item = "TpRestorate" |
|||
probability = 2 |
|||
|
|||
[[unit.item]] |
|||
item = "PbAmplifier" |
|||
probability = 2 |
|||
|
|||
|
@ -0,0 +1,259 @@ |
|||
use std::collections::HashMap;
|
|||
use std::fs::File;
|
|||
use std::io::Read;
|
|||
use std::path::PathBuf;
|
|||
use serde::Deserialize;
|
|||
use rand::{Rng, SeedableRng};
|
|||
use rand::distributions::{WeightedIndex, Distribution};
|
|||
use rand::seq::{SliceRandom, IteratorRandom};
|
|||
use crate::entity::character::SectionID;
|
|||
use crate::ship::room::Difficulty;
|
|||
use crate::entity::item::armor::ArmorType;
|
|||
use crate::entity::item::shield::ShieldType;
|
|||
use crate::entity::item::unit::UnitType;
|
|||
|
|||
|
|||
enum ShopArmor {
|
|||
Frame(ArmorType, usize),
|
|||
Barrier(ShieldType),
|
|||
Unit(UnitType),
|
|||
}
|
|||
|
|||
|
|||
|
|||
#[derive(Debug, Deserialize, Clone)]
|
|||
struct FrameTierItem {
|
|||
item: ArmorType,
|
|||
probability: usize,
|
|||
}
|
|||
|
|||
#[derive(Debug, Deserialize, Clone)]
|
|||
struct FrameTier {
|
|||
level: usize,
|
|||
item: Vec<FrameTierItem>,
|
|||
}
|
|||
|
|||
#[derive(Debug, Deserialize)]
|
|||
struct SlotRate {
|
|||
slot: usize,
|
|||
probability: usize,
|
|||
}
|
|||
|
|||
#[derive(Debug, Deserialize)]
|
|||
struct FrameTable {
|
|||
frame: Vec<FrameTier>,
|
|||
slot_rate: Vec<SlotRate>,
|
|||
}
|
|||
|
|||
|
|||
#[derive(Debug, Deserialize, Clone)]
|
|||
struct BarrierTierItem {
|
|||
item: ShieldType,
|
|||
probability: usize,
|
|||
}
|
|||
|
|||
#[derive(Debug, Deserialize, Clone)]
|
|||
struct BarrierTier {
|
|||
level: usize,
|
|||
item: Vec<BarrierTierItem>,
|
|||
}
|
|||
|
|||
#[derive(Debug, Deserialize)]
|
|||
struct BarrierTable {
|
|||
barrier: Vec<BarrierTier>,
|
|||
}
|
|||
|
|||
#[derive(Debug, Deserialize, Clone)]
|
|||
struct UnitTierItem {
|
|||
item: UnitType,
|
|||
probability: usize,
|
|||
}
|
|||
|
|||
#[derive(Debug, Deserialize, Clone)]
|
|||
struct UnitTier {
|
|||
level: usize,
|
|||
item: Vec<UnitTierItem>,
|
|||
}
|
|||
|
|||
#[derive(Debug, Deserialize)]
|
|||
struct UnitTable {
|
|||
unit: Vec<UnitTier>,
|
|||
}
|
|||
|
|||
|
|||
|
|||
fn load_frame_table() -> FrameTable {
|
|||
let path = PathBuf::from("data/shops/frame.toml");
|
|||
let mut f = File::open(path).unwrap();
|
|||
let mut s = String::new();
|
|||
f.read_to_string(&mut s).unwrap();
|
|||
|
|||
let table: FrameTable = toml::from_str(s.as_str()).unwrap();
|
|||
table
|
|||
}
|
|||
|
|||
fn load_barrier_table() -> BarrierTable {
|
|||
let path = PathBuf::from("data/shops/barrier.toml");
|
|||
let mut f = File::open(path).unwrap();
|
|||
let mut s = String::new();
|
|||
f.read_to_string(&mut s).unwrap();
|
|||
|
|||
let table: BarrierTable = toml::from_str(s.as_str()).unwrap();
|
|||
table
|
|||
}
|
|||
|
|||
fn load_unit_table() -> UnitTable {
|
|||
let path = PathBuf::from("data/shops/unit.toml");
|
|||
let mut f = File::open(path).unwrap();
|
|||
let mut s = String::new();
|
|||
f.read_to_string(&mut s).unwrap();
|
|||
|
|||
let table: UnitTable = toml::from_str(s.as_str()).unwrap();
|
|||
table
|
|||
}
|
|||
|
|||
|
|||
fn number_of_frames_to_generate(character_level: usize) -> usize {
|
|||
if character_level <= 10 {
|
|||
4
|
|||
}
|
|||
else if character_level <= 25 {
|
|||
6
|
|||
}
|
|||
else if character_level <= 42 {
|
|||
7
|
|||
}
|
|||
else {
|
|||
8
|
|||
}
|
|||
}
|
|||
|
|||
fn number_of_barriers_to_generate(character_level: usize) -> usize {
|
|||
if character_level <= 10 {
|
|||
4
|
|||
}
|
|||
else if character_level <= 25 {
|
|||
5
|
|||
}
|
|||
else if character_level <= 42 {
|
|||
6
|
|||
}
|
|||
else {
|
|||
7
|
|||
}
|
|||
}
|
|||
|
|||
fn number_of_units_to_generate(character_level: usize) -> usize {
|
|||
if character_level <= 10 {
|
|||
0
|
|||
}
|
|||
else if character_level <= 25 {
|
|||
3
|
|||
}
|
|||
else if character_level <= 42 {
|
|||
5
|
|||
}
|
|||
else {
|
|||
6
|
|||
}
|
|||
}
|
|||
|
|||
#[derive(Debug)]
|
|||
struct ArmorShop<R: Rng + SeedableRng> {
|
|||
frame: FrameTable,
|
|||
barrier: BarrierTable,
|
|||
unit: UnitTable,
|
|||
rng: R,
|
|||
}
|
|||
|
|||
impl<R: Rng + SeedableRng> ArmorShop<R> {
|
|||
pub fn new() -> ArmorShop<R> {
|
|||
ArmorShop {
|
|||
frame: load_frame_table(),
|
|||
barrier: load_barrier_table(),
|
|||
unit: load_unit_table(),
|
|||
rng: R::from_entropy(),
|
|||
}
|
|||
}
|
|||
|
|||
fn generate_frame_list(&mut self, character_level: usize) -> Vec<ShopArmor> {
|
|||
let tier = self.frame.frame.iter()
|
|||
.filter(|t| t.level <= character_level)
|
|||
.last()
|
|||
.cloned()
|
|||
.unwrap();
|
|||
|
|||
let frame_choice = WeightedIndex::new(tier.item.iter().map(|f| f.probability)).unwrap();
|
|||
let slot_choice = WeightedIndex::new(self.frame.slot_rate.iter().map(|sr| sr.probability)).unwrap();
|
|||
(0..number_of_frames_to_generate(character_level))
|
|||
.map(|_| {
|
|||
let frame_detail = tier.item.get(frame_choice.sample(&mut self.rng)).unwrap();
|
|||
let slot = self.frame.slot_rate.get(slot_choice.sample(&mut self.rng)).unwrap();
|
|||
|
|||
ShopArmor::Frame(frame_detail.item, slot.slot)
|
|||
})
|
|||
.collect()
|
|||
}
|
|||
|
|||
fn generate_barrier_list(&mut self, character_level: usize) -> Vec<ShopArmor> {
|
|||
let tier = self.barrier.barrier.iter()
|
|||
.filter(|t| t.level <= character_level)
|
|||
.last()
|
|||
.cloned()
|
|||
.unwrap();
|
|||
|
|||
let barrier_choice = WeightedIndex::new(tier.item.iter().map(|b| b.probability)).unwrap();
|
|||
(0..number_of_barriers_to_generate(character_level))
|
|||
.map(|_| {
|
|||
let barrier_detail = tier.item.get(barrier_choice.sample(&mut self.rng)).unwrap();
|
|||
|
|||
ShopArmor::Barrier(barrier_detail.item)
|
|||
})
|
|||
.collect()
|
|||
}
|
|||
|
|||
fn generate_unit_list(&mut self, character_level: usize) -> Vec<ShopArmor> {
|
|||
self.unit.unit.iter()
|
|||
.filter(|t| t.level <= character_level)
|
|||
.last()
|
|||
.cloned()
|
|||
.map(|tier| {
|
|||
let unit_choice = WeightedIndex::new(tier.item.iter().map(|u| u.probability)).unwrap();
|
|||
(0..number_of_units_to_generate(character_level))
|
|||
.map(|_| {
|
|||
let unit_detail = tier.item.get(unit_choice.sample(&mut self.rng)).unwrap();
|
|||
|
|||
ShopArmor::Unit(unit_detail.item)
|
|||
})
|
|||
.collect()
|
|||
})
|
|||
.unwrap_or(Vec::new())
|
|||
}
|
|||
|
|||
pub fn generate_armor_list(&mut self, character_level: usize) -> Vec<ShopArmor> {
|
|||
self.generate_frame_list(character_level).into_iter()
|
|||
.chain(self.generate_barrier_list(character_level).into_iter())
|
|||
.chain(self.generate_unit_list(character_level).into_iter())
|
|||
.collect()
|
|||
}
|
|||
}
|
|||
|
|||
|
|||
|
|||
#[cfg(test)]
|
|||
mod test {
|
|||
use super::*;
|
|||
|
|||
#[test]
|
|||
fn test_loading_tool_shop() {
|
|||
ArmorShop::<rand_chacha::ChaCha20Rng>::new();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_generating_some_armor() {
|
|||
let mut fs = ArmorShop::<rand_chacha::ChaCha20Rng>::new();
|
|||
for i in 0..200 {
|
|||
fs.generate_armor_list(i);
|
|||
}
|
|||
}
|
|||
}
|
@ -1,2 +1,3 @@ |
|||
pub mod weapon;
|
|||
pub mod tool;
|
|||
pub mod armor;
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue