Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #27 from rodrigocam/bear-person
Browse files Browse the repository at this point in the history
Add BearPerson implementation
  • Loading branch information
AnneKitsune authored Jan 11, 2021
2 parents 1c7a193 + b754512 commit e90b971
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 2 deletions.
6 changes: 6 additions & 0 deletions assets/effector_defs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ defs:
effects:
- - ActionPointRefillRate
- MultiplicativeMultiplier: 0.5
Savagery:
key: Savagery
duration: 10.0
effects:
- - AttackSpeed
- Additive: 5.0
6 changes: 6 additions & 0 deletions assets/leader_defs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ defs:
skills:
- NatureSummon
- Root
BearPersonLeader:
key: BearPersonLeader
name: "BearPersonLeader"
skills:
- BearSummon
- Savagery
21 changes: 21 additions & 0 deletions assets/skill_defs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,24 @@ defs:
MinValue: 3.0
item_conditions: []
stat_effectors: []
BearSummon:
key: BearSummon
name: Bear Summon
friendly_name: bear_summon
description: Spawns a bear as companion of the leader.
cooldown: 120.0
passive: true
conditions: []
item_conditions: []
stat_effectors: []
Savagery:
key: Savagery
name: Savagery
friendly_name: savagery
description: Increase the attack speed of both leader and companion in 5 points for 10s. Cooldown 20s.
cooldown: 20.0
passive: true
conditions: []
item_conditions: []
stat_effectors:
- Savagery
6 changes: 6 additions & 0 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pub struct Hero1ProximityAttack {
/// The radius at which we can attack.
pub radius: f32,
}
/// Identifies which type is the companion
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum Companion {
/// A bear companion
Bear(Entity),
}
/// Tags a tower projectile.
pub struct TowerProjectile;
/// Tags a core.
Expand Down
4 changes: 4 additions & 0 deletions src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub enum Skills {
Root,
AttackSpeedIncrease,
SlowAOE,
BearSummon,
Savagery,
}

/// The different items ids.
Expand All @@ -52,6 +54,7 @@ pub enum Effectors {
Root,
AttackSpeedIncrease,
HalfMovementSpeed,
Savagery,
}

/// The different leader ids.
Expand All @@ -62,4 +65,5 @@ pub enum Leaders {
Generic2,
Generic3,
TreePersonLeader,
BearPersonLeader,
}
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ fn main() -> BError {
apply_effector_system::<Stats, Effectors>,
remove_outdated_effector_system::<Effectors>,
nature_summon_system,
bear_spawner_system,
savagery_system,
aoe_damage_system,
damage_entity_system,
kill_entity_system,
Expand Down Expand Up @@ -406,14 +408,14 @@ fn main() -> BError {
Leaders::Generic2,
Leaders::Generic3,
Leaders::TreePersonLeader,
Leaders::Generic3,
Leaders::BearPersonLeader,
],
vec![
Leaders::Generic1,
Leaders::Generic2,
Leaders::Generic3,
Leaders::TreePersonLeader,
Leaders::Generic3,
Leaders::BearPersonLeader,
],
);
*world.get_mut::<TeamLeaders>().unwrap() = team_heroes;
Expand Down
46 changes: 46 additions & 0 deletions src/systems/bear_spawner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use crate::*;

/// Spawn a bear companion at a specific location
pub fn bear_spawner_system(
events: &Vec<SkillTriggerEvent<Skills>>,
stat_def: &StatDefinitions<Stats>,
teams: &mut Components<Team>,
proximity_attacks: &mut Components<ProximityAttack>,
simple_movements: &mut Components<SimpleMovement>,
stats: &mut Components<StatSet<Stats>>,
positions: &mut Components<Point>,
entities: &mut Entities,
companions: &mut Components<Companion>,
sprites: &mut Components<Sprite>,
sprite_indices: &mut Components<SpriteIndex>,
) -> SystemResult {
for ev in events.iter() {
if ev.1 == Skills::BearSummon {
let pos = positions.get(ev.0).unwrap().clone();
let team = teams.get_mut(ev.0).unwrap().clone();

let bear = entities.create();
positions.insert(bear, pos.clone());
companions.insert(ev.0, Companion::Bear(bear));
simple_movements.insert(bear, SimpleMovement);
teams.insert(bear, team);
stats.insert(bear, stat_def.to_statset());
proximity_attacks.insert(bear, ProximityAttack::new(CREEP_ATTACK_RADIUS));
let bg = if team == Team::Me {
RGBA::named(GREEN)
} else {
RGBA::named(RED)
};
sprites.insert(
bear,
Sprite {
glyph: to_cp437('c'),
fg: RGBA::named(YELLOW),
bg,
},
);
sprite_indices.insert(bear, SpriteIndex(15));
}
}
Ok(())
}
4 changes: 4 additions & 0 deletions src/systems/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod aoe_damage;
mod bear_spawner;
mod creep_spawner;
mod damage_entity;
mod game_stats_updater;
Expand All @@ -12,6 +13,7 @@ mod leader_respawn_driver;
mod nature_summon;
mod proximity_attack;
mod root;
mod savagery;
mod select_hero;
mod simple_movement;
mod spawn_creep;
Expand All @@ -23,6 +25,7 @@ mod update_collision_resource;
mod update_enemies_around_stat;
mod update_win_condition;
pub use self::aoe_damage::*;
pub use self::bear_spawner::*;
pub use self::creep_spawner::*;
pub use self::damage_entity::*;
pub use self::game_stats_updater::*;
Expand All @@ -36,6 +39,7 @@ pub use self::leader_respawn_driver::*;
pub use self::nature_summon::*;
pub use self::proximity_attack::*;
pub use self::root::*;
pub use self::savagery::*;
pub use self::select_hero::*;
pub use self::simple_movement::*;
pub use self::simple_movement::*;
Expand Down
37 changes: 37 additions & 0 deletions src/systems/savagery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::*;

/// Increase the attack speed of both leader and companion in 5 points.
pub fn savagery_system(
effector_defs: &EffectorDefinitions<Stats, Effectors>,
companions: &Components<Companion>,
effectors: &mut Components<EffectorSet<Effectors>>,
events: &mut Vec<SkillTriggerEvent<Skills>>,
) -> SystemResult {
for ev in events.iter() {
if ev.1 == Skills::Savagery {
let savagery_effector_def = effector_defs
.defs
.get(&Effectors::Savagery)
.expect("Unknown effector key.");

let savagery_effector =
EffectorInstance::new(Effectors::Savagery, savagery_effector_def.duration);

if let Some(c) = companions.get(ev.0) {
match c {
Companion::Bear(e) => {
if effectors.get(*e).is_none() {
effectors.insert(*e, EffectorSet::default());
}
effectors
.get_mut(*e)
.unwrap()
.effectors
.push(savagery_effector);
}
}
}
}
}
Ok(())
}

0 comments on commit e90b971

Please sign in to comment.