Skip to content

Commit d9da19f

Browse files
committed
entity and IsHidden fixes
1 parent fac04b1 commit d9da19f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+664
-586
lines changed

Intersect.Client.Core/Core/Input.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static void OnKeyPressed(Keys modifier, Keys key)
132132
{
133133
// We've closed our windows, don't do anything else. :)
134134
}
135-
else if (Globals.Me is {} me && me.TargetIndex != default && me.Status.All(s => s.Type != SpellEffect.Taunt))
135+
else if (Globals.Me is {} me && me.TargetId != default && me.Status.All(s => s.Type != SpellEffect.Taunt))
136136
{
137137
_ = me.ClearTarget();
138138
}

Intersect.Client.Core/Entities/Animation.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,7 @@ public void Show()
265265
Hidden = false;
266266
}
267267

268-
public bool ParentGone()
269-
{
270-
if (mParent != null && mParent.IsDisposed())
271-
{
272-
return true;
273-
}
274-
275-
return false;
276-
}
268+
public bool ParentGone() => mParent is { IsDisposed: true };
277269

278270
public void Dispose()
279271
{

Intersect.Client.Core/Entities/Entity.cs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ public Guid[] Equipment
7373
}
7474

7575
_equipment = value;
76-
LoadAnimationTexture(string.IsNullOrWhiteSpace(TransformedSprite) ? Sprite : TransformedSprite, SpriteAnimations.Weapon);
76+
LoadAnimationTexture(
77+
string.IsNullOrWhiteSpace(TransformedSprite) ? Sprite : TransformedSprite,
78+
SpriteAnimations.Weapon
79+
);
7780
}
7881
}
7982

80-
IReadOnlyList<int> IEntity.EquipmentSlots => [.. MyEquipment];
83+
IReadOnlyList<int> IEntity.EquipmentSlots => [..MyEquipment];
8184

8285
public Animation?[] EquipmentAnimations { get; set; } = new Animation[Options.Instance.Equipment.Slots.Count];
8386

@@ -114,7 +117,8 @@ public Guid[] Equipment
114117
//Vitals & Stats
115118
public long[] MaxVital { get; set; } = new long[Enum.GetValues<Vital>().Length];
116119

117-
IReadOnlyList<long> IEntity.MaxVitals => [.. MaxVital];
120+
IReadOnlyDictionary<Vital, long> IEntity.MaxVitals =>
121+
Enum.GetValues<Vital>().ToDictionary(vital => vital, vital => MaxVital[(int)vital]);
118122

119123
protected Pointf mOrigin = Pointf.Empty;
120124

@@ -179,7 +183,8 @@ public Guid SpellCast
179183

180184
public int[] Stat { get; set; } = new int[Enum.GetValues<Stat>().Length];
181185

182-
IReadOnlyList<int> IEntity.Stats => [.. Stat];
186+
IReadOnlyDictionary<Stat, int> IEntity.Stats =>
187+
Enum.GetValues<Stat>().ToDictionary(stat => stat, stat => Stat[(int)stat]);
183188

184189
public GameTexture? Texture { get; set; }
185190

@@ -205,7 +210,8 @@ public Guid SpellCast
205210

206211
public long[] Vital { get; set; } = new long[Enum.GetValues<Vital>().Length];
207212

208-
IReadOnlyList<long> IEntity.Vitals => [.. Vital];
213+
IReadOnlyDictionary<Vital, long> IEntity.Vitals =>
214+
Enum.GetValues<Vital>().ToDictionary(vital => vital, vital => Vital[(int)vital]);
209215

210216
public int WalkFrame { get; set; }
211217

@@ -454,7 +460,7 @@ public virtual void Load(EntityPacket? packet)
454460
}
455461
}
456462
}
457-
else if (Id != Guid.Empty && Id == Globals.Me.TargetIndex)
463+
else if (Id != Guid.Empty && Id == Globals.Me.TargetId)
458464
{
459465
if (Globals.Me.TargetBox == null)
460466
{
@@ -517,10 +523,7 @@ public void ClearAnimations(List<Animation>? anims)
517523
}
518524
}
519525

520-
public virtual bool IsDisposed()
521-
{
522-
return mDisposed;
523-
}
526+
public bool IsDisposed => mDisposed;
524527

525528
public virtual void Dispose()
526529
{
@@ -1617,19 +1620,8 @@ public float GetLabelLocation(LabelType type)
16171620
return y;
16181621
}
16191622

1620-
public long GetShieldSize()
1621-
{
1622-
long shieldSize = 0;
1623-
foreach (var status in Status)
1624-
{
1625-
if (status.Type == SpellEffect.Shield)
1626-
{
1627-
shieldSize += status.Shield[(int)Enums.Vital.Health];
1628-
}
1629-
}
1630-
1631-
return shieldSize;
1632-
}
1623+
public long ShieldSize =>
1624+
Status.Sum(status => status.Type == SpellEffect.Shield ? status.Shield[(int)Enums.Vital.Health] : 0);
16331625

16341626
protected virtual bool ShouldDrawHpBar
16351627
{
@@ -1645,7 +1637,7 @@ protected virtual bool ShouldDrawHpBar
16451637
return true;
16461638
}
16471639

