File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments