-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Trisfald/status-effects
Status effects
- Loading branch information
Showing
38 changed files
with
2,330 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,3 +64,6 @@ name = "undo" | |
|
||
[[example]] | ||
name = "passive" | ||
|
||
[[example]] | ||
name = "status" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
# Initiative | ||
|
||
This example shows how to implement `RoundsRules` to decide the order of acting during a battle. | ||
|
||
The first step is to create five creatures, each one with a different value of *speed*. Then, we will repeatedly start and end rounds while also displaying the global order of initiative. | ||
|
||
Run the example with: | ||
``` | ||
cargo run --example initiative --all-features | ||
``` | ||
|
||
The program is implemented in two source code files: | ||
- [rules.rs](rules.rs): rules definition (round rules, in particular). | ||
- [main.rs](main.rs): manages the battle and creates a few events. | ||
# Initiative | ||
|
||
This example shows how to implement `RoundsRules` to decide the order of acting during a battle. | ||
|
||
The first step is to create five creatures, each one with a different value of *speed*. Then, we will repeatedly start and end rounds while also displaying the global order of initiative. | ||
|
||
Run the example with: | ||
``` | ||
cargo run --example initiative --all-features | ||
``` | ||
|
||
The program is implemented in two source code files: | ||
- [rules.rs](rules.rs): rules definition (round rules, in particular). | ||
- [main.rs](main.rs): manages the battle and creates a few events. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
# Space | ||
|
||
In this example we'll discover how to manage the *space dimension* in weasel. | ||
|
||
Our space model will start as a two dimensional plane, divided in squares. We will then spawn a few creatures, each one on a different square. | ||
|
||
As the next step, deadly traps will be placed across the two diagonals. | ||
|
||
Finally, we are going to regenerate the space, transforming the 2D plane into a single line of squares; in other words we drop one dimension. | ||
|
||
Run the example with: | ||
``` | ||
cargo run --example space | ||
``` | ||
|
||
The program is implemented in two source code files: | ||
- [rules.rs](rules.rs): rules definition (space rules, in particular). | ||
- [main.rs](main.rs): manages the battle and creates a few events. | ||
# Space | ||
|
||
In this example we'll discover how to manage the *space dimension* in weasel. | ||
|
||
Our space model will start as a two dimensional plane, divided in squares. We will then spawn a few creatures, each one on a different square. | ||
|
||
As the next step, deadly traps will be placed across the two diagonals. | ||
|
||
Finally, we are going to regenerate the space, transforming the 2D plane into a single line of squares; in other words we drop one dimension. | ||
|
||
Run the example with: | ||
``` | ||
cargo run --example space | ||
``` | ||
|
||
The program is implemented in two source code files: | ||
- [rules.rs](rules.rs): rules definition (space rules, in particular). | ||
- [main.rs](main.rs): manages the battle and creates a few events. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Status | ||
|
||
In this example we will demonstrate how to implement different types of long lasting status effects. | ||
|
||
We will first create a creature and an object. Then, we inflict a status effect on the creature that will increase its health as long as it is active. The object, instead, will be dealt damage over time which will reduce its life at each round. Finally, we will see how to end the effects manually or after a certain number of rounds. | ||
|
||
Run the example with: | ||
``` | ||
cargo run --example status | ||
``` | ||
|
||
The program is implemented in two source code files: | ||
- [rules.rs](rules.rs): rules definition. | ||
- [main.rs](main.rs): manages the displayed messages and handles the battle server. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
use crate::rules::*; | ||
use weasel::battle::Battle; | ||
use weasel::creature::{CreateCreature, CreatureId}; | ||
use weasel::entity::EntityId; | ||
use weasel::event::{EventKind, EventTrigger}; | ||
use weasel::object::{CreateObject, ObjectId}; | ||
use weasel::round::{EndRound, EnvironmentRound, StartRound}; | ||
use weasel::status::{ClearStatus, InflictStatus}; | ||
use weasel::team::{CreateTeam, TeamId}; | ||
use weasel::util::Id; | ||
use weasel::Server; | ||
|
||
mod rules; | ||
|
||
static TEAM_ID: TeamId<CustomRules> = 1; | ||
static CREATURE_ID: CreatureId<CustomRules> = 1; | ||
static OBJECT_ID: ObjectId<CustomRules> = 2; | ||
static ENTITY_1_ID: EntityId<CustomRules> = EntityId::Creature(CREATURE_ID); | ||
static ENTITY_2_ID: EntityId<CustomRules> = EntityId::Object(OBJECT_ID); | ||
|
||
fn main() { | ||
// Create a server to manage the battle. | ||
let battle = Battle::builder(CustomRules::new()).build(); | ||
let mut server = Server::builder(battle).build(); | ||
// Create a team. | ||
CreateTeam::trigger(&mut server, TEAM_ID).fire().unwrap(); | ||
// Spawn a creature and an object, both with 50 HEALTH. | ||
println!("Spawning a creature..."); | ||
CreateCreature::trigger(&mut server, CREATURE_ID, TEAM_ID, ()) | ||
.statistics_seed(50) | ||
.fire() | ||
.unwrap(); | ||
println!("Spawning an object..."); | ||
CreateObject::trigger(&mut server, OBJECT_ID, ()) | ||
.statistics_seed(50) | ||
.fire() | ||
.unwrap(); | ||
// Display the entities' state. | ||
print_state(&server); | ||
// Inflict a power-up status effect on the creature, with no time limit. | ||
println!("Inflicting a power-up on the creature..."); | ||
InflictStatus::trigger(&mut server, ENTITY_1_ID, VIGOR) | ||
.potency((50, None)) | ||
.fire() | ||
.unwrap(); | ||
// Inflict a DoT status effect on the object, for two rounds. | ||
println!("Inflicting a DoT on the object..."); | ||
InflictStatus::trigger(&mut server, ENTITY_2_ID, DOT) | ||
.potency((10, Some(2))) | ||
.fire() | ||
.unwrap(); | ||
// Display the entities' state. | ||
print_state(&server); | ||
// Do two full turns. | ||
for i in 1..=2 { | ||
turn(&mut server, i); | ||
} | ||
// The DoT should have been cleared automatically. | ||
// Remove the power-up manually. | ||
println!("Removing the creature power-up..."); | ||
ClearStatus::trigger(&mut server, ENTITY_1_ID, VIGOR) | ||
.fire() | ||
.unwrap(); | ||
print_state(&server); | ||
// Display the link between the DoT status and the effects it created. | ||
print_dot_effects(&server); | ||
} | ||
|
||
/// Performs a turn. | ||
fn turn(server: &mut Server<CustomRules>, turn: u32) { | ||
// Display in which turn we are. | ||
println!("Turn {}", turn); | ||
println!(); | ||
// Start and end a round for the creature. | ||
println!("Round of Creature (1)..."); | ||
StartRound::trigger(server, ENTITY_1_ID).fire().unwrap(); | ||
EndRound::trigger(server).fire().unwrap(); | ||
// Do a round for all non-actor entities, to update their statuses. | ||
println!("Round of environment..."); | ||
EnvironmentRound::trigger(server).fire().unwrap(); | ||
// Display the entities' state. | ||
print_state(server); | ||
} | ||
|
||
/// Displays briefly the state of all entities. | ||
fn print_state(server: &Server<CustomRules>) { | ||
println!(); | ||
println!("------------------------- Entities -------------------------"); | ||
for character in server.battle().entities().characters() { | ||
let statuses: Vec<_> = character | ||
.statuses() | ||
.map(|status| match *status.id() { | ||
VIGOR => "vigor", | ||
DOT => "DoT", | ||
_ => unimplemented!(), | ||
}) | ||
.collect(); | ||
println!( | ||
"{:?} => health: {}, statuses: {:?}", | ||
character.entity_id(), | ||
character.statistic(&HEALTH).unwrap().value(), | ||
statuses | ||
); | ||
} | ||
println!(); | ||
} | ||
|
||
fn print_dot_effects(server: &Server<CustomRules>) { | ||
println!("Event derived from the DOT status:"); | ||
// We want to show the chain of events derived from the DOT status. | ||
// First find the event that put the DOT on the object. | ||
// We know it's first InflictStatus iterating in reverse order. | ||
let events = server.battle().history().events(); | ||
let inflict_event = events | ||
.iter() | ||
.rev() | ||
.find(|e| e.kind() == EventKind::InflictStatus) | ||
.unwrap(); | ||
println!("{:?}", inflict_event.event()); | ||
// Get all events with inflict_event as origin. | ||
for event in events { | ||
if event.origin() == Some(inflict_event.id()) { | ||
println!("+-- {:?}", event.event()); | ||
} | ||
} | ||
} |
Oops, something went wrong.