Compare commits
2 Commits
430de3e1f1
...
9d78db008d
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d78db008d | |||
| cae47f86ed |
@ -305,14 +305,19 @@ impl IPlayer for LocalPlayer {
|
||||
if let Some(mut weapon) = self.get_weapon()
|
||||
&& let Some(camera_origin) = &self.camera_origin
|
||||
{
|
||||
weapon.dyn_bind_mut().shoot(
|
||||
if weapon.dyn_bind_mut().shoot(
|
||||
rid,
|
||||
self.player_id.unwrap_or(0),
|
||||
camera_origin.get_global_position(),
|
||||
to,
|
||||
camera_origin.get_global_basis().col_b(),
|
||||
deal_damage,
|
||||
)
|
||||
) {
|
||||
weapon.set_rotation(Vector3::RIGHT * 0.3);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@ -551,6 +556,13 @@ impl ICharacterBody3D for LocalPlayer {
|
||||
} else {
|
||||
(0., 0.)
|
||||
};
|
||||
let done_cd_percent =
|
||||
1. - (weapon.dyn_bind().get_remaining_cd() / weapon.dyn_bind().get_max_cd());
|
||||
let new_weapon_rot = weapon
|
||||
.get_rotation()
|
||||
.lerp(Vector3::ZERO, 0.03 * done_cd_percent as f32);
|
||||
weapon.set_rotation(new_weapon_rot);
|
||||
|
||||
let prev_weapon_pos = weapon.get_position();
|
||||
let new_y = prev_weapon_pos.y.lerp(target_y as f32, 0.2);
|
||||
let new_x = prev_weapon_pos.x.lerp(target_x as f32, 0.2);
|
||||
@ -710,11 +722,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,9 @@ pub trait Weapon {
|
||||
deal_damage: bool,
|
||||
) -> bool;
|
||||
fn get_type(&self) -> WeaponType;
|
||||
fn get_max_cd(&self) -> f64;
|
||||
fn get_remaining_cd(&self) -> f64;
|
||||
fn set_remaining_cd(&mut self, cd: f64);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, PartialOrd)]
|
||||
@ -127,6 +130,18 @@ impl Weapon for Raygun {
|
||||
fn get_type(&self) -> WeaponType {
|
||||
WeaponType::Raygun
|
||||
}
|
||||
|
||||
fn get_max_cd(&self) -> f64 {
|
||||
self.cooldown
|
||||
}
|
||||
|
||||
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 +234,18 @@ impl Weapon for Shotgun {
|
||||
fn get_type(&self) -> WeaponType {
|
||||
WeaponType::Shotgun
|
||||
}
|
||||
|
||||
fn get_max_cd(&self) -> f64 {
|
||||
self.cooldown
|
||||
}
|
||||
|
||||
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 +307,14 @@ impl Weapon for BallWeapon {
|
||||
fn get_type(&self) -> WeaponType {
|
||||
WeaponType::Ball
|
||||
}
|
||||
|
||||
fn get_max_cd(&self) -> f64 {
|
||||
0.
|
||||
}
|
||||
|
||||
fn get_remaining_cd(&self) -> f64 {
|
||||
0.
|
||||
}
|
||||
|
||||
fn set_remaining_cd(&mut self, _: f64) {}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user