System.Math.Round(double)

Here are the examples of the csharp api System.Math.Round(double) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2100 Examples 7

19 View Source File : Player_Skills.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void GrantLevelProportionalSkillXP(Skill skill, double percent, long min, long max)
        {
            var creatureSkill = GetCreatureSkill(skill, false);
            if (creatureSkill == null || creatureSkill.IsMaxRank)
                return;

            var nextLevelXP = GetXPBetweenSkillLevels(creatureSkill.AdvancementClreplaced, creatureSkill.Ranks, creatureSkill.Ranks + 1);
            if (nextLevelXP == null)
                return;

            var amount = (uint)Math.Round(nextLevelXP.Value * percent);

            if (max > 0 && max <= uint.MaxValue)
                amount = Math.Min(amount, (uint)max);

            amount = Math.Min(amount, creatureSkill.ExperienceLeft);

            if (min > 0)
                amount = Math.Max(amount, (uint)min);

            //Console.WriteLine($"{Name}.GrantLevelProportionalSkillXP({skill}, {percent}, {max:N0})");
            //Console.WriteLine($"Amount: {amount:N0}");

            AwardSkillXP(skill, amount, true);
        }

19 View Source File : UIElementExtension.cs
License : GNU General Public License v3.0
Project Creator : aduskin

public static double RoundLayoutValue(double value, double dpiScale)
      {
         double num;
         if (!DoubleUtil.AreClose(dpiScale, 1.0))
         {
            num = Math.Round(value * dpiScale) / dpiScale;
            if (DoubleUtil.IsNaN(num) || double.IsInfinity(num) || DoubleUtil.AreClose(num, 1.7976931348623157E+308))
            {
               num = value;
            }
         }
         else
         {
            num = Math.Round(value);
         }
         return num;
      }

19 View Source File : TimestampConverter.cs
License : MIT License
Project Creator : aabiryukov

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (writer == null) throw new ArgumentNullException(nameof(writer));

            if (quotes)
                writer.WriteValue(Math.Round(((DateTime)value - new DateTime(1970, 1, 1)).TotalMilliseconds));
            else
                writer.WriteRawValue(Math.Round(((DateTime)value - new DateTime(1970, 1, 1)).TotalMilliseconds).ToString(CultureInfo.InvariantCulture));
        }

19 View Source File : Monster_Combat.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void TakeDamageOverTime_NotifySource(Player source, DamageType damageType, float amount, bool aetheria = false)
        {
            if (!PropertyManager.GetBool("show_dot_messages").Item)
                return;

            var iAmount = (uint)Math.Round(amount);

            var notifyType = damageType == DamageType.Undef ? DamageType.Health : damageType;

            string verb = null, plural = null;
            var percent = amount / Health.MaxValue;
            Strings.GetAttackVerb(notifyType, percent, ref verb, ref plural);

            string msg = null;

            var type = ChatMessageType.CombatSelf;

            if (damageType == DamageType.Nether)
            {
                msg = $"You {verb} {Name} for {iAmount} points of periodic nether damage!";
                type = ChatMessageType.Magic;
            }
            else if (aetheria)
            {
                msg = $"With Surge of Affliction you {verb} {iAmount} points of health from {Name}!";
                type = ChatMessageType.Magic;
            }
            else
            {
                /*var skill = source.GetCreatureSkill(Skill.DirtyFighting);
                var attack = skill.AdvancementClreplaced == SkillAdvancementClreplaced.Specialized ? "Bleeding replacedault" : "Bleeding Blow";
                msg = $"With {attack} you {verb} {iAmount} points of health from {Name}!";*/

                msg = $"You bleed {Name} for {iAmount} points of periodic health damage!";
                type = ChatMessageType.CombatSelf;
            }
            source.SendMessage(msg, type);
        }

19 View Source File : Fellowship.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void SplitLuminance(ulong amount, XpType xpType, ShareType shareType, Player player)
        {
            // https://asheron.fandom.com/wiki/Announcements_-_2002/02_-_Fever_Dreams#Letter_to_the_Players_1

            shareType &= ~ShareType.Fellowship;

            if (xpType == XpType.Quest)
            {
                // quest luminance is not shared
                player.GrantLuminance((long)amount, XpType.Quest, shareType);
            }
            else
            {
                // pre-filter: evenly divide between luminance-eligible fellows
                var shareableMembers = GetFellowshipMembers().Values.Where(f => f.MaximumLuminance != null).ToList();

                if (shareableMembers.Count == 0)
                    return;

                var perAmount = (long)Math.Round((double)(amount / (ulong)shareableMembers.Count));

                // further filter to fellows in radar range
                var inRange = shareableMembers.Intersect(WithinRange(player, true)).ToList();

                foreach (var member in inRange)
                {
                    var fellowXpType = player == member ? xpType : XpType.Fellowship;

                    member.GrantLuminance(perAmount, fellowXpType, shareType);
                }
            }
        }

19 View Source File : Mathd.cs
License : MIT License
Project Creator : 734843327

public static int RoundToInt(double d) {
            return (int)Math.Round(d);
        }

19 View Source File : CustomIndicatorTag.cs
License : MIT License
Project Creator : Actipro

public override void DrawGlyph(TextViewDrawContext context, ITextViewLine viewLine, TagSnapshotRange<IIndicatorTag> tagRange, Rect bounds) {
			var diameter = Math.Max(8.0, Math.Min(13, Math.Round(Math.Min(bounds.Width, bounds.Height) - 2.0)));
			var x = bounds.X + (bounds.Width - diameter) / 2.0;
			var y = bounds.Y + (bounds.Height - diameter) / 2.0;

			context.FillEllipse(new Rect(x, y, diameter, diameter), Color.FromArgb(0xff, 0x8a, 0xf3, 0x82));
			context.DrawEllipse(new Rect(x, y, diameter, diameter), Color.FromArgb(0xff, 0x00, 0x40, 0x00), LineKind.Solid, 1);
		}

19 View Source File : spline3.cs
License : MIT License
Project Creator : 1CM69

public static void splinecopy(ref double[] c, ref double[] cc)
  {
    int num = (int) System.Math.Round(c[0]);
    cc = new double[num - 1 + 1];
    for (int index = 0; index <= num - 1; ++index)
      cc[index] = c[index];
  }

19 View Source File : SerpentBoss.cs
License : GNU General Public License v3.0
Project Creator : aedenthorn

public override void behaviorAtGameTick(GameTime time)
        {
            base.behaviorAtGameTick(time);

            if (Health <= 0)
            {
                return;
            }

            // fire!

            this.timeUntilNextAttack -= time.ElapsedGameTime.Milliseconds;
            if (this.attackState.Value == 0 && this.withinPlayerThreshold(5))
            {
                this.firing.Set(false);
                if (this.timeUntilNextAttack < 0)
                {
                    this.timeUntilNextAttack = 0;
                    this.attackState.Set(1);
                    this.nextFireTime = 50;
                    this.totalFireTime = 3000;
                    return;
                }
            }
            else if (this.totalFireTime > 0)
            {
                Farmer player = base.Player;
                if (!this.firing)
                {
                    if (player != null)
                    {
                        base.faceGeneralDirection(player.Position, 0, false);
                    }
                }
                this.totalFireTime -= time.ElapsedGameTime.Milliseconds;
                if (this.nextFireTime > 0)
                {
                    this.nextFireTime -= time.ElapsedGameTime.Milliseconds;
                    if (this.nextFireTime <= 0)
                    {
                        if (!this.firing.Value)
                        {
                            this.firing.Set(true);
                            base.currentLocation.playSound("furnace", NetAudio.SoundContext.Default);
                        }
                        float fire_angle = 0f;
                        Vector2 shot_origin = new Vector2((float)this.GetBoundingBox().Center.X, (float)this.GetBoundingBox().Center.Y);
                        base.faceGeneralDirection(player.Position, 0, false);
                        switch (this.facingDirection.Value)
                        {
                            case 0:
                                this.yVelocity = -1f;
                                shot_origin.Y -= 64f;
                                fire_angle = 90f;
                                break;
                            case 1:
                                this.xVelocity = -1f;
                                shot_origin.X += 64f;
                                fire_angle = 0f;
                                break;
                            case 2:
                                this.yVelocity = 1f;
                                fire_angle = 270f;
                                break;
                            case 3:
                                this.xVelocity = 1f;
                                shot_origin.X -= 64f;
                                fire_angle = 180f;
                                break;
                        }
                        fire_angle += (float)Math.Sin((double)((float)this.totalFireTime / 1000f * 180f) * 3.1415926535897931 / 180.0) * 25f;
                        Vector2 shot_velocity = new Vector2((float)Math.Cos((double)fire_angle * 3.1415926535897931 / 180.0), -(float)Math.Sin((double)fire_angle * 3.1415926535897931 / 180.0));
                        shot_velocity *= 10f;
                        BasicProjectile projectile = new BasicProjectile((int)Math.Round(10 * difficulty), 10, 0, 1, 0.196349546f, shot_velocity.X, shot_velocity.Y, shot_origin, "", "", false, false, base.currentLocation, this, false, null);
                        projectile.ignoreTravelGracePeriod.Value = true;
                        projectile.maxTravelDistance.Value = 512;
                        base.currentLocation.projectiles.Add(projectile);
                        if (Health < MaxHealth / 2)
                        {
                            base.currentLocation.projectiles.Add(new BasicProjectile((int)Math.Round(10 * difficulty), 10, 3, 4, 0f, shot_velocity.X, shot_velocity.Y, shot_origin, "", "", true, false, base.currentLocation, this, false, null));
                        }
                        this.nextFireTime = 50;
                    }
                }
                if (this.totalFireTime <= 0)
                {
                    this.totalFireTime = 0;
                    this.nextFireTime = 0;
                    this.attackState.Set(0);
                    this.timeUntilNextAttack = Game1.random.Next(2000, 4000);
                }
            }
        }

19 View Source File : spline3.cs
License : MIT License
Project Creator : 1CM69

