1 use std::io;
2 use rand::Rng;
3 use std::{thread, time};
4
5 //////////
6 // Objects
7 //////////
8
9 struct Market {
10 // Store current values of drugs on the market
11 weed_min: u32,
12 weed_max: u32,
13 cocaine_min: u32,
14 cocaine_max: u32,
15 heroin_min: u32,
16 heroin_max: u32,
17 acid_min: u32,
18 acid_max: u32,
19 xtc_min: u32,
20 xtc_max: u32,
21 ludes_min: u32,
22 ludes_max: u32,
23 weed: u32,
24 cocaine: u32,
25 heroin: u32,
26 acid: u32,
27 xtc: u32,
28 ludes: u32,
29 }
30
31 // Market::new(100,600,18000,28000,3000,10000,700,2000,120,500,15,200,0,0,0,0,0,0)
32
33 impl Market {
34 pub fn new(weed_min: u32, weed_max: u32, cocaine_min: u32, cocaine_max: u32, heroin_min: u32, heroin_max: u32, acid_min: u32, acid_max: u32, xtc_min: u32, xtc_max: u32, ludes_min: u32, ludes_max: u32, weed: u32, cocaine: u32, heroin: u32, acid: u32, xtc: u32, ludes: u32) -> Self {
35 Market { weed_min, weed_max, cocaine_min, cocaine_max, heroin_min, heroin_max, acid_min, acid_max, xtc_min, xtc_max, ludes_min, ludes_max, weed, cocaine, heroin, acid, xtc, ludes }
36 }
37
38 // This is normal market fluctuation when moving locations, as opposed to an event that drives prices up/down
39 pub fn change_prices(&mut self) {
40
41 let mut rng = rand::thread_rng();
42 let weed_diff = rng.gen_range(self.weed_min,self.weed_max);
43 let cocaine_diff = rng.gen_range(self.cocaine_min,self.cocaine_max);
44 let heroin_diff = rng.gen_range(self.heroin_min,self.heroin_max);
45 let acid_diff = rng.gen_range(self.acid_min,self.acid_max);
46 let xtc_diff = rng.gen_range(self.xtc_min,self.xtc_max);
47 let ludes_diff = rng.gen_range(self.ludes_min,self.ludes_max);
48
49 self.weed = weed_diff;
50 self.cocaine = cocaine_diff;
51 self.heroin = heroin_diff;
52 self.acid = acid_diff;
53 self.xtc = xtc_diff;
54 self.ludes = ludes_diff;
55
56 }
57
58 pub fn dump(&self) {
59 println!("Prices\nWeed: ${}\tCocaine: ${}\nHeroin: ${}\tAcid: ${}\nXTC: ${}\tLudes: ${}\n", self.weed, self.cocaine, self.heroin, self.acid, self.xtc, self.ludes);
60 }
61
62 pub fn set_price(&mut self, drug_to_set: &String, price_to_set: u32) {
63 match drug_to_set.as_ref() {
64 "weed" => self.weed = price_to_set,
65 "cocaine" => self.cocaine = price_to_set,
66 "heroin" => self.heroin = price_to_set,
67 "acid" => self.acid = price_to_set,
68 "xtc" => self.xtc = price_to_set,
69 "ludes" => self.ludes = price_to_set,
70 _ => panic!("Market::set_price got a drug_to_set value that doesn't make sense"),
71 }
72 }
73
74 pub fn get_current_price(&self, drug_to_get: &String) -> u32 {
75 let current_price: u32;
76 match drug_to_get.as_ref() {
77 "weed" => current_price = self.weed,
78 "cocaine" => current_price = self.cocaine,
79 "heroin" => current_price = self.heroin,
80 "acid" => current_price = self.acid,
81 "xtc" => current_price = self.xtc,
82 "ludes" => current_price = self.ludes,
83 _ => panic!("Market::get_current_price got a drug_to_get value that doesn't make sense"),
84 }
85
86 return current_price;
87 }
88
89 pub fn get_min_price(&self, drug_to_get: &String) -> u32 {
90 let min_price: u32;
91 match drug_to_get.as_ref() {
92 "weed" => min_price = self.weed_min,
93 "cocaine" => min_price = self.cocaine_min,
94 "heroin" => min_price = self.heroin_min,
95 "acid" => min_price = self.acid_min,
96 "xtc" => min_price = self.xtc_min,
97 "ludes" => min_price = self.ludes_min,
98 _ => panic!("Market::get_min_price got a drug_to_get value that doesn't make sense"),
99 }
100
101 return min_price;
102 }
103
104 pub fn get_max_price(&self, drug_to_get: &String) -> u32 {
105 let max_price: u32;
106 match drug_to_get.as_ref() {
107 "weed" => max_price = self.weed_max,
108 "cocaine" => max_price = self.cocaine_max,
109 "heroin" => max_price = self.heroin_max,
110 "acid" => max_price = self.acid_max,
111 "xtc" => max_price = self.xtc_max,
112 "ludes" => max_price = self.ludes_max,
113 _ => panic!("Market::get_min_price got a drug_to_get value that doesn't make sense"),
114 }
115
116 return max_price;
117 }
118 }
119
120 struct HeadStash {
121 weed: u32,
122 cocaine: u32,
123 heroin: u32,
124 acid: u32,
125 xtc: u32,
126 ludes: u32,
127 money: u32,
128 }
129
130 impl HeadStash {
131
132 pub fn new(weed: u32, cocaine: u32, heroin: u32, acid: u32, xtc: u32, ludes: u32, money: u32) -> Self {
133 HeadStash { weed, cocaine, heroin, acid, xtc, ludes, money }
134 }
135
136 pub fn dump(&self) {
137 println!("You've got ${} in your head stash",self.money);
138 println!("You're head stash has:\nWeed: {} Cocaine: {}\nHeroin: {} Acid: {}\nXTC: {} Ludes: {}\n", self.weed, self.cocaine, self.heroin, self.acid, self.xtc, self.ludes);
139 }
140
141 pub fn move_drug_to_stash(&mut self, drug_to_move: &String, amount_to_move: &u32) {
142 match drug_to_move.as_ref() {
143 "weed" => self.weed += amount_to_move,
144 "cocaine" => self.cocaine += amount_to_move,
145 "heroin" => self.heroin += amount_to_move,
146 "acid" => self.acid += amount_to_move,
147 "xtc" => self.xtc += amount_to_move,
148 "ludes" => self.ludes += amount_to_move,
149 _ => panic!("move_drug_to_stash got a drug_to_move value that doesn't make sense"),
150 }
151 }
152
153 pub fn grab_from_stash(&mut self, drug_to_grab: &String, amount_to_grab: &u32) {
154 match drug_to_grab.as_ref() {
155 "weed" => self.weed -= amount_to_grab,
156 "cocaine" => self.cocaine -= amount_to_grab,
157 "heroin" => self.heroin -= amount_to_grab,
158 "acid" => self.acid -= amount_to_grab,
159 "xtc" => self.xtc -= amount_to_grab,
160 "ludes" => self.ludes -= amount_to_grab,
161 _ => panic!("sell_transaction got a drug_to_sell value that doesn't make sense"),
162 }
163 }
164
165 pub fn bank_stash(&mut self, amount_to_bank: &u32) {
166 self.money += amount_to_bank;
167 }
168
169 pub fn withdraw_stash(&mut self, amount_to_withdraw: &u32) {
170 self.money -= amount_to_withdraw;
171 }
172
173 pub fn get_head_stash_amount(&self, drug: &String) -> u32 {
174 let amount;
175 match drug.as_ref() {
176 "weed" => amount = self.weed,
177 "cocaine" => amount = self.cocaine,
178 "heroin" => amount = self.heroin,
179 "acid" => amount = self.acid,
180 "xtc" => amount = self.xtc,
181 "ludes" => amount = self.ludes,
182 _ => amount = 0,
183 }
184
185 return amount;
186 }
187
188 }
189 struct Player {
190 health: u32,
191 money: u32,
192 debt: u32,
193 weed: u32,
194 cocaine: u32,
195 heroin: u32,
196 acid: u32,
197 xtc: u32,
198 ludes: u32,
199 location: String,
200 loan_timer: u32,
201 stash_size: u32,
202 }
203
204 // TODO
205 // A lot of the functions for Player duplicate code, need to make some "generic" functions
206
207 impl Player {
208 pub fn new(health: u32, money: u32, debt: u32, weed: u32, cocaine: u32, heroin: u32, acid: u32, xtc: u32, ludes: u32, location: String, loan_timer: u32, stash_size: u32 ) -> Self {
209 Player { health, money, debt, weed, cocaine, heroin, acid, xtc, ludes, location, loan_timer, stash_size }
210 }
211
212 pub fn dump(&self) {
213 println!("Health: {}\nMoney: ${}\tDebt: ${}", self.health, self.money, self.debt);
214 println!("You're in {}\n", self.location);
215 println!("You can hold {} units in your stash",self.stash_size);
216 println!("You're holding:\nWeed: {} Cocaine: {}\nHeroin: {} Acid: {}\nXTC: {} Ludes: {}\n", self.weed, self.cocaine, self.heroin, self.acid, self.xtc, self.ludes);
217 }
218
219 pub fn change_location(&mut self, new_location: String) {
220 self.location = new_location;
221 }
222
223 pub fn get_stash_amount(&self, drug: &String) -> u32 {
224 let amount;
225 match drug.as_ref() {
226 "weed" => amount = self.weed,
227 "cocaine" => amount = self.cocaine,
228 "heroin" => amount = self.heroin,
229 "acid" => amount = self.acid,
230 "xtc" => amount = self.xtc,
231 "ludes" => amount = self.ludes,
232 _ => amount = 0,
233 }
234
235 return amount;
236 }
237
238 pub fn buy_transaction(&mut self, drug_to_buy: &String, amount_to_buy: &u32, market_price: &u32) {
239 let cost = market_price * amount_to_buy;
240 self.money -= cost;
241
242 let add_amount = amount_to_buy;
243 self.gain_drug(&drug_to_buy,&add_amount);
244 }
245
246 pub fn sell_transaction(&mut self, drug_to_sell: &String, amount_to_sell: &u32, market_price: &u32) {
247 let revenue = market_price * amount_to_sell;
248 self.lose_drug(&drug_to_sell,&amount_to_sell);
249 self.money += revenue;
250 }
251
252
253 pub fn debt_interest(&mut self) {
254 let interest_amount: u32;
255 match self.debt {
256 0 => interest_amount = 0,
257 _ => interest_amount = ( self.debt as f32 * 0.2 ) as u32,
258 }
259
260 self.debt += interest_amount;
261 }
262
263 pub fn remove_debt(&mut self, payback_amount: u32) {
264 if (self.debt as i32 - payback_amount as i32) < 0 {
265 self.money -= payback_amount;
266 self.debt = 0;
267 } else {
268 self.money -= payback_amount;
269 self.debt -= payback_amount;
270 }
271 }
272
273 pub fn borrow_from_shark(&mut self, borrow_amount: u32) {
274 self.money += borrow_amount;
275 self.debt += borrow_amount;
276 }
277
278 pub fn take_damage(&mut self, damage_amount: u32) {
279 if (self.health as i32 - damage_amount as i32) < 0 {
280 self.health = 0;
281 } else {
282 self.health -= damage_amount;
283 }
284 }
285
286 pub fn decrease_loan_timer(&mut self, timer_amount: u32) {
287 if (self.loan_timer as i32 - timer_amount as i32) < 0 {
288 self.loan_timer = 0;
289 } else {
290 self.loan_timer -= timer_amount;
291 }
292 }
293
294 pub fn increase_loan_timer(&mut self, timer_amount: u32) {
295 self.loan_timer += timer_amount;
296 }
297
298 pub fn buy_trenchcoat(&mut self, cost: u32) {
299 self.stash_size += 25;
300 self.money -= cost;
301 }
302
303 pub fn buy_body_armor(&mut self, cost: u32) {
304 self.health += 2;
305 self.money -= cost;
306 }
307
308 pub fn stash_fill(&self) -> u32 {
309 let stash_fill = self.weed + self.cocaine + self.heroin + self.xtc + self.acid + self.ludes;
310 return stash_fill;
311 }
312
313 pub fn holding(&self) -> bool {
314 if self.stash_fill() == 0 {
315 return false;
316 } else {
317 return true;
318 }
319 }
320
321 pub fn arrested(&mut self) {
322 self.money = 0;
323 self.weed = 0;
324 self.cocaine = 0;
325 self.heroin = 0;
326 self.xtc = 0;
327 self.acid = 0;
328 self.ludes = 0;
329 }
330
331 pub fn lose_money(&mut self, amount: &u32) {
332 self.money -= amount;
333 }
334
335 pub fn gain_money(&mut self, amount: &u32) {
336 self.money += amount;
337 }
338
339 pub fn lose_drug(&mut self, drug: &String, amount: &u32) {
340 match drug.as_ref() {
341 "weed" => self.weed -= amount,
342 "cocaine" => self.cocaine -= amount,
343 "heroin" => self.heroin -= amount,
344 "acid" => self.acid -= amount,
345 "xtc" => self.xtc -= amount,
346 "ludes" => self.ludes -= amount,
347 _ => panic!("lose_drug got a drug value that doesn't make sense"),
348 }
349 }
350
351 pub fn gain_drug(&mut self, drug: &String, amount: &u32) {
352 match drug.as_ref() {
353 "weed" => self.weed += amount,
354 "cocaine" => self.cocaine += amount,
355 "heroin" => self.heroin += amount,
356 "acid" => self.acid += amount,
357 "xtc" => self.xtc += amount,
358 "ludes" => self.ludes += amount,
359 _ => panic!("lose_drug got a drug value that doesn't make sense"),
360 }
361 }
362 }
363
364 ////////////////////////////////////////////////////////
365 // "Low-level" Fuctions, called by "Top-level" functions
366 ////////////////////////////////////////////////////////
367
368 fn prompt(prompt_text: String) -> io::Result<String> {
369 println!("$ {}",prompt_text);
370 let mut input = String::new();
371 std::io::stdin().read_line(&mut input)?;
372
373 let value: String = input.trim().parse().unwrap();
374 Ok(value)
375 }
376
377 // This hurts portability but works for now
378 fn clear_term() {
379
380 print!("{}[2J", 27 as char);
381
382 }
383
384 fn get_drug_market_value(drug_to_buy: &String, market: &Market) -> io::Result<u32> {
385
386 let market_value: u32;
387 match drug_to_buy.as_ref() {
388 "weed" => market_value = market.weed,
389 "cocaine" => market_value = market.cocaine,
390 "heroin" => market_value = market.heroin,
391 "acid" => market_value = market.acid,
392 "xtc" => market_value = market.xtc,
393 "ludes" => market_value = market.ludes,
394 _ => panic!("get_drug_market_value got a drug_to_buy value that doesn't make sense!"),
395 }
396
397 Ok(market_value)
398
399 }
400
401 // This is maybe stupid? Or could be more idomatic ?? TODO?
402 // This honestly might not even be needed? Don't really
403 // understand why I made this
404 // May should use match inside of let ?
405 fn get_drug_as_string(drug: &String) -> io::Result<String> {
406
407 let mut drug_as_string: String;
408 match drug.as_ref() {
409 "weed" => drug_as_string = "weed".to_string(),
410 "cocaine" => drug_as_string = "cocaine".to_string(),
411 "heroin" => drug_as_string = "heroin".to_string(),
412 "acid" => drug_as_string = "acid".to_string(),
413 "xtc" => drug_as_string = "xtc".to_string(),
414 "ludes" => drug_as_string = "ludes".to_string(),
415 _ => drug_as_string = "null".to_string(),
416 }
417
418 Ok(drug_as_string)
419
420 }
421
422 ////////////////////////////////////
423 // Events -- happen randomly in main
424 ////////////////////////////////////
425
426 fn trenchcoat_event(player: &mut Player) {
427
428 let mut relative_cost = ( player.money as f64 * 0.25 ) as u32;
429 if relative_cost < 200 {
430 relative_cost = 200;
431 }
432 println!("A guy is selling his trench count, it'll allow you to carry 25 more units, want to buy it for ${} ?", relative_cost);
433 println!("You have ${}", player.money);
434 let response = prompt("Yes/no?".to_string()).unwrap();
435 if response.contains("yes") {
436 if player.money < relative_cost {
437 println!("You cant afford this!");
438 } else {
439 player.buy_trenchcoat(relative_cost);
440 }
441 }
442
443 }
444
445 fn body_armor_event(player: &mut Player) {
446
447 let mut relative_cost = ( player.money as f64 * 0.3 ) as u32;
448 if relative_cost < 300 {
449 relative_cost = 300;
450 }
451 println!("A guy is selling some body armor, it'll increase your health by 2, want to buy it for ${} ?", relative_cost);
452 println!("You have ${}", player.money);
453 let response = prompt("Yes/no?".to_string()).unwrap();
454 if response.contains("yes") {
455 if player.money < relative_cost {
456 println!("You cant afford this!");
457 } else {
458 player.buy_body_armor(relative_cost);
459 }
460 }
461
462 }
463
464 fn cops_event(player: &mut Player) {
465
466 let one_second = time::Duration::from_secs(1);
467 if ! player.holding() {
468 println!("The cops found you, but you're not holding so it's chill.");
469 let _placeholder = prompt("".to_string());
470 } else {
471 println!("The cops found you! Run!");
472 thread::sleep(one_second);
473 let mut rng = rand::thread_rng();
474 let mut escape: u32;
475 let mut hit: u32;
476 let mut done = false;
477 while ! done {
478 escape = rng.gen_range(0,5);
479 hit = rng.gen_range(0,3);
480 if escape == 0 {
481 println!("You got away!");
482 let _placeholder = prompt("".to_string());
483 done = true;
484 } else {
485 println!("You cant get away, the cops are firing!");
486 thread::sleep(one_second);
487 if hit == 0 {
488 println!("You're hit for 4 damage!");
489 player.take_damage(4);
490 thread::sleep(one_second);
491 let arrest = rng.gen_range(0,1);
492 if arrest == 0 {
493 println!("The cops got you! They confiscate your cash and stash!");
494 player.arrested();
495 let _placeholder = prompt("".to_string());
496 done = true;
497 }
498 } else {
499 println!("They miss and you keep running!");
500 thread::sleep(one_second);
501 }
502 }
503 }
504 }
505 }
506
507 fn price_event(market: &mut Market) {
508
509 let mut rng = rand::thread_rng();
510 let raise_drop = rng.gen_range(0,2);
511 let choose_drug = rng.gen_range(0,5);
512 let drug_to_edit: String;
513 match choose_drug {
514 0 => drug_to_edit = "weed".to_string(),
515 1 => drug_to_edit = "cocaine".to_string(),
516 2 => drug_to_edit = "heroin".to_string(),
517 3 => drug_to_edit = "acid".to_string(),
518 4 => drug_to_edit = "xtc".to_string(),
519 5 => drug_to_edit = "ludes".to_string(),
520 _ => panic!("drug_to_edit match in price_drop_event got a match that doesn't make sense"),
521 }
522
523 if raise_drop == 0 {
524 // Price drop
525 println!("A new shipment has flooded the market and caused the price of {} to dive!",drug_to_edit);
526 let temp_price = (market.get_current_price(&drug_to_edit) as f64 * 0.2) as u32;
527 market.set_price(&drug_to_edit,temp_price);
528 let _placeholder = prompt("".to_string());
529 } else {
530 // Price raise
531 println!("A bust has caused the price of {} to soar!",drug_to_edit);
532 let temp_price = market.get_current_price(&drug_to_edit) + market.get_max_price(&drug_to_edit);
533 market.set_price(&drug_to_edit,temp_price);
534 let _placeholder = prompt("".to_string());
535 }
536
537 }
538
539
540 ////////////////////////////////////////
541 // "Top-level" Functions, called by main
542 ////////////////////////////////////////
543
544 fn go_to_location(player: &mut Player, market: &mut Market) {
545
546 let mut loc_loop = false;
547 while ! loc_loop {
548 let mut new_location = prompt("Select a new location, locations are\nBrooklyn Midtown Harlem CentralPark".to_string()).unwrap();
549 match new_location.as_ref() {
550 "Brooklyn" => println!("Going to Brooklyn"),
551 "Midtown" => println!("Going to Midtown"),
552 "Harlem" => println!("Going to Harlem"),
553 "CentralPark" => println!("Going to CentralPark"),
554 _ => new_location = "null".to_string(),
555 }
556
557 if new_location != "null".to_string() {
558 if new_location == player.location {
559 println!("Youre already in {}", player.location);
560 } else {
561 player.change_location(new_location);
562 market.change_prices();
563 loc_loop = true;
564 }
565 } else {
566 println!("Not a valid location, try again");
567 }
568 }
569
570 }
571
572 fn buy_drugs(player: &mut Player, market: &mut Market) {
573
574 let mut done = false;
575 let mut drug_to_buy: String = String::new();
576 while ! done {
577 drug_to_buy = prompt("What drug will you buy?".to_string()).unwrap();
578 drug_to_buy = get_drug_as_string(&drug_to_buy).unwrap();
579 if drug_to_buy != "null".to_string() {
580 done = true;
581 } else {
582 println!("Try again");
583 }
584 }
585
586 let mut done1 = false;
587 while ! done1 {
588 let drug_market_value: u32 = get_drug_market_value(&drug_to_buy, &market).unwrap();
589 let affordable_amount: u32 = (player.money / drug_market_value) as u32;
590 println!("You can afford {} {}", affordable_amount, drug_to_buy);
591 let amount_to_buy = prompt("How many will you buy?".to_string()).unwrap();
592 let amount_to_buy_int: u32 = amount_to_buy.parse().unwrap();
593 let current_stash_fill = player.stash_fill();
594 if amount_to_buy_int > affordable_amount {
595 println!("You cant afford that many");
596 } else if amount_to_buy_int > player.stash_size {
597 println!("You cant hold that much!");
598 } else if (amount_to_buy_int + current_stash_fill) > player.stash_size {
599 println!("You cant hold that much!");
600 } else {
601 println!("Buying {} {}", amount_to_buy_int, drug_to_buy);
602 player.buy_transaction(&drug_to_buy,&amount_to_buy_int,&drug_market_value);
603 done1 = true;
604 }
605 }
606 }
607
608 fn sell_drugs(player: &mut Player, market: &mut Market) {
609
610 let mut done = false;
611 let mut drug_to_sell: String = String::new();
612 while ! done {
613 drug_to_sell = prompt("What drug will you sell?".to_string()).unwrap();
614 drug_to_sell = get_drug_as_string(&drug_to_sell).unwrap();
615 if drug_to_sell != "null".to_string() {
616 done = true;
617 } else {
618 println!("Try again");
619 }
620 }
621
622 let mut done1 = false;
623 let mut amount_to_sell: String;
624 while ! done1 {
625 amount_to_sell = prompt("How many to sell?".to_string()).unwrap();
626 let amount_to_sell_int: u32 = amount_to_sell.parse().unwrap();
627 let drug_market_value: u32 = get_drug_market_value(&drug_to_sell, &market).unwrap();
628 let amount_possible_to_sell: u32 = player.get_stash_amount(&drug_to_sell);
629 if amount_to_sell_int > amount_possible_to_sell {
630 println!("You don't have that many {}, try again", drug_to_sell);
631 } else {
632 println!("Selling {} {}", amount_to_sell_int, drug_to_sell);
633 player.sell_transaction(&drug_to_sell,&amount_to_sell_int,&drug_market_value);
634 done1 = true;
635 }
636 }
637 }
638
639 fn loan_shark(player: &mut Player) {
640
641 if player.location != "Brooklyn".to_string() {
642 println!("Can only talk to the loanshark in Brooklyn");
643 } else {
644 let mut loan_done = false;
645 while ! loan_done {
646 let action = prompt("What do you want to do? (borrow,repay)".to_string()).unwrap();
647 if action.contains("repay") {
648 let payback_amount: u32 = prompt("How much to pay back?".to_string()).unwrap().parse().unwrap();
649 if payback_amount > player.money {
650 println!("You dont have that much money");
651 } else {
652 player.remove_debt(payback_amount);
653 println!("You now owe the loanshark: ${}", player.debt);
654 loan_done = true;
655 }
656 } else if action.contains("borrow") {
657 let borrow_amount = prompt("How much do you want to borrow? (Limit 20000)".to_string()).unwrap().parse().unwrap();
658 if borrow_amount > 20000 {
659 println!("You cant borrow that much");
660 } else {
661 player.borrow_from_shark(borrow_amount);
662 loan_done = true;
663 }
664 }
665 }
666
667 }
668 }
669
670 fn head_stash_op(player: &mut Player, head_stash: &mut HeadStash) {
671
672 if player.location != "Brooklyn".to_string() {
673 println!("Your head stash is in Brooklyn");
674 } else {
675 let mut head_stash_done = false;
676 while ! head_stash_done {
677 let action = prompt("What do you want to do? (bank,withdraw)".to_string()).unwrap();
678 if action.contains("bank") {
679 let bank_type = prompt("What do you want to bank? (cash,drugs)".to_string()).unwrap();
680 if bank_type.contains("cash") {
681 let bank_amount: u32 = prompt("How much do you want to bank?".to_string()).unwrap().parse().unwrap();
682 if bank_amount > player.money {
683 println!("You don't have that much money on you!");
684 } else {
685 head_stash.bank_stash(&bank_amount);
686 player.lose_money(&bank_amount);
687 head_stash_done = true;
688 }
689 }
690
691 if bank_type.contains("drugs") {
692 let mut drug_type = prompt("What drug to you want to stash?".to_string()).unwrap();
693 drug_type = get_drug_as_string(&drug_type).unwrap();
694 if drug_type != "null".to_string() {
695 let stash_amount: u32 = prompt("How much do you want to stash?".to_string()).unwrap().parse().unwrap();
696 if stash_amount > player.get_stash_amount(&drug_type) {
697 println!("You don't have that much in your stash!");
698 } else {
699 head_stash.move_drug_to_stash(&drug_type,&stash_amount);
700 player.lose_drug(&drug_type,&stash_amount);
701 head_stash_done = true;
702 }
703 } else {
704 println!("Try again");
705 }
706 }
707 }
708
709 if action.contains("withdraw") {
710 let withdraw_type = prompt("What do you want to withdraw? (cash,drugs)".to_string()).unwrap();
711 if withdraw_type.contains("cash") {
712 let withdraw_amount: u32 = prompt("How much do you want to withdraw?".to_string()).unwrap().parse().unwrap();
713 if withdraw_amount > head_stash.money {
714 println!("You don't have that much money in the stash!");
715 } else {
716 head_stash.withdraw_stash(&withdraw_amount);
717 player.gain_money(&withdraw_amount);
718 head_stash_done = true;
719 }
720 }
721
722 if withdraw_type.contains("drugs") {
723 let mut drug_type = prompt("What drug to you want to withdraw?".to_string()).unwrap();
724 drug_type = get_drug_as_string(&drug_type).unwrap();
725 if drug_type != "null".to_string() {
726 let withdraw_amount: u32 = prompt("How much do you want to stash?".to_string()).unwrap().parse().unwrap();
727 if withdraw_amount > head_stash.get_head_stash_amount(&drug_type) {
728 println!("You dont have that much {} in your stash!",&drug_type);
729 } else {
730 head_stash.grab_from_stash(&drug_type,&withdraw_amount);
731 player.gain_drug(&drug_type,&withdraw_amount);
732 head_stash_done = true;
733 }
734 } else {
735 println!("Try again");
736 }
737 }
738 }
739 }
740 }
741 }
742
743
744 ///////
745 // Main
746 ///////
747
748 fn main() {
749 let mut player = Player::new(10,2000,2050,0,0,0,0,0,0,"Brooklyn".to_string(),10,50);
750 // let mut market = Market::new(0,0,0,0,0,0);
751 let mut market = Market::new(100,600,18000,28000,3000,10000,700,2000,120,500,15,200,0,0,0,0,0,0);
752 let mut head_stash = HeadStash::new(0,0,0,0,0,0,0);
753 Market::change_prices(&mut market);
754 let mut done = false;
755 while ! done {
756 let input = prompt("Type start, quit, or help".to_string()).unwrap();
757
758 if input == "quit".to_string() {
759 done = true;
760 } else if input == "start".to_string() {
761 println!("Starting the game");
762 let mut main_loop = false;
763 while ! main_loop {
764 clear_term();
765
766 if player.health == 0 {
767 clear_term();
768 println!("You died! Game over!");
769 let _placeholder = prompt("".to_string());
770 main_loop = true;
771 }
772
773 if player.debt != 0 {
774 if player.loan_timer == 0 {
775 println!("The loan shark wants his money! He beats you to a pulp to remind you!");
776 player.take_damage(2);
777 player.increase_loan_timer(5);
778 println!("You take 2 damage!");
779 let _placeholder = prompt("".to_string());
780 }
781 }
782
783 player.dump();
784 head_stash.dump();
785 market.dump();
786
787 if player.location == "Brooklyn".to_string() {
788 println!("You're currently in {}, what will you do? (buy,sell,jet,loanshark,headstash)",player.location);
789 } else {
790 println!("You're currently in {}, what will you do? (buy,sell,jet)",player.location);
791 }
792
793 let action = prompt("".to_string()).unwrap();
794 if action.contains("buy") {
795 buy_drugs(&mut player, &mut market);
796 } else if action.contains("sell") {
797 sell_drugs(&mut player, &mut market);
798 } else if action.contains("jet") {
799 go_to_location(&mut player, &mut market);
800 player.debt_interest();
801 player.decrease_loan_timer(1);
802
803 // Only have events trigger after 'jetting'
804 let mut rng = rand::thread_rng();
805 let event_chance = rng.gen_range(0,9);
806 if event_chance == 3 {
807 price_event(&mut market);
808 }
809
810 if event_chance == 2 {
811 trenchcoat_event(&mut player);
812 }
813
814 if event_chance == 1 {
815 body_armor_event(&mut player);
816 }
817
818 if event_chance == 0 {
819 cops_event(&mut player);
820 }
821
822 if player.health == 0 {
823 clear_term();
824 println!("You died! Game over!");
825 let _placeholder = prompt("".to_string());
826 main_loop = true;
827 }
828
829 } else if action.contains("loanshark") {
830 loan_shark(&mut player);
831 } else if action.contains("headstash") {
832 head_stash_op(&mut player, &mut head_stash);
833 } else if action == "quit".to_string() {
834 std::process::exit(0);
835 }
836 }
837 }
838 }
839 }