public static Concealment Calculate([NotNull] UnitEntityData initiator, [NotNull] UnitEntityData target, bool attack = false)
        {
            UnitPartConcealment         unitPartConcealment         = initiator.Get <UnitPartConcealment>();
            UnitPartOutgoingConcealment unitPartOutgoingConcealment = initiator.Get <UnitPartOutgoingConcealment>();

            if (unitPartOutgoingConcealment?.m_Concealments == null)
            {
                return(Concealment.None); //no concelement update
            }

            bool        has_true_seeing = initiator.Descriptor.State.HasCondition(UnitCondition.TrueSeeing);
            Concealment a = Concealment.None;
            var         ignore_fog_concealement_part = initiator.Get <UnitPartIgnoreFogConcealement>();

            foreach (UnitPartConcealment.ConcealmentEntry concealment in unitPartOutgoingConcealment.m_Concealments)
            {
                if (concealment.Descriptor == ConcealmentDescriptor.Fog && ignore_fog_concealement_part != null && ignore_fog_concealement_part.active())
                {
                    continue;
                }

                if (concealment.Descriptor != ConcealmentDescriptor.Fog && concealment.Descriptor != ConcealmentDescriptor.InitiatorIsBlind && has_true_seeing)
                {
                    continue;
                }

                if (!concealment.OnlyForAttacks || attack)
                {
                    if (concealment.DistanceGreater > 0.Feet())
                    {
                        float num1 = initiator.DistanceTo(target);
                        float num2 = initiator.View.Corpulence + target.View.Corpulence;
                        if ((double)num1 <= (double)concealment.DistanceGreater.Meters + (double)num2)
                        {
                            continue;
                        }
                    }
                    if (concealment.RangeType.HasValue)
                    {
                        RuleAttackRoll   ruleAttackRoll   = Rulebook.CurrentContext.LastEvent <RuleAttackRoll>();
                        ItemEntityWeapon itemEntityWeapon = ruleAttackRoll == null?initiator.GetFirstWeapon() : ruleAttackRoll.Weapon;

                        if (itemEntityWeapon == null || !AttackTypeAttackBonus.CheckRangeType(itemEntityWeapon.Blueprint, concealment.RangeType.Value))
                        {
                            continue;
                        }
                    }
                    a = UnitPartOutgoingConcealment.Max(a, concealment.Concealment);
                }
            }
            return(a);
        }
