Football Bug

wow97

New Member
Apr 14, 2019
6
0
Please, help me!


C#:
using Plus.Collections;
using Plus.HabboHotel.GameClients;
using Plus.HabboHotel.Items;
using Plus.HabboHotel.PathFinding;
using Plus.Messages;
using Plus.Messages.Parsers;
using Plus.Util;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;

namespace Plus.HabboHotel.Rooms.Games
{
    internal class Soccer
    {
        private RoomItem[] _gates;
        private Room _room;
        private QueuedDictionary<uint, RoomItem> _balls;

        public Soccer(Room room)
        {
            _room = room;
            _gates = new RoomItem[4];
            _balls = new QueuedDictionary<uint, RoomItem>();
        }

        public static int GetThreadTime(int i)
        {
            switch (i)
            {
                case 1:
                    return 75;

                case 2:
                    return 100;

                case 3:
                    return 125;

                case 4:
                    return 150;

                default:
                    if (i != 5)
                        return ((i != 6) ? 200 : 350);
                    return 200;
            }
        }

        internal void AddBall(RoomItem item)
        {
            _balls.Add(item.Id, item);
        }

        internal void Destroy()
        {
            Array.Clear(_gates, 0, _gates.Length);
            _gates = null;
            _room = null;
            _balls.Destroy();
            _balls = null;
        }

        internal void OnCycle()
        {
            _balls.OnCycle();
        }

        internal void OnGateRemove(RoomItem item)
        {
            switch (item.GetBaseItem().InteractionType)
            {
                case Interaction.FootballGoalGreen:
                case Interaction.FootballCounterGreen:
                    _room.GetGameManager().RemoveFurnitureFromTeam(item, Team.green);
                    return;

                case Interaction.FootballGoalYellow:
                case Interaction.FootballCounterYellow:
                    _room.GetGameManager().RemoveFurnitureFromTeam(item, Team.yellow);
                    return;

                case Interaction.FootballGoalBlue:
                case Interaction.FootballCounterBlue:
                    _room.GetGameManager().RemoveFurnitureFromTeam(item, Team.blue);
                    return;

                case Interaction.FootballGoalRed:
                case Interaction.FootballCounterRed:
                    _room.GetGameManager().RemoveFurnitureFromTeam(item, Team.red);
                    return;

                default:
                    return;
            }
        }

        private IEnumerable<RoomItem> GetFootballItemsForAllTeams()
        {
            var items = _room.GetGameManager().GetItems(Team.red).Values.ToList();
            items.AddRange(_room.GetGameManager().GetItems(Team.green).Values);

            items.AddRange(_room.GetGameManager().GetItems(Team.blue).Values);

            items.AddRange(_room.GetGameManager().GetItems(Team.yellow).Values);

            return items;
        }

        private bool GameItemOverlaps(RoomItem gameItem)
        {
            var gameItemCoord = gameItem.Coordinate;
            return
                GetFootballItemsForAllTeams()
                    .Any(
                        item =>
                            item.AffectedTiles.Values.Any(
                                tile => tile.X == gameItemCoord.X && tile.Y == gameItemCoord.Y));
        }

