From 8cc4eba05de8b4be0dcd8478d3d49eae7c0693bf Mon Sep 17 00:00:00 2001 From: ntr Date: Wed, 22 May 2019 13:49:18 +1000 Subject: [PATCH] skill components --- client/src/components/info.component.jsx | 8 +- client/src/components/vbox.component.jsx | 4 +- server/src/item.rs | 153 ++++++++++++++--------- server/src/skill.rs | 10 +- server/src/vbox.rs | 4 +- 5 files changed, 109 insertions(+), 70 deletions(-) diff --git a/client/src/components/info.component.jsx b/client/src/components/info.component.jsx index 89dd44ca..2c7f2dc8 100644 --- a/client/src/components/info.component.jsx +++ b/client/src/components/info.component.jsx @@ -100,7 +100,7 @@ function Info(args) { if (!(combiner.every(u => u === null))) { const filteredCombos = itemInfo.combos .filter(combo => combiner.every(u => u === null - || combo.units.includes(player.vbox.bound[u]))); + || combo.components.includes(player.vbox.bound[u]))); if (filteredCombos.length > 6) return false; return ( @@ -108,14 +108,14 @@ function Info(args) { {filteredCombos.map((c, i) => - {c.units.map((u, j) => )} + {c.components.map((u, j) => )} )}
{convertItem(c.item)}{convertItem(u)}{convertItem(u)}
); } - const vboxCombos = itemInfo.combos.filter(c => c.units.includes(info)); + const vboxCombos = itemInfo.combos.filter(c => c.components.includes(info)); if (vboxCombos.length > 6) return false; return ( @@ -123,7 +123,7 @@ function Info(args) { {vboxCombos.map((c, i) => - {c.units.map((u, j) => )} + {c.components.map((u, j) => )} )} diff --git a/client/src/components/vbox.component.jsx b/client/src/components/vbox.component.jsx index 181104ca..df699660 100644 --- a/client/src/components/vbox.component.jsx +++ b/client/src/components/vbox.component.jsx @@ -113,10 +113,10 @@ function Vbox(args) { const combinerValues = newCombiner.map(cv => player.vbox.bound[cv]).filter(cv => cv); const filteredCombos = itemInfo.combos - .filter(combo => combinerValues.every(u => combo.units.includes(u))); + .filter(combo => combinerValues.every(u => combo.components.includes(u))); const comboValues = itemInfo.items.filter(v => { - if (!filteredCombos.some(c => c.units.includes(v.item))) return false; + if (!filteredCombos.some(c => c.components.includes(v.item))) return false; if (!['Red', 'Green', 'Blue'].includes(v.item) && combinerValues.includes(v.item)) return false; return true; }); diff --git a/server/src/item.rs b/server/src/item.rs index 97e1c040..2bdab2c8 100644 --- a/server/src/item.rs +++ b/server/src/item.rs @@ -98,7 +98,7 @@ impl Item { let combos = get_combos(); let combo = combos.iter().find(|c| c.item == *self); match combo { - Some(c) => c.units.iter().for_each(|unit| match unit { + Some(c) => c.components.iter().for_each(|unit| match unit { Item::Red => count.red += 1, Item::Blue => count.blue += 1, Item::Green => count.green += 1, @@ -114,6 +114,16 @@ impl Item { } } + pub fn components(&self) -> Vec { + let combos = get_combos(); + let combo = combos.iter().find(|c| c.item == *self); + + match combo { + Some(c) => c.components.iter().flat_map(|c| c.components()).collect::>(), + None => vec![*self], + } + } + pub fn cost(&self) -> u16 { match self { Item::Red => 1, @@ -134,7 +144,7 @@ impl Item { let combos = get_combos(); let combo = combos.iter().find(|c| c.item == *self) .unwrap_or_else(|| panic!("unable to find components for {:?}", self)); - return combo.units.iter().fold(0, |acc, c| acc + c.cost()); + return combo.components.iter().fold(0, |acc, c| acc + c.cost()); }, } } @@ -155,7 +165,7 @@ impl Item { let combos = get_combos(); let combo = combos.iter().find(|c| c.item == *self) .unwrap_or_else(|| panic!("unable to find components for {:?}", self)); - return combo.units.iter().fold(0, |acc, c| acc + c.speed()); + return combo.components.iter().fold(0, |acc, c| acc + c.speed()); }, } } @@ -537,73 +547,73 @@ impl From for Item { #[derive(Debug,Clone,Serialize,Deserialize)] pub struct Combo { pub item: Item, - pub units: Vec, + pub components: Vec, } pub fn get_combos() -> Vec { let mut combinations = vec![ - Combo { units: vec![Item::Buff, Item::Red, Item::Red], item: Item::Taunt }, - Combo { units: vec![Item::Buff, Item::Green, Item::Green], item: Item::Triage }, - Combo { units: vec![Item::Buff, Item::Blue, Item::Blue], item: Item::Scatter }, //To be impl - Combo { units: vec![Item::Buff, Item::Red, Item::Green], item: Item::Haste }, - Combo { units: vec![Item::Buff, Item::Green, Item::Blue], item: Item::Impurity }, - Combo { units: vec![Item::Buff, Item::Red, Item::Blue], item: Item::Amplify }, // Some flavour + Combo { components: vec![Item::Buff, Item::Red, Item::Red], item: Item::Taunt }, + Combo { components: vec![Item::Buff, Item::Green, Item::Green], item: Item::Triage }, + Combo { components: vec![Item::Buff, Item::Blue, Item::Blue], item: Item::Scatter }, //To be impl + Combo { components: vec![Item::Buff, Item::Red, Item::Green], item: Item::Haste }, + Combo { components: vec![Item::Buff, Item::Green, Item::Blue], item: Item::Impurity }, + Combo { components: vec![Item::Buff, Item::Red, Item::Blue], item: Item::Amplify }, // Some flavour - Combo { units: vec![Item::Debuff, Item::Red, Item::Red], item: Item::Snare }, - Combo { units: vec![Item::Debuff, Item::Green, Item::Green], item: Item::Purge }, // Needs flavour - Combo { units: vec![Item::Debuff, Item::Blue, Item::Blue], item: Item::Silence }, - Combo { units: vec![Item::Debuff, Item::Red, Item::Green], item: Item::Curse }, // To be reworked - Combo { units: vec![Item::Debuff, Item::Green, Item::Blue], item: Item::Decay }, - Combo { units: vec![Item::Debuff, Item::Red, Item::Blue], item: Item::Invert }, + Combo { components: vec![Item::Debuff, Item::Red, Item::Red], item: Item::Snare }, + Combo { components: vec![Item::Debuff, Item::Green, Item::Green], item: Item::Purge }, // Needs flavour + Combo { components: vec![Item::Debuff, Item::Blue, Item::Blue], item: Item::Silence }, + Combo { components: vec![Item::Debuff, Item::Red, Item::Green], item: Item::Curse }, // To be reworked + Combo { components: vec![Item::Debuff, Item::Green, Item::Blue], item: Item::Decay }, + Combo { components: vec![Item::Debuff, Item::Red, Item::Blue], item: Item::Invert }, - Combo { units: vec![Item::Block, Item::Red, Item::Red], item: Item::Parry }, // Add red recharge - Combo { units: vec![Item::Block, Item::Green, Item::Green], item: Item::Purify }, - Combo { units: vec![Item::Block, Item::Blue, Item::Blue], item: Item::Corrupt }, - Combo { units: vec![Item::Block, Item::Red, Item::Green], item: Item::Clutch }, - Combo { units: vec![Item::Block, Item::Green, Item::Blue], item: Item::Reflect }, - Combo { units: vec![Item::Block, Item::Red, Item::Blue], item: Item::Recharge }, + Combo { components: vec![Item::Block, Item::Red, Item::Red], item: Item::Parry }, // Add red recharge + Combo { components: vec![Item::Block, Item::Green, Item::Green], item: Item::Purify }, + Combo { components: vec![Item::Block, Item::Blue, Item::Blue], item: Item::Corrupt }, + Combo { components: vec![Item::Block, Item::Red, Item::Green], item: Item::Clutch }, + Combo { components: vec![Item::Block, Item::Green, Item::Blue], item: Item::Reflect }, + Combo { components: vec![Item::Block, Item::Red, Item::Blue], item: Item::Recharge }, - Combo { units: vec![Item::Stun, Item::Red, Item::Red], item: Item::Strangle }, - Combo { units: vec![Item::Stun, Item::Green, Item::Green], item: Item::Sleep }, - Combo { units: vec![Item::Stun, Item::Blue, Item::Blue], item: Item::Ruin }, - Combo { units: vec![Item::Stun, Item::Red, Item::Green], item: Item::Throw }, - Combo { units: vec![Item::Stun, Item::Green, Item::Blue], item: Item::Hex }, - Combo { units: vec![Item::Stun, Item::Red, Item::Blue], item: Item::Banish }, + Combo { components: vec![Item::Stun, Item::Red, Item::Red], item: Item::Strangle }, + Combo { components: vec![Item::Stun, Item::Green, Item::Green], item: Item::Sleep }, + Combo { components: vec![Item::Stun, Item::Blue, Item::Blue], item: Item::Ruin }, + Combo { components: vec![Item::Stun, Item::Red, Item::Green], item: Item::Throw }, + Combo { components: vec![Item::Stun, Item::Green, Item::Blue], item: Item::Hex }, + Combo { components: vec![Item::Stun, Item::Red, Item::Blue], item: Item::Banish }, - Combo { units: vec![Item::Attack, Item::Red, Item::Red], item: Item::Strike }, - Combo { units: vec![Item::Strike, Item::Strike, Item::Strike], item: Item::StrikeII }, - Combo { units: vec![Item::StrikeII, Item::StrikeII, Item::StrikeII], item: Item::StrikeIII }, + Combo { components: vec![Item::Attack, Item::Red, Item::Red], item: Item::Strike }, + Combo { components: vec![Item::Strike, Item::Strike, Item::Strike], item: Item::StrikeII }, + Combo { components: vec![Item::StrikeII, Item::StrikeII, Item::StrikeII], item: Item::StrikeIII }, - Combo { units: vec![Item::Attack, Item::Green, Item::Green], item: Item::Heal }, - Combo { units: vec![Item::Attack, Item::Blue, Item::Blue], item: Item::Blast }, - Combo { units: vec![Item::Attack, Item::Red, Item::Green], item: Item::Slay }, - Combo { units: vec![Item::Attack, Item::Green, Item::Blue], item: Item::Siphon }, - Combo { units: vec![Item::Attack, Item::Red, Item::Blue], item: Item::Chaos }, + Combo { components: vec![Item::Attack, Item::Green, Item::Green], item: Item::Heal }, + Combo { components: vec![Item::Attack, Item::Blue, Item::Blue], item: Item::Blast }, + Combo { components: vec![Item::Attack, Item::Red, Item::Green], item: Item::Slay }, + Combo { components: vec![Item::Attack, Item::Green, Item::Blue], item: Item::Siphon }, + Combo { components: vec![Item::Attack, Item::Red, Item::Blue], item: Item::Chaos }, - Combo { units: vec![Item::Damage, Item::Red, Item::Red], item: Item::RedDamageI }, - Combo { units: vec![Item::Damage, Item::Green, Item::Green], item: Item::GreenDamageI }, - Combo { units: vec![Item::Damage, Item::Blue, Item::Blue], item: Item::BlueDamageI }, - Combo { units: vec![Item::Damage, Item::Red, Item::Green], item: Item::GRDI }, - Combo { units: vec![Item::Damage, Item::Green, Item::Blue], item: Item::GBDI }, - Combo { units: vec![Item::Damage, Item::Red, Item::Blue], item: Item::RBDI }, + Combo { components: vec![Item::Damage, Item::Red, Item::Red], item: Item::RedDamageI }, + Combo { components: vec![Item::Damage, Item::Green, Item::Green], item: Item::GreenDamageI }, + Combo { components: vec![Item::Damage, Item::Blue, Item::Blue], item: Item::BlueDamageI }, + Combo { components: vec![Item::Damage, Item::Red, Item::Green], item: Item::GRDI }, + Combo { components: vec![Item::Damage, Item::Green, Item::Blue], item: Item::GBDI }, + Combo { components: vec![Item::Damage, Item::Red, Item::Blue], item: Item::RBDI }, - Combo { units: vec![Item::Life, Item::Red, Item::Red], item: Item::RedLifeI }, - Combo { units: vec![Item::Life, Item::Green, Item::Green], item: Item::GreenLifeI }, - Combo { units: vec![Item::Life, Item::Blue, Item::Blue], item: Item::BlueLifeI }, - Combo { units: vec![Item::Life, Item::Red, Item::Green], item: Item::GRLI }, - Combo { units: vec![Item::Life, Item::Green, Item::Blue], item: Item::GBLI }, - Combo { units: vec![Item::Life, Item::Red, Item::Blue], item: Item::RBLI }, + Combo { components: vec![Item::Life, Item::Red, Item::Red], item: Item::RedLifeI }, + Combo { components: vec![Item::Life, Item::Green, Item::Green], item: Item::GreenLifeI }, + Combo { components: vec![Item::Life, Item::Blue, Item::Blue], item: Item::BlueLifeI }, + Combo { components: vec![Item::Life, Item::Red, Item::Green], item: Item::GRLI }, + Combo { components: vec![Item::Life, Item::Green, Item::Blue], item: Item::GBLI }, + Combo { components: vec![Item::Life, Item::Red, Item::Blue], item: Item::RBLI }, - Combo { units: vec![Item::Speed, Item::Red, Item::Red], item: Item::RedSpeedI }, - Combo { units: vec![Item::Speed, Item::Green, Item::Green], item: Item::GreenSpeedI }, - Combo { units: vec![Item::Speed, Item::Blue, Item::Blue], item: Item::BlueSpeedI }, - Combo { units: vec![Item::Speed, Item::Red, Item::Green], item: Item::GRSpeedI }, - Combo { units: vec![Item::Speed, Item::Green, Item::Blue], item: Item::GBSpeedI }, - Combo { units: vec![Item::Speed, Item::Red, Item::Blue], item: Item::RBSpeedI }, + Combo { components: vec![Item::Speed, Item::Red, Item::Red], item: Item::RedSpeedI }, + Combo { components: vec![Item::Speed, Item::Green, Item::Green], item: Item::GreenSpeedI }, + Combo { components: vec![Item::Speed, Item::Blue, Item::Blue], item: Item::BlueSpeedI }, + Combo { components: vec![Item::Speed, Item::Red, Item::Green], item: Item::GRSpeedI }, + Combo { components: vec![Item::Speed, Item::Green, Item::Blue], item: Item::GBSpeedI }, + Combo { components: vec![Item::Speed, Item::Red, Item::Blue], item: Item::RBSpeedI }, ]; - combinations.iter_mut().for_each(|set| set.units.sort_unstable()); + combinations.iter_mut().for_each(|set| set.components.sort_unstable()); return combinations; } @@ -628,8 +638,8 @@ pub fn item_info() -> ItemInfoCtr { let mut items = combos .into_iter() .flat_map(|mut c| { - c.units.push(c.item); - c.units + c.components.push(c.item); + c.components }) .collect::>(); @@ -653,3 +663,32 @@ pub fn item_info() -> ItemInfoCtr { items, }; } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn item_components_test() { + assert_eq!(Item::Strike.components(), vec![Item::Red, Item::Red, Item::Attack]); + assert_eq!(Item::StrikeII.components(), vec![ + Item::Red, Item::Red, Item::Attack, + Item::Red, Item::Red, Item::Attack, + Item::Red, Item::Red, Item::Attack, + ]); + assert_eq!(Item::StrikeIII.components(), vec![ + Item::Red, Item::Red, Item::Attack, + Item::Red, Item::Red, Item::Attack, + Item::Red, Item::Red, Item::Attack, + + Item::Red, Item::Red, Item::Attack, + Item::Red, Item::Red, Item::Attack, + Item::Red, Item::Red, Item::Attack, + + Item::Red, Item::Red, Item::Attack, + Item::Red, Item::Red, Item::Attack, + Item::Red, Item::Red, Item::Attack, + ]); + + } +} \ No newline at end of file diff --git a/server/src/skill.rs b/server/src/skill.rs index 99d08f9e..c6598136 100644 --- a/server/src/skill.rs +++ b/server/src/skill.rs @@ -409,11 +409,7 @@ impl Effect { Effect::Banish => true, Effect::Strangle => true, Effect::Strangling => skill != Skill::StrangleTick, - Effect::Silence => match skill.category() { - Category::Blue => true, - Category::Red => false, - _ => false, - }, + Effect::Silence => skill.components().contains(Item::Blue), Effect::Snare => match skill.category() { Category::Blue => false, Category::Red => true, @@ -949,6 +945,10 @@ impl Skill { _ => false, } } + + pub fn components(&self) -> Vec { + Item::from(*self).components() + } } fn touch(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { diff --git a/server/src/vbox.rs b/server/src/vbox.rs index 309ebc16..b3e61de6 100644 --- a/server/src/vbox.rs +++ b/server/src/vbox.rs @@ -146,7 +146,7 @@ impl Vbox { // combos are sorted when created input.sort_unstable(); let combos = get_combos(); - let combo = combos.iter().find(|c| c.units == input).ok_or(err_msg("not a combo"))?; + let combo = combos.iter().find(|c| c.components == input).ok_or(err_msg("not a combo"))?; self.bound.push(combo.item); self.bound.sort_unstable(); @@ -211,7 +211,7 @@ mod tests { // sort input so they align input.sort_unstable(); - let combo = combos.iter().find(|c| c.units == input); + let combo = combos.iter().find(|c| c.components == input); assert!(combo.is_some()); }
{convertItem(c.item)}{convertItem(u)}{convertItem(u)}