public static void splineunpack(ref double[] c, ref int n, ref double[,] tbl)
  {
    n = (int) System.Math.Round(c[2]);
    tbl = new double[n - 2 + 1, 6];
    for (int index = 0; index <= n - 2; ++index)
    {
      tbl[index, 0] = c[3 + index];
      tbl[index, 1] = c[3 + index + 1];
      tbl[index, 2] = c[3 + n + 4 * index];
      tbl[index, 3] = c[3 + n + 4 * index + 1];
      tbl[index, 4] = c[3 + n + 4 * index + 2];
      tbl[index, 5] = c[3 + n + 4 * index + 3];
    }
  }

19 View Source File : Creature_Rating.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static int ModToRating(float mod)
        {
            if (mod >= 1.0f)
                return (int)Math.Round(mod * 100 - 100);
            else
                return (int)Math.Round(-100 / mod + 100);
        }

19 View Source File : Proficiency.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void OnSuccessUse(Player player, CreatureSkill skill, uint difficulty)
        {
            //Console.WriteLine($"Proficiency.OnSuccessUse({player.Name}, {skill.Skill}, targetDiff: {difficulty})");

            // TODO: this formula still probably needs some work to match up with retail truly...

            // possible todo: does this only apply to players?
            // ie., can monsters still level up from skill usage, or killing players?
            // it was possible on release, but i think they might have removed that feature?

            if (player.IsOlthoiPlayer)
                return;

            // ensure skill is at least trained
            if (skill.AdvancementClreplaced < SkillAdvancementClreplaced.Trained)
                return;

            var last_difficulty = skill.PropertiesSkill.ResistanceAtLastCheck;
            var last_used_time = skill.PropertiesSkill.LastUsedTime;

            var currentTime = Time.GetUnixTime();

            var timeDiff = currentTime - last_used_time;

            if (timeDiff < 0)
            {
                // can happen if server clock is rewound back in time
                log.Warn($"Proficiency.OnSuccessUse({player.Name}, {skill.Skill}, {difficulty}) - timeDiff: {timeDiff}");
                skill.PropertiesSkill.LastUsedTime = currentTime;       // update to prevent log spam
                return;
            }

            var difficulty_check = difficulty > last_difficulty;
            var time_check = timeDiff >= FullTime.TotalSeconds;

            if (difficulty_check || time_check)
            {
                // todo: not independent variables?
                // always scale if timeDiff < FullTime?
                var timeScale = 1.0f;
                if (!time_check)
                {
                    // 10 mins elapsed from 15 min FullTime:
                    // 0.66f timeScale
                    timeScale = (float)(timeDiff / FullTime.TotalSeconds);

                    // any rng involved?
                }

                skill.PropertiesSkill.ResistanceAtLastCheck = difficulty;
                skill.PropertiesSkill.LastUsedTime = currentTime;

                player.ChangesDetected = true;

                if (player.IsMaxLevel) return;

                var pp = (uint)Math.Round(difficulty * timeScale);
                var totalXPGranted = (long)Math.Round(pp * 1.1f);   // give additional 10% of proficiency XP to unreplacedigned XP

                if (totalXPGranted > 10000)
                {
                    log.Warn($"Proficiency.OnSuccessUse({player.Name}, {skill.Skill}, {difficulty}) - totalXPGranted: {totalXPGranted:N0}");
                }

                var maxLevel = Player.GetMaxLevel();
                var remainingXP = player.GetRemainingXP(maxLevel).Value;

                if (totalXPGranted > remainingXP)
                {
                    // checks and balances:
                    // total xp = pp * 1.1
                    // pp = total xp / 1.1

                    totalXPGranted = remainingXP;
                    pp = (uint)Math.Round(totalXPGranted / 1.1f);
                }

                // if skill is maxed out, but player is below MaxLevel,
                // not sure if retail granted 0%, 10%, or 110% of the pp to TotalExperience here
                // since pp is such a miniscule system at the higher levels,
                // going to just naturally add it to TotalXP for now..

                pp = Math.Min(pp, skill.ExperienceLeft);

                //Console.WriteLine($"Earned {pp} PP ({skill.Skill})");

                // send CP to player as unreplacedigned XP
                player.GrantXP(totalXPGranted, XpType.Proficiency, ShareType.None);

                // send PP to player as skill XP, which gets spent from the CP sent
                if (pp > 0)
                {
                    player.HandleActionRaiseSkill(skill.Skill, pp);
                }
            }
        }

19 View Source File : LunarYear.cs
License : MIT License
Project Creator : 6tail

private void compute()
        {
            // 节气(中午12点)
            double[] jq = new double[27];
            // 合朔,即每月初一(中午12点)
            double[] hs = new double[16];
            // 每月天数
            int[] dayCounts = new int[hs.Length - 1];

            int currentYear = this.year;

            int year = currentYear - 2000;
            // 从上年的大雪到下年的立春
            for (int i = 0, j = Lunar.JIE_QI_IN_USE.Length; i < j; i++)
            {
                // 精确的节气
                double t = 36525 * ShouXingUtil.saLonT((year + (17 + i) * 15d / 360) * ShouXingUtil.PI_2);
                t += ShouXingUtil.ONE_THIRD - ShouXingUtil.dtT(t);
                jieQiJulianDays.Add(t + Solar.J2000);
                // 按中午12点算的节气
                if (i > 0 && i < 28)
                {
                    jq[i - 1] = Math.Round(t);
                }
            }

            // 冬至前的初一
            double w = ShouXingUtil.calcShuo(jq[0]);
            if (w > jq[0])
            {
                w -= 29.5306;
            }
            // 递推每月初一
            for (int i = 0, j = hs.Length; i < j; i++)
            {
                hs[i] = ShouXingUtil.calcShuo(w + 29.5306 * i);
            }
            // 每月天数
            for (int i = 0, j = dayCounts.Length; i < j; i++)
            {
                dayCounts[i] = (int)(hs[i + 1] - hs[i]);
            }

            int currentYearLeap = -1;
            try
            {
                currentYearLeap = LEAP[currentYear];
            }
            catch { }
            if (-1 == currentYearLeap)
            {
                currentYearLeap = -1;
                if (hs[13] <= jq[24])
                {
                    int i = 1;
                    while (hs[i + 1] > jq[2 * i] && i < 13)
                    {
                        i++;
                    }
                    currentYearLeap = i;
                }
            }

            int prevYear = currentYear - 1;
            int prevYearLeap = -1;
            try
            {
                prevYearLeap = LEAP[prevYear];
            }
            catch { }
            prevYearLeap = -1 == prevYearLeap ? -1 : prevYearLeap - 12;

            int y = prevYear;
            int m = 11;
            for (int i = 0, j = dayCounts.Length; i < j; i++)
            {
                int cm = m;
                bool isNextLeap = false;
                if (y == currentYear && i == currentYearLeap)
                {
                    cm = -cm;
                }
                else if (y == prevYear && i == prevYearLeap)
                {
                    cm = -cm;
                }
                if (y == currentYear && i + 1 == currentYearLeap)
                {
                    isNextLeap = true;
                }
                else if (y == prevYear && i + 1 == prevYearLeap)
                {
                    isNextLeap = true;
                }
                this.months.Add(new LunarMonth(y, cm, dayCounts[i], hs[i] + Solar.J2000));
                if (!isNextLeap)
                {
                    m++;
                }
                if (m == 13)
                {
                    m = 1;
                    y++;
                }
            }
        }

19 View Source File : Monster_Melee.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public float GetArmorMod(WorldObject armor, DamageType damageType, bool ignoreMagicArmor)
        {
            // get base armor/resistance level
            var baseArmor = armor.GetProperty(PropertyInt.ArmorLevel) ?? 0;
            var armorType = armor.GetProperty(PropertyInt.ArmorType) ?? 0;
            var resistance = GetResistance(armor, damageType);

            /*Console.WriteLine(armor.Name);
            Console.WriteLine("--");
            Console.WriteLine("Base AL: " + baseArmor);
            Console.WriteLine("Base RL: " + resistance);*/

            // armor level additives
            var armorMod = armor.EnchantmentManager.GetArmorMod();

            if (ignoreMagicArmor)
                armorMod = (int)Math.Round(IgnoreMagicArmorScaled(armorMod));

            // Console.WriteLine("Impen: " + armorMod);
            var effectiveAL = baseArmor + armorMod;

            // resistance additives
            var armorBane = armor.EnchantmentManager.GetArmorModVsType(damageType);

            if (ignoreMagicArmor)
                armorBane = IgnoreMagicArmorScaled(armorBane);

            // Console.WriteLine("Bane: " + armorBane);
            var effectiveRL = (float)(resistance + armorBane);

            // resistance clamp
            effectiveRL = Math.Clamp(effectiveRL, -2.0f, 2.0f);

            // TODO: could brittlemail / lures send a piece of armor or clothing's AL into the negatives?
            //if (effectiveAL < 0 && effectiveRL != 0)
                //effectiveRL = 1.0f / effectiveRL;

            /*Console.WriteLine("Effective AL: " + effectiveAL);
            Console.WriteLine("Effective RL: " + effectiveRL);
            Console.WriteLine();*/

            return effectiveAL * effectiveRL;
        }

19 View Source File : SQLite.cs
License : GNU General Public License v3.0
Project Creator : 0xfd3

