Skip to content

Commit

Permalink
Add FireTrigger period option;
Browse files Browse the repository at this point in the history
Add FindUnit expression;
Add Guardian;
  • Loading branch information
makscee committed Mar 6, 2024
1 parent 37cd849 commit fb3b679
Show file tree
Hide file tree
Showing 12 changed files with 624 additions and 406 deletions.
849 changes: 463 additions & 386 deletions assets/ron/custom.battle.ron

Large diffs are not rendered by default.

39 changes: 34 additions & 5 deletions assets/ron/heroes/equalizer.unit.ron
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,46 @@
),
children: [],
mapping: {
Rotation: Sum(Mul(Mul(PI, Float(0.25)), Index), Mul(Sin(Mul(Sum(GameTime, Mul(Index, Sum(Float(0.2), Beat))), Float(0.5))), Float(0.5))),
Rotation: Sum(
Mul(
Mul(
PI,
Float(
0.25,
),
),
Index,
),
Mul(
Sin(
Mul(
Sum(
GameTime,
Mul(
Index,
Sum(
Float(
0.2,
),
Beat,
),
),
),
Float(
0.5,
),
),
),
Float(0.5),
),
),
},
count: 8,
),
],
mapping: {},
count: 0,
),
state: (
history: {},
birth: 0.0,
),
state: (history: {}, birth: 0.0),
statuses: [],
)
30 changes: 30 additions & 0 deletions assets/ron/heroes/guardian.unit.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(
name: "Guardian",
hp: 2,
atk: 1,
stacks: 1,
level: 1,
houses: "Paladins",
description: "%trigger → %effect on ally that doesn\'t have [Shield]",
trigger: Fire(
trigger: BattleStart,
target: FindUnit(Equals(StatusCharges(String("Shield")), Zero)),
effect: UseAbility("Shield"),
period: 1,
),
representation: (
material: Shape(
shape: Circle,
fill: Line,
size: Vec2E(Float(0.8)),
thickness: Float(0.6),
alpha: Float(1.0),
color: State(Color),
),
children: [],
mapping: {
Offset: Mul(UnitVec(Mul(Sum(Index, Int(1)), Mul(PI, Float(0.1)))), Mul(Float(0.3), Sin(Sum(GameTime, Mul(Beat, Float(0.5)))))),
},
count: 9,
),
)
26 changes: 21 additions & 5 deletions assets/ron/heroes/trimmer.unit.ron
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,33 @@
),
children: [],
mapping: {
Rotation: Sum(Mul(Mul(PI, Float(0.25)), Index), Mul(Sin(Sum(GameTime, Index)), Float(0.3))),
Rotation: Sum(
Mul(
Mul(
PI,
Float(
0.25,
),
),
Index,
),
Mul(
Sin(
Sum(
GameTime,
Index,
),
),
Float(0.3),
),
),
},
count: 2,
),
],
mapping: {},
count: 0,
),
state: (
history: {},
birth: 0.0,
),
state: (history: {}, birth: 0.0),
statuses: [],
)
4 changes: 1 addition & 3 deletions assets/ron/houses/alchemists.house.ron
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
description: "Next taken damage is fatal",
effect: List(
[
AddStatus(
"Petrify",
),
AddStatus("Petrify"),
Vfx("apply_status"),
],
),
Expand Down
2 changes: 1 addition & 1 deletion assets/ron/vfx/apply_status.vfx.ron
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
(
material: Curve(
color: Hex("#263238"),
curvature: Float(1.6),
curvature: Float(2.0),
thickness: Mul(
Float(0.2),
State(Thickness),
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/hero_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,15 @@ impl HeroEditorPlugin {
trigger,
target,
effect,
period,
} => {
CollapsingHeader::new("Trigger").default_open(true).show(
ui,
|ui| {
ui.horizontal(|ui| {
ui.label("period:");
DragValue::new(period).ui(ui);
});
trigger.show_editor(entity, ui);
match trigger {
FireTrigger::List(list) => {
Expand Down Expand Up @@ -756,6 +761,7 @@ impl EditorNodeGenerator for Expression {
| Expression::SlotUnit(x)
| Expression::FactionCount(x)
| Expression::FilterMaxEnemy(x)
| Expression::FindUnit(x)
| Expression::StatusCharges(x) => show_node(
x.as_mut(),
format!("{path}:x"),
Expand Down Expand Up @@ -862,7 +868,7 @@ impl EditorNodeGenerator for Expression {
}

fn show_replace_buttons(&mut self, lookup: &str, submit: bool, ui: &mut Ui) -> bool {
for (e, s) in Expression::iter()
for (e, _) in Expression::iter()
.filter_map(|e| {
let s = e.to_string().to_lowercase();
match s.contains(lookup) {
Expand Down
21 changes: 21 additions & 0 deletions src/resourses/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ impl ContextLayer {
_ => None,
}
}
pub fn get_status(&self) -> Option<Entity> {
match self {
ContextLayer::Status(entity, ..) => Some(*entity),
_ => None,
}
}
pub fn get_var(&self, var: VarName, world: &World) -> Option<VarValue> {
match self {
ContextLayer::Owner(entity, ..) => {
Expand Down Expand Up @@ -204,6 +210,21 @@ impl Context {
self.stack(ContextLayer::Status(entity, name), world)
}

pub fn status(&self) -> Entity {
self.get_status().expect("Target not found")
}

pub fn get_status(&self) -> Option<Entity> {
let mut result = None;
for layer in self.layers.iter().rev() {
result = layer.get_status();
if result.is_some() {
break;
}
}
result
}

pub fn take(&mut self) -> Self {
mem::take(self)
}
Expand Down
21 changes: 20 additions & 1 deletion src/resourses/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub enum Expression {
FactionCount(Box<Expression>),
StatusCharges(Box<Expression>),
FilterMaxEnemy(Box<Expression>),
FindUnit(Box<Expression>),

Vec2EE(Box<Expression>, Box<Expression>),
Sum(Box<Expression>, Box<Expression>),
Expand Down Expand Up @@ -303,7 +304,7 @@ impl Expression {
}
}
}
Err(anyhow!("Can't find status"))
Ok(VarValue::Int(0))
}
Expression::FilterMaxEnemy(value) => {
let faction = Self::OppositeFaction.get_faction(context, world)?;
Expand All @@ -324,6 +325,21 @@ impl Expression {
.context("Failed to filer max enemy")?;
Ok(VarValue::Entity(unit))
}
Expression::FindUnit(condition) => {
let faction = context
.get_var(VarName::Faction, world)
.context("No Faction var in context")?
.get_faction()?;
let unit = UnitPlugin::collect_faction(faction, world)
.into_iter()
.find(|u| {
condition
.get_bool(&Context::from_owner(*u, world), world)
.unwrap_or_default()
})
.context("Failed to find unit")?;
Ok(VarValue::Entity(unit))
}
Expression::Beat => {
let beat = AudioPlugin::beat_index(world);
let to_next = AudioPlugin::to_next_beat(world);
Expand Down Expand Up @@ -422,6 +438,7 @@ impl Expression {
| Self::FactionCount(x)
| Self::StatusCharges(x)
| Self::FilterMaxEnemy(x)
| Self::FindUnit(x)
| Self::Vec2E(x) => vec![x],

Self::Vec2EE(a, b)
Expand Down Expand Up @@ -531,6 +548,7 @@ impl Expression {
| Expression::SlotUnit(_)
| Expression::FactionCount(_)
| Expression::FilterMaxEnemy(_)
| Expression::FindUnit(_)
| Expression::StatusCharges(_) => hex_color!("#448AFF"),
Expression::Vec2EE(_, _)
| Expression::Sum(_, _)
Expand Down Expand Up @@ -600,6 +618,7 @@ impl Expression {
| Expression::SlotUnit(v)
| Expression::FactionCount(v)
| Expression::FilterMaxEnemy(v)
| Expression::FindUnit(v)
| Expression::StatusCharges(v) => format!(
"{} ({})",
self.to_string().to_case(Case::Lower),
Expand Down
6 changes: 6 additions & 0 deletions src/resourses/packed_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,13 @@ impl PackedUnit {
trigger: trigger_a,
target: target_a,
effect: effect_a,
period: period_a,
},
Trigger::Fire {
trigger: trigger_b,
target: target_b,
effect: effect_b,
period: period_b,
},
) => {
if !trigger_a.eq(trigger_b) {
Expand All @@ -247,6 +249,7 @@ impl PackedUnit {
),
target: target_a.clone(),
effect: effect_a.clone(),
period: *period_a.max(period_b),
};
result.push(Self::fuse_base(&a, &b, trigger, world));
let trigger = Trigger::Fire {
Expand All @@ -255,6 +258,7 @@ impl PackedUnit {
),
target: target_b.clone(),
effect: effect_b.clone(),
period: *period_a.max(period_b),
};
result.push(Self::fuse_base(&b, &a, trigger, world));
}
Expand All @@ -264,6 +268,7 @@ impl PackedUnit {
effect: Effect::List(
[Box::new(effect_a.clone()), Box::new(effect_b.clone())].into(),
),
period: *period_a.max(period_b),
};
result.push(Self::fuse_base(&a, &b, trigger, world));
let trigger = Trigger::Fire {
Expand All @@ -272,6 +277,7 @@ impl PackedUnit {
effect: Effect::List(
[Box::new(effect_a.clone()), Box::new(effect_b.clone())].into(),
),
period: *period_a.max(period_b),
};
result.push(Self::fuse_base(&b, &a, trigger, world));
}
Expand Down
23 changes: 19 additions & 4 deletions src/resourses/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub enum Trigger {
#[serde(default = "owner")]
target: Expression,
effect: Effect,
#[serde(default)]
period: usize,
},
Change {
trigger: DeltaTrigger,
Expand Down Expand Up @@ -131,6 +133,7 @@ impl Default for Trigger {
trigger: FireTrigger::Noop,
target: Expression::Owner,
effect: Effect::Noop,
period: 0,
}
}
}
Expand All @@ -149,10 +152,19 @@ impl Trigger {
trigger,
target,
effect,
period,
} => {
if !trigger.catch(event, context, world) {
return false;
}
let mut state = VarState::get_mut(context.status(), world);
let count = state.get_int(VarName::Count).unwrap_or_default() + 1;
if count > *period as i32 {
state.set_int(VarName::Count, 0);
} else {
state.set_int(VarName::Count, count + 1);
return false;
}
let effect = Effect::WithTarget(target.clone(), Box::new(effect.clone()));
match trigger {
FireTrigger::List(_)
Expand Down Expand Up @@ -240,12 +252,15 @@ impl Trigger {
trigger,
target,
effect,
period,
} => {
let mut trigger = trigger.get_description_string();
if *period > 0 {
let s = format!(" ({})", *period + 1);
trigger.push_str(&s);
}
state
.init(
VarName::TriggerDescription,
VarValue::String(trigger.get_description_string()),
)
.init(VarName::TriggerDescription, VarValue::String(trigger))
.init(
VarName::EffectDescription,
VarValue::String(
Expand Down
1 change: 1 addition & 0 deletions src/resourses/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub enum VarName {
Curvature,
Delta,
T,
Count,
Alpha,
Index,
Stacks,
Expand Down

0 comments on commit fb3b679

Please sign in to comment.