Skip to content

Commit

Permalink
Complete Identify effect
Browse files Browse the repository at this point in the history
Identify effect now supports Chance and will roll to identify each item.
Spell points are deducted every time player uses identify button in UI.
Player will need to re-create any Identify spells in spellbook to assign Chance settings.
  • Loading branch information
Interkarma committed May 6, 2022
1 parent be600cb commit bff417a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3583,6 +3583,14 @@ MonoBehaviour:
m_Key: SixteenTen
m_Metadata:
m_Items: []
- m_Id: 213117009860509696
m_Key: notEnoughSpellpointsLeft
m_Metadata:
m_Items: []
- m_Id: 213117165859258368
m_Key: totalIdentified
m_Metadata:
m_Items: []
m_Metadata:
m_Items: []
m_KeyGenerator:
Expand Down
8 changes: 8 additions & 0 deletions Assets/Localization/StringTables/Internal_Strings_en.asset
Original file line number Diff line number Diff line change
Expand Up @@ -3964,5 +3964,13 @@ MonoBehaviour:
m_Localized: 16:10
m_Metadata:
m_Items: []
- m_Id: 213117009860509696
m_Localized: You do not have enough spell points left.
m_Metadata:
m_Items: []
- m_Id: 213117165859258368
m_Localized: '{0} out of {1} identified.'
m_Metadata:
m_Items: []
references:
version: 1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using DaggerfallWorkshop.Game.Entity;
using DaggerfallWorkshop.Game.UserInterface;
using DaggerfallWorkshop.Game.UserInterfaceWindows;
using DaggerfallWorkshop.Game.Formulas;

namespace DaggerfallWorkshop.Game.MagicAndEffects.MagicEffects
{
Expand All @@ -28,12 +29,13 @@ public override void SetProperties()
{
properties.Key = EffectKey;
properties.ClassicKey = MakeClassicKey(40, 255);
//properties.SupportChance = true;
properties.SupportChance = true;
properties.AllowedTargets = TargetTypes.CasterOnly;
properties.AllowedElements = ElementTypes.Magic;
properties.AllowedCraftingStations = MagicCraftingStations.SpellMaker;
properties.MagicSkill = DFCareer.MagicSkills.Thaumaturgy;
//properties.DurationCosts = MakeEffectCosts(40, 100, 28);
properties.ChanceCosts = MakeEffectCosts(40, 100, 28);
properties.ChanceFunction = ChanceFunction.Custom;
}

public override string GroupName => TextManager.Instance.GetLocalizedText("identify");
Expand All @@ -44,9 +46,18 @@ public override void Start(EntityEffectManager manager, DaggerfallEntityBehaviou
{
base.Start(manager, caster);

// Refund spell point cost for this effect before opening trade window
// Actual spell point cost is applied when player clicks Identify button in trade window
// Any other effects bundled with identify on spell will not have their spell point cost refunded
FormulaHelper.SpellCost cost = FormulaHelper.CalculateEffectCosts(this, settings, caster.Entity);
caster.Entity.IncreaseMagicka(cost.spellPointCost);

// Open identify trade window in spell mode
UserInterfaceManager uiManager = DaggerfallUI.UIManager as UserInterfaceManager;
DaggerfallTradeWindow tradeWindow = (DaggerfallTradeWindow)UIWindowFactory.GetInstanceWithArgs(UIWindowType.Trade, new object[] { uiManager, null, DaggerfallTradeWindow.WindowModes.Identify, null });
tradeWindow.UsingIdentifySpell = true;
tradeWindow.IdentifySpellChance = ChanceValue();
tradeWindow.IdentifySpellCost = cost.spellPointCost;
uiManager.PushWindow(tradeWindow);
}
}
Expand Down
47 changes: 43 additions & 4 deletions Assets/Scripts/Game/UserInterfaceWindows/DaggerfallTradeWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ public bool UsingIdentifySpell
set { usingIdentifySpell = value; }
}

public int IdentifySpellChance { get; set; }

public int IdentifySpellCost { get; set; }

#endregion

#region Constructors
Expand Down Expand Up @@ -815,7 +819,8 @@ protected override void LocalItemListScroller_OnItemClick(DaggerfallUnityItem it

case WindowModes.Identify:
// Check if item is unidentified & transfer
if (!item.IsIdentified)
// In spell mode items can be transferred even if identified (matches classic)
if (!item.IsIdentified || UsingIdentifySpell)
TransferItem(item, localItems, remoteItems);
else
DaggerfallUI.MessageBox(TextManager.Instance.GetLocalizedText("doesntNeedIdentify"));
Expand Down Expand Up @@ -948,11 +953,45 @@ void StealButton_OnKeyboardEvent(BaseScreenComponent sender, Event keyboardEvent

private void DoModeAction()
{
// Identify using spell or trade
if (usingIdentifySpell)
{ // No trade when using a spell, just identify immediately
{
// Must have enough spell points available or be in godmode
if (IdentifySpellCost > GameManager.Instance.PlayerEntity.CurrentMagicka && !GameManager.Instance.PlayerEntity.GodMode)
{
DaggerfallUI.MessageBox(TextManager.Instance.GetLocalizedText("notEnoughSpellpointsLeft"));
return;
}

// Identify all items in remote list
int successCount = 0;
for (int i = 0; i < remoteItems.Count; i++)
remoteItems.GetItem(i).IdentifyItem();
DaggerfallUI.MessageBox(TextManager.Instance.GetLocalizedText("itemsIdentified"));
{
// Already identified items are always considered successful
if (remoteItems.GetItem(i).IsIdentified)
{
successCount++;
continue;
}

// Roll for chance and identify item if successful
if (Dice100.SuccessRoll(IdentifySpellChance))
{
remoteItems.GetItem(i).IdentifyItem();
successCount++;
}
}

// Reduce spell points when total items greater than zero
if (remoteItems.Count > 0)
GameManager.Instance.PlayerEntity.DecreaseMagicka(IdentifySpellCost);

// Output to player how many items were identified
DaggerfallUI.MessageBox(string.Format(TextManager.Instance.GetLocalizedText("totalIdentified"), successCount, remoteItems.Count));

// Transfer all items back to player
ClearSelectedItems();
Refresh();
}
else
ShowTradePopup();
Expand Down

0 comments on commit bff417a

Please sign in to comment.