78 lines
1.8 KiB
Rust
78 lines
1.8 KiB
Rust
use godot::classes::class_macros::private::virtuals::ZipReader::Color;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::player::IPlayer;
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Buffs {
|
|
buffs: Vec<Buff>,
|
|
}
|
|
|
|
impl Default for Buffs {
|
|
fn default() -> Self {
|
|
let buffs = Vec::new();
|
|
|
|
Self { buffs }
|
|
}
|
|
}
|
|
|
|
impl Buffs {
|
|
pub fn update(&mut self, delta: f64) -> bool {
|
|
for buff in &mut self.buffs {
|
|
buff.update(delta);
|
|
}
|
|
let prev_length = self.buffs.len();
|
|
self.buffs.retain(|b| b.time_remaining >= 0.);
|
|
prev_length != self.buffs.len()
|
|
}
|
|
|
|
pub fn update_effects(self, player: &mut dyn IPlayer) {
|
|
let mut new_bubble_color = Color::BLACK.with_alpha(0.);
|
|
for buff in &self.buffs {
|
|
match buff.kind {
|
|
BuffKind::SpawnProtection => new_bubble_color = Color::BLUE,
|
|
}
|
|
}
|
|
player.set_bubble_color(new_bubble_color);
|
|
}
|
|
|
|
pub fn can_take_damage(&self) -> bool {
|
|
for buff in &self.buffs {
|
|
match buff.kind {
|
|
BuffKind::SpawnProtection => return false,
|
|
}
|
|
}
|
|
true
|
|
}
|
|
|
|
pub fn can_shoot(&self) -> bool {
|
|
for buff in &self.buffs {
|
|
match buff.kind {
|
|
BuffKind::SpawnProtection => return false,
|
|
}
|
|
}
|
|
true
|
|
}
|
|
|
|
pub fn new_buff(&mut self, buff: Buff) {
|
|
self.buffs.push(buff);
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Buff {
|
|
pub time_remaining: f64,
|
|
pub kind: BuffKind,
|
|
}
|
|
|
|
impl Buff {
|
|
pub fn update(&mut self, delta: f64) {
|
|
self.time_remaining -= delta;
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub enum BuffKind {
|
|
SpawnProtection,
|
|
}
|