Exemple #1
0
        /// <summary>
        /// Vends un consommable dans le slot donné du héros donné.
        /// </summary>
        public ShopTransactionResult SellConsummable(EntityHero hero, int slot)
        {
            // Vérifie la distance au shop.
            float dst = Vector2.Distance(hero.Position, m_owner.Position);

            if (dst > m_shopRange)
            {
                return(ShopTransactionResult.NotInShopRange);
            }

            // Slot out of range : erreur
            if (slot < 0 || slot >= hero.Consummables.Length)
            {
                return(ShopTransactionResult.ProvidedSlotDoesNotExist);
            }

            // Consommable vide ?
            bool emptySlot = hero.Consummables[slot].Model.ConsummableType == ConsummableType.Empty;

            if (emptySlot)
            {
                return(ShopTransactionResult.NoItemToSell);
            }

            if (hero.Consummables[slot].Count <= 0)
            {
                return(ShopTransactionResult.NoItemToSell);
            }

            ConsummableModel model = hero.Consummables[slot].Model;

            hero.PA += model.Price;
            hero.Consummables[slot].Count--;
            return(ShopTransactionResult.Success);
        }
Exemple #2
0
        /// <summary>
        /// Achète un consommable pour le héros donné, et le place dans le slot donné.
        /// </summary>
        public ShopTransactionResult PurchaseConsummable(EntityHero hero, int consummableId, int slot)
        {
            EquipmentModel equip = GetEquipmentById(consummableId);

            if (equip == null || equip.Type != EquipmentType.Consummable)
            {
                return(ShopTransactionResult.ItemDoesNotExist);
            }
            ConsummableModel model = (ConsummableModel)equip;

            if (equip.Price > hero.PA)
            {
                return(ShopTransactionResult.NotEnoughMoney);
            }

            float dst = Vector2.Distance(hero.Position, m_owner.Position);

            if (dst > m_shopRange)
            {
                return(ShopTransactionResult.NotInShopRange);
            }

            // Slot out of range : erreur
            if (slot < 0 || slot >= hero.Consummables.Length)
            {
                return(ShopTransactionResult.ProvidedSlotDoesNotExist);
            }
            bool emptySlot = hero.Consummables[slot].Model.ConsummableType == ConsummableType.Empty;

            // Si un consommable d'un autre type est dans le slot, erreur
            if (!emptySlot && (hero.Consummables[slot].Model.ConsummableType != model.ConsummableType))
            {
                return(ShopTransactionResult.NoSlotAvailableOnHero);
            }

            // Dépassement de la stack du consommable : erreur
            if (hero.Consummables[slot].Count >= hero.Consummables[slot].Model.MaxStackSize)
            {
                return(ShopTransactionResult.StackOverflow);
            }

            // Achat !!
            hero.Consummables[slot].Model = model;
            hero.Consummables[slot].Count++;
            hero.PA -= equip.Price;
            return(ShopTransactionResult.Success);
        }