private void ReadMasterTable(ulong Offset)
        {
            if (this.db_bytes[(int)Offset] == 13)
            {
                ushort num2 = Convert.ToUInt16(decimal.Subtract(new decimal(this.ConvertToInteger(Convert.ToInt32(decimal.Add(new decimal(Offset), 3M)), 2)), decimal.One));
                int length = 0;
                if (this.master_table_entries != null)
                {
                    length = this.master_table_entries.Length;
                    this.master_table_entries = (sqlite_master_entry[])Utils.CopyArray((Array)this.master_table_entries, new sqlite_master_entry[(this.master_table_entries.Length + num2) + 1]);
                }
                else
                {
                    this.master_table_entries = new sqlite_master_entry[num2 + 1];
                }
                int num13 = num2;
                for (int i = 0; i <= num13; i++)
                {
                    ulong num = this.ConvertToInteger(Convert.ToInt32(decimal.Add(decimal.Add(new decimal(Offset), 8M), new decimal(i * 2))), 2);
                    if (decimal.Compare(new decimal(Offset), 100M) != 0)
                    {
                        num += Offset;
                    }
                    int endIndex = this.GVL((int)num);
                    long num7 = this.CVL((int)num, endIndex);
                    int num6 = this.GVL(Convert.ToInt32(decimal.Add(decimal.Add(new decimal(num), decimal.Subtract(new decimal(endIndex), new decimal(num))), decimal.One)));
                    this.master_table_entries[length + i].row_id = this.CVL(Convert.ToInt32(decimal.Add(decimal.Add(new decimal(num), decimal.Subtract(new decimal(endIndex), new decimal(num))), decimal.One)), num6);
                    num = Convert.ToUInt64(decimal.Add(decimal.Add(new decimal(num), decimal.Subtract(new decimal(num6), new decimal(num))), decimal.One));
                    endIndex = this.GVL((int)num);
                    num6 = endIndex;
                    long num5 = this.CVL((int)num, endIndex);
                    long[] numArray = new long[5];
                    int index = 0;
                    do
                    {
                        endIndex = num6 + 1;
                        num6 = this.GVL(endIndex);
                        numArray[index] = this.CVL(endIndex, num6);
                        if (numArray[index] > 9L)
                        {
                            if (this.IsOdd(numArray[index]))
                            {
                                numArray[index] = (long)Math.Round((double)(((double)(numArray[index] - 13L)) / 2.0));
                            }
                            else
                            {
                                numArray[index] = (long)Math.Round((double)(((double)(numArray[index] - 12L)) / 2.0));
                            }
                        }
                        else
                        {
                            numArray[index] = this.SQLDataTypeSize[(int)numArray[index]];
                        }
                        index++;
                    }
                    while (index <= 4);
                    if (decimal.Compare(new decimal(this.encoding), decimal.One) == 0)
                    {
                        this.master_table_entries[length + i].item_type = Encoding.Default.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(new decimal(num), new decimal(num5))), (int)numArray[0]);
                    }
                    else if (decimal.Compare(new decimal(this.encoding), 2M) == 0)
                    {
                        this.master_table_entries[length + i].item_type = Encoding.Unicode.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(new decimal(num), new decimal(num5))), (int)numArray[0]);
                    }
                    else if (decimal.Compare(new decimal(this.encoding), 3M) == 0)
                    {
                        this.master_table_entries[length + i].item_type = Encoding.BigEndianUnicode.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(new decimal(num), new decimal(num5))), (int)numArray[0]);
                    }
                    if (decimal.Compare(new decimal(this.encoding), decimal.One) == 0)
                    {
                        this.master_table_entries[length + i].item_name = Encoding.Default.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(decimal.Add(new decimal(num), new decimal(num5)), new decimal(numArray[0]))), (int)numArray[1]);
                    }
                    else if (decimal.Compare(new decimal(this.encoding), 2M) == 0)
                    {
                        this.master_table_entries[length + i].item_name = Encoding.Unicode.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(decimal.Add(new decimal(num), new decimal(num5)), new decimal(numArray[0]))), (int)numArray[1]);
                    }
                    else if (decimal.Compare(new decimal(this.encoding), 3M) == 0)
                    {
                        this.master_table_entries[length + i].item_name = Encoding.BigEndianUnicode.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(decimal.Add(new decimal(num), new decimal(num5)), new decimal(numArray[0]))), (int)numArray[1]);
                    }
                    this.master_table_entries[length + i].root_num = (long)this.ConvertToInteger(Convert.ToInt32(decimal.Add(decimal.Add(decimal.Add(decimal.Add(new decimal(num), new decimal(num5)), new decimal(numArray[0])), new decimal(numArray[1])), new decimal(numArray[2]))), (int)numArray[3]);
                    if (decimal.Compare(new decimal(this.encoding), decimal.One) == 0)
                    {
                        this.master_table_entries[length + i].sql_statement = Encoding.Default.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(decimal.Add(decimal.Add(decimal.Add(decimal.Add(new decimal(num), new decimal(num5)), new decimal(numArray[0])), new decimal(numArray[1])), new decimal(numArray[2])), new decimal(numArray[3]))), (int)numArray[4]);
                    }
                    else if (decimal.Compare(new decimal(this.encoding), 2M) == 0)
                    {
                        this.master_table_entries[length + i].sql_statement = Encoding.Unicode.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(decimal.Add(decimal.Add(decimal.Add(decimal.Add(new decimal(num), new decimal(num5)), new decimal(numArray[0])), new decimal(numArray[1])), new decimal(numArray[2])), new decimal(numArray[3]))), (int)numArray[4]);
                    }
                    else if (decimal.Compare(new decimal(this.encoding), 3M) == 0)
                    {
                        this.master_table_entries[length + i].sql_statement = Encoding.BigEndianUnicode.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(decimal.Add(decimal.Add(decimal.Add(decimal.Add(new decimal(num), new decimal(num5)), new decimal(numArray[0])), new decimal(numArray[1])), new decimal(numArray[2])), new decimal(numArray[3]))), (int)numArray[4]);
                    }
                }
            }
            else if (this.db_bytes[(int)Offset] == 5)
            {
                ushort num11 = Convert.ToUInt16(decimal.Subtract(new decimal(this.ConvertToInteger(Convert.ToInt32(decimal.Add(new decimal(Offset), 3M)), 2)), decimal.One));
                int num14 = num11;
                for (int j = 0; j <= num14; j++)
                {
                    ushort startIndex = (ushort)this.ConvertToInteger(Convert.ToInt32(decimal.Add(decimal.Add(new decimal(Offset), 12M), new decimal(j * 2))), 2);
                    if (decimal.Compare(new decimal(Offset), 100M) == 0)
                    {
                        this.ReadMasterTable(Convert.ToUInt64(decimal.Multiply(decimal.Subtract(new decimal(this.ConvertToInteger(startIndex, 4)), decimal.One), new decimal(this.page_size))));
                    }
                    else
                    {
                        this.ReadMasterTable(Convert.ToUInt64(decimal.Multiply(decimal.Subtract(new decimal(this.ConvertToInteger((int)(Offset + startIndex), 4)), decimal.One), new decimal(this.page_size))));
                    }
                }
                this.ReadMasterTable(Convert.ToUInt64(decimal.Multiply(decimal.Subtract(new decimal(this.ConvertToInteger(Convert.ToInt32(decimal.Add(new decimal(Offset), 8M)), 4)), decimal.One), new decimal(this.page_size))));
            }
        }

19 View Source File : PrintSettings.cs
License : GNU Lesser General Public License v3.0
Project Creator : acnicholas

public static bool CheckSheetSize(
                    double width, double height, double tw, double th)
        {
            double w = Math.Round(width);
            double h = Math.Round(height);

            // use a tolerance of 2mm.
            return tw + 2 > w && tw - 2 < w && th + 2 > h && th - 2 < h;
        }

19 View Source File : AccelCalculator.cs
License : MIT License
Project Creator : a1xd

public ReadOnlyCollection<SimulatedMouseInput> GetSimulatedInput()
        {
            var magnitudes = new List<SimulatedMouseInput>();

            foreach (var slowMoveX in SlowMovements)
            {
                var slowMoveY = 0.0;
                var ceilX = (int)Math.Round(slowMoveX*50);
                var ceilY = (int)Math.Round(slowMoveY*50);
                var ceilMagnitude = Magnitude(ceilX, ceilY);
                var timeFactor = ceilMagnitude / Magnitude(slowMoveX, slowMoveY);

                SimulatedMouseInput mouseInputData;
                mouseInputData.x = ceilX;
                mouseInputData.y = ceilY;
                mouseInputData.time = MeasurementTime*timeFactor;
                mouseInputData.velocity = DecimalCheck(Velocity(ceilX, ceilY, mouseInputData.time));
                mouseInputData.angle = Math.Atan2(ceilY, ceilX);
                magnitudes.Add(mouseInputData);
            }

            for (double i = 5; i < MaxVelocity; i+=Increment)
            {
                SimulatedMouseInput mouseInputData;
                var ceil = (int)Math.Ceiling(i);
                var timeFactor = ceil / i;
                mouseInputData.x = ceil;
                mouseInputData.y = 0;
                mouseInputData.time = MeasurementTime * timeFactor;
                mouseInputData.velocity = DecimalCheck(Velocity(ceil, 0, mouseInputData.time));
                mouseInputData.angle = Math.Atan2(ceil, 0);
                magnitudes.Add(mouseInputData);
            }

            magnitudes.Sort((m1, m2) => m1.velocity.CompareTo(m2.velocity));

            return magnitudes.AsReadOnly();
        }

19 View Source File : Helper.cs
License : MIT License
Project Creator : adamped

public static double round(this double value) => Math.Round(value);

19 View Source File : GaugeTimerTracker.cs
License : GNU Affero General Public License v3.0
Project Creator : 0ceal0t

public string GetText() => ((int)Math.Round(TimeLeft)).ToString();

19 View Source File : AMFPatches.cs
License : GNU General Public License v3.0
Project Creator : aedenthorn

