void UpdateSpellCosts()
        {
            // Note: Daggerfall shows gold cost 0 and spellpoint cost 5 with no effects added
            // Not copying this behaviour at this time intentionally as it seems unclear for an invalid
            // spell to have any casting cost at all - may change later
            totalGoldCost       = 0;
            totalSpellPointCost = 0;

            // Do nothing when effect editor not setup or not used effect slots
            // This means there is nothing to calculate
            if (effectEditor == null || !effectEditor.IsSetup || CountUsedEffectSlots() == 0)
            {
                SetStatusLabels();
                return;
            }

            // Update slot being edited with current effect editor settings
            if (editOrDeleteSlot != -1)
            {
                effectEntries[editOrDeleteSlot] = effectEditor.EffectEntry;
            }

            // Get total costs
            FormulaHelper.CalculateTotalEffectCosts(effectEntries, selectedTarget, out totalGoldCost, out totalSpellPointCost);
            SetStatusLabels();
        }
        public void CastReadySpell()
        {
            // Do nothing if silenced
            if (SilenceCheck())
            {
                return;
            }

            // Must have a ready spell and a previous cast must not be in progress
            if (readySpell == null || castInProgress)
            {
                return;
            }

            // Get spellpoint costs of this spell
            int totalGoldCost, totalSpellPointCost;

            FormulaHelper.CalculateTotalEffectCosts(readySpell.Settings.Effects, readySpell.Settings.TargetType, out totalGoldCost, out totalSpellPointCost);

            // TODO: Enforce spellpoint costs - all spells are free to cast right now, even at 0 mana
            // This is to allow for easier testing during build-out stages

            // Deduct spellpoint cost from entity
            entityBehaviour.Entity.DecreaseMagicka(totalSpellPointCost);

            // Play casting animation based on element type
            // Spell is released by event handler PlayerSpellCasting_OnReleaseFrame
            // TODO: Do not need to show spellcasting animations for certain spell effects
            GameManager.Instance.PlayerSpellCasting.PlayOneShot(readySpell.Settings.ElementType);

            // Block further casting attempts until previous cast is complete
            castInProgress = true;
        }
        private void PopulateSpellsList(List <EffectBundleSettings> spells, int?availableSpellPoints = null)
        {
            foreach (EffectBundleSettings spell in spells)
            {
                // Get spell costs
                // Costs can change based on player skills and stats so must be calculated each time
                int goldCost, spellPointCost;
                FormulaHelper.CalculateTotalEffectCosts(spell.Effects, spell.TargetType, out goldCost, out spellPointCost, null, spell.MinimumCastingCost);

                // Lycanthropy is a free spell, even though it shows a cost in classic
                // Setting cost to 0 so it displays correctly in spellbook
                if (spell.Tag == PlayerEntity.lycanthropySpellTag)
                {
                    spellPointCost = 0;
                }

                // Display spell name and cost
                ListBox.ListItem listItem;
                spellsListBox.AddItem(string.Format("{0} - {1}", spellPointCost, spell.Name), out listItem);
                if (availableSpellPoints != null && availableSpellPoints < spellPointCost)
                {
                    // Desaturate unavailable spells
                    float desaturation = 0.75f;
                    listItem.textColor                    = Color.Lerp(listItem.textColor, Color.grey, desaturation);
                    listItem.selectedTextColor            = Color.Lerp(listItem.selectedTextColor, Color.grey, desaturation);
                    listItem.highlightedTextColor         = Color.Lerp(listItem.highlightedTextColor, Color.grey, desaturation);
                    listItem.highlightedSelectedTextColor = Color.Lerp(listItem.highlightedSelectedTextColor, Color.grey, desaturation);
                }
            }
        }
