private Item CreateItem(RewardInfo.ItemData itemData) { Item item = ItemManager.CreateByItemID(itemData.itemid, itemData.amount, itemData.skin); item.condition = itemData.condition; if (itemData.instanceData != null) { itemData.instanceData.Restore(item); } BaseProjectile weapon = item.GetHeldEntity() as BaseProjectile; if (weapon != null) { if (!string.IsNullOrEmpty(itemData.ammotype)) { weapon.primaryMagazine.ammoType = ItemManager.FindItemDefinition(itemData.ammotype); } weapon.primaryMagazine.contents = itemData.ammo; } if (itemData.contents != null) { foreach (var contentData in itemData.contents) { var newContent = ItemManager.CreateByItemID(contentData.itemid, contentData.amount); if (newContent != null) { newContent.condition = contentData.condition; newContent.MoveToContainer(item.contents); } } } return(item); }
private void ccmdBounty(ConsoleSystem.Arg arg) { if (arg.Connection != null) { return; } if (arg.Args == null || arg.Args.Length == 0) { SendReply(arg, "bounty view <target name or ID> - View active bounties on the specified player"); SendReply(arg, "bounty top - View the top 20 bounty hunters"); SendReply(arg, "bounty wanted - View the top 20 most wanted players"); SendReply(arg, "bounty clear <target name or ID> - Clear all active bounties on the specified player"); SendReply(arg, "bounty wipe - Wipe all bounty data"); return; } switch (arg.Args[0].ToLower()) { case "view": { if (arg.Args.Length < 2) { SendReply(arg, "Invalid command syntax! Type 'bounty' to see available commands"); return; } IPlayer targetPlayer = covalence.Players.FindPlayer(arg.Args[1]); if (targetPlayer == null) { SendReply(arg, "Unable to find a player with that name or ID"); return; } PlayerData playerData; if (!storedData.players.TryGetValue(ulong.Parse(targetPlayer.Id), out playerData) || playerData.activeBounties.Count == 0) { SendReply(arg, "That player does not have any active bounties"); return; } SendReply(arg, string.Format("{0} has {1} active bounties", targetPlayer.Name, playerData.activeBounties.Count)); foreach (var bounty in playerData.activeBounties) { RewardInfo rewardInfo = storedData.rewards[bounty.rewardId]; string reward = string.Empty; if (rewardInfo.rewardItems.Count > 1) { for (int i = 0; i < rewardInfo.rewardItems.Count; i++) { RewardInfo.ItemData itemData = rewardInfo.rewardItems.ElementAt(i); reward += (string.Format("{0}x {1}", itemData.amount, idToDisplayName[itemData.itemid]) + (i < rewardInfo.rewardItems.Count - 1 ? ", " : "")); } } else { reward = rewardInfo.econAmount > 0 ? string.Format("{0} economics", rewardInfo.econAmount) : string.Format("{0} rp", rewardInfo.rpAmount); } SendReply(arg, string.Format("Placed by {0} {1} ago. Reward: {2}", bounty.initiatorName, FormatTime(CurrentTime() - bounty.initiatedTime), reward)); } } return; case "top": IEnumerable <PlayerData> top20Hunters = storedData.players.Values.OrderByDescending(x => x.bountiesClaimed).Take(20); string hunterMessage = "Top 20 Hunters:"; foreach (PlayerData playerData in top20Hunters) { hunterMessage += string.Format("\n{0} - {1} bounties collected", playerData.displayName, playerData.bountiesClaimed); } SendReply(arg, hunterMessage); return; case "wanted": IEnumerable <PlayerData> top20Hunted = storedData.players.Values.OrderByDescending(x => x.totalWantedTime + x.GetCurrentWantedTime()).Take(20); string wantedMessage = "Top 20 Most Wanted:"; foreach (PlayerData playerData in top20Hunted) { wantedMessage += string.Format("\n{0} has all together been on the run for {1} with a total of {2} bounties", playerData.displayName, FormatTime(playerData.totalWantedTime + playerData.GetCurrentWantedTime()), playerData.totalBounties); } SendReply(arg, wantedMessage); return; case "clear": { if (arg.Args.Length < 2) { SendReply(arg, "Invalid command syntax! Type 'bounty' to see available commands"); return; } IPlayer targetPlayer = covalence.Players.FindPlayer(arg.Args[1]); if (targetPlayer == null) { SendReply(arg, "Unable to find a player with that name or ID"); return; } PlayerData playerData; if (!storedData.players.TryGetValue(ulong.Parse(targetPlayer.Id), out playerData) || playerData.activeBounties.Count == 0) { SendReply(arg, "That player does not have any active bounties"); return; } foreach (var bounty in playerData.activeBounties) { storedData.rewards.Remove(bounty.rewardId); } playerData.activeBounties.Clear(); SendReply(arg, $"You have cleared all pending bounties from {targetPlayer.Name}"); } return; case "wipe": storedData = new StoredData(); SaveData(); SendReply(arg, "All data has been wiped!"); return; default: SendReply(arg, "Invalid command syntax! Type 'bounty' to see available commands"); break; } }
private void cmdBounty(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, "bounty.use")) { SendReply(player, msg("no_permission", player.userID)); return; } if (args.Length == 0) { SendReply(player, string.Format(msg("title", player.userID), Title, Version)); if (configData.Rewards.AllowItems) { SendReply(player, msg("help1", player.userID)); } if (configData.Rewards.AllowServerRewards && ServerRewards) { SendReply(player, msg("help2", player.userID)); } if (configData.Rewards.AllowEconomics && Economics) { SendReply(player, msg("help3", player.userID)); } SendReply(player, msg("help4", player.userID)); SendReply(player, msg("help5", player.userID)); SendReply(player, msg("help6", player.userID)); SendReply(player, msg("help7", player.userID)); SendReply(player, msg("help8", player.userID)); if (player.IsAdmin || permission.UserHasPermission(player.UserIDString, "bounty.admin")) { SendReply(player, msg("help9", player.userID)); } return; } switch (args[0].ToLower()) { case "add": { if (args.Length < 3) { SendReply(player, msg("invalid_syntax", player.userID)); return; } List <BasePlayer> players = FindPlayer(args[2]); if (players.Count == 0) { SendReply(player, msg("no_player_found", player.userID)); return; } if (players.Count > 1) { SendReply(player, msg("multiple_players_found", player.userID)); return; } BasePlayer targetPlayer = players[0]; if (targetPlayer == null) { SendReply(player, msg("no_player_found", player.userID)); return; } if (targetPlayer == player) { SendReply(player, msg("cant_bounty_self", player.userID)); return; } PlayerData playerData; if (!storedData.players.TryGetValue(targetPlayer.userID, out playerData)) { playerData = new PlayerData(targetPlayer.displayName); storedData.players.Add(targetPlayer.userID, playerData); } if (playerData.activeBounties.Find(x => x.initiatorId == player.userID) != null) { SendReply(player, msg("has_active_bounty", player.userID)); return; } switch (args[1].ToLower()) { case "items": SpawnItemContainer(player); if (bountyCreator.ContainsKey(player.userID)) { bountyCreator[player.userID] = targetPlayer.userID; } else { bountyCreator.Add(player.userID, targetPlayer.userID); } return; case "rp": if (!configData.Rewards.AllowServerRewards || !ServerRewards || args.Length != 4) { SendReply(player, msg("invalid_syntax", player.userID)); return; } int rpAmount; if (!int.TryParse(args[3], out rpAmount)) { SendReply(player, msg("no_value_entered", player.userID)); return; } int availableRp = (int)ServerRewards?.Call("CheckPoints", player.userID); if (availableRp < rpAmount || !(bool)ServerRewards?.Call("TakePoints", player.userID, rpAmount)) { SendReply(player, msg("not_enough_rp", player.userID)); return; } CreateNewBounty(player, targetPlayer.userID, rpAmount, 0, null); return; case "eco": if (!configData.Rewards.AllowEconomics || !Economics || args.Length != 4) { SendReply(player, msg("invalid_syntax", player.userID)); return; } int ecoAmount; if (!int.TryParse(args[3], out ecoAmount)) { SendReply(player, msg("no_value_entered", player.userID)); return; } double availableEco = (double)Economics?.Call("Balance", player.UserIDString); if (availableEco < ecoAmount || !(bool)Economics?.Call("Withdraw", player.UserIDString, (double)ecoAmount)) { SendReply(player, msg("not_enough_eco", player.userID)); return; } CreateNewBounty(player, targetPlayer.userID, 0, ecoAmount, null); return; default: SendReply(player, msg("invalid_syntax", player.userID)); return; } } case "cancel": { if (args.Length < 2) { SendReply(player, msg("invalid_syntax", player.userID)); return; } IPlayer targetPlayer = covalence.Players.FindPlayer(args[1]); if (targetPlayer == null) { SendReply(player, msg("no_player_found", player.userID)); return; } CancelBounty(player, targetPlayer); } return; case "claim": { PlayerData playerData; if (!storedData.players.TryGetValue(player.userID, out playerData) || playerData.unclaimedRewards.Count == 0) { SendReply(player, msg("no_rewards_pending", player.userID)); return; } if (args.Length < 2) { SendReply(player, msg("help10", player.userID)); foreach (int rewardId in playerData.unclaimedRewards) { RewardInfo rewardInfo = storedData.rewards[rewardId]; string reward = string.Empty; if (rewardInfo.rewardItems.Count > 1) { for (int i = 0; i < rewardInfo.rewardItems.Count; i++) { RewardInfo.ItemData itemData = rewardInfo.rewardItems.ElementAt(i); reward += (string.Format(msg("reward_item", player.userID), itemData.amount, idToDisplayName[itemData.itemid]) + (i < rewardInfo.rewardItems.Count - 1 ? ", " : "")); } } else { reward = rewardInfo.econAmount > 0 ? string.Format(msg("reward_econ", player.userID), rewardInfo.econAmount) : string.Format(msg("reward_rp", player.userID), rewardInfo.rpAmount); } SendReply(player, string.Format(msg("reward_info", player.userID), rewardId, reward)); } } else { int rewardId; if (!int.TryParse(args[1], out rewardId) || !playerData.unclaimedRewards.Contains(rewardId)) { SendReply(player, msg("invalid_reward_id", player.userID)); return; } RewardInfo rewardInfo = storedData.rewards[rewardId]; GivePlayerRewards(player, rewardInfo); storedData.rewards.Remove(rewardId); playerData.unclaimedRewards.Remove(rewardId); } } return; case "view": { if (args.Length < 2) { SendReply(player, msg("invalid_syntax", player.userID)); return; } IPlayer targetPlayer = covalence.Players.FindPlayer(args[1]); if (targetPlayer == null) { SendReply(player, msg("no_player_found", player.userID)); return; } PlayerData playerData; if (!storedData.players.TryGetValue(ulong.Parse(targetPlayer.Id), out playerData) || playerData.activeBounties.Count == 0) { SendReply(player, msg("no_active_bounties", player.userID)); return; } SendReply(player, string.Format(msg("player_has_bounties", player.userID), targetPlayer.Name, playerData.activeBounties.Count)); foreach (var bounty in playerData.activeBounties) { RewardInfo rewardInfo = storedData.rewards[bounty.rewardId]; string reward = string.Empty; if (rewardInfo.rewardItems.Count > 1) { for (int i = 0; i < rewardInfo.rewardItems.Count; i++) { RewardInfo.ItemData itemData = rewardInfo.rewardItems.ElementAt(i); reward += (string.Format(msg("reward_item", player.userID), itemData.amount, idToDisplayName[itemData.itemid]) + (i < rewardInfo.rewardItems.Count - 1 ? ", " : "")); } } else { reward = rewardInfo.econAmount > 0 ? string.Format(msg("reward_econ", player.userID), rewardInfo.econAmount) : string.Format(msg("reward_rp", player.userID), rewardInfo.rpAmount); } SendReply(player, string.Format(msg("bounty_info", player.userID), bounty.initiatorName, FormatTime(CurrentTime() - bounty.initiatedTime), reward)); } } return; case "top": IEnumerable <PlayerData> top10Hunters = storedData.players.Values.OrderByDescending(x => x.bountiesClaimed).Take(10); string hunterMessage = msg("top_hunters", player.userID); foreach (PlayerData playerData in top10Hunters) { hunterMessage += string.Format(msg("top_hunter_entry", player.userID), playerData.displayName, playerData.bountiesClaimed); } SendReply(player, hunterMessage); return; case "wanted": IEnumerable <PlayerData> top10Hunted = storedData.players.Values.OrderByDescending(x => x.totalWantedTime + x.GetCurrentWantedTime()).Take(10); string wantedMessage = msg("top_wanted", player.userID); foreach (PlayerData playerData in top10Hunted) { wantedMessage += string.Format(msg("top_wanted_entry", player.userID), playerData.displayName, FormatTime(playerData.totalWantedTime + playerData.GetCurrentWantedTime()), playerData.totalBounties); } SendReply(player, wantedMessage); return; case "clear": { if (args.Length < 2) { SendReply(player, msg("invalid_syntax", player.userID)); return; } IPlayer targetPlayer = covalence.Players.FindPlayer(args[1]); if (targetPlayer == null) { SendReply(player, msg("no_player_found", player.userID)); return; } PlayerData playerData; if (!storedData.players.TryGetValue(ulong.Parse(targetPlayer.Id), out playerData) || playerData.activeBounties.Count == 0) { SendReply(player, msg("no_active_bounties", player.userID)); return; } foreach (var bounty in playerData.activeBounties) { storedData.rewards.Remove(bounty.rewardId); } playerData.activeBounties.Clear(); SendReply(player, string.Format(msg("bounties_cleared", player.userID), targetPlayer.Name)); } return; default: SendReply(player, msg("invalid_syntax", player.userID)); break; } }