1648-
if (GetShieldSize() > 0)
1640+
if (ShieldSize > 0)
16491641
{
16501642
return true;
16511643
}
@@ -1700,7 +1692,7 @@ public void DrawHpBar()
17001692

17011693
// Check for shields
17021694
var maxVital = MaxVital[(int)Enums.Vital.Health];
1703-
var shieldSize = GetShieldSize();
1695+
var shieldSize = ShieldSize;
17041696

17051697
if (shieldSize + Vital[(int)Enums.Vital.Health] > maxVital)
17061698
{

Intersect.Client.Core/Entities/Player.cs

Lines changed: 82 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Intersect.Core;
2020
using Intersect.Enums;
2121
using Intersect.Extensions;
22+
using Intersect.Framework.Reflection;
2223
using Intersect.GameObjects;
2324
using Intersect.GameObjects.Maps;
2425
using Intersect.Network.Packets.Server;
@@ -97,7 +98,7 @@ public override Direction MoveDir
9798

9899
public PlayerStatusWindow? StatusWindow { get; set; }
99100

100-
public Guid TargetIndex { get; set; }
101+
public Guid TargetId { get; set; }
101102

102103
TargetType IPlayer.TargetType => (TargetType)TargetType;
103104

@@ -284,11 +285,11 @@ public override bool Update()
284285
TargetBox = new EntityBox(Interface.Interface.GameUi.GameCanvas, EntityType.Player, null);
285286
TargetBox.Hide();
286287
}
287-
else if (TargetIndex != default)
288+
else if (TargetId != default)
288289
{
289-
if (!Globals.Entities.TryGetValue(TargetIndex, out var foundEntity))
290+
if (!Globals.Entities.TryGetValue(TargetId, out var foundEntity))
290291
{
291-
foundEntity = TargetBox?.MyEntity?.MapInstance?.Entities.FirstOrDefault(entity => entity.Id == TargetIndex) as Entity;
292+
foundEntity = TargetBox?.MyEntity?.MapInstance?.Entities.FirstOrDefault(entity => entity.Id == TargetId) as Entity;
292293
}
293294

294295
if (foundEntity == default || foundEntity.IsHidden || foundEntity.IsStealthed)
@@ -487,7 +488,7 @@ public void TryUseItem(int index)
487488
if (!IsItemOnCooldown(index) &&
488489
index >= 0 && index < Globals.Me?.Inventory.Length && Globals.Me.Inventory[index]?.Quantity > 0)
489490
{
490-
PacketSender.SendUseItem(index, TargetIndex);
491+
PacketSender.SendUseItem(index, TargetId);
491492
}
492493
}
493494

@@ -1224,7 +1225,7 @@ public void TryUseSpell(int index)
12241225
return;
12251226
}
12261227

1227-
PacketSender.SendUseSpell(index, TargetIndex);
1228+
PacketSender.SendUseSpell(index, TargetId);
12281229
}
12291230
}
12301231

@@ -1639,39 +1640,43 @@ public void AutoTarget()
16391640

16401641
mLastEntitySelected = targetedEntity;
16411642

1642-
if (TargetIndex != targetedEntity.Id)
1643+
if (TargetId != targetedEntity.Id)
16431644
{
1644-
SetTargetBox(targetedEntity);
1645-
TargetIndex = targetedEntity.Id;
1646-
TargetType = 0;
1645+
Target = targetedEntity;
16471646
}
16481647
}
16491648

1650-
private void SetTargetBox(Entity? en)
1649+
private void SetTargetBox(IEntity? targetEntity)
16511650
{
1652-
if (en == null)
1651+
switch (targetEntity)
16531652
{
1654-
TargetBox?.SetEntity(null);
1655-
TargetBox?.Hide();
1656-
PacketSender.SendTarget(Guid.Empty);
1657-
return;
1658-
}
1653+
case null:
1654+
{
1655+
// ReSharper disable once InvertIf
1656+
if (TargetBox is { } targetBox)
1657+
{
1658+
TargetBox.SetEntity(null);
1659+
if (targetBox.IsVisible)
1660+
{
1661+
TargetBox.Hide();
1662+
}
1663+
}
1664+
return;
1665+
}
16591666

1660-
if (en is Player)
1661-
{
1662-
TargetBox?.SetEntity(en, EntityType.Player);
1663-
}
1664-
else if (en is Event)
1665-
{
1666-
TargetBox?.SetEntity(en, EntityType.Event);
1667-
}
1668-
else
1669-
{
1670-
TargetBox?.SetEntity(en, EntityType.GlobalEntity);
1667+
case Player:
1668+
TargetBox?.SetEntity(targetEntity, EntityType.Player);
1669+
break;
1670+
case Event:
1671+
TargetBox?.SetEntity(targetEntity, EntityType.Event);
1672+
break;
1673+
default:
1674+
TargetBox?.SetEntity(targetEntity, EntityType.GlobalEntity);
1675+
break;
16711676
}
16721677

16731678
TargetBox?.Show();
1674-
PacketSender.SendTarget(en.Id);
1679+
PacketSender.SendTarget(targetEntity.Id);
16751680
}
16761681

