Skip to content

Commit

Permalink
Rework action queue for action & event queue;
Browse files Browse the repository at this point in the history
Single test run task;
Increasing income;
  • Loading branch information
makscee committed Jan 30, 2024
1 parent 2af4d23 commit 8e9e3a0
Show file tree
Hide file tree
Showing 25 changed files with 362 additions and 467 deletions.
21 changes: 21 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,27 @@
"RUST_BACKTRACE": "1"
}
},
{
"type": "cargo",
"command": "run",
"problemMatcher": [
"$rustc"
],
"label": "Single Test Scenario",
"args": [
"--",
"--mode",
"test",
"--path",
"ron/scenarios/kill_after_death.scenario.ron"
],
"group": {
"kind": "build"
},
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "cargo",
"command": "run",
Expand Down
213 changes: 95 additions & 118 deletions assets/ron/custom.battle.ron
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,110 @@
left: (
units: [
(
name: "Mentalist",
hp: 1,
atk: 2,
houses: "Meta",
name: "Wizard",
hp: 3,
atk: 1,
houses: "Mages",
trigger: Fire(
trigger: BattleStart,
target: AllyUnits,
trigger: TurnEnd,
target: RandomEnemy,
effect: UseAbility(
"Amnesia",
"Magic Missile",
),
),
representation: (
material: Shape(
shape: Circle,
fill: Opaque,
size: Vec2E(
Float(0.25),
),
thickness: Float(1.3),
alpha: If(
Equals(
State(
Index,
),
Zero,
),
Float(0.6),
Float(0.1),
),
color: State(Color),
),
(
name: "Wizard",
hp: 3,
atk: 1,
houses: "Mages",
trigger: Fire(
trigger: TurnEnd,
target: RandomEnemy,
effect: UseAbility(
"Magic Missile",
),
children: [],
mapping: {
Position: Mul(
Vec2EE(
Cos(
State(
T,
),
),
Sin(
State(
T,
),
),
),
Float(0.5),
),
T: Sum(
Sin(
Sum(
GameTime,
Mul(
IntFloat(
State(
Index,
),
),
Float(
-0.15,
),
),
),
),
Mul(
PI,
Float(
1.5,
),
),
),
},
count: 8,
),
),
(
name: "Wizard",
hp: 3,
atk: 1,
houses: "Mages",
trigger: Fire(
trigger: TurnEnd,
target: RandomEnemy,
effect: UseAbility(
"Magic Missile",
),
),
),
(
name: "Wizard",
hp: 3,
atk: 1,
houses: "Mages",
trigger: Fire(
trigger: TurnEnd,
target: RandomEnemy,
effect: UseAbility(
"Magic Missile",
),
),
),
(
name: "Bolla",
hp: 1,
atk: 1,
houses: "Dragons",
trigger: Fire(
trigger: TurnEnd,
effect: UseAbility("Grow"),
),
state: (history: {}, birth: 0.0),
statuses: [],
),
],
),
right: (
units: [
(
name: "Priest",
hp: 1,
atk: 1,
houses: "Holy",
trigger: Fire(
trigger: BattleStart,
target: AllyUnits,
effect: UseAbility(
"Blessing",
),
),
),
(
name: "Priest",
hp: 12,
atk: 1,
houses: "Holy",
),
(
name: "Priest",
hp: 1,
atk: 1,
houses: "Holy",
),
(
name: "Priest",
hp: 1,
atk: 1,
houses: "Holy",
),
(
name: "Priest",
hp: 1,
atk: 1,
houses: "Holy",
),
(
name: "Protector",
hp: 2,
Expand All @@ -91,57 +118,7 @@
effect: UseAbility("Shield"),
),
description: "%trigger → use %effect on front ally",
representation: (
material: Shape(
shape: Circle,
fill: Line,
size: Vec2E(
Float(0.67),
),
thickness: Float(0.37),
alpha: Float(0.36),
color: State(Color),
),
children: [],
mapping: {
Position: Mul(
UnitVec(
Sum(
IntFloat(
State(
Index,
),
),
Sum(
GameTime,
Sin(
Mul(
RandomFloat,
GameTime,
),
),
),
),
),
Mul(
Sin(
Mul(
GameTime,
Float(
0.3,
),
),
),
Float(
0.19,
),
),
),
},
count: 16,
),
),
],
),
right: (units: []),
)
5 changes: 3 additions & 2 deletions assets/ron/scenarios/kill_after_death.scenario.ron
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#![enable(implicit_some)]
(
left: (units: [(hp: 15, atk: 3)]),
left: (units: [(name: "left", hp: 15, atk: 3)]),
right: (
units: [
(
hp: 3,
atk: 3,
name: "left",
name: "right",
description: "Kill after dealing any damage",
trigger: Fire(
trigger: AfterDamageDealt,
target: Target,
effect: Kill,
),
),
Expand Down
10 changes: 6 additions & 4 deletions server/src/arena_run.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Range;

use itertools::Itertools;
use rand::seq::IteratorRandom;
use rand::thread_rng;
Expand Down Expand Up @@ -37,7 +39,7 @@ pub struct ShopOffer {
unit: TeamUnit,
}

const G_PER_ROUND: i64 = 4;
const G_PER_ROUND: Range<i64> = 4..10;
const PRICE_REROLL: i64 = 1;
const PRICE_UNIT: i64 = 3;
const PRICE_SELL: i64 = 1;
Expand Down Expand Up @@ -82,15 +84,15 @@ fn run_submit_result(ctx: ReducerContext, win: bool) -> Result<(), String> {
if run.state.loses > 2 || run.state.wins > 9 {
run.active = false;
} else {
let round = run.state.wins + run.state.loses;
let round = run.round();
if let Some(enemy) = ArenaPool::filter_by_round(&round)
// .filter(|e| e.owner != user_id)
.choose(&mut thread_rng())
{
run.enemies.push(enemy.id);
}
}
run.change_g(G_PER_ROUND);
run.change_g((G_PER_ROUND.start + run.round() as i64).min(G_PER_ROUND.end));
run.state.case.clear();
run.fill_case();
run.save();
Expand Down Expand Up @@ -221,7 +223,7 @@ impl ArenaRun {
state: GameState {
wins: 0,
loses: 0,
g: G_PER_ROUND,
g: G_PER_ROUND.start,
team: Vec::default(),
case: Vec::default(),
next_id: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/components/representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl RepresentationMaterial {
}

pub fn update(&self, entity: Entity, world: &mut World) {
let t = get_play_head();
let t = GameTimer::get().play_head();
if let Ok(state) = VarState::try_get(entity, world) {
let visible = state.get_bool_at(VarName::Visible, t).unwrap_or(true);
let visible = visible && state.birth < t;
Expand Down
17 changes: 12 additions & 5 deletions src/components/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Status {

fn reindex_statuses(unit: Entity, world: &mut World) -> Result<()> {
let mut ind: i32 = 0;
let t = get_insert_head();
let t = GameTimer::get().insert_head();
for entity in Self::collect_entity_statuses(unit, world) {
let mut state = VarState::get_mut(entity, world);
if state.get_int(VarName::Charges).is_ok_and(|x| x > 0) {
Expand Down Expand Up @@ -192,17 +192,24 @@ impl Status {
.collect_vec()
}

pub fn notify(statuses: Vec<Entity>, event: &Event, context: &Context, world: &mut World) {
pub fn notify(
statuses: Vec<Entity>,
event: &Event,
context: &Context,
world: &mut World,
) -> bool {
let mut result = false;
for (status, trigger) in Self::collect_triggers(statuses, world) {
trigger.fire(
result |= trigger.fire(
event,
context
.clone()
.set_owner(get_parent(status, world), world)
.set_status(status, world),
world,
)
);
}
result
}

pub fn refresh_entity_mapping(status: Entity, world: &mut World) {
Expand All @@ -213,7 +220,7 @@ impl Status {
.take();
let s = world.get::<Status>(status).unwrap();
for (var, value) in s.trigger.clone().collect_mappings(&context, world) {
let t = get_insert_head();
let t = GameTimer::get().insert_head();
let mut state_mapping = world.get_mut::<VarStateDelta>(status).unwrap();
if state_mapping.need_update(var, &value) {
state_mapping.state.insert_simple(var, value, t);
Expand Down
Loading

0 comments on commit 8e9e3a0

Please sign in to comment.