        internal void OnUserWalk(RoomUser user)
        {
            if (user == null)
                return;

            foreach (RoomItem ball in _balls.Values)
            {
                if (user.SetX == ball.X && user.SetY == ball.Y && user.GoalX == ball.X && user.GoalY == ball.Y && user.HandelingBallStatus == 0) // super chute.
                {
                    var userPoint = new Point(user.X, user.Y);
                    ball.ExtraData = "55";
                    ball.BallIsMoving = true;
                    ball.BallValue = 1;
                    MoveBall(ball, user.GetClient(), userPoint);
                }
                else if (user.X == ball.X && user.Y == ball.Y && user.HandelingBallStatus == 0)
                {
                    var userPoint = new Point(user.SetX, user.SetY);
                    ball.ExtraData = "55";
                    ball.BallIsMoving = true;
                    ball.BallValue = 1;
                    MoveBall(ball, user.GetClient(), userPoint);
                }
                else
                {
                    if (user.HandelingBallStatus == 0 && user.GoalX == ball.X && user.GoalY == ball.Y)
                        return;

                    if (user.SetX != ball.X || user.SetY != ball.Y || !user.IsWalking ||
                        (user.X == user.GoalX && user.Y == user.GoalY))
                        return;
                    user.HandelingBallStatus = 1;
                    var comeDirection = ComeDirection.GetComeDirection(new Point(user.X, user.Y), ball.Coordinate);
                    if (comeDirection == IComeDirection.Null)
                        return;

                    var newX = user.SetX;
                    var newY = user.SetY;

                    if (!ball.GetRoom().GetGameMap().ValidTile2(user.SetX, user.SetY) || !ball.GetRoom().GetGameMap().ItemCanBePlacedHere(user.SetX, user.SetY))
                    {
                        comeDirection = ComeDirection.InverseDirections(_room, comeDirection, user.X, user.Y);
                        newX = ball.X;
                        newY = ball.Y;
                    }

                    ComeDirection.GetNewCoords(comeDirection, ref newX, ref newY);
                    ball.ExtraData = "11";
                    MoveBall(ball, user.GetClient(), newX, newY);
                }
            }
        }

        internal bool MoveBall(RoomItem item, GameClient mover, int newX, int newY)
        {
            if (item == null || item.GetBaseItem() == null /*|| mover == null || mover.GetHabbo() == null*/)
                return false;

            if (!_room.GetGameMap().ItemCanBePlacedHere(newX, newY))
                return false;

            var oldRoomCoord = item.Coordinate;
            var itemIsOnGameItem = GameItemOverlaps(item);
            double newZ = _room.GetGameMap().Model.SqFloorHeight[newX][newY];

            var mMessage = new ServerMessage();
            mMessage.Init(LibraryParser.OutgoingRequest("ItemAnimationMessageComposer")); // Cf
            mMessage.AppendInteger(item.Coordinate.X);
            mMessage.AppendInteger(item.Coordinate.Y);
            mMessage.AppendInteger(newX);
            mMessage.AppendInteger(newY);
            mMessage.AppendInteger(1);
            mMessage.AppendInteger(item.Id);
            mMessage.AppendString(TextHandling.GetString(item.Z));
            mMessage.AppendString(TextHandling.GetString(newZ));
            mMessage.AppendInteger(item.Id);
            _room.SendMessage(mMessage);

            if (oldRoomCoord.X == newX && oldRoomCoord.Y == newY)
                return false;

            item.SetState(newX, newY, item.Z,
                Gamemap.GetAffectedTiles(item.GetBaseItem().Length, item.GetBaseItem().Width, newX, newY, item.Rot));

            if (itemIsOnGameItem || mover == null || mover.GetHabbo() == null)
                return false;
            HandleFootballGameItems(new Point(newX, newY),
                _room.GetRoomUserManager().GetRoomUserByHabbo(mover.GetHabbo().Id));
            return false;
        }

        internal void MoveBall(RoomItem item, GameClient client, Point user)
        {
            try
            {
                item.ComeDirection = ComeDirection.GetComeDirection(user, item.Coordinate);

                if (item.ComeDirection != IComeDirection.Null)
                    // item.ballMover = client;
                    new TaskFactory().StartNew(() => MoveBallProcess(item, client));
            }
            catch
            {
            }
        }

