コード例 #1
0
            private static int AddFakeScrapToContainerUpdate(ProtoBuf.ItemContainer containerInfo, int scrapAmount)
            {
                // Always use a separate item so it can be placed out of view.
                var itemInfo = _pluginInstance._scrapItem.Save();

                itemInfo.amount = scrapAmount;
                itemInfo.slot   = PlayerInventoryUtils.GetNextAvailableSlot(containerInfo);
                containerInfo.contents.Add(itemInfo);
                return(itemInfo.slot);
            }
コード例 #2
0
            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);
            }
コード例 #3
0
            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);
            }