/// <summary> /// Gets a List of DiplomaticEntities that are in a non neutral state to the sender DiplomaticEntity /// </summary> /// <param name="sender"></param> /// <param name="target"></param> /// <returns></returns> public List <FullDiplomaticRelationProposals> getAllContacts(DiplomaticEntity sender, Relation?filter = null) { //fetch user parent data if (sender.group != null) { return(getAllContacts(sender.group, filter)); } List <FullDiplomaticRelationProposals> Diplomatics = new List <FullDiplomaticRelationProposals>(); if (DiplomaticEntityState.ContainsKey(sender)) { foreach (var contact in DiplomaticEntityState[sender]) { if (filter != null) { if (contact.Value != filter) { continue; } } FullDiplomaticRelationProposals Prop = new FullDiplomaticRelationProposals(sender, contact.Key, (int)contact.Value, (int)contact.Value, (int)contact.Value); Diplomatics.Add(Prop); } } return(Diplomatics); }
/// <summary> /// Gets a bidirectional relation between user and target. Traverses recursively up, so that alliance relations are used /// </summary> /// <param name="user"></param> /// <param name="target"></param> /// <returns></returns> private FullDiplomaticRelationProposals getFullDiplomaticRelationProposals(DiplomaticEntity user, DiplomaticEntity target) { //fetch user parent data if (user.group != null) { FullDiplomaticRelationProposals proposal = getFullDiplomaticRelationProposals(user.group, target); proposal.sender = user; proposal.target = target; return(proposal); } //fetch target parent data if (target.group != null) { FullDiplomaticRelationProposals proposal = getFullDiplomaticRelationProposals(user, target.group); proposal.sender = user; proposal.target = target; return(proposal); } //no more parents left - fetch data Relation offer = Relation.Neutral; Relation received = Relation.Neutral; Relation current = Relation.Neutral; if (DiplomaticEntityState.ContainsKey(user) && DiplomaticEntityState[user].ContainsKey(target)) { offer = DiplomaticEntityState[user][target]; } if (DiplomaticEntityState.ContainsKey(target) && DiplomaticEntityState[target].ContainsKey(user)) { received = DiplomaticEntityState[target][user]; } if (target is User) { if (((User)target).AiId > 0 && ((User)target).AiRelation < (int)Relation.Neutral) { received = UserRelations.Min(received, ((Relation)((User)target).AiRelation)); } } current = Min(offer, received); FullDiplomaticRelationProposals fullDiplomatics = new FullDiplomaticRelationProposals( user, target, (int)offer, (int)received, (int)current ); return(fullDiplomatics); }