Exemplo n.º 1
0
        public void OnTrigger(GameClients.GameClient Session, RoomItem Item, int Request, bool HasRights)
        {
            if (Item == null || Item.GetRoom() == null || Session == null || Session.GetHabbo() == null)
                return;
            RoomUser User = Item.GetRoom().GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            User.LastInteraction = SilverwaveEnvironment.GetUnixTimestamp();
            if (User == null)
            {
                return;
            }

            if ((User.LastInteraction - SilverwaveEnvironment.GetUnixTimestamp() < 0) && User.InteractingGate && User.GateId == Item.Id)
            {
                User.InteractingGate = false;
                User.GateId = 0;
            }

            if (!User.InteractingGate && User.GateId != Item.Id && Item.TollPrice > 0)
            {
                if (Session.GetHabbo().Credits < Item.TollPrice)
                {
                    Session.SendNotif("You have not got enough credits to get through this gate.\n" +
                        "You need atleast " + Item.TollPrice + " to get through this gate");
                    return;
                }
                Session.SendWhisper("This gate has a toll of " + Item.TollPrice + " credits.");
                Session.SendWhisper("To continue through it, double click again!");
                User.InteractingGate = true;
                User.GateId = Item.Id;
                User.LastInteraction = SilverwaveEnvironment.GetUnixTimestamp() + 7;
                return;
            }

            // Alright. But is this user in the right position?
            if (User.Coordinate == Item.Coordinate || User.Coordinate == Item.SquareInFront)
            {
                // Fine. But is this tele even free?
                if (Item.InteractingUser != 0)
                {
                    return;
                }

                if (!User.CanWalk || Session.GetHabbo().IsTeleporting || Session.GetHabbo().TeleporterId != 0 || (User.LastInteraction + 2) - SilverwaveEnvironment.GetUnixTimestamp() < 0)
                    return;

                if (Item.TollPrice > 0 && Session.GetHabbo().Credits > Item.TollPrice)
                {
                    Habbo Data = SilverwaveEnvironment.getHabboForId(Convert.ToUInt32(Item.GetRoom().OwnerId));
                    if (Data != null)
                    {
                        using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor())
                        {
                            dbClient.setQuery("SELECT online FROM users WHERE id=" + Data.Id + " LIMIT 1");
                            string online = dbClient.getString();
                            if (online == "0")
                            {
                                dbClient.runFastQuery("UPDATE users SET credits = credits+" + Item.TollPrice + " WHERE id=" + Data.Id + " LIMIT 1");
                            }
                            else if (online == "1")
                            {
                                GameClient H = SilverwaveEnvironment.GetGame().GetClientManager().GetClientByUserID(Data.Id);
                                H.GetHabbo().Credits += Item.TollPrice;
                                H.GetHabbo().UpdateCreditsBalance();
                            }
                            else
                            {
                                Session.SendWhisper("An error occured!");
                                return;
                            }
                        }
                    }
                    Session.GetHabbo().Credits -= Item.TollPrice;
                    Session.GetHabbo().UpdateCreditsBalance();
                }
                else if (Session.GetHabbo().Credits < Item.TollPrice)
                {
                    User.InteractingGate = false;
                    User.GateId = 0;
                    return;
                }

                User.TeleDelay = 2;
                Item.InteractingUser = User.GetClient().GetHabbo().Id;

            }
            else if (User.CanWalk)
            {
                User.MoveTo(Item.SquareInFront);
            }
        }
Exemplo n.º 2
0
        public void OnTrigger(GameClients.GameClient Session, RoomItem Item, int Request, bool HasRights)
        {
            if (Session == null)
                return;
            RoomUser User = Item.GetRoom().GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);

            if (Item.InteractingUser2 != User.userID)
                Item.InteractingUser2 = User.userID;

            if (User == null)
            {
                return;
            }

            if (User.Coordinate != Item.SquareInFront && User.CanWalk)
            {
                User.MoveTo(Item.SquareInFront);
                return;
            }
            if (!Item.GetRoom().GetGameMap().ValidTile(Item.SquareBehind.X, Item.SquareBehind.Y) || !Item.GetRoom().GetGameMap().CanWalk(Item.SquareBehind.X, Item.SquareBehind.Y, false)
                || !Item.GetRoom().GetGameMap().SquareIsOpen(Item.SquareBehind.X, Item.SquareBehind.Y, false))
            {
                return;
            }

            if ((User.LastInteraction - SilverwaveEnvironment.GetUnixTimestamp() < 0) && User.InteractingGate && User.GateId == Item.Id)
            {
                User.InteractingGate = false;
                User.GateId = 0;
            }

            if (!User.InteractingGate && User.GateId != Item.Id && Item.TollPrice > 0)
            {
                if (Session.GetHabbo().Credits < Item.TollPrice)
                {
                    Session.SendNotif("You have not got enough credits to get through this gate.\n" +
                        "You need atleast " + Item.TollPrice + " to get through this gate");
                    return;
                }
                Session.SendWhisper("This gate has a toll of " + Item.TollPrice + " credits.");
                Session.SendWhisper("To continue through it, double click again!");
                User.InteractingGate = true;
                User.GateId = Item.Id;
                User.LastInteraction = SilverwaveEnvironment.GetUnixTimestamp() + 7;
                return;
            }

            if (!Item.GetRoom().GetGameMap().CanWalk(Item.SquareBehind.X, Item.SquareBehind.Y, User.AllowOverride))
            {
                return;
            }

            if (Item.InteractingUser == 0)
            {
                User.InteractingGate = true;
                User.GateId = Item.Id;
                Item.InteractingUser = User.HabboId;

                User.CanWalk = false;

                if (User.IsWalking && (User.GoalX != Item.SquareInFront.X || User.GoalY != Item.SquareInFront.Y))
                {
                    User.ClearMovement(true);
                }

                if (Item.TollPrice > 0 && Session.GetHabbo().Credits > Item.TollPrice)
                {
                    Habbo Data = SilverwaveEnvironment.getHabboForId(Convert.ToUInt32(Item.GetRoom().OwnerId));
                    if (Data != null)
                    {
                        using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor())
                        {
                            dbClient.setQuery("SELECT online FROM users WHERE id=" + Data.Id + " LIMIT 1");
                            string online = dbClient.getString();
                            if (online == "0")
                            {
                                dbClient.runFastQuery("UPDATE users SET credits = credits+" + Item.TollPrice + " WHERE id=" + Data.Id + " LIMIT 1");
                            }
                            else if (online == "1")
                            {
                                GameClient H = SilverwaveEnvironment.GetGame().GetClientManager().GetClientByUserID(Data.Id);
                                H.GetHabbo().Credits += Item.TollPrice;
                                H.GetHabbo().UpdateCreditsBalance();
                            }
                            else
                            {
                                Session.SendWhisper("An error occured!");
                                return;
                            }
                        }
                    }
                    Session.GetHabbo().Credits -= Item.TollPrice;
                    Session.GetHabbo().UpdateCreditsBalance();
                }
                else if (Session.GetHabbo().Credits < Item.TollPrice)
                {
                    User.InteractingGate = false;
                    User.GateId = 0;
                    return;
                }

                User.AllowOverride = true;
                User.MoveTo(Item.Coordinate);

                Item.ReqUpdate(4, true);
            }
        }