예제 #4
0
        void RefreshSpellsList()
        {
            // Clear existing list
            spellsListBox.ClearItems();

            // Add spells based on mode
            if (buyMode)
            {
                // Load spells for sale
                offeredSpells.Clear();
                List <SpellRecord.SpellRecordData> standardSpells = DaggerfallSpellReader.ReadSpellsFile(Path.Combine(DaggerfallUnity.Arena2Path, spellsFilename));
                if (standardSpells == null || standardSpells.Count == 0)
                {
                    Debug.LogError("Failed to load SPELLS.STD for spellbook in buy mode.");
                    return;
                }

                for (int i = 0; i < standardSpells.Count; i++)
                {
                    // Filter internal spells starting with exclamation point '!'
                    if (standardSpells[i].spellName.StartsWith("!"))
                    {
                        continue;
                    }

                    // NOTE: Classic allows purchase of duplicate spells
                    // If ever changing this, must ensure spell is an *exact* duplicate (i.e. not a custom spell with same name)
                    // Just allowing duplicates for now as per classic and let user manage preference

                    // Get effect bundle settings from classic spell
                    EffectBundleSettings bundle;
                    if (!GameManager.Instance.EntityEffectBroker.ClassicSpellRecordDataToEffectBundleSettings(standardSpells[i], BundleTypes.Spell, out bundle))
                    {
                        continue;
                    }

                    // Store offered spell and add to list box
                    offeredSpells.Add(bundle);
                    spellsListBox.AddItem(standardSpells[i].spellName);
                }
            }
            else
            {
                // Add player spells to list
                EffectBundleSettings[] spellbook = GameManager.Instance.PlayerEntity.GetSpells();
                if (spellbook != null)
                {
                    for (int i = 0; i < spellbook.Length; i++)
                    {
                        // Show spell name and cost
                        // Costs can change based on player skills and stats so must be calculated each time
                        int goldCost, spellPointCost;
                        FormulaHelper.CalculateTotalEffectCosts(spellbook[i].Effects, spellbook[i].TargetType, out goldCost, out spellPointCost);
                        spellsListBox.AddItem(string.Format("{0} - {1}", spellPointCost, spellbook[i].Name));
                    }
                }
            }
        }
        public void SortSpellsPointCost()
        {
            List <EffectBundleSettings> sortedSpellbook = spellbook
                                                          .OrderBy((EffectBundleSettings spell) =>
            {
                (int _, int spellPointCost) = FormulaHelper.CalculateTotalEffectCosts(spell.Effects, spell.TargetType, null, spell.MinimumCastingCost);
                return(spellPointCost);
            })
                                                          .ToList();

            if (sortedSpellbook.Count == spellbook.Count)
            {
                spellbook = sortedSpellbook;
            }
        }
예제 #6
0
        void RefreshSpellsList()
        {
            // Clear existing list
            spellsListBox.ClearItems();

            // Add player spells to list
            EffectBundleSettings[] spellbook = GameManager.Instance.PlayerEntity.GetSpells();
            if (spellbook != null)
            {
                for (int i = 0; i < spellbook.Length; i++)
                {
                    // Show spell name and cost
                    // Costs can change based on player skills and stats so must be calculated each time
                    int goldCost, spellPointCost;
                    FormulaHelper.CalculateTotalEffectCosts(spellbook[i].Effects, spellbook[i].TargetType, out goldCost, out spellPointCost);
                    spellsListBox.AddItem(string.Format("{0} - {1}", spellPointCost, spellbook[i].Name));
                }
            }
        }
 private void PopulateSpellsList(List <EffectBundleSettings> spells, int?availableSpellPoints = null)
 {
     foreach (EffectBundleSettings spell in spells)
     {
         // Show spell name and cost
         // Costs can change based on player skills and stats so must be calculated each time
         int goldCost, spellPointCost;
         FormulaHelper.CalculateTotalEffectCosts(spell.Effects, spell.TargetType, out goldCost, out spellPointCost, null, spell.MinimumCastingCost);
         ListBox.ListItem listItem;
         spellsListBox.AddItem(string.Format("{0} - {1}", spellPointCost, spell.Name), out listItem);
         if (availableSpellPoints != null && availableSpellPoints < spellPointCost)
         {
             // Desaturate unavailable spells
             float desaturation = 0.75f;
             listItem.textColor                    = Color.Lerp(listItem.textColor, Color.grey, desaturation);
             listItem.selectedTextColor            = Color.Lerp(listItem.selectedTextColor, Color.grey, desaturation);
             listItem.highlightedTextColor         = Color.Lerp(listItem.highlightedTextColor, Color.grey, desaturation);
             listItem.highlightedSelectedTextColor = Color.Lerp(listItem.highlightedSelectedTextColor, Color.grey, desaturation);
         }
     }
 }
