Exemplo n.º 1
0
        protected override void Created(Actor self)
        {
            targetableCells = self.TraitOrDefault <ITargetableCells>();
            turret          = self.TraitsImplementing <Turreted>().FirstOrDefault(t => t.Name == Info.Turret);

            base.Created(self);
        }
Exemplo n.º 2
0
        public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info)
        {
            var self = init.Self;
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <BodyOrientation>();

            // TODO: Carry orientation over from the parent instead of just facing
            var bodyFacing = init.Contains <DynamicFacingInit>() ? init.Get <DynamicFacingInit, Func <int> >()()
                                : init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : 0;

            facing = WAngle.FromFacing(Turreted.TurretFacingFromInit(init, 0)());

            // Calculate final position
            var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024));
            var throwDistance = Game.CosmeticRandom.Next(info.MinThrowRange.Length, info.MaxThrowRange.Length);

            initialPos = pos = info.Offset.Rotate(body.QuantizeOrientation(self, WRot.FromFacing(bodyFacing)));
            finalPos   = initialPos + new WVec(throwDistance, 0, 0).Rotate(throwRotation);
            angle      = new WAngle(Game.CosmeticRandom.Next(info.MinThrowAngle.Angle, info.MaxThrowAngle.Angle));
            length     = (finalPos - initialPos).Length / info.Velocity;

            // Facing rotation
            rotation = WAngle.FromFacing(WDist.FromPDF(Game.CosmeticRandom, 2).Length *info.TurnSpeed / 1024);

            var anim = new Animation(init.World, rs.GetImage(self), () => facing.Angle / 4);

            anim.PlayRepeating(info.Anim);
            rs.Add(new AnimationWithOffset(anim, () => pos, null));
        }
Exemplo n.º 3
0
 public void Created(Actor self)
 {
     turret         = self.TraitsImplementing <Turreted>().FirstOrDefault(t => t.Name == Info.Turret);
     ammoPool       = self.TraitsImplementing <AmmoPool>().FirstOrDefault(la => la.Info.Name == Info.AmmoPoolName);
     coords         = self.Trait <BodyOrientation>();
     rangeModifiers = self.TraitsImplementing <IRangeModifier>().ToArray().Select(m => m.GetRangeModifier());
 }
Exemplo n.º 4
0
        public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info)
        {
            var self = init.Self;
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <BodyOrientation>();

            // TODO: Carry orientation over from the parent instead of just facing
            var dynamicFacingInit = init.GetOrDefault <DynamicFacingInit>();
            var bodyFacing        = dynamicFacingInit != null?dynamicFacingInit.Value() : init.GetValue <FacingInit, WAngle>(WAngle.Zero);

            facing = Turreted.TurretFacingFromInit(init, info, WAngle.Zero)();

            // Calculate final position
            var throwRotation = WRot.FromYaw(new WAngle(Game.CosmeticRandom.Next(1024)));
            var throwDistance = Game.CosmeticRandom.Next(info.MinThrowRange.Length, info.MaxThrowRange.Length);

            initialPos = pos = info.Offset.Rotate(body.QuantizeOrientation(self, WRot.FromYaw(bodyFacing)));
            finalPos   = initialPos + new WVec(throwDistance, 0, 0).Rotate(throwRotation);
            angle      = new WAngle(Game.CosmeticRandom.Next(info.MinThrowAngle.Angle, info.MaxThrowAngle.Angle));
            length     = (finalPos - initialPos).Length / info.Velocity;

            // WAngle requires positive inputs, so track the speed and direction separately
            var rotationSpeed = WDist.FromPDF(Game.CosmeticRandom, 2).Length *info.TurnSpeed / 1024;

            direction = rotationSpeed < 0 ? -1 : 1;
            rotation  = WAngle.FromFacing(Math.Abs(rotationSpeed));

            var anim = new Animation(init.World, rs.GetImage(self), () => facing);

            anim.PlayRepeating(info.Anim);
            rs.Add(new AnimationWithOffset(anim, () => pos, null));
        }
