public MatchState ResetState(MatchState state) { for (uint i = 0; i < state.PlayerCount; i++) { state.SetPlayerState(i, PlayerSimulations[i].ResetState(state.GetPlayerState(i))); } return(state); }
void SetDefaultDamages(MatchConfig config, MatchState initialState) { for (int i = 0; i < initialState.PlayerCount; i++) { var state = initialState.GetPlayerState(i); state.Damage = config.PlayerConfigs[i].DefaultDamage; initialState.SetPlayerState(i, state); } }
public MatchState ResetState(MatchState state) { for (var i = 0; i < state.PlayerCount; i++) { // TODO(james7132): Replace this with ref return/locals var playerState = state.GetPlayerState(i); PlayerSimulations[i].ResetState(ref playerState); state.SetPlayerState(i, playerState); } return(state); }
MatchState CreateInitialStateSimple(MatchConfig config) { var initialState = new MatchState(config); for (var i = 0; i < initialState.PlayerCount; i++) { var state = initialState.GetPlayerState(i); state.Position = new Vector3((int)i * 2 - 3, 1, 0); initialState.SetPlayerState(i, state); } return(initialState); }
MatchState CreateInitialStateByTransform(MatchConfig config, GameObject[] startPositions) { var initialState = new MatchState(config); startPositions = startPositions.OrderBy(s => s.transform.GetSiblingIndex()).ToArray(); for (int i = 0; i < initialState.PlayerCount; i++) { var startPos = startPositions[i % startPositions.Length].transform; var state = initialState.GetPlayerState(i); state.Position = startPos.position; state.Direction = startPos.transform.forward.x >= 0; initialState.SetPlayerState(i, state); } return(initialState); }
public void Simulate(ref MatchState state, MatchInputContext input) { if (ActiveHitboxes.Count + ActiveHurtboxes.Count > 0) { Physics.SyncTransforms(); CreateCollisions(); for (var i = 0; i < Config.PlayerCount; i++) { var playerState = state.GetPlayerState(i); var collisions = CollisionManager.PlayerCollisions[i]; ApplyCollisions(collisions, ref playerState, state); state.SetPlayerState(i, playerState); } } CollisionManager.Clear(); ActiveHitboxes.Clear(); ActiveHurtboxes.Clear(); }
public void Simulate(ref MatchState state, MatchInputContext input) { Assert.IsTrue(input.IsValid); Assert.AreEqual(PlayerSimulations.Length, state.PlayerCount); Assert.AreEqual(PlayerSimulations.Length, input.PlayerInputs.Length); for (var i = 0; i < state.PlayerCount; i++) { PlayerSimulations[i].Presimulate(state.GetPlayerState(i)); } for (var i = 0; i < state.PlayerCount; i++) { var playerState = state.GetPlayerState(i); var simulation = PlayerSimulations[i]; var playerInput = input.PlayerInputs[i]; simulation.Simulate(ref playerState, playerInput); state.SetPlayerState(i, playerState); } }
// TODO(james7132): Split and generalize this... somehow. public void ApplyCollisions(List <HitboxCollision> collisions, ref PlayerState state, MatchState match) { if (collisions.Count <= 0 || IsPlayerInvincible(state)) { return; } bool isShielded = false; bool isHit = false; foreach (var collision in collisions) { var source = collision.Source; int srcPlayerId = (int)collision.Source.PlayerID; int dstPlayerId = (int)collision.Destination.PlayerID; switch (collision.Destination.Type) { case HurtboxType.Damageable: var sourceState = match.GetPlayerState((int)source.PlayerID); // Check if hit is valid. if (isShielded || isHit || sourceState.HasHit(dstPlayerId)) { continue; } // Deal damage, knockback, and hitstun to the target var hitDamage = source.BaseDamage; var hitKnockback = source.GetKnocback(state.Damage, sourceState.Direction); state.Damage += hitDamage; state.Velocity = hitKnockback; state.Hitstun = source.GetHitstun(state.Damage); // Apply hitlag state.Hitlag = source.Hitlag; sourceState.Hitlag = source.Hitlag; // Mark the source as having hit the destination. sourceState.HitPlayer(dstPlayerId); match.SetPlayerState(srcPlayerId, sourceState); collision.PlayEffect(new HitInfo { Source = collision.Source, Destination = collision.Destination, MatchState = match, }); isHit = true; break; case HurtboxType.Shield: isShielded = true; state.ShieldDamage += (uint)(source.BaseDamage * 100); break; case HurtboxType.Invincible: collision.PlayEffect(new HitInfo { Source = collision.Source, Destination = collision.Destination, MatchState = match, }); break; } } }