public static bool _OnDealDamage_Prefix(BaseEnchantment __instance, string ____displayName, Monster monster, GameLocation location, Farmer who, ref int amount)
        {
            if (!(__instance is BaseWeaponEnchantment) || ____displayName == null  || ____displayName == "" || !ModEntry.advancedEnchantments.ContainsKey(____displayName) || (ModEntry.EnchantmentTriggers.ContainsKey(who.uniqueMultiplayerID + ____displayName) && ModEntry.EnchantmentTriggers[who.uniqueMultiplayerID + ____displayName] == Game1.ticks))
                return true;
            AdvancedEnchantmentData enchantment = ModEntry.advancedEnchantments[____displayName];

            if (enchantment?.parameters?.ContainsKey("trigger") != true)
                return true;

            if (enchantment.parameters["trigger"] == "damage" || (enchantment.parameters["trigger"] == "crit" && amount > (who.CurrentTool as MeleeWeapon).maxDamage) && !Environment.StackTrace.Contains("OnCalculateDamage"))
            {
                context.Monitor.Log($"Triggered enchantment {enchantment.name} on {enchantment.parameters["trigger"]} {amount} {(who.CurrentTool as MeleeWeapon).enchantments.Count}");
                ModEntry.EnchantmentTriggers[who.uniqueMultiplayerID + ____displayName] = Game1.ticks;
                if (enchantment.type == "heal")
                {
                    if (Game1.random.NextDouble() < float.Parse(enchantment.parameters["chance"]) / 100f)
                    {
                        int heal = Math.Max(1, (int)(amount * float.Parse(enchantment.parameters["amountMult"])));
                        who.health = Math.Min(who.maxHealth, Game1.player.health + heal);
                        location.debris.Add(new Debris(heal, new Vector2((float)Game1.player.getStandingX(), (float)Game1.player.getStandingY()), Color.Lime, 1f, who));
                        if (enchantment.parameters.ContainsKey("sound"))
                            Game1.playSound(enchantment.parameters["sound"]);
                    }
                }
                else if (enchantment.type == "coins")
                {
                    if (Game1.random.NextDouble() < float.Parse(enchantment.parameters["chance"]) / 100f)
                    {
                        float mult = float.Parse(enchantment.parameters["amountMult"]);
                        int coins = (int)Math.Round(mult * amount);
                        who.Money += coins;
                        if (enchantment.parameters.ContainsKey("sound"))
                            Game1.playSound(enchantment.parameters["sound"]);
                    }
                } 
            }
            return false;
        }

19 View Source File : ChessMatch.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void AdjustPlayerRanks(ObjectGuid playerGuid, ObjectGuid opponentGuid, ObjectGuid winnerGuid)
        {
            var player = PlayerManager.FindByGuid(playerGuid, out bool playerIsOnline);
            var opponent = PlayerManager.FindByGuid(opponentGuid, out bool opponentIsOnline);

            var rank = player.GetProperty(PropertyInt.ChessRank) ?? 1400;
            var opRank = 1400;
            if (opponent != null)   // chess ai
                opRank = opponent.GetProperty(PropertyInt.ChessRank) ?? 1400;

            var chance = ExpectationToWin(rank, opRank);

            var win = playerGuid == winnerGuid ? 1.0f : 0.0f;
            var delta = (int)Math.Round(RankFactor * (win - chance));

            player.SetProperty(PropertyInt.ChessRank, rank + delta);

            if (opponent != null)
                opponent.SetProperty(PropertyInt.ChessRank, opRank - delta);

            if (playerIsOnline)
            {
                var onlinePlayer = PlayerManager.GetOnlinePlayer(playerGuid);
                onlinePlayer.Session.Network.EnqueueSend(new GameMessagePrivateUpdatePropertyInt(onlinePlayer, PropertyInt.ChessRank, rank + delta));
            }

            if (opponent != null && opponentIsOnline)
            {
                var onlineOp = PlayerManager.GetOnlinePlayer(opponentGuid);
                onlineOp.Session.Network.EnqueueSend(new GameMessagePrivateUpdatePropertyInt(onlineOp, PropertyInt.ChessRank, opRank - delta));
            }
        }

19 View Source File : Fellowship.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void SplitXp(ulong amount, XpType xpType, ShareType shareType, Player player)
        {
            // https://asheron.fandom.com/wiki/Announcements_-_2002/02_-_Fever_Dreams#Letter_to_the_Players_1

            var fellowshipMembers = GetFellowshipMembers();

            shareType &= ~ShareType.Fellowship;

            // quest turn-ins: flat share (retail default)
            if (xpType == XpType.Quest && !PropertyManager.GetBool("fellow_quest_bonus").Item)
            {
                var perAmount = (long)amount / fellowshipMembers.Count;

                foreach (var member in fellowshipMembers.Values)
                {
                    var fellowXpType = player == member ? XpType.Quest : XpType.Fellowship;

                    member.GrantXP(perAmount, fellowXpType, shareType);
                }
            }

            // divides XP evenly to all the sharable fellows within level range,
            // but with a significant boost to the amount of xp, based on # of fellowship members
            else if (EvenShare)
            {
                var totalAmount = (ulong)Math.Round(amount * GetMemberSharePercent());

                foreach (var member in fellowshipMembers.Values)
                {
                    var shareAmount = (ulong)Math.Round(totalAmount * GetDistanceScalar(player, member, xpType));

                    var fellowXpType = player == member ? xpType : XpType.Fellowship;

                    member.GrantXP((long)shareAmount, fellowXpType, shareType);
                }

                return;
            }

            // divides XP to all sharable fellows within level range
            // based on each fellowship member's level
            else
            {
                var levelXPSum = fellowshipMembers.Values.Select(p => p.GetXPToNextLevel(p.Level.Value)).Sum();

                foreach (var member in fellowshipMembers.Values)
                {
                    var levelXPScale = (double)member.GetXPToNextLevel(member.Level.Value) / levelXPSum;

                    var playerTotal = (ulong)Math.Round(amount * levelXPScale * GetDistanceScalar(player, member, xpType));

                    var fellowXpType = player == member ? xpType : XpType.Fellowship;

                    member.GrantXP((long)playerTotal, fellowXpType, shareType);
                }
            }
        }

19 View Source File : ImageTransform.cs
License : MIT License
Project Creator : 0xC0000054

internal static void Crop(CleanApertureBox cleanApertureBox, ref Surface surface)
        {
            if (cleanApertureBox is null)
            {
                ExceptionUtil.ThrowArgumentNullException(nameof(cleanApertureBox));
            }

            if (cleanApertureBox.Width.Denominator == 0 ||
                cleanApertureBox.Height.Denominator == 0 ||
                cleanApertureBox.HorizontalOffset.Denominator == 0 ||
                cleanApertureBox.VerticalOffset.Denominator == 0)
            {
                return;
            }

            int cropWidth = cleanApertureBox.Width.ToInt32();
            int cropHeight = cleanApertureBox.Height.ToInt32();

            if (cropWidth <= 0 || cropHeight <= 0)
            {
                // Invalid crop width/height.
                return;
            }

            double offsetX = cleanApertureBox.HorizontalOffset.ToDouble();
            double offsetY = cleanApertureBox.VerticalOffset.ToDouble();

            double pictureCenterX = offsetX + ((surface.Width - 1) / 2.0);
            double pictureCenterY = offsetY + ((surface.Height - 1) / 2.0);

            int cropRectX = (int)Math.Round(pictureCenterX - ((cropWidth - 1) / 2.0));
            int cropRectY = (int)Math.Round(pictureCenterY - ((cropHeight - 1) / 2.0));

            Rectangle cropRect = new Rectangle(cropRectX, cropRectY, cropWidth, cropHeight);

            // Check that the crop rectangle is within the surface bounds.
            if (cropRect.IntersectsWith(surface.Bounds))
            {
                Surface temp = new Surface(cropWidth, cropHeight);
                try
                {
                    temp.CopySurface(surface, cropRect);

                    surface.Dispose();
                    surface = temp;
                    temp = null;
                }
                finally
                {
                    temp?.Dispose();
                }
            }
        }

19 View Source File : AttackList.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void OnHeal(int healAmount, int missingHealth)
        {
            // on heal, scale the damage from each source by 1 - healAmount / missingHealth
            var scalar = 1.0f - healAmount / missingHealth;

            foreach (var damager in Damagers.Keys)
                Damagers[damager] *= (uint)Math.Round(scalar);
        }

19 View Source File : spline3.cs
License : MIT License
Project Creator : 1CM69

public static void splinelintransx(ref double[] c, double a, double b)
  {
    double s = 0.0;
    double ds = 0.0;
    double d2s = 0.0;
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    double[] numArray3 = new double[0];
    int n = (int) System.Math.Round(c[2]);
    if (a == 0.0)
    {
      double num = spline3.splineinterpolation(ref c, b);
      for (int index = 0; index <= n - 2; ++index)
      {
        c[3 + n + 4 * index] = num;
        c[3 + n + 4 * index + 1] = 0.0;
        c[3 + n + 4 * index + 2] = 0.0;
        c[3 + n + 4 * index + 3] = 0.0;
      }
    }
    else
    {
      double[] x = new double[n - 1 + 1];
      double[] y = new double[n - 1 + 1];
      double[] d = new double[n - 1 + 1];
      for (int index = 0; index <= n - 1; ++index)
      {
        x[index] = c[3 + index];
        spline3.splinedifferentiation(ref c, x[index], ref s, ref ds, ref d2s);
        x[index] = (x[index] - b) / a;
        y[index] = s;
        d[index] = a * ds;
      }
      spline3.buildhermitespline(x, y, d, n, ref c);
    }
  }

19 View Source File : ImgTex.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void MergeTexture(byte[] data, uint dest_height, uint dest_width, ImgTex csi_merge_tex, uint tiling, ImgTex alphaMap, LandDefs.Rotation rot)
        {
            var imageData = csi_merge_tex.ImageData;

            var src_height = imageData != null ? imageData.Height : 0;
            var src_width = imageData != null ? imageData.Width : 0;

            var alphaData = alphaMap.ImageData;
            var alpha_width = alphaData != null ? alphaData.Width : 0;
            var alpha_height = alphaData != null ? alphaData.Height : 0;

            var alpha_scale = (float)dest_width / alpha_width;

            var pixelIdx = 0;
            var stepX = 0;
            var stepY = 0;

            switch (rot)
            {
                case LandDefs.Rotation.Rot0:
                    pixelIdx = 0;
                    stepX = 1;
                    stepY = src_width;
                    break;
                case LandDefs.Rotation.Rot90:
                    pixelIdx = src_width - 1;
                    stepX = src_width;
                    stepY = -1;
                    break;
                case LandDefs.Rotation.Rot180:
                    pixelIdx = src_width * src_height - 1;
                    stepX = -1;
                    stepY = -src_width;
                    break;
                case LandDefs.Rotation.Rot270:
                    pixelIdx = src_width * (src_height - 1);
                    stepX = -src_width;
                    stepY = -1;
                    break;
            }

            // alphaStep handles upscaling / downscaling
            var alphaStep = 1.0f / alpha_scale;

            // copy csi_merge_tex into dest buffer (data)
            Array.Copy(imageData.Data, data, imageData.Data.Length);

            // start walking the alpha map
            for (var _alphaY = 0.0f; _alphaY < alpha_height; _alphaY += alphaStep)
            {
                var alphaY = (int)Math.Round(_alphaY);

                for (var _alphaX = 0.0f; _alphaX < alpha_width; _alphaX += alphaStep)
                {
                    // TODO: handle rotation
                    var alphaX = (int)Math.Round(_alphaX);

                    var idx = (alphaY * alpha_width + alphaX) * 4;
                    var a = alphaData.Data[idx];
                    data[idx] = a;
                }
            }
        }

