Exemplo n.º 1
0
        /// <summary>Checks if the warhead is valid against (can do something to) the actor.</summary>
        public bool IsValidAgainst(Actor victim, Actor firedBy)
        {
            if (!CanTargetActor(victim.Info, firedBy))
            {
                return(false);
            }

            if (!AffectsParent && victim == firedBy)
            {
                return(false);
            }

            var stance = firedBy.Owner.Stances[victim.Owner];

            if (!ValidStances.HasStance(stance))
            {
                return(false);
            }

            // A target type is valid if it is in the valid targets list, and not in the invalid targets list.
            var targetable = victim.TraitOrDefault <ITargetable>();

            if (targetable == null || !IsValidTarget(targetable.TargetTypes))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        protected override void OnInside(Actor self)
        {
            if (target.IsDead)
            {
                return;
            }

            var stance = self.Owner.Stances[target.Owner];

            if (!validStances.HasStance(stance))
            {
                return;
            }

            if (cloak != null && cloak.Info.UncloakOn.HasFlag(UncloakType.Infiltrate))
            {
                cloak.Uncloak();
            }

            foreach (var t in target.TraitsImplementing <INotifyInfiltrated>())
            {
                t.Infiltrated(target, self);
            }

            if (!string.IsNullOrEmpty(notification))
            {
                Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",
                                            notification, self.Owner.Faction.InternalName);
            }
        }
Exemplo n.º 3
0
 void AddCellsToPlayerShroud(Player p, PPos[] uv)
 {
     if (!validStances.HasStance(p.Stances[player]))
     {
         return;
     }
     p.Shroud.AddSource(this, sourceType, uv);
 }
