engine/gavania-core/src/game/content/abilities/selfcast.rs

76 lines
1.8 KiB
Rust
Raw Normal View History

2024-08-23 11:22:09 +00:00
#![allow(unused)]
use anyhow::Result;
use engine::prelude::*;
use crate::game::{
content::prelude::*,
game::{Game, GameHandle},
};
use cgmath::{Deg, Vector2};
use std::sync::{Arc, Mutex, MutexGuard};
use super::particle_spawn::ParticleSpawn;
pub struct SelfCast {
data: AbilityLoader,
}
impl SelfCast {
pub fn new(data: AbilityLoader) -> Result<Self> {
Ok(SelfCast { data })
}
}
impl Ability for SelfCast {
fn data(&self) -> &AbilityLoader {
&self.data
}
fn name(&self) -> &str {
self.data.name()
}
fn execute(
&self,
owner: Entity,
owner_components: &mut MultiMut<'_>,
direction: Vector2<f32>,
book: &AbilityBook,
game_handle: &GameHandle,
entities: &mut Entities<'_>,
events: &mut ContentEvents<'_>,
) -> Result<()> {
let location = owner_components.get::<Location>()?;
let owner_stats = owner_components.get::<Statistics>()?;
let hit_box = owner_components.get::<HitBox>()?;
let mut base_damage = self.data.damage(book.level(), book.addons(), owner_stats);
let range = self.data.settings.parameter.radius * book.addons().size();
let (mut entity_object, particle_spawn) = AreaOfEffect::new(
direction,
location.position(),
Deg(self.data.settings.parameter.arc),
range,
hit_box.height() * 0.75,
owner,
self.data.clone(),
base_damage,
game_handle.clone(),
)?;
Faction::copy(owner_components, &mut entity_object);
entities.add_entity(entity_object)?;
if let Some(particle_spawn) = particle_spawn {
events.write_event(particle_spawn);
}
Ok(())
}
}