Example #1
0
        private static void GetPetData(Session Session, ClientMessage Message)
        {
            CatalogItem PetItem  = null;
            string      ItemName = Message.PopString();

            if (mCatalogItemsNameIndex.ContainsKey(ItemName))
            {
                PetItem = mCatalogItemsNameIndex[ItemName];
            }

            if (PetItem == null || PetItem.Definition.Behavior != ItemBehavior.Pet)
            {
                return;
            }

            int PetType = PetItem.Definition.BehaviorData;

            Session.SendData(CatalogPetDataComposer.Compose(PetItem, PetDataManager.GetRaceDataForType(PetType), PetType));
        }
        public static void HandlePurchase(SqlDatabaseClient MySqlClient, Session Session, CatalogItem Item, string ItemFlags)
        {
            lock (mPurchaseSyncRoot)
            {
                string Color           = "ffffff";
                int    TotalCreditCost = Item.CostCredits;
                int    TotalApCost     = Item.CostActivityPoints;

                if (Session.CharacterInfo.CreditsBalance < TotalCreditCost || Session.CharacterInfo.ActivityPointsBalance
                    < TotalApCost)
                {
                    return;
                }

                string[] PetData = null;

                if (Item.PresetFlags.Length > 0)
                {
                    ItemFlags = Item.PresetFlags;
                }
                else
                {
                    switch (Item.Definition.Behavior)
                    {
                    case ItemBehavior.Pet:

                        PetData = ItemFlags.Split('\n');
                        if (PetData.Length != 3)
                        {
                            return;
                        }

                        string Name = PetData[0];
                        Color = PetData[2];

                        int Race = 0;
                        int.TryParse(PetData[1], out Race);

                        bool RaceOk = false;

                        List <PetRaceData> Races = PetDataManager.GetRaceDataForType(Item.Definition.BehaviorData);

                        foreach (PetRaceData RaceData in Races)
                        {
                            if (RaceData.Data1 == Race)
                            {
                                RaceOk = true;
                                break;
                            }
                        }

                        /// if (PetName.VerifyPetName(Name) != PetNameError.NameOk || Color.ToLower() != "ffffff" || !RaceOk)
                        if (PetName.VerifyPetName(Name) != PetNameError.NameOk || !RaceOk)     // WHY COLOR???
                        {
                            return;
                        }

                        break;

                    case ItemBehavior.PrizeTrophy:

                        if (ItemFlags.Length > 255)
                        {
                            ItemFlags = ItemFlags.Substring(0, 255);
                        }

                        ItemFlags = Session.CharacterInfo.Username + Convert.ToChar(9) + DateTime.Now.Day + "-" +
                                    DateTime.Now.Month + "-" + DateTime.Now.Year + Convert.ToChar(9) +
                                    UserInputFilter.FilterString(ItemFlags.Trim(), true);
                        break;

                    default:

                        ItemFlags = string.Empty;
                        break;
                    }
                }

                if (TotalCreditCost > 0)
                {
                    Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, -TotalCreditCost);
                    Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance));
                }

                if (TotalApCost > 0)
                {
                    Session.CharacterInfo.UpdateActivityPointsBalance(MySqlClient, -TotalApCost);
                    Session.SendData(ActivityPointsBalanceComposer.Compose(Session.CharacterInfo.ActivityPointsBalance, -TotalApCost));
                }

                Dictionary <int, List <uint> > NewItems = new Dictionary <int, List <uint> >();

                for (int i = 0; i < Item.Amount; i++)
                {
                    switch (Item.Definition.Type)
                    {
                    default:

                        List <Item> GeneratedGenericItems = new List <Item>();
                        double      ExpireTimestamp       = 0;

                        if (Item.Definition.Behavior == ItemBehavior.Rental)
                        {
                            ExpireTimestamp = UnixTimestamp.GetCurrent() + 3600;
                        }

                        GeneratedGenericItems.Add(ItemFactory.CreateItem(MySqlClient, Item.DefinitionId,
                                                                         Session.CharacterId, ItemFlags, ItemFlags, ExpireTimestamp));

                        switch (Item.Definition.Behavior)
                        {
                        case ItemBehavior.Teleporter:

                            Item LinkedItem = ItemFactory.CreateItem(MySqlClient, Item.DefinitionId,
                                                                     Session.CharacterId, GeneratedGenericItems[0].Id.ToString(), string.Empty,
                                                                     ExpireTimestamp);

                            GeneratedGenericItems[0].Flags = LinkedItem.Id.ToString();
                            GeneratedGenericItems[0].SynchronizeDatabase(MySqlClient, true);

                            GeneratedGenericItems.Add(LinkedItem);
                            break;
                        }

                        foreach (Item GeneratedItem in GeneratedGenericItems)
                        {
                            Session.InventoryCache.Add(GeneratedItem);

                            int TabId = GeneratedItem.Definition.Type == ItemType.FloorItem ? 1 : 2;

                            if (!NewItems.ContainsKey(TabId))
                            {
                                NewItems.Add(TabId, new List <uint>());
                            }

                            NewItems[TabId].Add(GeneratedItem.Id);
                        }

                        break;

                    case ItemType.AvatarEffect:

                        AvatarEffect Effect = null;

                        if (Session.AvatarEffectCache.HasEffect((int)Item.Definition.SpriteId))
                        {
                            Effect = Session.AvatarEffectCache.GetEffect((int)Item.Definition.SpriteId);

                            if (Effect != null)
                            {
                                Effect.AddToQuantity();
                            }
                        }
                        else
                        {
                            Effect = AvatarEffectFactory.CreateEffect(MySqlClient, Session.CharacterId, (int)Item.Definition.SpriteId, 3600);
                            Session.AvatarEffectCache.Add(Effect);
                        }

                        if (Effect != null)
                        {
                            Session.SendData(UserEffectAddedComposer.Compose(Effect));
                        }

                        break;

                    case ItemType.Pet:

                        Pet Pet = PetFactory.CreatePet(MySqlClient, Session.CharacterId, Item.Definition.BehaviorData, PetData[0], int.Parse(PetData[1]), Color.ToLower());
                        Session.PetInventoryCache.Add(Pet);

                        Session.SendData(InventoryPetAddedComposer.Compose(Pet));

                        if (!NewItems.ContainsKey(3))
                        {
                            NewItems.Add(3, new List <uint>());
                        }

                        NewItems[3].Add(Pet.Id);

                        break;
                    }
                }

                Session.SendData(CatalogPurchaseResultComposer.Compose(Item));
                Session.SendData(InventoryRefreshComposer.Compose());

                foreach (KeyValuePair <int, List <uint> > NewItemData in NewItems)
                {
                    foreach (uint NewItem in NewItemData.Value)
                    {
                        Session.NewItemsCache.MarkNewItem(MySqlClient, NewItemData.Key, NewItem);
                    }
                }

                if (NewItems.Count > 0)
                {
                    Session.SendData(InventoryNewItemsComposer.Compose(new Dictionary <int, List <uint> >(NewItems)));
                }
            }
        }