Esempio n. 1
0
        public static int HandleRotation(int oldRotation, RotationState state)
        {
            var rotation = oldRotation;

            switch (state)
            {
            case RotationState.ClocWise:
            {
                HandleClockwiseRotation(ref rotation);
                return(rotation);
            }

            case RotationState.CounterClockWise:
            {
                HandleCounterClockwiseRotation(ref rotation);
                return(rotation);
            }

            case RotationState.Random:
            {
                if (Plus.GetRandomNumber(0, 3) == 1)
                {
                    HandleClockwiseRotation(ref rotation);
                }
                else
                {
                    HandleCounterClockwiseRotation(ref rotation);
                }
                return(rotation);
            }
            }

            return(rotation);
        }
Esempio n. 2
0
        /// <summary>
        /// Called when [teleport room user enter].
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="item">The item.</param>
        internal void OnTeleportRoomUserEnter(RoomUser user, RoomItem item)
        {
            var items = _banzaiTeleports.Values.Where(p => p.Id != item.Id).ToList();

            if (!items.Any())
            {
                return;
            }

            var countId     = Plus.GetRandomNumber(0, items.Count());
            var countAmount = 0;

            foreach (var current in items.Where(current => current != null))
            {
                if (countAmount != countId)
                {
                    countAmount++;
                    continue;
                }
                current.ExtraData    = "1";
                current.UpdateNeeded = true;
                _room.GetGameMap().TeleportToItem(user, current);
                item.ExtraData    = "1";
                item.UpdateNeeded = true;
                current.UpdateState();
                item.UpdateState();

                break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Runs to a random spot in room
        /// </summary>
        private void RunRandomly()
        {
            int randomX = Plus.GetRandomNumber(0, GetRoom().GetGameMap().Model.MapSizeX);
            int randomY = Plus.GetRandomNumber(0, GetRoom().GetGameMap().Model.MapSizeY);

            GetRoomUser().MoveTo(randomX, randomY);
        }
Esempio n. 4
0
        public static Point HandleMovementDir(Point newCoordinate, MovementDirection state, int newRotation)
        {
            var newPoint = new Point(newCoordinate.X, newCoordinate.Y);

            switch (state)
            {
            case MovementDirection.Up:
            case MovementDirection.Down:
            case MovementDirection.Left:
            case MovementDirection.Right:
            case MovementDirection.DownRight:
            case MovementDirection.DownLeft:
            case MovementDirection.UpRight:
            case MovementDirection.UpLeft:
            {
                HandleMovementDir(ref newPoint, state);
                break;
            }

            case MovementDirection.Random:
            {
                switch (Plus.GetRandomNumber(1, 5))
                {
                case 1:
                {
                    HandleMovementDir(ref newPoint, MovementDirection.Up);
                    break;
                }

                case 2:
                {
                    HandleMovementDir(ref newPoint, MovementDirection.Down);
                    break;
                }

                case 3:
                {
                    HandleMovementDir(ref newPoint, MovementDirection.Left);
                    break;
                }

                case 4:
                {
                    HandleMovementDir(ref newPoint, MovementDirection.Right);
                    break;
                }
                }
                break;
            }
            }

            return(newPoint);
        }
Esempio n. 5
0
 /// <summary>
 /// Pets the energy.
 /// </summary>
 /// <param name="add">if set to <c>true</c> [add].</param>
 internal void PetEnergy(bool add)
 {
     {
         int num;
         if (add)
         {
             if (Energy > 100)
             {
                 Energy = 100;
                 return;
             }
             if (Energy > 85)
             {
                 return;
             }
             if (Energy > 85)
             {
                 num = MaxEnergy - Energy;
             }
             else
             {
                 num = 10;
             }
         }
         else
         {
             num = 15;
         }
         if (num <= 4)
         {
             num = 15;
         }
         var randomNumber = Plus.GetRandomNumber(4, num);
         if (!add)
         {
             Energy -= randomNumber;
             if (Energy < 0)
             {
                 Energy = 1;
             }
         }
         else
         {
             Energy += randomNumber;
         }
         if (DbState != DatabaseUpdateState.NeedsInsert)
         {
             DbState = DatabaseUpdateState.NeedsUpdate;
         }
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Gets the random speech.
        /// </summary>
        /// <param name="mixPhrases">if set to <c>true</c> [mix phrases].</param>
        /// <returns>System.String.</returns>
        internal string GetRandomSpeech(bool mixPhrases)
        {
            if (!RandomSpeech.Any())
            {
                return("");
            }

            {
                if (mixPhrases)
                {
                    return(RandomSpeech[Plus.GetRandomNumber(0, RandomSpeech.Count - 1)]);
                }
                if (LastSpokenPhrase >= RandomSpeech.Count)
                {
                    LastSpokenPhrase = 1;
                }
                var result = RandomSpeech[LastSpokenPhrase - 1];
                LastSpokenPhrase++;
                return(result);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Cycles the pyramids.
        /// </summary>
        private void CyclePyramids()
        {
            foreach (var item in _banzaiPyramids.Select(pyramid => pyramid.Value).Where(current => current != null))
            {
                if (item.InteractionCountHelper == 0 && item.ExtraData == "1")
                {
                    _room.GetGameMap().RemoveFromMap(item, false);
                    item.InteractionCountHelper = 1;
                }
                if (string.IsNullOrEmpty(item.ExtraData))
                {
                    item.ExtraData = "0";
                }

                var randomNumber = Plus.GetRandomNumber(0, 30);
                if (randomNumber <= 26)
                {
                    continue;
                }
                if (item.ExtraData == "0")
                {
                    item.ExtraData = "1";
                    item.UpdateState();
                    _room.GetGameMap().RemoveFromMap(item, false);
                }
                else
                {
                    if (!_room.GetGameMap().ItemCanBePlacedHere(item.X, item.Y))
                    {
                        continue;
                    }
                    item.ExtraData = "0";
                    item.UpdateState();
                    _room.GetGameMap().AddItemToMap(item, false);
                }
            }
        }
Esempio n. 8
0
        public static Point HandleMovement(Point newCoordinate, MovementState state, int newRotation)
        {
            var newPoint = new Point(newCoordinate.X, newCoordinate.Y);

            switch (state)
            {
            case MovementState.Up:
            case MovementState.Down:
            case MovementState.Left:
            case MovementState.Right:
            {
                HandleMovement(ref newPoint, state);
                break;
            }

            case MovementState.LeftRight:
            {
                if (Plus.GetRandomNumber(0, 2) == 1)
                {
                    HandleMovement(ref newPoint, MovementState.Left);
                }
                else
                {
                    HandleMovement(ref newPoint, MovementState.Right);
                }
                break;
            }

            case MovementState.UpDown:
            {
                if (Plus.GetRandomNumber(0, 2) == 1)
                {
                    HandleMovement(ref newPoint, MovementState.Up);
                }
                else
                {
                    HandleMovement(ref newPoint, MovementState.Down);
                }
                break;
            }

            case MovementState.Random:
            {
                switch (Plus.GetRandomNumber(1, 5))
                {
                case 1:
                {
                    HandleMovement(ref newPoint, MovementState.Up);
                    break;
                }

                case 2:
                {
                    HandleMovement(ref newPoint, MovementState.Down);
                    break;
                }

                case 3:
                {
                    HandleMovement(ref newPoint, MovementState.Left);
                    break;
                }

                case 4:
                {
                    HandleMovement(ref newPoint, MovementState.Right);
                    break;
                }
                }
                break;
            }
            }

            return(newPoint);
        }
Esempio n. 9
0
        /// <summary>
        /// Called when [timer tick].
        /// </summary>
        internal override void OnTimerTick()
        {
            if (GetRoomUser().FollowingOwner != null)
            {
                GetRoomUser().MoveTo(GetRoomUser().FollowingOwner.SquareBehind);
            }
            if (_speechTimer <= 0)
            {
                RoomUser roomUser = GetRoomUser();
                if (roomUser != null)
                {
                    if (roomUser.PetData.DbState != DatabaseUpdateState.NeedsInsert)
                    {
                        roomUser.PetData.DbState = DatabaseUpdateState.NeedsUpdate;
                    }
                    var random = new Random();
                    RemovePetStatus();
                    string[] value = PetLocale.GetValue(string.Format("speech.pet{0}", roomUser.PetData.Type));
                    string   text  = value[random.Next(0, value.Length - 1)];
                    if (GetRoom() != null && !GetRoom().MutedPets)
                    {
                        roomUser.Chat(null, text, false, 0, 0);
                    }
                    else
                    {
                        roomUser.Statusses.Add(text, TextHandling.GetString(roomUser.Z));
                    }
                }
                _speechTimer = Plus.GetRandomNumber(20, 120);
            }
            else
            {
                _speechTimer--;
            }
            if (_actionTimer <= 0 && GetRoomUser() != null)
            {
                try
                {
                    _actionTimer = GetRoomUser().FollowingOwner != null
                        ? 2
                        : Plus.GetRandomNumber(15, 40 + GetRoomUser().PetData.VirtualId);
                    RemovePetStatus();
                    _actionTimer = Plus.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
                            }
                            var 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)
                {
                    Logging.HandleException(pException, "PetBot.OnTimerTick");
                    goto IL_1B5;
                }
            }
            _actionTimer--;
IL_1B5:
            if (_energyTimer <= 0)
            {
                RemovePetStatus();
                var roomUser2 = GetRoomUser();
                if (roomUser2 != null)
                {
                    roomUser2.PetData.PetEnergy(true);
                }
                _energyTimer = Plus.GetRandomNumber(30, 120);
                return;
            }
            _energyTimer--;
        }
Esempio n. 10
0
        public bool Execute(params object[] stuff)
        {
            if (stuff[0] == null)
            {
                return(false);
            }
            var user = (RoomUser)stuff[0];
            var item = (Interaction)stuff[1];

            if (_mBanned.Contains(item))
            {
                return(false);
            }

            if (user == null)
            {
                return(false);
            }

            var amountLeft = int.Parse(OtherExtraString2);
            var often      = int.Parse(OtherExtraString);

            bool premied = false;

            if (amountLeft == 0)
            {
                var message = new ServerMessage(LibraryParser.OutgoingRequest("WiredRewardAlertMessageComposer"));
                message.AppendInteger(0);
                user.GetClient().SendMessage(message);

                return(true);
            }

            foreach (var dataStr in OtherString.Split(';'))
            {
                var dataArray = dataStr.Split(',');

                var isbadge    = dataArray[0] == "0";
                var code       = dataArray[1];
                var percentage = int.Parse(dataArray[2]);

                var random = Plus.GetRandomNumber(0, 100);

                var message =
                    new ServerMessage(LibraryParser.OutgoingRequest("WiredRewardAlertMessageComposer"));

                if (often == 0 && random <= percentage)
                {
                    continue;
                }
                premied = true;

                if (isbadge)
                {
                    if (user.GetClient().GetHabbo().GetBadgeComponent().HasBadge(code))
                    {
                        message.AppendInteger(1);
                        user.GetClient().SendMessage(message);
                    }
                    else
                    {
                        user.GetClient()
                        .GetHabbo()
                        .GetBadgeComponent()
                        .GiveBadge(code, true, user.GetClient(), true);

                        message.AppendInteger(7);
                        user.GetClient().SendMessage(message);
                    }
                }
                else //item or effect
                {
                    var roomItem = Plus.GetGame().GetItemManager().GetItem(uint.Parse(code));
                    if (roomItem == null)
                    {
                        continue;
                    }

                    if (roomItem.Type == 'e') // is effect
                    {
                        user.GetClient()
                        .GetHabbo()
                        .GetAvatarEffectsInventoryComponent().AddNewEffect(roomItem.SpriteId, 3600, 1);
                    }
                    else
                    {
                        user.GetClient()
                        .GetHabbo()
                        .GetInventoryComponent()
                        .AddNewItem(0u, roomItem.ItemId, "0", 0u, true, false, 0, 0, "");
                        user.GetClient()
                        .SendMessage(
                            new ServerMessage(LibraryParser.OutgoingRequest("UpdateInventoryMessageComposer")));
                    }

                    message.AppendInteger(6);
                    user.GetClient().SendMessage(message);
                }
            }

            if (!premied)
            {
                var message = new ServerMessage(LibraryParser.OutgoingRequest("WiredRewardAlertMessageComposer"));
                message.AppendInteger(4);
                user.GetClient().SendMessage(message);
            }
            return(true);
        }