        internal async void MoveBallProcess(RoomItem item, GameClient client)
        {
            var tryes = 0;
            var newX = item.Coordinate.X;
            var newY = item.Coordinate.Y;

            //while (tryes < 3)
            {
                if (_room == null || _room.GetGameMap() == null)
                    return;

                var total = item.ExtraData == "55" ? 6 : 1;
                for (var i = 0; i != total; i++)
                {
                    if (item.ComeDirection == IComeDirection.Null)
                    {
                        item.BallIsMoving = false;
                        break;
                    }

                    var resetX = newX;
                    var resetY = newY;

                    ComeDirection.GetNewCoords(item.ComeDirection, ref newX, ref newY);

                    var ignoreUsers = false;

                    if (_room.GetGameMap().SquareHasUsers(newX, newY))
                    {
                        if (item.ExtraData != "55" && item.ExtraData != "44")
                        {
                            item.BallIsMoving = false;
                            break;
                        }
                        ignoreUsers = true;
                    }

                    if (ignoreUsers == false)
                        if (!_room.GetGameMap().ItemCanBePlacedHere(newX, newY))
                        {
                            item.ComeDirection = ComeDirection.InverseDirections(_room, item.ComeDirection, newX, newY);
                            newX = resetX;
                            newY = resetY;
                            tryes++;
                            if (tryes > 2)
                                item.BallIsMoving = false;
                            continue;
                        }

                    if (MoveBall(item, client, newX, newY))
                    {
                        item.BallIsMoving = false;
                        break;
                    }

                    int number;
                    int.TryParse(item.ExtraData, out number);
                    if (number > 11)
                        item.ExtraData = (int.Parse(item.ExtraData) - 11).ToString();

                    await Task.Delay(90);
                }

                item.BallValue++;

                if (item.BallValue <= 6)
                    return;
                item.BallIsMoving = false;
                item.BallValue = 1;
                //break;
            }
        }

        internal void RegisterGate(RoomItem item)
        {
            if (_gates[0] == null)
            {
                item.Team = Team.blue;
                _gates[0] = item;
                return;
            }
            if (_gates[1] == null)
            {
                item.Team = Team.red;
                _gates[1] = item;
                return;
            }
            if (_gates[2] == null)
            {
                item.Team = Team.green;
                _gates[2] = item;
                return;
            }
            if (_gates[3] != null)
                return;
            item.Team = Team.yellow;
            _gates[3] = item;
        }

        internal void RemoveBall(uint itemId)
        {
            _balls.Remove(itemId);
        }

        internal void UnRegisterGate(RoomItem item)
        {
            switch (item.Team)
            {
                case Team.red:
                    _gates[1] = null;
                    return;

                case Team.green:
                    _gates[2] = null;
                    return;

                case Team.blue:
                    _gates[0] = null;
                    return;

                case Team.yellow:
                    _gates[3] = null;
                    return;

                default:
                    return;
            }
        }

        private static bool Veryficball(RoomUser user, int actualx, int nexx, int actualy, int nexy)
        {
            return PathFinder.CalculateRotation(user.X, user.Y, actualx, actualy) == user.RotBody;
        }

        private void HandleFootballGameItems(Point ballItemCoord, RoomUser user)
        {
            if (user == null || _room == null || _room.GetGameManager() == null) return;
            var serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("RoomUserActionMessageComposer"));

            if (_room.GetGameManager()
                .GetItems(Team.red)
                .Values.SelectMany(current => current.AffectedTiles.Values)
                .Any(current2 => current2.X == ballItemCoord.X && current2.Y == ballItemCoord.Y))
                _room.GetGameManager().AddPointToTeam(Team.red, user);
            if (
                _room.GetGameManager()
                    .GetItems(Team.green)
                    .Values.SelectMany(current3 => current3.AffectedTiles.Values)
                    .Any(current4 => current4.X == ballItemCoord.X && current4.Y == ballItemCoord.Y))
                _room.GetGameManager().AddPointToTeam(Team.green, user);
            if (
                _room.GetGameManager()
                    .GetItems(Team.blue)
                    .Values.SelectMany(current5 => current5.AffectedTiles.Values)
                    .Any(current6 => current6.X == ballItemCoord.X && current6.Y == ballItemCoord.Y))
                _room.GetGameManager().AddPointToTeam(Team.blue, user);
            if (!_room.GetGameManager()
                .GetItems(Team.yellow)
                .Values.SelectMany(current7 => current7.AffectedTiles.Values)
                .Any(current8 => current8.X == ballItemCoord.X && current8.Y == ballItemCoord.Y))
                _room.GetGameManager().AddPointToTeam(Team.yellow, user);

            serverMessage.AppendInteger(user.VirtualId);
            serverMessage.AppendInteger(0);
            user.GetClient().GetHabbo().CurrentRoom.SendMessage(serverMessage);
        }
    }
}

