Skip to content
Merged
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
172 changes: 68 additions & 104 deletions Intersect.Client.Core/Interface/Game/Character/CharacterWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using Intersect.Enums;
using Intersect.Framework.Core.GameObjects.Items;
using Intersect.Framework.Core.GameObjects.PlayerClass;
using Intersect.GameObjects;
using Intersect.Network.Packets.Server;

namespace Intersect.Client.Interface.Game.Character;

Expand Down Expand Up @@ -71,40 +69,24 @@ public partial class CharacterWindow
public int Y;

//Extra Buffs
Button _detailsButton;

ClassDescriptor mPlayer;

Label mHpRegen;

long HpRegenAmount;

Label mManaRegen;

long ManaRegenAmount;

Label mLifeSteal;

int LifeStealAmount = 0;

Label mAttackSpeed;

Label mExtraExp;

int ExtraExpAmount = 0;

Label mLuck;

int LuckAmount = 0;

Label mTenacity;

int TenacityAmount = 0;

Label mCooldownReduction;

int CooldownAmount = 0;

Label mManaSteal;

int ManaStealAmount = 0;

//Init
Expand Down Expand Up @@ -168,18 +150,12 @@ public CharacterWindow(Canvas gameCanvas)
Items[i].Setup();
}

var extraBuffsLabel = new Label(mCharacterWindow, "ExtraBuffsLabel");
extraBuffsLabel.SetText(Strings.Character.ExtraBuffs);

mHpRegen = new Label(mCharacterWindow, "HpRegen");
mManaRegen = new Label(mCharacterWindow, "ManaRegen");
mLifeSteal = new Label(mCharacterWindow, "Lifesteal");
mAttackSpeed = new Label(mCharacterWindow, "AttackSpeed");
mExtraExp = new Label(mCharacterWindow, "ExtraExp");
mLuck = new Label(mCharacterWindow, "Luck");
mTenacity = new Label(mCharacterWindow, "Tenacity");
mCooldownReduction = new Label(mCharacterWindow, "CooldownReduction");
mManaSteal = new Label(mCharacterWindow, "Manasteal");
_detailsButton = new Button(mCharacterWindow, nameof(_detailsButton))
{
Text = Strings.Character.ExtraBuffDetails,
};
_detailsButton.HoverEnter += UpdateExtraBuffTooltip; // Update Tooltip on hover.
UpdateExtraBuffTooltip(null, null); // Initial tooltip update.

mCharacterWindow.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
}
Expand Down Expand Up @@ -213,7 +189,7 @@ void _addAttackBtn_Clicked(Base sender, MouseButtonState arguments)
//Methods
public void Update()
{
if (mCharacterWindow.IsHidden)
if (mCharacterWindow.IsHidden || Globals.Me is null)
{
return;
}
Expand Down Expand Up @@ -375,72 +351,45 @@ public void Update()
mAddSpeedBtn.IsHidden =
Globals.Me.StatPoints == 0 || Globals.Me.Stat[(int) Stat.Speed] == Options.Instance.Player.MaxStat;

UpdateExtraBuffs();
UpdateEquippedItems();
}

private void UpdateEquippedItems(bool updateExtraBuffs = false)
{
if (Globals.Me is not { } player)
{
return;
}

for (var i = 0; i < Options.Instance.Equipment.Slots.Count; i++)
{
if (Globals.Me.MyEquipment[i] > -1 && Globals.Me.MyEquipment[i] < Options.Instance.Player.MaxInventory)
var invSlot = player.MyEquipment[i];
if (invSlot < 0 || invSlot >= Options.Instance.Player.MaxInventory)
{
if (Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemId != Guid.Empty)
{
Items[i]
.Update(
Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemId,
Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemProperties
);

UpdateExtraBuffs(Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemId);
}
else
{
Items[i].Update(Guid.Empty, mItemProperties);
}
Items[i].Update(Guid.Empty, mItemProperties);
continue;
}
else

var item = player.Inventory[invSlot];
if (item.ItemId == Guid.Empty)
{
Items[i].Update(Guid.Empty, mItemProperties);
continue;
}
}
}