Exemplo n.º 4
0
        /// <summary>Checks if the warhead is valid against (can do something to) the actor.</summary>
        public virtual bool IsValidAgainst(Actor victim, Actor firedBy)
        {
            if (!AffectsParent && victim == firedBy)
            {
                return(false);
            }

            var stance = firedBy.Owner.Stances[victim.Owner];

            if (!ValidStances.HasStance(stance))
            {
                return(false);
            }

            // A target type is valid if it is in the valid targets list, and not in the invalid targets list.
            if (!IsValidTarget(victim.GetEnabledTargetTypes()))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
        /// <summary>Checks if the warhead is valid against (can do something to) the actor.</summary>
        public virtual bool IsValidAgainst(Actor victim, Actor firedBy)
        {
            if (!AffectsParent && victim == firedBy)
            {
                return(false);
            }

            var stance = firedBy.Owner.Stances[victim.Owner];

            if (!ValidStances.HasStance(stance))
            {
                return(false);
            }

            // A target type is valid if it is in the valid targets list, and not in the invalid targets list.
            var targetable = victim.TraitsImplementing <ITargetable>().Where(Exts.IsTraitEnabled);

            if (!IsValidTarget(targetable.SelectMany(t => t.TargetTypes)))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        public string TooltipForPlayerStance(Stance stance)
        {
            if (stance == Stance.None || !GenericVisibility.HasStance(stance))
            {
                return(Name);
            }

            if (GenericStancePrefix && stance == Stance.Ally)
            {
                return("Allied " + GenericName);
            }

            if (GenericStancePrefix && stance == Stance.Enemy)
            {
                return("Enemy " + GenericName);
            }

            return(GenericName);
        }
Exemplo n.º 7
0
        public bool CanBeTargetedBy(Actor captor, Player owner)
        {
            var c = captor.Info.TraitInfoOrDefault <CapturesInfo>();

            if (c == null)
            {
                return(false);
            }

            var stance = owner.Stances[captor.Owner];

            if (!ValidStance.HasStance(stance))
            {
                return(false);
            }

            if (!c.CaptureTypes.Overlaps(Types))
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 8
0
        public string TooltipForPlayerStance(Stance stance)
        {
            if (stance == Stance.None || !GenericVisibility.HasStance(stance))
            {
                return(Name);
            }

            if (GenericStancePrefix && !string.IsNullOrEmpty(AllyPrefix) && stance == Stance.Ally)
            {
                return(AllyPrefix + " " + GenericName);
            }

            if (GenericStancePrefix && !string.IsNullOrEmpty(NeutralPrefix) && stance == Stance.Neutral)
            {
                return(NeutralPrefix + " " + GenericName);
            }

            if (GenericStancePrefix && !string.IsNullOrEmpty(EnemyPrefix) && stance == Stance.Enemy)
            {
                return(EnemyPrefix + " " + GenericName);
            }

            return(GenericName);
        }
Exemplo n.º 9
0
        public override void DoImpact(Target target, WarheadArgs args)
        {
            var firedBy = args.SourceActor;

            if (!target.IsValidFor(firedBy))
            {
                return;
            }

            var world = firedBy.World;
            var map   = world.Map;

            if (!IsValidImpact(target.CenterPosition, firedBy))
            {
                return;
            }

            var epicenter = AroundTarget && args.WeaponTarget.Type != TargetType.Invalid
                                ? args.WeaponTarget.CenterPosition
                                : target.CenterPosition;

            var directActors = world.FindActorsOnCircle(target.CenterPosition, WDist.Zero)
                               .Where(a =>
            {
                var activeShapes = a.TraitsImplementing <HitShape>().Where(Exts.IsTraitEnabled);
                if (!activeShapes.Any())
                {
                    return(false);
                }

                var distance = activeShapes.Min(t => t.DistanceFromEdge(a, epicenter));

                if (distance != WDist.Zero)
                {
                    return(false);
                }

                return(true);
            });

            var availableTargetActors = world.FindActorsOnCircle(target.CenterPosition, weapon.Range)
                                        .Where(x => (AllowDirectHit || !directActors.Contains(x)) &&
                                               weapon.IsValidAgainst(Target.FromActor(x), firedBy.World, firedBy) &&
                                               AimTargetStances.HasStance(firedBy.Owner.Stances[x.Owner]))
                                        .Where(x =>
            {
                var activeShapes = x.TraitsImplementing <HitShape>().Where(Exts.IsTraitEnabled);
                if (!activeShapes.Any())
                {
                    return(false);
                }

                var distance = activeShapes.Min(t => t.DistanceFromEdge(x, epicenter));

                if (distance < weapon.Range)
                {
                    return(true);
                }

                return(false);
            })
                                        .Shuffle(world.SharedRandom);

            var targetActor = availableTargetActors.GetEnumerator();

            var amount = Amount.Length == 2
                                        ? world.SharedRandom.Next(Amount[0], Amount[1])
                                        : Amount[0];

            for (var i = 0; i < amount; i++)
            {
                Target shrapnelTarget = Target.Invalid;

                if (world.SharedRandom.Next(100) < AimChance && targetActor.MoveNext())
                {
                    shrapnelTarget = Target.FromActor(targetActor.Current);
                }

                if (ThrowWithoutTarget && shrapnelTarget.Type == TargetType.Invalid)
                {
                    var rotation  = WRot.FromFacing(world.SharedRandom.Next(1024));
                    var range     = world.SharedRandom.Next(weapon.MinRange.Length, weapon.Range.Length);
                    var targetpos = target.CenterPosition + new WVec(range, 0, 0).Rotate(rotation);
                    var tpos      = Target.FromPos(new WPos(targetpos.X, targetpos.Y, map.CenterOfCell(map.CellContaining(targetpos)).Z));
                    if (weapon.IsValidAgainst(tpos, firedBy.World, firedBy))
                    {
                        shrapnelTarget = tpos;
                    }
                }

                if (shrapnelTarget.Type == TargetType.Invalid)
                {
                    continue;
                }

                var projectileArgs = new ProjectileArgs
                {
                    Weapon = weapon,
                    Facing = (shrapnelTarget.CenterPosition - target.CenterPosition).Yaw.Facing,

                    DamageModifiers = !firedBy.IsDead ? firedBy.TraitsImplementing <IFirepowerModifier>()
                                      .Select(a => a.GetFirepowerModifier()).ToArray() : new int[0],

                    InaccuracyModifiers = !firedBy.IsDead ? firedBy.TraitsImplementing <IInaccuracyModifier>()
                                          .Select(a => a.GetInaccuracyModifier()).ToArray() : new int[0],

                    RangeModifiers = !firedBy.IsDead ? firedBy.TraitsImplementing <IRangeModifier>()
                                     .Select(a => a.GetRangeModifier()).ToArray() : new int[0],

                    Source        = target.CenterPosition,
                    CurrentSource = () => target.CenterPosition,
                    SourceActor   = firedBy,
                    GuidedTarget  = shrapnelTarget,
                    PassiveTarget = shrapnelTarget.CenterPosition
                };

                if (args.Weapon.Projectile != null)
                {
                    var projectile = projectileArgs.Weapon.Projectile.Create(projectileArgs);
                    if (projectile != null)
                    {
                        firedBy.World.AddFrameEndTask(w => w.Add(projectile));
                    }

                    if (projectileArgs.Weapon.Report != null && projectileArgs.Weapon.Report.Any())
                    {
                        Game.Sound.Play(SoundType.World, projectileArgs.Weapon.Report.Random(firedBy.World.SharedRandom), target.CenterPosition);
                    }
                }
            }
        }
Exemplo n.º 10
0
        public override void DoImpact(Target target, Actor firedBy, IEnumerable <int> damageModifiers)
        {
            if (!IsValidImpact(target.CenterPosition, firedBy))
            {
                return;
            }

            var directActors = firedBy.World.FindActorsInCircle(target.CenterPosition, TargetSearchRadius);

            var availableTargetActors = firedBy.World.FindActorsInCircle(target.CenterPosition, weapon.Range)
                                        .Where(x => (AllowDirectHit || !directActors.Contains(x)) &&
                                               weapon.IsValidAgainst(Target.FromActor(x), firedBy.World, firedBy) &&
                                               AimTargetStances.HasStance(firedBy.Owner.Stances[x.Owner]))
                                        .Shuffle(firedBy.World.SharedRandom);

            var targetActor = availableTargetActors.GetEnumerator();

            var amount = Amount.Length == 2
                    ? firedBy.World.SharedRandom.Next(Amount[0], Amount[1])
                    : Amount[0];

            for (var i = 0; i < amount; i++)
            {
                Target shrapnelTarget = Target.Invalid;

                if (firedBy.World.SharedRandom.Next(100) < AimChance && targetActor.MoveNext())
                {
                    shrapnelTarget = Target.FromActor(targetActor.Current);
                }

                if (ThrowWithoutTarget && shrapnelTarget.Type == TargetType.Invalid)
                {
                    var rotation  = WRot.FromFacing(firedBy.World.SharedRandom.Next(1024));
                    var range     = firedBy.World.SharedRandom.Next(weapon.MinRange.Length, weapon.Range.Length);
                    var targetpos = target.CenterPosition + new WVec(range, 0, 0).Rotate(rotation);
                    var tpos      = Target.FromPos(new WPos(targetpos.X, targetpos.Y, firedBy.World.Map.CenterOfCell(firedBy.World.Map.CellContaining(targetpos)).Z));
                    if (weapon.IsValidAgainst(tpos, firedBy.World, firedBy))
                    {
                        shrapnelTarget = tpos;
                    }
                }

                if (shrapnelTarget.Type == TargetType.Invalid)
                {
                    continue;
                }

                var args = new ProjectileArgs
                {
                    Weapon = weapon,
                    Facing = (shrapnelTarget.CenterPosition - target.CenterPosition).Yaw.Facing,

                    DamageModifiers = !firedBy.IsDead ? firedBy.TraitsImplementing <IFirepowerModifier>()
                                      .Select(a => a.GetFirepowerModifier()).ToArray() : new int[0],

                    InaccuracyModifiers = !firedBy.IsDead ? firedBy.TraitsImplementing <IInaccuracyModifier>()
                                          .Select(a => a.GetInaccuracyModifier()).ToArray() : new int[0],

                    RangeModifiers = !firedBy.IsDead ? firedBy.TraitsImplementing <IRangeModifier>()
                                     .Select(a => a.GetRangeModifier()).ToArray() : new int[0],

                    Source        = target.CenterPosition,
                    SourceActor   = firedBy,
                    GuidedTarget  = shrapnelTarget,
                    PassiveTarget = shrapnelTarget.CenterPosition
                };

                if (args.Weapon.Projectile != null)
                {
                    var projectile = args.Weapon.Projectile.Create(args);
                    if (projectile != null)
                    {
                        firedBy.World.AddFrameEndTask(w => w.Add(projectile));
                    }

                    if (args.Weapon.Report != null && args.Weapon.Report.Any())
                    {
                        Game.Sound.Play(SoundType.World, args.Weapon.Report.Random(firedBy.World.SharedRandom), target.CenterPosition);
                    }
                }
            }
        }