public void InitFootball() { Stats.CheckTableExists(); SkillHandler.Init(); PlayerHandlers.InitHandlers(); BotInstruction.Instructions.Add(new RefereeInstruction()); BotInstruction.Instructions.Add(new BallInstruction()); Server.s.Log("Added player handlers"); Commands.CommandHandler.AddAll(); Server.s.Log("Added commands"); Ball = new Ball(); Match = new Match(Ball); footballTimer.Interval = ServerConfig.PositionUpdateInterval; footballTimer.Elapsed += delegate { Scheduler.Update(); foreach (Player p in Player.players) { HUD.UpdateAll(p); } }; footballTimer.Start(); Core.Match.MatchTimer.Elapsed += new ElapsedEventHandler(Match.UnforcedEnd); Task.Run(() => Match.KickOff(true)); Server.s.Log("Football started"); }
private static void Dribble(Player player, ushort x, ushort y, ushort z, byte yaw, byte pitch) { if (DateTime.Now > (DateTime)player.ExtraData["SkillTime"] && (string)player.ExtraData["SkillSequence"] != "") { SkillHandler.Execute(player, (string)player.ExtraData["SkillSequence"]); return; } if (Core.Match.State == MatchState.Penalty || (bool)player.ExtraData["IsSkilling"]) { return; } if (DistanceFromBall(x, y, z) <= Constants.FirstTouchRadius && (Core.Match.State == MatchState.InGame || Core.Match.State == MatchState.KickOff) && Core.Ball.PickedUp == null) { if (Core.Ball.LastTouch == Team.FindPlayer(player) && Core.Ball.LastTouchPlayer != player) { FirstTouch(player, yaw); player.ExtraData.ChangeOrCreate("InControl", 2); /* Interferes in kicking * Server.Ball._velocity.X = 0; * Server.Ball._velocity.Y = 0; * Server.Ball._velocity.Z = 0; */ } Core.Ball.InControl = player; if ((int)player.ExtraData["InControl"] < 2) { FirstTouch(player, yaw); } else if (Core.Match.CanTouch(player) && ((Core.Match.State == MatchState.InGame) || !Core.Match.started)) { var team = Team.FindPlayer(player); if (Core.Ball.LastTouchPlayer != player) { Core.Ball.SecondLastTouchPlayer = Core.Ball.LastTouchPlayer; if (Team.FindPlayer(Core.Ball.SecondLastTouchPlayer) == team) { team.SecondLastTouch = Core.Ball.SecondLastTouchPlayer; } } Core.Ball.LastTouch = team; Core.Ball.LastTouchPlayer = player; double distance = 48; double a = Math.Sin(((double)(128 - yaw) / 256) * 2 * Math.PI); double b = Math.Cos(((double)(128 - yaw) / 256) * 2 * Math.PI); double c = Math.Cos(((double)(pitch + 64) / 256) * 2 * Math.PI); double d = Math.Cos(((double)(pitch) / 256) * 2 * Math.PI); ushort X = (ushort)Math.Round(x + (double)(a * distance)); ushort Z = (ushort)Math.Round(z + (double)(b * distance)); Core.Ball._position3d.X = X; Core.Ball._position3d.Y = Z; if (Core.Ball.Velocity == ZeroVelocity) { player.ExtraData["Speed"] = Constants.DefaultSpeed - 0.5f; } } } else { if ((int)player.ExtraData["InControl"] >= 2 && Core.Ball.InControl != player) { player.ExtraData.ChangeOrCreate("Speed", 2.0f); player.ExtraData.ChangeOrCreate("InControl", 0); player.SendMessage("You lost control of the ball"); } } if ((float)player.ExtraData["OldSpeed"] != (float)player.ExtraData["Speed"]) { SetSpeed(player); player.ExtraData.ChangeOrCreate("OldSpeed", player.ExtraData["Speed"]); } }