Skip to content

Instantly share code, notes, and snippets.

@mooman219
Created June 1, 2019 03:45
Show Gist options
  • Select an option

  • Save mooman219/e656bf0ca315ccb7c0673d694ea8f575 to your computer and use it in GitHub Desktop.

Select an option

Save mooman219/e656bf0ca315ccb7c0673d694ea8f575 to your computer and use it in GitHub Desktop.
extern crate rand;
use rand::prelude::*;
use std::fmt;
#[derive(Debug, Clone)]
pub struct Item {
pub id: u32,
pub name: String,
}
impl Item {
pub fn new(id: u32, name: &str) -> Item {
Item {
id: id,
name: String::from(name),
}
}
}
impl fmt::Display for Item {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{}] {}", self.id, self.name)
}
}
#[derive(Debug, Clone)]
pub struct Pack {
pub common: Vec<Item>,
pub uncommon: Vec<Item>,
pub rare: Vec<Item>,
pub equipment: Vec<Item>,
}
impl Pack {
pub fn print_pack(&mut self) {
let mut rng = rand::thread_rng();
self.common.shuffle(&mut rng);
self.uncommon.shuffle(&mut rng);
self.rare.shuffle(&mut rng);
self.equipment.shuffle(&mut rng);
println!("Pack: ");
for index in 0..3 {
println!(" Common: {}", &self.common[index]);
}
for index in 0..2 {
println!(" Uncommon: {}", &self.uncommon[index]);
}
for index in 0..1 {
println!(" Rare: {}", &self.rare[index]);
}
for index in 0..1 {
println!(" Equipment: {}", &self.equipment[index]);
}
}
}
fn main() {
// ^(.*)\t(.*)$
// Item::new($1,"$2"),
let mut pack = Pack {
common: vec![
Item::new(58, "Backup Magazine"),
Item::new(16, "Bustling Fungus"),
Item::new(27, "Cautious Slug"),
Item::new(17, "Crowbar"),
Item::new(57, "Energy Drink"),
Item::new(8, "Goat Hoof"),
Item::new(7, "Lens-Maker's Glasses"),
Item::new(36, "Medkit"),
Item::new(29, "Personal Shield Generator"),
Item::new(0, "Soldier's Syringe"),
Item::new(59, "Sticky Bomb"),
Item::new(41, "Stun Grenade"),
Item::new(1, "Tougher Times"),
Item::new(20, "Tri-Tip Dagger"),
],
uncommon: vec![
Item::new(3, "AtG Missile Mk.1"),
Item::new(65, "Chronobauble"),
Item::new(30, "Fuel Cell"),
Item::new(26, "Harvester's Scythe"),
Item::new(9, "Hopoo Feather"),
Item::new(64, "Kjaro's Band"),
Item::new(13, "Leeching Seed"),
Item::new(25, "Old War Stealthkit"),
Item::new(19, "Predatory Instincts"),
Item::new(21, "Red Whip"),
Item::new(62, "Rose Buckler"),
Item::new(63, "Runald's Band"),
Item::new(11, "Ukulele"),
Item::new(76, "Wax Quail"),
Item::new(53, "Queen's Gland"),
Item::new(52, "Titanic Knurl"),
],
rare: vec![
Item::new(35, "57 Leaf Clover"),
Item::new(50, "Alien Head"),
Item::new(2, "Brilliant Behemoth"),
Item::new(66, "Dio's Best Friend"),
Item::new(22, "H3AD-5T v2"),
Item::new(68, "Hardlight Afterburner"),
Item::new(31, "N'kuhana's Opinion"),
Item::new(75, "Rejuvenation Rack"),
Item::new(38, "Sentient Meat Hook"),
Item::new(32, "Unstable Tesla Coil"),
Item::new(71, "Corpsebloom"),
Item::new(74, "Gesture of the Drowned"),
Item::new(43, "Shaped Glass"),
Item::new(49, "Transcendence"),
],
equipment: vec![
Item::new(26, "Effigy of Grief"),
Item::new(23, "Helfire Tincture"),
Item::new(0, "Disposable Missile Launcher"),
Item::new(2, "Foreign Fruit"),
Item::new(3, "Glowing Meteorite"),
Item::new(21, "Gnarled Woodsprite"),
Item::new(9, "Her Biting Embrace"),
Item::new(5, "Ifrit's Distinction"),
Item::new(18, "Milky Chrysalis"),
Item::new(13, "Ocular HUD"),
Item::new(16, "Preon Accumulator"),
Item::new(11, "Primordial Cube"),
Item::new(19, "Royal Capacitor"),
Item::new(6, "Silence Between Two Strikes"),
Item::new(14, "The Back-up"),
],
};
println!("```");
for _ in 0..3 {
pack.print_pack();
}
println!("```");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment