/// <summary> /// Update <see cref="Reputation"/> for supplied <see cref="Faction"/> and value. /// </summary> /// <remarks> /// Value is a delta, if a negative value is supplied it will be deducted from the existing reputation if any. /// </remarks> public void UpdateReputation(Faction factionId, float value) { FactionNode faction = FactionManager.Instance.GetFaction(factionId); if (faction == null) { throw new ArgumentException($"Invalid faction id {factionId}!"); } if (!reputations.TryGetValue(factionId, out Reputation reputation)) { reputation = new Reputation(faction, value); reputations.Add(reputation.Id, reputation); } else { reputation.Amount += value; } owner.Session.EnqueueMessageEncrypted(new ServerReputationUpdate { FactionId = factionId, Value = value }); }
/// <summary> /// Link <see cref="RelationshipNode"/> with supplied <see cref="FactionNode"/>. /// </summary> public void Link(FactionNode node) { if (Node != null) { throw new InvalidOperationException(); } Node = node; }
/// <summary> /// Get <see cref="Reputation"/> for supplied <see cref="Faction"/>. /// </summary> public Reputation GetReputation(Faction factionId) { FactionNode faction = FactionManager.Instance.GetFaction(factionId); if (faction == null) { throw new ArgumentException($"Invalid faction id {factionId}!"); } return(reputations.TryGetValue(factionId, out Reputation reputation) ? reputation : null); }
/// <summary> /// Create a new <see cref="ReputationManager"/> from existing <see cref="CharacterModel"/> database model. /// </summary> public ReputationManager(Player player, CharacterModel model) { owner = player; foreach (CharacterReputation reputationModel in model.Reputation) { FactionNode faction = FactionManager.Instance.GetFaction((Faction)reputationModel.FactionId); if (faction == null) { throw new DatabaseDataException($"Character {model.Id} has invalid faction {reputationModel.FactionId} stored!"); } var reputation = new Reputation(faction, reputationModel); reputations.Add(reputation.Id, reputation); } }
/// <summary> /// Return <see cref="FactionLevel"/> /// </summary> public FactionLevel?GetFriendshipFactionLevel(Faction factionId) { foreach (RelationshipNode relationship in relationships) { if (relationship.Node.FactionId == factionId) { return((FactionLevel)relationship.Entry.FactionLevel); } FactionNode node = relationship.Node.GetDescendent(factionId); if (node != null) { return((FactionLevel)relationship.Entry.FactionLevel); } } return(null); }
/// <summary> /// Traverse down tree looking for <see cref="FactionNode"/> for supplied <see cref="Faction"/>. /// </summary> public FactionNode GetDescendent(Faction factionId) { foreach (FactionNode child in children) { if (child.FactionId == factionId) { return(child); } FactionNode ss = child.GetDescendent(factionId); if (ss != null) { return(ss); } } return(null); }
/// <summary> /// Link <see cref="FactionNode"/> with supplied parent and child <see cref="FactionNode"/>'s. /// </summary> public void Link(FactionNode parentNode, List <FactionNode> childNodes, List <FactionNode> relationshipNodes) { if (Parent != null) { throw new InvalidOperationException(); } if (children != null) { throw new InvalidOperationException(); } Parent = parentNode; children = childNodes.ToImmutableList(); foreach (RelationshipNode relationship in relationships) { relationship.Link(relationshipNodes.SingleOrDefault(n => n.FactionId == relationship.Id)); } }