diff --git a/src/Game.js b/src/Game.js index 975e020f..5c324e04 100644 --- a/src/Game.js +++ b/src/Game.js @@ -128,9 +128,6 @@ export default class Game { }) ); } - getSkill(id, k) { - return this.get_one_skill(id, enums.EventId[k]); - } tgtToPos(id, p1id) { const pos = this.tgt_to_pos(id, p1id); return pos === 0 ? null : { x: pos & 4095, y: pos >> 12 }; diff --git a/src/rs/build.rs b/src/rs/build.rs index 46ce0339..ffcc15f9 100644 --- a/src/rs/build.rs +++ b/src/rs/build.rs @@ -9,7 +9,6 @@ use serde_json::Value; #[derive(Default, Serialize)] struct Enums { - EventId: BTreeMap, FlagId: BTreeMap, Fx: BTreeMap, StatId: BTreeMap, @@ -272,28 +271,10 @@ fn main() { println!("cargo:rerun-if-changed=./src/skill.rs"); let gamers = fs::read_to_string("src/game.rs").expect("failed to read game.rs"); - let skillrs = fs::read_to_string("src/skill.rs").expect("failed to read skill.rs"); let mut enums = Enums::default(); let mut source = String::from("#![no_std]\n#![allow(non_upper_case_globals)]\nuse crate::card::{Card,CardSet,Cards};use crate::game::{Flag,Fx,Kind,Stat};use crate::skill::{Event,Skill};\n"); - let skillevent = subsource(&skillrs, "impl Event {\n"); - let mut eventid = 1; - for line in skillevent.lines() { - if let Some(endname) = line.find(": Event = Event") { - if let Some(startname) = line.find("pub const ") { - let mut name = String::from(&line[startname + "pub const ".len()..endname]); - unsafe { name.as_mut_vec()[0] += b'a' - b'A' }; - let id = eventid; - eventid += 1; - let mut ownname = String::from("own"); - ownname.push_str(&name); - enums.EventId.insert(name, id); - enums.EventId.insert(ownname, id | 128); - } - } - } - source.push_str("pub fn id_stat(s:Stat)->i32{match s{\n"); let gamestat = subsource(&gamers, "pub enum Stat {\n"); let mut stat_source = String::from("pub fn stat_id(s:i32)->Option{Some(match s{\n"); diff --git a/src/rs/src/game.rs b/src/rs/src/game.rs index d9e8b0ba..a7a5a983 100644 --- a/src/rs/src/game.rs +++ b/src/rs/src/game.rs @@ -843,62 +843,8 @@ impl Game { } } - pub fn get_one_skill(&self, id: i32, k: u8) -> Option { - Event::try_from(k) - .ok() - .and_then(|ev| self.skill_text(id, ev)) - } - - pub fn active_text(&self, id: i32) -> String { - if let Some(acast) = self.skill_text(id, Event::Cast) { - return format!( - "{}:{}{}", - self.get(id, Stat::cast), - self.get(id, Stat::castele), - acast - ); - } - - for ev in [ - Event::Hit, - Event::Death, - Event::OwnDeath, - Event::Buff, - Event::Destroy, - Event::Draw, - Event::Play, - Event::Spell, - Event::Dmg, - Event::Shield, - Event::Postauto, - ] { - if let Some(a) = self.skill_text(id, ev) { - return format!( - "{}{}", - match ev { - Event::Hit => "hit ", - Event::Death => "death ", - Event::OwnDeath => "owndeath ", - Event::Buff => "buff ", - Event::Destroy => "destroy ", - Event::Draw => "draw ", - Event::Play => "play ", - Event::Spell => "spell ", - Event::Dmg => "dmg ", - Event::Shield => "shield ", - Event::Postauto => "postauto ", - _ => "", - }, - a - ); - } - } - - if let Some(auto) = self.skill_text(id, Event::OwnAttack) { - return auto; - } - - String::new() + pub fn get_cast_skill(&self, id: i32) -> Option { + self.skill_text(id, Event::Cast) } pub fn actinfo(&self, c: i32, t: i32) -> Option { @@ -955,12 +901,84 @@ impl Game { }) } + pub fn instance_text(&self, id: i32) -> String { + let thing = self.get_thing(id); + let card = self.cards.get(thing.status.get(Stat::card).unwrap_or(0)); + if thing.kind == Kind::Spell { + format!( + "{}\n{}:{}", + card.name, + thing.status.get(Stat::cost).unwrap_or(0), + thing.status.get(Stat::costele).unwrap_or(0) + ) + } else { + let charges = thing.status.get(Stat::charges).unwrap_or(0); + let mut text = self.active_text(id); + match thing.kind { + Kind::Creature => { + write!(text, "\n{} | {}", self.trueatk(id), self.truehp(id)); + if charges != 0 { + write!(text, " \u{00d7}{}", charges); + } + } + Kind::Permanent => { + if thing.flag.get(Flag::pillar) { + text.clear(); + write!( + text, + "\n1:{}\u{00d7}{}", + if thing.flag.get(Flag::pendstate) { + self.get_mark(thing.owner) + } else { + card.element as i32 + }, + charges + ); + } else if thing + .skill + .get(Event::OwnAttack) + .map(|sk| sk.as_ref()) + .unwrap_or(&[]) == &[Skill::locket] + { + let mode = thing.status.get(Stat::mode).unwrap_or(0); + write!( + text, + "\n1:{}", + if mode != -1 { + mode + } else { + self.get_mark(thing.owner) + } + ); + } else if charges != 0 { + write!(text, "\n{}", charges); + } + } + Kind::Weapon => { + write!(text, "\n{}", self.trueatk(id)); + if charges != 0 { + write!(text, " \u{00d7}{}", charges); + } + } + Kind::Shield => { + if charges != 0 { + write!(text, "\n\u{00d7}{}", charges); + } else { + write!(text, "\n{}", self.truedr(id)); + } + } + _ => (), + }; + text + } + } + pub fn thingText(&self, id: i32) -> String { let thing = self.get_thing(id); let mut ret = String::new(); if thing.kind != Kind::Player { let instkind = if thing.kind == Kind::Spell { - self.get_card(self.get(id, Stat::card)).kind + self.cards.get(self.get(id, Stat::card)).kind } else { thing.kind }; @@ -1097,18 +1115,6 @@ impl Game { }) && (ckind == Kind::Spell || !self.get(id, Flag::immaterial | Flag::burrowed)) } - pub fn truedr(&self, id: i32) -> i32 { - self.get(id, Stat::hp) + self.trigger_pure(Event::Buff, id, 0) - } - - pub fn truehp(&self, id: i32) -> i32 { - self.get(id, Stat::hp) + self.calcBonusHp(id) - } - - pub fn trueatk(&self, id: i32) -> i32 { - self.trueatk_adrenaline(id, self.get(id, Stat::adrenaline)) - } - pub fn visible_instances(&self, id: i32, isp1: bool, cloaked: bool) -> Vec { let pl = self.get_player(id); let mut ids = @@ -1141,19 +1147,17 @@ impl Game { if self.get_kind(id) == Kind::Spell { 0 } else { - (self.get(id, Flag::psionic) as u32) | - (self.get(id, Flag::aflatoxin) as u32) << 1 | - ((!self.get(id, Flag::aflatoxin) && - (self.get(id, Stat::poison) > 0)) as u32) << 2 | - (self.get(id, Flag::airborne) as u32) << 3 | - ((!self.get(id, Flag::airborne) && - self.get(id, Flag::ranged)) as u32) << 4 | - (self.get(id, Flag::momentum) as u32) << 5 | - ((self.get(id, Stat::adrenaline) > 0) as u32) << 6 | - ((self.get(id, Stat::poison) < 0) as u32) << 7 | - ((self.get(id, Stat::delayed) > 0) as u32) << 8 | - ((id == self.get(self.get_owner(id), Stat::gpull)) as u32) << 9 | - ((self.get(id, Stat::frozen) > 0) as u32) << 10 + (self.get(id, Flag::psionic) as u32) + | (self.get(id, Flag::aflatoxin) as u32) << 1 + | ((!self.get(id, Flag::aflatoxin) && (self.get(id, Stat::poison) > 0)) as u32) << 2 + | (self.get(id, Flag::airborne) as u32) << 3 + | ((!self.get(id, Flag::airborne) && self.get(id, Flag::ranged)) as u32) << 4 + | (self.get(id, Flag::momentum) as u32) << 5 + | ((self.get(id, Stat::adrenaline) > 0) as u32) << 6 + | ((self.get(id, Stat::poison) < 0) as u32) << 7 + | ((self.get(id, Stat::delayed) > 0) as u32) << 8 + | ((id == self.get(self.get_owner(id), Stat::gpull)) as u32) << 9 + | ((self.get(id, Stat::frozen) > 0) as u32) << 10 } } @@ -1435,6 +1439,58 @@ impl Game { None } + pub fn active_text(&self, id: i32) -> String { + if let Some(acast) = self.skill_text(id, Event::Cast) { + return format!( + "{}:{}{}", + self.get(id, Stat::cast), + self.get(id, Stat::castele), + acast + ); + } + + for ev in [ + Event::Hit, + Event::Death, + Event::OwnDeath, + Event::Buff, + Event::Destroy, + Event::Draw, + Event::Play, + Event::Spell, + Event::Dmg, + Event::Shield, + Event::Postauto, + ] { + if let Some(a) = self.skill_text(id, ev) { + return format!( + "{}{}", + match ev { + Event::Hit => "hit ", + Event::Death => "death ", + Event::OwnDeath => "owndeath ", + Event::Buff => "buff ", + Event::Destroy => "destroy ", + Event::Draw => "draw ", + Event::Play => "play ", + Event::Spell => "spell ", + Event::Dmg => "dmg ", + Event::Shield => "shield ", + Event::Postauto => "postauto ", + _ => "", + }, + a + ); + } + } + + if let Some(auto) = self.skill_text(id, Event::OwnAttack) { + return auto; + } + + String::new() + } + fn mutantactive(&mut self, id: i32, actives: &'static [Skill]) -> bool { self.lobo(id); let idx = self.rng.gen_range(-3..actives.len() as isize); @@ -1451,7 +1507,7 @@ impl Game { false } else { let cast = self.rng.gen_range(1..=2); - let castele = self.get_card(self.get(id, Stat::card)).element as i32; + let castele = self.cards.get(self.get(id, Stat::card)).element as i32; self.set(id, Stat::cast, cast); self.set(id, Stat::castele, castele); self.setSkill(id, Event::Cast, &actives[idx as usize..=idx as usize]); @@ -1588,6 +1644,18 @@ impl Game { } } + pub fn truedr(&self, id: i32) -> i32 { + self.get(id, Stat::hp) + self.trigger_pure(Event::Buff, id, 0) + } + + pub fn truehp(&self, id: i32) -> i32 { + self.get(id, Stat::hp) + self.calcBonusHp(id) + } + + pub fn trueatk(&self, id: i32) -> i32 { + self.trueatk_adrenaline(id, self.get(id, Stat::adrenaline)) + } + pub fn trueatk_adrenaline(&self, id: i32, adrenaline: i32) -> i32 { let dmg = self.get(id, Stat::atk) + self.get(id, Stat::dive) @@ -1971,7 +2039,7 @@ impl Game { } pub fn transform(&mut self, c: i32, code: i32) { - let card = self.get_card(code); + let card = self.cards.get(code); let thing = self.get_thing_mut(c); thing.status.insert(Stat::card, code); thing.status.insert(Stat::hp, card.health as i32); @@ -2620,7 +2688,7 @@ impl Game { } for (i, &cr) in self.get_player(id).creatures.clone().iter().enumerate() { if cr != 0 { - let crcard = self.get_card(self.get(cr, Stat::card)); + let crcard = self.cards.get(self.get(cr, Stat::card)); if patienceFlag { let floodbuff = if i > floodingIndex && crcard.element == etg::Water as i8 { 5 @@ -2744,7 +2812,7 @@ impl Game { } pub fn play(&mut self, c: i32, t: i32, fromhand: bool) { - let kind = self.get_card(self.get(c, Stat::card)).kind; + let kind = self.cards.get(self.get(c, Stat::card)).kind; self.remove(c); if kind == Kind::Spell { self.castSpell(c, t, self.getSkill(c, Event::Cast)[0]) diff --git a/src/views/Match.jsx b/src/views/Match.jsx index a5f00449..a74980a0 100644 --- a/src/views/Match.jsx +++ b/src/views/Match.jsx @@ -420,49 +420,7 @@ function Thing(props) { const memo = createMemo(() => { if (faceDown()) return {}; - let statText, topText; - if (!isSpell()) { - const charges = props.game.get(props.id, 'charges'); - topText = props.game.active_text(props.id); - if (props.game.get_kind(props.id) === Kind.Creature) { - statText = `${props.game.trueatk(props.id)} | ${props.game.truehp( - props.id, - )}${charges ? ` \u00d7${charges}` : ''}`; - } else if (props.game.get_kind(props.id) === Kind.Permanent) { - if (props.game.get(props.id, 'pillar')) { - statText = `1:${ - props.game.get(props.id, 'pendstate') - ? props.game.get_mark(props.game.get_owner(props.id)) - : props.game.getCard(props.id).element - }\u00d7${charges}`; - topText = ''; - } else { - const ownattack = props.game.getSkill(props.id, 'ownattack'); - if (ownattack === 'locket') { - const mode = props.game.get(props.id, 'mode'); - statText = `1:${ - ~mode ? mode : props.game.get_mark(props.game.get_owner(props.id)) - }`; - } else { - statText = `${charges || ''}`; - } - } - } else if (props.game.get_kind(props.id) === Kind.Weapon) { - statText = `${props.game.trueatk(props.id)}${ - charges ? ` \u00d7${charges}` : '' - }`; - } else if (props.game.get_kind(props.id) === Kind.Shield) { - statText = charges - ? '\u00d7' + charges - : props.game.truedr(props.id).toString(); - } - } else { - topText = props.game.getCard(props.id).name; - statText = `${props.game.get(props.id, 'cost')}:${props.game.get( - props.id, - 'costele', - )}`; - } + const [topText, statText] = props.game.instance_text(props.id).split('\n'); return { topText, statText }; }); @@ -876,7 +834,7 @@ export default function Match(props) { element: card.element, costele: game.get(id, isSpell ? 'costele' : 'castele'), cost: game.get(id, isSpell ? 'cost' : 'cast'), - name: isSpell ? card.name : game.getSkill(id, 'cast'), + name: isSpell ? card.name : game.get_cast_skill(id), upped: card.upped, shiny: card.shiny, c: id, @@ -1202,7 +1160,7 @@ export default function Match(props) { cb(tgt); setTargeting(null); }, - text: game.getSkill(id, 'cast'), + text: game.get_cast_skill(id), src: id, }); }