@Hypothesis
 
Last edited:

Central

Imagination is more important than knowledge.
Feb 22, 2015
709
107
I tried it on my hotel and it works, try this?
C#:
using System;
using System.Linq;
using System.Drawing;
using System.Collections.Generic;
using System.Collections.Concurrent;

using Plus.Communication.Packets.Incoming;

using Plus.HabboHotel.Items;
using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Rooms.Engine;
using Plus.HabboHotel.Rooms.Games.Teams;
using Plus.HabboHotel.Items.Wired;
using Plus.HabboHotel.Rooms.PathFinding;

namespace Plus.HabboHotel.Rooms.Games.Football
{
    public class Soccer
    {
        private Room _room;
        private Item[] gates;
        private ConcurrentDictionary<int, Item> _balls;
        private bool _gameStarted;

        public Soccer(Room room)
        {
            this._room = room;
            this.gates = new Item[4];
            this._balls = new ConcurrentDictionary<int, Item>();
            this._gameStarted = false;
        }
        public bool GameIsStarted
        {
            get { return this._gameStarted; }
        }
        public void StopGame(bool userTriggered = false)
        {
            this._gameStarted = false;

            if (!userTriggered)
                _room.GetWired().TriggerEvent(WiredBoxType.TriggerGameEnds, null);
        }

        public void StartGame()
        {
            this._gameStarted = true;
        }

        public void AddBall(Item item)
        {
            this._balls.TryAdd(item.Id, item);
        }

        public void RemoveBall(int itemID)
        {
            Item Item = null;
            this._balls.TryRemove(itemID, out Item);
        }

        public void OnUserWalk(RoomUser User)
        {
            if (User == null)
                return;

            foreach (Item item in this._balls.Values.ToList())
            {
                int NewX = 0;
                int NewY = 0;
                int differenceX = User.X - item.GetX;
                int differenceY = User.Y - item.GetY;

                if (differenceX == 0 && differenceY == 0)
                {
                    if (User.RotBody == 4)
                    {
                        NewX = User.X;
                        NewY = User.Y + 2;

                    }
                    else if (User.RotBody == 6)
                    {
                        NewX = User.X - 2;
                        NewY = User.Y;

                    }
                    else if (User.RotBody == 0)
                    {
                        NewX = User.X;
                        NewY = User.Y - 2;

                    }
                    else if (User.RotBody == 2)
                    {
                        NewX = User.X + 2;
                        NewY = User.Y;

                    }
                    else if (User.RotBody == 1)
                    {
                        NewX = User.X + 2;
                        NewY = User.Y - 2;

                    }
                    else if (User.RotBody == 7)
                    {
                        NewX = User.X - 2;
                        NewY = User.Y - 2;

                    }
                    else if (User.RotBody == 3)
                    {
                        NewX = User.X + 2;
                        NewY = User.Y + 2;

                    }
                    else if (User.RotBody == 5)
                    {
                        NewX = User.X - 2;
                        NewY = User.Y + 2;
                    }

                    if (!this._room.GetRoomItemHandler().CheckPosItem(User.GetClient(), item, NewX, NewY, item.Rotation, false, false))
                    {
                        if (User.RotBody == 0)
                        {
                            NewX = User.X;
                            NewY = User.Y + 1;
                        }
                        else if (User.RotBody == 2)
                        {
                            NewX = User.X - 1;
                            NewY = User.Y;
                        }
                        else if (User.RotBody == 4)
                        {
                            NewX = User.X;
                            NewY = User.Y - 1;
                        }
                        else if (User.RotBody == 6)
                        {
                            NewX = User.X + 1;
                            NewY = User.Y;
                        }
                        else if (User.RotBody == 5)
                        {
                            NewX = User.X + 1;
                            NewY = User.Y - 1;
                        }
                        else if (User.RotBody == 3)
                        {
                            NewX = User.X - 1;
                            NewY = User.Y - 1;
                        }
                        else if (User.RotBody == 7)
                        {
                            NewX = User.X + 1;
                            NewY = User.Y + 1;
                        }
                        else if (User.RotBody == 1)
                        {
                            NewX = User.X - 1;
                            NewY = User.Y + 1;
                        }
                    }
                }
                else if (differenceX <= 1 && differenceX >= -1 && differenceY <= 1 && differenceY >= -1 && VerifyBall(User, item.Coordinate.X, item.Coordinate.Y))//VERYFIC BALL CHECAR SI ESTA EN DIRECCION ASIA LA PELOTA
                {
                    NewX = differenceX * -1;
                    NewY = differenceY * -1;

                    NewX = NewX + item.GetX;
                    NewY = NewY + item.GetY;
                }

                if (item.GetRoom().GetGameMap().ValidTile(NewX, NewY))
                {
                    MoveBall(item, NewX, NewY, User);
                }
            }
        }