Exemplo n.º 5
0
        public IEnumerable <VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
        {
            if (UpgradeMinEnabledLevel > 0)
            {
                yield break;
            }

            var body     = init.Actor.TraitInfo <BodyOrientationInfo>();
            var armament = init.Actor.TraitInfos <ArmamentInfo>()
                           .First(a => a.Name == Armament);
            var t = init.Actor.TraitInfos <TurretedInfo>()
                    .First(tt => tt.Turret == armament.Turret);

            var voxel = VoxelProvider.GetVoxel(image, Sequence);

            var turretFacing      = Turreted.GetInitialTurretFacing(init, t.InitialFacing, t.Turret);
            var turretOrientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(turretFacing) - orientation.Yaw), facings);

            var quantizedTurret = body.QuantizeOrientation(turretOrientation, facings);
            var quantizedBody   = body.QuantizeOrientation(orientation, facings);
            var barrelOffset    = body.LocalToWorld((t.Offset + LocalOffset.Rotate(quantizedTurret)).Rotate(quantizedBody));

            yield return(new VoxelAnimation(voxel, () => barrelOffset, () => new[] { turretOrientation, orientation },
                                            () => false, () => 0));
        }
Exemplo n.º 6
0
        public IEnumerable <IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
        {
            if (UpgradeMinEnabledLevel > 0)
            {
                yield break;
            }

            var body = init.Actor.TraitInfo <BodyOrientationInfo>();
            var t    = init.Actor.TraitInfos <TurretedInfo>()
                       .First(tt => tt.Turret == Turret);

            var ifacing    = init.Actor.TraitInfoOrDefault <IFacingInfo>();
            var bodyFacing = ifacing != null?init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : ifacing.GetInitialFacing() : 0;

            var turretFacing = Turreted.GetInitialTurretFacing(init, t.InitialFacing, Turret);

            var anim = new Animation(init.World, image, () => turretFacing);

            anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));

            var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(bodyFacing)), facings);
            var offset      = body.LocalToWorld(t.Offset.Rotate(orientation));

            yield return(new SpriteActorPreview(anim, offset, -(offset.Y + offset.Z) + 1, p, rs.Scale));
        }
Exemplo n.º 7
0
        public WithVoxelTurret(Actor self, WithVoxelTurretInfo info)
        {
            this.self = self;
            body      = self.Trait <IBodyOrientation>();
            turreted  = self.TraitsImplementing <Turreted>()
                        .First(tt => tt.Name == info.Turret);

            var rv = self.Trait <RenderVoxels>();

            rv.Add(new VoxelAnimation(VoxelProvider.GetVoxel(rv.Image, info.Sequence),
                                      () => turreted.Position(self), TurretRotation,
                                      () => false, () => 0));
        }
Exemplo n.º 8
0
        protected override void Created(Actor self)
        {
            turret = self.TraitsImplementing <Turreted>().FirstOrDefault(t => t.Name == Info.Turret);
            coords = self.Trait <BodyOrientation>();
            notifyBurstComplete = self.TraitsImplementing <INotifyBurstComplete>().ToArray();
            notifyAttacks       = self.TraitsImplementing <INotifyAttack>().ToArray();

            rangeModifiers      = self.TraitsImplementing <IRangeModifier>().ToArray().Select(m => m.GetRangeModifier());
            reloadModifiers     = self.TraitsImplementing <IReloadModifier>().ToArray().Select(m => m.GetReloadModifier());
            damageModifiers     = self.TraitsImplementing <IFirepowerModifier>().ToArray().Select(m => m.GetFirepowerModifier());
            inaccuracyModifiers = self.TraitsImplementing <IInaccuracyModifier>().ToArray().Select(m => m.GetInaccuracyModifier());

            base.Created(self);
        }
Exemplo n.º 9
0
        public WithVoxelTurret(Actor self, WithVoxelTurretInfo info)
            : base(info)
        {
            this.self = self;
            body      = self.Trait <BodyOrientation>();
            turreted  = self.TraitsImplementing <Turreted>()
                        .First(tt => tt.Name == Info.Turret);
            buildComplete = !self.Info.HasTraitInfo <BuildingInfo>();            // always render instantly for units

            var rv = self.Trait <RenderVoxels>();

            rv.Add(new VoxelAnimation(VoxelProvider.GetVoxel(rv.Image, Info.Sequence),
                                      () => turreted.Position(self), TurretRotation,
                                      () => IsTraitDisabled || !buildComplete, () => 0));
        }
Exemplo n.º 10
0
        public WithVoxelBarrel(Actor self, WithVoxelBarrelInfo info)
        {
            this.self = self;
            this.info = info;
            body      = self.Trait <IBodyOrientation>();
            armament  = self.TraitsImplementing <Armament>()
                        .First(a => a.Info.Name == info.Armament);
            turreted = self.TraitsImplementing <Turreted>()
                       .First(tt => tt.Name == armament.Info.Turret);

            var rv = self.Trait <RenderVoxels>();

            rv.Add(new VoxelAnimation(VoxelProvider.GetVoxel(rv.Image, info.Sequence),
                                      BarrelOffset, BarrelRotation,
                                      () => false, () => 0));
        }
