using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using Blizzard.HabboHotel.Rooms; using Blizzard.HabboHotel.Items; using Blizzard.HabboHotel.Users; namespace Blizzard.HabboHotel.Wired { class WiredEffects { internal Habbo User; internal RoomItem Item; internal RoomItem ItemToUse; internal RoomItem WiredToUse; internal string WiredStringToUse; internal WiredEffects(RoomItem sItem, Habbo sUser) { User = sUser; Item = sItem; ItemToUse = null; WiredStringToUse = ""; } internal void DoWiredEffects() { try { // Time to wired :O! if (Item.GetBaseItem().Name == "wf_act_show_message") { // Wired Effect: Shows Message To User if (Item.WiredString != "") User.WhispToMe(Item.WiredString); // Send Message to me! } else if (Item.GetBaseItem().Name == "wf_act_teleport_to") { // Wired Effect: Teleport User To if (Item.WiredItems.Count > 0) { Dictionary Pos = new Dictionary(); foreach (int i in Item.WiredItems) { Pos.Add((Pos.Count + 1), RoomItem.RegisteredItems[i]); } RoomItem sItem = Pos[(new Random()).Next(1, Item.WiredItems.Count)]; // Random Item if we have more than one, else onlye Next(1, 1) = 1! ItemToUse = sItem; // To Thread Thread Move = new Thread(new ThreadStart(GoTeleport)); // Init new thread (If you don't, you can't walk :(!) Move.Start(); // Go! StaticGame.WiredMoveSystem.Add(User.Id, Move); // Add to Remove later... } } else if (Item.GetBaseItem().Name == "wf_act_toggle_state") { if (Item.WiredItems.Count > 0) { List Items = new List(); foreach (int i in Item.WiredItems) { Items.Add(RoomItem.RegisteredItems[i]); } foreach (RoomItem sItem in Items) { if (!StaticGame.WiredUpdateItemsSystem.ContainsKey(sItem.Id)) { ItemToUse = sItem; WiredStringToUse = Item.WiredString; Thread Update = new Thread(new ThreadStart(UpdateItems)); StaticGame.WiredUpdateItemsSystem.Add(sItem.Id, Update); Update.Start(); } } } } else if (Item.GetBaseItem().Name.Contains("wf_act_move_rotate")) { if (Item.WiredItems.Count > 0) { List Items = new List(); foreach (int i in Item.WiredItems) { Items.Add(RoomItem.RegisteredItems[i]); } foreach (RoomItem sItem in Items) { if (!StaticGame.WiredMoveItemsSystem.ContainsKey(sItem.Id)) { ItemToUse = sItem; WiredToUse = Item; WiredStringToUse = Item.WiredString; Thread Move = new Thread(new ThreadStart(MoveItems)); StaticGame.WiredMoveItemsSystem.Add(sItem.Id, Move); Move.Start(); } } } } } catch (Exception e) { BlizzardSystem.WriteLine("Wired Exception: " + e.ToString()); } } internal void UpdateItems() { try { RoomItem Item = ItemToUse; Room R = StaticGame.VirtualRooms[User.CurrentRoomId]; Thread Move = StaticGame.WiredUpdateItemsSystem[Item.Id]; // Call thread if (WiredStringToUse != "") Thread.Sleep(int.Parse(WiredStringToUse)); if (Item.ExtraData == "") Item.ExtraData = "0"; if (Item.ExtraData == "0") Item.ExtraData = "1"; else if (Item.ExtraData == "1") Item.ExtraData = "0"; Item.UpdateState(User); StaticGame.WiredUpdateItemsSystem.Remove(Item.Id); // Remove from dictionary! Thread.Sleep(1500); // Let it sleeping a lot :O //Move.Abort(); } catch (Exception e) { } } internal void MoveItems() { try { RoomItem Item = ItemToUse; RoomItem sItem = WiredToUse; Room R = StaticGame.VirtualRooms[User.CurrentRoomId]; Thread Move = StaticGame.WiredMoveItemsSystem[Item.Id]; // Call thread if (WiredStringToUse.Contains("|")) { string[] Separe = WiredStringToUse.Split('|'); int sMove = int.Parse(Separe[0]); int Rotate = int.Parse(Separe[1]); int Time = int.Parse(Separe[2]); Thread.Sleep(Time); // ...and wait 3 seconds Dictionary Coords = new Dictionary(); #region Coords if (sMove != 0) { // 0 = no move // 4 = To right (derecha) // 5 = To behind (detras) // 6 = To left (izquierda) // 7 = To Front (delante) // 2 = Adelante/atras (5/7) // 3 = Izquierda/derecha (4/6) // 1 = Random (4,5,6,7) if (sMove == 4) Coords.Add((Coords.Count + 1), Item.SquareDer2); else if(sMove == 5) Coords.Add((Coords.Count + 1), Item.SquareBehind2); else if(sMove == 6) Coords.Add((Coords.Count + 1), Item.SquareIzq2); else if(sMove == 7) Coords.Add((Coords.Count + 1), Item.SquareInFront2); else if (sMove == 2) { Coords.Add((Coords.Count + 1), Item.SquareBehind2); Coords.Add((Coords.Count + 1), Item.SquareInFront2); } else if (sMove == 3) { Coords.Add((Coords.Count + 1), Item.SquareDer2); Coords.Add((Coords.Count + 1), Item.SquareIzq2); } else if (sMove == 1) { Coords.Add((Coords.Count + 1), Item.SquareBehind2); Coords.Add((Coords.Count + 1), Item.SquareInFront2); Coords.Add((Coords.Count + 1), Item.SquareDer2); Coords.Add((Coords.Count + 1), Item.SquareIzq2); } else { return; } Coord C = Coords[(new Random()).Next(1, Coords.Count)]; R.MoveItemToXY(Item, C.X, C.Y, Item.Rot, sItem.Id); } #endregion #region Rotates if (Rotate != 0) { Dictionary Rotations = new Dictionary(); if (Rotate == 1) Rotations.Add((Rotations.Count + 1), 0); else if (Rotate == 2) Rotations.Add((Rotations.Count + 1), 1); else if (Rotate == 3) { Rotations.Add((Rotations.Count + 1), 0); Rotations.Add((Rotations.Count + 1), 1); } int Rotationz = Rotations[(new Random()).Next(1, Rotations.Count)]; int Rot; if (Rotationz == 0) { if (Item.Rot == 6) Rot = 0; else if (Item.Rot == 4) Rot = 6; else if (Item.Rot == 2) Rot = 4; else Rot = 2; } else { if (Item.Rot == 6) Rot = 4; else if (Item.Rot == 4) Rot = 2; else if (Item.Rot == 2) Rot = 0; else Rot = 6; } R.MoveItemToXY(Item, Item.X, Item.Y, Rot); } #endregion } StaticGame.WiredMoveItemsSystem.Remove(Item.Id); // Remove from dictionary! Thread.Sleep(1500); // Let it sleeping a lot :O //Move.Abort(); // Remove Thread } catch (Exception e) { BlizzardSystem.WriteLine("Wired Exception: " + e.ToString()); } } internal void GoTeleport() { try { Thread Move = StaticGame.WiredMoveSystem[User.Id]; // Call thread int CurrentEffect = User.CurrentEffect; // Save Effect (new EffectsInventory()).ShowEffect(User, 4); // Apply Effect... Thread.Sleep(2100); // ...and wait 3 seconds User.IsWalking = false; // stop walk User.SetPos(ItemToUse.X, ItemToUse.Y, ""); // save new pos (new EffectsInventory()).ShowEffect(User, CurrentEffect); // return Effect StaticGame.WiredMoveSystem.Remove(User.Id); // Remove from dictionary! //Move.Abort(); // Remove Thread } catch (Exception e) { BlizzardSystem.WriteLine("Wired Exception: " + e.ToString()); } } } }