skill components

This commit is contained in:
ntr 2019-05-22 13:49:18 +10:00
parent 9f15bf1def
commit 8cc4eba05d
5 changed files with 109 additions and 70 deletions

View File

@ -100,7 +100,7 @@ function Info(args) {
if (!(combiner.every(u => u === null))) { if (!(combiner.every(u => u === null))) {
const filteredCombos = itemInfo.combos const filteredCombos = itemInfo.combos
.filter(combo => combiner.every(u => u === null .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; if (filteredCombos.length > 6) return false;
return ( return (
<table> <table>
@ -108,14 +108,14 @@ function Info(args) {
{filteredCombos.map((c, i) => {filteredCombos.map((c, i) =>
<tr key={i} > <tr key={i} >
<td className="highlight" >{convertItem(c.item)}</td> <td className="highlight" >{convertItem(c.item)}</td>
{c.units.map((u, j) => <td key={j}>{convertItem(u)}</td>)} {c.components.map((u, j) => <td key={j}>{convertItem(u)}</td>)}
</tr> </tr>
)} )}
</tbody> </tbody>
</table> </table>
); );
} }
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; if (vboxCombos.length > 6) return false;
return ( return (
<table className="combos"> <table className="combos">
@ -123,7 +123,7 @@ function Info(args) {
{vboxCombos.map((c, i) => {vboxCombos.map((c, i) =>
<tr key={i} > <tr key={i} >
<td className="highlight" >{convertItem(c.item)}</td> <td className="highlight" >{convertItem(c.item)}</td>
{c.units.map((u, j) => <td key={j} >{convertItem(u)}</td>)} {c.components.map((u, j) => <td key={j} >{convertItem(u)}</td>)}
</tr> </tr>
)} )}
</tbody> </tbody>

View File

@ -113,10 +113,10 @@ function Vbox(args) {
const combinerValues = newCombiner.map(cv => player.vbox.bound[cv]).filter(cv => cv); const combinerValues = newCombiner.map(cv => player.vbox.bound[cv]).filter(cv => cv);
const filteredCombos = itemInfo.combos 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 => { 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; if (!['Red', 'Green', 'Blue'].includes(v.item) && combinerValues.includes(v.item)) return false;
return true; return true;
}); });

View File

@ -98,7 +98,7 @@ impl Item {
let combos = get_combos(); let combos = get_combos();
let combo = combos.iter().find(|c| c.item == *self); let combo = combos.iter().find(|c| c.item == *self);
match combo { 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::Red => count.red += 1,
Item::Blue => count.blue += 1, Item::Blue => count.blue += 1,
Item::Green => count.green += 1, Item::Green => count.green += 1,
@ -114,6 +114,16 @@ impl Item {
} }
} }
pub fn components(&self) -> Vec<Item> {
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::<Vec<Item>>(),
None => vec![*self],
}
}
pub fn cost(&self) -> u16 { pub fn cost(&self) -> u16 {
match self { match self {
Item::Red => 1, Item::Red => 1,
@ -134,7 +144,7 @@ impl Item {
let combos = get_combos(); let combos = get_combos();
let combo = combos.iter().find(|c| c.item == *self) let combo = combos.iter().find(|c| c.item == *self)
.unwrap_or_else(|| panic!("unable to find components for {:?}", 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 combos = get_combos();
let combo = combos.iter().find(|c| c.item == *self) let combo = combos.iter().find(|c| c.item == *self)
.unwrap_or_else(|| panic!("unable to find components for {:?}", 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<Spec> for Item {
#[derive(Debug,Clone,Serialize,Deserialize)] #[derive(Debug,Clone,Serialize,Deserialize)]
pub struct Combo { pub struct Combo {
pub item: Item, pub item: Item,
pub units: Vec<Item>, pub components: Vec<Item>,
} }
pub fn get_combos() -> Vec<Combo> { pub fn get_combos() -> Vec<Combo> {
let mut combinations = vec![ let mut combinations = vec![
Combo { units: vec![Item::Buff, Item::Red, Item::Red], item: Item::Taunt }, Combo { components: vec![Item::Buff, Item::Red, Item::Red], item: Item::Taunt },
Combo { units: vec![Item::Buff, Item::Green, Item::Green], item: Item::Triage }, Combo { components: 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 { components: 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 { components: vec![Item::Buff, Item::Red, Item::Green], item: Item::Haste },
Combo { units: vec![Item::Buff, Item::Green, Item::Blue], item: Item::Impurity }, Combo { components: 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::Blue], item: Item::Amplify }, // Some flavour
Combo { units: vec![Item::Debuff, Item::Red, Item::Red], item: Item::Snare }, Combo { components: 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 { components: 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 { components: 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 { components: 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 { components: 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::Blue], item: Item::Invert },
Combo { units: vec![Item::Block, Item::Red, Item::Red], item: Item::Parry }, // Add red recharge Combo { components: 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 { components: vec![Item::Block, Item::Green, Item::Green], item: Item::Purify },
Combo { units: vec![Item::Block, Item::Blue, Item::Blue], item: Item::Corrupt }, Combo { components: vec![Item::Block, Item::Blue, Item::Blue], item: Item::Corrupt },
Combo { units: vec![Item::Block, Item::Red, Item::Green], item: Item::Clutch }, Combo { components: vec![Item::Block, Item::Red, Item::Green], item: Item::Clutch },
Combo { units: vec![Item::Block, Item::Green, Item::Blue], item: Item::Reflect }, Combo { components: 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::Blue], item: Item::Recharge },
Combo { units: vec![Item::Stun, Item::Red, Item::Red], item: Item::Strangle }, Combo { components: vec![Item::Stun, Item::Red, Item::Red], item: Item::Strangle },
Combo { units: vec![Item::Stun, Item::Green, Item::Green], item: Item::Sleep }, Combo { components: vec![Item::Stun, Item::Green, Item::Green], item: Item::Sleep },
Combo { units: vec![Item::Stun, Item::Blue, Item::Blue], item: Item::Ruin }, Combo { components: vec![Item::Stun, Item::Blue, Item::Blue], item: Item::Ruin },
Combo { units: vec![Item::Stun, Item::Red, Item::Green], item: Item::Throw }, Combo { components: vec![Item::Stun, Item::Red, Item::Green], item: Item::Throw },
Combo { units: vec![Item::Stun, Item::Green, Item::Blue], item: Item::Hex }, Combo { components: 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::Blue], item: Item::Banish },
Combo { units: vec![Item::Attack, Item::Red, Item::Red], item: Item::Strike }, Combo { components: vec![Item::Attack, Item::Red, Item::Red], item: Item::Strike },
Combo { units: vec![Item::Strike, Item::Strike, Item::Strike], item: Item::StrikeII }, Combo { components: 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::StrikeII, Item::StrikeII, Item::StrikeII], item: Item::StrikeIII },
Combo { units: vec![Item::Attack, Item::Green, Item::Green], item: Item::Heal }, Combo { components: vec![Item::Attack, Item::Green, Item::Green], item: Item::Heal },
Combo { units: vec![Item::Attack, Item::Blue, Item::Blue], item: Item::Blast }, Combo { components: vec![Item::Attack, Item::Blue, Item::Blue], item: Item::Blast },
Combo { units: vec![Item::Attack, Item::Red, Item::Green], item: Item::Slay }, Combo { components: vec![Item::Attack, Item::Red, Item::Green], item: Item::Slay },
Combo { units: vec![Item::Attack, Item::Green, Item::Blue], item: Item::Siphon }, Combo { components: 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::Red, Item::Blue], item: Item::Chaos },
Combo { units: vec![Item::Damage, Item::Red, Item::Red], item: Item::RedDamageI }, Combo { components: vec![Item::Damage, Item::Red, Item::Red], item: Item::RedDamageI },
Combo { units: vec![Item::Damage, Item::Green, Item::Green], item: Item::GreenDamageI }, Combo { components: vec![Item::Damage, Item::Green, Item::Green], item: Item::GreenDamageI },
Combo { units: vec![Item::Damage, Item::Blue, Item::Blue], item: Item::BlueDamageI }, Combo { components: vec![Item::Damage, Item::Blue, Item::Blue], item: Item::BlueDamageI },
Combo { units: vec![Item::Damage, Item::Red, Item::Green], item: Item::GRDI }, Combo { components: vec![Item::Damage, Item::Red, Item::Green], item: Item::GRDI },
Combo { units: vec![Item::Damage, Item::Green, Item::Blue], item: Item::GBDI }, Combo { components: 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::Blue], item: Item::RBDI },
Combo { units: vec![Item::Life, Item::Red, Item::Red], item: Item::RedLifeI }, Combo { components: vec![Item::Life, Item::Red, Item::Red], item: Item::RedLifeI },
Combo { units: vec![Item::Life, Item::Green, Item::Green], item: Item::GreenLifeI }, Combo { components: vec![Item::Life, Item::Green, Item::Green], item: Item::GreenLifeI },
Combo { units: vec![Item::Life, Item::Blue, Item::Blue], item: Item::BlueLifeI }, Combo { components: vec![Item::Life, Item::Blue, Item::Blue], item: Item::BlueLifeI },
Combo { units: vec![Item::Life, Item::Red, Item::Green], item: Item::GRLI }, Combo { components: vec![Item::Life, Item::Red, Item::Green], item: Item::GRLI },
Combo { units: vec![Item::Life, Item::Green, Item::Blue], item: Item::GBLI }, Combo { components: 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::Blue], item: Item::RBLI },
Combo { units: vec![Item::Speed, Item::Red, Item::Red], item: Item::RedSpeedI }, Combo { components: vec![Item::Speed, Item::Red, Item::Red], item: Item::RedSpeedI },
Combo { units: vec![Item::Speed, Item::Green, Item::Green], item: Item::GreenSpeedI }, Combo { components: vec![Item::Speed, Item::Green, Item::Green], item: Item::GreenSpeedI },
Combo { units: vec![Item::Speed, Item::Blue, Item::Blue], item: Item::BlueSpeedI }, Combo { components: vec![Item::Speed, Item::Blue, Item::Blue], item: Item::BlueSpeedI },
Combo { units: vec![Item::Speed, Item::Red, Item::Green], item: Item::GRSpeedI }, Combo { components: vec![Item::Speed, Item::Red, Item::Green], item: Item::GRSpeedI },
Combo { units: vec![Item::Speed, Item::Green, Item::Blue], item: Item::GBSpeedI }, Combo { components: 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::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; return combinations;
} }
@ -628,8 +638,8 @@ pub fn item_info() -> ItemInfoCtr {
let mut items = combos let mut items = combos
.into_iter() .into_iter()
.flat_map(|mut c| { .flat_map(|mut c| {
c.units.push(c.item); c.components.push(c.item);
c.units c.components
}) })
.collect::<Vec<Item>>(); .collect::<Vec<Item>>();
@ -653,3 +663,32 @@ pub fn item_info() -> ItemInfoCtr {
items, 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,
]);
}
}

View File

@ -409,11 +409,7 @@ impl Effect {
Effect::Banish => true, Effect::Banish => true,
Effect::Strangle => true, Effect::Strangle => true,
Effect::Strangling => skill != Skill::StrangleTick, Effect::Strangling => skill != Skill::StrangleTick,
Effect::Silence => match skill.category() { Effect::Silence => skill.components().contains(Item::Blue),
Category::Blue => true,
Category::Red => false,
_ => false,
},
Effect::Snare => match skill.category() { Effect::Snare => match skill.category() {
Category::Blue => false, Category::Blue => false,
Category::Red => true, Category::Red => true,
@ -949,6 +945,10 @@ impl Skill {
_ => false, _ => false,
} }
} }
pub fn components(&self) -> Vec<Item> {
Item::from(*self).components()
}
} }
fn touch(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { fn touch(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {

View File

@ -146,7 +146,7 @@ impl Vbox {
// combos are sorted when created // combos are sorted when created
input.sort_unstable(); input.sort_unstable();
let combos = get_combos(); 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.push(combo.item);
self.bound.sort_unstable(); self.bound.sort_unstable();
@ -211,7 +211,7 @@ mod tests {
// sort input so they align // sort input so they align
input.sort_unstable(); 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()); assert!(combo.is_some());
} }