mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Consolidates projectile offsets into utils
This commit is contained in:
parent
9c2ce83430
commit
5838a84568
@ -10,7 +10,6 @@ use crate::{
|
||||
use rand::{thread_rng, Rng};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::time::Duration;
|
||||
use vek::*;
|
||||
|
||||
/// Separated out to condense update portions of character state
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@ -85,7 +84,7 @@ impl CharacterBehavior for Data {
|
||||
// Shoots all projectiles simultaneously
|
||||
for i in 0..self.static_data.num_projectiles {
|
||||
// Gets offsets
|
||||
let body_offsets = projectile_offsets(data.body, update.ori.look_vec());
|
||||
let body_offsets = data.body.projectile_offsets(update.ori.look_vec());
|
||||
let pos = Pos(data.pos.0 + body_offsets);
|
||||
// Adds a slight spread to the projectiles. First projectile has no spread,
|
||||
// and spread increases linearly with number of projectiles created.
|
||||
@ -146,31 +145,3 @@ impl CharacterBehavior for Data {
|
||||
fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) {
|
||||
handle_input(join, update, data.static_data.ability_info.input);
|
||||
}
|
||||
|
||||
fn height_offset(body: &Body) -> f32 {
|
||||
match body {
|
||||
Body::Golem(_) => body.height() * 0.4,
|
||||
_ => body.eye_height(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn projectile_offsets(body: &Body, ori: Vec3<f32>) -> Vec3<f32> {
|
||||
let dim = body.dimensions();
|
||||
// The width (shoulder to shoulder) and length (nose to tail)
|
||||
let (width, length) = (dim.x, dim.y);
|
||||
let body_radius = if length > width {
|
||||
// Dachshund-like
|
||||
body.max_radius()
|
||||
} else {
|
||||
// Cyclops-like
|
||||
body.min_radius()
|
||||
};
|
||||
|
||||
let body_offsets_z = height_offset(body);
|
||||
|
||||
Vec3::new(
|
||||
body_radius * ori.x * 1.1,
|
||||
body_radius * ori.y * 1.1,
|
||||
body_offsets_z,
|
||||
)
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ use crate::{
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::time::Duration;
|
||||
use vek::*;
|
||||
|
||||
/// Separated out to condense update portions of character state
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@ -112,7 +111,7 @@ impl CharacterBehavior for Data {
|
||||
get_crit_data(data, self.static_data.ability_info);
|
||||
let buff_strength = get_buff_strength(data, self.static_data.ability_info);
|
||||
// Gets offsets
|
||||
let body_offsets = projectile_offsets(data.body, update.ori.look_vec());
|
||||
let body_offsets = data.body.projectile_offsets(update.ori.look_vec());
|
||||
let pos = Pos(data.pos.0 + body_offsets);
|
||||
let projectile = arrow.create_projectile(
|
||||
Some(*data.uid),
|
||||
@ -192,31 +191,3 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
}
|
||||
|
||||
fn height_offset(body: &Body) -> f32 {
|
||||
match body {
|
||||
Body::Golem(_) => body.height() * 0.4,
|
||||
_ => body.eye_height(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn projectile_offsets(body: &Body, ori: Vec3<f32>) -> Vec3<f32> {
|
||||
let dim = body.dimensions();
|
||||
// The width (shoulder to shoulder) and length (nose to tail)
|
||||
let (width, length) = (dim.x, dim.y);
|
||||
let body_radius = if length > width {
|
||||
// Dachshund-like
|
||||
body.max_radius()
|
||||
} else {
|
||||
// Cyclops-like
|
||||
body.min_radius()
|
||||
};
|
||||
|
||||
let body_offsets_z = height_offset(body);
|
||||
|
||||
Vec3::new(
|
||||
body_radius * ori.x * 1.1,
|
||||
body_radius * ori.y * 1.1,
|
||||
body_offsets_z,
|
||||
)
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ use crate::{
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::time::Duration;
|
||||
use vek::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
/// Separated out to condense update portions of character state
|
||||
@ -93,7 +92,7 @@ impl CharacterBehavior for Data {
|
||||
get_crit_data(data, self.static_data.ability_info);
|
||||
let buff_strength = get_buff_strength(data, self.static_data.ability_info);
|
||||
// Gets offsets
|
||||
let body_offsets = projectile_offsets(data.body, update.ori.look_vec());
|
||||
let body_offsets = data.body.projectile_offsets(update.ori.look_vec());
|
||||
let pos = Pos(data.pos.0 + body_offsets);
|
||||
let projectile = self.static_data.projectile.create_projectile(
|
||||
Some(*data.uid),
|
||||
@ -169,31 +168,3 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
}
|
||||
|
||||
fn height_offset(body: &Body) -> f32 {
|
||||
match body {
|
||||
Body::Golem(_) => body.height() * 0.4,
|
||||
_ => body.eye_height(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn projectile_offsets(body: &Body, ori: Vec3<f32>) -> Vec3<f32> {
|
||||
let dim = body.dimensions();
|
||||
// The width (shoulder to shoulder) and length (nose to tail)
|
||||
let (width, length) = (dim.x, dim.y);
|
||||
let body_radius = if length > width {
|
||||
// Dachshund-like
|
||||
body.max_radius()
|
||||
} else {
|
||||
// Cyclops-like
|
||||
body.min_radius()
|
||||
};
|
||||
|
||||
let body_offsets_z = height_offset(body);
|
||||
|
||||
Vec3::new(
|
||||
body_radius * ori.x * 1.1,
|
||||
body_radius * ori.y * 1.1,
|
||||
body_offsets_z,
|
||||
)
|
||||
}
|
||||
|
@ -238,6 +238,32 @@ impl Body {
|
||||
/// Returns how well a body can move backwards while strafing (0.0 = not at
|
||||
/// all, 1.0 = same as forward)
|
||||
pub fn reverse_move_factor(&self) -> f32 { 0.45 }
|
||||
|
||||
/// Returns the position where a projectile should be fired relative to this
|
||||
/// body
|
||||
pub fn projectile_offsets(&self, ori: Vec3<f32>) -> Vec3<f32> {
|
||||
let body_offsets_z = match self {
|
||||
Body::Golem(_) => self.height() * 0.4,
|
||||
_ => self.eye_height(),
|
||||
};
|
||||
|
||||
let dim = self.dimensions();
|
||||
// The width (shoulder to shoulder) and length (nose to tail)
|
||||
let (width, length) = (dim.x, dim.y);
|
||||
let body_radius = if length > width {
|
||||
// Dachshund-like
|
||||
self.max_radius()
|
||||
} else {
|
||||
// Cyclops-like
|
||||
self.min_radius()
|
||||
};
|
||||
|
||||
Vec3::new(
|
||||
body_radius * ori.x * 1.1,
|
||||
body_radius * ori.y * 1.1,
|
||||
body_offsets_z,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles updating `Components` to move player based on state of `JoinData`
|
||||
|
@ -28,7 +28,7 @@ use common::{
|
||||
path::TraversalConfig,
|
||||
resources::{DeltaTime, Time, TimeOfDay},
|
||||
rtsim::{Memory, MemoryItem, RtSimEntity, RtSimEvent},
|
||||
states::{basic_beam, basic_ranged, charged_ranged, repeater_ranged, utils::StageSection},
|
||||
states::{basic_beam, utils::StageSection},
|
||||
terrain::{Block, TerrainGrid},
|
||||
time::DayPeriod,
|
||||
trade::{TradeAction, TradePhase, TradeResult},
|
||||
@ -1832,7 +1832,7 @@ impl<'a> AgentData<'a> {
|
||||
projectile_speed,
|
||||
self.pos.0
|
||||
+ self.body.map_or(Vec3::zero(), |body| {
|
||||
charged_ranged::projectile_offsets(body, self.ori.look_vec())
|
||||
body.projectile_offsets(self.ori.look_vec())
|
||||
}),
|
||||
Vec3::new(
|
||||
tgt_data.pos.0.x,
|
||||
@ -1847,7 +1847,7 @@ impl<'a> AgentData<'a> {
|
||||
projectile_speed,
|
||||
self.pos.0
|
||||
+ self.body.map_or(Vec3::zero(), |body| {
|
||||
basic_ranged::projectile_offsets(body, self.ori.look_vec())
|
||||
body.projectile_offsets(self.ori.look_vec())
|
||||
}),
|
||||
Vec3::new(
|
||||
tgt_data.pos.0.x,
|
||||
@ -1862,7 +1862,7 @@ impl<'a> AgentData<'a> {
|
||||
projectile_speed,
|
||||
self.pos.0
|
||||
+ self.body.map_or(Vec3::zero(), |body| {
|
||||
repeater_ranged::projectile_offsets(body, self.ori.look_vec())
|
||||
body.projectile_offsets(self.ori.look_vec())
|
||||
}),
|
||||
Vec3::new(
|
||||
tgt_data.pos.0.x,
|
||||
|
Loading…
Reference in New Issue
Block a user