//internal void Serialize(ServerMessage Message) //{ // Message.AppendUInt(Id); // Message.AppendInt32(0); // if (mBaseItem == null) // Logging.LogException("Unknown base: " + BaseItem); // Message.AppendString(mBaseItem.Type.ToString().ToUpper()); // Message.AppendUInt(Id); // Message.AppendInt32(mBaseItem.SpriteId); // if (mBaseItem.Name.Contains("a2")) // Message.AppendInt32(3); // else if (mBaseItem.Name.Contains("wallpaper")) // Message.AppendInt32(2); // else if (mBaseItem.Name.Contains("landscape")) // Message.AppendInt32(4); // else // Message.AppendInt32(0); // Message.AppendString(ExtraData); // Message.AppendBoolean(mBaseItem.AllowRecycle); // Message.AppendBoolean(mBaseItem.AllowTrade); // Message.AppendBoolean(mBaseItem.AllowInventoryStack); // Message.AppendBoolean(Marketplace.CanSellItem(this)); // Message.AppendInt32(-1); // if (mBaseItem.Type == 's') // { // Message.AppendString(""); // Message.AppendInt32(-1); // } //} internal void SerializeWall(ServerMessage Message, Boolean Inventory) { Message.AppendUInt(Id); Message.AppendString(mBaseItem.Type.ToString().ToUpper()); Message.AppendUInt(Id); Message.AppendInt32(GetBaseItem().SpriteId); if (GetBaseItem().Name.Contains("floor")) { Message.AppendInt32(3); } else if (GetBaseItem().Name.Contains("wallpaper")) { Message.AppendInt32(2); } else if (GetBaseItem().Name.Contains("landscape")) { Message.AppendInt32(4); } else { Message.AppendInt32(1); } int result = 0; //if (this.GetBaseItem().InteractionType == InteractionType.gift && ExtraData.Contains(Convert.ToChar(5).ToString())) //{ // int color = int.Parse(ExtraData.Split((char)5)[1]); // int lazo = int.Parse(ExtraData.Split((char)5)[2]); // result = color * 1000 + lazo; //} Message.AppendInt32(result); Message.AppendString(Data.ToString()); Message.AppendBoolean(GetBaseItem().AllowRecycle); Message.AppendBoolean(GetBaseItem().AllowTrade); Message.AppendBoolean(GetBaseItem().AllowInventoryStack); Message.AppendBoolean(Marketplace.CanSellItem(this)); Message.AppendInt32(-1); }
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; } } } }
internal UserItem AddNewItem(UInt32 Id, UInt32 BaseItem, IRoomItemData data, int extra, bool insert, bool fromRoom, UInt32 songID = 0) { isUpdated = false; if (insert) { if (fromRoom) { using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("REPLACE INTO items_users VALUES (" + Id + "," + UserId + ")"); //dbClient.setQuery("REPLACE INTO user_items (id, user_id,base_item,extra_data) VALUES ('" + Id + "','" + UserId + "','" + BaseItem + "',@extra_data)"); //dbClient.addParameter("extra_data", ExtraData); //dbClient.runQuery(); } Item baseItem = FirewindEnvironment.GetGame().GetItemManager().GetItem(BaseItem); if (baseItem != null && baseItem.InteractionType == InteractionType.musicdisc) { using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("DELETE FROM items_rooms_songs WHERE item_id = " + Id); //dbClient.runFastQuery("REPLACE INTO user_items_songs (item_id,user_id,song_id) VALUES (" + Id + "," + UserId + "," + songID + ")"); } } } else { using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO items (base_id) VALUES (" + BaseItem + ")"); Id = (uint)dbClient.insertQuery(); //if (!string.IsNullOrEmpty(ExtraData)) { dbClient.setQuery("INSERT INTO items_extradata VALUES (" + Id + ",@datatype,@data,@extra)"); dbClient.addParameter("datatype", data.GetTypeID()); dbClient.addParameter("data", data.ToString()); dbClient.addParameter("extra", extra); dbClient.runQuery(); } dbClient.runFastQuery("INSERT INTO items_users VALUES (" + Id + "," + UserId + ")"); //dbClient.setQuery("INSERT INTO user_items (user_id,base_item,extra_data) VALUES ('" + UserId + "','" + BaseItem + "',@extra_data)"); //dbClient.addParameter("extra_data", ExtraData); //Id = (uint)dbClient.insertQuery(); } } } UserItem ItemToAdd = new UserItem(Id, BaseItem, data, extra); if (UserHoldsItem(Id)) { RemoveItem(Id, false); } if (ItemToAdd.GetBaseItem().InteractionType == InteractionType.musicdisc) { discs.Add(ItemToAdd.Id, ItemToAdd); } if (ItemToAdd.isWallItem) { wallItems.Add(ItemToAdd.Id, ItemToAdd); } else { floorItems.Add(ItemToAdd.Id, ItemToAdd); } if (mRemovedItems.Contains(Id)) { mRemovedItems.Remove(Id); } if (!mAddedItems.ContainsKey(Id)) { mAddedItems.Add(Id, ItemToAdd); } return(ItemToAdd); //Logging.WriteLine("Item added: " + BaseItem); }
internal UserItem AddNewItem(UInt32 Id, UInt32 BaseItem, IRoomItemData data, int extra, bool insert, bool fromRoom, UInt32 songID = 0) { isUpdated = false; if (insert) { if (fromRoom) { using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("REPLACE INTO items_users VALUES (" + Id + "," + UserId + ")"); //dbClient.setQuery("REPLACE INTO user_items (id, user_id,base_item,extra_data) VALUES ('" + Id + "','" + UserId + "','" + BaseItem + "',@extra_data)"); //dbClient.addParameter("extra_data", ExtraData); //dbClient.runQuery(); } Item baseItem = FirewindEnvironment.GetGame().GetItemManager().GetItem(BaseItem); if (baseItem != null && baseItem.InteractionType == InteractionType.musicdisc) { using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("DELETE FROM items_rooms_songs WHERE item_id = " + Id); //dbClient.runFastQuery("REPLACE INTO user_items_songs (item_id,user_id,song_id) VALUES (" + Id + "," + UserId + "," + songID + ")"); } } } else { using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO items (base_id) VALUES (" + BaseItem + ")"); Id = (uint)dbClient.insertQuery(); //if (!string.IsNullOrEmpty(ExtraData)) { dbClient.setQuery("INSERT INTO items_extradata VALUES (" + Id + ",@datatype,@data,@extra)"); dbClient.addParameter("datatype", data.GetTypeID()); dbClient.addParameter("data", data.ToString()); dbClient.addParameter("extra", extra); dbClient.runQuery(); } dbClient.runFastQuery("INSERT INTO items_users VALUES (" + Id + "," + UserId + ")"); //dbClient.setQuery("INSERT INTO user_items (user_id,base_item,extra_data) VALUES ('" + UserId + "','" + BaseItem + "',@extra_data)"); //dbClient.addParameter("extra_data", ExtraData); //Id = (uint)dbClient.insertQuery(); } } } UserItem ItemToAdd = new UserItem(Id, BaseItem, data, extra); if (UserHoldsItem(Id)) { RemoveItem(Id, false); } if (ItemToAdd.GetBaseItem().InteractionType == InteractionType.musicdisc) discs.Add(ItemToAdd.Id, ItemToAdd); if (ItemToAdd.isWallItem) wallItems.Add(ItemToAdd.Id, ItemToAdd); else floorItems.Add(ItemToAdd.Id, ItemToAdd); if (mRemovedItems.Contains(Id)) mRemovedItems.Remove(Id); if (!mAddedItems.ContainsKey(Id)) mAddedItems.Add(Id, ItemToAdd); return ItemToAdd; //Logging.WriteLine("Item added: " + BaseItem); }