/// <summary>
/// Update Extra Buffs Effects like hp/mana regen and items effect types
/// </summary>
public void UpdateExtraBuffs()
{
mPlayer = ClassDescriptor.Get(Globals.Me?.Class ?? Guid.Empty);

//Getting HP and Mana Regen
if (mPlayer != null)
{
HpRegenAmount = mPlayer.VitalRegen[0];
mHpRegen.SetText(Strings.Character.HealthRegen.ToString(HpRegenAmount));
ManaRegenAmount = mPlayer.VitalRegen[1];
mManaRegen.SetText(Strings.Character.ManaRegen.ToString(ManaRegenAmount));
Items[i].Update(item.ItemId, item.ItemProperties);
if (updateExtraBuffs)
{
UpdateExtraBuffs(item.ItemId);
}
}

CooldownAmount = 0;
LifeStealAmount = 0;
TenacityAmount = 0;
LuckAmount = 0;
ExtraExpAmount = 0;
ManaStealAmount = 0;

mLifeSteal.SetText(Strings.Character.Lifesteal.ToString(0));
mExtraExp.SetText(Strings.Character.ExtraExp.ToString(0));
mLuck.SetText(Strings.Character.Luck.ToString(0));
mTenacity.SetText(Strings.Character.Tenacity.ToString(0));
mCooldownReduction.SetText(Strings.Character.CooldownReduction.ToString(0));
mManaSteal.SetText(Strings.Character.Manasteal.ToString(0));

mAttackSpeed.SetText(Strings.Character.AttackSpeed.ToString(Globals.Me.CalculateAttackTime() / 1000f));
}

/// <summary>
/// Update Extra Buffs Effects like hp/mana regen and items effect types
/// </summary>
/// <param name="itemId">Id of item to update extra buffs</param>
public void UpdateExtraBuffs(Guid itemId)
private void UpdateExtraBuffs(Guid itemId)
{
var item = ItemDescriptor.Get(itemId);

Expand All @@ -449,23 +398,21 @@ public void UpdateExtraBuffs(Guid itemId)
return;
}

//Getting HP and Mana Regen
if (item.VitalsRegen[0] != 0)
//Getting HP and Mana Regen from items
if (item.VitalsRegen[(int)Vital.Health] != 0)
{
HpRegenAmount += item.VitalsRegen[0];
mHpRegen?.SetText(Strings.Character.HealthRegen.ToString(HpRegenAmount));
HpRegenAmount += item.VitalsRegen[(int)Vital.Health];
}

if (item.VitalsRegen[1] != 0)
if (item.VitalsRegen[(int)Vital.Mana] != 0)
{
ManaRegenAmount += item.VitalsRegen[1];
mManaRegen?.SetText(Strings.Character.ManaRegen.ToString(ManaRegenAmount));
ManaRegenAmount += item.VitalsRegen[(int)Vital.Mana];
}

//Getting extra buffs
//Getting extra buffs from items
if (item.Effects.Find(effect => effect.Type != ItemEffect.None && effect.Percentage > 0) != default)
{
foreach(var effect in item.Effects)
foreach (var effect in item.Effects)
{
if (effect.Percentage <= 0)
{
Expand All @@ -476,39 +423,56 @@ public void UpdateExtraBuffs(Guid itemId)
{
case ItemEffect.CooldownReduction:
CooldownAmount += effect.Percentage;
mCooldownReduction?.SetText(Strings.Character.CooldownReduction.ToString(CooldownAmount));

break;
case ItemEffect.Lifesteal:
LifeStealAmount += effect.Percentage;
mLifeSteal?.SetText(Strings.Character.Lifesteal.ToString(LifeStealAmount));

break;
case ItemEffect.Tenacity:
TenacityAmount += effect.Percentage;
mTenacity?.SetText(Strings.Character.Tenacity.ToString(TenacityAmount));

break;
case ItemEffect.Luck:
LuckAmount += effect.Percentage;
mLuck?.SetText(Strings.Character.Luck.ToString(LuckAmount));

break;
case ItemEffect.EXP:
ExtraExpAmount += effect.Percentage;
mExtraExp?.SetText(Strings.Character.ExtraExp.ToString(ExtraExpAmount));

break;
case ItemEffect.Manasteal:
ManaStealAmount += effect.Percentage;
mManaSteal?.SetText(Strings.Character.Manasteal.ToString(ManaStealAmount));

break;
}
}
}
}