19 View Source File : Cloak.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void ShowMessage(Creature defender, WorldObject attacker, float origDamage, float reducedDamage)
        {
            ShowMessage(defender, attacker, (int)Math.Round(origDamage), (int)Math.Round(reducedDamage));
        }

19 View Source File : spline3.cs
License : MIT License
Project Creator : 1CM69

public static double splineintegration(ref double[] c, double x)
  {
    int num1 = (int) System.Math.Round(c[2]);
    int index1 = 3;
    int num2 = 3 + num1 - 2 + 1;
    while (index1 != num2 - 1)
    {
      int index2 = (index1 + num2) / 2;
      if (c[index2] >= x)
        num2 = index2;
      else
        index1 = index2;
    }
    double num3 = 0.0;
    for (int index2 = 3; index2 <= index1 - 1; ++index2)
    {
      double X = c[index2 + 1] - c[index2];
      int index3 = 3 + num1 + 4 * (index2 - 3);
      num3 = num3 + c[index3] * X + c[index3 + 1] * AP.Math.Sqr(X) / 2.0 + c[index3 + 2] * AP.Math.Sqr(X) * X / 3.0 + c[index3 + 3] * AP.Math.Sqr(AP.Math.Sqr(X)) / 4.0;
    }
    double X1 = x - c[index1];
    int index4 = 3 + num1 + 4 * (index1 - 3);
    return num3 + c[index4] * X1 + c[index4 + 1] * AP.Math.Sqr(X1) / 2.0 + c[index4 + 2] * AP.Math.Sqr(X1) * X1 / 3.0 + c[index4 + 3] * AP.Math.Sqr(AP.Math.Sqr(X1)) / 4.0;
  }

19 View Source File : Hotspot.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

private void Activate(Creature creature)
        {
            if (!IsHot) return;

            var amount = DamageNext;
            var iAmount = (int)Math.Round(amount);

            var player = creature as Player;

            switch (DamageType)
            {
                default:

                    if (creature.Invincible) return;

                    amount *= creature.GetResistanceMod(DamageType, this, null);

                    if (player != null)
                        iAmount = player.TakeDamage(this, DamageType, amount, Server.Enreplacedy.BodyPart.Foot);
                    else
                        iAmount = (int)creature.TakeDamage(this, DamageType, amount);

                    if (creature.IsDead && Creatures.Contains(creature.Guid))
                        Creatures.Remove(creature.Guid);

                    break;

                case DamageType.Mana:
                    iAmount = creature.UpdateVitalDelta(creature.Mana, -iAmount);
                    break;

                case DamageType.Stamina:
                    iAmount = creature.UpdateVitalDelta(creature.Stamina, -iAmount);
                    break;

                case DamageType.Health:
                    iAmount = creature.UpdateVitalDelta(creature.Health, -iAmount);

                    if (iAmount > 0)
                        creature.DamageHistory.OnHeal((uint)iAmount);
                    else
                        creature.DamageHistory.Add(this, DamageType.Health, (uint)-iAmount);

                    break;
            }

            if (!Visibility)
                EnqueueBroadcast(new GameMessageSound(Guid, Sound.TriggerActivated, 1.0f));

            if (player != null && !string.IsNullOrWhiteSpace(ActivationTalk) && iAmount != 0)
                player.Session.Network.EnqueueSend(new GameMessageSystemChat(ActivationTalk.Replace("%i", Math.Abs(iAmount).ToString()), ChatMessageType.Broadcast));

            // perform activation emote
            if (ActivationResponse.HasFlag(ActivationResponse.Emote))
                OnEmote(creature);
        }

19 View Source File : SQLite.cs
License : GNU General Public License v3.0
Project Creator : 0xfd3

private bool ReadTableFromOffset(ulong Offset)
        {
            if (this.db_bytes[(int)Offset] == 13)
            {
                int num2 = Convert.ToInt32(decimal.Subtract(new decimal(this.ConvertToInteger(Convert.ToInt32(decimal.Add(new decimal(Offset), 3M)), 2)), decimal.One));
                int length = 0;
                if (this.table_entries != null)
                {
                    length = this.table_entries.Length;
                    this.table_entries = (table_entry[])Utils.CopyArray((Array)this.table_entries, new table_entry[(this.table_entries.Length + num2) + 1]);
                }
                else
                {
                    this.table_entries = new table_entry[num2 + 1];
                }
                int num16 = num2;
                for (int i = 0; i <= num16; i++)
                {
                    record_header_field[] _fieldArray = null;
                    ulong num = this.ConvertToInteger(Convert.ToInt32(decimal.Add(decimal.Add(new decimal(Offset), 8M), new decimal(i * 2))), 2);
                    if (decimal.Compare(new decimal(Offset), 100M) != 0)
                    {
                        num += Offset;
                    }
                    int endIndex = this.GVL((int)num);
                    long num9 = this.CVL((int)num, endIndex);
                    int num8 = this.GVL(Convert.ToInt32(decimal.Add(decimal.Add(new decimal(num), decimal.Subtract(new decimal(endIndex), new decimal(num))), decimal.One)));
                    this.table_entries[length + i].row_id = this.CVL(Convert.ToInt32(decimal.Add(decimal.Add(new decimal(num), decimal.Subtract(new decimal(endIndex), new decimal(num))), decimal.One)), num8);
                    num = Convert.ToUInt64(decimal.Add(decimal.Add(new decimal(num), decimal.Subtract(new decimal(num8), new decimal(num))), decimal.One));
                    endIndex = this.GVL((int)num);
                    num8 = endIndex;
                    long num7 = this.CVL((int)num, endIndex);
                    long num10 = Convert.ToInt64(decimal.Add(decimal.Subtract(new decimal(num), new decimal(endIndex)), decimal.One));
                    for (int j = 0; num10 < num7; j++)
                    {
                        _fieldArray = (record_header_field[])Utils.CopyArray((Array)_fieldArray, new record_header_field[j + 1]);
                        endIndex = num8 + 1;
                        num8 = this.GVL(endIndex);
                        _fieldArray[j].type = this.CVL(endIndex, num8);
                        if (_fieldArray[j].type > 9L)
                        {
                            if (this.IsOdd(_fieldArray[j].type))
                            {
                                _fieldArray[j].size = (long)Math.Round((double)(((double)(_fieldArray[j].type - 13L)) / 2.0));
                            }
                            else
                            {
                                _fieldArray[j].size = (long)Math.Round((double)(((double)(_fieldArray[j].type - 12L)) / 2.0));
                            }
                        }
                        else
                        {
                            _fieldArray[j].size = this.SQLDataTypeSize[(int)_fieldArray[j].type];
                        }
                        num10 = (num10 + (num8 - endIndex)) + 1L;
                    }
                    this.table_entries[length + i].content = new string[(_fieldArray.Length - 1) + 1];
                    int num4 = 0;
                    int num17 = _fieldArray.Length - 1;
                    for (int k = 0; k <= num17; k++)
                    {
                        if (_fieldArray[k].type > 9L)
                        {
                            if (!this.IsOdd(_fieldArray[k].type))
                            {
                                if (decimal.Compare(new decimal(this.encoding), decimal.One) == 0)
                                {
                                    this.table_entries[length + i].content[k] = Encoding.Default.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(decimal.Add(new decimal(num), new decimal(num7)), new decimal(num4))), (int)_fieldArray[k].size);
                                }
                                else if (decimal.Compare(new decimal(this.encoding), 2M) == 0)
                                {
                                    this.table_entries[length + i].content[k] = Encoding.Unicode.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(decimal.Add(new decimal(num), new decimal(num7)), new decimal(num4))), (int)_fieldArray[k].size);
                                }
                                else if (decimal.Compare(new decimal(this.encoding), 3M) == 0)
                                {
                                    this.table_entries[length + i].content[k] = Encoding.BigEndianUnicode.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(decimal.Add(new decimal(num), new decimal(num7)), new decimal(num4))), (int)_fieldArray[k].size);
                                }
                            }
                            else
                            {
                                this.table_entries[length + i].content[k] = Encoding.Default.GetString(this.db_bytes, Convert.ToInt32(decimal.Add(decimal.Add(new decimal(num), new decimal(num7)), new decimal(num4))), (int)_fieldArray[k].size);
                            }
                        }
                        else
                        {
                            this.table_entries[length + i].content[k] = Conversions.ToString(this.ConvertToInteger(Convert.ToInt32(decimal.Add(decimal.Add(new decimal(num), new decimal(num7)), new decimal(num4))), (int)_fieldArray[k].size));
                        }
                        num4 += (int)_fieldArray[k].size;
                    }
                }
            }
            else if (this.db_bytes[(int)Offset] == 5)
            {
                ushort num14 = Convert.ToUInt16(decimal.Subtract(new decimal(this.ConvertToInteger(Convert.ToInt32(decimal.Add(new decimal(Offset), 3M)), 2)), decimal.One));
                int num18 = num14;
                for (int m = 0; m <= num18; m++)
                {
                    ushort num13 = (ushort)this.ConvertToInteger(Convert.ToInt32(decimal.Add(decimal.Add(new decimal(Offset), 12M), new decimal(m * 2))), 2);
                    this.ReadTableFromOffset(Convert.ToUInt64(decimal.Multiply(decimal.Subtract(new decimal(this.ConvertToInteger((int)(Offset + num13), 4)), decimal.One), new decimal(this.page_size))));
                }
                this.ReadTableFromOffset(Convert.ToUInt64(decimal.Multiply(decimal.Subtract(new decimal(this.ConvertToInteger(Convert.ToInt32(decimal.Add(new decimal(Offset), 8M)), 4)), decimal.One), new decimal(this.page_size))));
            }
            return true;
        }

