Addressed comments

This commit is contained in:
Sam 2020-09-21 17:38:01 -05:00
parent 8ab0d5e5e0
commit 2ff59c9f60
10 changed files with 608 additions and 611 deletions

View File

@ -381,19 +381,21 @@ impl From<&CharacterAbility> for CharacterState {
max_speed_increase,
is_interruptible,
} => CharacterState::ComboMelee(combo_melee::Data {
stage: 1,
static_data: combo_melee::StaticData {
num_stages: stage_data.len() as u32,
combo: 0,
stage_data: stage_data.clone(),
initial_energy_gain: *initial_energy_gain,
max_energy_gain: *max_energy_gain,
energy_increase: *energy_increase,
timer: Duration::default(),
stage_section: StageSection::Buildup,
next_stage: false,
speed_increase: 1.0 - *speed_increase,
max_speed_increase: *max_speed_increase - 1.0,
is_interruptible: *is_interruptible,
},
stage: 1,
combo: 0,
timer: Duration::default(),
stage_section: StageSection::Buildup,
next_stage: false,
}),
CharacterAbility::LeapMelee {
energy_cost: _,

View File

@ -124,8 +124,9 @@ impl LoadoutBuilder {
};
let loadout = match body {
Body::Humanoid(_) => match is_giant {
true => Loadout {
Body::Humanoid(_) => {
if is_giant {
Loadout {
active_item,
second_item: None,
shoulder: Some(Item::new_from_asset_expect(
@ -153,8 +154,9 @@ impl LoadoutBuilder {
glider: None,
head: None,
tabard: None,
},
false => match alignment {
}
} else {
match alignment {
Alignment::Npc => Loadout {
active_item,
second_item: None,
@ -220,13 +222,16 @@ impl LoadoutBuilder {
)),
ring: None,
neck: None,
lantern: Some(Item::new_from_asset_expect("common.items.lantern.black_0")),
lantern: Some(Item::new_from_asset_expect(
"common.items.lantern.black_0",
)),
glider: None,
head: None,
tabard: None,
},
_ => LoadoutBuilder::animal(body).build(),
},
}
}
},
Body::Golem(golem) => match golem.species {
golem::Species::StoneGolem => Loadout {

View File

@ -33,16 +33,11 @@ pub struct Stage {
pub forward_movement: f32,
}
/// A sequence of attacks that can incrementally become faster and more
/// damaging.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Data {
/// Indicates what stage the combo is in
pub stage: u32,
/// Separated out to condense update portions of character state
pub struct StaticData {
/// Indicates number of stages in combo
pub num_stages: u32,
/// Number of consecutive strikes
pub combo: u32,
/// Data for each stage
pub stage_data: Vec<Stage>,
/// Initial energy gain per strike
@ -51,12 +46,6 @@ pub struct Data {
pub max_energy_gain: u32,
/// Energy gain increase per combo
pub energy_increase: u32,
/// Timer for each stage
pub timer: Duration,
/// Checks what section a stage is in
pub stage_section: StageSection,
/// Whether the state should go onto the next stage
pub next_stage: bool,
/// (100% - speed_increase) is percentage speed increases from current to
/// max when combo increases
pub speed_increase: f32,
@ -65,6 +54,24 @@ pub struct Data {
/// Whether the state can be interrupted by other abilities
pub is_interruptible: bool,
}
/// A sequence of attacks that can incrementally become faster and more
/// damaging.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Data {
/// Struct containing data that does not change over the course of the
/// character state
pub static_data: StaticData,
/// Indicates what stage the combo is in
pub stage: u32,
/// Number of consecutive strikes
pub combo: u32,
/// Timer for each stage
pub timer: Duration,
/// Checks what section a stage is in
pub stage_section: StageSection,
/// Whether the state should go onto the next stage
pub next_stage: bool,
}
impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate {
@ -76,7 +83,7 @@ impl CharacterBehavior for Data {
let stage_index = (self.stage - 1) as usize;
// Allows for other states to interrupt this state
if self.is_interruptible && !data.inputs.primary.is_pressed() {
if self.static_data.is_interruptible && !data.inputs.primary.is_pressed() {
handle_interrupt(data, &mut update);
match update.character {
CharacterState::ComboMelee(_) => {},
@ -86,182 +93,147 @@ impl CharacterBehavior for Data {
}
}
if self.stage_section == StageSection::Buildup
&& self.timer < self.stage_data[stage_index].base_buildup_duration
{
match self.stage_section {
StageSection::Buildup => {
if self.timer < self.static_data.stage_data[stage_index].base_buildup_duration {
// Build up
update.character = CharacterState::ComboMelee(Data {
static_data: self.static_data.clone(),
stage: self.stage,
num_stages: self.num_stages,
combo: self.combo,
stage_data: self.stage_data.clone(),
initial_energy_gain: self.initial_energy_gain,
max_energy_gain: self.max_energy_gain,
energy_increase: self.energy_increase,
timer: self
.timer
.checked_add(Duration::from_secs_f32(
(1.0 + self.max_speed_increase
* (1.0 - self.speed_increase.powi(self.combo as i32)))
(1.0 + self.static_data.max_speed_increase
* (1.0
- self.static_data.speed_increase.powi(self.combo as i32)))
* data.dt.0,
))
.unwrap_or_default(),
stage_section: self.stage_section,
next_stage: self.next_stage,
speed_increase: self.speed_increase,
max_speed_increase: self.max_speed_increase,
is_interruptible: self.is_interruptible,
});
} else if self.stage_section == StageSection::Buildup {
} else {
// Transitions to swing section of stage
update.character = CharacterState::ComboMelee(Data {
static_data: self.static_data.clone(),
stage: self.stage,
num_stages: self.num_stages,
combo: self.combo,
stage_data: self.stage_data.clone(),
initial_energy_gain: self.initial_energy_gain,
max_energy_gain: self.max_energy_gain,
energy_increase: self.energy_increase,
timer: Duration::default(),
stage_section: StageSection::Swing,
next_stage: self.next_stage,
speed_increase: self.speed_increase,
max_speed_increase: self.max_speed_increase,
is_interruptible: self.is_interruptible,
});
// Hit attempt
data.updater.insert(data.entity, Attacking {
base_healthchange: -((self.stage_data[stage_index].max_damage.min(
self.stage_data[stage_index].base_damage
+ self.combo / self.num_stages
* self.stage_data[stage_index].damage_increase,
base_healthchange: -((self.static_data.stage_data[stage_index]
.max_damage
.min(
self.static_data.stage_data[stage_index].base_damage
+ self.combo / self.static_data.num_stages
* self.static_data.stage_data[stage_index].damage_increase,
)) as i32),
range: self.stage_data[stage_index].range,
max_angle: self.stage_data[stage_index].angle.to_radians(),
range: self.static_data.stage_data[stage_index].range,
max_angle: self.static_data.stage_data[stage_index].angle.to_radians(),
applied: false,
hit_count: 0,
knockback: self.stage_data[stage_index].knockback,
knockback: self.static_data.stage_data[stage_index].knockback,
});
} else if self.stage_section == StageSection::Swing
&& self.timer < self.stage_data[stage_index].base_swing_duration
{
}
},
StageSection::Swing => {
if self.timer < self.static_data.stage_data[stage_index].base_swing_duration {
// Forward movement
forward_move(
data,
&mut update,
0.3,
self.stage_data[stage_index].forward_movement,
self.static_data.stage_data[stage_index].forward_movement,
);
// Swings
update.character = CharacterState::ComboMelee(Data {
static_data: self.static_data.clone(),
stage: self.stage,
num_stages: self.num_stages,
combo: self.combo,
stage_data: self.stage_data.clone(),
initial_energy_gain: self.initial_energy_gain,
max_energy_gain: self.max_energy_gain,
energy_increase: self.energy_increase,
timer: self
.timer
.checked_add(Duration::from_secs_f32(
(1.0 + self.max_speed_increase
* (1.0 - self.speed_increase.powi(self.combo as i32)))
(1.0 + self.static_data.max_speed_increase
* (1.0
- self.static_data.speed_increase.powi(self.combo as i32)))
* data.dt.0,
))
.unwrap_or_default(),
stage_section: self.stage_section,
next_stage: self.next_stage,
speed_increase: self.speed_increase,
max_speed_increase: self.max_speed_increase,
is_interruptible: self.is_interruptible,
});
} else if self.stage_section == StageSection::Swing {
} else {
// Transitions to recover section of stage
update.character = CharacterState::ComboMelee(Data {
static_data: self.static_data.clone(),
stage: self.stage,
num_stages: self.num_stages,
combo: self.combo,
stage_data: self.stage_data.clone(),
initial_energy_gain: self.initial_energy_gain,
max_energy_gain: self.max_energy_gain,
energy_increase: self.energy_increase,
timer: Duration::default(),
stage_section: StageSection::Recover,
next_stage: self.next_stage,
speed_increase: self.speed_increase,
max_speed_increase: self.max_speed_increase,
is_interruptible: self.is_interruptible,
});
} else if self.stage_section == StageSection::Recover
&& self.timer < self.stage_data[stage_index].base_recover_duration
{
}
},
StageSection::Recover => {
if self.timer < self.static_data.stage_data[stage_index].base_recover_duration {
// Recovers
if data.inputs.primary.is_pressed() {
// Checks if state will transition to next stage after recover
update.character = CharacterState::ComboMelee(Data {
static_data: self.static_data.clone(),
stage: self.stage,
num_stages: self.num_stages,
combo: self.combo,
stage_data: self.stage_data.clone(),
initial_energy_gain: self.initial_energy_gain,
max_energy_gain: self.max_energy_gain,
energy_increase: self.energy_increase,
timer: self
.timer
.checked_add(Duration::from_secs_f32(
(1.0 + self.max_speed_increase
* (1.0 - self.speed_increase.powi(self.combo as i32)))
(1.0 + self.static_data.max_speed_increase
* (1.0
- self
.static_data
.speed_increase
.powi(self.combo as i32)))
* data.dt.0,
))
.unwrap_or_default(),
stage_section: self.stage_section,
next_stage: true,
speed_increase: self.speed_increase,
max_speed_increase: self.max_speed_increase,
is_interruptible: self.is_interruptible,
});
} else {
update.character = CharacterState::ComboMelee(Data {
static_data: self.static_data.clone(),
stage: self.stage,
num_stages: self.num_stages,
combo: self.combo,
stage_data: self.stage_data.clone(),
initial_energy_gain: self.initial_energy_gain,
max_energy_gain: self.max_energy_gain,
energy_increase: self.energy_increase,
timer: self
.timer
.checked_add(Duration::from_secs_f32(
(1.0 + self.max_speed_increase
* (1.0 - self.speed_increase.powi(self.combo as i32)))
(1.0 + self.static_data.max_speed_increase
* (1.0
- self
.static_data
.speed_increase
.powi(self.combo as i32)))
* data.dt.0,
))
.unwrap_or_default(),
stage_section: self.stage_section,
next_stage: self.next_stage,
speed_increase: self.speed_increase,
max_speed_increase: self.max_speed_increase,
is_interruptible: self.is_interruptible,
});
}
} else if self.next_stage {
// Transitions to buildup section of next stage
update.character = CharacterState::ComboMelee(Data {
stage: (self.stage % self.num_stages) + 1,
num_stages: self.num_stages,
static_data: self.static_data.clone(),
stage: (self.stage % self.static_data.num_stages) + 1,
combo: self.combo,
stage_data: self.stage_data.clone(),
initial_energy_gain: self.initial_energy_gain,
max_energy_gain: self.max_energy_gain,
energy_increase: self.energy_increase,
timer: Duration::default(),
stage_section: StageSection::Buildup,
next_stage: false,
speed_increase: self.speed_increase,
max_speed_increase: self.max_speed_increase,
is_interruptible: self.is_interruptible,
});
} else {
// Done
@ -269,28 +241,29 @@ impl CharacterBehavior for Data {
// Make sure attack component is removed
data.updater.remove::<Attacking>(data.entity);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding;
// Make sure attack component is removed
data.updater.remove::<Attacking>(data.entity);
},
}
// Grant energy on successful hit
if let Some(attack) = data.attacking {
if attack.applied && attack.hit_count > 0 {
let energy = self
.max_energy_gain
.min(self.initial_energy_gain + self.combo * self.energy_increase)
as i32;
let energy = self.static_data.max_energy_gain.min(
self.static_data.initial_energy_gain
+ self.combo * self.static_data.energy_increase,
) as i32;
update.character = CharacterState::ComboMelee(Data {
static_data: self.static_data.clone(),
stage: self.stage,
num_stages: self.num_stages,
combo: self.combo + 1,
stage_data: self.stage_data.clone(),
initial_energy_gain: self.initial_energy_gain,
max_energy_gain: self.max_energy_gain,
energy_increase: self.energy_increase,
timer: self.timer,
stage_section: self.stage_section,
next_stage: self.next_stage,
speed_increase: self.speed_increase,
max_speed_increase: self.max_speed_increase,
is_interruptible: self.is_interruptible,
});
data.updater.remove::<Attacking>(data.entity);
update.energy.change_by(energy, EnergySource::HitEnemy);

View File

@ -73,9 +73,9 @@ impl CharacterBehavior for Data {
}
}
if self.stage_section == StageSection::Buildup
&& self.timer < self.static_data.buildup_duration
{
match self.stage_section {
StageSection::Buildup => {
if self.timer < self.static_data.buildup_duration {
// Build up
update.character = CharacterState::DashMelee(Data {
static_data: self.static_data,
@ -86,8 +86,8 @@ impl CharacterBehavior for Data {
.unwrap_or_default(),
stage_section: self.stage_section,
exhausted: self.exhausted,
})
} else if self.stage_section == StageSection::Buildup {
});
} else {
// Transitions to charge section of stage
update.character = CharacterState::DashMelee(Data {
static_data: self.static_data,
@ -95,9 +95,11 @@ impl CharacterBehavior for Data {
timer: Duration::default(),
stage_section: StageSection::Charge,
exhausted: self.exhausted,
})
} else if self.stage_section == StageSection::Charge
&& (self.timer < self.static_data.charge_duration
});
}
},
StageSection::Charge => {
if (self.timer < self.static_data.charge_duration
|| (self.static_data.infinite_charge && data.inputs.secondary.is_pressed()))
&& update.energy.current() > 0
&& !self.end_charge
@ -114,7 +116,8 @@ impl CharacterBehavior for Data {
- self.static_data.base_damage as f32)
* charge_frac
+ self.static_data.base_damage as f32;
let knockback = (self.static_data.max_knockback - self.static_data.base_knockback)
let knockback = (self.static_data.max_knockback
- self.static_data.base_knockback)
* charge_frac
+ self.static_data.base_knockback;
data.updater.insert(data.entity, Attacking {
@ -193,7 +196,7 @@ impl CharacterBehavior for Data {
-(self.static_data.energy_drain as f32 * data.dt.0) as i32,
EnergySource::Ability,
);
} else if self.stage_section == StageSection::Charge {
} else {
// Transitions to swing section of stage
update.character = CharacterState::DashMelee(Data {
static_data: self.static_data,
@ -201,10 +204,11 @@ impl CharacterBehavior for Data {
timer: Duration::default(),
stage_section: StageSection::Swing,
exhausted: self.exhausted,
})
} else if self.stage_section == StageSection::Swing
&& self.timer < self.static_data.swing_duration
{
});
}
},
StageSection::Swing => {
if self.timer < self.static_data.swing_duration {
// Swings
update.character = CharacterState::DashMelee(Data {
static_data: self.static_data,
@ -215,8 +219,8 @@ impl CharacterBehavior for Data {
.unwrap_or_default(),
stage_section: self.stage_section,
exhausted: self.exhausted,
})
} else if self.stage_section == StageSection::Swing {
});
} else {
// Transitions to recover section of stage
update.character = CharacterState::DashMelee(Data {
static_data: self.static_data,
@ -224,10 +228,11 @@ impl CharacterBehavior for Data {
timer: Duration::default(),
stage_section: StageSection::Recover,
exhausted: self.exhausted,
})
} else if self.stage_section == StageSection::Recover
&& self.timer < self.static_data.recover_duration
{
});
}
},
StageSection::Recover => {
if self.timer < self.static_data.recover_duration {
// Recover
update.character = CharacterState::DashMelee(Data {
static_data: self.static_data,
@ -238,13 +243,15 @@ impl CharacterBehavior for Data {
.unwrap_or_default(),
stage_section: self.stage_section,
exhausted: self.exhausted,
})
});
} else {
// Done
update.character = CharacterState::Wielding;
// Make sure attack component is removed
data.updater.remove::<Attacking>(data.entity);
}
},
}
update
}

View File

@ -70,9 +70,9 @@ impl CharacterBehavior for Data {
}
}
if self.stage_section == StageSection::Buildup
&& self.timer < self.static_data.buildup_duration
{
match self.stage_section {
StageSection::Buildup => {
if self.timer < self.static_data.buildup_duration {
// Build up
update.character = CharacterState::SpinMelee(Data {
static_data: self.static_data,
@ -84,7 +84,7 @@ impl CharacterBehavior for Data {
stage_section: self.stage_section,
exhausted: self.exhausted,
});
} else if self.stage_section == StageSection::Buildup {
} else {
// Transitions to swing section of stage
update.character = CharacterState::SpinMelee(Data {
static_data: self.static_data,
@ -93,7 +93,10 @@ impl CharacterBehavior for Data {
stage_section: StageSection::Swing,
exhausted: self.exhausted,
});
} else if !self.exhausted {
}
},
StageSection::Swing => {
if !self.exhausted {
update.character = CharacterState::SpinMelee(Data {
static_data: self.static_data,
timer: Duration::default(),
@ -110,9 +113,7 @@ impl CharacterBehavior for Data {
hit_count: 0,
knockback: self.static_data.knockback,
});
} else if self.stage_section == StageSection::Swing
&& self.timer < self.static_data.swing_duration
{
} else if self.timer < self.static_data.swing_duration {
if !self.static_data.is_helicopter {
forward_move(data, &mut update, 0.1, self.static_data.forward_speed);
handle_orientation(data, &mut update, 1.0);
@ -150,7 +151,7 @@ impl CharacterBehavior for Data {
-(self.static_data.energy_cost as i32),
EnergySource::Ability,
);
} else if self.stage_section == StageSection::Swing {
} else {
// Transitions to recover section of stage
update.character = CharacterState::SpinMelee(Data {
static_data: self.static_data,
@ -158,10 +159,11 @@ impl CharacterBehavior for Data {
spins_remaining: self.spins_remaining,
stage_section: StageSection::Recover,
exhausted: self.exhausted,
})
} else if self.stage_section == StageSection::Recover
&& self.timer < self.static_data.recover_duration
{
});
}
},
StageSection::Recover => {
if self.timer < self.static_data.recover_duration {
// Recover
update.character = CharacterState::SpinMelee(Data {
static_data: self.static_data,
@ -172,13 +174,21 @@ impl CharacterBehavior for Data {
spins_remaining: self.spins_remaining,
stage_section: self.stage_section,
exhausted: self.exhausted,
})
});
} else {
// Done
update.character = CharacterState::Wielding;
// Make sure attack component is removed
data.updater.remove::<Attacking>(data.entity);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding;
// Make sure attack component is removed
data.updater.remove::<Attacking>(data.entity);
},
}
update
}

View File

@ -193,10 +193,6 @@ impl<'a> System<'a> for Sys {
continue;
}
if entity_other == entity {
continue;
}
let scale_other = scale_other.map(|s| s.0).unwrap_or(1.0);
let radius_other = collider_other.map(|c| c.get_radius()).unwrap_or(0.5);
let z_limits_other = collider_other

View File

@ -114,9 +114,8 @@ fn matches_ability_stage() {
let result = CombatEventMapper::map_event(
&CharacterState::ComboMelee(states::combo_melee::Data {
stage: 1,
static_data: states::combo_melee::StaticData {
num_stages: 1,
combo: 0,
stage_data: vec![states::combo_melee::Stage {
stage: 1,
base_damage: 100,
@ -133,12 +132,15 @@ fn matches_ability_stage() {
initial_energy_gain: 0,
max_energy_gain: 100,
energy_increase: 20,
timer: Duration::default(),
stage_section: states::utils::StageSection::Swing,
next_stage: false,
speed_increase: 0.05,
max_speed_increase: 1.8,
is_interruptible: true,
},
stage: 1,
combo: 0,
timer: Duration::default(),
stage_section: states::utils::StageSection::Swing,
next_stage: false,
}),
&PreviousEntityState {
event: SfxEvent::Idle,
@ -172,9 +174,8 @@ fn ignores_different_ability_stage() {
let result = CombatEventMapper::map_event(
&CharacterState::ComboMelee(states::combo_melee::Data {
stage: 1,
static_data: states::combo_melee::StaticData {
num_stages: 1,
combo: 0,
stage_data: vec![states::combo_melee::Stage {
stage: 1,
base_damage: 100,
@ -191,12 +192,15 @@ fn ignores_different_ability_stage() {
initial_energy_gain: 0,
max_energy_gain: 100,
energy_increase: 20,
timer: Duration::default(),
stage_section: states::utils::StageSection::Swing,
next_stage: false,
speed_increase: 0.05,
max_speed_increase: 1.8,
is_interruptible: true,
},
stage: 1,
combo: 0,
timer: Duration::default(),
stage_section: states::utils::StageSection::Swing,
next_stage: false,
}),
&PreviousEntityState {
event: SfxEvent::Idle,

View File

@ -267,7 +267,7 @@ image_ids! {
fire_spell_1: "voxygen.element.icons.fire_spell_0",
snake_arrow_0: "voxygen.element.icons.snake",
heal_0: "voxygen.element.icons.heal_0",
sowrd_whirlwind: "voxygen.element.icons.sword_whirlwind",
sword_whirlwind: "voxygen.element.icons.sword_whirlwind",
// Buttons
button: "voxygen.element.buttons.button",

View File

@ -145,7 +145,7 @@ impl<'a> SlotKey<HotbarSource<'a>, HotbarImageSource<'a>> for HotbarSlot {
HotbarImage::Item(key) => item_imgs.img_id_or_not_found_img(key.clone()),
HotbarImage::SnakeArrow => imgs.snake_arrow_0,
HotbarImage::Fireball => imgs.fire_spell_1,
HotbarImage::SwordWhirlwind => imgs.sowrd_whirlwind,
HotbarImage::SwordWhirlwind => imgs.sword_whirlwind,
}
}
}

View File

@ -978,19 +978,19 @@ impl FigureMgr {
let stage_progress = match s.stage_section {
StageSection::Buildup => {
stage_time
/ s.stage_data[stage_index]
/ s.static_data.stage_data[stage_index]
.base_buildup_duration
.as_secs_f64()
},
StageSection::Swing => {
stage_time
/ s.stage_data[stage_index]
/ s.static_data.stage_data[stage_index]
.base_swing_duration
.as_secs_f64()
},
StageSection::Recover => {
stage_time
/ s.stage_data[stage_index]
/ s.static_data.stage_data[stage_index]
.base_recover_duration
.as_secs_f64()
},