示例#1
0
        /// <summary>
        /// Adds a certain amount of fame (or disrepute) for a player, to their relationship with a faction.
        /// </summary>
        /// <param name="playerName">Name of the player to change reputation for</param>
        /// <param name="factionName">Faction with which reputation will be changed</param>
        /// <param name="amount">Amount by which reputation will change</param>
        public static OperationResult ChangeFactionStanding(string playerName, string factionName, int amount)
        {
            var result = new OperationResult();

            var player = GetByName(playerName);

            if (player == null)
            {
                result.Message = $"Player {playerName} has no entry in the Penumbra database.";
                return(result);
            }

            var faction = FactionRepository.GetByName(factionName);

            if (faction == null)
            {
                result.Message = $"Faction {factionName} has no entry in the Penumbra database.";
                return(result);
            }

            var relevantReputation = player.Reputations.FirstOrDefault(r => r.Id == faction.Id);

            if (relevantReputation == null)
            {
                relevantReputation = new Reputation
                {
                    PlayerId  = player.Id,
                    FactionId = faction.Id,
                    Standing  = amount
                };

                ReputationRepository.Create(relevantReputation);
            }
            else
            {
                relevantReputation.Standing += amount;

                ReputationRepository.Update(relevantReputation);
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Gets an existing player record by name.
        /// </summary>
        /// <param name="name">Name to look for.</param>
        /// <returns>Player if found, otherwise null.</returns>
        public static Player GetByName(string name)
        {
            var existingPlayer = PlayerRepository.GetByName(name);

            if (existingPlayer == null)
            {
                return(null);
            }

            var existingNetWorth = NetWorthRepository.GetByPlayerId(existingPlayer.Id);

            if (existingNetWorth == null)
            {
                throw new ApplicationException($"Could not find a NetWorths record for Player ID #{existingPlayer.Id}");
            }

            var existingBounties = BountyRepository.GetByTargetPlayerId(existingPlayer.Id);

            if (existingBounties == null)
            {
                existingBounties = new List <Bounty>();
            }

            var existingReputations = ReputationRepository.GetByPlayerId(existingPlayer.Id);

            if (existingReputations == null)
            {
                existingReputations = new List <Reputation>();
            }

            existingPlayer.NetWorth    = existingNetWorth;
            existingPlayer.Bounties    = existingBounties;
            existingPlayer.Reputations = existingReputations;

            return(existingPlayer);
        }
 public ReputationService(ReputationRepository repo)
 {
     _repo = repo;
 }
示例#4
0
 public ReputationCommands(ReputationRepository reputationRepository)
 {
     this._reputationRepository = reputationRepository;
 }