19 View Source File : Monster_Combat.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public virtual uint TakeDamage(WorldObject source, DamageType damageType, float amount, bool crit = false)
        {
            var tryDamage = (int)Math.Round(amount);
            var damage = -UpdateVitalDelta(Health, -tryDamage);

            // TODO: update monster stamina?

            // source should only be null for combined DoT ticks from multiple sources
            if (source != null)
            {
                if (damage >= 0)
                    DamageHistory.Add(source, damageType, (uint)damage);
                else
                    DamageHistory.OnHeal((uint)-damage);
            }

            if (Health.Current <= 0)
            {
                OnDeath(DamageHistory.LastDamager, damageType, crit);

                Die();
            }
            return (uint)Math.Max(0, damage);
        }

19 View Source File : Mathd.cs
License : MIT License
Project Creator : 734843327

public static double Round(double d) {
            return Math.Round(d);
        }

19 View Source File : SpellProjectile.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void DamageTarget(Creature target, float damage, bool critical, bool critDefended, bool overpower)
        {
            var targetPlayer = target as Player;

            if (targetPlayer != null && targetPlayer.Invincible || target.IsDead)
                return;

            var sourceCreature = ProjectileSource as Creature;
            var sourcePlayer = ProjectileSource as Player;

            var pkBattle = sourcePlayer != null && targetPlayer != null;

            var amount = 0u;
            var percent = 0.0f;

            var damageRatingMod = 1.0f;
            var heritageMod = 1.0f;
            var sneakAttackMod = 1.0f;
            var critDamageRatingMod = 1.0f;
            var pkDamageRatingMod = 1.0f;

            var damageResistRatingMod = 1.0f;
            var critDamageResistRatingMod = 1.0f;
            var pkDamageResistRatingMod = 1.0f;

            WorldObject equippedCloak = null;

            // handle life projectiles for stamina / mana
            if (Spell.Category == SpellCategory.StaminaLowering)
            {
                percent = damage / target.Stamina.MaxValue;
                amount = (uint)-target.UpdateVitalDelta(target.Stamina, (int)-Math.Round(damage));
            }
            else if (Spell.Category == SpellCategory.Mreplacedowering)
            {
                percent = damage / target.Mana.MaxValue;
                amount = (uint)-target.UpdateVitalDelta(target.Mana, (int)-Math.Round(damage));
            }
            else
            {
                // for possibly applying sneak attack to magic projectiles,
                // only do this for health-damaging projectiles?
                if (sourcePlayer != null)
                {
                    // TODO: use target direction vs. projectile position, instead of player position
                    // could sneak attack be applied to void DoTs?
                    sneakAttackMod = sourcePlayer.GetSneakAttackMod(target);
                    //Console.WriteLine("Magic sneak attack:  + sneakAttackMod);
                    heritageMod = sourcePlayer.GetHeritageBonus(sourcePlayer.GetEquippedWand()) ? 1.05f : 1.0f;
                }

                var damageRating = sourceCreature?.GetDamageRating() ?? 0;
                damageRatingMod = Creature.AdditiveCombine(Creature.GetPositiveRatingMod(damageRating), heritageMod, sneakAttackMod);

                damageResistRatingMod = target.GetDamageResistRatingMod(CombatType.Magic);

                if (critical)
                {
                    critDamageRatingMod = Creature.GetPositiveRatingMod(sourceCreature?.GetCritDamageRating() ?? 0);
                    critDamageResistRatingMod = Creature.GetNegativeRatingMod(target.GetCritDamageResistRating());

                    damageRatingMod = Creature.AdditiveCombine(damageRatingMod, critDamageRatingMod);
                    damageResistRatingMod = Creature.AdditiveCombine(damageResistRatingMod, critDamageResistRatingMod);
                }

                if (pkBattle)
                {
                    pkDamageRatingMod = Creature.GetPositiveRatingMod(sourceCreature?.GetPKDamageRating() ?? 0);
                    pkDamageResistRatingMod = Creature.GetNegativeRatingMod(target.GetPKDamageResistRating());

                    damageRatingMod = Creature.AdditiveCombine(damageRatingMod, pkDamageRatingMod);
                    damageResistRatingMod = Creature.AdditiveCombine(damageResistRatingMod, pkDamageResistRatingMod);
                }

                damage *= damageRatingMod * damageResistRatingMod;

                percent = damage / target.Health.MaxValue;

                //Console.WriteLine($"Damage rating: " + Creature.ModToRating(damageRatingMod));

                equippedCloak = target.EquippedCloak;

                if (equippedCloak != null && Cloak.HasDamageProc(equippedCloak) && Cloak.RollProc(equippedCloak, percent))
                {
                    var reducedDamage = Cloak.GetReducedAmount(ProjectileSource, damage);

                    Cloak.ShowMessage(target, ProjectileSource, damage, reducedDamage);

                    damage = reducedDamage;
                    percent = damage / target.Health.MaxValue;
                }

                amount = (uint)-target.UpdateVitalDelta(target.Health, (int)-Math.Round(damage));
                target.DamageHistory.Add(ProjectileSource, Spell.DamageType, amount);

                //if (targetPlayer != null && targetPlayer.Fellowship != null)
                    //targetPlayer.Fellowship.OnVitalUpdate(targetPlayer);
            }

            amount = (uint)Math.Round(damage);    // full amount for debugging

            // show debug info
            if (sourceCreature != null && sourceCreature.DebugDamage.HasFlag(Creature.DebugDamageType.Attacker))
            {
                ShowInfo(sourceCreature, heritageMod, sneakAttackMod, damageRatingMod, damageResistRatingMod, critDamageRatingMod, critDamageResistRatingMod, pkDamageRatingMod, pkDamageResistRatingMod, damage);
            }
            if (target.DebugDamage.HasFlag(Creature.DebugDamageType.Defender))
            {
                ShowInfo(target, heritageMod, sneakAttackMod, damageRatingMod, damageResistRatingMod, critDamageRatingMod, critDamageResistRatingMod, pkDamageRatingMod, pkDamageResistRatingMod, damage);
            }

            if (target.IsAlive)
            {
                string verb = null, plural = null;
                Strings.GetAttackVerb(Spell.DamageType, percent, ref verb, ref plural);
                var type = Spell.DamageType.GetName().ToLower();

                var critMsg = critical ? "Critical hit! " : "";
                var sneakMsg = sneakAttackMod > 1.0f ? "Sneak Attack! " : "";
                var overpowerMsg = overpower ? "Overpower! " : "";

                var nonHealth = Spell.Category == SpellCategory.StaminaLowering || Spell.Category == SpellCategory.Mreplacedowering;

                if (sourcePlayer != null)
                {
                    var critProt = critDefended ? " Your critical hit was avoided with their augmentation!" : "";

                    var attackerMsg = $"{critMsg}{overpowerMsg}{sneakMsg}You {verb} {target.Name} for {amount} points with {Spell.Name}.{critProt}";

                    // could these crit / sneak attack?
                    if (nonHealth)
                    {
                        var vital = Spell.Category == SpellCategory.StaminaLowering ? "stamina" : "mana";
                        attackerMsg = $"With {Spell.Name} you drain {amount} points of {vital} from {target.Name}.";
                    }

                    if (!sourcePlayer.SquelchManager.Squelches.Contains(target, ChatMessageType.Magic))
                        sourcePlayer.Session.Network.EnqueueSend(new GameMessageSystemChat(attackerMsg, ChatMessageType.Magic));
                }

                if (targetPlayer != null)
                {
                    var critProt = critDefended ? " Your augmentation allows you to avoid a critical hit!" : "";

                    var defenderMsg = $"{critMsg}{overpowerMsg}{sneakMsg}{ProjectileSource.Name} {plural} you for {amount} points with {Spell.Name}.{critProt}";

                    if (nonHealth)
                    {
                        var vital = Spell.Category == SpellCategory.StaminaLowering ? "stamina" : "mana";
                        defenderMsg = $"{ProjectileSource.Name} casts {Spell.Name} and drains {amount} points of your {vital}.";
                    }

                    if (!targetPlayer.SquelchManager.Squelches.Contains(ProjectileSource, ChatMessageType.Magic))
                        targetPlayer.Session.Network.EnqueueSend(new GameMessageSystemChat(defenderMsg, ChatMessageType.Magic));

                    if (sourceCreature != null)
                        targetPlayer.SetCurrentAttacker(sourceCreature);
                }

                if (!nonHealth)
                {
                    if (equippedCloak != null && Cloak.HasProcSpell(equippedCloak))
                        Cloak.TryProcSpell(target, ProjectileSource, equippedCloak, percent);

                    target.EmoteManager.OnDamage(sourcePlayer);

                    if (critical)
                        target.EmoteManager.OnReceiveCritical(sourcePlayer);
                }
            }
            else
            {
                var lastDamager = ProjectileSource != null ? new DamageHistoryInfo(ProjectileSource) : null;
                target.OnDeath(lastDamager, Spell.DamageType, critical);
                target.Die();
            }
        }

19 View Source File : UIIconTimer.cs
License : GNU Affero General Public License v3.0
Project Creator : 0ceal0t

public override void SetProgress(float current, float max) {
            if (State == IconState.TimerDone && current <= 0) return;
            State = IconState.TimerRunning;

            UIHelper.Show(Text);
            Text->SetText(((int)Math.Round(current)).ToString());

            UIHelper.Show(Ring);
            Ring->PartId = (ushort)(80 - (float)(current / max) * 80);

            JobBars.IconBuilder.AddIconOverride(new IntPtr(OriginalImage));
            SetDimmed(true);
        }

