Пример #1
0
        //internal Pet GeneratePetFromRow(DataRow Row, uint PetID)
        //{
        //    if (Row == null)
        //        return null;

        //    return new Pet(PetID, (uint)Row["user_id"], (uint)Row["room_id"], (string)Row["name"], (uint)Row["type"], (string)Row["race"], (string)Row["color"], (int)Row["expirience"], (int)Row["energy"], (int)Row["nutrition"], (int)Row["respect"], (double)Row["createstamp"], (int)Row["x"], (int)Row["y"], (double)Row["z"]);
        //}

        //internal uint GenerateItemId()
        //{
        //    //uint i = 0;

        //    //using (DatabaseClient dbClient = FirewindEnvironment.GetDatabase().GetClient())
        //    //{
        //    //    i = mCacheID++;
        //    //    dbClient.runFastQuery("UPDATE item_id_generator SET id_generator = '" + mCacheID + "' LIMIT 1");
        //    //}

        //    return mCacheID++;
        //}

        internal EcotronReward GetRandomEcotronReward()
        {
            uint Level = 1;

            if (FirewindEnvironment.GetRandomNumber(1, 2000) == 2000)
            {
                Level = 5;
            }
            else if (FirewindEnvironment.GetRandomNumber(1, 200) == 200)
            {
                Level = 4;
            }
            else if (FirewindEnvironment.GetRandomNumber(1, 40) == 40)
            {
                Level = 3;
            }
            else if (FirewindEnvironment.GetRandomNumber(1, 4) == 4)
            {
                Level = 2;
            }

            List <EcotronReward> PossibleRewards = GetEcotronRewardsForLevel(Level);

            if (PossibleRewards != null && PossibleRewards.Count >= 1)
            {
                return(PossibleRewards[FirewindEnvironment.GetRandomNumber(0, (PossibleRewards.Count - 1))]);
            }
            else
            {
                return(new EcotronReward(0, 1479, 0)); // eco lamp two :D
            }
        }
Пример #2
0
        internal Point getRandomWalkableSquare()
        {
            List <Point> walkableSquares = new List <Point>();

            for (int y = 0; y < mGameMap.GetUpperBound(1) - 1; y++)
            {
                for (int x = 0; x < mGameMap.GetUpperBound(0) - 1; x++)
                {
                    if (mStaticModel.DoorX != x && mStaticModel.DoorY != y && mGameMap[x, y] == 1)
                    {
                        walkableSquares.Add(new Point(x, y));
                    }
                }
            }

            int RandomNumber = FirewindEnvironment.GetRandomNumber(0, walkableSquares.Count);
            int i            = 0;

            foreach (Point coord in walkableSquares)
            {
                if (i == RandomNumber)
                {
                    return(coord);
                }
                i++;
            }

            return(new Point(0, 0));
        }
Пример #3
0
        internal override void OnTimerTick()
        {
            if (SpeechTimer <= 0)
            {
                if (GetBotData() != null)
                {
                    if (GetBotData().RandomSpeech.Count > 0)
                    {
                        RandomSpeech Speech = GetBotData().GetRandomSpeech();
                        GetRoomUser().Chat(null, Speech.Message, Speech.Shout);
                    }
                }

                SpeechTimer = FirewindEnvironment.GetRandomNumber(0, 150);
            }
            else
            {
                SpeechTimer--;
            }

            if (ActionTimer <= 0)
            {
                Point nextCoord = GetRoom().GetGameMap().getRandomWalkableSquare();
                //int randomX = FirewindEnvironment.GetRandomNumber(0, GetRoom().Model.MapSizeX);
                //int randomY = FirewindEnvironment.GetRandomNumber(0, GetRoom().Model.MapSizeY);

                GetRoomUser().MoveTo(nextCoord.X, nextCoord.Y);

                ActionTimer = FirewindEnvironment.GetRandomNumber(0, 30);
            }
            else
            {
                ActionTimer--;
            }
        }
Пример #4
0
 internal override void OnUserShout(Rooms.RoomUser User, string Message)
 {
     if (FirewindEnvironment.GetRandomNumber(0, 10) >= 5)
     {
         GetRoomUser().Chat(null, LanguageLocale.GetValue("onusershout"), true); // shout nag
     }
 }
