示例#1
0
        // -------------------------------------------------------------------------------
        // SellHandlerItem
        // -------------------------------------------------------------------------------
        protected void SellHandlerItem(InventorySlot selectedSlot)
        {
            InstanceItem item = (InstanceItem)selectedSlot;

            if (item.template.tradeCost.sellValue == 0)
            {
                Finder.audio.PlaySFX(SFX.ButtonCancel);
                Finder.log.Add(Finder.txt.basicVocabulary.cannotSell);
                return;
            }

            Finder.audio.PlaySFX(SFX.Sell);

            selectedSlot.Quantity -= 1;

            if (selectedSlot.Quantity <= 0)
            {
                Finder.party.inventory.Items.Remove(item);
                content.Remove(selectedSlot);
            }

            Finder.party.currencies.setResource(parent.shop.currencyType, item.template.tradeCost.sellValue);

            Finder.log.Add(string.Format("{0} " + Finder.txt.basicVocabulary.soldFor + " {1} " + Finder.txt.getCurrencyName(parent.shop.currencyType), item.template.name, item.template.tradeCost.sellValue));
        }
        // -------------------------------------------------------------------------------
        // PlayerUseItem (Post Selection)
        // -------------------------------------------------------------------------------
        public void PlayerUseItem(InstanceItem instance, CharacterBase[] targets)
        {
            Finder.ui.ActivateBattleCommands(false);

            if (targets != null)
            {
                Finder.ui.PopState();
                Finder.ui.ActivateBattleCommands(false);

                if (currentCharacter.CommandUseItem(instance, targets))
                {
                    if (instance.template.getCharacterActionType == CharacterActionType.PlayerExitBattle)
                    {
                        ForceEndBattle();
                    }
                    else
                    {
                        currentCharacter.BattleTurnFinished = true;
                    }
                }
            }
            else
            {
                PlayerCancel();
            }
        }
示例#3
0
        // -------------------------------------------------------------------------------
        // GetQuantity
        // -------------------------------------------------------------------------------
        public int GetQuantity(TemplateItem tmpl)
        {
            InstanceItem item = Items.FirstOrDefault(x => x.template == tmpl);

            if (item != null)
            {
                return(item.Quantity);
            }
            return(0);
        }
示例#4
0
        // -------------------------------------------------------------------------------
        // TrashConfirmedHandler
        // -------------------------------------------------------------------------------
        protected override void TrashConfirmedHandler()
        {
            if (selectedSlot != null)
            {
                if (selectedSlot is InstanceEquipment)
                {
                    InstanceEquipment equip = (InstanceEquipment)selectedSlot;
                    Finder.party.equipment.Equipment.Remove(equip);
                    content.Remove(selectedSlot);
                }
                else if (selectedSlot is InstanceItem)
                {
                    InstanceItem item = (InstanceItem)selectedSlot;
                    Finder.party.inventory.Items.Remove(item);
                    content.Remove(selectedSlot);
                }

                selectedSlot = null;
                Refresh();
            }
        }
示例#5
0
        // -------------------------------------------------------------------------------
        // AddItem
        // -------------------------------------------------------------------------------
        public void AddItem(TemplateItem tmpl, int quantity)
        {
            InstanceItem item = Items.FirstOrDefault(x => x.template == tmpl);

            if (item != null)
            {
                item.Quantity += quantity;
                if (item.Quantity <= 0)
                {
                    Items.Remove(item);
                }
            }
            else
            {
                InstanceItem newItem = new InstanceItem
                {
                    Quantity = quantity,
                    template = tmpl
                };
                this.Items.Add(newItem);
            }
        }
