void OnNpcConversationResponded(NPCTalking npcTalking, BasePlayer player, ConversationData conversationData, ConversationData.ResponseNode responseNode)
        {
            int ScrapAmount = GetScrapAmount(player, responseNode);

            if (ScrapAmount <= 0)
            {
                return;
            }

            var ScrapDifference = ItemManager.CreateByName("scrap", ScrapAmount, 0);

            if (ScrapDifference == null)
            {
                return;
            }

            player.inventory.GiveItem(ScrapDifference, player.inventory.containerMain);

            timer.Once((float)0.5, () =>
            {
                player.inventory.Take(null, ScrapID, ScrapAmount);
            });

            return;
        }
            public override string Intercept(NPCTalking npcTalking, BasePlayer player, ConversationData conversationData, ResponseNode responseNode)
            {
                if (responseNode.actionString != _matchResponseAction)
                {
                    return(string.Empty);
                }

                int vanillaPrice;

                if (!ConversationUtils.ResponseHasScrapPrice(responseNode, out vanillaPrice))
                {
                    return(string.Empty);
                }

                var priceConfig = _getVehicleConfig().GetPriceForPlayer(player.IPlayer, _freePermission);

                if (priceConfig == null || priceConfig.MatchesVanillaPrice(vanillaPrice))
                {
                    return(string.Empty);
                }

                var neededScrap           = PlayerInventoryUtils.GetPlayerNeededScrap(player, vanillaPrice);
                var canAffordVanillaPrice = neededScrap <= 0;
                var canAffordCustomPrice  = priceConfig.CanPlayerAfford(player);

                if (!canAffordCustomPrice)
                {
                    return(ConversationUtils.SpeechNodes.Goodbye);
                }

                // Add scrap so the vanilla checks will pass. Add full amount for simplicity.
                player.inventory.containerMain.AddItem(ItemManager.itemDictionary[ScrapItemId], vanillaPrice);

                // Check conditions just in case, to make sure we don't give free scrap.
                if (!responseNode.PassesConditions(player, npcTalking))
                {
                    _pluginInstance.LogError($"Price adjustment unexpectedly failed for price config (response: '{_matchResponseAction}', player: {player.userID}).");
                    player.inventory.containerMain.AddItem(ItemManager.itemDictionary[ScrapItemId], -vanillaPrice);
                    return(string.Empty);
                }

                priceConfig.TryChargePlayer(player, vanillaPrice);

                return(string.Empty);
            }
            public override string Intercept(NPCTalking npcTalking, BasePlayer player, ConversationData conversationData, ResponseNode responseNode)
            {
                int vanillaPrice;

                if (!ConversationUtils.PrecedesPaymentOption(conversationData, responseNode, _matchResponseAction, out vanillaPrice))
                {
                    return(string.Empty);
                }

                var priceConfig = _getVehicleConfig().GetPriceForPlayer(player.IPlayer, _freePermission);

                if (priceConfig == null || priceConfig.MatchesVanillaPrice(vanillaPrice))
                {
                    return(string.Empty);
                }

                var neededScrap           = PlayerInventoryUtils.GetPlayerNeededScrap(player, vanillaPrice);
                var canAffordVanillaPrice = neededScrap <= 0;
                var canAffordCustomPrice  = priceConfig.CanPlayerAfford(player);

                CostLabelUI.Create(player, priceConfig);

                if (canAffordCustomPrice == canAffordVanillaPrice)
                {
                    return(string.Empty);
                }

                if (!canAffordCustomPrice)
                {
                    // Reduce scrap that will be removed to just below the amount they need for vanilla.
                    neededScrap--;
                }

                // Add or remove scrap so the vanilla logic for showing the payment option will match the custom payment logic.
                PlayerInventoryUtils.UpdateWithFakeScrap(player, neededScrap);

                // This delay needs to be long enough for the text to print out, which could vary by language.
                player.Invoke(() => PlayerInventoryUtils.Refresh(player), 3f);

                return(string.Empty);
            }
            public override string Intercept(NPCTalking npcTalking, BasePlayer player, ConversationData conversationData, ResponseNode responseNode)
            {
                int vanillaPrice;

                if (!ConversationUtils.PrecedesPaymentOption(conversationData, responseNode, _matchResponseAction, out vanillaPrice))
                {
                    return(string.Empty);
                }

                if (!_getVehicleConfig().RequiresPermission)
                {
                    return(string.Empty);
                }

                if (_pluginInstance.HasPermissionAny(player.UserIDString, Permission_Allow_All, _allowPermission))
                {
                    return(string.Empty);
                }

                _pluginInstance.ChatMessage(player, "Error.Vehicle.NoPermission");
                return(ConversationUtils.SpeechNodes.Goodbye);
            }
        object OnNpcConversationRespond(NPCTalking npcTalking, BasePlayer player, ConversationData conversationData, ConversationData.ResponseNode responseNode)
        {
            switch (responseNode.responseTextLocalized.english)
            {
            case "[PAY 750]":

                if (config.MinicopterPrice < 750)
                {
                    var ScrapDifference = ItemManager.CreateByName("scrap", 750 - config.MinicopterPrice, 0);
                    if (ScrapDifference == null)
                    {
                        return(null);
                    }
                    player.inventory.GiveItem(ScrapDifference, player.inventory.containerMain);
                }

                if (config.MinicopterPrice > 750)
                {
                    player.inventory.Take(null, ScrapID, config.MinicopterPrice - 750);
                }

                return(null);

            case "[PAY 1250]":

                if (config.ScrapHeliPrice < 1250)
                {
                    var ScrapDifference = ItemManager.CreateByName("scrap", 1250 - config.ScrapHeliPrice, 0);
                    if (ScrapDifference == null)
                    {
                        return(null);
                    }
                    player.inventory.GiveItem(ScrapDifference, player.inventory.containerMain);
                }

                if (config.ScrapHeliPrice > 1250)
                {
                    player.inventory.Take(null, ScrapID, config.ScrapHeliPrice - 1250);
                }

                return(null);

            case "[PAY 125 SCRAP]":

                if (config.RowBoatPrice < 125)
                {
                    var ScrapDifference = ItemManager.CreateByName("scrap", 125 - config.RowBoatPrice, 0);
                    if (ScrapDifference == null)
                    {
                        return(null);
                    }
                    player.inventory.GiveItem(ScrapDifference, player.inventory.containerMain);
                }

                if (config.MinicopterPrice > 125)
                {
                    player.inventory.Take(null, ScrapID, config.RowBoatPrice - 125);
                }

                return(null);

            case "[PAY 300 SCRAP]":

                if (config.RHIBPrice < 300)
                {
                    var ScrapDifference = ItemManager.CreateByName("scrap", 300 - config.RHIBPrice, 0);
                    if (ScrapDifference == null)
                    {
                        return(null);
                    }
                    player.inventory.GiveItem(ScrapDifference, player.inventory.containerMain);
                }

                if (config.RHIBPrice > 300)
                {
                    player.inventory.Take(null, ScrapID, config.RHIBPrice - 300);
                }

                return(null);
            }

            return(null);
        }
 public abstract string Intercept(NPCTalking npcTalking, BasePlayer player, ConversationData conversationData, ResponseNode responseNode);
            public static void ForceSpeechNode(NPCTalking npcTalking, BasePlayer player, string speechNodeName)
            {
                int speechNodeIndex = npcTalking.GetConversationFor(player).GetSpeechNodeIndex(speechNodeName);

                npcTalking.ForceSpeechNode(player, speechNodeIndex);
            }