Beispiel #2
0
        private bool CheckCondition(RuleAttackRoll evt)
        {
            Main.logger.Log(evt.Weapon.Blueprint.name);
            ItemEntity owner = (this.Fact as ItemEnchantment)?.Owner;

            if (owner != null && owner != evt.Weapon ||
                (this.WeaponType != null && this.WeaponType != evt.Weapon.Blueprint.Type || this.CheckWeaponCategory && this.Category != evt.Weapon.Blueprint.Category) ||
                (this.CheckWeaponRangeType && !AttackTypeAttackBonus.CheckRangeType(evt.Weapon.Blueprint, this.RangeType)) ||
                this.AllNaturalAndUnarmed && !evt.Weapon.Blueprint.Type.IsNatural && !evt.Weapon.Blueprint.Type.IsUnarmed)
            {
                return(false);
            }

            if (this.CheckDistance && (double)evt.Target.DistanceTo(evt.Initiator) > (double)this.DistanceLessEqual.Meters)
            {
                return(false);
            }
            bool flag = evt.Weapon.Blueprint.Category.HasSubCategory(WeaponSubCategory.Light) || evt.Weapon.Blueprint.Category.HasSubCategory(WeaponSubCategory.OneHandedPiercing) || (bool)evt.Initiator.Descriptor.State.Features.DuelingMastery && evt.Weapon.Blueprint.Category == WeaponCategory.DuelingSword || evt.Initiator.Descriptor.Ensure <DamageGracePart>().HasEntry(evt.Weapon.Blueprint.Category);

            return(!this.DuelistWeapon || flag);
        }
        public static bool Prefix(UnitEntityData initiator, UnitEntityData target, bool attack, ref Concealment __result)
        {
            UnitPartConcealment unitPartConcealment1 = initiator.Get <UnitPartConcealment>();
            UnitPartConcealment unitPartConcealment2 = target.Get <UnitPartConcealment>();

            bool has_true_seeing = initiator.Descriptor.State.HasCondition(UnitCondition.TrueSeeing);

            if (unitPartConcealment1 != null && unitPartConcealment1.IgnoreAll)
            {
                __result = Concealment.None;
                return(false);
            }
            List <Feet> m_BlindsightRanges = Harmony12.Traverse.Create(unitPartConcealment1).Field("m_BlindsightRanges").GetValue <List <Feet> >();

            if (m_BlindsightRanges != null)
            {
                Feet feet = 0.Feet();
                foreach (Feet blindsightRange in m_BlindsightRanges)
                {
                    if (feet < blindsightRange)
                    {
                        feet = blindsightRange;
                    }
                }
                float num = initiator.View.Corpulence + target.View.Corpulence;
                if ((double)initiator.DistanceTo(target) - (double)num <= (double)feet.Meters)
                {
                    __result = Concealment.None;
                    return(false);
                }
            }
            Concealment a = Concealment.None;

            if (!initiator.Descriptor.IsSeeInvisibility && target.Descriptor.State.HasCondition(UnitCondition.Invisible))
            {
                a = Concealment.Total;
            }

            var ignore_fog_concealement_part = initiator.Get <UnitPartIgnoreFogConcealement>();
            List <UnitPartConcealment.ConcealmentEntry> m_Concealments = Harmony12.Traverse.Create(unitPartConcealment2).Field("m_Concealments").GetValue <List <UnitPartConcealment.ConcealmentEntry> >();

            var all_concealements         = m_Concealments?.ToArray() ?? new UnitPartConcealment.ConcealmentEntry[0];
            var specific_concealment_part = target.Get <UnitPartISpecificConcealment>();

            if (specific_concealment_part != null)
            {
                all_concealements = all_concealements.AddToArray(specific_concealment_part.GetConcealments(initiator));
            }

            if (a < Concealment.Total && !all_concealements.Empty())
            {
                foreach (UnitPartConcealment.ConcealmentEntry concealment in all_concealements)
                {
                    if (concealment.Descriptor == ConcealmentDescriptor.Fog && ignore_fog_concealement_part != null && ignore_fog_concealement_part.active())
                    {
                        continue;
                    }

                    if (concealment.Descriptor != ConcealmentDescriptor.Fog && concealment.Descriptor != ConcealmentDescriptor.InitiatorIsBlind && has_true_seeing)
                    {
                        continue;
                    }

                    if (!concealment.OnlyForAttacks || attack)
                    {
                        if (concealment.DistanceGreater > 0.Feet())
                        {
                            float num1 = initiator.DistanceTo(target);
                            float num2 = initiator.View.Corpulence + target.View.Corpulence;
                            if ((double)num1 <= (double)concealment.DistanceGreater.Meters + (double)num2)
                            {
                                continue;
                            }
                        }
                        if (concealment.RangeType.HasValue)
                        {
                            RuleAttackRoll   ruleAttackRoll   = Rulebook.CurrentContext.LastEvent <RuleAttackRoll>();
                            ItemEntityWeapon itemEntityWeapon = ruleAttackRoll == null?initiator.GetFirstWeapon() : ruleAttackRoll.Weapon;

                            if (itemEntityWeapon == null || !AttackTypeAttackBonus.CheckRangeType(itemEntityWeapon.Blueprint, concealment.RangeType.Value))
                            {
                                continue;
                            }
                        }
                        a = a > concealment.Concealment ? a : concealment.Concealment;
                    }
                }
            }
            if (unitPartConcealment2 != null && unitPartConcealment2.Disable)
            {
                a = Concealment.None;
            }
            if (initiator.Descriptor.State.HasCondition(UnitCondition.Blindness))
            {
                a = Concealment.Total;
            }
            if (initiator.Descriptor.State.HasCondition(UnitCondition.PartialConcealmentOnAttacks))
            {
                a = Concealment.Partial;
            }
            if (a == Concealment.None && (ignore_fog_concealement_part == null || !ignore_fog_concealement_part.active()) &&
                Game.Instance.Player.Weather.ActualWeather >= BlueprintRoot.Instance.WeatherSettings.ConcealmentBeginsOn)
            {
                RuleAttackRoll   ruleAttackRoll   = Rulebook.CurrentContext.LastEvent <RuleAttackRoll>();
                ItemEntityWeapon itemEntityWeapon = ruleAttackRoll == null?initiator.GetFirstWeapon() : ruleAttackRoll.Weapon;

                if (itemEntityWeapon != null && AttackTypeAttackBonus.CheckRangeType(itemEntityWeapon.Blueprint, AttackTypeAttackBonus.WeaponRangeType.Ranged))
                {
                    a = Concealment.Partial;
                }
            }

            a = UnitPartOutgoingConcealment.Max(UnitPartOutgoingConcealment.Calculate(initiator, target, attack), a);
            if (unitPartConcealment1 != null && unitPartConcealment1.IgnorePartial && a == Concealment.Partial)
            {
                a = Concealment.None;
            }
            if (unitPartConcealment1 != null && unitPartConcealment1.TreatTotalAsPartial && a == Concealment.Total)
            {
                a = Concealment.Partial;
            }
            __result = a;
            return(false);
        }
 public bool CheckConditions(RuleCalculateWeaponStats evt)
 {
     if (this.FullAttack == ConditionEnum.Only && (evt.AttackWithWeapon == null || !evt.AttackWithWeapon.IsFullAttack) ||
         this.FullAttack == ConditionEnum.Not && (evt.AttackWithWeapon == null || evt.AttackWithWeapon.IsFullAttack) ||
         (this.FirstAttack == ConditionEnum.Only && (evt.AttackWithWeapon == null || !evt.AttackWithWeapon.IsFirstAttack) ||
          this.FirstAttack == ConditionEnum.Not && (evt.AttackWithWeapon == null || evt.AttackWithWeapon.IsFirstAttack)))
     {
         return(false);
     }
     if (this.CheckCategory)
     {
         WeaponCategory?category = evt.Weapon?.Blueprint.Category;
         if (((category.GetValueOrDefault() != this.Category ? 1 : (!category.HasValue ? 1 : 0)) != 0) &&
             !checkHasFeralCombat(evt.Initiator, evt.Weapon))
         {
             return(false);
         }
     }
     return(!this.CheckTwoHanded || evt.Weapon != null && evt.Weapon.HoldInTwoHands && AttackTypeAttackBonus.CheckRangeType(evt.Weapon.Blueprint, AttackTypeAttackBonus.WeaponRangeType.Melee));
 }
