engine/gavania-core/src/game/content/abilities/selfcast.rs
2024-08-25 09:11:52 +02:00

64 lines
1.7 KiB
Rust

#![allow(unused)]
use anyhow::Result;
use engine::prelude::*;
use entity_manager::*;
use rpg_components::{
components::{abilityloader::AbilityLoader, statistics::Statistics},
items::ability_book::AbilityBook,
};
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;
impl SelfCast {
pub fn execute(
ability: &AbilityLoader,
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 = ability.damage(book.level(), book.addons(), owner_stats);
let range = ability.settings.parameter.radius * book.addons().size();
let (mut entity_object, particle_spawn) = AreaOfEffect::new(
direction,
location.position(),
Deg(ability.settings.parameter.arc),
range,
hit_box.height() * 0.75,
owner,
ability.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(())
}
}