diff --git a/Cargo.toml b/Cargo.toml index b636599f..55851e8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,5 +5,5 @@ authors = ["ntr "] [dependencies] rand = "0.5.4" -uuid = "0.6.5" +uuid = { version = "0.6", features = ["serde", "v4"] } serde_json = "1.0.24" diff --git a/README.md b/README.md index 51b6b62f..cce4403f 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,79 @@ # Cryps ("creeps") // Creeptography -## Stats -str agi int -items -wallet value? -gain 1 lvl per battle - +## Items ## Rolling - stat & rng block hash or totally random -friendship on ties? \ No newline at end of file +friendship on ties? + +## missions +also the idea is like +the currency is kinda like path right +you're trying to get like chaos +to reroll some stat +or some item +so maybe like a sword +has 5 bits of damage it can guarantee +but a badman-sabre has 16 bits +and you keep blowing chaos on it til it gets 1111111111 +MashyToday at 9:04 PM +yeah that would be cool +natureToday at 9:05 PM +i feel like that would make it kinda p2w +so probably needs limits +MashyToday at 9:05 PM +I was thinking the p2w more just like making the needs and missions quicker right +so like instead of feeding your dude you get some item where hes fed for 2 days or something +or you could reduce the mission time which is like kinda pay to win but not really +natureToday at 9:06 PM +well what do the missions give you +MashyToday at 9:06 PM +well thats what i was thinking you'd do to get items +so instead of doing a zone in an rpg and getting all this loot +you send your dude out and you got a notification 4 hours later like success / failure this is what you got back +natureToday at 9:07 PM +i was thinking aobut that +i don't really like the possibility of failure on a mission +imagine sending your dude out on a mission for 2 days and it ceoms back like "nope wrong" +i'd just fucken rq +MashyToday at 9:08 PM +Yeah +natureToday at 9:08 PM +BUT +a better thing is like +playing off crypto +MashyToday at 9:08 PM +its something like this https://www.youtube.com/watch?v=bXLW9dF7LN8 +YouTube +Tommy J +WoW: Garrison Mission Chance - How it Works + +natureToday at 9:08 PM +missions are like +MashyToday at 9:08 PM +so you get told before hand the % chance for success +natureToday at 9:08 PM +go and do 2000 overkill damage to some monster +and your dude is out there using his items and rolling +so it can happen quick if you're lucky +or slow if you're not +but still will eventually happen +and then you get like easy limits for missions right +MashyToday at 9:09 PM +yeah that would be better actually +natureToday at 9:09 PM +like a creep that onl deals 100 dmg can't finish that mission +i feel like that would be good +cause then if you have like a defensive cryp +it could have a defensive kinda mission +like go and block 40000 damage in pve +and then it gets some baller shield +and is like speccing into defense +MashyToday at 9:10 PM +sounds better +natureToday at 9:10 PM +and like an offensive cryp could do that too +but it might keep getting KOd +and you hvae to pay to revive it \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 6e6218cd..66010a2f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,123 +1,216 @@ extern crate rand; +extern crate uuid; // extern crate serde_json; +use uuid::Uuid; use rand::prelude::*; #[derive(Debug,Clone)] struct Cryp { - dmg: u64, - def: u64, - stam: u64, - name: String, + id: Uuid, + dmg: u64, + def: u64, + stam: u64, + xp: u64, + lvl: u8, + name: String, } struct Turn { - dmg: u64, - def: u64, + dmg: Roll, + def: Roll, } -fn att_roll(att: u64) -> u64 { - let mut rng = thread_rng(); - let roll: u64 = rng.gen(); - println!("{:b} & {:b}", att, roll); - return att & roll; +#[derive(Debug)] +enum Attribute { + Dmg, + Def, } -fn cryp_turn(c: &Cryp) -> Turn { - let dmg = att_roll(c.dmg); - let def = att_roll(c.def); - - println!("{:?}", c.name); - println!("dmg: {:b}", dmg); - println!("def: {:b}", def); - - return Turn { dmg, def } -} - -fn assign_dmg(a: &Cryp, t: &Turn) -> Cryp { - Cryp { - dmg: a.dmg, - def: a.def, - stam: match a.stam.checked_sub(t.dmg) { - Some(v) => v, - None => 0, - }, - name: a.name.clone() +impl Attribute { + pub fn as_str(&self) -> &'static str { + match self { + Dmg => "dmg", + Def => "def", + } } } +struct Roll { + value: u64, + roll: u64, + result: u64, + att: Attribute +} + +fn check_lvl(lvl: u8) -> u8 { + if lvl > 64 { return 64; } + if lvl == 0 { return 0; } + return lvl; +} + +fn create_cryp(name: String, lvl: u8) -> Cryp { + let mut rng = thread_rng(); + let max = 2_u64.pow(lvl.into()); + let dmg: u64 = rng.gen_range(1, max); + let def: u64 = rng.gen_range(1, max); + let stam: u64 = rng.gen_range(1, max); + let id = Uuid::new_v4(); + return Cryp { + id, + dmg, + def, + stam, + lvl, + xp: 0, + name: name.clone() + }; +} + +fn att_roll(value: u64, att: Attribute) -> Roll { + let mut rng = thread_rng(); + let roll: u64 = rng.gen(); + return Roll { att, value, roll, result: value & roll }; +} + +fn print_roll(r: &Roll) { + println!("{:?}", r.att); + println!("{:064b} &", r.roll); + println!("{:064b}", r.value); + println!("{:064b} - {:?}", r.result, r.result); + println!(""); +} + +fn cryp_turn(c: &Cryp) -> Turn { + println!("{:?}'s turn:", c.name); + let dmg = att_roll(c.dmg, Attribute::Dmg); + let def = att_roll(c.def, Attribute::Dmg); + + print_roll(&dmg); + print_roll(&def); + + return Turn { dmg, def } +} + +fn assign_dmg(plr: &Cryp, opp: &Cryp, plr_t: &Turn, opp_t: &Turn) -> Cryp { + let final_dmg = match opp_t.dmg.result.checked_sub(plr_t.def.result) { + Some(v) => v, + None => 0, + }; + + println!("{:?} deals {:?} dmg to {:?} ({:?} blocked)" + ,opp.name + ,final_dmg + ,plr.name + ,opp_t.def.result); + + return Cryp { + dmg: plr.dmg, + def: plr.def, + stam: match plr.stam.checked_sub(final_dmg) { + Some(v) => v, + None => 0, + }, + xp: plr.xp, + lvl: plr.lvl, + id: plr.id, + name: plr.name.clone() + }; +} + fn combat_phase(a: &Cryp, b: &Cryp) -> Vec { - let a_turn = cryp_turn(&a); - let b_turn = cryp_turn(&b); - return vec![ - assign_dmg(&a, &b_turn), - assign_dmg(&b, &a_turn), - ]; + let a_turn = cryp_turn(&a); + let b_turn = cryp_turn(&b); + return vec![ + assign_dmg(&a, &b, &a_turn, &b_turn), + assign_dmg(&b, &a, &b_turn, &a_turn), + ]; } fn battle(a: &Cryp, b: &Cryp) -> Vec { - let mut cryps = vec![ - a.clone(), - b.clone() - ]; - loop { - let combat = combat_phase(&cryps[0], &cryps[1]); - println!("{:?}", combat); - if combat.iter().any(|c| c.stam == 0) { - return combat; - } - cryps = combat; + let mut cryps = vec![ + a.clone(), + b.clone() + ]; + + println!("battle:",); + println!("{:?}", cryps[0]); + println!("{:?}", cryps[1]); + loop { + let combat = combat_phase(&cryps[0], &cryps[1]); + println!("{:?}", combat); + if combat.iter().any(|c| c.stam == 0) { + return combat; } + cryps = combat; + } } -// fn main() { -// let mut bodies = vec![ -// Body { x: 10, y: 10, v: 0 }, -// Body { x: 20, y: 30, v: 0 }, -// ]; +fn pve(plr: &Cryp) { + let mut rng = thread_rng(); + let mob_lvl: u8 = rng.gen_range(1, check_lvl(plr.lvl + 1)); + let mob = create_cryp("bamboo basher".to_string(), mob_lvl); -// for _ in 0..2 { -// let next_bodies = bodies -// .iter() -// .map(|b| { -// let next_v = bodies -// .iter() -// .fold(b.v, { |a, b_inner| a + b.x * b_inner.x }); -// Body { v: next_v, ..*b } -// }) -// .collect(); -// bodies = next_bodies; -// } + let battle = battle(plr, &mob); -// println!("{:?}", bodies); -// } + let winner = match battle.iter().find(|c| c.stam > 0) { + Some(w) => w, + None => panic!("no winner found {:?}", battle), + }; + + if winner.id == plr.id { + println!("level up"); + } + +} pub fn main() { - let a = Cryp { - name: "pronounced \"creeep\"".to_string(), - dmg: 10, - def: 5, - stam: 25, + let a = create_cryp("pronounced \"creeep\"".to_string(), 8); + let b = create_cryp("lemongrass tea".to_string(), 8); + + let battle = battle(&a, &b); + + let draw = battle.iter().all(|c| c.stam == 0); + if draw { + println!("{:?} was a draw", battle); + return; + } + + let winner = match battle.iter().find(|c| c.stam > 0) { + Some(w) => w, + None => panic!("no winner found {:?}", battle), }; - let b = Cryp { - name: "lemongrass tea".to_string(), - dmg: 8, - def: 8, - stam: 25, - }; + println!("{:?} is the winner with {:?} hp remaining", winner.name, winner.stam); - battle(&a, &b); return; } #[cfg(test)] mod tests { - use main; + use *; + #[test] - fn it_works() { - main(); - return; - } + fn battle_test() { + main(); + return; + } + #[test] + fn create_cryp_test() { + let lvl_eight = create_cryp("hatchling".to_string(), 2); + assert!(lvl_eight.dmg <= 2_u64.pow(2)); + assert!(lvl_eight.def <= 2_u64.pow(2)); + assert!(lvl_eight.stam < 2_u64.pow(2)); + println!("{:?}", lvl_eight); + return; + } + + #[test] + fn pve_test() { + let player = create_cryp("ca phe sua da".to_string(), 2); + pve(&player); + return; + } + }