示例#6
0
        // -------------------------------------------------------------------------------
        // UseRequestHandler
        // -------------------------------------------------------------------------------
        protected void UseRequestHandler()  
        {
            CharacterBase[] targets = Finder.ui.GetSelectedCharacters();
            InstanceItem    item    = (InstanceItem)selectedSlot;

            if (targets != null)
            {
                foreach (CharacterBase target in targets)
                {
                    if (target != null)
                    {
                        if (!target.CanUseItem(item.template))
                        {
                            Finder.audio.PlaySFX(SFX.ButtonCancel);
                            Finder.log.Add(target.Name + " " + Finder.txt.basicVocabulary.requirementsNotMet + " " + item.name);
                            return;
                        }
                    }
                }

                if (Finder.battle.InBattle)
                {
                    Finder.battle.PlayerUseItem(item, targets);
                }
                else
                {
                    targets[0].CommandUseItem(item, targets);
                }

                foreach (CharacterBase target in targets)
                {
                    if (target != null)
                    {
                        target.CalculateDerivedStats();
                    }
                }
            }
        }
示例#7
0
        // -------------------------------------------------------------------------------
        // getCanUseType
        // -------------------------------------------------------------------------------
        public static void DropLoot(List <LootDrop> lootdrop)
        {
            List <InventorySlot> lootList;

            lootList = new List <InventorySlot>();

            InventorySlot tmpl = null;

            bool uniqueDrop = false;

            int quantity = 0;

            int[] resourceCount = new int[Enum.GetNames(typeof(CurrencyType)).Length];

            if (lootdrop != null)
            {
                foreach (LootDrop loot in lootdrop)
                {
                    if (
                        UnityEngine.Random.value <= loot.dropChance &&
                        (!loot.useAcquisitionRules ||
                         (loot.useAcquisitionRules &&
                          (loot.lootObject.PartyClassRequirementsMet || !loot.useClassRequirementRules) &&
                          (loot.lootObject.PartyStatRequirementsMet || !loot.useStatRequirementRules) &&
                          (loot.lootObject.AcquisitionRequirementsMet || !loot.useAcquisitionRules)
                         )))
                    {
                        if (loot.minQuantity > 0 && loot.maxQuantity > 0)
                        {
                            quantity = UnityEngine.Random.Range(loot.minQuantity, loot.maxQuantity);
                        }
                        else
                        {
                            quantity = Math.Max(loot.minQuantity, loot.maxQuantity);
                            if (quantity <= 0)
                            {
                                quantity = 1;
                            }
                        }

                        if (loot.lootObject is TemplateResource && (loot.uniqueDrop == false || uniqueDrop == false))
                        {
                            if (quantity > 0)
                            {
                                Finder.party.currencies.setResource(((TemplateResource)loot.lootObject).currencyType, quantity);
                                resourceCount[(int)((TemplateResource)loot.lootObject).currencyType] += quantity;
                                uniqueDrop = loot.uniqueDrop;
                            }
                        }
                        else if (loot.lootObject is TemplateEquipment && (loot.uniqueDrop == false || uniqueDrop == false))
                        {
                            TemplateEquipment obj = (TemplateEquipment)loot.lootObject;
                            Finder.party.equipment.AddEquipment(obj);

                            tmpl = new InstanceEquipment {
                                template = obj
                            };
                            lootList.Add(tmpl);

                            uniqueDrop = loot.uniqueDrop;
                        }
                        else if (loot.lootObject is TemplateItem && (loot.uniqueDrop == false || uniqueDrop == false))
                        {
                            TemplateItem obj = (TemplateItem)loot.lootObject;
                            Finder.party.inventory.AddItem(obj, quantity);

                            tmpl = new InstanceItem {
                                template = obj, Quantity = quantity
                            };
                            lootList.Add(tmpl);

                            uniqueDrop = loot.uniqueDrop;
                        }
                    }
                }

                int i = 0;

                foreach (int value in resourceCount)
                {
                    if (value > 0)
                    {
                        tmpl = new InstanceResource {
                            currencyType = (CurrencyType)i, Quantity = value
                        };
                        lootList.Add(tmpl);
                    }
                    i++;
                }
            }

            if (lootList.Count > 0)
            {
                lootList.Sort((x, y) => y.Quantity.CompareTo(x.Quantity));
            }
            Finder.loot.Show(lootList);
        }