Beispiel #5
0
        public static Concealment Calculate([NotNull] UnitEntityData initiator, [NotNull] UnitEntityData target, bool attack = false)
        {
            UnitPartConcealment         unitPartConcealment         = initiator.Get <UnitPartConcealment>();
            UnitPartOutgoingConcealment unitPartOutgoingConcealment = initiator.Get <UnitPartOutgoingConcealment>();

            if (unitPartOutgoingConcealment?.m_Concealments == null)
            {
                return(Concealment.None); //no concelement update
            }


            if (unitPartConcealment != null)
            {
                List <Feet> m_BlindsightRanges = Harmony12.Traverse.Create(unitPartConcealment).Field("m_BlindsightRanges").GetValue <List <Feet> >();
                if (m_BlindsightRanges != null)
                {
                    Feet feet = 0.Feet();
                    foreach (Feet blindsightRange in m_BlindsightRanges)
                    {
                        if (feet < blindsightRange)
                        {
                            feet = blindsightRange;
                        }
                    }
                    float num = initiator.View.Corpulence + target.View.Corpulence;
                    if ((double)initiator.DistanceTo(target) - (double)num <= (double)feet.Meters)
                    {
                        return(Concealment.None);
                    }
                }
            }

            Concealment a = Concealment.None;

            foreach (UnitPartConcealment.ConcealmentEntry concealment in unitPartOutgoingConcealment.m_Concealments)
            {
                if (!concealment.OnlyForAttacks || attack)
                {
                    if (concealment.DistanceGreater > 0.Feet())
                    {
                        float num1 = initiator.DistanceTo(target);
                        float num2 = initiator.View.Corpulence + target.View.Corpulence;
                        if ((double)num1 <= (double)concealment.DistanceGreater.Meters + (double)num2)
                        {
                            continue;
                        }
                    }
                    if (concealment.RangeType.HasValue)
                    {
                        RuleAttackRoll   ruleAttackRoll   = Rulebook.CurrentContext.LastEvent <RuleAttackRoll>();
                        ItemEntityWeapon itemEntityWeapon = ruleAttackRoll == null?initiator.GetFirstWeapon() : ruleAttackRoll.Weapon;

                        if (itemEntityWeapon == null || !AttackTypeAttackBonus.CheckRangeType(itemEntityWeapon.Blueprint, concealment.RangeType.Value))
                        {
                            continue;
                        }
                    }
                    a = UnitPartOutgoingConcealment.Max(a, concealment.Concealment);
                }
            }
            return(a);
        }