public override void OnDirectInput(SnapshotPlayerInput newInput) { LatestPrevInput.Fill(LatestInput); LatestInput.Fill(newInput); if (LatestInput.TargetX == 0 && LatestInput.TargetY == 0) { LatestInput.TargetY = -1; } if (NumInputs > 2 && Player.Team != Team.Spectators) { HandleWeaponSwitch(); FireWeapon(); } LatestPrevInput.Fill(LatestInput); }
public abstract void OnPredictedInput(SnapshotPlayerInput newInput);
public abstract void OnDirectInput(SnapshotPlayerInput newInput);
public abstract void Tick(SnapshotPlayerInput input);
public override void OnDirectInput(SnapshotPlayerInput input) { if (GameContext.World.Paused) { PlayerFlags = input.PlayerFlags; return; } if (input.PlayerFlags.HasFlag(PlayerFlags.Chatting)) { if (PlayerFlags.HasFlag(PlayerFlags.Chatting)) { return; } Character?.ResetInput(); PlayerFlags = input.PlayerFlags; return; } PlayerFlags = input.PlayerFlags; Character?.OnDirectInput(input); if (Character == null && Team != Team.Spectators && (input.Fire & 1) != 0) { Respawn(); } if (Character == null && Team == Team.Spectators && (input.Fire & 1) != 0) { if (!ActiveSpectatorSwitch) { ActiveSpectatorSwitch = true; if (SpectatorMode == SpectatorMode.FreeView) { var character = BaseCharacter.Entities.Closest(ViewPos, 6 * 32f, null); var flag = Flag.Entities.Closest(ViewPos, 6 * 32f, null); if (character != null || flag != null) { if (character == null || flag != null && character != null && MathHelper.Distance(ViewPos, flag.Position) < MathHelper.Distance(ViewPos, character.Position)) { SpectatorMode = flag.Team == Team.Red ? SpectatorMode.FlagRed : SpectatorMode.FlagBlue; SpectatorFlag = flag; SpectatorId = -1; } else { SpectatorMode = SpectatorMode.Player; SpectatorFlag = null; SpectatorId = character.Player.ClientId; } } } else { SpectatorMode = SpectatorMode.FreeView; SpectatorFlag = null; SpectatorId = -1; } } } else if (ActiveSpectatorSwitch) { ActiveSpectatorSwitch = false; } if (input.Direction != 0 || LatestActivity.TargetX != input.TargetX || LatestActivity.TargetY != input.TargetY || input.IsJump || (input.Fire & 1) != 0 || input.IsHook) { LatestActivity.TargetX = input.TargetX; LatestActivity.TargetY = input.TargetY; LastActionTick = Server.Tick; InactivityTickCounter = 0; } }
public override void Tick(SnapshotPlayerInput input) { TriggeredEvents = CoreEvents.None; var isGrounded = false; if (MapCollision.IsTileSolid(Position.x + TeeSize / 2, Position.y + TeeSize / 2 + 5)) { isGrounded = true; } else if (MapCollision.IsTileSolid(Position.x - TeeSize / 2, Position.y + TeeSize / 2 + 5)) { isGrounded = true; } var vel = Velocity; vel.y += World.Tuning["gravity"]; if (input != null) { Direction = input.Direction; Angle = (int)(MathHelper.Angle(new Vector2(input.TargetX, input.TargetY)) * 256f); if (input.IsJump) { if ((Jumped & 1) == 0) { if (isGrounded) { TriggeredEvents |= CoreEvents.GroundJump; vel.y = -World.Tuning["ground_jump_impulse"]; Jumped |= 1; } else if ((Jumped & 2) == 0) { TriggeredEvents |= CoreEvents.AirJump; vel.y = -World.Tuning["air_jump_impulse"]; Jumped |= 3; } } } else { Jumped &= ~1; } if (input.IsHook) { if (HookState == HookState.Idle) { var targetDirection = new Vector2(input.TargetX, input.TargetY).Normalized; HookState = HookState.Flying; HookPosition = Position + targetDirection * TeeSize * 1.5f; HookDirection = targetDirection; HookedPlayer = -1; HookTick = 0; //TriggeredEvents |= CoreEvents.HookLaunch; } } else { HookedPlayer = -1; HookState = HookState.Idle; HookPosition = Position; } } float maxSpeed = isGrounded ? World.Tuning["ground_control_speed"] : World.Tuning["air_control_speed"]; float accel = isGrounded ? World.Tuning["ground_control_accel"] : World.Tuning["air_control_accel"]; float friction = isGrounded ? World.Tuning["ground_friction"] : World.Tuning["air_friction"]; if (Direction < 0) { vel.x = MathHelper.SaturatedAdd(-maxSpeed, maxSpeed, vel.x, -accel); } else if (Direction > 0) { vel.x = MathHelper.SaturatedAdd(-maxSpeed, maxSpeed, vel.x, +accel); } else { vel.x *= friction; } if (isGrounded) { Jumped &= ~2; } if (HookState == HookState.Idle) { HookedPlayer = -1; HookPosition = Position; } else if (HookState >= HookState.RetractStart && HookState < HookState.RetractEnd) { HookState++; } else if (HookState == HookState.RetractEnd) { HookState = HookState.Retracted; //TriggeredEvents |= CoreEvents.HOOK_RETRACT; } else if (HookState == HookState.Flying) { var newHookPos = HookPosition + HookDirection * World.Tuning["hook_fire_speed"]; if (MathHelper.Distance(Position, newHookPos) > World.Tuning["hook_length"]) { HookState = HookState.RetractStart; newHookPos = Position + (newHookPos - Position).Normalized * World.Tuning["hook_length"]; } var goingToHitGround = false; var goingToRetract = false; var hitFlags = MapCollision.IntersectLine(HookPosition, newHookPos, out newHookPos, out _); if (hitFlags != CollisionFlags.None) { if (hitFlags.HasFlag(CollisionFlags.NoHook)) { goingToRetract = true; } else { goingToHitGround = true; } } if (World.Tuning["player_hooking"] > 0) { var distance = 0f; for (var i = 0; i < World.CharacterCores.Length; i++) { var characterCore = World.CharacterCores[i]; if (characterCore == null || characterCore == this) { continue; } var closestPoint = MathHelper.ClosestPointOnLine(HookPosition, newHookPos, characterCore.Position); if (MathHelper.Distance(characterCore.Position, closestPoint) < TeeSize + 2f) { if (HookedPlayer == -1 || MathHelper.Distance(HookPosition, characterCore.Position) < distance) { TriggeredEvents |= CoreEvents.HookAttachPlayer; HookState = HookState.Grabbed; HookedPlayer = i; distance = MathHelper.Distance(HookPosition, characterCore.Position); break; } } } } if (HookState == HookState.Flying) { if (goingToHitGround) { TriggeredEvents |= CoreEvents.HookAttachGround; HookState = HookState.Grabbed; } else if (goingToRetract) { TriggeredEvents |= CoreEvents.HookHitNoHook; HookState = HookState.RetractStart; } HookPosition = newHookPos; } } if (HookState == HookState.Grabbed) { if (HookedPlayer != -1) { var characterCore = World.CharacterCores[HookedPlayer]; if (characterCore != null) { HookPosition = characterCore.Position; } else { HookedPlayer = -1; HookState = HookState.Retracted; HookPosition = Position; } } if (HookedPlayer == -1 && MathHelper.Distance(HookPosition, Position) > 46.0f) { var hookVel = (HookPosition - Position).Normalized * World.Tuning["hook_drag_accel"]; if (hookVel.y > 0) { hookVel.y *= 0.3f; } if (hookVel.x < 0 && Direction < 0 || hookVel.x > 0 && Direction > 0) { hookVel.x *= 0.95f; } else { hookVel.x *= 0.75f; } var newVel = vel + hookVel; if (newVel.Length < World.Tuning["hook_drag_speed"] || newVel.Length < vel.Length) { vel = newVel; } } HookTick++; // 60 = 1.25s if (HookedPlayer != -1 && (HookTick > 60 || World.CharacterCores[HookedPlayer] == null)) { HookedPlayer = -1; HookState = HookState.Retracted; HookPosition = Position; } } if (World.Tuning["player_collision"] > 0 || World.Tuning["player_hooking"] > 0) { for (var i = 0; i < World.CharacterCores.Length; i++) { var characterCore = World.CharacterCores[i]; if (characterCore == null || characterCore == this) { continue; } var distance = MathHelper.Distance(Position, characterCore.Position); var direction = (Position - characterCore.Position).Normalized; if (World.Tuning["player_collision"] > 0 && distance < TeeSize * 1.25f && distance > 0) { var a = (TeeSize * 1.45f - distance); var velocity = 0.5f; if (vel.Length > 0.0001f) { velocity = 1 - (MathHelper.Dot(vel.Normalized, direction) + 1) / 2; } vel += direction * a * (velocity * 0.75f); vel *= 0.85f; } if (World.Tuning["player_hooking"] > 0 && HookedPlayer == i) { if (distance > TeeSize * 1.50f) { var hookAccelerate = World.Tuning["hook_drag_accel"] * (distance / World.Tuning["hook_length"]); float dragSpeed = World.Tuning["hook_drag_speed"]; characterCore.Velocity = new Vector2( MathHelper.SaturatedAdd(-dragSpeed, dragSpeed, characterCore.Velocity.x, hookAccelerate * direction.x * 1.5f), MathHelper.SaturatedAdd(-dragSpeed, dragSpeed, characterCore.Velocity.y, hookAccelerate * direction.y * 1.5f) ); vel.x = MathHelper.SaturatedAdd(-dragSpeed, dragSpeed, vel.x, -hookAccelerate * direction.x * 0.25f); vel.y = MathHelper.SaturatedAdd(-dragSpeed, dragSpeed, vel.y, -hookAccelerate * direction.y * 0.25f); } } } } if (vel.Length > 6000) { vel = vel.Normalized * 6000; } Velocity = vel; }