Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legendary item ranges hint fix #14

Open
wants to merge 3 commits into
base: releases/EpicLoot/v0.9.37-vapok
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion EpicLoot/Crafting/AugmentChoiceDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void Show(ItemDrop.ItemData fromItem, int effectIndex, Action<ItemDrop.It
var button = EffectChoiceButtons[index];
button.gameObject.SetActive(true);
var text = button.GetComponentInChildren<TMP_Text>();
text.text = Localization.instance.Localize((index == 0 ? "<color=white>($mod_epicloot_augment_keep)</color> " : "") + MagicItem.GetEffectText(effect, rarity, true));
text.text = Localization.instance.Localize((index == 0 ? "<color=white>($mod_epicloot_augment_keep)</color> " : "") + MagicItem.GetEffectText(effect, rarity, fromItem.m_shared.m_name, true, magicItem.LegendaryID));
text.color = rarityColor;

if (EpicLoot.HasAuga)
Expand Down
4 changes: 2 additions & 2 deletions EpicLoot/Crafting/AugmentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static List<MagicItemEffectDefinition> GetAvailableAugments(AugmentRecipe
if (recipe.EffectIndex >= 0 && recipe.EffectIndex < magicItem.Effects.Count)
{
var currentEffectDef = MagicItemEffectDefinitions.Get(magicItem.Effects[recipe.EffectIndex].EffectType);
valuelessEffect = currentEffectDef.GetValuesForRarity(rarity) == null;
valuelessEffect = currentEffectDef.GetValuesForRarity(rarity, item.m_shared.m_name) == null;
}

return MagicItemEffectDefinitions.GetAvailableEffects(item.Extended(), item.GetMagicItem(), valuelessEffect ? -1 : recipe.EffectIndex);
Expand All @@ -179,7 +179,7 @@ public static string GetAugmentSelectorText(MagicItem magicItem, int i, IReadOnl
{
var pip = EpicLoot.GetMagicEffectPip(magicItem.IsEffectAugmented(i));
bool free = EnchantCostsHelper.EffectIsDeprecated(augmentableEffects[i].EffectType);
return $"{pip} {Localization.instance.Localize(MagicItem.GetEffectText(augmentableEffects[i], rarity, true))}{(free ? " [<color=yellow>*FREE</color>]" : "")}";
return $"{pip} {Localization.instance.Localize(MagicItem.GetEffectText(augmentableEffects[i], rarity, magicItem.ItemName, true, magicItem.LegendaryID))}{(free ? " [<color=yellow>*FREE</color>]" : "")}";
}

public static List<KeyValuePair<ItemDrop, int>> GetAugmentCosts(ItemDrop.ItemData item, int recipeEffectIndex)
Expand Down
2 changes: 1 addition & 1 deletion EpicLoot/Crafting/AugmentsAvailableDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void Show(AugmentHelper.AugmentRecipe recipe)

foreach (var effectDef in availableEffects)
{
var values = effectDef.GetValuesForRarity(item.GetRarity());
var values = effectDef.GetValuesForRarity(item.GetRarity(), item.m_shared.m_name);
var valueDisplay = values != null ? Mathf.Approximately(values.MinValue, values.MaxValue) ? $"{values.MinValue}" : $"({values.MinValue}-{values.MaxValue})" : "";
t.AppendLine($"‣ {string.Format(Localization.instance.Localize(effectDef.DisplayText), valueDisplay)}");
}
Expand Down
6 changes: 3 additions & 3 deletions EpicLoot/CraftingV2/EnchantingUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private static string GetEnchantInfo(ItemDrop.ItemData item, MagicRarityUnity _r

foreach (var effectDef in availableEffects)
{
var values = effectDef.GetValuesForRarity(rarity);
var values = effectDef.GetValuesForRarity(rarity, item.m_shared.m_name);
var valueDisplay = values != null ? Mathf.Approximately(values.MinValue, values.MaxValue) ? $"{values.MinValue}" : $"({values.MinValue}-{values.MaxValue})" : "";
sb.AppendLine($"‣ {string.Format(Localization.instance.Localize(effectDef.DisplayText), valueDisplay)}");
}
Expand Down Expand Up @@ -520,7 +520,7 @@ private static string GetAvailableAugmentEffects(ItemDrop.ItemData item, int aug
if (augmentindex >= 0 && augmentindex < magicItem.Effects.Count)
{
var currentEffectDef = MagicItemEffectDefinitions.Get(magicItem.Effects[augmentindex].EffectType);
valuelessEffect = currentEffectDef.GetValuesForRarity(rarity) == null;
valuelessEffect = currentEffectDef.GetValuesForRarity(rarity, item.m_shared.m_name) == null;
}

var availableEffects = MagicItemEffectDefinitions.GetAvailableEffects(item.Extended(), item.GetMagicItem(), valuelessEffect ? -1 : augmentindex);
Expand All @@ -529,7 +529,7 @@ private static string GetAvailableAugmentEffects(ItemDrop.ItemData item, int aug
sb.Append($"<color={rarityColor}>");
foreach (var effectDef in availableEffects)
{
var values = effectDef.GetValuesForRarity(item.GetRarity());
var values = effectDef.GetValuesForRarity(item.GetRarity(), item.m_shared.m_name);
var valueDisplay = values != null ? Mathf.Approximately(values.MinValue, values.MaxValue) ? $"{values.MinValue}" : $"({values.MinValue}-{values.MaxValue})" : "";
sb.AppendLine($"‣ {string.Format(Localization.instance.Localize(effectDef.DisplayText), valueDisplay)}");
}
Expand Down
23 changes: 12 additions & 11 deletions EpicLoot/LootRoller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private static List<GameObject> RollLootTableInternal(LootTable lootTable, int l
var magicItem = RollMagicItem(lootDrop, itemData, luckFactor);
if (CheatForceMagicEffect)
{
AddDebugMagicEffects(magicItem);
AddDebugMagicEffects(magicItem, itemData.m_shared.m_name);
}
magicItemComponent.SetMagicItem(magicItem);
itemDrop.m_itemData = itemData;
Expand Down Expand Up @@ -464,7 +464,7 @@ public static MagicItem RollMagicItem(ItemRarity rarity, ItemDrop.ItemData baseI
rarity = ItemRarity.Legendary;
}

var magicItem = new MagicItem { Rarity = rarity };
var magicItem = new MagicItem { Rarity = rarity, ItemName = baseItem.m_shared.m_name };

var effectCount = CheatEffectCount >= 1 ? CheatEffectCount : RollEffectCountPerRarity(magicItem.Rarity);

Expand Down Expand Up @@ -512,7 +512,7 @@ public static MagicItem RollMagicItem(ItemRarity rarity, ItemDrop.ItemData baseI
continue;
}

var effect = RollEffect(effectDef, ItemRarity.Legendary, guaranteedMagicEffect.Values);
var effect = RollEffect(effectDef, ItemRarity.Legendary, baseItem.m_shared.m_name, guaranteedMagicEffect.Values);
magicItem.Effects.Add(effect);
effectCount--;
}
Expand All @@ -532,7 +532,7 @@ public static MagicItem RollMagicItem(ItemRarity rarity, ItemDrop.ItemData baseI
_weightedEffectTable.Setup(availableEffects, x => x.SelectionWeight);
var effectDef = _weightedEffectTable.Roll();

var effect = RollEffect(effectDef, magicItem.Rarity);
var effect = RollEffect(effectDef, magicItem.Rarity, baseItem.m_shared.m_name);
magicItem.Effects.Add(effect);
}

Expand Down Expand Up @@ -612,10 +612,10 @@ public static List<KeyValuePair<int, float>> GetEffectCountsPerRarity(ItemRarity
return result;
}

public static MagicItemEffect RollEffect(MagicItemEffectDefinition effectDef, ItemRarity itemRarity, MagicItemEffectDefinition.ValueDef valuesOverride = null)
public static MagicItemEffect RollEffect(MagicItemEffectDefinition effectDef, ItemRarity itemRarity, string itemName, MagicItemEffectDefinition.ValueDef valuesOverride = null)
{
float value = MagicItemEffect.DefaultValue;
var valuesDef = valuesOverride ?? effectDef.GetValuesForRarity(itemRarity);
var valuesDef = valuesOverride ?? effectDef.GetValuesForRarity(itemRarity, itemName);
if (valuesDef != null)
{
value = valuesDef.MinValue;
Expand All @@ -630,7 +630,8 @@ public static MagicItemEffect RollEffect(MagicItemEffectDefinition effectDef, It
return new MagicItemEffect(effectDef.Type, value);
}

public static List<MagicItemEffect> RollEffects(List<MagicItemEffectDefinition> availableEffects, ItemRarity itemRarity, int count, bool removeOnSelect = true)

public static List<MagicItemEffect> RollEffects(List<MagicItemEffectDefinition> availableEffects, ItemRarity itemRarity, string itemName, int count, bool removeOnSelect = true)
{
var results = new List<MagicItemEffect>();

Expand All @@ -644,7 +645,7 @@ public static List<MagicItemEffect> RollEffects(List<MagicItemEffectDefinition>
EpicLoot.LogError($"EffectDef was null! RollEffects({itemRarity}, {count})");
continue;
}
results.Add(RollEffect(effectDef, itemRarity));
results.Add(RollEffect(effectDef, itemRarity, itemName));
}

return results;
Expand Down Expand Up @@ -818,7 +819,7 @@ public static List<MagicItemEffect> RollAugmentEffects(ItemDrop.ItemData item, M

for (var i = 0; i < augmentChoices && i < availableEffects.Count; i++)
{
var newEffect = RollEffects(availableEffects, rarity, 1, false).FirstOrDefault();
var newEffect = RollEffects(availableEffects, rarity, item.m_shared.m_name, 1, false).FirstOrDefault();
if (newEffect == null)
{
EpicLoot.LogError($"Rolled a null effect: item:{item.m_shared.m_name}, index:{effectIndex}");
Expand All @@ -837,12 +838,12 @@ public static List<MagicItemEffect> RollAugmentEffects(ItemDrop.ItemData item, M
return results;
}

public static void AddDebugMagicEffects(MagicItem item)
public static void AddDebugMagicEffects(MagicItem item, string itemName)
{
if (!string.IsNullOrEmpty(ForcedMagicEffect) && !item.HasEffect(ForcedMagicEffect))
{
EpicLoot.Log($"AddDebugMagicEffect {ForcedMagicEffect}");
item.Effects.Add(RollEffect(MagicItemEffectDefinitions.Get(ForcedMagicEffect), item.Rarity));
item.Effects.Add(RollEffect(MagicItemEffectDefinitions.Get(ForcedMagicEffect), item.Rarity, itemName));
}
}

Expand Down
33 changes: 22 additions & 11 deletions EpicLoot/MagicItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public MagicItemEffect(string type, float value = DefaultValue)
[Serializable]
public class MagicItem
{
public int Version = 2;
public int Version = 3;
public ItemRarity Rarity;
public List<MagicItemEffect> Effects = new List<MagicItemEffect>();
public string TypeNameOverride;
Expand All @@ -48,6 +48,7 @@ public class MagicItem
public string DisplayName;
public string LegendaryID;
public string SetID;
public string ItemName;

public string GetItemTypeName(ItemDrop.ItemData baseItem)
{
Expand All @@ -71,7 +72,7 @@ public string GetTooltip()
{
var effect = Effects[index];
var pip = EpicLoot.GetMagicEffectPip(IsEffectAugmented(index));
tooltip.AppendLine($"{pip} {GetEffectText(effect, Rarity, showRange)}");
tooltip.AppendLine($"{pip} {GetEffectText(effect, Rarity, ItemName, showRange, LegendaryID)}");
}

tooltip.Append($"</color>");
Expand Down Expand Up @@ -127,11 +128,26 @@ public static string GetEffectText(MagicItemEffectDefinition effectDef, float va
return result;
}

public static string GetEffectText(MagicItemEffect effect, ItemRarity rarity, bool showRange, string legendaryID, MagicItemEffectDefinition.ValueDef valuesOverride)
public static string GetEffectText(MagicItemEffect effect, ItemRarity rarity, string itemName, bool showRange, string legendaryID, MagicItemEffectDefinition.ValueDef valuesOverride)
{
var effectDef = MagicItemEffectDefinitions.Get(effect.EffectType);
var result = GetEffectText(effectDef, effect.EffectValue);
var values = valuesOverride ?? (string.IsNullOrEmpty(legendaryID) ? effectDef.GetValuesForRarity(rarity) : UniqueLegendaryHelper.GetLegendaryEffectValues(legendaryID, effect.EffectType));
MagicItemEffectDefinition.ValueDef values = null;
if (valuesOverride != null)
{
values = valuesOverride;
}
else
{
if (!string.IsNullOrEmpty(legendaryID))
{
values = UniqueLegendaryHelper.GetLegendaryEffectValues(legendaryID, effect.EffectType);
}
if (values == null)
{
values = effectDef.GetValuesForRarity(rarity, itemName);
}
}
if (showRange && values != null)
{
if (!Mathf.Approximately(values.MinValue, values.MaxValue))
Expand All @@ -142,14 +158,9 @@ public static string GetEffectText(MagicItemEffect effect, ItemRarity rarity, bo
return result;
}

public static string GetEffectText(MagicItemEffect effect, ItemRarity rarity, bool showRange, string legendaryID = null)
{
return GetEffectText(effect, rarity, showRange, legendaryID, null);
}

public static string GetEffectText(MagicItemEffect effect, MagicItemEffectDefinition.ValueDef valuesOverride)
public static string GetEffectText(MagicItemEffect effect, ItemRarity rarity, string itemName, bool showRange, string legendaryID = null)
{
return GetEffectText(effect, ItemRarity.Legendary, false, null, valuesOverride);
return GetEffectText(effect, rarity, itemName, showRange, legendaryID, null);
}

public void ReplaceEffect(int index, MagicItemEffect newEffect)
Expand Down
52 changes: 39 additions & 13 deletions EpicLoot/MagicItemEffectDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,20 @@ public class ValuesPerRarityDef
public ValueDef Mythic;
}

[Serializable]
public class ValuesPerItemNameDef
{
public List<string> ItemNames = new List<string>();
public ValuesPerRarityDef ValuesPerRarity = new ValuesPerRarityDef();
}

public string Type { get; set; }

public string DisplayText = "";
public string Description = "";
public MagicItemEffectRequirements Requirements = new MagicItemEffectRequirements();
public ValuesPerRarityDef ValuesPerRarity = new ValuesPerRarityDef();
public List<ValuesPerItemNameDef> ValuesPerItemName = new List<ValuesPerItemNameDef>();
public float SelectionWeight = 1;
public bool CanBeAugmented = true;
public bool CanBeDisenchanted = true;
Expand Down Expand Up @@ -336,20 +344,38 @@ public bool HasRarityValues()
return ValuesPerRarity.Magic != null && ValuesPerRarity.Epic != null && ValuesPerRarity.Rare != null && ValuesPerRarity.Legendary != null;
}

public ValueDef GetValuesForRarity(ItemRarity itemRarity)
public ValueDef GetValuesForRarity(ItemRarity itemRarity, string itemName)
{
switch (itemRarity)
{
case ItemRarity.Magic: return ValuesPerRarity.Magic;
case ItemRarity.Rare: return ValuesPerRarity.Rare;
case ItemRarity.Epic: return ValuesPerRarity.Epic;
case ItemRarity.Legendary: return ValuesPerRarity.Legendary;
case ItemRarity.Mythic:
// TODO: Mythic Hookup
return null;//ValuesPerRarity.Mythic;
default:
throw new ArgumentOutOfRangeException(nameof(itemRarity), itemRarity, null);
ValueDef ValueForRarity(ValuesPerRarityDef valuesPerRarity)
{
switch (itemRarity)
{
case ItemRarity.Magic: return valuesPerRarity.Magic;
case ItemRarity.Rare: return valuesPerRarity.Rare;
case ItemRarity.Epic: return valuesPerRarity.Epic;
case ItemRarity.Legendary: return valuesPerRarity.Legendary;
case ItemRarity.Mythic:
// TODO: Mythic Hookup
return null;//ValuesPerRarity.Mythic;
default:
throw new ArgumentOutOfRangeException(nameof(itemRarity), itemRarity, null);
}
}

if (string.IsNullOrEmpty(itemName) || ValuesPerItemName == null)
{
return ValueForRarity(ValuesPerRarity);
}

for (var i = 0; i < ValuesPerItemName.Count; i++)
{
if (ValuesPerItemName[i].ItemNames.Contains(itemName))
{
return ValueForRarity(ValuesPerItemName[i].ValuesPerRarity);
}
}

return ValueForRarity(ValuesPerRarity);
}
}

Expand Down Expand Up @@ -426,7 +452,7 @@ public static bool IsValuelessEffect(string effectType, ItemRarity rarity)
return false;
}

return effectDef.GetValuesForRarity(rarity) == null;
return effectDef.GetValuesForRarity(rarity, null) == null;
}
}
}
2 changes: 1 addition & 1 deletion EpicLoot/Multiplayer_Player_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private static bool DoCheck(Player player, ZDO zdo, string equipKey, string lege
itemData = targetItemData.Clone();
itemData.m_durability = float.PositiveInfinity;
var magicItemComponent = itemData.Data().GetOrCreate<MagicItemComponent>();
var stubMagicItem = new MagicItem { Rarity = ItemRarity.Legendary, LegendaryID = zdoLegendaryID };
var stubMagicItem = new MagicItem { Rarity = ItemRarity.Legendary, ItemName = itemData.m_shared.m_name, LegendaryID = zdoLegendaryID };
magicItemComponent.SetMagicItem(stubMagicItem);

ForceResetVisEquipment(player, itemData);
Expand Down
2 changes: 1 addition & 1 deletion EpicLoot/Terminal_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ private static void ReplaceMagicEffect(ItemDrop.ItemData itemData, MagicItem mag
return;
}

var replacementEffect = LootRoller.RollEffect(replacementEffectDef, magicItem.Rarity);
var replacementEffect = LootRoller.RollEffect(replacementEffectDef, magicItem.Rarity, itemData.m_shared.m_name);
magicItem.Effects[index] = replacementEffect;
itemData.SaveMagicItem(magicItem);
}
Expand Down
3 changes: 2 additions & 1 deletion EpicLoot/TextsDialog_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public static void AddMagicEffectsPage(TextsDialog textsDialog, Player player)
{
var effect = entry2.Key;
var item = entry2.Value;
t.AppendLine($" <color=#c0c0c0ff>- {MagicItem.GetEffectText(effect, item.GetRarity(), false)} ({item.GetDecoratedName()})</color>");
var magicItem = item.GetMagicItem();
t.AppendLine($" <color=#c0c0c0ff>- {MagicItem.GetEffectText(effect, item.GetRarity(), item.m_shared.m_name, false, magicItem?.LegendaryID)} ({item.GetDecoratedName()})</color>");
}

t.AppendLine();
Expand Down