Example #1
0
        internal void ForceReward(Player player, string reward = "$$random$$")
        {
            if (reward == "$$random$$")
            {
                Votifier_OnPlayerVoted(player, new ServiceDefinition {
                    Name = "Admin"
                });
            }
            else
            {
                RewardBundle bundle = null;
                if (m_Configuration.GetSection("RewardBundles").Get <List <RewardBundle> >().Count != 0)
                {
                    bundle = m_Configuration.GetSection("RewardBundles").Get <List <RewardBundle> >().FirstOrDefault(r => r.Name == reward);
                }
                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))
                    {
                        m_Logger.LogInformation(m_StringLocalizer["FAIL: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.spawnLockedVehicleForPlayer(vehicle.VehicleID, vector, player.Player.transform.rotation, player.Player);
                        if (status == null)
                        {
                            m_Logger.LogInformation(m_StringLocalizer["FAIL: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);
                }
            }
        }
Example #2
0
        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);
            }
        }