Skip to content

Commit 5fbfddd

Browse files
author
geno
committed
Add buy max commands
Tweak the incrementing rate. Update UI for buy max.
1 parent 0db273c commit 5fbfddd

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

src/commands.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ pub fn read_inputs(
121121
// Purchase notification updates
122122
for (k, p) in upgrades.iter() {
123123
let t: DateTime<Local> = Local::now();
124+
125+
// Skip if nothing was purchased
126+
if p.cost == 0 {
127+
continue;
128+
}
129+
124130
match k {
125131
PurchaseType::Boost => msg.insert(
126132
0,
@@ -174,6 +180,12 @@ pub fn boost_cost(cps: u64) -> u64 {
174180
1u64.checked_shl(v).unwrap_or(0)
175181
}
176182

183+
pub fn boost_max_cost(cps: u64, boost: u64) -> u64 {
184+
let cost = boost_cost(cps);
185+
let left = (u16::MAX as u64 - boost) / 128;
186+
cost * left
187+
}
188+
177189
fn buy_boost(
178190
connection: &mut Connection,
179191
wallet: &mut Wallet,
@@ -184,7 +196,7 @@ fn buy_boost(
184196
"You need at least 1024 Cps to be able to purchase boost\n",
185197
));
186198
}
187-
if connection.miner.boost > u16::MAX as u64 {
199+
if connection.miner.boost >= u16::MAX as u64 - 128 {
188200
return Err(Error::new(
189201
ErrorKind::InvalidData,
190202
"You cannot purchase any more boost right now\n",
@@ -199,6 +211,9 @@ fn buy_boost(
199211
}
200212
let bought: usize = 128;
201213
connection.miner.boost = connection.miner.boost.saturating_add(bought as u64);
214+
if connection.miner.boost > u16::MAX as u64 {
215+
connection.miner.boost = u16::MAX as u64;
216+
}
202217

203218
Ok((
204219
PurchaseType::Boost,
@@ -233,6 +248,20 @@ pub fn miner_cost(max_miners: u64) -> u64 {
233248
}
234249
}
235250

251+
pub fn miner_max_cost(max_miners: u64) -> u128 {
252+
let mut max = max_miners;
253+
let mut cost = 0u128;
254+
loop {
255+
if max <= ABS_MAX_MINERS {
256+
cost += miner_cost(max) as u128;
257+
max += 1;
258+
} else {
259+
break;
260+
}
261+
}
262+
cost
263+
}
264+
236265
fn buy_miner(mut wallet: &mut Wallet) -> Result<(PurchaseType, Purchase), Error> {
237266
if wallet.max_miners >= ABS_MAX_MINERS {
238267
return Err(Error::new(
@@ -276,6 +305,10 @@ pub fn time_cost() -> u64 {
276305
1000
277306
}
278307

308+
pub fn time_max_cost(chrono: u64) -> u64 {
309+
(chrono / 1000) * 1000
310+
}
311+
279312
fn buy_time(
280313
connection: &mut Connection,
281314
wallet: &mut Wallet,
@@ -287,8 +320,7 @@ fn buy_time(
287320
));
288321
}
289322

290-
let bought = 60 * 60;
291-
let mut c = bought;
323+
let mut c = 60 * 60;
292324
loop {
293325
miner_session(&mut connection.miner);
294326
c -= 1;
@@ -300,7 +332,7 @@ fn buy_time(
300332
Ok((
301333
PurchaseType::Chrono,
302334
Purchase {
303-
bought,
335+
bought: 1,
304336
cost: time_cost() as u128,
305337
},
306338
))

src/main.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,11 @@ fn print_wallets(
395395
if c.miner.cps > 1024 {
396396
c.purchases.push(
397397
format!(
398-
"'b'<enter>\tPurchase 128 seconds of Miner Boost for {} idlecoin\n",
399-
commands::boost_cost(c.miner.cps)
398+
"{}b{}: Purchase 128 seconds of Miner Boost for {} idlecoin / {}B{}: Purchase Max for {} idlecoin\n",
399+
RED, RST,
400+
commands::boost_cost(c.miner.cps),
401+
RED, RST,
402+
commands::boost_max_cost(c.miner.cps, c.miner.boost),
400403
)
401404
.to_string(),
402405
);
@@ -405,13 +408,13 @@ fn print_wallets(
405408
if g.max_miners < ABS_MAX_MINERS && (g.idlecoin > miner_cost || g.supercoin > 1)
406409
{
407410
c.purchases.push(format!(
408-
"'m'<enter>\tPurchase 1 Miner License for {} idlecoin\n",
409-
miner_cost
411+
"{}m{}: Purchase 1 Miner License for {} idlecoin\n",
412+
RED, RST, miner_cost
410413
));
411414
}
412415
}
413416
if g.chronocoin > commands::time_cost() {
414-
c.purchases.push(format!("'c'<enter>\tPurchase 60m of time travel for this miner for {} chronocoins\n", commands::time_cost()));
417+
c.purchases.push(format!("{}c{}: Purchase 1 hour of time travel for this miner for {} chronocoin / {}C{}: Purchase Max for {} chronocoin\n", RED, RST,commands::time_cost(), RED, RST,commands::time_max_cost(g.chronocoin)));
415418
}
416419

417420
// Build miner display

src/miner.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ pub fn miner_session(mut miner: &mut Miner) {
166166
}
167167

168168
// Increment cps
169-
let increase = if miner.boost > 0 {
169+
miner.inc = if miner.boost > 0 {
170170
miner.boost -= 1;
171-
(miner.inc + miner.level) * 3
171+
miner.inc.saturating_add(miner.level * 3)
172172
} else {
173-
miner.inc + miner.level
173+
miner.inc.saturating_add(miner.level)
174174
};
175-
miner.cps = miner.cps.saturating_add(increase);
175+
miner.cps = miner.cps.saturating_add(miner.inc);
176176
}

0 commit comments

Comments
 (0)