Esempio n. 1
0
        public IList <IEntity> GetEntitiesUnderPosition(GridCoordinates coordinates)
        {
            // Find all the entities intersecting our click
            var worldCoords = coordinates.ToWorld(_mapManager);
            var entities    = _entityManager.GetEntitiesIntersecting(_mapManager.GetGrid(coordinates.GridID).ParentMapId, worldCoords.Position);

            // Check the entities against whether or not we can click them
            var foundEntities = new List <(IEntity clicked, int drawDepth)>();

            foreach (var entity in entities)
            {
                if (entity.TryGetComponent <IClientClickableComponent>(out var component) &&
                    entity.Transform.IsMapTransform &&
                    component.CheckClick(coordinates.Position, out var drawDepthClicked))
                {
                    foundEntities.Add((entity, drawDepthClicked));
                }
            }

            if (foundEntities.Count == 0)
            {
                return(new List <IEntity>());
            }

            foundEntities.Sort(new ClickableEntityComparer());
            // 0 is the top element.
            foundEntities.Reverse();
            return(foundEntities.Select(a => a.clicked).ToList());
        }
Esempio n. 2
0
        /// <summary>
        ///     Play an audio stream at a static position.
        /// </summary>
        /// <param name="filename">The audio stream to play.</param>
        /// <param name="coordinates">The coordinates at which to play the audio.</param>
        public void Play(AudioStream stream, GridCoordinates coordinates, AudioParams?audioParams = null)
        {
            if (GameController.Mode == GameController.DisplayMode.Clyde)
            {
                var source = _clyde.CreateAudioSource(stream);
                source.SetPosition(coordinates.ToWorld().Position);
                if (audioParams.HasValue)
                {
                    source.SetPitch(audioParams.Value.PitchScale);
                    source.SetVolume(audioParams.Value.Volume);
                }

                source.StartPlaying();
                var playing = new PlayingClydeStream
                {
                    Source = source,
                    TrackingCoordinates = coordinates
                };
                PlayingClydeStreams.Add(playing);
                return;
            }

            if (GameController.Mode != GameController.DisplayMode.Godot)
            {
                return;
            }

            var player = new Godot.AudioStreamPlayer2D()
            {
                Stream  = stream.GodotAudioStream,
                Playing = true,
                // TODO: Handle grid and map of the coordinates.
                Position = (coordinates.Position * EyeManager.PIXELSPERMETER).Convert()
            };

            if (audioParams != null)
            {
                var val = audioParams.Value;
                player.Bus      = audioParams.Value.BusName;
                player.VolumeDb = val.Volume;
                //player.PitchScale = val.PitchScale;
                player.Attenuation = val.Attenuation;
                player.MaxDistance = EyeManager.PIXELSPERMETER * val.MaxDistance;
            }

            sceneTree.WorldRoot.AddChild(player);
            TrackGodotPlayer(player);
        }
