示例#1
0
        public void Killed(Actor self, AttackInfo e)
        {
            if (!self.IsInWorld)
            {
                return;
            }

            if (self.World.SharedRandom.Next(100) > explodesInfo.Chance)
            {
                return;
            }

            if (explodesInfo.InfDeath != null && e.Warhead != null && !explodesInfo.InfDeath.Contains(e.Warhead.InfDeath))
            {
                return;
            }

            var weapon = ChooseWeaponForExplosion(self);

            if (weapon != null)
            {
                Combat.DoExplosion(e.Attacker, weapon, self.CenterPosition);
            }
        }
示例#2
0
 public void Tick(Actor self)
 {
     history.Tick(self.CenterLocation - new PVecInt(0, move.Altitude) - Combat.GetTurretPosition(self, facing, contrailTurret));
 }
示例#3
0
        public void CheckFire(Actor self, AttackBase attack, IMove move, IFacing facing, Target target)
        {
            if (FireDelay > 0)
            {
                return;
            }

            var limitedAmmo = self.TraitOrDefault <LimitedAmmo>();

            if (limitedAmmo != null && !limitedAmmo.HasAmmo())
            {
                return;
            }

            if (!Combat.IsInRange(self.CenterLocation, Info.Range, target))
            {
                return;
            }
            if (Combat.IsInRange(self.CenterLocation, Info.MinRange, target))
            {
                return;
            }

            if (!IsValidAgainst(self.World, target))
            {
                return;
            }

            var barrel   = Barrels[Burst % Barrels.Length];
            var destMove = target.IsActor ? target.Actor.TraitOrDefault <IMove>() : null;
            var turreted = self.TraitOrDefault <Turreted>();

            var args = new ProjectileArgs
            {
                weapon = Info,

                firedBy = self,
                target  = target,

                src          = (self.CenterLocation + Combat.GetBarrelPosition(self, facing, Turret, barrel)),
                srcAltitude  = move != null ? move.Altitude : 0,
                dest         = target.CenterLocation,
                destAltitude = destMove != null ? destMove.Altitude : 0,

                facing = barrel.Facing +
                         (turreted != null ? turreted.turretFacing :
                          facing != null ? facing.Facing : Util.GetFacing(target.CenterLocation - self.CenterLocation, 0)),

                firepowerModifier = self.TraitsImplementing <IFirepowerModifier>()
                                    .Select(a => a.GetFirepowerModifier())
                                    .Product()
            };

            attack.ScheduleDelayedAction(attack.FireDelay(self, target, self.Info.Traits.Get <AttackBaseInfo>()), () =>
            {
                if (args.weapon.Projectile != null)
                {
                    var projectile = args.weapon.Projectile.Create(args);
                    if (projectile != null)
                    {
                        self.World.Add(projectile);
                    }

                    if (!string.IsNullOrEmpty(args.weapon.Report))
                    {
                        Sound.Play(args.weapon.Report + ".aud", self.CenterLocation);
                    }
                }
            });

            foreach (var na in self.TraitsImplementing <INotifyAttack>())
            {
                na.Attacking(self, target);
            }

            FiredShot();
        }
示例#4
0
 public override void Activate(Actor collector)
 {
     Combat.DoExplosion(self, ((ExplodeCrateActionInfo)info).Weapon, collector.CenterPosition);
     base.Activate(collector);
 }
