Transfer cd from previous weapon
This commit is contained in:
parent
430de3e1f1
commit
cae47f86ed
@ -710,11 +710,16 @@ impl LocalPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_weapon(&mut self, weapon: DynGd<Node3D, dyn Weapon>) {
|
||||
if let Some(mut weapon) = self.weapon.take() {
|
||||
fn spawn_weapon(&mut self, mut weapon: DynGd<Node3D, dyn Weapon>) {
|
||||
let prev_cd = if let Some(mut weapon) = self.weapon.take() {
|
||||
let prev_cd = weapon.dyn_bind().get_remaining_cd();
|
||||
weapon.queue_free();
|
||||
}
|
||||
prev_cd
|
||||
} else {
|
||||
0.
|
||||
};
|
||||
if let Some(weapon_node) = &mut self.weapon_node {
|
||||
weapon.dyn_bind_mut().set_remaining_cd(prev_cd);
|
||||
weapon_node.add_child(&weapon);
|
||||
self.weapon = Some(weapon);
|
||||
}
|
||||
|
||||
@ -80,12 +80,17 @@ impl SoldierMesh {
|
||||
|
||||
fn spawn_weapon(
|
||||
&mut self,
|
||||
node: DynGd<Node3D, dyn Weapon>,
|
||||
mut node: DynGd<Node3D, dyn Weapon>,
|
||||
) -> Option<DynGd<Node3D, dyn Weapon>> {
|
||||
if let Some(mut weapon) = self.current_weapon.take() {
|
||||
let prev_cd = if let Some(mut weapon) = self.current_weapon.take() {
|
||||
let rem = weapon.dyn_bind().get_remaining_cd();
|
||||
weapon.queue_free();
|
||||
}
|
||||
rem
|
||||
} else {
|
||||
0.
|
||||
};
|
||||
if let Some(hand) = &mut self.hand_attachment {
|
||||
node.dyn_bind_mut().set_remaining_cd(prev_cd);
|
||||
hand.add_child(&node);
|
||||
self.current_weapon = Some(node.clone());
|
||||
Some(node)
|
||||
|
||||
@ -23,6 +23,8 @@ pub trait Weapon {
|
||||
deal_damage: bool,
|
||||
) -> bool;
|
||||
fn get_type(&self) -> WeaponType;
|
||||
fn get_remaining_cd(&self) -> f64;
|
||||
fn set_remaining_cd(&mut self, cd: f64);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, PartialOrd)]
|
||||
@ -127,6 +129,14 @@ impl Weapon for Raygun {
|
||||
fn get_type(&self) -> WeaponType {
|
||||
WeaponType::Raygun
|
||||
}
|
||||
|
||||
fn get_remaining_cd(&self) -> f64 {
|
||||
self.cooldown_remaining
|
||||
}
|
||||
|
||||
fn set_remaining_cd(&mut self, cd: f64) {
|
||||
self.cooldown_remaining = cd;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(GodotClass)]
|
||||
@ -219,6 +229,14 @@ impl Weapon for Shotgun {
|
||||
fn get_type(&self) -> WeaponType {
|
||||
WeaponType::Shotgun
|
||||
}
|
||||
|
||||
fn get_remaining_cd(&self) -> f64 {
|
||||
self.cooldown_remaining
|
||||
}
|
||||
|
||||
fn set_remaining_cd(&mut self, cd: f64) {
|
||||
self.cooldown_remaining = cd;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(GodotClass)]
|
||||
@ -280,4 +298,10 @@ impl Weapon for BallWeapon {
|
||||
fn get_type(&self) -> WeaponType {
|
||||
WeaponType::Ball
|
||||
}
|
||||
|
||||
fn get_remaining_cd(&self) -> f64 {
|
||||
0.
|
||||
}
|
||||
|
||||
fn set_remaining_cd(&mut self, _: f64) {}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user