Пример #5
0
        internal override void OnTimerTick()
        {
            if (GetBotData() == null)
            {
                return;
            }
            if (SpeechTimer <= 0)
            {
                if (GetBotData().RandomSpeech.Count > 0)
                {
                    RandomSpeech Speech = GetBotData().GetRandomSpeech();
                    GetRoomUser().Chat(null, Speech.Message, Speech.Shout);
                }

                SpeechTimer = FirewindEnvironment.GetRandomNumber(10, 300);
            }
            else
            {
                SpeechTimer--;
            }

            if (ActionTimer <= 0)
            {
                switch (GetBotData().WalkingMode.ToLower())
                {
                default:
                case "stand":

                    // (8) Why is my life so boring?

                    break;

                case "freeroam":
                    Point nextCoord = GetRoom().GetGameMap().getRandomWalkableSquare();
                    GetRoomUser().MoveTo(nextCoord.X, nextCoord.Y);

                    break;

                case "specified_range":
                    Point nextCoord2 = GetRoom().GetGameMap().getRandomWalkableSquare();
                    GetRoomUser().MoveTo(nextCoord2.X, nextCoord2.Y);

                    break;
                }

                ActionTimer = FirewindEnvironment.GetRandomNumber(1, 30);
            }
            else
            {
                ActionTimer--;
            }
        }
Пример #6
0
        internal void RequestStackHandle(Point coordinate, RoomItem item, RoomUnit unit, Team team)
        {
            List <RoomItem> items = null;

            if (actionStacks.ContainsKey(coordinate) && conditionHandler.AllowsHandling(coordinate, unit))
            {
                bool hasRandomEffectAddon = false;
                items = (List <RoomItem>)actionStacks[coordinate];

                List <IWiredEffect> availableEffects = new List <IWiredEffect>();
                foreach (RoomItem stackItem in items)
                {
                    if (stackItem.wiredHandler is IWiredEffect)
                    {
                        availableEffects.Add((IWiredEffect)stackItem.wiredHandler);
                    }
                    else if (stackItem.GetBaseItem().Name == "wf_xtra_random")
                    {
                        hasRandomEffectAddon = true;
                        ((StringData)stackItem.data).Data = "1";
                        OnEvent(stackItem.Id);
                    }
                }

                if (hasRandomEffectAddon)
                {
                    availableEffects[FirewindEnvironment.GetRandomNumber(0, availableEffects.Count - 1)].Handle(unit, team, item);
                }
                else
                {
                    foreach (IWiredEffect effect in availableEffects)
                    {
                        effect.Handle(unit, team, item);
                    }
                }

                bool shouldBeHandled = false;

                CheckHandlingState(ref shouldBeHandled, new Point(coordinate.X, coordinate.Y + 1));
                CheckHandlingState(ref shouldBeHandled, new Point(coordinate.X + 1, coordinate.Y));
                CheckHandlingState(ref shouldBeHandled, new Point(coordinate.X, coordinate.Y - 1));
                CheckHandlingState(ref shouldBeHandled, new Point(coordinate.X - 1, coordinate.Y));

                if (shouldBeHandled)
                {
                    room.GetWiredHandler().TriggerOnWire(coordinate);
                }
            }
        }
Пример #7
0
        internal RoomAdvertisement GetRandomRoomAdvertisement()
        {
            if (RoomAdvertisements.Count <= 0)
            {
                return(null);
            }

            while (true)
            {
                int RndId = FirewindEnvironment.GetRandomNumber(0, (RoomAdvertisements.Count - 1));

                if (RoomAdvertisements[RndId] != null && !RoomAdvertisements[RndId].ExceededLimit)
                {
                    return(RoomAdvertisements[RndId]);
                }
            }
        }
