Move cd management to weapon itself
This commit is contained in:
parent
95e0032948
commit
c589832268
@ -297,15 +297,11 @@ impl IPlayer for LocalPlayer {
|
||||
return true;
|
||||
}
|
||||
|
||||
if self.shoot_cd <= 0. {
|
||||
let rid = self.base().get_rid();
|
||||
if let Some(mut weapon) = self.get_weapon() {
|
||||
weapon
|
||||
.dyn_bind_mut()
|
||||
.shoot(rid, self.player_id.unwrap_or(0), to, deal_damage);
|
||||
}
|
||||
self.shoot_cd = 0.2;
|
||||
true
|
||||
.shoot(rid, self.player_id.unwrap_or(0), to, deal_damage)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@ -749,17 +745,13 @@ impl IPlayer for RemotePlayer {
|
||||
return true;
|
||||
}
|
||||
|
||||
if self.shoot_cd <= 0. {
|
||||
let rid = self.base().get_rid();
|
||||
if let Some(mesh) = &mut self.soldier_mesh
|
||||
&& let Some(mut weapon) = mesh.bind().get_weapon()
|
||||
{
|
||||
weapon
|
||||
.dyn_bind_mut()
|
||||
.shoot(rid, self.player_id.unwrap_or(0), to, deal_damage);
|
||||
}
|
||||
self.shoot_cd = 0.2;
|
||||
true
|
||||
.shoot(rid, self.player_id.unwrap_or(0), to, deal_damage)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ use crate::{
|
||||
};
|
||||
|
||||
pub trait Weapon {
|
||||
fn shoot(&mut self, player_rid: Rid, player_id: u16, to: Vector3, deal_damage: bool);
|
||||
fn shoot(&mut self, player_rid: Rid, player_id: u16, to: Vector3, deal_damage: bool) -> bool;
|
||||
fn get_type(&self) -> WeaponType;
|
||||
}
|
||||
|
||||
@ -29,12 +29,28 @@ pub struct Raygun {
|
||||
#[export]
|
||||
bullet_source: Option<Gd<Node3D>>,
|
||||
|
||||
#[export]
|
||||
cooldown: f64,
|
||||
|
||||
cooldown_remaining: f64,
|
||||
|
||||
base: Base<Node3D>,
|
||||
}
|
||||
|
||||
#[godot_api]
|
||||
impl INode3D for Raygun {
|
||||
fn process(&mut self, delta: f64) {
|
||||
self.cooldown_remaining -= delta;
|
||||
}
|
||||
}
|
||||
|
||||
#[godot_dyn]
|
||||
impl Weapon for Raygun {
|
||||
fn shoot(&mut self, player: Rid, player_id: u16, to: Vector3, deal_damage: bool) {
|
||||
fn shoot(&mut self, player: Rid, player_id: u16, to: Vector3, deal_damage: bool) -> bool {
|
||||
if self.cooldown_remaining > 0. {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(emitter) = &mut self.sound_emitter {
|
||||
emitter.play();
|
||||
}
|
||||
@ -89,6 +105,10 @@ impl Weapon for Raygun {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.cooldown_remaining = self.cooldown;
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
fn get_type(&self) -> WeaponType {
|
||||
@ -148,7 +168,9 @@ pub struct BallWeapon {
|
||||
|
||||
#[godot_dyn]
|
||||
impl Weapon for BallWeapon {
|
||||
fn shoot(&mut self, _: Rid, _: u16, _: Vector3, _: bool) {}
|
||||
fn shoot(&mut self, _: Rid, _: u16, _: Vector3, _: bool) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn get_type(&self) -> WeaponType {
|
||||
WeaponType::Ball
|
||||
|
||||
Loading…
Reference in New Issue
Block a user