Esempio n. 3
0
        public bool IsColliding(GridCoordinates coordinates)
        {
            var bounds      = pManager.ColliderAABB;
            var worldcoords = coordinates.ToWorld();

            var collisionbox = Box2.FromDimensions(
                bounds.Left + worldcoords.Position.X,
                bounds.Bottom + worldcoords.Position.Y,
                bounds.Width,
                bounds.Height);

            if (pManager.PhysicsManager.IsColliding(collisionbox, coordinates.MapID))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        /// <summary>
        ///     Play an audio stream at a static position.
        /// </summary>
        /// <param name="stream">The audio stream to play.</param>
        /// <param name="coordinates">The coordinates at which to play the audio.</param>
        /// <param name="audioParams"></param>
        public IPlayingAudioStream Play(AudioStream stream, GridCoordinates coordinates,
                                        AudioParams?audioParams = null)
        {
            var source = _clyde.CreateAudioSource(stream);

            source.SetPosition(coordinates.ToWorld(_mapManager).Position);
            ApplyAudioParams(audioParams, source);

            source.StartPlaying();
            var playing = new PlayingStream
            {
                Source = source,
                TrackingCoordinates = coordinates,
            };

            PlayingClydeStreams.Add(playing);
            return(playing);
        }
Esempio n. 5
0
        void IAfterAttack.Afterattack(IEntity user, GridCoordinates clicklocation, IEntity attacked)
        {
            var location = user.GetComponent <ITransformComponent>().GridPosition;
            var angle    = new Angle(clicklocation.ToWorld().Position - location.ToWorld().Position);
            var entities = IoCManager.Resolve <IServerEntityManager>().GetEntitiesInArc(user.GetComponent <ITransformComponent>().GridPosition, Range, angle, ArcWidth);

            foreach (var entity in entities)
            {
                if (!entity.GetComponent <ITransformComponent>().IsMapTransform || entity == user)
                {
                    continue;
                }

                if (entity.TryGetComponent(out DamageableComponent damagecomponent))
                {
                    damagecomponent.TakeDamage(DamageType.Brute, Damage);
                }
            }
        }
Esempio n. 6
0
            public void Update(float frameTime)
            {
                Age += TimeSpan.FromSeconds(frameTime);
                if (Age >= Deathtime)
                {
                    return;
                }

                Velocity           += Acceleration * frameTime;
                RadialVelocity     += RadialAcceleration * frameTime;
                TangentialVelocity += TangentialAcceleration * frameTime;

                var deltaPosition = new Vector2(0f, 0f);

                //If we have an emitter we can do special effects around that emitter position
                if (EmitterCoordinates.IsValidLocation())
                {
                    //Calculate delta p due to radial velocity
                    var positionRelativeToEmitter = Coordinates.ToWorld().Position - EmitterCoordinates.ToWorld().Position;
                    var deltaRadial = RadialVelocity * frameTime;
                    deltaPosition = positionRelativeToEmitter * (deltaRadial / positionRelativeToEmitter.Length);

                    //Calculate delta p due to tangential velocity
                    var radius = positionRelativeToEmitter.Length;
                    if (radius > 0)
                    {
                        var theta = (float)Math.Atan2(positionRelativeToEmitter.Y, positionRelativeToEmitter.X);
                        theta         += TangentialVelocity * frameTime;
                        deltaPosition += new Vector2(radius * (float)Math.Cos(theta), radius * (float)Math.Sin(theta))
                                         - positionRelativeToEmitter;
                    }
                }

                //Calculate new position from our velocity as well as possible rotation/movement around emitter
                deltaPosition += Velocity * frameTime;
                Coordinates    = new GridCoordinates(Coordinates.Position + deltaPosition, Coordinates.Grid);

                //Finish calculating new rotation, size, color
                Rotation += RotationRate * frameTime;
                Size     += SizeDelta * frameTime;
                Color    += ColorDelta * frameTime;
            }
Esempio n. 7
0
        /// <summary>
        ///     Play an audio stream at a static position.
        /// </summary>
        /// <param name="stream">The audio stream to play.</param>
        /// <param name="coordinates">The coordinates at which to play the audio.</param>
        /// <param name="audioParams"></param>
        public void Play(AudioStream stream, GridCoordinates coordinates, AudioParams?audioParams = null)
        {
            var source = _clyde.CreateAudioSource(stream);

            source.SetPosition(coordinates.ToWorld(_mapManager).Position);
            if (audioParams.HasValue)
            {
                source.SetPitch(audioParams.Value.PitchScale);
                source.SetVolume(audioParams.Value.Volume);
            }

            source.StartPlaying();
            var playing = new PlayingStream
            {
                Source = source,
                TrackingCoordinates = coordinates
            };

            PlayingClydeStreams.Add(playing);
        }
Esempio n. 8
0
            public void Update(float frameTime)
            {
                Age += TimeSpan.FromSeconds(frameTime);
                if (Age >= Deathtime)
                {
                    return;
                }

                Velocity           += Acceleration * frameTime;
                RadialVelocity     += RadialAcceleration * frameTime;
                TangentialVelocity += TangentialAcceleration * frameTime;

                var deltaPosition = new Vector2(0f, 0f);

                //If we have an emitter we can do special effects around that emitter position
                if (_mapManager.GridExists(EmitterCoordinates.GridID))
                {
                    //Calculate delta p due to radial velocity
                    var positionRelativeToEmitter =
                        Coordinates.ToWorld(_mapManager).Position - EmitterCoordinates.ToWorld(_mapManager).Position;
                    var deltaRadial = RadialVelocity * frameTime;
                    deltaPosition = positionRelativeToEmitter * (deltaRadial / positionRelativeToEmitter.Length);

                    //Calculate delta p due to tangential velocity
                    var radius = positionRelativeToEmitter.Length;
                    if (radius > 0)
                    {
                        var theta = (float)Math.Atan2(positionRelativeToEmitter.Y, positionRelativeToEmitter.X);
                        theta         += TangentialVelocity * frameTime;
                        deltaPosition += new Vector2(radius * (float)Math.Cos(theta), radius * (float)Math.Sin(theta))
                                         - positionRelativeToEmitter;
                    }
                }

                //Calculate new position from our velocity as well as possible rotation/movement around emitter
                deltaPosition += Velocity * frameTime;
                Coordinates    = new GridCoordinates(Coordinates.Position + deltaPosition, Coordinates.GridID);

                //Finish calculating new rotation, size, color
                Rotation += RotationRate * frameTime;
                Size     += SizeDelta * frameTime;
                Color    += ColorDelta * frameTime;

                if (RsiState == null)
                {
                    return;
                }

                // Calculate RSI animations.
                var delayCount = RsiState.DelayCount(RSI.State.Direction.South);

                if (delayCount > 0 && (AnimationLoops || AnimationIndex < delayCount - 1))
                {
                    AnimationTime += frameTime;
                    while (RsiState.GetFrame(RSI.State.Direction.South, AnimationIndex).delay < AnimationTime)
                    {
                        var(_, delay)   = RsiState.GetFrame(RSI.State.Direction.South, AnimationIndex);
                        AnimationIndex += 1;
                        AnimationTime  -= delay;
                        if (AnimationIndex == delayCount)
                        {
                            if (AnimationLoops)
                            {
                                AnimationIndex = 0;
                            }
                            else
                            {
                                break;
                            }
                        }

                        EffectSprite = RsiState.GetFrame(RSI.State.Direction.South, AnimationIndex).icon;
                    }
                }
            }
        public static void SpawnExplosion(GridCoordinates coords, int devastationRange, int heavyImpactRange, int lightImpactRange, int flashRange)
        {
            var tileDefinitionManager = IoCManager.Resolve <ITileDefinitionManager>();
            var serverEntityManager   = IoCManager.Resolve <IServerEntityManager>();
            var entitySystemManager   = IoCManager.Resolve <IEntitySystemManager>();
            var mapManager            = IoCManager.Resolve <IMapManager>();
            var robustRandom          = IoCManager.Resolve <IRobustRandom>();

            var maxRange = MathHelper.Max(devastationRange, heavyImpactRange, lightImpactRange, 0f);
            //Entity damage calculation
            var entitiesAll = serverEntityManager.GetEntitiesInRange(coords, maxRange).ToList();

            foreach (var entity in entitiesAll)
            {
                if (entity.Deleted)
                {
                    continue;
                }
                if (!entity.Transform.IsMapTransform)
                {
                    continue;
                }

                var distanceFromEntity = (int)entity.Transform.GridPosition.Distance(mapManager, coords);
                var exAct    = entitySystemManager.GetEntitySystem <ActSystem>();
                var severity = ExplosionSeverity.Destruction;
                if (distanceFromEntity < devastationRange)
                {
                    severity = ExplosionSeverity.Destruction;
                }
                else if (distanceFromEntity < heavyImpactRange)
                {
                    severity = ExplosionSeverity.Heavy;
                }
                else if (distanceFromEntity < lightImpactRange)
                {
                    severity = ExplosionSeverity.Light;
                }
                else
                {
                    continue;
                }
                //exAct.HandleExplosion(Owner, entity, severity);
                exAct.HandleExplosion(null, entity, severity);
            }

            //Tile damage calculation mockup
            //TODO: make it into some sort of actual damage component or whatever the boys think is appropriate
            var mapGrid = mapManager.GetGrid(coords.GridID);
            var circle  = new Circle(coords.Position, maxRange);
            var tiles   = mapGrid.GetTilesIntersecting(circle);

            foreach (var tile in tiles)
            {
                var tileLoc          = mapGrid.GridTileToLocal(tile.GridIndices);
                var tileDef          = (ContentTileDefinition)tileDefinitionManager[tile.Tile.TypeId];
                var distanceFromTile = (int)tileLoc.Distance(mapManager, coords);
                if (!string.IsNullOrWhiteSpace(tileDef.SubFloor))
                {
                    if (distanceFromTile < devastationRange)
                    {
                        mapGrid.SetTile(tileLoc, new Tile(tileDefinitionManager["space"].TileId));
                    }
                    if (distanceFromTile < heavyImpactRange)
                    {
                        if (robustRandom.Prob(80))
                        {
                            mapGrid.SetTile(tileLoc, new Tile(tileDefinitionManager[tileDef.SubFloor].TileId));
                        }
                        else
                        {
                            mapGrid.SetTile(tileLoc, new Tile(tileDefinitionManager["space"].TileId));
                        }
                    }
                    if (distanceFromTile < lightImpactRange)
                    {
                        if (robustRandom.Prob(50))
                        {
                            mapGrid.SetTile(tileLoc, new Tile(tileDefinitionManager[tileDef.SubFloor].TileId));
                        }
                    }
                }
            }

            //Effects and sounds
            var time    = IoCManager.Resolve <IGameTiming>().CurTime;
            var message = new EffectSystemMessage
            {
                EffectSprite = "Effects/explosion.rsi",
                RsiState     = "explosionfast",
                Born         = time,
                DeathTime    = time + TimeSpan.FromSeconds(5),
                Size         = new Vector2(flashRange / 2, flashRange / 2),
                Coordinates  = coords,
                //Rotated from east facing
                Rotation   = 0f,
                ColorDelta = new Vector4(0, 0, 0, -1500f),
                Color      = Vector4.Multiply(new Vector4(255, 255, 255, 750), 0.5f),
                Shaded     = false
            };

            entitySystemManager.GetEntitySystem <EffectSystem>().CreateParticle(message);
            entitySystemManager.GetEntitySystem <AudioSystem>().Play("/Audio/effects/explosion.ogg", coords);

            // Knock back cameras of all players in the area.

            var playerManager = IoCManager.Resolve <IPlayerManager>();
            //var selfPos = Owner.Transform.WorldPosition; //vec2
            var selfPos = coords.ToWorld(mapManager).Position;

            foreach (var player in playerManager.GetAllPlayers())
            {
                if (player.AttachedEntity == null ||
                    player.AttachedEntity.Transform.MapID != mapGrid.ParentMapId ||
                    !player.AttachedEntity.TryGetComponent(out CameraRecoilComponent recoil))
                {
                    continue;
                }

                var playerPos = player.AttachedEntity.Transform.WorldPosition;
                var delta     = selfPos - playerPos;
                var distance  = delta.LengthSquared;

                var effect = 1 / (1 + 0.2f * distance);
                if (effect > 0.01f)
                {
                    var kick = -delta.Normalized * effect;
                    recoil.Kick(kick);
                }
            }
        }