enum magic
This commit is contained in:
parent
820c56bb64
commit
ebca0bb55c
@ -5,5 +5,5 @@ authors = ["ntr <ntr@smokestack.io>"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rand = "0.5.4"
|
rand = "0.5.4"
|
||||||
uuid = "0.6.5"
|
uuid = { version = "0.6", features = ["serde", "v4"] }
|
||||||
serde_json = "1.0.24"
|
serde_json = "1.0.24"
|
||||||
|
|||||||
80
README.md
80
README.md
@ -1,15 +1,79 @@
|
|||||||
# Cryps ("creeps") // Creeptography
|
# Cryps ("creeps") // Creeptography
|
||||||
|
|
||||||
## Stats
|
## Items
|
||||||
str agi int
|
|
||||||
items
|
|
||||||
wallet value?
|
|
||||||
gain 1 lvl per battle
|
|
||||||
|
|
||||||
|
|
||||||
## Rolling
|
## Rolling
|
||||||
|
|
||||||
stat & rng
|
stat & rng
|
||||||
block hash or totally random
|
block hash or totally random
|
||||||
|
|
||||||
friendship on ties?
|
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
|
||||||
261
src/lib.rs
261
src/lib.rs
@ -1,123 +1,216 @@
|
|||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
extern crate uuid;
|
||||||
// extern crate serde_json;
|
// extern crate serde_json;
|
||||||
|
|
||||||
|
use uuid::Uuid;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
|
|
||||||
#[derive(Debug,Clone)]
|
#[derive(Debug,Clone)]
|
||||||
struct Cryp {
|
struct Cryp {
|
||||||
dmg: u64,
|
id: Uuid,
|
||||||
def: u64,
|
dmg: u64,
|
||||||
stam: u64,
|
def: u64,
|
||||||
name: String,
|
stam: u64,
|
||||||
|
xp: u64,
|
||||||
|
lvl: u8,
|
||||||
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Turn {
|
struct Turn {
|
||||||
dmg: u64,
|
dmg: Roll,
|
||||||
def: u64,
|
def: Roll,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn att_roll(att: u64) -> u64 {
|
#[derive(Debug)]
|
||||||
let mut rng = thread_rng();
|
enum Attribute {
|
||||||
let roll: u64 = rng.gen();
|
Dmg,
|
||||||
println!("{:b} & {:b}", att, roll);
|
Def,
|
||||||
return att & roll;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cryp_turn(c: &Cryp) -> Turn {
|
impl Attribute {
|
||||||
let dmg = att_roll(c.dmg);
|
pub fn as_str(&self) -> &'static str {
|
||||||
let def = att_roll(c.def);
|
match self {
|
||||||
|
Dmg => "dmg",
|
||||||
println!("{:?}", c.name);
|
Def => "def",
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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<Cryp> {
|
fn combat_phase(a: &Cryp, b: &Cryp) -> Vec<Cryp> {
|
||||||
let a_turn = cryp_turn(&a);
|
let a_turn = cryp_turn(&a);
|
||||||
let b_turn = cryp_turn(&b);
|
let b_turn = cryp_turn(&b);
|
||||||
return vec![
|
return vec![
|
||||||
assign_dmg(&a, &b_turn),
|
assign_dmg(&a, &b, &a_turn, &b_turn),
|
||||||
assign_dmg(&b, &a_turn),
|
assign_dmg(&b, &a, &b_turn, &a_turn),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
fn battle(a: &Cryp, b: &Cryp) -> Vec<Cryp> {
|
fn battle(a: &Cryp, b: &Cryp) -> Vec<Cryp> {
|
||||||
let mut cryps = vec![
|
let mut cryps = vec![
|
||||||
a.clone(),
|
a.clone(),
|
||||||
b.clone()
|
b.clone()
|
||||||
];
|
];
|
||||||
loop {
|
|
||||||
let combat = combat_phase(&cryps[0], &cryps[1]);
|
println!("battle:",);
|
||||||
println!("{:?}", combat);
|
println!("{:?}", cryps[0]);
|
||||||
if combat.iter().any(|c| c.stam == 0) {
|
println!("{:?}", cryps[1]);
|
||||||
return combat;
|
loop {
|
||||||
}
|
let combat = combat_phase(&cryps[0], &cryps[1]);
|
||||||
cryps = combat;
|
println!("{:?}", combat);
|
||||||
|
if combat.iter().any(|c| c.stam == 0) {
|
||||||
|
return combat;
|
||||||
}
|
}
|
||||||
|
cryps = combat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn main() {
|
fn pve(plr: &Cryp) {
|
||||||
// let mut bodies = vec![
|
let mut rng = thread_rng();
|
||||||
// Body { x: 10, y: 10, v: 0 },
|
let mob_lvl: u8 = rng.gen_range(1, check_lvl(plr.lvl + 1));
|
||||||
// Body { x: 20, y: 30, v: 0 },
|
let mob = create_cryp("bamboo basher".to_string(), mob_lvl);
|
||||||
// ];
|
|
||||||
|
|
||||||
// for _ in 0..2 {
|
let battle = battle(plr, &mob);
|
||||||
// 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;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 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() {
|
pub fn main() {
|
||||||
let a = Cryp {
|
let a = create_cryp("pronounced \"creeep\"".to_string(), 8);
|
||||||
name: "pronounced \"creeep\"".to_string(),
|
let b = create_cryp("lemongrass tea".to_string(), 8);
|
||||||
dmg: 10,
|
|
||||||
def: 5,
|
let battle = battle(&a, &b);
|
||||||
stam: 25,
|
|
||||||
|
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 {
|
println!("{:?} is the winner with {:?} hp remaining", winner.name, winner.stam);
|
||||||
name: "lemongrass tea".to_string(),
|
|
||||||
dmg: 8,
|
|
||||||
def: 8,
|
|
||||||
stam: 25,
|
|
||||||
};
|
|
||||||
|
|
||||||
battle(&a, &b);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use main;
|
use *;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_works() {
|
fn battle_test() {
|
||||||
main();
|
main();
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user