예제 #8
0
        public void CastReadySpell()
        {
            // Must have a ready spell
            if (readySpell == null)
            {
                return;
            }

            // Get spellpoint costs of this spell
            int totalGoldCost, totalSpellPointCost;

            FormulaHelper.CalculateTotalEffectCosts(readySpell.Settings.Effects, readySpell.Settings.TargetType, out totalGoldCost, out totalSpellPointCost);

            // TODO: Enforce spellpoint costs - all spells are free to cast right now, even at 0 mana
            // This is to allow for easier testing during build-out stages

            // Deduct spellpoint cost from entity
            entityBehaviour.Entity.DecreaseMagicka(totalSpellPointCost);

            // Play casting animation based on element type
            // Spell is released by event handler PlayerSpellCasting_OnReleaseFrame
            // TODO: Do not need to show spellcasting animations for certain spell effects
            GameManager.Instance.PlayerSpellCasting.PlayOneShot(readySpell.Settings.ElementType);
        }
        void UpdateSelection()
        {
            // Update spell list scroller
            spellsListScrollBar.Reset(spellsListBox.RowsDisplayed, spellsListBox.Count, spellsListBox.ScrollIndex);
            spellsListScrollBar.TotalUnits  = spellsListBox.Count;
            spellsListScrollBar.ScrollIndex = spellsListBox.ScrollIndex;

            // Get spell settings selected from player spellbook or offered spells
            EffectBundleSettings spellSettings;

            if (buyMode)
            {
                spellSettings = offeredSpells[spellsListBox.SelectedIndex];

                // The price shown in buy mode is the player casting cost * 4
                int goldCost, spellPointCost;
                FormulaHelper.CalculateTotalEffectCosts(spellSettings.Effects, spellSettings.TargetType, out goldCost, out spellPointCost);
                presentedCost = spellPointCost * 4;

                // Presented cost is halved on Witches Festival holiday
                uint gameMinutes = DaggerfallUnity.Instance.WorldTime.DaggerfallDateTime.ToClassicDaggerfallTime();
                int  holidayID   = FormulaHelper.GetHolidayId(gameMinutes, 0);
                if (holidayID == (int)DaggerfallConnect.DFLocation.Holidays.Witches_Festival)
                {
                    presentedCost >>= 1;
                    if (presentedCost == 0)
                    {
                        presentedCost = 1;
                    }
                }

                spellCostLabel.Text = presentedCost.ToString();
            }
            else
            {
                // Get spell and exit if spell index not found
                if (!GameManager.Instance.PlayerEntity.GetSpell(spellsListBox.SelectedIndex, out spellSettings))
                {
                    spellNameLabel.Text = string.Empty;
                    ClearEffectLabels();
                    ShowIcons(false);
                    return;
                }
            }

            // Update spell name label
            spellNameLabel.Text = spellSettings.Name;

            // Update effect labels
            for (int i = 0; i < 3; i++)
            {
                if (i < spellSettings.Effects.Length)
                {
                    SetEffectLabels(spellSettings.Effects[i].Key, i);
                }
                else
                {
                    SetEffectLabels(string.Empty, i);
                }
            }

            // Update spell icons
            spellIconPanel.BackgroundTexture        = GetSpellIcon(spellSettings.Icon);
            spellTargetIconPanel.BackgroundTexture  = GetSpellTargetIcon(spellSettings.TargetType);
            spellTargetIconPanel.ToolTipText        = GetTargetTypeDescription(spellSettings.TargetType);
            spellElementIconPanel.BackgroundTexture = GetSpellElementIcon(spellSettings.ElementType);
            spellElementIconPanel.ToolTipText       = GetElementDescription(spellSettings.ElementType);
            ShowIcons(true);
        }