示例#1
0
 public void DestroyArtefact(ArtefactId id)
 {
     if (!Account.KnowsArtefact(id) || Account.GetArtefact(id).OwnerId != Account.Id)
     {
         throw new ArgumentException("Tried to destroy artefact not owned");
     }
     OnDestroyArtefact(Account.GetArtefact(id));
 }
示例#2
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (GroupId != null ? GroupId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ArtefactId != null ? ArtefactId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Version != null ? Version.GetHashCode() : 0);
         return(hashCode);
     }
 }
示例#3
0
        public void ForgetArtefact(ArtefactId id)
        {
            if (!KnowsArtefact(id))
            {
                return;
            }
            var artefact = GetArtefact(id);

            _knownArtefacts.Remove(id);
            if (artefact.OwnerId == default || !IsConnectedTo(artefact.OwnerId))
            {
                return;
            }
            GetPeer(artefact.OwnerId).RemoveArtefact(id);
        }
示例#4
0
 public Artefact GetArtefact(ArtefactId id)
 => _artefacts.TryGetValue(id, out var artefact)
     ? artefact
     : throw new NotFound <Artefact>(nameof(id), id.ToString());
示例#5
0
 public bool HasArtefact(ArtefactId id)
 => _artefacts.ContainsKey(id);
示例#6
0
 public void RemoveArtefact(ArtefactId id)
 {
     _artefacts.Remove(id);
 }
示例#7
0
 public Artefact(ArtefactId id, string name, AgentId ownerId)
 {
     Id      = id;
     Name    = name;
     OwnerId = ownerId;
 }
示例#8
0
 public Artefact GetArtefact(ArtefactId id)
 => _knownArtefacts[id];
示例#9
0
 public bool KnowsArtefact(ArtefactId id)
 => _knownArtefacts.ContainsKey(id);