private void UpdateExtraBuffTooltip(Base? sender, EventArgs? arguments)
{
//Reset all values
HpRegenAmount = mPlayer?.VitalRegen[(int)Vital.Health] ?? 0;
ManaRegenAmount = mPlayer?.VitalRegen[(int)Vital.Mana] ?? 0;
CooldownAmount = 0;
LifeStealAmount = 0;
TenacityAmount = 0;
LuckAmount = 0;
ExtraExpAmount = 0;
ManaStealAmount = 0;

// Update extra buffs from equipped items
UpdateEquippedItems(true);

// Update tooltip with the current extra buffs
var tooltip = new System.Text.StringBuilder();
tooltip.AppendLine(Strings.Character.HealthRegen.ToString(HpRegenAmount));
tooltip.AppendLine(Strings.Character.ManaRegen.ToString(ManaRegenAmount));
tooltip.AppendLine(Strings.Character.Lifesteal.ToString(LifeStealAmount));
tooltip.AppendLine(Strings.Character.AttackSpeed.ToString(Globals.Me?.CalculateAttackTime() / 1000f));
tooltip.AppendLine(Strings.Character.ExtraExp.ToString(ExtraExpAmount));
tooltip.AppendLine(Strings.Character.Luck.ToString(LuckAmount));
tooltip.AppendLine(Strings.Character.Tenacity.ToString(TenacityAmount));
tooltip.AppendLine(Strings.Character.CooldownReduction.ToString(CooldownAmount));
tooltip.AppendLine(Strings.Character.Manasteal.ToString(ManaStealAmount));
_detailsButton.SetToolTipText(tooltip.ToString());
}

/// <summary>
/// Show the window
/// </summary>
Expand Down
51 changes: 26 additions & 25 deletions Intersect.Client.Core/Interface/Game/Character/EquipmentItem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics;
using Intersect.Client.Framework.File_Management;
using Intersect.Client.Framework.GenericClasses;
using Intersect.Client.Framework.Gwen.Control;
using Intersect.Client.Framework.Gwen.Control.EventArguments;
Expand All @@ -20,7 +22,7 @@ public partial class EquipmentItem

private ItemProperties mItemProperties = null;

private bool mTexLoaded;
private string? _loadedTexture;

private int mYindex;

Expand Down Expand Up @@ -110,32 +112,31 @@ public FloatRect RenderBounds()

public void Update(Guid currentItemId, ItemProperties itemProperties)
{
if (currentItemId != mCurrentItemId || !mTexLoaded)
if (!ItemDescriptor.TryGet(currentItemId, out var item))
{
mCurrentItemId = currentItemId;
mItemProperties = itemProperties;
var item = ItemDescriptor.Get(mCurrentItemId);
if (item != null)
{
var itemTex = Globals.ContentManager.GetTexture(Framework.Content.TextureType.Item, item.Icon);
if (itemTex != null)
{
ContentPanel.Show();
ContentPanel.Texture = itemTex;
ContentPanel.RenderColor = item.Color;
}
else
{
ContentPanel.Hide();
}
}
else
{
ContentPanel.Hide();
}
ContentPanel.Hide();
_loadedTexture = default;
return;
}

mTexLoaded = true;
if (currentItemId == mCurrentItemId && ContentPanel.Texture?.Name == _loadedTexture)
{
return;
}
}

mCurrentItemId = currentItemId;
mItemProperties = itemProperties;

if (GameContentManager.Current.GetTexture(Framework.Content.TextureType.Item, item.Icon) is not { } itemTexture)
{
ContentPanel.Hide();
_loadedTexture = default;
return;
}

ContentPanel.Show();
ContentPanel.Texture = itemTexture;
ContentPanel.RenderColor = item.Color;
_loadedTexture = ContentPanel.Texture?.Name;
}
}
2 changes: 1 addition & 1 deletion Intersect.Client.Core/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ public partial struct Character
public static LocalizedString Equipment = @"Equipment:";

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public static LocalizedString ExtraBuffs = @"Extra Buffs";
public static LocalizedString ExtraBuffDetails = @"Details";

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public static LocalizedString ExtraExp = @"Bonus EXP: {00}%";
Expand Down
Loading