Skip to content

Commit 485d847

Browse files
committed
avoid duplicate in Nosmates
1 parent e472797 commit 485d847

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

TaleKit/Game/Entities/Entity.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,32 @@ public enum EntityType
1010
Drop = 9
1111
}
1212

13-
public abstract class Entity
13+
public abstract class Entity : IEquatable<Entity>
1414
{
1515
public int Id { get; set; }
1616
public string Name { get; set; }
1717
public Position Position { get; set; }
1818
public Map Map { get; set; }
1919

2020
public abstract EntityType EntityType { get; }
21+
22+
public bool Equals(Entity other)
23+
{
24+
if (other is null) return false;
25+
if (ReferenceEquals(this, other)) return true;
26+
return Id == other.Id && EntityType == other.EntityType;
27+
}
28+
29+
public override bool Equals(object obj)
30+
{
31+
if (obj is null) return false;
32+
if (ReferenceEquals(this, obj)) return true;
33+
if (obj.GetType() != GetType()) return false;
34+
return Equals((Entity)obj);
35+
}
36+
37+
public override int GetHashCode()
38+
{
39+
return HashCode.Combine(Id, (int)EntityType);
40+
}
2141
}

TaleKit/Game/Entities/Player.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ public class Player : LivingEntity
77
public int Level { get; set; }
88
public int HeroLevel { get; set; }
99

10-
public List<Nosmate> Nosmates { get; set; } = [];
10+
public HashSet<Nosmate> Nosmates { get; set; } = [];
1111
}

0 commit comments

Comments
 (0)