generated upgrades and bars
This commit is contained in:
parent
e07fac4211
commit
74d146242b
4 changed files with 155 additions and 169 deletions
189
src/unlocks.rs
189
src/unlocks.rs
|
|
@ -1,18 +1,20 @@
|
|||
use crate::Currency;
|
||||
use crate::game::{Game, State};
|
||||
use std::collections::VecDeque;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::fmt::{Debug, Formatter, format};
|
||||
use std::ops::Mul;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct UnlockSystem {
|
||||
bought: usize,
|
||||
last_unlock: Option<String>,
|
||||
unlock_queue: VecDeque<Unlock>,
|
||||
}
|
||||
|
||||
pub(crate) struct Unlock {
|
||||
pub(crate) name: &'static str,
|
||||
pub(crate) name: String,
|
||||
pub(crate) cost: Currency,
|
||||
pub(crate) apply: fn(&mut State),
|
||||
pub(crate) apply: Box<dyn Fn(&mut State)>,
|
||||
}
|
||||
|
||||
impl Debug for Unlock {
|
||||
|
|
@ -25,124 +27,68 @@ impl Debug for Unlock {
|
|||
}
|
||||
|
||||
impl UnlockSystem {
|
||||
pub(crate) fn new() -> Self {
|
||||
pub(crate) fn new(start_state: &State) -> Self {
|
||||
let mut upgrades = start_state
|
||||
.bars
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(index, bar)| {
|
||||
let initial_cost = 10usize.pow(index as u32);
|
||||
[
|
||||
Unlock {
|
||||
name: format!("Start {}", bar.name()),
|
||||
cost: initial_cost as f64,
|
||||
apply: Box::new(move |game| {
|
||||
game.bars[index].enabled = true;
|
||||
}),
|
||||
},
|
||||
Unlock {
|
||||
name: format!("{} productivity", bar.name()),
|
||||
cost: initial_cost.mul(2) as f64,
|
||||
apply: Box::new(move |game| {
|
||||
game.bars[index].productivity *= 2.0;
|
||||
}),
|
||||
},
|
||||
Unlock {
|
||||
name: format!("{} speed", bar.name()),
|
||||
cost: initial_cost.mul(20) as f64,
|
||||
apply: Box::new(move |game| {
|
||||
game.bars[index].speed *= 1.5;
|
||||
}),
|
||||
},
|
||||
]
|
||||
})
|
||||
.chain(
|
||||
(1..10).map(|level|
|
||||
Unlock {
|
||||
name: format!("The answer {}", level),
|
||||
cost: (42usize * 10usize.pow(level)) as f64,
|
||||
apply: Box::new(move |game| {
|
||||
game.speed *= 1.1;
|
||||
}),
|
||||
}
|
||||
)
|
||||
)
|
||||
.chain(
|
||||
(1..10).map(|level|
|
||||
Unlock {
|
||||
name: format!("??? {}", level),
|
||||
cost: (23usize * 10usize.pow(level)) as f64,
|
||||
apply: Box::new(move |game| {
|
||||
game.productivity *= 1.1;
|
||||
}),
|
||||
},
|
||||
)
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
upgrades.sort_by(|l, r| l.cost.total_cmp(&r.cost));
|
||||
|
||||
let unlock_queue = upgrades.into();
|
||||
|
||||
Self {
|
||||
unlock_queue,
|
||||
bought: 0,
|
||||
unlock_queue: vec![
|
||||
Unlock {
|
||||
name: "Start Powering infrastructure",
|
||||
cost: 0f64,
|
||||
apply: |game| {
|
||||
game.bars[0].enabled = true;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "More power",
|
||||
cost: 10f64,
|
||||
apply: |game| {
|
||||
game.bars[0].productivity *= 2.0;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "",
|
||||
cost: 23f64,
|
||||
apply: |game| {
|
||||
game.productivity *= 1.1;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "The answer",
|
||||
cost: 42f64,
|
||||
apply: |game| {
|
||||
game.speed *= 1.1;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "Start Dusting ServicePoint",
|
||||
cost: 64f64,
|
||||
apply: |game| {
|
||||
game.bars[1].enabled = true;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "Dust filters",
|
||||
cost: 100f64,
|
||||
apply: |game| {
|
||||
game.bars[1].productivity *= 2.0;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "HASS automation",
|
||||
cost: 128f64,
|
||||
apply: |game| {
|
||||
game.bars[0].speed *= 1.5;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "Start Activating colorful lights",
|
||||
cost: 256f64,
|
||||
apply: |game| {
|
||||
game.bars[2].enabled = true;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "Start Dimming darkroom",
|
||||
cost: 1024f64,
|
||||
apply: |game| {
|
||||
game.bars[3].enabled = true;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "Start Refilling Matemat",
|
||||
cost: 4096f64,
|
||||
apply: |game| {
|
||||
game.bars[4].enabled = true;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "Start Pre-heating convectiomat",
|
||||
cost: 16384f64,
|
||||
apply: |game| {
|
||||
game.bars[5].enabled = true;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "Start Resetting chair heights",
|
||||
cost: 65536f64,
|
||||
apply: |game| {
|
||||
game.bars[6].enabled = true;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "Start Untangling 'block chain'",
|
||||
cost: 262144f64,
|
||||
apply: |game| {
|
||||
game.bars[7].enabled = true;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "Start Refilling sticker box",
|
||||
cost: 1048576f64,
|
||||
apply: |game| {
|
||||
game.bars[8].enabled = true;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "Start Setting room to public",
|
||||
cost: 4194304f64,
|
||||
apply: |game| {
|
||||
game.bars[9].enabled = true;
|
||||
},
|
||||
},
|
||||
Unlock {
|
||||
name: "Start Welcoming creatures",
|
||||
cost: 16777216f64,
|
||||
apply: |game| {
|
||||
game.bars[10].enabled = true;
|
||||
},
|
||||
},
|
||||
]
|
||||
.into(),
|
||||
last_unlock: None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,6 +103,7 @@ impl UnlockSystem {
|
|||
let next_upgrade = self.unlock_queue.pop_front().unwrap();
|
||||
state.currency -= next_upgrade.cost;
|
||||
(next_upgrade.apply)(state);
|
||||
self.last_unlock = Some(next_upgrade.name);
|
||||
self.bought += 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -165,4 +112,8 @@ impl UnlockSystem {
|
|||
pub(crate) fn bought(&self) -> usize {
|
||||
self.bought
|
||||
}
|
||||
|
||||
pub(crate) fn previous(&self) -> Option<&String> {
|
||||
self.last_unlock.as_ref()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue