Added hands field onto weapons.

This commit is contained in:
Sam 2021-02-12 00:15:10 -05:00
parent b4adc5369a
commit d4f509b3d0
14 changed files with 134 additions and 89 deletions

View File

@ -4,7 +4,8 @@ rustflags = [
]
[alias]
generate = "run --package tools --"
csv-export = "run --manifest-path common/Cargo.toml --features=bin_csv --bin csv_export"
csv-import = "run --manifest-path common/Cargo.toml --features=bin_csv --bin csv_import"
test-server = "-Zpackage-features run --bin veloren-server-cli --no-default-features -- -b"
tracy-server = "-Zunstable-options -Zpackage-features run --bin veloren-server-cli --no-default-features --features tracy,simd --profile no_overflow"
test-voxygen = "-Zpackage-features run --bin veloren-voxygen --no-default-features --features gl,simd"

View File

@ -71,6 +71,7 @@ fn weapon_stats() -> Result<(), Box<dyn Error>> {
"Path",
"Kind",
"Name",
"Hands",
"Quality",
"Power",
"Poise Strength",
@ -89,11 +90,13 @@ fn weapon_stats() -> Result<(), Box<dyn Error>> {
let speed = tool.base_speed().to_string();
let equip_time = tool.equip_time().subsec_millis().to_string();
let kind = get_tool_kind(&tool.kind);
let hands = get_tool_hands(&tool);
wtr.write_record(&[
item.item_definition_id(),
&kind,
item.name(),
&hands,
&format!("{:?}", item.quality()),
&power,
&poise_strength,
@ -127,6 +130,13 @@ fn get_tool_kind(kind: &ToolKind) -> String {
}
}
fn get_tool_hands(tool: &Tool) -> String {
match tool.hands {
Hands::OneHand => "OneHand".to_string(),
Hands::TwoHand => "TwoHand".to_string(),
}
}
fn get_armor_kind(kind: &ArmorKind) -> String {
match kind {
ArmorKind::Shoulder(_) => "Shoulder".to_string(),

View File

@ -171,7 +171,7 @@ fn weapon_stats() -> Result<(), Box<dyn Error>> {
{
let kind = tool.kind;
let equip_time_millis: u32 = record
.get(7)
.get(8)
.expect(&format!(
"Error unwrapping equip time for {:?}",
item.item_definition_id()
@ -179,7 +179,7 @@ fn weapon_stats() -> Result<(), Box<dyn Error>> {
.parse()
.expect(&format!("Not a u32? {:?}", item.item_definition_id()));
let power: f32 = record
.get(4)
.get(5)
.expect(&format!(
"Error unwrapping power for {:?}",
item.item_definition_id()
@ -187,7 +187,7 @@ fn weapon_stats() -> Result<(), Box<dyn Error>> {
.parse()
.expect(&format!("Not a f32? {:?}", item.item_definition_id()));
let poise_strength: f32 = record
.get(5)
.get(6)
.expect(&format!(
"Error unwrapping poise power for {:?}",
item.item_definition_id()
@ -196,7 +196,7 @@ fn weapon_stats() -> Result<(), Box<dyn Error>> {
.expect(&format!("Not a f32? {:?}", item.item_definition_id()));
let speed: f32 = record
.get(6)
.get(7)
.expect(&format!(
"Error unwrapping speed for {:?}",
item.item_definition_id()
@ -204,15 +204,40 @@ fn weapon_stats() -> Result<(), Box<dyn Error>> {
.parse()
.expect(&format!("Not a f32? {:?}", item.item_definition_id()));
let hands = if let Some(hands_raw) = record.get(3) {
match hands_raw {
"OneHand" | "One" | "1" | "1h" => {
comp::item::tool::Hands::OneHand
},
"TwoHand" | "Two" | "2" | "2h" => {
comp::item::tool::Hands::TwoHand
},
_ => {
eprintln!(
"Unknown hand variant for {:?}",
item.item_definition_id()
);
comp::item::tool::Hands::TwoHand
},
}
} else {
eprintln!(
"Could not unwrap hand for {:?}",
item.item_definition_id()
);
comp::item::tool::Hands::TwoHand
};
let tool = comp::item::tool::Tool::new(
kind,
hands,
equip_time_millis,
power,
poise_strength,
speed,
);
let quality = if let Some(quality_raw) = record.get(3) {
let quality = if let Some(quality_raw) = record.get(4) {
match quality_raw {
"Low" => comp::item::Quality::Low,
"Common" => comp::item::Quality::Common,
@ -238,7 +263,7 @@ fn weapon_stats() -> Result<(), Box<dyn Error>> {
comp::item::Quality::Debug
};
let description = record.get(8).expect(&format!(
let description = record.get(9).expect(&format!(
"Error unwrapping description for {:?}",
item.item_definition_id()
));

View File

@ -99,7 +99,7 @@ impl ItemTag {
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum ItemKind {
/// Something wieldable
Tool(tool::Tool),

View File

@ -27,31 +27,13 @@ pub enum ToolKind {
Empty,
}
impl ToolKind {
pub fn hands(&self) -> Hands {
match self {
ToolKind::Sword => Hands::TwoHand,
ToolKind::Axe => Hands::TwoHand,
ToolKind::Hammer => Hands::TwoHand,
ToolKind::Bow => Hands::TwoHand,
ToolKind::Dagger => Hands::OneHand,
ToolKind::Staff => Hands::TwoHand,
ToolKind::Sceptre => Hands::TwoHand,
ToolKind::Shield => Hands::OneHand,
ToolKind::Unique(_) => Hands::TwoHand,
ToolKind::Debug => Hands::TwoHand,
ToolKind::Farming => Hands::TwoHand,
ToolKind::Empty => Hands::OneHand,
}
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum Hands {
OneHand,
TwoHand,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct Stats {
equip_time_millis: u32,
power: f32,
@ -59,9 +41,10 @@ pub struct Stats {
speed: f32,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Tool {
pub kind: ToolKind,
pub hands: Hands,
pub stats: Stats,
// TODO: item specific abilities
}
@ -71,6 +54,7 @@ impl Tool {
// Added for CSV import of stats
pub fn new(
kind: ToolKind,
hands: Hands,
equip_time_millis: u32,
power: f32,
poise_strength: f32,
@ -78,6 +62,7 @@ impl Tool {
) -> Self {
Self {
kind,
hands,
stats: Stats {
equip_time_millis,
power,
@ -90,6 +75,7 @@ impl Tool {
pub fn empty() -> Self {
Self {
kind: ToolKind::Empty,
hands: Hands::OneHand,
stats: Stats {
equip_time_millis: 0,
power: 1.00,

View File

@ -424,28 +424,25 @@ pub fn handle_ability1_input(data: &JoinData, update: &mut StateUpdate) {
pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) {
if data.inputs.secondary.is_pressed() {
let active_tool_kind = match data
let active_tool_hands = match data
.inventory
.equipped(EquipSlot::Mainhand)
.map(|i| i.kind())
{
Some(ItemKind::Tool(Tool { kind, .. })) => Some(kind),
Some(ItemKind::Tool(tool)) => Some(tool.hands),
_ => None,
};
let second_tool_kind = match data
let second_tool_hands = match data
.inventory
.equipped(EquipSlot::Offhand)
.map(|i| i.kind())
{
Some(ItemKind::Tool(Tool { kind, .. })) => Some(kind),
Some(ItemKind::Tool(tool)) => Some(tool.hands),
_ => None,
};
match (
active_tool_kind.map(|tk| tk.hands()),
second_tool_kind.map(|tk| tk.hands()),
) {
match (active_tool_hands, second_tool_hands) {
(Some(Hands::TwoHand), _) => {
if let Some(ability) = data
.inventory

View File

@ -8,7 +8,13 @@ use std::{f32::consts::PI, ops::Mul};
pub struct IdleAnimation;
impl Animation for IdleAnimation {
type Dependency = (Option<ToolKind>, Option<ToolKind>, f64);
#[allow(clippy::type_complexity)]
type Dependency = (
Option<ToolKind>,
Option<ToolKind>,
(Option<Hands>, Option<Hands>),
f64,
);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
@ -17,7 +23,7 @@ impl Animation for IdleAnimation {
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_idle")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, second_tool_kind, global_time): Self::Dependency,
(active_tool_kind, second_tool_kind, hands, global_time): Self::Dependency,
anim_time: f64,
_rate: &mut f32,
s_a: &SkeletonAttr,
@ -137,10 +143,7 @@ impl Animation for IdleAnimation {
next.torso.position = Vec3::new(0.0, 0.0, 0.0) * s_a.scaler;
next.second.scale = match (
active_tool_kind.map(|tk| tk.hands()),
second_tool_kind.map(|tk| tk.hands()),
) {
next.second.scale = match hands {
(Some(Hands::OneHand), Some(Hands::OneHand)) => Vec3::one(),
(_, _) => Vec3::zero(),
};

View File

@ -7,9 +7,11 @@ use std::f32::consts::PI;
pub struct JumpAnimation;
impl Animation for JumpAnimation {
#[allow(clippy::type_complexity)]
type Dependency = (
Option<ToolKind>,
Option<ToolKind>,
(Option<Hands>, Option<Hands>),
Vec3<f32>,
Vec3<f32>,
f64,
@ -23,7 +25,7 @@ impl Animation for JumpAnimation {
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, second_tool_kind, orientation, last_ori, global_time): Self::Dependency,
(active_tool_kind, second_tool_kind, hands, orientation, last_ori, global_time): Self::Dependency,
anim_time: f64,
_rate: &mut f32,
s_a: &SkeletonAttr,
@ -179,10 +181,7 @@ impl Animation for JumpAnimation {
next.torso.orientation = Quaternion::rotation_x(-0.2);
next.torso.scale = Vec3::one() / 11.0 * s_a.scaler;
next.second.scale = match (
active_tool_kind.map(|tk| tk.hands()),
second_tool_kind.map(|tk| tk.hands()),
) {
next.second.scale = match hands {
(Some(Hands::OneHand), Some(Hands::OneHand)) => Vec3::one(),
(_, _) => Vec3::zero(),
};

View File

@ -10,6 +10,7 @@ pub struct RunAnimation;
type RunAnimationDependency = (
Option<ToolKind>,
Option<ToolKind>,
(Option<Hands>, Option<Hands>),
Vec3<f32>,
Vec3<f32>,
Vec3<f32>,
@ -32,6 +33,7 @@ impl Animation for RunAnimation {
(
active_tool_kind,
second_tool_kind,
hands,
velocity,
orientation,
last_ori,
@ -263,10 +265,7 @@ impl Animation for RunAnimation {
next.torso.position = Vec3::new(0.0, 0.0, 0.0) * s_a.scaler;
next.torso.scale = Vec3::one() / 11.0 * s_a.scaler;
next.second.scale = match (
active_tool_kind.map(|tk| tk.hands()),
second_tool_kind.map(|tk| tk.hands()),
) {
next.second.scale = match hands {
(Some(Hands::OneHand), Some(Hands::OneHand)) => Vec3::one(),
(_, _) => Vec3::zero(),
};

View File

@ -8,7 +8,14 @@ use std::{f32::consts::PI, ops::Mul};
pub struct StandAnimation;
impl Animation for StandAnimation {
type Dependency = (Option<ToolKind>, Option<ToolKind>, f64, Vec3<f32>);
#[allow(clippy::type_complexity)]
type Dependency = (
Option<ToolKind>,
Option<ToolKind>,
(Option<Hands>, Option<Hands>),
f64,
Vec3<f32>,
);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
@ -17,7 +24,7 @@ impl Animation for StandAnimation {
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_stand")]
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, second_tool_kind, global_time, avg_vel): Self::Dependency,
(active_tool_kind, second_tool_kind, hands, global_time, avg_vel): Self::Dependency,
anim_time: f64,
_rate: &mut f32,
s_a: &SkeletonAttr,
@ -143,10 +150,7 @@ impl Animation for StandAnimation {
next.torso.position = Vec3::new(0.0, 0.0, 0.0) * s_a.scaler;
next.second.scale = match (
active_tool_kind.map(|tk| tk.hands()),
second_tool_kind.map(|tk| tk.hands()),
) {
next.second.scale = match hands {
(Some(Hands::OneHand), Some(Hands::OneHand)) => Vec3::one(),
(_, _) => Vec3::zero(),
};

View File

@ -10,6 +10,7 @@ pub struct SwimAnimation;
type SwimAnimationDependency = (
Option<ToolKind>,
Option<ToolKind>,
(Option<Hands>, Option<Hands>),
Vec3<f32>,
Vec3<f32>,
Vec3<f32>,
@ -28,7 +29,16 @@ impl Animation for SwimAnimation {
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, second_tool_kind, velocity, orientation, last_ori, global_time, avg_vel): Self::Dependency,
(
active_tool_kind,
second_tool_kind,
hands,
velocity,
orientation,
last_ori,
global_time,
avg_vel,
): Self::Dependency,
anim_time: f64,
rate: &mut f32,
s_a: &SkeletonAttr,
@ -223,10 +233,7 @@ impl Animation for SwimAnimation {
* Quaternion::rotation_z(tilt * 8.0);
next.torso.scale = Vec3::one() / 11.0 * s_a.scaler;
next.second.scale = match (
active_tool_kind.map(|tk| tk.hands()),
second_tool_kind.map(|tk| tk.hands()),
) {
next.second.scale = match hands {
(Some(Hands::OneHand), Some(Hands::OneHand)) => Vec3::one(),
(_, _) => Vec3::zero(),
};

View File

@ -587,10 +587,7 @@ impl<'a> Widget for Skillbar<'a> {
let active_tool = get_tool(self.inventory, EquipSlot::Mainhand);
let second_tool = get_tool(self.inventory, EquipSlot::Offhand);
let tool = match (
active_tool.map(|x| x.kind.hands()),
second_tool.map(|x| x.kind.hands()),
) {
let tool = match (active_tool.map(|x| x.hands), second_tool.map(|x| x.hands)) {
(Some(Hands::TwoHand), _) => active_tool,
(_, Some(Hands::OneHand)) => second_tool,
(_, _) => None,

View File

@ -689,22 +689,26 @@ impl FigureMgr {
let active_item_kind = inventory
.and_then(|i| i.equipped(EquipSlot::Mainhand))
.map(|i| i.kind());
let active_tool_kind = if let Some(ItemKind::Tool(tool)) = active_item_kind {
Some(tool.kind)
let (active_tool_kind, active_tool_hand) =
if let Some(ItemKind::Tool(tool)) = active_item_kind {
(Some(tool.kind), Some(tool.hands))
} else {
None
(None, None)
};
let second_item_kind = inventory
.and_then(|i| i.equipped(EquipSlot::Offhand))
.map(|i| i.kind());
let second_tool_kind = if let Some(ItemKind::Tool(tool)) = second_item_kind {
Some(tool.kind)
let (second_tool_kind, second_tool_hand) =
if let Some(ItemKind::Tool(tool)) = second_item_kind {
(Some(tool.kind), Some(tool.hands))
} else {
None
(None, None)
};
let hands = (active_tool_hand, second_tool_hand);
match body {
Body::Humanoid(body) => {
let (model, skeleton_attr) = self.model_cache.get_or_create_model(
@ -742,7 +746,13 @@ impl FigureMgr {
// Standing
(true, false, false) => anim::character::StandAnimation::update_skeleton(
&CharacterSkeleton::default(),
(active_tool_kind, second_tool_kind, time, state.avg_vel),
(
active_tool_kind,
second_tool_kind,
hands,
time,
state.avg_vel,
),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
@ -753,6 +763,7 @@ impl FigureMgr {
(
active_tool_kind,
second_tool_kind,
hands,
vel.0,
// TODO: Update to use the quaternion.
ori * anim::vek::Vec3::<f32>::unit_y(),
@ -771,6 +782,7 @@ impl FigureMgr {
(
active_tool_kind,
second_tool_kind,
hands,
// TODO: Update to use the quaternion.
ori * anim::vek::Vec3::<f32>::unit_y(),
state.last_ori * anim::vek::Vec3::<f32>::unit_y(),
@ -786,6 +798,7 @@ impl FigureMgr {
(
active_tool_kind,
second_tool_kind,
hands,
vel.0,
// TODO: Update to use the quaternion.
ori * anim::vek::Vec3::<f32>::unit_y(),

View File

@ -308,26 +308,30 @@ impl Scene {
.and_then(|inv| inv.equipped(EquipSlot::Mainhand))
.map(|i| i.kind());
let active_tool_kind = if let Some(ItemKind::Tool(tool)) = active_item_kind {
Some(tool.kind)
let (active_tool_kind, active_tool_hand) =
if let Some(ItemKind::Tool(tool)) = active_item_kind {
(Some(tool.kind), Some(tool.hands))
} else {
None
(None, None)
};
let second_item_kind = inventory
.and_then(|inv| inv.equipped(EquipSlot::Offhand))
.map(|i| i.kind());
let second_tool_kind = if let Some(ItemKind::Tool(tool)) = second_item_kind {
Some(tool.kind)
let (second_tool_kind, second_tool_hand) =
if let Some(ItemKind::Tool(tool)) = second_item_kind {
(Some(tool.kind), Some(tool.hands))
} else {
None
(None, None)
};
let hands = (active_tool_hand, second_tool_hand);
if let Some(body) = scene_data.body {
let tgt_skeleton = IdleAnimation::update_skeleton(
self.figure_state.skeleton_mut(),
(active_tool_kind, second_tool_kind, scene_data.time),
(active_tool_kind, second_tool_kind, hands, scene_data.time),
scene_data.time,
&mut 0.0,
&SkeletonAttr::from(&body),