private void Wc_DownloadStringCompleted(DownloadStringCompletedEventArgs e, Player _caller, Service _service, ServiceDefinition _apidefinition, bool _giveItemDirectly) { VoteResult v = new VoteResult() { caller = _caller, result = e.Result, apidefinition = _apidefinition, service = _service, giveItemDirectly = _giveItemDirectly }; lock (queue) { queue.Enqueue(v); } }
private void Votifier_OnPlayerVoted(UnturnedPlayer player, ServiceDefinition definition) { int probSum = Instance.Configuration.Instance.RewardBundles.Sum(p => p.Probability); RewardBundle bundle = new RewardBundle(); if (probSum != 0) { Random r = new Random(); int i = 0, diceRoll = r.Next(0, probSum); foreach (RewardBundle b in Instance.Configuration.Instance.RewardBundles) { if (diceRoll > i && diceRoll <= i + b.Probability) { bundle = b; break; } i += b.Probability; } } else { Logger.Log(Instance.Translations.Instance.Translate("no_rewards_found")); return; } // Experience Reward player.Experience += bundle.Reward.Experiences; // Item Reward foreach (var item in bundle.Reward.Items) { if (!player.GiveItem(item.ItemID, item.Amount)) { Logger.Log(Instance.Translations.Instance.Translate("vote_give_error_message", player.CharacterName, item.ItemID, item.Amount, "item")); } } // Vehicle Reward foreach (var vehicle in bundle.Reward.Vehicles) { for (int i = 0; i < vehicle.Amount; i++) { InteractableVehicle status = null; Vector3 vector = player.Player.transform.position + player.Player.transform.forward * 6f; Physics.Raycast(vector + Vector3.up * 16f, Vector3.down, out RaycastHit raycastHit, 32f, RayMasks.BLOCK_VEHICLE); if (raycastHit.collider != null) { vector.y = raycastHit.point.y + 16f; } status = VehicleManager.spawnLockedVehicleForPlayerV2(vehicle.VehicleID, vector, player.Player.transform.rotation, player.Player); if (status == null) { Logger.Log(Instance.Translations.Instance.Translate("vote_give_error_message", player.CharacterName, vehicle.VehicleID, vehicle.Amount, "vehicle")); } } } // Command Reward foreach (var command in bundle.Reward.Commands) { bool yes = true; CommandWindow.onCommandWindowInputted(command.Replace("{playerid}", player.CSteamID.m_SteamID.ToString().Replace("{playername}", player.CharacterName)), ref yes); } if (Configuration.Instance.GlobalRewardAnnouncement) { Say(Translations.Instance.Translate("vote_success_message", player.CharacterName, definition.Name, bundle.Name), MsgColor, Configuration.Instance.MessageSuccessIconUrl); } else { Say(player, Instance.Translations.Instance.Translate("vote_success_message", player.CharacterName, definition.Name, bundle.Name), MsgColor, Configuration.Instance.MessageSuccessIconUrl); } }