Skip to content

Commit

Permalink
Introduce 12 new weapons, along with a rare Earth spell Imbue
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Sep 22, 2024
1 parent c37c676 commit bc75f0b
Show file tree
Hide file tree
Showing 10 changed files with 614 additions and 165 deletions.
144 changes: 86 additions & 58 deletions src/cards.csv

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/rs/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ opt-level = 1
etg = { version = "0.1", path = "../" }
rand = { version = "0.8", default-features = false }
rand_pcg = { version = "0.3", default-features = false }
rayon = "1.5"
rayon = "1"
13 changes: 8 additions & 5 deletions src/rs/src/aieval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,11 @@ fn eval_skill(
Skill::hush => 3 * PREC,
Skill::icebolt | Skill::v_icebolt(_) => 10 * PREC,
Skill::ignite => 10 * PREC,
Skill::immolate(_) => 5 * PREC,
Skill::immolate(x) => x as i32 * (PREC / 2),
Skill::improve | Skill::v_improve => 6 * PREC,
Skill::inertia => 2 * PREC,
Skill::ink => 3 * PREC,
Skill::innovation => 3 * PREC,
Skill::innovate(x) => x as i32 * PREC,
Skill::integrity | Skill::v_integrity => 4 * PREC,
Skill::jelly => 5 * PREC,
Skill::jetstream => 5 * (PREC / 2),
Expand Down Expand Up @@ -870,7 +870,8 @@ fn estimate_damage(ctx: &Game, id: i16, freedom: i32, wall: &mut Wall) -> i32 {
(momatk * 3 + 1) / 2
} else {
momatk
} * freedom >> PRECBITS;
} * freedom
>> PRECBITS;
}
for &skill in ctx.getSkill(id, Event::Hit) {
if skill == Skill::vampire {
Expand Down Expand Up @@ -949,7 +950,8 @@ fn evalthing(
let mut hp = 0;
if iscrea {
if inhand
|| !flooded || thing.flag.get(Flag::aquatic)
|| !flooded
|| thing.flag.get(Flag::aquatic)
|| !ctx.material(id, None)
|| ctx.getIndex(id) <= 4
{
Expand Down Expand Up @@ -1165,7 +1167,8 @@ pub fn eval(ctx: &Game) -> i32 {
.filter(|&pr| pr != 0 && ctx.hasskill(pr, Event::Attack, Skill::v_freedom))
.map(|pr| ctx.get(pr, Stat::charges))
.sum::<i16>()
.min(4) as i32 * (PREC / 4)
.min(4) as i32
* (PREC / 4)
};
if !stasis && !patience {
for cr in player.creatures {
Expand Down
3 changes: 2 additions & 1 deletion src/rs/src/aisearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ fn lethal(ctx: &Game) -> Option<GameMove> {
.into_iter()
.filter(|&id| id != 0)
.map(|id| gclone.trueatk(id))
.sum::<i16>() > 0
.sum::<i16>()
> 0
{
proc_sopa(&mut gclone, turn);
}
Expand Down
13 changes: 10 additions & 3 deletions src/rs/src/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,22 @@ impl Card {
}

pub fn status(&self) -> &'static [(Stat, i16)] {
unsafe { StatTable.get_unchecked(self.statidx as usize..self.statidx as usize + self.statlen as usize) }
unsafe {
StatTable.get_unchecked(self.statidx as usize..self.statidx as usize + self.statlen as usize)
}
}

pub fn skill(&self) -> &'static [(Event, &'static [Skill])] {
unsafe { SkillTable.get_unchecked(self.skillidx as usize..self.skillidx as usize + self.skilllen as usize) }
unsafe {
SkillTable
.get_unchecked(self.skillidx as usize..self.skillidx as usize + self.skilllen as usize)
}
}

pub fn name(&self) -> &'static str {
unsafe { NameTable.get_unchecked(self.nameidx as usize..self.nameidx as usize + self.namelen as usize) }
unsafe {
NameTable.get_unchecked(self.nameidx as usize..self.nameidx as usize + self.namelen as usize)
}
}
}

Expand Down
62 changes: 40 additions & 22 deletions src/rs/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ impl PlayerData {
self.hand_iter().count()
}

pub fn hand_last(&self) -> Option<i16> {
pub fn hand_last(&self) -> i16 {
if self.hand[0] == 0 {
None
return 0;
} else {
let mut idx = 7;
loop {
if self.hand[idx] != 0 {
return Some(self.hand[idx]);
return self.hand[idx];
}
idx -= 1;
}
Expand Down Expand Up @@ -453,6 +453,7 @@ impl Flag {
pub const vindicated: u64 = 1 << 32;
pub const voodoo: u64 = 1 << 33;
pub const whetstone: u64 = 1 << 34;
pub const bug: u64 = 1 << 35;

pub fn get(self, key: u64) -> bool {
self.0 & key != 0
Expand Down Expand Up @@ -853,14 +854,16 @@ impl Game {
format!(
"{}",
3 + (self.get_quanta(self.get_owner(c), etg::Fire) as i16
- self.get(c, Stat::cost)) / 4
- self.get(c, Stat::cost))
/ 4
)
}
Skill::drainlife => {
format!(
"{}",
2 + (self.get_quanta(self.get_owner(c), etg::Darkness) as i16
- self.get(c, Stat::cost)) / 5
- self.get(c, Stat::cost))
/ 5
)
}
Skill::icebolt => {
Expand Down Expand Up @@ -1354,6 +1357,10 @@ impl Game {
self.rng.choose(slice)
}

pub fn choose_iter<'a, 'b, T>(&'a self, a: impl IntoIterator<Item = &'b T>) -> Option<&'b T> {
self.rng.choose_iter(a)
}

pub fn upto(&mut self, n: u32) -> u32 {
self.rng.upto(n)
}
Expand Down Expand Up @@ -1604,7 +1611,7 @@ impl Game {
}

pub fn truedr(&self, id: i16, t: i16) -> i16 {
self.get(id, Stat::hp) + self.trigger_pure(Event::Buff, id, t)
self.get(id, Stat::hp) + self.trigger_pure(Event::Hp, id, t)
}

pub fn truehp(&self, id: i16) -> i16 {
Expand Down Expand Up @@ -1646,8 +1653,8 @@ impl Game {
if dmg != 0 {
let mut data = ProcData::default();
data.dmg = dmg;
self.trigger_data(Event::Hit, c, t, &mut data);
self.trigger_data(Event::Shield, t, c, &mut data);
self.trigger_data(Event::Hit, c, t, &mut data);
}
}
}
Expand Down Expand Up @@ -1964,15 +1971,20 @@ impl Game {
thing.status.insert(Stat::atk, card.attack as i16);
thing.status.insert(Stat::cost, card.cost as i16);
thing.status.insert(Stat::costele, card.costele as i16);
thing.flag.0 &=
!(Flag::additive
| Flag::airborne | Flag::aquatic
| Flag::golem | Flag::nightfall
| Flag::nocturnal
| Flag::pillar | Flag::poisonous
| Flag::ranged | Flag::stackable
| Flag::token | Flag::tunnel
| Flag::voodoo | Flag::whetstone);
thing.flag.0 &= !(Flag::additive
| Flag::airborne
| Flag::aquatic
| Flag::golem
| Flag::nightfall
| Flag::nocturnal
| Flag::pillar
| Flag::poisonous
| Flag::ranged
| Flag::stackable
| Flag::token
| Flag::tunnel
| Flag::voodoo
| Flag::whetstone);
thing.flag.0 |= card.flag();
for &(k, v) in card.status() {
thing.status.insert(k, v);
Expand Down Expand Up @@ -2180,7 +2192,7 @@ impl Game {

pub fn trigger_data(&mut self, k: Event, c: i16, t: i16, data: &mut ProcData) {
if let Some(ss) = self.get_thing(c).skill.get(k) {
for &s in ss.clone().iter() {
for s in ss.clone().into_iter() {
s.proc(self, c, t, data);
}
}
Expand Down Expand Up @@ -2305,6 +2317,11 @@ impl Game {
}
}

pub fn shatter(&mut self, id: i16) {
self.fx(id, Fx::Shatter);
self.die(id);
}

pub fn die(&mut self, id: i16) {
let idx = self.remove(id);
if idx == -1 {
Expand Down Expand Up @@ -2448,11 +2465,12 @@ impl Game {

pub fn clearStatus(&mut self, id: i16) {
let thing = self.get_thing_mut(id);
thing.flag.0 &=
!(Flag::additive
| Flag::cloak | Flag::nightfall
| Flag::stackable
| Flag::tunnel | Flag::whetstone);
thing.flag.0 &= !(Flag::additive
| Flag::cloak
| Flag::nightfall
| Flag::stackable
| Flag::tunnel
| Flag::whetstone);
for (st, ref mut val) in thing.status.iter_mut() {
if matches!(st, Stat::charges | Stat::flooding) {
*val = 0;
Expand Down
14 changes: 7 additions & 7 deletions src/rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ mod test {
ctx.set_quanta(p2, etg::Light, 2);
attack_foe(&mut ctx, dev);
attack_foe(&mut ctx, dev);
assert_eq!(ctx.get_player(p1).hand_last(), Some(dev));
assert_eq!(ctx.get_player(p1).hand_last(), dev);
assert_eq!(ctx.get(dev, Stat::atk), 4);
assert_eq!(ctx.get(dev, Stat::hp), 2);
assert_eq!(ctx.get(dev, Stat::maxhp), 2);
Expand All @@ -208,7 +208,7 @@ mod test {
Skill::ren.proc(&mut ctx, dev, dev, &mut ProcData::default());
Skill::pacify.proc(&mut ctx, dev, dev, &mut ProcData::default());
Skill::equalize.proc(&mut ctx, dev, dev, &mut ProcData::default());
assert_eq!(ctx.get_player(p1).hand_last(), Some(dev));
assert_eq!(ctx.get_player(p1).hand_last(), dev);
assert_eq!(ctx.get(dev, Stat::atk), 0);
assert_eq!(ctx.get(dev, Stat::hp), 0);
assert_eq!(ctx.get(dev, Stat::maxhp), 0);
Expand Down Expand Up @@ -286,7 +286,7 @@ mod test {
ctx.setWeapon(p2, dagger);
ctx.r#move(GameMove::End(0));
assert_eq!(ctx.get_weapon(p2), 0);
assert_eq!(ctx.get_player(p2).hand_last(), Some(dagger));
assert_eq!(ctx.get_player(p2).hand_last(), dagger);
}

#[test]
Expand Down Expand Up @@ -466,7 +466,7 @@ mod test {
let tgting = Skill::regrade.targeting(CardSet::Open).unwrap();
let (mut ctx, p1, p2) = setup(CardSet::Open);
assert!(!tgting.check(&ctx, p1, p2));
let pillar = ctx.get_player(p1).hand_last().unwrap();
let pillar = ctx.get_player(p1).hand_last();
assert!(!tgting.check(&ctx, pillar, pillar));
assert!(tgting.check(&ctx, p1, pillar));
ctx.play(pillar, 0, true);
Expand Down Expand Up @@ -597,14 +597,14 @@ mod test {
ctx.set(whim, Stat::casts, 1);
ctx.useactive(whim, tstorm);
assert_eq!(ctx.get_player(p1).deck.first(), Some(&tstorm));
assert_eq!(ctx.get_player(p1).hand_last(), Some(dfly));
assert_eq!(ctx.get_player(p1).hand_last(), dfly);
}

#[test]
fn yoink_targeting() {
let tgting = Skill::yoink.targeting(CardSet::Open).unwrap();
let (ctx, p1, p2) = setup(CardSet::Open);
assert!(tgting.check(&ctx, p1, ctx.get_player(p2).hand_last().unwrap()));
assert!(!tgting.check(&ctx, p1, ctx.get_player(p1).hand_last().unwrap()));
assert!(tgting.check(&ctx, p1, ctx.get_player(p2).hand_last()));
assert!(!tgting.check(&ctx, p1, ctx.get_player(p1).hand_last()));
}
}
Loading

0 comments on commit bc75f0b

Please sign in to comment.