Exemple #1
0
        private void ClientRemote_OnArrowHitGround(Vector2Ushort endTilePosition)
        {
            var hitPosition = new Vector2D(endTilePosition.X + 0.5,
                                           endTilePosition.Y + 0.5);

            WeaponSystemClientDisplay.ClientAddHitSparks(
                WeaponHitSparksPresets.Firearm,
                new WeaponHitData(hitPosition: hitPosition),
                hitWorldObject: null,
                protoWorldObject: null,
                worldObjectPosition: endTilePosition.ToVector2D(),
                projectilesCount: 1,
                objectMaterial: ObjectMaterial.Wood,
                randomizeHitPointOffset: false,
                randomRotation: false,
                drawOrder: DrawOrder.Light);
        }
Exemple #2
0
        public override void Update(double deltaTime)
        {
            if (this.dronePublicState.TargetObjectPosition.HasValue)
            {
                this.lastTargetPosition = this.dronePublicState.TargetObjectPosition.Value.ToVector2D();

                if (this.hitWorldObject is null)
                {
                    this.hitWorldObject = Client.World.GetTile(this.lastTargetPosition.Value.ToVector2Ushort())
                                          .StaticObjects
                                          .FirstOrDefault();
                }

                if (this.hitWorldObject != null)
                {
                    var objectCenter = DroneTargetPositionHelper.GetTargetPosition(this.hitWorldObject);
                    objectCenter             = (objectCenter.X, objectCenter.Y * 0.5 + 0.2);
                    this.lastTargetPosition += objectCenter;
                }
            }
            else
            {
                this.hitWorldObject = null;
            }

            if (this.hitWorldObject != null &&
                this.soundEmitterMiningProcess.SoundResource is null)
            {
                this.soundEmitterMiningProcess.SoundResource
                    = GetSourceResourceMiningProcess(this.hitWorldObject.ProtoStaticWorldObject);
            }

            var wasEnabled   = this.spriteRendererLine.IsEnabled;
            var isBeamActive = this.dronePublicState.IsMining &&
                               this.lastTargetPosition.HasValue;

            this.alpha = MathHelper.LerpWithDeltaTime(
                this.alpha,
                isBeamActive ? 1 : 0,
                deltaTime: deltaTime,
                rate: 20);

            var isEnabled = this.alpha > 0.001;

            this.spriteRendererLine.IsEnabled        = isEnabled;
            this.spriteRendererOrigin.IsEnabled      = isEnabled;
            this.soundEmitterMiningProcess.IsEnabled = isEnabled;

            if (!isEnabled)
            {
                if (wasEnabled)
                {
                    // just disabled
                    Api.Client.Audio.PlayOneShot(SourceResourceMiningEnd,
                                                 this.SceneObject,
                                                 MiningVolume);
                }

                return;
            }

            if (!wasEnabled)
            {
                // just enabled
                Api.Client.Audio.PlayOneShot(SourceResourceMiningStart,
                                             this.SceneObject,
                                             MiningVolume);
            }

            var alphaComponent = (byte)(this.alpha * byte.MaxValue);

            this.spriteRendererLine.Color         = this.beamColor.WithAlpha(alphaComponent);
            this.spriteRendererOrigin.Color       = Color.FromArgb(alphaComponent, 0xFF, 0xFF, 0xFF);
            this.soundEmitterMiningProcess.Volume = (float)(this.alpha * MiningVolume);

            // update line start-end positions and rotation angle
            var currentBeamOriginOffset = this.beamOriginOffset
                                          + this.primaryRenderer.PositionOffset
                                          - this.primaryRendererDefaultPositionOffset;

            var lineStartWorldPosition = this.SceneObject.Position + currentBeamOriginOffset;

            // ReSharper disable once PossibleInvalidOperationException
            var lineEndWorldPosition = this.lastTargetPosition.Value;

            lineEndWorldPosition += this.GetMiningTargetMovementAnimation(deltaTime);

            var lineDirection = lineEndWorldPosition - lineStartWorldPosition;

            this.spriteRendererLine.PositionOffset   = currentBeamOriginOffset;
            this.spriteRendererLine.RotationAngleRad = (float)-Math.Atan2(lineDirection.Y, lineDirection.X);
            this.spriteRendererLine.Scale            = (lineDirection.Length, this.beamWidth);
            this.spriteRendererLine.DrawOrderOffsetY = this.primaryRenderer.DrawOrderOffsetY;

            this.spriteRendererOrigin.PositionOffset   = currentBeamOriginOffset;
            this.spriteRendererOrigin.Scale            = this.beamWidth;
            this.spriteRendererOrigin.DrawOrderOffsetY = this.primaryRenderer.DrawOrderOffsetY;

            if (this.hitWorldObject is null)
            {
                return;
            }

            this.timeSinceLastHitSparks -= deltaTime;
            if (this.timeSinceLastHitSparks < 0)
            {
                WeaponSystemClientDisplay.ClientAddHitSparks(
                    WeaponHitSparksPresets.LaserMining,
                    new WeaponHitData(Vector2D.Zero),
                    this.hitWorldObject,
                    this.hitWorldObject.ProtoStaticWorldObject,
                    worldObjectPosition: lineEndWorldPosition,
                    projectilesCount: 1,
                    objectMaterial: this.hitWorldObject.ProtoStaticWorldObject.SharedGetObjectMaterial(),
                    randomizeHitPointOffset: false,
                    randomRotation: true,
                    drawOrder: DrawOrder.Light + 2,
                    animationFrameDuration: 3 / 60.0);
                this.timeSinceLastHitSparks += HitSparksInterval;
            }
        }