public void KickOff(bool left) { while (PlayersNotSpec() < 2 && !started) { System.Threading.Thread.Sleep(1000); } System.Threading.Thread.Sleep(1000); if (!started) { _timeEllapsed = 0; Team.CurrentTeams.Clear(); Team team1 = Team.GetRandomTeam(); Team team2 = Team.GetRandomTeam(); while (team1.Name == team2.Name) { team2 = Team.GetRandomTeam(); } Team.CurrentTeams[0] = team1; Team.CurrentTeams[1] = team2; Team.JoinAll(); Team.CurrentTeams[0].PickCaptain(); Team.CurrentTeams[1].PickCaptain(); foreach (Player pl in Player.players) { HUD.UpdateAll(pl); } // Chat.MessageAll("Kick off is in 45 seconds. Use this time to talk with your team"); // System.Threading.Thread.Sleep(45000); _timeEllapsed = 0; started = true; MatchTimer.Start(); EndTime = DateTime.Now.AddMilliseconds(900000); _teamLeft = Team.CurrentTeams[0]; _teamRight = Team.CurrentTeams[1]; } Team.SpawnAll(); Core.Ball.PickedUp = null; Team.CurrentTeams[0].SecondLastTouch = null; Team.CurrentTeams[1].SecondLastTouch = null; Server.s.Log("Ball spawning"); Core.Ball.SpawnAt(new Vector2d(Constants.CenterPoint.X + 16, Constants.CenterPoint.Y + 16)); Server.s.Log("Ball spawned"); _state = MatchState.KickOff; _teamInPossession = left ? _teamLeft : _teamRight; Chat.MessageAll("Kicking off. " + _teamInPossession.Color + _teamInPossession.Name + Server.DefaultColor + " is starting"); Barriers.HandleKickOff(); }
static void OnMovement(Player player, Position pos, byte yaw, byte pitch) { if ((bool)player.ExtraData["Spec"]) { return; } if (Core.Match.State != MatchState.InGame) { Task.Run(() => Barriers.HandleMovement(player, (ushort)pos.X, (ushort)pos.Y, (ushort)pos.Z)); } else { Task.Run(() => CheckInBox(player, (ushort)pos.X, (ushort)pos.Y, (ushort)pos.Z)); Task.Run(() => Dribble(player, (ushort)pos.X, (ushort)pos.Y, (ushort)pos.Z, yaw, pitch)); } }
public void End(bool forced = true) { if (!forced) { OnEnd(); } Team.Clear(); started = false; Core.Match.State = MatchState.KickOff; MatchTimer.Stop(); Chat.MessageAll("Restarting game"); Core.Ball.PickedUp = null; Core.Ball.SpawnAt(Constants.CenterPoint); Barriers.OnSetPieceTake(); Task.Run(() => KickOff(true)); }
public static bool Foul(Player player, ushort x, ushort y, ushort z) { if (DistanceFromClosestOpposition(player, x, y, z) <= 48) { var team = Team.FindPlayer(player); Team opposition = Core.Match.OppositeTeam(team); bool insideBox = false; if (opposition == Core.Match.TeamRight) { if (player.pos[0] <= Constants.BoxLeft && player.pos[2] <= Constants.BoxBottom && player.pos[2] >= Constants.BoxTop) { insideBox = true; } } if (opposition == Core.Match.TeamLeft) { if (player.pos[0] >= Constants.BoxRight && player.pos[2] <= Constants.BoxBottom && player.pos[2] >= Constants.BoxTop) { insideBox = true; } } Core.Match.TeamInPossession = opposition; if (insideBox) { if (opposition.Name == Core.Match.TeamRight.Name) { Core.Match.DeadBallLocation = Constants.PenaltyLeft; Chat.MessageAll("Penalty for Team " + opposition.Color + opposition.Name + "(" + player.ColoredName + Server.DefaultColor + ")"); } if (opposition.Name == Core.Match.TeamLeft.Name) { Core.Match.DeadBallLocation = Constants.PenaltyRight; Chat.MessageAll("Penalty for Team " + opposition.Color + opposition.Name + "(" + player.ColoredName + Server.DefaultColor + ")"); } Barriers.HandlePenalty(); Core.Match.State = MatchState.Penalty; } else { if (!PlayAdvantage(player, team, x, y, z)) { Core.Match.DeadBallLocation = new Vector2d(player.pos[0], player.pos[2]); Chat.MessageAll("Free Kick for Team " + opposition.Color + opposition.Name + Server.DefaultColor + " (" + player.ColoredName + Server.DefaultColor + ")"); Barriers.HandleFreekick(); Core.Match.State = MatchState.FreeKick; } else { Chat.MessageAll("Advantage played for " + opposition.Color + opposition.Name + Server.DefaultColor + " (" + player.ColoredName + Server.DefaultColor + ")"); player.ExtraData.ChangeOrCreate("Fouls", (int)player.ExtraData["Fouls"] + 1); return(false); } } player.ExtraData.ChangeOrCreate("Fouls", (int)player.ExtraData["Fouls"] + 1); Core.Ball.SpawnAt(Core.Match.DeadBallLocation); team.Goalie.ExtraData.ChangeOrCreate("Teleported", false); if (opposition.Name == Core.Match.TeamLeft.Name) { PlayerActions.MoveCoords(team.Goalie, (int)(Constants.GoalLineRight / 32), 1, (int)((Constants.BoxTop + Constants.BoxBottom) / 64), team.Goalie.rot[0], team.Goalie.rot[1]); } if (opposition.Name == Core.Match.TeamRight.Name) { PlayerActions.MoveCoords(team.Goalie, (int)(Constants.GoalLineLeft / 32), 1, (int)((Constants.BoxTop + Constants.BoxBottom) / 64), team.Goalie.rot[0], team.Goalie.rot[1]); } Server.Background.QueueOnce(OnFoul); Thread.Sleep(500); team.Goalie.ExtraData.ChangeOrCreate("Teleported", true); return(true); } return(false); }
private void UpdateStateOfPlay() { #region in play if (!started) { return; } if (_state == MatchState.InGame) { // assuming the ball was in play last time we checked. BallState ballState = DetermineBallState(Core.Ball.Position3d); switch (ballState) { case BallState.InBounds: break; case BallState.NetLeft: Core.Ball.PickedUp = null; _state = MatchState.KickOff; Core.Ball.SpawnAt(Constants.CenterPoint); _teamInPossession = _teamLeft; TeamRight.Goals++; if (Core.Ball.LastTouch == TeamLeft) { Chat.MessageAll("Magnificent OWN goal by Team " + TeamLeft.Color + TeamLeft.Name + " " + Server.DefaultColor + "(" + Core.Ball.LastTouchPlayer.ColoredName + Server.DefaultColor + ")"); Core.Ball.LastTouchPlayer.ExtraData.ChangeOrCreate("OwnGoals", (int)Core.Ball.LastTouchPlayer.ExtraData["OwnGoals"] + 1); } else { Chat.MessageAll("Magnificent goal by Team " + TeamRight.Color + TeamRight.Name + " " + Server.DefaultColor + "(" + Core.Ball.LastTouchPlayer.ColoredName + Server.DefaultColor + ")"); try { if (TeamRight.SecondLastTouch != null) { Chat.MessageAll("Awesome assist by " + TeamRight.SecondLastTouch.ColoredName); TeamRight.SecondLastTouch.ExtraData.ChangeOrCreate("Assists", (int)TeamRight.SecondLastTouch.ExtraData["Assists"] + 1); } } catch { } Core.Ball.LastTouchPlayer.ExtraData.ChangeOrCreate("Goals", (int)Core.Ball.LastTouchPlayer.ExtraData["Goals"] + 1); } foreach (Player p in Player.players) { HUD.UpdateAll(p); } Task.Run(() => KickOff(true)); break; case BallState.NetRight: Core.Ball.PickedUp = null; _state = MatchState.KickOff; Core.Ball.SpawnAt(Constants.CenterPoint); _teamInPossession = _teamRight; TeamLeft.Goals++; if (Core.Ball.LastTouch == TeamRight) { Player.GlobalMessage("Magnificent OWN goal by Team " + TeamRight.Color + TeamRight.Name + " " + Server.DefaultColor + "(" + Core.Ball.LastTouchPlayer.ColoredName + Server.DefaultColor + ")"); Core.Ball.LastTouchPlayer.ExtraData.ChangeOrCreate("OwnGoals", (int)Core.Ball.LastTouchPlayer.ExtraData["OwnGoals"] + 1); } else { Player.GlobalMessage("Magnificent goal by Team " + TeamLeft.Color + TeamLeft.Name + " " + Server.DefaultColor + "(" + Core.Ball.LastTouchPlayer.ColoredName + Server.DefaultColor + ")"); Core.Ball.LastTouchPlayer.ExtraData.ChangeOrCreate("Goals", (int)Core.Ball.LastTouchPlayer.ExtraData["Goals"] + 1); try { if (TeamLeft.SecondLastTouch != null) { Chat.MessageAll("Awesome assist by " + TeamRight.SecondLastTouch.ColoredName); TeamLeft.SecondLastTouch.ExtraData.ChangeOrCreate("Assists", (int)TeamLeft.SecondLastTouch.ExtraData["Assists"] + 1); } } catch { } } foreach (Player p in Player.players) { HUD.UpdateAll(p); } Task.Run(() => KickOff(false)); break; case BallState.OutLeftTop: if (Core.Ball.LastTouch == _teamLeft) { _state = MatchState.Corner; _deadBallLocation = Constants.CornerPoint[0]; Core.Ball.SpawnAt(_deadBallLocation); _teamInPossession = _teamRight; Chat.MessageAll("Corner for Team " + _teamInPossession.Color + _teamInPossession.Name); Barriers.HandleCorner(); } else { _state = MatchState.GoalKick; _deadBallLocation = Constants.GoalKickPoint[0]; Core.Ball.SpawnAt(_deadBallLocation); _teamInPossession = _teamLeft; Chat.MessageAll("Goalkick for Team " + _teamInPossession.Color + _teamInPossession.Name); } break; case BallState.OutLeftBottom: if (Core.Ball.LastTouch == _teamLeft) { _state = MatchState.Corner; _deadBallLocation = Constants.CornerPoint[1]; Core.Ball.SpawnAt(_deadBallLocation); _teamInPossession = _teamRight; Chat.MessageAll("Corner for Team " + _teamInPossession.Color + _teamInPossession.Name); Barriers.HandleCorner(); } else { _state = MatchState.GoalKick; _deadBallLocation = Constants.GoalKickPoint[0]; Core.Ball.SpawnAt(_deadBallLocation); _teamInPossession = _teamLeft; Chat.MessageAll("Goalkick for Team " + _teamInPossession.Color + _teamInPossession.Name); } break; case BallState.OutRightTop: if (Core.Ball.LastTouch == _teamRight) { _state = MatchState.Corner; _deadBallLocation = Constants.CornerPoint[2]; Core.Ball.SpawnAt(_deadBallLocation); _teamInPossession = _teamLeft; Chat.MessageAll("Corner for Team " + _teamInPossession.Color + _teamInPossession.Name); Barriers.HandleCorner(); } else { _state = MatchState.GoalKick; _deadBallLocation = Constants.GoalKickPoint[1]; Core.Ball.SpawnAt(_deadBallLocation); _teamInPossession = _teamRight; Chat.MessageAll("Goalkick for Team " + _teamInPossession.Color + _teamInPossession.Name); } break; case BallState.OutRightBottom: if (Core.Ball.LastTouch == _teamRight) { _state = MatchState.Corner; _deadBallLocation = Constants.CornerPoint[3]; Core.Ball.SpawnAt(_deadBallLocation); _teamInPossession = _teamLeft; Chat.MessageAll("Corner for Team " + _teamInPossession.Color + _teamInPossession.Name); Barriers.HandleCorner(); } else { _state = MatchState.GoalKick; _deadBallLocation = Constants.GoalKickPoint[1]; Core.Ball.SpawnAt(_deadBallLocation); _teamInPossession = _teamRight; Chat.MessageAll("Goalkick for Team " + _teamInPossession.Color + _teamInPossession.Name); } break; case BallState.ThrowTop: _state = MatchState.ThrowIn; _deadBallLocation = new Vector2d(Core.Ball.Position3d.X, Constants.TouchLineTop); Core.Ball.SpawnAt(_deadBallLocation); if (Core.Ball.LastTouch == _teamLeft) { _teamInPossession = _teamRight; } else { _teamInPossession = _teamLeft; } Chat.MessageAll("Throw In for Team " + _teamInPossession.Color + _teamInPossession.Name); Barriers.HandleThrowIn(); break; case BallState.ThrowBottom: _state = MatchState.ThrowIn; _deadBallLocation = new Vector2d(Core.Ball.Position3d.X, Constants.TouchLineBottom); Core.Ball.SpawnAt(_deadBallLocation); if (Core.Ball.LastTouch == _teamLeft) { _teamInPossession = _teamRight; } else { _teamInPossession = _teamLeft; } Chat.MessageAll("Throw In for Team " + _teamInPossession.Color + _teamInPossession.Name); Barriers.HandleThrowIn(); break; } } #endregion else if (_teamInPossession.TakenSetPiece) { Barriers.OnSetPieceTake(); Chat.MessageAll("Set piece taken by Team " + _teamInPossession.Color + _teamInPossession.Name); _teamInPossession.TakenSetPiece = false; _state = MatchState.InGame; } }