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