timing sync fixes, block timer during animation, remove timeout for POST_ONLY

This commit is contained in:
Mashy 2019-10-08 13:35:39 +10:00
parent 38bd94875d
commit e93b56541f
6 changed files with 49 additions and 26 deletions

View File

@ -86,7 +86,7 @@ function getSequence(resolution) {
case 'EndPost': return ['END_SKILL', 'POST_SKILL']; case 'EndPost': return ['END_SKILL', 'POST_SKILL'];
case 'EndOnly': return ['END_SKILL']; case 'EndOnly': return ['END_SKILL'];
case 'PostOnly': return ['POST_SKILL']; case 'PostOnly': return ['POST_SKILL'];
case 'None': return []; case 'NoStages': return [];
default: return ['START_SKILL', 'END_SKILL', 'POST_SKILL']; default: return ['START_SKILL', 'END_SKILL', 'POST_SKILL'];
} }
} }

View File

@ -10,11 +10,13 @@ const GameCtrlTopButtons = require('./game.ctrl.btns.top');
const addState = connect( const addState = connect(
function receiveState(state) { function receiveState(state) {
const { const {
animating,
game, game,
account, account,
} = state; } = state;
return { return {
animating,
game, game,
account, account,
}; };
@ -23,6 +25,7 @@ const addState = connect(
function Controls(args) { function Controls(args) {
const { const {
animating,
account, account,
game, game,
} = args; } = args;
@ -31,10 +34,10 @@ function Controls(args) {
const opponent = game.players.find(t => t.id !== account.id); const opponent = game.players.find(t => t.id !== account.id);
const player = game.players.find(t => t.id === account.id); const player = game.players.find(t => t.id === account.id);
const zero = Date.parse(game.phase_start); const zero = Date.parse(game.phase_start);
const now = Date.now(); const now = animating ? zero : Date.now();
const end = Date.parse(game.phase_end); const end = Date.parse(game.phase_end);
const timerPct = game.phase_end const timerPct = game.phase_end
? ((now - zero) / (end - zero) * 100) ? ((now - zero) / (end - zero) * 100)
: 100; : 100;

View File

@ -1,10 +1,10 @@
const preact = require('preact'); const preact = require('preact');
const SOURCE_DURATION_MS = 1000; const SOURCE_DURATION_MS = 1000; // Time for SOURCE ONLY
const TARGET_DELAY_MS = 500; const TARGET_DELAY_MS = 500; // Used for Source + Target
const TARGET_DURATION_MS = 1500; const TARGET_DURATION_MS = 1500; // Time for TARGET ONLY
const POST_SKILL_DURATION_MS = 1000; const POST_SKILL_DURATION_MS = 1000; // Time for all POST
const SOURCE_AND_TARGET_TOTAL_DURATION = TARGET_DELAY_MS + TARGET_DURATION_MS; const SOURCE_AND_TARGET_TOTAL_DURATION = TARGET_DELAY_MS + TARGET_DURATION_MS; // SOURCE + TARGET time
module.exports = { module.exports = {
TIMES: { TIMES: {

View File

@ -82,10 +82,14 @@ function registerEvents(store) {
} }
if (sequence.includes('POST_SKILL') && text) { if (sequence.includes('POST_SKILL') && text) {
// timeout to prevent text classes from being added too soon // timeout to prevent text classes from being added too soon
setTimeout( if (timeout === TIMES.POST_SKILL_DURATION_MS) {
() => store.dispatch(actions.setAnimText(text)), store.dispatch(actions.setAnimText(text));
timeout - TIMES.POST_SKILL_DURATION_MS } else {
); setTimeout(
() => store.dispatch(actions.setAnimText(text)),
timeout - TIMES.POST_SKILL_DURATION_MS
);
}
} }
return setTimeout(() => { return setTimeout(() => {
store.dispatch(actions.setAnimSkill(null)); store.dispatch(actions.setAnimSkill(null));

View File

@ -161,14 +161,12 @@ impl Game {
self.skill_phase_start(0) self.skill_phase_start(0)
} }
fn skill_phase_start(mut self, num_resolutions: usize) -> Game { fn skill_phase_start(mut self, resolution_time: i64) -> Game {
let resolution_animation_ms = num_resolutions as i64 * 2500;
self.phase_start = Utc::now() self.phase_start = Utc::now()
.checked_add_signed(Duration::milliseconds(resolution_animation_ms)) .checked_add_signed(Duration::milliseconds(resolution_time))
.expect("could not set phase start"); .expect("could not set phase start");
self.phase_end = self.time_control.game_phase_end(resolution_animation_ms); self.phase_end = self.time_control.game_phase_end(resolution_time);
for player in self.players.iter_mut() { for player in self.players.iter_mut() {
if player.skills_required() == 0 { if player.skills_required() == 0 {
@ -428,13 +426,12 @@ impl Game {
// temp vec of this round's resolving skills // temp vec of this round's resolving skills
// because need to check cooldown use before pushing them into the complete list // because need to check cooldown use before pushing them into the complete list
let mut casts = vec![]; let mut casts = vec![];
let mut turn_events = 0; let mut resolution_delay = 0;
while let Some(cast) = self.stack.pop() { while let Some(cast) = self.stack.pop() {
// info!("{:} casts ", cast); // info!("{:} casts ", cast);
let mut resolutions = resolution_steps(&cast, &mut self); let mut resolutions = resolution_steps(&cast, &mut self);
turn_events += resolutions.len(); resolution_delay = resolutions.iter().fold(resolution_delay, |acc, r| acc + r.clone().get_delay());
self.resolved.append(&mut resolutions); self.resolved.append(&mut resolutions);
// while let Some(resolution) = resolutions.pop() { // while let Some(resolution) = resolutions.pop() {
@ -460,7 +457,7 @@ impl Game {
return self.finish() return self.finish()
} }
self.skill_phase_start(turn_events) self.skill_phase_start(resolution_delay)
} }
fn progress_durations(&mut self, resolved: &Vec<Cast>) -> &mut Game { fn progress_durations(&mut self, resolved: &Vec<Cast>) -> &mut Game {

View File

@ -415,7 +415,7 @@ pub enum EventStages {
EndPost, // Skip Anim Anim EndPost, // Skip Anim Anim
EndOnly, // Skip Anim Skip EndOnly, // Skip Anim Skip
PostOnly, // Skip Skip Anim PostOnly, // Skip Skip Anim
None, // Skip Skip Skip NoStages, // Skip Skip Skip
} }
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)] #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
@ -455,6 +455,25 @@ impl Resolution {
self.stages = s; self.stages = s;
self self
} }
pub fn get_delay(self) -> i64 {
let source_duration = 1000; // Time for SOURCE ONLY
let target_delay = 500; // Used for Source + Target
let target_duration = 1500; // Time for TARGET ONLY
let post_skill = 1000; // Time for all POST
let source_and_target_total = target_delay + target_duration; // SOURCE + TARGET time
match self.stages {
EventStages::AllStages => source_and_target_total + post_skill, // Anim Anim Anim
EventStages::StartEnd => source_and_target_total, // Anim Anim Skip
EventStages::StartPost => source_duration + post_skill, // Anim Skip Anim
EventStages::StartOnly => source_duration, // Anim Skip Skip
EventStages::EndPost => target_duration + post_skill, // Skip Anim Anim
EventStages::EndOnly => target_duration, // Skip Anim Skip
EventStages::PostOnly => post_skill, // Skip Skip Anim
EventStages::NoStages => 0, // Skip Skip Skip
}
}
} }
@ -1363,7 +1382,7 @@ fn sustain(source: &mut Construct, target: &mut Construct, mut results: Resoluti
let stages = match e { let stages = match e {
Event::Recharge { red, blue, skill: _ } => { Event::Recharge { red, blue, skill: _ } => {
if red > 0 || blue > 0 { EventStages::PostOnly } if red > 0 || blue > 0 { EventStages::PostOnly }
else { EventStages::None } else { EventStages::NoStages }
} }
_ => panic!("not recharge") _ => panic!("not recharge")
}; };
@ -1382,7 +1401,7 @@ fn intercept(source: &mut Construct, target: &mut Construct, mut results: Resolu
let stages = match e { let stages = match e {
Event::Recharge { red, blue, skill: _ } => { Event::Recharge { red, blue, skill: _ } => {
if red > 0 || blue > 0 { EventStages::PostOnly } if red > 0 || blue > 0 { EventStages::PostOnly }
else { EventStages::None } else { EventStages::NoStages }
} }
_ => panic!("not recharge") _ => panic!("not recharge")
}; };
@ -1606,7 +1625,7 @@ fn electrocute(source: &mut Construct, target: &mut Construct, mut results: Reso
let electrocute = ConstructEffect::new(effect, duration).set_tick(Cast::new_tick(source, target, tick_skill)); let electrocute = ConstructEffect::new(effect, duration).set_tick(Cast::new_tick(source, target, tick_skill));
results.push(Resolution::new(source, target) results.push(Resolution::new(source, target)
.event(target.add_effect(skill, electrocute)) .event(target.add_effect(skill, electrocute))
.stages(EventStages::EndPost)); .stages(EventStages::PostOnly));
match skip_tick { match skip_tick {
@ -1674,7 +1693,7 @@ fn reflect(source: &mut Construct, target: &mut Construct, mut results: Resoluti
let stages = match e { let stages = match e {
Event::Recharge { red, blue, skill: _ } => { Event::Recharge { red, blue, skill: _ } => {
if red > 0 || blue > 0 { EventStages::PostOnly } if red > 0 || blue > 0 { EventStages::PostOnly }
else { EventStages::None } else { EventStages::NoStages }
} }
_ => panic!("not recharge") _ => panic!("not recharge")
}; };