Ejemplo n.º 1
0
Archivo: RoomUser.cs Proyecto: sgf/Yupi
 /// <summary>
 ///     Serializes the status.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="status">The status.</param>
 internal void SerializeStatus(ServerMessage message, string status)
 {
     if (IsSpectator)
     {
         return;
     }
     message.AppendInteger(VirtualId);
     message.AppendInteger(X);
     message.AppendInteger(Y);
     message.AppendString(ServerUserChatTextHandler.GetString(SetZ));
     message.AppendInteger(RotHead);
     message.AppendInteger(RotBody);
     message.AppendString(status);
 }
Ejemplo n.º 2
0
        internal void MovePuck(RoomItem item, GameClient client, int newX, int newY, Team team)
        {
            if (!_room.GetGameMap().ItemCanBePlacedHere(newX, newY))
            {
                return;
            }

            Point oldRoomCoord = item.Coordinate;

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

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

            item.ExtraData    = ((int)team).ToString();
            item.UpdateNeeded = true;
            item.UpdateState();

            ServerMessage serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("ItemAnimationMessageComposer"));

            serverMessage.AppendInteger(oldRoomCoord.X);
            serverMessage.AppendInteger(oldRoomCoord.Y);
            serverMessage.AppendInteger(newX);
            serverMessage.AppendInteger(newY);
            serverMessage.AppendInteger(1);
            serverMessage.AppendInteger(item.Id);
            serverMessage.AppendString(ServerUserChatTextHandler.GetString(item.Z));
            serverMessage.AppendString(ServerUserChatTextHandler.GetString(newZ));
            serverMessage.AppendInteger(-1);
            _room.SendMessage(serverMessage);

            _room.GetRoomItemHandler()
            .SetFloorItem(client, item, newX, newY, item.Rot, false, false, false, false, false);

            if (client == null || client.GetHabbo() == null)
            {
                return;
            }

            RoomUser user = client.GetHabbo().CurrentRoom.GetRoomUserManager().GetRoomUserByHabbo(client.GetHabbo().Id);

            if (IsBanzaiActive)
            {
                HandleBanzaiTiles(new Point(newX, newY), team, user);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Serializes the status.
        /// </summary>
        /// <param name="message">The message.</param>
        internal void SerializeStatus(ServerMessage message)
        {
            message.AppendInteger(VirtualId);
            message.AppendInteger(X);
            message.AppendInteger(Y);
            message.AppendString(ServerUserChatTextHandler.GetString(Z));
            message.AppendInteger(RotHead);
            message.AppendInteger(RotBody);

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("/");

            if (IsPet && PetData.Type == "pet_monster")
            {
                stringBuilder.AppendFormat("/{0}{1}", PetData.MoplaBreed.GrowStatus, Statusses.Count >= 1 ? "/" : "");
            }

            lock (Statusses)
            {
                foreach (KeyValuePair <string, string> current in Statusses)
                {
                    stringBuilder.Append(current.Key);

                    if (!string.IsNullOrEmpty(current.Value))
                    {
                        stringBuilder.Append(" ");
                        stringBuilder.Append(current.Value);
                    }

                    stringBuilder.Append("/");
                }
            }

            stringBuilder.Append("/");

            message.AppendString(stringBuilder.ToString());

            if (!Statusses.ContainsKey("sign"))
            {
                return;
            }

            RemoveStatus("sign");
            UpdateNeeded = true;
        }
Ejemplo n.º 4
0
        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);
            }

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

            ServerMessage 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(ServerUserChatTextHandler.GetString(item.Z));
            mMessage.AppendString(ServerUserChatTextHandler.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);
        }
