1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-03-16 11:26:11 +00:00

Separate Tech Rolls (#126)

* Add Wrapper for rand

* Separate Tech Rolls
This commit is contained in:
sidschingis 2020-08-11 21:57:40 +02:00 committed by GitHub
parent 48391ac27c
commit 96008c6ea3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 46 deletions

View file

@ -108,7 +108,8 @@ option after getting up.
// clang-format off
#define ENUM_CLASS_TechFlag(type,x) \
x(type,Miss,"Miss Tech") \
x(type,Roll,"Roll") \
x(type,RollF,"RollF") \
x(type,RollB,"RollB") \
x(type,InPlace,"In Place")
// clang-format on

View file

@ -1,9 +1,6 @@
use crate::common::get_random_int;
use core::f64::consts::PI;
use smash::lib::lua_const::*;
use smash::hash40;
use smash::app;
/// Hitbox Visualization
#[repr(i32)]
@ -134,7 +131,7 @@ macro_rules! to_vec_impl {
// Ledge Option
bitflags! {
pub struct LedgeOption : u32
pub struct LedgeOption : u32
{
const NEUTRAL = 0b1;
const ROLL = 0b10;
@ -143,8 +140,8 @@ bitflags! {
}
}
pub unsafe fn random_option<T>(arg : &Vec<T>) -> &T {
return &arg[app::sv_math::rand(hash40("fighter"), arg.len() as i32) as usize];
pub unsafe fn random_option<T>(arg: &Vec<T>) -> &T {
return &arg[get_random_int(arg.len() as i32) as usize];
}
impl LedgeOption {
@ -157,20 +154,21 @@ impl LedgeOption {
_ => return None,
})
}
to_vec_impl!{LedgeOption}
to_vec_impl! {LedgeOption}
}
// Tech options
bitflags! {
pub struct TechFlags : u32 {
const NO_TECH = 0b1;
const ROLL = 0b10;
const IN_PLACE = 0b100;
const NO_TECH = 0x1;
const ROLL_F = 0x2;
const ROLL_B = 0x4;
const IN_PLACE = 0x8;
}
}
impl TechFlags {
to_vec_impl!{TechFlags}
to_vec_impl! {TechFlags}
}
/// Mash States

View file

@ -2,6 +2,7 @@ pub mod consts;
use crate::common::consts::*;
use smash::app::{self, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;
pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpackMenu {
@ -117,3 +118,7 @@ pub unsafe fn is_in_shieldstun(module_accessor: &mut app::BattleObjectModuleAcce
|| (prev_status == FIGHTER_STATUS_KIND_GUARD_DAMAGE
&& status_kind == FIGHTER_STATUS_KIND_GUARD_OFF)
}
pub fn get_random_int(max: i32) -> i32 {
unsafe { app::sv_math::rand(hash40("fighter"), max) }
}

View file

@ -1,8 +1,7 @@
use crate::common::consts::*;
use crate::common::*;
use core::f64::consts::PI;
use smash::app::{self, lua_bind::*, sv_system};
use smash::hash40;
use smash::app::{lua_bind::*, sv_system};
use smash::lib::lua_const::*;
use smash::lib::L2CValue;
use smash::lua2cpp::L2CFighterCommon;
@ -71,7 +70,7 @@ unsafe fn get_angle(direction: Direction) -> f64 {
unsafe fn get_random_direction() -> Direction {
// Choose Left/Right/None
let rand = app::sv_math::rand(hash40("fighter"), 3);
let rand = get_random_int(3);
if rand == 0 {
Direction::Left
} else if rand == 1 {

View file

@ -2,7 +2,6 @@ use crate::common::consts::*;
use crate::common::*;
use crate::training::mash;
use smash::app::{self, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;
pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor) {
@ -17,10 +16,7 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor
return;
}
let random_frame = app::sv_math::rand(
hash40("fighter"),
MotionModule::end_frame(module_accessor) as i32,
) as f32;
let random_frame = get_random_int(MotionModule::end_frame(module_accessor) as i32) as f32;
let frame = MotionModule::frame(module_accessor) as f32;
if !(frame == random_frame || frame > 30.0) {
@ -32,9 +28,15 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor
let ledge_options = MENU.ledge_state.to_vec();
match ledge_options.len() {
0 => { ledge_case = LedgeOption::empty(); },
1 => { ledge_case = ledge_options[0]; },
_ => { ledge_case = *random_option(&ledge_options); }
0 => {
ledge_case = LedgeOption::empty();
}
1 => {
ledge_case = ledge_options[0];
}
_ => {
ledge_case = *random_option(&ledge_options);
}
}
if let Some(new_status) = ledge_case.into_status() {

View file

@ -3,7 +3,6 @@ use crate::common::*;
use core::f64::consts::PI;
use smash::app::{self, lua_bind::*};
use smash::lib::lua_const::*;
use smash::hash40;
static mut STICK_DIRECTION: Direction = Direction::None;
@ -54,11 +53,10 @@ unsafe fn get_angle(module_accessor: &mut app::BattleObjectModuleAccessor) -> f6
// TODO: if left_stick is used for something other than
// directional airdodge, this may not make sense.
let launch_speed_x = KineticEnergy::get_speed_x(
KineticModule::get_energy(
module_accessor,
*FIGHTER_KINETIC_ENERGY_ID_DAMAGE
) as *mut smash::app::KineticEnergy);
let launch_speed_x = KineticEnergy::get_speed_x(KineticModule::get_energy(
module_accessor,
*FIGHTER_KINETIC_ENERGY_ID_DAMAGE,
) as *mut smash::app::KineticEnergy);
// If we're launched left, reverse stick X
if launch_speed_x < 0.0 {
@ -90,6 +88,6 @@ unsafe fn pick_angle(direction: Direction) -> f64 {
}
unsafe fn get_random_direction() -> Direction {
let rand = app::sv_math::rand(hash40("fighter"), 8);
let rand = get_random_int(8);
Direction::from(rand)
}

View file

@ -4,7 +4,6 @@ use crate::training::character_specific;
use crate::training::fast_fall;
use crate::training::shield;
use smash::app::{self, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;
static mut CURRENT_AERIAL: Action = Action::Nair;
@ -148,7 +147,7 @@ fn should_reset(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool {
}
fn should_buffer(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool {
unsafe{
unsafe {
if MENU.mash_in_neutral == OnOff::On {
return true;
}
@ -207,8 +206,7 @@ fn get_random_action(module_accessor: &mut app::BattleObjectModuleAccessor) -> A
random_cmds.push(Mash::Spotdodge);
}
let random_cmd_index =
app::sv_math::rand(hash40("fighter"), random_cmds.len() as i32) as usize;
let random_cmd_index = get_random_int(random_cmds.len() as i32) as usize;
mash_to_action(random_cmds[random_cmd_index])
}
@ -519,13 +517,12 @@ pub unsafe fn perform_defensive_option() {
Mash::Attack,
];
let random_cmd_index =
app::sv_math::rand(hash40("fighter"), random_cmds.len() as i32) as usize;
let random_cmd_index = get_random_int(random_cmds.len() as i32) as usize;
action = mash_to_action(random_cmds[random_cmd_index]);
}
Defensive::Roll => {
if app::sv_math::rand(hash40("fighter"), 2) == 0 {
if get_random_int(2) == 0 {
action = Action::RollForward;
} else {
action = Action::RollBack;

View file

@ -8,6 +8,8 @@ use smash::lib::lua_const::*;
use smash::lib::L2CValue;
use smash::lua2cpp::L2CFighterBase;
static mut ROLL_DIRECTION: Direction = Direction::None;
#[skyline::hook(replace = smash::lua2cpp::L2CFighterBase_change_status)]
pub unsafe fn handle_change_status(
fighter: &mut L2CFighterBase,
@ -44,10 +46,14 @@ unsafe fn mod_handle_change_status(
|| status_kind_int == FIGHTER_STATUS_KIND_DAMAGE_FLY_REFLECT_D
{
let states = MENU.tech_state.to_vec();
let mut state = if states.is_empty() { TechFlags::empty() } else { states[0] };
let mut state = if states.is_empty() {
TechFlags::empty()
} else {
states[0]
};
if states.len() > 1 {
let idx = app::sv_math::rand(hash40("fighter"), states.len() as i32) as usize;
let idx = get_random_int(states.len() as i32) as usize;
state = states[idx];
}
@ -56,9 +62,15 @@ unsafe fn mod_handle_change_status(
*status_kind = FIGHTER_STATUS_KIND_PASSIVE.as_lua_int();
*unk = LUA_TRUE;
}
TechFlags::ROLL => {
TechFlags::ROLL_F => {
*status_kind = FIGHTER_STATUS_KIND_PASSIVE_FB.as_lua_int();
*unk = LUA_TRUE;
ROLL_DIRECTION = Direction::Left; // = In
}
TechFlags::ROLL_B => {
*status_kind = FIGHTER_STATUS_KIND_PASSIVE_FB.as_lua_int();
*unk = LUA_TRUE;
ROLL_DIRECTION = Direction::Right; // = Away
}
_ => (),
}
@ -117,8 +129,7 @@ pub unsafe fn get_command_flag_cat(
*FIGHTER_STATUS_KIND_DOWN_STAND_ATTACK, // Getup Attack
];
let random_status_index =
app::sv_math::rand(hash40("fighter"), random_statuses.len() as i32) as usize;
let random_status_index = get_random_int(random_statuses.len() as i32) as usize;
StatusModule::change_status_request_from_script(
module_accessor,
random_statuses[random_status_index],
@ -140,14 +151,14 @@ pub unsafe fn change_motion(
return None;
}
if MENU.tech_state == TechFlags::empty() || MENU.tech_state == TechFlags::NO_TECH {
if MENU.tech_state == TechFlags::empty() {
return None;
}
let random_roll = app::sv_math::rand(hash40("fighter"), 2);
let random_roll = get_random_int(2);
if [hash40("passive_stand_f"), hash40("passive_stand_b")].contains(&motion_kind) {
if random_roll != 0 {
if ROLL_DIRECTION == Direction::Left {
return Some(hash40("passive_stand_f"));
} else {
return Some(hash40("passive_stand_b"));