public ServerPacket Compose() { ServerPacket message = new ServerPacket(Outgoing.CatalogSearchResultMessageComposer); message.WriteInteger(item.Id); message.WriteString(item.Name); message.WriteBoolean(false); message.WriteInteger(item.Credits); message.WriteInteger(item.Points); message.WriteInteger(item.PointsType); message.WriteBoolean(item.CanGift); message.WriteInteger(item.GetItems().Count); item.GetItems().ForEach(data => { message.WriteString(data.Type); message.WriteInteger(data.SpriteId); message.WriteString(data.ExtraData); message.WriteInteger(item.GetItemAmount(data.Id)); message.WriteBoolean(item.IsLimited); if (item.IsLimited) { message.WriteInteger(item.LimitedStack); message.WriteInteger(item.LimitedStack - item.LimitedSells); } }); message.WriteInteger(item.ClubLevel); message.WriteBoolean(item.HasOffer); message.WriteBoolean(false); message.WriteString(item.Name + ".png"); return(message); }
public void Handle(GameClient session, ClientMessage message) { uint itemId = message.PopWiredUInt(); CatalogItem item = Skylight.GetGame().GetCatalogManager().GetItemByID(itemId); if (item != null) { ServerMessage message_ = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108); message_.Init(r63aOutgoing.OfferIsGiftable); message_.AppendUInt(itemId); bool allowGift = true; foreach (Tuple <Item, int> data in item.GetItems()) { if (!data.Item1.AllowGift) { allowGift = false; break; } } message_.AppendBoolean(allowGift); session.SendMessage(message_); } }
public async void Handle(Session session, ClientPacket message) { int pageId = message.PopInt(); int itemId = message.PopInt(); string extraData = message.PopString(); int amount = message.PopInt(); CatalogPage page = Alias.Server.CatalogManager.GetCatalogPage(pageId); if (page == null) { session.Send(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); return; } if (page.Rank > session.Player.Rank) { session.Send(new AlertPurchaseUnavailableComposer(AlertPurchaseUnavailableComposer.ILLEGAL)); return; } CatalogItem item = page.GetCatalogItem(itemId); if (item == null) { session.Send(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); return; } if (item.ClubLevel > session.Player.ClubLevel) { session.Send(new AlertPurchaseUnavailableComposer(AlertPurchaseUnavailableComposer.REQUIRES_CLUB)); return; } if (amount <= 0 || amount > 100) { session.Send(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); return; } if (amount > 1 && !item.HasOffer) { session.Send(new AlertPurchaseFailedComposer(AlertPurchaseUnavailableComposer.ILLEGAL)); return; } if (item.IsLimited) { amount = 1; if (item.LimitedNumbers.Count <= 0) { session.Send(new AlertLimitedSoldOutComposer()); return; } } int limitedNumber = 0; int limitedStack = 0; if (item.IsLimited) { limitedNumber = item.GetNumber; limitedStack = item.LimitedStack; } List <InventoryItem> itemsList = new List <InventoryItem>(); int totalCredits = 0; int totalPoints = 0; for (int i = 0; i < amount; i++) { if (item.Credits <= session.Player.Credits - totalCredits) { //if (item.Points <= session.Player.Currency.TryGetCurrency(item.PointsType).Amount - totalPoints) todo: { if (((i + 1) % 6 != 0 && item.HasOffer) || !item.HasOffer) { totalCredits += item.Credits; totalPoints += item.Points; } foreach (ItemData baseItem in item.GetItems()) { for (int k = 0; k < item.GetItemAmount(baseItem.Id); k++) { if (baseItem.Interaction == ItemInteraction.BOT) { CatalogBots botData = Alias.Server.CatalogManager.GetCatalogBot(baseItem.Id); if (botData != null) { InventoryBot habboBot = new InventoryBot(-1, botData.Name, botData.Motto, botData.Look, botData.Gender); await session.Player.Inventory.AddBot(habboBot); session.Send(new AddBotComposer(habboBot)); } } else { if (baseItem.Interaction == ItemInteraction.TROPHY) { extraData = session.Player.Username + (char)9 + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + (char)9 + extraData; } if (baseItem.Interaction == ItemInteraction.TELEPORT) { InventoryItem teleportOne = new InventoryItem(-1, limitedNumber, limitedStack, baseItem.Id, session.Player.Id, extraData); await session.Player.Inventory.AddItem(teleportOne); InventoryItem teleportTwo = new InventoryItem(-1, limitedNumber, limitedStack, baseItem.Id, session.Player.Id, teleportOne.Id.ToString()); await session.Player.Inventory.AddItem(teleportTwo); teleportOne.ExtraData = teleportTwo.Id.ToString(); await session.Player.Inventory.UpdateItem(teleportOne); itemsList.Add(teleportOne); itemsList.Add(teleportTwo); } else { InventoryItem habboItem = new InventoryItem(-1, limitedNumber, limitedStack, baseItem.Id, session.Player.Id, extraData); await session.Player.Inventory.AddItem(habboItem); itemsList.Add(habboItem); } } } } } } } if (totalCredits > 0) { session.Player.Credits -= totalCredits; session.Send(new UserCreditsComposer(session.Player)); } if (totalPoints > 0) { //session.Player.Currency.GetCurrencyType(item.PointsType).Amount -= totalPoints; todo: //session.Send(new UserPointsComposer(session.Player.Currency.GetCurrencyType(item.PointsType).Amount, -totalPoints, item.PointsType)); } if (item.IsLimited) { item.AddLimited(limitedNumber); await Alias.Server.CatalogManager.AddLimitedAsync(item.Id, limitedNumber); } if (itemsList != null) { session.Send(new AddPlayerItemsComposer(itemsList)); } session.Player.AddPurchase(item); session.Send(new PurchaseOKComposer(item)); session.Send(new InventoryRefreshComposer()); }
public ServerPacket Compose() { ServerPacket message = new ServerPacket(Outgoing.PurchaseOKMessageComposer); if (this.item != null) { message.WriteInteger(item.Id); message.WriteString(item.Name); message.WriteBoolean(false); message.WriteInteger(item.Credits); message.WriteInteger(item.Points); message.WriteInteger(item.PointsType); message.WriteBoolean(item.CanGift); message.WriteInteger(item.GetItems().Count); item.GetItems().ForEach(data => { message.WriteString(data.Type); if (data.Type.Equals("b")) { message.WriteString(data.Name); } else { message.WriteInteger(data.SpriteId); message.WriteString(data.ExtraData); message.WriteInteger(item.GetItemAmount(data.Id)); message.WriteBoolean(item.IsLimited); if (item.IsLimited) { message.WriteInteger(item.LimitedStack); message.WriteInteger(item.LimitedStack - item.LimitedSells); } } }); message.WriteInteger(item.ClubLevel); message.WriteBoolean(item.HasOffer); message.WriteBoolean(false); message.WriteString(item.Name + ".png"); } else { message.WriteInteger(0); message.WriteString(""); message.WriteBoolean(false); message.WriteInteger(0); message.WriteInteger(0); message.WriteInteger(0); message.WriteBoolean(true); message.WriteInteger(1); message.WriteString("s"); message.WriteInteger(0); message.WriteString(""); message.WriteInteger(1); message.WriteInteger(0); message.WriteString(""); message.WriteInteger(1); } return(message); }