Ejemplo n.º 5
0
        private static bool Paste(GameClient session)
        {
            Room room = session.GetHabbo().CurrentRoom;

            RoomUser user = room.GetRoomUserManager()
                            .GetRoomUserByHabbo(session.GetHabbo().UserName);

            if (user.CopyX == 0 || user.CopyY == 0)
            {
                session.SendWhisper("First usage :developer copy");
                return(true);
            }
            using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
            {
                foreach (
                    RoomItem item in
                    room.GetGameMap()
                    .GetAllRoomItemForSquare(user.CopyX, user.CopyY))
                {
                    queryReactor.SetQuery(
                        "INSERT INTO items_rooms (item_name, user_id, room_id, extra_data, x, y, z, rot, group_id) VALUES (" +
                        item.GetBaseItem().Name + ", " + user.UserId + ", " + user.RoomId + ", @extraData, " +
                        user.LastSelectedX + ", " + user.LastSelectedY + ", @height, " + item.Rot + ", " + item.GroupId +
                        ")");
                    queryReactor.AddParameter("extraData", item.ExtraData);
                    queryReactor.AddParameter("height", ServerUserChatTextHandler.GetString(item.Z));

                    uint insertId = (uint)queryReactor.InsertQuery();

                    RoomItem roomItem = new RoomItem(insertId, user.RoomId, item.GetBaseItem().Name, item.ExtraData,
                                                     user.LastSelectedX, user.LastSelectedY, item.Z, item.Rot, session.GetHabbo().CurrentRoom,
                                                     user.UserId, item.GroupId, item.SongCode,
                                                     item.IsBuilder);
                    room.GetRoomItemHandler().DeveloperSetFloorItem(session, roomItem);
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
Archivo: RoomUser.cs Proyecto: sgf/Yupi
        /// <summary>
        ///     Serializes the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="gotPublicRoom">if set to <c>true</c> [got public room].</param>
        internal void Serialize(ServerMessage message, bool gotPublicRoom)
        {
            if (message == null)
            {
                return;
            }
            if (IsSpectator)
            {
                return;
            }
            if (!IsBot)
            {
                if (GetClient() == null || GetClient().GetHabbo() == null)
                {
                    return;
                }
                Group group = Yupi.GetGame().GetGroupManager().GetGroup(GetClient().GetHabbo().FavouriteGroup);
                if (GetClient() == null || GetClient().GetHabbo() == null)
                {
                    return;
                }
                Habbo habbo = GetClient().GetHabbo();

                if (habbo == null)
                {
                    return;
                }

                message.AppendInteger(habbo.Id);
                message.AppendString(habbo.UserName);
                message.AppendString(habbo.Motto);
                message.AppendString(habbo.Look);
                message.AppendInteger(VirtualId);
                message.AppendInteger(X);
                message.AppendInteger(Y);
                message.AppendString(ServerUserChatTextHandler.GetString(Z));
                message.AppendInteger(0);
                message.AppendInteger(1);
                message.AppendString(habbo.Gender.ToLower());
                if (@group != null)
                {
                    message.AppendInteger(@group.Id);
                    message.AppendInteger(0);
                    message.AppendString(@group.Name);
                }
                else
                {
                    message.AppendInteger(0);
                    message.AppendInteger(0);
                    message.AppendString("");
                }
                message.AppendString("");
                message.AppendInteger(habbo.AchievementPoints);
                message.AppendBool(false);
                return;
            }

            if (BotAi == null || BotData == null)
            {
                throw new NullReferenceException("BotAI or BotData is undefined");
            }

            message.AppendInteger(BotAi.BaseId);
            message.AppendString(BotData.Name);
            message.AppendString(BotData.Motto);
            if (BotData.AiType == AiType.Pet)
            {
                if (PetData.Type == 16u)
                {
                    message.AppendString(PetData.MoplaBreed.PlantData);
                }
                else if (PetData.HaveSaddle == Convert.ToBoolean(2))
                {
                    message.AppendString(string.Concat(BotData.Look.ToLower(), " 3 4 10 0 2 ", PetData.PetHair, " ",
                                                       PetData.HairDye, " 3 ", PetData.PetHair, " ", PetData.HairDye));
                }
                else if (PetData.HaveSaddle == Convert.ToBoolean(1))
                {
                    message.AppendString(string.Concat(BotData.Look.ToLower(), " 3 2 ", PetData.PetHair, " ",
                                                       PetData.HairDye, " 3 ", PetData.PetHair, " ", PetData.HairDye, " 4 9 0"));
                }
                else
                {
                    message.AppendString(string.Concat(BotData.Look.ToLower(), " 2 2 ", PetData.PetHair, " ",
                                                       PetData.HairDye, " 3 ", PetData.PetHair, " ", PetData.HairDye));
                }
            }
            else
            {
                message.AppendString(BotData.Look.ToLower());
            }
            message.AppendInteger(VirtualId);
            message.AppendInteger(X);
            message.AppendInteger(Y);
            message.AppendString(ServerUserChatTextHandler.GetString(Z));
            message.AppendInteger(0);
            message.AppendInteger(BotData.AiType == AiType.Generic ? 4 : 2);
            if (BotData.AiType == AiType.Pet)
            {
                message.AppendInteger(PetData.Type);
                message.AppendInteger(PetData.OwnerId);
                message.AppendString(PetData.OwnerName);
                message.AppendInteger(PetData.Type == 16u ? 0 : 1);
                message.AppendBool(PetData.HaveSaddle);
                message.AppendBool(RidingHorse);
                message.AppendInteger(0);
                message.AppendInteger(PetData.Type == 16u ? 1 : 0);
                message.AppendString(PetData.Type == 16u ? PetData.MoplaBreed.GrowStatus : "");
                return;
            }
            message.AppendString(BotData.Gender.ToLower());
            message.AppendInteger(BotData.OwnerId);
            message.AppendString(Yupi.GetGame().GetClientManager().GetNameById(BotData.OwnerId));
            message.AppendInteger(5);
            message.AppendShort(1);
            message.AppendShort(2);
            message.AppendShort(3);
            message.AppendShort(4);
            message.AppendShort(5);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Called when [timer tick].
        /// </summary>
        internal override void OnTimerTick()
        {
            RoomUser roomUser = GetRoomUser();

            if (roomUser == null)
            {
                return;
            }

            Random random = new Random();

            if (_actionTimer > 0)
            {
                _actionTimer--;
            }

            if (_speechTimer > 0)
            {
                _speechTimer--;
            }

            if (_energyTimer > 0)
            {
                _energyTimer--;
            }

            if (roomUser.X == roomUser.GoalX && roomUser.Y == roomUser.GoalY && roomUser.Statusses.ContainsKey("mv") && !roomUser.IsWalking)
            {
                roomUser.ClearMovement();
            }

            if (_speechTimer == 0)
            {
                _speechTimer = (uint)new Random().Next(20, 100);

                if (roomUser.PetData.DbState != DatabaseUpdateState.NeedsInsert)
                {
                    roomUser.PetData.DbState = DatabaseUpdateState.NeedsUpdate;
                }

                string[] value = PetLocale.GetValue($"speech.pet{roomUser.PetData.Type.Replace("pet", string.Empty)}");

                string text = value[random.Next(0, value.Length - 1)];

                if (GetRoom() != null && !GetRoom().MutedPets)
                {
                    roomUser.Chat(null, text, false, 0);
                }
                else
                {
                    roomUser.Statusses.Add(text, ServerUserChatTextHandler.GetString(roomUser.Z));
                }
            }

            if (_actionTimer == 0)
            {
                _actionTimer = (uint)random.Next(10, 40);

                if (roomUser.FollowingOwner != null)
                {
                    _actionTimer = 2;
                }

                if (!roomUser.RidingHorse)
                {
                    if (roomUser.PetData.Type == "pet_monster")
                    {
                        return;
                    }

                    if (roomUser.FollowingOwner != null)
                    {
                        roomUser.MoveTo(roomUser.FollowingOwner.SquareInFront);
                        roomUser.FollowingOwner = null;
                    }

                    if (roomUser.FollowingOwner == null)
                    {
                        Point randomPoint = GetRoom().GetGameMap().GetRandomWalkableSquare();

                        if (randomPoint.X == 0 || randomPoint.Y == 0)
                        {
                            return;
                        }

                        roomUser.MoveTo(randomPoint.X, randomPoint.Y);
                    }
                }

                if (random.Next(2, 5) % 2 == 0)
                {
                    RemovePetStatus();

                    switch (roomUser.PetData.Type)
                    {
                    case "pet_monster":
                    {
                        MoplaBreed breed = GetRoomUser().PetData.MoplaBreed;

                        roomUser.PetData.Energy--;

                        roomUser.AddStatus("gst", breed.LiveState == MoplaState.Dead ? "sad" : "sml");

                        roomUser.PetData.MoplaBreed.OnTimerTick(roomUser.PetData.LastHealth,
                                                                roomUser.PetData.UntilGrown);
                    }
                    break;

                    default:
                    {
                        if (roomUser.PetData.Energy < 30 || random.Next(2, 5) % 2 == 0)
                        {
                            roomUser.AddStatus("lay", string.Empty);
                        }
                        else if ((roomUser.PetData.Energy < 30 && roomUser.PetData.Nutrition < 30) ||
                                 roomUser.PetData.Nutrition < 30 || random.Next(2, 5) % 2 == 0)
                        {
                            roomUser.AddStatus("snf", string.Empty);
                        }
                        else if (GetRoomUser().PetData.Energy >= 30)
                        {
                            roomUser.AddStatus("gst", "joy");
                        }
                        else
                        {
                            roomUser.AddStatus("gst", "sml");
                        }
                    }
                    break;
                    }
                }
            }

            if (_energyTimer == 0)
            {
                _energyTimer = (uint)random.Next(30, 120);

                roomUser.PetData.PetEnergy(true);
            }
        }
Ejemplo n.º 8
0
Archivo: PetBot.cs Proyecto: sgf/Yupi
        /// <summary>
        ///     Called when [timer tick].
        /// </summary>
        internal override void OnTimerTick()
        {
            if (_speechTimer <= 0)
            {
                RoomUser roomUser = GetRoomUser();

                if (roomUser != null)
                {
                    if (roomUser.PetData.DbState != DatabaseUpdateState.NeedsInsert)
                    {
                        roomUser.PetData.DbState = DatabaseUpdateState.NeedsUpdate;
                    }

                    Random random = new Random();

                    RemovePetStatus();

                    string[] value = PetLocale.GetValue($"speech.pet{roomUser.PetData.Type}");

                    string text = value[random.Next(0, value.Length - 1)];

                    if (GetRoom() != null && !GetRoom().MutedPets)
                    {
                        roomUser.Chat(null, text, false, 0);
                    }
                    else
                    {
                        roomUser.Statusses.Add(text, ServerUserChatTextHandler.GetString(roomUser.Z));
                    }
                }

                _speechTimer = Yupi.GetRandomNumber(20, 120);
            }
            else
            {
                _speechTimer--;
            }

            if (_actionTimer <= 0 && GetRoomUser() != null)
            {
                try
                {
                    _actionTimer = GetRoomUser().FollowingOwner != null ? 2 : Yupi.GetRandomNumber(15, 40 + GetRoomUser().PetData.VirtualId);

                    RemovePetStatus();

                    _actionTimer = Yupi.GetRandomNumber(15, 40 + GetRoomUser().PetData.VirtualId);

                    if (GetRoomUser().RidingHorse != true)
                    {
                        RemovePetStatus();

                        if (GetRoomUser().FollowingOwner != null)
                        {
                            GetRoomUser().MoveTo(GetRoomUser().FollowingOwner.SquareBehind);
                        }
                        else
                        {
                            if (GetRoomUser().PetData.Type == 16)
                            {
                                return;                                   //Monsterplants can't move
                            }
                            Point nextCoord = GetRoom().GetGameMap().GetRandomValidWalkableSquare();
                            GetRoomUser().MoveTo(nextCoord.X, nextCoord.Y);
                        }
                    }

                    if (new Random().Next(2, 15) % 2 == 0)
                    {
                        if (GetRoomUser().PetData.Type == 16)
                        {
                            MoplaBreed breed = GetRoomUser().PetData.MoplaBreed;
                            GetRoomUser().PetData.Energy--;
                            GetRoomUser().AddStatus("gst", breed.LiveState == MoplaState.Dead ? "sad" : "sml");
                            GetRoomUser()
                            .PetData.MoplaBreed.OnTimerTick(GetRoomUser().PetData.LastHealth,
                                                            GetRoomUser().PetData.UntilGrown);
                        }
                        else
                        {
                            if (GetRoomUser().PetData.Energy < 30)
                            {
                                GetRoomUser().AddStatus("lay", "");
                            }
                            else
                            {
                                GetRoomUser().AddStatus("gst", "joy");
                                if (new Random().Next(1, 7) == 3)
                                {
                                    GetRoomUser().AddStatus("snf", "");
                                }
                            }
                        }
                        GetRoomUser().UpdateNeeded = true;
                    }

                    goto IL_1B5;
                }
                catch (Exception pException)
                {
                    ServerLogManager.HandleException(pException, "PetBot.OnTimerTick");

                    goto IL_1B5;
                }
            }

            _actionTimer--;

IL_1B5:

            if (_energyTimer <= 0)
            {
                RemovePetStatus();

                RoomUser roomUser2 = GetRoomUser();

                roomUser2?.PetData.PetEnergy(true);

                _energyTimer = Yupi.GetRandomNumber(30, 120);

                return;
            }

            _energyTimer--;
        }