        private bool VerifyBall(RoomUser user, int actualx, int actualy)
        {
            return Rotation.Calculate(user.X, user.Y, actualx, actualy) == user.RotBody;
        }

        public void RegisterGate(Item item)
        {
            if (gates[0] == null)
            {
                item.team = TEAM.BLUE;
                gates[0] = item;
            }
            else if (gates[1] == null)
            {
                item.team = TEAM.RED;
                gates[1] = item;
            }
            else if (gates[2] == null)
            {
                item.team = TEAM.GREEN;
                gates[2] = item;
            }
            else if (gates[3] == null)
            {
                item.team = TEAM.YELLOW;
                gates[3] = item;
            }
        }

        public void UnRegisterGate(Item item)
        {
            switch (item.team)
            {
                case TEAM.BLUE:
                    {
                        gates[0] = null;
                        break;
                    }
                case TEAM.RED:
                    {
                        gates[1] = null;
                        break;
                    }
                case TEAM.GREEN:
                    {
                        gates[2] = null;
                        break;
                    }
                case TEAM.YELLOW:
                    {
                        gates[3] = null;
                        break;
                    }
            }
        }

        public void onGateRemove(Item item)
        {
            switch (item.GetBaseItem().InteractionType)
            {
                case InteractionType.FOOTBALL_GOAL_RED:
                case InteractionType.footballcounterred:
                    {
                        _room.GetGameManager().RemoveFurnitureFromTeam(item, TEAM.RED);
                        break;
                    }
                case InteractionType.FOOTBALL_GOAL_GREEN:
                case InteractionType.footballcountergreen:
                    {
                        _room.GetGameManager().RemoveFurnitureFromTeam(item, TEAM.GREEN);
                        break;
                    }
                case InteractionType.FOOTBALL_GOAL_BLUE:
                case InteractionType.footballcounterblue:
                    {
                        _room.GetGameManager().RemoveFurnitureFromTeam(item, TEAM.BLUE);
                        break;
                    }
                case InteractionType.FOOTBALL_GOAL_YELLOW:
                case InteractionType.footballcounteryellow:
                    {
                        _room.GetGameManager().RemoveFurnitureFromTeam(item, TEAM.YELLOW);
                        break;
                    }
            }
        }

        public void MoveBall(Item item, int newX, int newY, RoomUser user)
        {
            if (item == null || user == null)
                return;

            if (!_room.GetGameMap().itemCanBePlacedHere(newX, newY))
                return;

            Point oldRoomCoord = item.Coordinate;
            if (oldRoomCoord.X == newX && oldRoomCoord.Y == newY)
                return;

            double NewZ = _room.GetGameMap().Model.SqFloorHeight[newX, newY];

            _room.SendPacket(new SlideObjectBundleComposer(item.Coordinate.X, item.Coordinate.Y, item.GetZ, newX, newY, NewZ, item.Id, item.Id, item.Id));

            item.ExtraData = "11";
            item.UpdateNeeded = true;

            _room.GetRoomItemHandler().SetFloorItem(null, item, newX, newY, item.Rotation, false, false, false, false);

            this._room.OnUserShoot(user, item);
        }

        public void Dispose()
        {
            Array.Clear(gates, 0, gates.Length);
            gates = null;
            _room = null;
            _balls.Clear();
            _balls = null;
        }
    }
}
 

Users who are viewing this thread

Top