Exemplo n.º 11
0
		public WithTurret(Actor self, WithTurretInfo info)
			: base(info)
		{
			rs = self.Trait<RenderSprites>();
			body = self.Trait<BodyOrientation>();
			Attack = self.TraitOrDefault<AttackBase>();
			t = self.TraitsImplementing<Turreted>()
				.First(tt => tt.Name == info.Turret);
			arms = self.TraitsImplementing<Armament>()
				.Where(w => w.Info.Turret == info.Turret).ToArray();

			DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => t.TurretFacing);
			DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
			rs.Add(new AnimationWithOffset(
				DefaultAnimation, () => TurretOffset(self), () => IsTraitDisabled, () => false, p => ZOffsetFromCenter(self, p, 1)));

			// Restrict turret facings to match the sprite
			t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
		}
Exemplo n.º 12
0
        public WithBarrel(Actor self, WithBarrelInfo info)
            : base(info)
        {
            this.self = self;
            body      = self.Trait <BodyOrientation>();
            armament  = self.TraitsImplementing <Armament>()
                        .First(a => a.Info.Name == Info.Armament);
            turreted = self.TraitsImplementing <Turreted>()
                       .First(tt => tt.Name == armament.Info.Turret);

            rs = self.Trait <RenderSprites>();
            DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => turreted.TurretFacing);
            DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence));
            rs.Add(new AnimationWithOffset(
                       DefaultAnimation, () => BarrelOffset(), () => IsTraitDisabled, () => false, p => WithTurret.ZOffsetFromCenter(self, p, 0)));

            // Restrict turret facings to match the sprite
            turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
        }
Exemplo n.º 13
0
        public WithBarrel(Actor self, WithBarrelInfo info)
        {
            this.self = self;
            this.info = info;
            body      = self.Trait <IBodyOrientation>();
            armament  = self.TraitsImplementing <Armament>()
                        .First(a => a.Info.Name == info.Armament);
            turreted = self.TraitsImplementing <Turreted>()
                       .First(tt => tt.Name == armament.Info.Turret);

            var rs = self.Trait <RenderSprites>();

            anim = new Animation(self.World, rs.GetImage(self), () => turreted.TurretFacing);
            anim.Play(info.Sequence);
            rs.Add(new AnimationWithOffset(
                       anim, () => BarrelOffset(), null, () => false, p => WithTurret.ZOffsetFromCenter(self, p, 0)));

            // Restrict turret facings to match the sprite
            turreted.QuantizedFacings = anim.CurrentSequence.Facings;
        }
Exemplo n.º 14
0
        public WithTurret(Actor self, WithTurretInfo info)
            : base(info)
        {
            rs   = self.Trait <RenderSprites>();
            body = self.Trait <IBodyOrientation>();

            ab = self.TraitOrDefault <AttackBase>();
            t  = self.TraitsImplementing <Turreted>()
                 .First(tt => tt.Name == info.Turret);
            arms = self.TraitsImplementing <Armament>()
                   .Where(w => w.Info.Turret == info.Turret);

            anim = new Animation(self.World, rs.GetImage(self), () => t.TurretFacing);
            anim.Play(info.Sequence);
            rs.Add("turret_{0}_{1}".F(info.Turret, info.Sequence), new AnimationWithOffset(
                       anim, () => TurretOffset(self), () => IsTraitDisabled, () => false, p => ZOffsetFromCenter(self, p, 1)));

            // Restrict turret facings to match the sprite
            t.QuantizedFacings = anim.CurrentSequence.Facings;
        }
Exemplo n.º 15
0
 public RenderBuildingTurreted(ActorInitializer init, RenderBuildingInfo info)
     : base(init, info, MakeTurretFacingFunc(init.Self))
 {
     t = init.Self.TraitsImplementing <Turreted>().FirstOrDefault();
     t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
 }
Exemplo n.º 16
0
 public WithTurretedSpriteBody(ActorInitializer init, WithSpriteBodyInfo info)
     : base(init, info, MakeTurretFacingFunc(init.Self))
 {
     turreted = init.Self.TraitsImplementing <Turreted>().FirstOrDefault();
     turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
 }