16771682
private void AutoTurnToTarget(Entity en)
@@ -1999,24 +2004,16 @@ public bool TryTarget()
19992004
}
20002005
}
20012006

2002-
if (bestMatch != null && bestMatch.Id != TargetIndex)
2007+
if (bestMatch != null && bestMatch.Id != TargetId)
20032008
{
2004-
var targetType = bestMatch is Event ? 1 : 0;
2005-
2006-
SetTargetBox(bestMatch as Entity);
2009+
Target = bestMatch;
20072010

2008-
if (bestMatch is Player)
2011+
if (bestMatch is Player && Interface.Interface.GameUi.IsAdminWindowOpen)
20092012
{
2010-
//Select in admin window if open
2011-
if (Interface.Interface.GameUi.IsAdminWindowOpen)
2012-
{
2013-
Interface.Interface.GameUi.AdminWindowSelectName(bestMatch.Name);
2014-
}
2013+
// Select in admin window if open
2014+
Interface.Interface.GameUi.AdminWindowSelectName(bestMatch.Name);
20152015
}
20162016

2017-
TargetType = targetType;
2018-
TargetIndex = bestMatch.Id;
2019-
20202017
return true;
20212018
}
20222019

@@ -2068,27 +2065,58 @@ public bool TryTarget(IEntity entity, bool force = false)
20682065
}
20692066
}
20702067

2071-
if (TargetIndex != entity.Id)
2068+
if (TargetId != entity.Id)
20722069
{
2073-
SetTargetBox(entity as Entity);
2074-
TargetType = targetType;
2075-
TargetIndex = entity.Id;
2070+
Target = entity;
20762071
}
20772072

20782073
return true;
20792074

20802075
}
20812076

2082-
public bool ClearTarget()
2077+
private IEntity? _target;
2078+
2079+
public IEntity? Target
20832080
{
2084-
SetTargetBox(null);
2081+
get => _target;
2082+
set
2083+
{
2084+
if (value == _target)
2085+
{
2086+
return;
2087+
}
2088+
2089+
_target = value;
2090+
2091+
if (value == null)
2092+
{
2093+
TargetId = default;
2094+
TargetType = 0;
2095+
}
2096+
else
2097+
{
2098+
TargetId = value.Id;
2099+
TargetType = value is Event ? 1 : 0;
2100+
}
2101+
2102+
SetTargetBox(value as Entity);
2103+
}
2104+
}
20852105

2086-
if (TargetIndex == default && TargetType == -1)
2106+
public bool ClearTarget()
2107+
{
2108+
if (TargetId == default && TargetType == -1)
20872109
{
20882110
return false;
20892111
}
20902112

2091-
TargetIndex = Guid.Empty;
2113+
if (TargetId != default)
2114+
{
2115+
PacketSender.SendTarget(default);
2116+
SetTargetBox(null);
2117+
}
2118+
2119+
TargetId = default;
20922120
TargetType = -1;
20932121
return true;
20942122
}
@@ -2629,7 +2657,7 @@ public void DrawTargets()
26292657
continue;
26302658
}
26312659

2632-
if (TargetType != 0 || TargetIndex != en.Value.Id)
2660+
if (TargetType != 0 || TargetId != en.Value.Id)
26332661
{
26342662
continue;
26352663
}
@@ -2668,7 +2696,7 @@ public void DrawTargets()
26682696
continue;
26692697
}
26702698

2671-
if (TargetType != 1 || TargetIndex != en.Value.Id)
2699+
if (TargetType != 1 || TargetId != en.Value.Id)
26722700
{
26732701
continue;
26742702
}
@@ -2706,7 +2734,7 @@ public void DrawTargets()
27062734
{
27072735
if (en.Value is not (Projectile or Resource))
27082736
{
2709-
if (TargetType != 0 || TargetIndex != en.Value.Id)
2737+
if (TargetType != 0 || TargetId != en.Value.Id)
27102738
{
27112739
en.Value.DrawTarget((int)Enums.TargetType.Hover);
27122740
ToggleTargetContextMenu(en.Value);
@@ -2731,7 +2759,7 @@ public void DrawTargets()
27312759
en.Value is Player player && Globals.Me?.IsInMyParty(player) == true) &&
27322760
en.Value.WorldPos.Contains(mouseInWorld.X, mouseInWorld.Y))
27332761
{
2734-
if (TargetType != 1 || TargetIndex != en.Value.Id)
2762+
if (TargetType != 1 || TargetId != en.Value.Id)
27352763
{
27362764
en.Value.DrawTarget((int)Enums.TargetType.Hover);
27372765
ToggleTargetContextMenu(en.Value);

Intersect.Client.Core/General/Globals.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public static Entity GetEntity(Guid id, EntityType type)
225225
{
226226
var entity = Entities[id];
227227

228-
if (!entity.IsDisposed() && entity.Type == type)
228+
if (!entity.IsDisposed && entity.Type == type)
229229
{
230230
EntitiesToDispose.Remove(entity.Id);
231231

0 commit comments

Comments
 (0)