Esempio n. 1
0
        public static void Run([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log)
        {
            log.LogInformation(eventGridEvent.Data.ToString());

            var jsonEvent = JsonSerializer.Deserialize <EventItem>(eventGridEvent.Data.ToString());

            var ThingId = jsonEvent.DeviceId + 500;

            log.LogInformation("Thing Id: " + ThingId);

            ThingItem thingItem = new ThingItem
            {
                Thingid   = jsonEvent.DeviceId + 500,
                Latitude  = jsonEvent.Latitude,
                Longitude = jsonEvent.Longitude,
                Image     = jsonEvent.Image,
                Text      = jsonEvent.Text,
                Name      = jsonEvent.Name
            };

            var jsonThing = JsonSerializer.Serialize <ThingItem>(thingItem);

            log.LogInformation("Thing >>>" + jsonThing.ToString());

            string logappUrl = "https://prod-55.northeurope.logic.azure.com:443/workflows/c815fd9d3f73440889a7de71e5130933/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=6elFcQJB3hEHYSHTy-HXaoP9CBQFIdngKRU35IrmA4w";

            using (var client = new HttpClient())
            {
                var response = client.PostAsync(
                    logappUrl,
                    new StringContent(jsonThing, Encoding.UTF8, "application/json")).Result;

                log.LogInformation("Response >>>" + response.StatusCode);
            }
        }
Esempio n. 2
0
        private static void ValidateItemData()
        {
            ItemData ??= new Dictionary <string, ItemData>();
            List <string> tradeables = StoreDialog.GetTradeables().Select(t => t.defName).ToList();
            List <string> toCull     = ItemData.Keys.Where(dataKey => !tradeables.Contains(dataKey.CapitalizeFirst())).ToList();

            foreach (string defName in toCull)
            {
                ItemData.Remove(defName);
            }

            var builder = new StringBuilder();

            foreach (ThingDef item in tradeables.Where(t => !ItemData.ContainsKey(t)).Select(i => DefDatabase <ThingDef> .GetNamed(i)))
            {
                ModContentPack contentPack = item.modContentPack;

                var data = new ItemData
                {
                    Version        = Models.ItemData.CurrentVersion,
                    QuantityLimit  = -1,
                    IsStuffAllowed = true,
                    IsUsable       = GameHelper.GetDefaultUsability(item),
                    IsWearable     = true,
                    IsEquippable   = true
                };

                if (contentPack != null)
                {
                    data.Mod = contentPack.IsCoreMod ? "RimWorld" : contentPack.Name ?? "Unknown";
                }

                ItemData[item.defName] = data;

                try
                {
                    data.IsMelee  = item.IsMeleeWeapon;
                    data.IsRanged = item.IsRangedWeapon;
                    data.IsWeapon = item.IsWeapon;
                }
                catch (Exception e)
                {
                    builder.Append($"Failed to gather weapon data for item '{item.label ?? "Unknown"}' from mod '{item.TryGetModName()}'");
                    builder.AppendLine($" -- Exception: {e.GetType().Name}({e.Message ?? "No message"})");
                }
            }

            foreach (KeyValuePair <string, ItemData> pair in ItemData.Where(data => data.Value.Version < Models.ItemData.CurrentVersion))
            {
                string   defName = pair.Key;
                ItemData data    = pair.Value;

                ThingItem item = Items.Find(i => i.DefName?.Equals(defName) == true);

                data.IsUsable     = item?.Thing == null || GameHelper.GetDefaultUsability(item.Thing);
                data.IsWearable   = true;
                data.IsEquippable = true;
                data.Version      = Models.ItemData.CurrentVersion;
            }
        }
Esempio n. 3
0
        private void PerformAnimalLookup(string query, int quantity)
        {
            PawnKindDef kindDef = DefDatabase <PawnKindDef> .AllDefs.FirstOrDefault(
                i => i.RaceProps.Animal && (i.label.ToToolkit().EqualsIgnoreCase(query.ToToolkit()) || i.defName.ToToolkit().EqualsIgnoreCase(query.ToToolkit()))
                );

            if (kindDef == null)
            {
                return;
            }

            ThingItem item = Data.Items.FirstOrDefault(i => i.DefName.EqualsIgnoreCase(kindDef.defName));

            if (item == null || item.Cost <= 0)
            {
                return;
            }

            if (!PurchaseHelper.TryMultiply(item.Cost, quantity, out int result))
            {
                MessageHelper.ReplyToUser(_invoker, "TKUtils.Overflowed".Localize());

                return;
            }

            NotifyLookupComplete("TKUtils.Price.Limited".LocalizeKeyed(kindDef.defName.CapitalizeFirst(), result.ToString("N0")));
        }
Esempio n. 4
0
        public static int GetItemPrice([NotNull] this ThingItem thing, [CanBeNull] ThingItem stuff)
        {
            if (stuff == null)
            {
                return(thing.Cost);
            }

            int cost = thing.Cost;

            if (!thing.Thing.MadeFromStuff)
            {
                return(cost);
            }

            if (stuff.Thing.smallVolume)
            {
                cost += thing.Thing.CostStuffCount * stuff.Cost * 10;
            }
            else
            {
                cost += thing.Thing.CostStuffCount * stuff.Cost;
            }

            cost = Mathf.CeilToInt(cost * 1.05f);

            return(cost);
        }
Esempio n. 5
0
        /// <summary>
        ///     Loads items from the given partial data.
        /// </summary>
        /// <param name="partialData">A collection of partial data to load</param>
        public static void LoadItemPartial([NotNull] IEnumerable <ItemPartial> partialData)
        {
            var builder = new StringBuilder();

            foreach (ItemPartial partial in partialData)
            {
                if (partial.DefName == null)
                {
                    builder.Append($"  - {partial.Data?.Mod ?? "UNKNOWN"}:{partial.DefName}\n");

                    continue;
                }

                ThingItem existing = Items.Find(i => i.DefName !.Equals(partial.DefName));

                if (existing == null)
                {
                    ThingDef thing = DefDatabase <ThingDef> .GetNamed(partial.DefName, false);

                    var item = Item.GetItemFromDefName(partial.DefName);

                    if (thing == null || item == null)
                    {
                        builder.Append($"  - {partial.Data?.Mod ?? "UNKNOWN"}:{partial.DefName}\n");

                        continue;
                    }

                    item.price = partial.Cost;
                    Items.Add(new ThingItem {
                        Thing = thing, Item = item, ItemData = partial.ItemData
                    });

                    continue;
                }

                existing.Name     = partial.Name;
                existing.Cost     = partial.Cost;
                existing.ItemData = partial.ItemData;
                existing.Update();
            }

            if (builder.Length <= 0)
            {
                return;
            }

            builder.Insert(0, "The following items could not be loaded from the partial data provided:\n");
            TkUtils.Logger.Warn(builder.ToString());
        }
Esempio n. 6
0
        public static int GetItemPrice([NotNull] this ThingItem thing, [CanBeNull] ThingItem stuff, QualityCategory quality)
        {
            int price = GetItemPrice(thing, stuff);

            switch (quality)
            {
            case QualityCategory.Awful:
                price = Mathf.CeilToInt(price * Item.AwfulMultiplier);

                break;

            case QualityCategory.Poor:
                price = Mathf.CeilToInt(price * Item.PoorMultiplier);

                break;

            case QualityCategory.Normal:
                price = Mathf.CeilToInt(price * Item.NormalMultiplier);

                break;

            case QualityCategory.Good:
                price = Mathf.CeilToInt(price * Item.GoodMultiplier);

                break;

            case QualityCategory.Excellent:
                price = Mathf.CeilToInt(price * Item.ExcellentMultiplier);

                break;

            case QualityCategory.Masterwork:
                price = Mathf.CeilToInt(price * Item.MasterworkMultiplier);

                break;

            case QualityCategory.Legendary:
                price = Mathf.CeilToInt(price * Item.LegendaryMultiplier);

                break;
            }

            return(Mathf.CeilToInt(price * 1.1f));
        }
Esempio n. 7
0
        private static void RemoveDanglingItems()
        {
            for (int index = Data.Items.Count - 1; index >= 0; index--)
            {
                ThingItem thingItem = Data.Items[index];

                if (StoreInventory.items.Contains(thingItem.Item))
                {
                    continue;
                }

                try
                {
                    Data.Items.RemoveAt(index);
                }
                catch (IndexOutOfRangeException)
                {
                    // While it's unlikely this will throw an exception,
                    // we'll still swallow the exception in the event it
                    // does.
                }
            }
        }
Esempio n. 8
0
        public override bool CanHappen(string msg, [NotNull] Viewer viewer)
        {
            if (!PurchaseHelper.TryGetPawn(viewer.username, out _pawn))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.NoPawn".Localize());

                return(false);
            }

            var worker = ArgWorker.CreateInstance(CommandFilter.Parse(msg).Skip(2));

            if (!worker.TryGetNextAsItem(out ArgWorker.ItemProxy item) || !item.IsValid())
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidItemQuery".LocalizeKeyed(item?.Thing?.Name ?? worker.GetLast()));

                return(false);
            }

            _buyableItem = item.Thing;

            if (item.TryGetError(out string error))
            {
                MessageHelper.ReplyToUser(viewer.username, error);

                return(false);
            }

            if (!worker.TryGetNextAsInt(out _amount, 1, viewer.GetMaximumPurchaseAmount(_buyableItem.Cost)))
            {
                _amount = 1;
            }

            if (!PurchaseHelper.TryMultiply(_buyableItem.Cost, _amount, out int cost))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.Overflowed".Localize());

                return(false);
            }

            if (!viewer.CanAfford(cost))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InsufficientBalance".LocalizeKeyed(cost.ToString("N0"), viewer.GetViewerCoins().ToString("N0")));

                return(false);
            }

            List <ResearchProjectDef> prerequisites = item.Thing.Thing.GetUnfinishedPrerequisites();

            if (BuyItemSettings.mustResearchFirst && prerequisites.Count > 0)
            {
                MessageHelper.ReplyToUser(
                    viewer.username,
                    "TKUtils.ResearchRequired".LocalizeKeyed(item.Thing.Thing.LabelCap.RawText, prerequisites.Select(p => p.LabelCap.RawText).SectionJoin())
                    );

                return(false);
            }

            foreach (IUsabilityHandler h in CompatRegistry.AllUsabilityHandlers)
            {
                if (!h.IsUsable(item.Thing.Thing))
                {
                    continue;
                }

                _handler = h;

                break;
            }

            if (_handler == null || item.Thing.ItemData?.IsUsable != true)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.DisabledItem".Localize());

                return(false);
            }

            _buyableItem = item !.Thing;

            return(true);
        }