Exemplo n.º 1
0
        public static string WriteDiscountRange(Item item, Shop shop)
        {
            if (item == null || shop == null)
            {
                return("");
            }

            var info = new StringBuilder();

            CatalogEntry entry = shop.Catalog?.Entries.FirstOrDefault(x => x.ItemId == item.Id);

            if (entry == null)
            {
                return("");
            }

            if (entry.DiscountChance <= 0)
            {
                return("");
            }

            info.Append($"(**{entry.MinDiscount ?? CatalogEntry.DefaultMinDiscount}**% to ");
            info.Append($"**{entry.MaxDiscount ?? CatalogEntry.DefaultMaxDiscount}**% discount range");

            info.Append($", **{RangeF.Convert(0, 1, 0, 100, entry.DiscountChance):##,0.##}**% chance of discount)");

            return(info.ToString());
        }
Exemplo n.º 2
0
        public static long GetCost(long cost, int discount)
        {
            discount = Math.Clamp(discount, 0, 100);

            if (discount == 0)
            {
                return(cost);
            }

            float d = RangeF.Convert(0, 100, 0, 1, discount);

            return((long)MathF.Floor(cost * (1 - d)));
        }
Exemplo n.º 3
0
        private static long GetCost(long value, int discountUpper)
        {
            discountUpper = Math.Clamp(discountUpper, 0, 100);

            if (discountUpper == 0)
            {
                return(value);
            }

            float discount = RangeF.Convert(0, 100, 0, 1, discountUpper);

            return((long)MathF.Floor(value * (1 - discount)));
        }
Exemplo n.º 4
0
        // 0% complete.
        private static string GetProgress(QuestData data)
        {
            Quest quest = GetQuest(data.Id);

            long sum   = 0;
            long total = 0;

            foreach (VarCriterion criterion in quest.Criteria)
            {
                sum   += data.Progress[criterion.Id];
                total += criterion.ExpectedValue;
            }

            return($"**{RangeF.Convert(0, total, 0, 100, sum):##,0}**% complete");
        }
Exemplo n.º 5
0
        // TODO: Implement travel speed calculation.
        public Vector2 GetCurrentPosition(DateTime startedAt)
        {
            float elapsedSeconds = (float)((DateTime.UtcNow - startedAt).TotalSeconds);

            if (elapsedSeconds > GetTotalTime())
            {
                return(To);
            }

            // a float from 0 to 1. this helps correlate position
            float progress = RangeF.Convert(0.0f, GetTotalTime(), 0.0f, 1.0f, elapsedSeconds);


            return(GetPositionAt(progress));
        }
Exemplo n.º 6
0
 public static AffinityLevel GetLevel(float value)
 {
     return((AffinityLevel)((int)MathF.Floor(RangeF.Convert(-1.0f, 1.0f, -3, 3, RangeF.Clamp(-1.0f, 1.0f, value)))));
 }
Exemplo n.º 7
0
 private static string GetProgress(MeritGroup group, int collected, int total)
 => CanShowProgress(group) ? $" (`{RangeF.Convert(0, total, 0.0f, 100.0f, collected)}%`)" : "";
Exemplo n.º 8
0
        // gets the desired point based on the completion of this route.
        private Vector2 GetPositionAt(float progress)
        {
            // converts the progress into the total distance travelled based on progress.
            float travelled = RangeF.Convert(0.0f, 1.0f, 0.0f, GetTotalDistance(), progress);

            float   dist = 0.0f;
            Vector2 from = From;
            int     i    = 0;

            // TODO: Create a sub-list referencing Points, and simply insert the From/To values
            foreach (Vector2 to in Points)
            {
                dist += CalcF.Distance(from, to);
                from  = to;

                if (dist >= travelled)
                {
                    break;
                }

                i++;
            }

            if (Points.Count == 0) // if there aren't any points specified
            {
                float pathProgress = RangeF.Convert(0.0f, GetTotalDistance(), 0.0f, 1.0f, travelled);

                return(new Vector2(RangeF.Convert(0.0f, 1.0f, From.X, To.X, pathProgress),
                                   RangeF.Convert(0.0f, 1.0f, From.Y, To.Y, pathProgress)));
            }
            else if (i == 0) // if the total travelled was less than the first checkpoint.
            {
                float pathProgress = RangeF.Convert(0.0f, GetDistanceAt(i), 0.0f, 1.0f, travelled);

                return(new Vector2(RangeF.Convert(0.0f, 1.0f, From.X, Points[i].X, pathProgress),
                                   RangeF.Convert(0.0f, 1.0f, From.Y, Points[i].Y, pathProgress)));
            }
            else if (dist < travelled) // if the total travelled is greater than all points
            {
                dist += CalcF.Distance(from, To);

                if (travelled >= dist)
                {
                    return(To);
                }
                else
                {
                    float pathProgress = RangeF.Convert(GetDistanceAt(i), GetTotalDistance(), 0.0f, 1.0f, travelled);

                    return(new Vector2(RangeF.Convert(0.0f, 1.0f, Points[i].X, To.X, pathProgress),
                                       RangeF.Convert(0.0f, 1.0f, Points[i].Y, To.Y, pathProgress)));
                }
            }
            else // if the travelled amount if within the points specified.
            {
                float pathProgress = RangeF.Convert(GetDistanceAt(i - 1), GetDistanceAt(i), 0.0f, 1.0f, travelled);

                return(new Vector2(RangeF.Convert(0.0f, 1.0f, Points[i - 1].X, Points[i].X, pathProgress),
                                   RangeF.Convert(0.0f, 1.0f, Points[i - 1].Y, Points[i].Y, pathProgress)));
            }
        }
Exemplo n.º 9
0
 private static float GetCurrentValue(float last, float next, float progress)
 => RangeF.Convert(0.0f, 1.0f, last, next, progress);
Exemplo n.º 10
0
 private static float GetTickProgress(long last, long next, long current)
 => RangeF.Convert(last, next, 0.0f, 1.0f, current);