19 View Source File : Player_Xp.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void GrantLevelProportionalXp(double percent, long min, long max)
        {
            var nextLevelXP = GetXPBetweenLevels(Level.Value, Level.Value + 1);

            var scaledXP = (long)Math.Round(nextLevelXP * percent);

            if (max > 0)
                scaledXP = Math.Min(scaledXP, max);

            if (min > 0)
                scaledXP = Math.Max(scaledXP, min);

            // apply xp modifiers?
            EarnXP(scaledXP, XpType.Quest, ShareType.Allegiance);
        }

19 View Source File : TestOpen3D.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

public static PointCloud Normals(PointCloud cloud, double radius=0.1, int iterations = 30, int neighbours = 100) {

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Conversion from Rhino PointCloud to Flat Array
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //var watch = System.Diagnostics.Stopwatch.StartNew();


            double[] p = new double[cloud.Count * 3];
            ulong p_c = (ulong)cloud.Count;

            double[] n = new double[cloud.Count * 3];
            ulong n_c = p_c;

            double[] c = new double[cloud.Count * 3];
            ulong c_c = p_c;

            bool hasColors = cloud.ContainsColors;

            System.Threading.Tasks.Parallel.For(0, cloud.Count, i => {
                //for (int i = 0; i < cloud.Count; i++) {
                p[i * 3 + 0] = cloud[i].Location.X;
                p[i * 3 + 1] = cloud[i].Location.Y;
                p[i * 3 + 2] = cloud[i].Location.Z;
                if (cloud.ContainsNormals) {
                    n[i * 3 + 0] = cloud[i].Normal.X;
                    n[i * 3 + 1] = cloud[i].Normal.Y;
                    n[i * 3 + 2] = cloud[i].Normal.Z;
                }
                if (cloud.ContainsColors) {
                    c[i * 3 + 0] = cloud[i].Color.R;
                    c[i * 3 + 1] = cloud[i].Color.G;
                    c[i * 3 + 2] = cloud[i].Color.B;
                }
                //}
                //if (Math.Abs(FastPlaneToPt(denom, eq[0], eq[1], eq[2], eq[3], points[i])) <= tol)
                //    sectionPoints.Add(points[i]);
            });



            //watch.Stop();
            // Rhino.RhinoApp.WriteLine("Convert PointCloud to double array "+watch.ElapsedMilliseconds.ToString());


            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Call C++
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //watch = System.Diagnostics.Stopwatch.StartNew();
            IntPtr p_pointer = IntPtr.Zero;
            int p_pointer_c = 0;
            IntPtr n_pointer = IntPtr.Zero;
            int n_pointer_c = 0;
            IntPtr c_pointer = IntPtr.Zero;
            int c_pointer_c = 0;


            UnsafeOpen3D.Open3DNormals(
                p, p_c,
                n, n_c,
                c, c_c,
                radius,
                iterations,
                neighbours,
                ref p_pointer, ref p_pointer_c,
                ref n_pointer, ref n_pointer_c,
                ref c_pointer, ref c_pointer_c
                );

            //watch.Stop();
            //Rhino.RhinoApp.WriteLine("C++ Downsample "+ watch.ElapsedMilliseconds.ToString());

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Convert Pointers to double arrays
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Convert faceIndicesPointer to C# int[]

            //watch = System.Diagnostics.Stopwatch.StartNew();
            double[] P = new double[p_pointer_c];
            Marshal.Copy(p_pointer, P, 0, P.Length);

            double[] N = new double[n_pointer_c];
            Marshal.Copy(n_pointer, N, 0, P.Length);

            double[] C = new double[c_pointer_c];
            Marshal.Copy(c_pointer, C, 0, P.Length);
            //watch.Stop();
            //Rhino.RhinoApp.WriteLine("Convert Pointer to double Array "+watch.ElapsedMilliseconds.ToString());

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Release C++ memory
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            UnsafeOpen3D.ReleaseDouble(p_pointer, true);
            UnsafeOpen3D.ReleaseDouble(n_pointer, true);
            UnsafeOpen3D.ReleaseDouble(c_pointer, true);


            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Convert C++ to C# Pointcloud
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //watch = System.Diagnostics.Stopwatch.StartNew();
            PointCloud newCloud = new PointCloud();

            //System.Threading.Tasks.Parallel.For(0, P.Length, i => {

            //    newCloud.Add(new Point3d(P[i + 0], P[i + 1], P[i + 2]));

            //    if (!(C[i + 0] == 0 && C[i + 1] == 0 && C[i + 2] == 0)) {
            //        newCloud[(int)(i / 3)].Color = System.Drawing.Color.FromArgb((int)C[i + 0], (int)C[i + 1], (int)C[i + 2]);
            //    }

            //});

            //System.Threading.Tasks.Parallel.For(0, P.Length, i => {

            //    if (!(N[i + 0] == 0 && N[i + 1] == 0 && N[i + 2] == 0)) {
            //        newCloud[(int)(i / 3)].Normal = new Vector3d(N[i + 0], N[i + 1], N[i + 2]);
            //    }

            //});







            for (int i = 0; i < P.Length; i += 3) {
                newCloud.Add(new Point3d(P[i + 0], P[i + 1], P[i + 2]));

                //if (c[i + 0] == 0 && c[i + 1] == 0 && c[i + 2] == 0) continue;
                newCloud[(int)Math.Round((i / 3.0))].Color = System.Drawing.Color.FromArgb((int)c[i + 0], (int)c[i + 1], (int)c[i + 2]);

            }


            for (int i = 0; i < P.Length; i += 3) {
                if (N[i + 0] == 0 && N[i + 1] == 0 && N[i + 2] == 0) continue;
                newCloud[(int)Math.Round((i / 3.0))].Normal = new Vector3d(N[i + 0], N[i + 1], N[i + 2]);
            }




            //watch.Stop();
            //Rhino.RhinoApp.WriteLine("Create PointCloud from double arrays "+ watch.ElapsedMilliseconds.ToString());


            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Output
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            return newCloud;

        }

19 View Source File : DegreeToScalarConverter.cs
License : MIT License
Project Creator : Actipro

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
		#endif
			var angle = (double)value;

			var stepValue = 1.0;
			var parameterText = parameter as string;
			if (!string.IsNullOrEmpty(parameterText))
				double.TryParse(parameterText, out stepValue);

			return Math.Round(angle / stepValue);
		}

19 View Source File : spline3.cs
License : MIT License
Project Creator : 1CM69

public static double splineinterpolation(ref double[] c, double x)
  {
    int num1 = (int) System.Math.Round(c[2]);
    int index1 = 3;
    int num2 = 3 + num1 - 2 + 1;
    while (index1 != num2 - 1)
    {
      int index2 = (index1 + num2) / 2;
      if (c[index2] >= x)
        num2 = index2;
      else
        index1 = index2;
    }
    x -= c[index1];
    int index3 = 3 + num1 + 4 * (index1 - 3);
    return c[index3] + x * (c[index3 + 1] + x * (c[index3 + 2] + x * c[index3 + 3]));
  }

19 View Source File : Round.cs
License : GNU General Public License v3.0
Project Creator : Adam-Wilkinson

public void Evaluate()
        {
            object testValueToRound = _valueToRound[INodeField.InputKey];
            double valueToRound = (double)testValueToRound;
            double roundValueField = _roundValueField.GetInput<double>();
            double integerRoundingValue = valueToRound / roundValueField;
            switch (_roundingMethod["display"])
            {
                case RoundingMethod.Closest:
                case 0:
                    integerRoundingValue = Math.Round(integerRoundingValue);
                    break;
                case RoundingMethod.Up:
                case 1:
                    integerRoundingValue = Math.Round(integerRoundingValue, MidpointRounding.ToPositiveInfinity);
                    break;
                case RoundingMethod.Down:
                case 2:
                    integerRoundingValue = Math.Round(integerRoundingValue, MidpointRounding.ToNegativeInfinity);
                    break;
            }
            _roundedValue.SetOutput(integerRoundingValue * _roundValueField.GetInput<double>());
        }

19 View Source File : TaskManager.cs
License : GNU General Public License v3.0
Project Creator : a4004

public void CloseTask()
            {
                Debug($"Finished ({Math.Round(DateTime.UtcNow.Subtract(StartTime).TotalSeconds)}s).");
                Program.Debug("taskmanager", $"{Task} finished in {Math.Round(DateTime.UtcNow.Subtract(StartTime).TotalSeconds)}s.", Event.Success);

                StartTime = default;
                Task = string.Empty;
            }

19 View Source File : MainWindow.xaml.cs
License : MIT License
Project Creator : ADeltaX

private void UpdateVolume(double volume)
        {

            Dispatcher.Invoke(new Action(() => 
            {
                UpdateVolumeGlyph(volume);
                _isInCodeValueChange = true;
                VolumeSlider.Value = Math.Round(volume);
                _isInCodeValueChange = false;
                textVal.Text = Math.Round(volume).ToString("00");
            }));
        }

19 View Source File : CooldownTracker.cs
License : GNU Affero General Public License v3.0
Project Creator : 0ceal0t

public void TickUI(UICooldownItem ui, float percent) {
            if (State == TrackerState.None) {
                ui.SetOffCD();
                ui.SetNoDash();
                ui.SetText("");
            }
            else if (State == TrackerState.Running) {
                ui.SetOffCD();
                ui.SetDash(percent);
                ui.SetText(((int)Math.Round(TimeLeft)).ToString());
            }
            else if (State == TrackerState.OnCD) {
                ui.SetOnCD();
                ui.SetNoDash();
                ui.SetText(((int)Math.Round(TimeLeft)).ToString());
            }
            else if (State == TrackerState.OffCD) {
                ui.SetOffCD();
                ui.SetNoDash();
                ui.SetText("");
            }
        }

19 View Source File : AngleBorder.cs
License : GNU General Public License v3.0
Project Creator : aduskin