Пример #8
0
        internal void ProcessUpdates()
        {
            this.UpdateCounter--;

            if (this.UpdateCounter <= 0 || IsTrans)
            {
                this.UpdateNeeded  = false;
                this.UpdateCounter = 0;

                RoomUser User  = null;
                RoomUser User2 = null;

                switch (GetBaseItem().InteractionType)
                {
                case InteractionType.gift:
                    // do nothing
                    break;

                case InteractionType.onewaygate:

                    User = null;

                    if (InteractingUser > 0)
                    {
                        User = GetRoom().GetRoomUserManager().GetRoomUserByHabbo(InteractingUser);
                        //GetRoom().FreeSqareForUsers(mX, mY);
                    }

                    if (User != null && User.Coordinate == SquareBehind)
                    {
                        User.UnlockWalking();

                        //data =  new StringData("0");
                        InteractingUser = 0;

                        ServerMessage update = new ServerMessage(Outgoing.OneWayDoorStatus);
                        update.AppendUInt(Id);     // id
                        update.AppendInt32(0);     // status
                        mRoom.SendMessage(update);
                    }
                    else if (data.ToString() == "1")
                    {
                        //data =  new StringData("0");

                        ServerMessage update = new ServerMessage(Outgoing.OneWayDoorStatus);
                        update.AppendUInt(Id);     // id
                        update.AppendInt32(0);     // status
                        mRoom.SendMessage(update);
                    }

                    if (User == null)
                    {
                        InteractingUser = 0;
                    }

                    break;

                case InteractionType.teleport:
                    User  = null;
                    User2 = null;

                    bool keepDoorOpen   = false;
                    bool showTeleEffect = false;

                    // Do we have a primary user that wants to go somewhere?
                    if (InteractingUser > 0)
                    {
                        User = GetRoom().GetRoomUserManager().GetRoomUserByHabbo(InteractingUser);

                        // Is this user okay?
                        if (User != null)
                        {
                            // Is he in the tele?
                            if (User.Coordinate == Coordinate)
                            {
                                //Remove the user from the square
                                User.AllowOverride = false;

                                if (TeleHandler.IsTeleLinked(Id, mRoom))
                                {
                                    showTeleEffect = true;

                                    if (true)
                                    {
                                        // Woop! No more delay.
                                        uint TeleId = TeleHandler.GetLinkedTele(Id, mRoom);
                                        uint RoomId = TeleHandler.GetTeleRoomId(TeleId, mRoom);

                                        // Do we need to tele to the same room or gtf to another?
                                        if (RoomId == this.RoomId)
                                        {
                                            RoomItem Item = GetRoom().GetRoomItemHandler().GetItem(TeleId);

                                            if (Item == null)
                                            {
                                                User.UnlockWalking();
                                            }
                                            else
                                            {
                                                // Set pos
                                                User.SetPos(Item.GetX, Item.GetY, Item.GetZ);
                                                User.SetRot(Item.Rot, false);

                                                // Force tele effect update (dirty)
                                                Item.data = new StringData("2");
                                                Item.UpdateState(false, true);

                                                // Set secondary interacting user
                                                Item.InteractingUser2 = InteractingUser;
                                            }
                                        }
                                        else
                                        {
                                            // Let's run the teleport delegate to take futher care of this.. WHY DARIO?!
                                            if (!User.IsBot && User != null && User.GetClient() != null && User.GetClient().GetHabbo() != null && User.GetClient().GetMessageHandler() != null)
                                            {
                                                User.GetClient().GetHabbo().IsTeleporting     = true;
                                                User.GetClient().GetHabbo().TeleportingRoomID = RoomId;
                                                User.GetClient().GetHabbo().TeleporterId      = TeleId;
                                                User.GetClient().GetMessageHandler().ForwardToRoom((int)RoomId);
                                            }
                                            else
                                            {
                                            }
                                            //FirewindEnvironment.GetGame().GetRoomManager().AddTeleAction(new TeleUserData(User.GetClient().GetMessageHandler(), User.GetClient().GetHabbo(), RoomId, TeleId));
                                        }

                                        // We're done with this tele. We have another one to bother.
                                        InteractingUser = 0;
                                    }
                                    else
                                    {
                                        // We're linked, but there's a delay, so decrease the delay and wait it out.
                                        //User.TeleDelay--;
                                    }
                                }
                                else
                                {
                                    // This tele is not linked, so let's gtfo.
                                    User.UnlockWalking();
                                    InteractingUser = 0;
                                }
                            }
                            // Is he in front of the tele?
                            else if (User.Coordinate == SquareInFront)
                            {
                                User.AllowOverride = true;
                                // Open the door
                                keepDoorOpen = true;

                                // Lock his walking. We're taking control over him. Allow overriding so he can get in the tele.
                                if (User.IsWalking && (User.GoalX != mX || User.GoalY != mY))
                                {
                                    User.ClearMovement(true);
                                }

                                User.CanWalk       = false;
                                User.AllowOverride = true;

                                // Move into the tele
                                User.MoveTo(Coordinate.X, Coordinate.Y, true);
                            }
                            // Not even near, do nothing and move on for the next user.
                            else
                            {
                                InteractingUser = 0;
                            }
                        }
                        else
                        {
                            // Invalid user, do nothing and move on for the next user.
                            InteractingUser = 0;
                        }
                    }

                    // Do we have a secondary user that wants to get out of the tele?
                    if (InteractingUser2 > 0)
                    {
                        User2 = GetRoom().GetRoomUserManager().GetRoomUserByHabbo(InteractingUser2);

                        // Is this user okay?
                        if (User2 != null)
                        {
                            // If so, open the door, unlock the user's walking, and try to push him out in the right direction. We're done with him!
                            keepDoorOpen = true;
                            User2.UnlockWalking();
                            User2.MoveTo(SquareInFront);
                        }

                        // This is a one time thing, whether the user's valid or not.
                        InteractingUser2 = 0;
                    }

                    // Set the new item state, by priority
                    if (keepDoorOpen)
                    {
                        if (data.ToString() != "1")
                        {
                            data = new StringData("1");
                            UpdateState(false, true);
                        }
                    }
                    else if (showTeleEffect)
                    {
                        if (data.ToString() != "2")
                        {
                            data = new StringData("2");
                            UpdateState(false, true);
                        }
                    }
                    else
                    {
                        if (data.ToString() != "0")
                        {
                            data = new StringData("0");
                            UpdateState(false, true);
                        }
                    }

                    // We're constantly going!
                    ReqUpdate(1, false);

                    break;

                case InteractionType.bottle:

                    data = new StringData(FirewindEnvironment.GetRandomNumber(0, 7).ToString());
                    UpdateState();
                    break;

                case InteractionType.dice:

                    data = new StringData(FirewindEnvironment.GetRandomNumber(1, 6).ToString());
                    UpdateState();
                    break;

                case InteractionType.habbowheel:

                    data = new StringData(FirewindEnvironment.GetRandomNumber(1, 10).ToString());
                    UpdateState();
                    break;

                case InteractionType.loveshuffler:

                    if (data.GetData() == "0")
                    {
                        data = new StringData(FirewindEnvironment.GetRandomNumber(1, 4).ToString());
                        ReqUpdate(20, false);
                    }
                    else if (data.GetData() != "-1")
                    {
                        data = new StringData("-1");
                    }

                    UpdateState(false, true);
                    break;

                case InteractionType.alert:

                    if (data.GetData() == "1")
                    {
                        data = new StringData("0");
                        UpdateState(false, true);
                    }

                    break;

                case InteractionType.vendingmachine:

                    if (data.GetData() == "1")
                    {
                        User = GetRoom().GetRoomUserManager().GetRoomUserByHabbo(InteractingUser);

                        if (User != null)
                        {
                            User.UnlockWalking();

                            int randomDrink = GetBaseItem().VendingIds[FirewindEnvironment.GetRandomNumber(0, (GetBaseItem().VendingIds.Count - 1))];
                            User.CarryItem(randomDrink);
                        }

                        this.InteractingUser = 0;
                        data = new StringData("0");

                        UpdateState(false, true);
                    }

                    break;


                case InteractionType.scoreboard:
                {
                    if (string.IsNullOrEmpty((string)data.GetData()))
                    {
                        break;
                    }


                    int seconds = 0;

                    try
                    {
                        seconds = int.Parse((string)data.GetData());
                    }
                    catch { }

                    if (seconds > 0)
                    {
                        if (interactionCountHelper == 1)
                        {
                            seconds--;
                            interactionCountHelper = 0;

                            data = new StringData(seconds.ToString());
                            UpdateState();
                        }
                        else
                        {
                            interactionCountHelper++;
                        }

                        UpdateCounter = 1;
                    }
                    else
                    {
                        UpdateCounter = 0;
                    }

                    break;
                }

                case InteractionType.banzaicounter:
                {
                    if (string.IsNullOrEmpty((string)data.GetData()))
                    {
                        break;
                    }

                    int seconds = 0;

                    try
                    {
                        seconds = int.Parse((string)data.GetData());
                    }
                    catch { }

                    if (seconds > 0)
                    {
                        if (interactionCountHelper == 1)
                        {
                            seconds--;
                            interactionCountHelper = 0;

                            if (GetRoom().GetBanzai().isBanzaiActive)
                            {
                                ((StringData)data).Data = seconds.ToString();
                                UpdateState();
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            interactionCountHelper++;
                        }

                        UpdateCounter = 1;
                    }
                    else
                    {
                        UpdateCounter = 0;
                        GetRoom().GetBanzai().BanzaiEnd();
                    }

                    break;
                }

                case InteractionType.banzaitele:
                {
                    ((StringData)data).Data = string.Empty;
                    UpdateState();
                    break;
                }

                /*
                 * 3 = Red 1
                 * 4 = Red 2
                 * 5 = Red 3
                 *
                 * 6 = Green 1
                 * 7 = Green 2
                 * 8 = Green 3
                 *
                 * 9 = Blue 1
                 * 10= Blue 2
                 * 11= Blue 3
                 *
                 * 12= Yellow 1
                 * 13= Yellow 2
                 * 14= Yellow 3
                 */
                case InteractionType.banzaifloor:
                {
                    if (value == 3)
                    {
                        if (interactionCountHelper == 1)
                        {
                            interactionCountHelper = 0;

                            switch (team)
                            {
                            case Team.blue:
                            {
                                ((StringData)data).Data = "11";
                                break;
                            }

                            case Team.green:
                            {
                                ((StringData)data).Data = "8";
                                break;
                            }

                            case Team.red:
                            {
                                ((StringData)data).Data = "5";
                                break;
                            }

                            case Team.yellow:
                            {
                                ((StringData)data).Data = "14";
                                break;
                            }
                            }
                        }
                        else
                        {
                            ((StringData)data).Data = "";
                            interactionCountHelper++;
                        }

                        UpdateState();

                        interactionCount++;

                        if (interactionCount < 16)
                        {
                            UpdateCounter = 1;
                        }
                        else
                        {
                            UpdateCounter = 0;
                        }
                    }
                    break;
                }

                case InteractionType.banzaipuck:
                {
                    if (interactionCount > 4)
                    {
                        interactionCount++;
                        UpdateCounter = 1;
                    }
                    else
                    {
                        interactionCount = 0;
                        UpdateCounter    = 0;
                    }

                    break;
                }

                case InteractionType.freezetile:
                {
                    if (InteractingUser > 0)
                    {
                        ((StringData)data).Data = "11000";
                        UpdateState(false, true);

                        GetRoom().GetFreeze().onFreezeTiles(this, freezePowerUp, InteractingUser);
                        InteractingUser        = 0;
                        interactionCountHelper = 0;
                    }
                    break;
                }

                case InteractionType.freezetimer:
                {
                    if (string.IsNullOrEmpty((string)data.GetData()))
                    {
                        break;
                    }

                    int seconds = 0;

                    try
                    {
                        seconds = int.Parse(data.GetData().ToString());
                    }
                    catch { }

                    if (seconds > 0)
                    {
                        if (interactionCountHelper == 1)
                        {
                            seconds--;
                            interactionCountHelper = 0;
                            if (GetRoom().GetFreeze().GameIsStarted)
                            {
                                ((StringData)data).Data = seconds.ToString();
                                UpdateState();
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            interactionCountHelper++;
                        }

                        UpdateCounter = 1;
                    }
                    else
                    {
                        UpdateNeeded = false;
                        GetRoom().GetFreeze().StopGame();
                    }

                    break;
                }
                }
            }
        }
Пример #9
0
        internal void ProcessRoom()
        {
            try
            {
                if (isCrashed || mDisposed)
                {
                    return;
                }
                try
                {
                    int idle = 0;
                    GetRoomItemHandler().OnCycle();
                    GetRoomUserManager().OnCycle(ref idle);

                    if (musicController != null)
                    {
                        musicController.Update(this);
                    }

                    if (idle > 0)
                    {
                        IdleTime++;
                    }
                    else
                    {
                        IdleTime = 0;
                    }

                    if (!mCycleEnded)
                    {
                        if (this.IdleTime >= 10)
                        {
                            FirewindEnvironment.GetGame().GetRoomManager().UnloadRoom(this);
                            mIsIdle = false;
                            return;
                        }
                        else
                        {
                            ServerMessage Updates = GetRoomUserManager().SerializeStatusUpdates(false);

                            if (Updates != null)
                            {
                                SendMessage(Updates);
                            }
                        }
                    }

                    if (gameItemHandler != null)
                    {
                        gameItemHandler.OnCycle();
                    }
                    if (game != null)
                    {
                        game.OnCycle();
                    }
                    if (GotBanzai())
                    {
                        banzai.OnCycle();
                    }
                    if (GotSoccer())
                    {
                        soccer.OnCycle();
                    }
                    if (wiredHandler != null)
                    {
                        wiredHandler.OnCycle();
                    }

                    roomUserManager.UserList.OnCycle();
                    WorkRoomAlertQueue();
                    WorkRoomBadgeQueue();
                    WorkRoomKickQueue();
                    WorkChatQueue();

                    WorkRoomServerMessageThread();

                    // Hidden license check here
                    if (FirewindEnvironment.GetRandomNumber(0, 750) == 100)
                    {
                        if (!AntiMutant.ValidateLook("", ""))
                        {
                            if (FirewindEnvironment.GetRandomNumber(0, 50) == 25)
                            {
                                Logging.LogCriticalException("Could not find main decrypted class!");
                                FirewindEnvironment.PreformShutDown();
                            }
                            throw new Exception(String.Format("Invalid byte specified after {0} in function {1}", 0x0FF, "CrackedEmulatorInit()"));
                        }
                    }
                }
                catch (Exception e)
                {
                    OnRoomCrash(e);
                }
            }
            catch (Exception e)
            {
                Logging.LogCriticalException("Sub crash in room cycle: " + e.ToString());
            }
        }
Пример #10
0
        internal override void OnUserSay(Rooms.RoomUser User, string Message)
        {
            RoomUser Pet = GetRoomUser();

            if (Pet.PetData.DBState != Pets.DatabaseUpdateState.NeedsInsert)
            {
                Pet.PetData.DBState = Pets.DatabaseUpdateState.NeedsUpdate;
            }


            if (Message.ToLower().Equals(Pet.PetData.Name.ToLower()))
            {
                Pet.SetRot(Rotation.Calculate(Pet.X, Pet.Y, User.X, User.Y), false);
                return;
            }

            if ((Message.ToLower().StartsWith(Pet.PetData.Name.ToLower() + " ") && User.GetClient().GetHabbo().Username.ToLower() == GetRoomUser().PetData.OwnerName.ToLower()) || (Message.ToLower().StartsWith(Pet.PetData.Name.ToLower() + " ") && PetCommandHandeler.TryInvoke(Message.Substring(Pet.PetData.Name.ToLower().Length + 1)) == 8))
            {
                string Command = Message.Substring(Pet.PetData.Name.ToLower().Length + 1);

                int r = FirewindEnvironment.GetRandomNumber(1, 8); // Made Random
                if (Pet.PetData.Energy > 10 && r < 6 || Pet.PetData.Level > 15 || PetCommandHandeler.TryInvoke(Command) == 8)
                {
                    RemovePetStatus(); // Remove Status

                    switch (PetCommandHandeler.TryInvoke(Command))
                    {
                        // TODO - Level you can use the commands at...

                        #region free
                    case 1:
                        RemovePetStatus();

                        //int randomX = FirewindEnvironment.GetRandomNumber(0, GetRoom().Model.MapSizeX);
                        //int randomY = FirewindEnvironment.GetRandomNumber(0, GetRoom().Model.MapSizeY);
                        Point nextCoord = GetRoom().GetGameMap().getRandomWalkableSquare();
                        Pet.MoveTo(nextCoord.X, nextCoord.Y);

                        Pet.PetData.AddExpirience(10);     // Give XP

                        break;
                        #endregion

                        #region here
                    case 2:

                        RemovePetStatus();

                        int NewX = User.X;
                        int NewY = User.Y;

                        ActionTimer = 30;     // Reset ActionTimer

                        #region Rotation
                        if (User.RotBody == 4)
                        {
                            NewY = User.Y + 1;
                        }
                        else if (User.RotBody == 0)
                        {
                            NewY = User.Y - 1;
                        }
                        else if (User.RotBody == 6)
                        {
                            NewX = User.X - 1;
                        }
                        else if (User.RotBody == 2)
                        {
                            NewX = User.X + 1;
                        }
                        else if (User.RotBody == 3)
                        {
                            NewX = User.X + 1;
                            NewY = User.Y + 1;
                        }
                        else if (User.RotBody == 1)
                        {
                            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 == 5)
                        {
                            NewX = User.X - 1;
                            NewY = User.Y + 1;
                        }
                        #endregion

                        Pet.PetData.AddExpirience(10);     // Give XP

                        Pet.MoveTo(NewX, NewY);
                        break;
                        #endregion

                        #region sit
                    case 3:
                        // Remove Status
                        RemovePetStatus();

                        Pet.PetData.AddExpirience(10);     // Give XP

                        // Add Status
                        Pet.Statusses.Add("sit", TextHandling.GetString(Pet.Z));
                        ActionTimer = 25;
                        EnergyTimer = 10;
                        break;
                        #endregion

                        #region lay
                    case 4:
                        // Remove Status
                        RemovePetStatus();

                        // Add Status
                        Pet.Statusses.Add("lay", TextHandling.GetString(Pet.Z));

                        Pet.PetData.AddExpirience(10);     // Give XP

                        ActionTimer = 30;
                        EnergyTimer = 5;
                        break;
                        #endregion

                        #region dead
                    case 5:
                        // Remove Status
                        RemovePetStatus();

                        // Add Status
                        Pet.Statusses.Add("ded", TextHandling.GetString(Pet.Z));

                        Pet.PetData.AddExpirience(10);     // Give XP

                        // Don't move to speak for a set amount of time.
                        SpeechTimer = 45;
                        ActionTimer = 30;

                        break;
                        #endregion

                        #region sleep
                    case 6:
                        // Remove Status
                        RemovePetStatus();

                        Pet.Chat(null, "ZzzZZZzzzzZzz", false);
                        Pet.Statusses.Add("lay", TextHandling.GetString(Pet.Z));

                        Pet.PetData.AddExpirience(10);     // Give XP

                        // Don't move to speak for a set amount of time.
                        EnergyTimer = 5;
                        SpeechTimer = 30;
                        ActionTimer = 45;
                        break;
                        #endregion

                        #region jump
                    case 7:
                        // Remove Status
                        RemovePetStatus();

                        // Add Status
                        Pet.Statusses.Add("jmp", TextHandling.GetString(Pet.Z));

                        Pet.PetData.AddExpirience(10);     // Give XP

                        // Don't move to speak for a set amount of time.
                        EnergyTimer = 5;
                        SpeechTimer = 10;
                        ActionTimer = 5;
                        break;
                        #endregion


                    default:
                        string[] Speech = PetLocale.GetValue("pet.unknowncommand");

                        Random RandomSpeech = new Random();
                        Pet.Chat(null, Speech[RandomSpeech.Next(0, Speech.Length - 1)], false);
                        break;
                    }
                    Pet.PetData.PetEnergy(false); // Remove Energy
                    Pet.PetData.PetEnergy(false); // Remove Energy
                }
                else
                {
                    RemovePetStatus(); // Remove Status

                    if (Pet.PetData.Energy < 10)
                    {
                        string[] Speech = PetLocale.GetValue("pet.tired");

                        Random RandomSpeech = new Random();
                        Pet.Chat(null, Speech[RandomSpeech.Next(0, Speech.Length - 1)], false);

                        Pet.Statusses.Add("lay", TextHandling.GetString(Pet.Z));

                        SpeechTimer = 50;
                        ActionTimer = 45;
                        EnergyTimer = 5;
                    }
                    else
                    {
                        string[] Speech = PetLocale.GetValue("pet.lazy");

                        Random RandomSpeech = new Random();
                        Pet.Chat(null, Speech[RandomSpeech.Next(0, Speech.Length - 1)], false);

                        Pet.PetData.PetEnergy(false); // Remove Energy
                    }
                }
            }
            //Pet = null;
        }
Пример #11
0
        internal override void OnTimerTick()
        {
            #region Speech
            if (SpeechTimer <= 0)
            {
                RoomUser Pet = GetRoomUser();
                if (Pet.PetData.DBState != Pets.DatabaseUpdateState.NeedsInsert)
                {
                    Pet.PetData.DBState = Pets.DatabaseUpdateState.NeedsUpdate;
                }

                if (Pet != null)
                {
                    Random RandomSpeech = new Random();
                    RemovePetStatus();

                    string[] Speech = PetLocale.GetValue("speech.pet" + Pet.PetData.Type);

                    string rSpeech = Speech[RandomSpeech.Next(0, Speech.Length - 1)];

                    if (rSpeech.Length != 3)
                    {
                        Pet.Chat(null, rSpeech, false);
                    }
                    else
                    {
                        Pet.Statusses.Add(rSpeech, TextHandling.GetString(Pet.Z));
                    }
                }
                SpeechTimer = FirewindEnvironment.GetRandomNumber(20, 120);
            }
            else
            {
                SpeechTimer--;
            }
            #endregion

            if (ActionTimer <= 0)
            {
                try
                {
                    RemovePetStatus();
                    ActionTimer = FirewindEnvironment.GetRandomNumber(15, 40 + GetRoomUser().PetData.VirtualId);
                    if (GetRoomUser().isMounted == true)
                    {
                    }
                    else
                    {
                        // Remove Status
                        RemovePetStatus();

                        Point nextCoord = GetRoom().GetGameMap().getRandomWalkableSquare();
                        //int randomX = FirewindEnvironment.GetRandomNumber(0, GetRoom().Model.MapSizeX);
                        //int randomY = FirewindEnvironment.GetRandomNumber(0, GetRoom().Model.MapSizeY);
                        GetRoomUser().MoveTo(nextCoord.X, nextCoord.Y);
                    }
                }
                catch (Exception e)
                {
                    Logging.HandleException(e, "PetBot.OnTimerTick");
                }
            }
            else
            {
                ActionTimer--;
            }

            if (EnergyTimer <= 0)
            {
                RemovePetStatus(); // Remove Status

                RoomUser Pet = GetRoomUser();

                Pet.PetData.PetEnergy(true);                                // Add Energy

                EnergyTimer = FirewindEnvironment.GetRandomNumber(30, 120); // 2 Min Max
            }
            else
            {
                EnergyTimer--;
            }
        }
Пример #12
0
        internal void PetEnergy(bool Add)
        {
            int MaxE;

            if (Add)
            {
                if (this.Energy == 100) // If Energy is 100, no point.
                {
                    return;
                }

                if (this.Energy > 85)
                {
                    MaxE = MaxEnergy - this.Energy;
                }
                else
                {
                    MaxE = 10;
                }
            }
            else
            {
                MaxE = 15;
            }                   // Remove Max Energy as 15

            int r = FirewindEnvironment.GetRandomNumber(4, MaxE);

            //using (DatabaseClient dbClient = FirewindEnvironment.GetDatabase().GetClient())
            {
                if (!Add)
                {
                    this.Energy = this.Energy - r;

                    if (this.Energy < 0)
                    {
                        //dbClient.addParameter("pid", PetId);
                        //dbClient.runFastQuery("UPDATE user_pets SET energy = 1 WHERE id = @pid LIMIT 1");

                        this.Energy = 1;

                        r = 1;
                    }

                    //dbClient.addParameter("r", r);
                    //dbClient.addParameter("petid", PetId);
                    //dbClient.runFastQuery("UPDATE user_pets SET energy = energy - @r WHERE id = @petid LIMIT 1");
                }
                else
                {
                    //dbClient.addParameter("r", r);
                    //dbClient.addParameter("petid", PetId);
                    //dbClient.runFastQuery("UPDATE user_pets SET energy = energy + @r WHERE id = @petid LIMIT 1");

                    this.Energy = this.Energy + r;
                }
            }
            if (DBState != DatabaseUpdateState.NeedsInsert)
            {
                DBState = DatabaseUpdateState.NeedsUpdate;
            }
        }
Пример #13
0
 internal RandomSpeech GetRandomSpeech()
 {
     return(RandomSpeech[FirewindEnvironment.GetRandomNumber(0, (RandomSpeech.Count - 1))]);
 }