示例#5
0
        public void ResolveOrder(Actor self, Order order)
        {
            if (order.OrderString == "PlaceBuilding" || order.OrderString == "LineBuild")
            {
                self.World.AddFrameEndTask(w =>
                {
                    var prevItems = GetNumBuildables(self.Owner);

                    // Find the queue with the target actor
                    var queue = w.ActorsWithTrait <ProductionQueue>()
                                .Where(p => p.Actor.Owner == self.Owner &&
                                       p.Trait.CurrentItem() != null &&
                                       p.Trait.CurrentItem().Item == order.TargetString &&
                                       p.Trait.CurrentItem().RemainingTime == 0)
                                .Select(p => p.Trait)
                                .FirstOrDefault();

                    if (queue == null)
                    {
                        return;
                    }

                    var unit         = Rules.Info[order.TargetString];
                    var buildingInfo = unit.Traits.Get <BuildingInfo>();

                    if (order.OrderString == "LineBuild")
                    {
                        bool playSounds = true;
                        foreach (var t in BuildingUtils.GetLineBuildCells(w, order.TargetLocation, order.TargetString, buildingInfo))
                        {
                            var building = w.CreateActor(order.TargetString, new TypeDictionary
                            {
                                new LocationInit(t),
                                new OwnerInit(order.Player),
                            });

                            if (playSounds)
                            {
                                foreach (var s in buildingInfo.BuildSounds)
                                {
                                    Sound.PlayToPlayer(order.Player, s, building.CenterLocation);
                                }
                            }
                            playSounds = false;
                        }
                    }
                    else
                    {
                        if (!self.World.CanPlaceBuilding(order.TargetString, buildingInfo, order.TargetLocation, null))
                        {
                            return;
                        }

                        var building = w.CreateActor(order.TargetString, new TypeDictionary
                        {
                            new LocationInit(order.TargetLocation),
                            new OwnerInit(order.Player),
                        });
                        foreach (var s in buildingInfo.BuildSounds)
                        {
                            Sound.PlayToPlayer(order.Player, s, building.CenterLocation);
                        }
                    }

                    PlayBuildAnim(self, unit);

                    queue.FinishProduction();

                    if (buildingInfo.RequiresBaseProvider)
                    {
                        var center = buildingInfo.CenterLocation(order.TargetLocation);
                        foreach (var bp in w.ActorsWithTrait <BaseProvider>())
                        {
                            if (bp.Actor.Owner.Stances[self.Owner] != Stance.Ally || !bp.Trait.Ready())
                            {
                                continue;
                            }

                            if (Combat.IsInRange(center, bp.Trait.Info.Range, bp.Actor.CenterLocation))
                            {
                                bp.Trait.BeginCooldown();
                                break;
                            }
                        }
                    }

                    if (GetNumBuildables(self.Owner) > prevItems)
                    {
                        w.Add(new DelayedAction(10,
                                                () => Sound.PlayNotification(order.Player, "Speech", "NewOptions", order.Player.Country.Race)));
                    }
                });
            }
        }
示例#6
0
        // Note: facing is only used by the legacy positioning code
        // The world coordinate model uses Actor.Orientation
        public void CheckFire(Actor self, AttackBase attack, IMove move, IFacing facing, Target target)
        {
            if (FireDelay > 0)
            {
                return;
            }

            var limitedAmmo = self.TraitOrDefault <LimitedAmmo>();

            if (limitedAmmo != null && !limitedAmmo.HasAmmo())
            {
                return;
            }

            if (!Combat.IsInRange(self.CenterLocation, Weapon.Range, target))
            {
                return;
            }
            if (Combat.IsInRange(self.CenterLocation, Weapon.MinRange, target))
            {
                return;
            }
            if (!IsValidAgainst(self.World, target))
            {
                return;
            }

            var barrel   = Barrels[Burst % Barrels.Length];
            var destMove = target.IsActor ? target.Actor.TraitOrDefault <IMove>() : null;

            var muzzlePosition       = self.CenterPosition + MuzzleOffset(self, barrel);
            var legacyMuzzlePosition = PPos.FromWPos(muzzlePosition);
            var legacyMuzzleAltitude = Game.CellSize * muzzlePosition.Z / 1024;
            var legacyFacing         = MuzzleOrientation(self, barrel).Yaw.Angle / 4;

            var args = new ProjectileArgs
            {
                weapon      = Weapon,
                firedBy     = self,
                target      = target,
                src         = legacyMuzzlePosition,
                srcAltitude = legacyMuzzleAltitude,

                dest         = target.CenterLocation,
                destAltitude = destMove != null ? destMove.Altitude : 0,

                facing = legacyFacing,

                firepowerModifier = self.TraitsImplementing <IFirepowerModifier>()
                                    .Select(a => a.GetFirepowerModifier())
                                    .Product()
            };

            attack.ScheduleDelayedAction(Info.FireDelay, () =>
            {
                if (args.weapon.Projectile != null)
                {
                    var projectile = args.weapon.Projectile.Create(args);
                    if (projectile != null)
                    {
                        self.World.Add(projectile);
                    }

                    if (args.weapon.Report != null && args.weapon.Report.Any())
                    {
                        Sound.Play(args.weapon.Report.Random(self.World.SharedRandom) + ".aud", self.CenterLocation);
                    }
                }
            });

            foreach (var na in self.TraitsImplementing <INotifyAttack>())
            {
                na.Attacking(self, target);
            }

            Recoil = Info.Recoil;

            if (--Burst > 0)
            {
                FireDelay = Weapon.BurstDelay;
            }
            else
            {
                FireDelay = Weapon.ROF;
                Burst     = Weapon.Burst;
            }
        }
示例#7
0
 public override void Activate(Actor collector)
 {
     Combat.DoExplosion(self, (info as ExplodeCrateActionInfo).Weapon, collector.CenterLocation, 0);
     base.Activate(collector);
 }