public static double RoundLayoutValue(double value, double dpiScale)
        {
            double num;
            if (!DoubleUtil.AreClose(dpiScale, 1.0))
            {
                num = Math.Round(value * dpiScale) / dpiScale;
                if (DoubleUtil.IsNaN(num) || double.IsInfinity(num) || DoubleUtil.AreClose(num, 1.7976931348623157E+308))
                {
                    num = value;
                }
            }
            else
            {
                num = Math.Round(value);
            }
            return num;
        }

19 View Source File : Dialog_BaseOnlineButton.cs
License : Apache License 2.0
Project Creator : AantCoder

public void DoTab0Contents(Rect inRect)
        {
            Text.Font = GameFont.Small;
            var rect = new Rect(inRect.x, inRect.y + 10f, inRect.width, 80f);
            Widgets.Label(rect, "OC_Incidents_Hire_text".Translate());
            rect.height = 30f;
            rect.y += 80f;

            Text.Font = GameFont.Medium;
            Widgets.Label(rect, "OC_What_To_DO".Translate());
            Text.Font = GameFont.Small;
            rect.y += rect.height;

            if (Widgets.RadioButtonLabeled(rect, "OC_Raid".Translate(), SelectTab0Type == "raid"))
            {
                StatusNeedUpdate = true;
                SelectTab0Type = "raid";
            }
            rect.y += rect.height;

            if (Widgets.RadioButtonLabeled(rect, "OC_Bugs".Translate(), SelectTab0Type == "inf"))
            {
                StatusNeedUpdate = true;
                SelectTab0Type = "inf";
            }
            rect.y += rect.height;

            if (SelectTab0Type == "raid")
            {
                rect.y += rect.height; //пробел
                Text.Font = GameFont.Medium;
                Widgets.Label(rect, "OC_Who_Hire".Translate());
                Text.Font = GameFont.Small;
                rect.y += rect.height;

                if (Widgets.RadioButtonLabeled(rect, "OC_Tribe".Translate(), SelectTab0Faction == "tribe"))
                {
                    StatusNeedUpdate = true;
                    SelectTab0Faction = "tribe";
                }
                rect.y += rect.height;

                if (Widgets.RadioButtonLabeled(rect, "OC_Pirate".Translate(), SelectTab0Faction == "pirate"))
                {
                    StatusNeedUpdate = true;
                    SelectTab0Faction = "pirate";
                }
                rect.y += rect.height;

                if (Widgets.RadioButtonLabeled(rect, "OC_Mech".Translate(), SelectTab0Faction == "mech"))
                {
                    StatusNeedUpdate = true;
                    SelectTab0Faction = "mech";
                }
                rect.y += rect.height;
            }

            if (SelectTab0Type == "raid")
            {
                rect.y += rect.height; //пробел
                Text.Font = GameFont.Medium;
                Widgets.Label(rect, "OC_Arrive".Translate());
                Text.Font = GameFont.Small;
                rect.y += rect.height;

                if (Widgets.RadioButtonLabeled(rect, "OC_Arrive_EdgeWalk".Translate(), SelectTab0ArrivalModes == "walk"))
                {
                    StatusNeedUpdate = true;
                    SelectTab0ArrivalModes = "walk";
                }
                rect.y += rect.height;

                if (Widgets.RadioButtonLabeled(rect, "OC_Arrive_DropCenter".Translate(), SelectTab0ArrivalModes == "air"))
                {
                    StatusNeedUpdate = true;
                    SelectTab0ArrivalModes = "air";
                }
                rect.y += rect.height;

                if (Widgets.RadioButtonLabeled(rect, "OC_Arrive_RandomDrop".Translate(), SelectTab0ArrivalModes == "random"))
                {
                    StatusNeedUpdate = true;
                    SelectTab0ArrivalModes = "random";
                }
                rect.y += rect.height;
            }

            rect.y += rect.height; //пробел
            Text.Font = GameFont.Medium;
            Widgets.Label(rect, "OC_Raid_Power".Translate((int)SelectTab0Mult));
            Text.Font = GameFont.Small;
            rect.y += rect.height;

            rect.height = 22f;
            if (SelectTab0Mult > SelectTab0MultMax) SelectTab0Mult = SelectTab0MultMax;
            if (SelectTab0Mult < 1) SelectTab0Mult = 1;
            SelectTab0Mult = (float)Math.Round(SelectTab0Mult + 0.001f);
            var newVal = Widgets.HorizontalSlider(rect, SelectTab0Mult, 1, SelectTab0MultMax);
            newVal = (float)Math.Round(newVal + 0.001f);
            if (newVal != SelectTab0Mult)
            {
                StatusNeedUpdate = true;
                SelectTab0Mult = newVal;
            }
            rect.y += rect.height;
            rect.height = 30f;

            DoTab1And2ContentsDown(rect);
        }

19 View Source File : spline3.cs
License : MIT License
Project Creator : 1CM69

public static void splinedifferentiation(ref double[] c, double x, ref double s, ref double ds, ref double d2s)
  {
    int num1 = (int) System.Math.Round(c[2]);
    int index1 = 3;
    int num2 = 3 + num1 - 2 + 1;
    while (index1 != num2 - 1)
    {
      int index2 = (index1 + num2) / 2;
      if (c[index2] >= x)
        num2 = index2;
      else
        index1 = index2;
    }
    x -= c[index1];
    int index3 = 3 + num1 + 4 * (index1 - 3);
    s = c[index3] + x * (c[index3 + 1] + x * (c[index3 + 2] + x * c[index3 + 3]));
    ds = c[index3 + 1] + 2.0 * x * c[index3 + 2] + 3.0 * AP.Math.Sqr(x) * c[index3 + 3];
    d2s = 2.0 * c[index3 + 2] + 6.0 * x * c[index3 + 3];
  }

19 View Source File : BuffTracker.cs
License : GNU Affero General Public License v3.0
Project Creator : 0ceal0t

public void TickUI(UIBuff ui) {
            if (UI != ui || UI?.Iconid != Config.Icon) {
                UI = ui;
                SetupUI();
            }

            UI.Show();

            if (State == BuffState.Running) {
                UI.SetOffCD();
                UI.SetPercent(Percent);
                UI.SetText(((int)Math.Round(TimeLeft)).ToString());
            }
            else if (State == BuffState.OffCD) {
                UI.SetOffCD();
                UI.SetPercent(0);
                UI.SetText("");
            }
            else if (State == BuffState.OnCD_Visible) {
                UI.SetOnCD();
                UI.SetPercent(Percent);
                UI.SetText(((int)Math.Round(TimeLeft)).ToString());
            }
        }

19 View Source File : UIIconBuff.cs
License : GNU Affero General Public License v3.0
Project Creator : 0ceal0t

public override void SetProgress(float current, float max) {
            if (State != IconState.BuffRunning) {
                State = IconState.BuffRunning;
                UIHelper.Hide(OriginalOverlay);
                UIHelper.Show(BigText);
                UIHelper.Show(Combo);
            }
            BigText->SetText(((int)Math.Round(current)).ToString());
        }

19 View Source File : Rational.cs
License : MIT License
Project Creator : 0xC0000054

public int ToInt32()
        {
            return this.Denominator == 1 ? this.Numerator : (int)Math.Round(ToDouble());
        }

19 View Source File : spline3.cs
License : MIT License
Project Creator : 1CM69

public static void splinelintransy(ref double[] c, double a, double b)
  {
    int num = (int) System.Math.Round(c[2]);
    for (int index = 0; index <= num - 2; ++index)
    {
      c[3 + num + 4 * index] = a * c[3 + num + 4 * index] + b;
      c[3 + num + 4 * index + 1] = a * c[3 + num + 4 * index + 1];
      c[3 + num + 4 * index + 2] = a * c[3 + num + 4 * index + 2];
      c[3 + num + 4 * index + 3] = a * c[3 + num + 4 * index + 3];
    }
  }

19 View Source File : LootGenerationFactory_Rare.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static WorldObject TryCreateRare(int luck = 0)
        {
            //var t1_chance = 2500; // 1 in 2,500 chance // Old rate. Property default is 0.04 (which is 0.04%, or the same 1/2500)
            double rare_drop_rate_percent = (float)Managers.PropertyManager.GetDouble("rare_drop_rate_percent").Item;

            // Check to make sure there *IS* a chance. Less than/equal to 0 would mean zero chance, so we can stop here
            if (rare_drop_rate_percent <= 0)
                return null;
            
            rare_drop_rate_percent = Math.Min(rare_drop_rate_percent/100, 1); 
            int t1_chance = (int)Math.Round(1 / rare_drop_rate_percent); // Default PropertyManager value results in a 1 in 2,500 chance
            t1_chance = Math.Max(t1_chance - luck, 1);

            int tier = 0;

            if (ThreadSafeRandom.Next(1, t1_chance) == 1)   // 1 in 2,500 chance
            {
                tier = 1;
                if (ThreadSafeRandom.Next(1, 10) == 1)      // 1 in 25,000 chance
                {
                    tier = 2;
                }
                if (ThreadSafeRandom.Next(1, 100) == 1)     // 1 in 250,000 chance
                {
                    tier = 3;
                }
                if (ThreadSafeRandom.Next(1, 1250) == 1)    // 1 in 3,120,000 chance
                {
                    tier = 4;
                }
                if (ThreadSafeRandom.Next(1, 3017) == 1)    // 1 in 7,542,500 (wiki avg. 7,543,103)
                {
                    tier = 5;
                }
                if (ThreadSafeRandom.Next(1, 3500) == 1)    // 1 in 8,750,000 chance
                {
                    tier = 6;
                }
            }

            if (tier == 0) return null;

            var tierRares = RareWCIDs[tier].ToList();

            var rng = ThreadSafeRandom.Next(0, tierRares.Count - 1);

            var rareWCID = tierRares[rng];

            var wo = WorldObjectFactory.CreateNewWorldObject((uint)rareWCID);

            if (wo == null)
                log.Error($"LootGenerationFactory_Rare.CreateRare(): failed to generate rare wcid {rareWCID}");

            return wo;
        }

See More Examples