/// <summary> /// Removes all bounties from the given player. /// </summary> /// <param name="targetPlayerName">Player from whom to remove bounties.</param> /// <returns>BountyPostResult, detailing success of the operation, or if it failed, why.</returns> public static OperationResult RemoveBounty(string targetPlayerName) { var result = new OperationResult(); var targetPlayer = GetByName(targetPlayerName); if (targetPlayer == null) { result.Message = $"Player {targetPlayerName} doesn't exist."; return(result); } BountyRepository.RemoveAllForPlayer(targetPlayer.Id); return(result); }
/// <summary> /// Posts a bounty from one player to another /// </summary> /// <param name="postingPlayerName">Name of the player posting the bounty</param> /// <param name="targetPlayerName">Player who will have the bounty posted against them.</param> /// <param name="bountyValue">Value of the bounty on the target</param> /// <returns>BountyPostResult, detailing success of the operation, or if it failed, why.</returns> public static OperationResult PostBounty(string postingPlayerName, string targetPlayerName, int bountyValue) { var result = new OperationResult(); var postingPlayer = GetByName(postingPlayerName); if (postingPlayer == null) { result.Message = $"Posting player ${postingPlayerName} does not exist."; return(result); } var targetPlayer = GetByName(targetPlayerName); if (targetPlayer == null) { result.Message = $"Target player ${targetPlayerName} does not exist."; return(result); } if (postingPlayer.NetWorth.Value < bountyValue) { result.Message = $"You don't have enough Net Worth to back the bounty on ${targetPlayerName}. Use !NETWORTH ME to see your accumulated value."; return(result); } postingPlayer.NetWorth.Value -= bountyValue; Update(postingPlayer); var bounty = new Bounty { TargetPlayerId = targetPlayer.Id, PostedDate = DateTime.Now, Value = bountyValue }; BountyRepository.Create(bounty); return(result); }
/// <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); }
/// <summary> /// Claims a bounty, with credit going to the claiming player. /// </summary> /// <param name="claimingPlayerName">Name of the player claiming the bounty.</param> /// <param name="targetPlayerName">Name of the player against whom bounties were claimed.</param> /// <returns>BountyPostResult, detailing success of the operation, or if it failed, why.</returns> public static OperationResult ClaimBounty(string claimingPlayerName, string targetPlayerName) { var result = new OperationResult(); var claimingPlayer = GetByName(claimingPlayerName); if (claimingPlayer == null) { result.Message = $"Player {claimingPlayerName} doesn't exist."; return(result); } var targetPlayer = GetByName(targetPlayerName); if (targetPlayer == null) { result.Message = $"Player {targetPlayerName} doesn't exist."; return(result); } BountyRepository.UpdateWithClaim(targetPlayer.Id, claimingPlayer.Id); return(result); }