/// <inheritdoc />
        public bool TrySpawnEntityAt(string EntityType, Vector2 position, int argMap, out IEntity entity)
        {
            var mapmanager  = IoCManager.Resolve <IMapManager>();
            var coordinates = new LocalCoordinates(position, mapmanager.GetMap(argMap).FindGridAt(position));

            return(TrySpawnEntityAt(EntityType, coordinates, out entity));
        }
Exemplo n.º 2
0
        public override void AlignPlacementMode(ScreenCoordinates mouseScreen)
        {
            MouseCoords = ScreenToPlayerGrid(mouseScreen);
            CurrentTile = MouseCoords.Grid.GetTile(MouseCoords);

            if (pManager.CurrentPermission.IsTile)
            {
                return;
            }

            var nodes = new List <Vector2>();

            if (pManager.CurrentPrototype.MountingPoints != null)
            {
                nodes.AddRange(
                    pManager.CurrentPrototype.MountingPoints.Select(
                        current => new Vector2(MouseCoords.X, CurrentTile.Y + current)));
            }
            else
            {
                nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 0.5f));
                nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 1.0f));
                nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 1.5f));
            }

            Vector2 closestNode = (from Vector2 node in nodes
                                   orderby(node - MouseCoords.Position).LengthSquared ascending
                                   select node).First();

            MouseCoords = new LocalCoordinates(closestNode + new Vector2(pManager.CurrentPrototype.PlacementOffset.X,
                                                                         pManager.CurrentPrototype.PlacementOffset.Y),
                                               MouseCoords.Grid);
        }
Exemplo n.º 3
0
        public override bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapId.Nullspace)
            {
                onGrid = false;
                return(false);
            }

            MouseScreen = mouseS;
            MouseCoords = pManager.eyeManager.ScreenToWorld(MouseScreen);

            snapSize = MouseCoords.Grid.SnapSize; //Find snap size.
            onGrid   = true;

            var mouselocal = new Vector2( //Round local coordinates onto the snap grid
                (float)Math.Round(MouseCoords.X / (double)snapSize, MidpointRounding.AwayFromZero) * snapSize,
                (float)Math.Round(MouseCoords.Y / (double)snapSize, MidpointRounding.AwayFromZero) * snapSize);

            //Convert back to original world and screen coordinates after applying offset
            MouseCoords = new LocalCoordinates(mouselocal + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y), MouseCoords.Grid);
            MouseScreen = pManager.eyeManager.WorldToScreen(MouseCoords);

            if (!RangeCheck())
            {
                return(false);
            }

            return(true);
        }
        /// <inheritdoc />
        public IEntity ForceSpawnEntityAt(string EntityType, Vector2 position, int argMap)
        {
            var mapmanager  = IoCManager.Resolve <IMapManager>();
            var coordinates = new LocalCoordinates(position, mapmanager.GetMap(argMap).FindGridAt(position));

            return(ForceSpawnEntityAt(EntityType, coordinates));
        }
Exemplo n.º 5
0
        public override void AlignPlacementMode(ScreenCoordinates mouseScreen)
        {
            if (mouseScreen.MapID == MapId.Nullspace)
            {
                return;
            }

            MouseCoords = ScreenToPlayerGrid(mouseScreen);

            CurrentTile = MouseCoords.Grid.GetTile(MouseCoords);
            float tileSize = MouseCoords.Grid.TileSize; //convert from ushort to float

            GridDistancing = tileSize;

            if (pManager.CurrentPermission.IsTile)
            {
                MouseCoords = new LocalCoordinates(CurrentTile.X + tileSize / 2,
                                                   CurrentTile.Y + tileSize / 2,
                                                   MouseCoords.Grid);
            }
            else
            {
                MouseCoords = new LocalCoordinates(CurrentTile.X + tileSize / 2 + pManager.CurrentPrototype.PlacementOffset.X,
                                                   CurrentTile.Y + tileSize / 2 + pManager.CurrentPrototype.PlacementOffset.Y,
                                                   MouseCoords.Grid);
            }
        }
        public bool CheckClick(LocalCoordinates worldPos, out int drawdepth)
        {
            var component = Owner.GetComponent <IClickTargetComponent>();

            drawdepth = (int)component.DrawDepth;
            return(true);
        }
Exemplo n.º 7
0
        public IEntity GetEntityUnderPosition(LocalCoordinates coordinates)
        {
            // Find all the entities intersecting our click
            var entities =
                _entityManager.GetEntitiesIntersecting(coordinates.MapID, coordinates.Position);

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

            foreach (IEntity entity in entities)
            {
                if (entity.TryGetComponent <IClientClickableComponent>(out var component) &&
                    entity.GetComponent <ITransformComponent>().IsMapTransform &&
                    component.CheckClick(coordinates, out int drawdepthofclicked))
                {
                    foundEntities.Add((entity, drawdepthofclicked));
                }
            }

            if (foundEntities.Count != 0)
            {
                foundEntities.Sort(new ClickableEntityComparer());
                return(foundEntities[foundEntities.Count - 1].clicked);
            }
            return(null);
        }
Exemplo n.º 8
0
        public override bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapId.Nullspace)
            {
                return(false);
            }

            MouseScreen = mouseS;
            MouseCoords = pManager.eyeManager.ScreenToWorld(MouseScreen);

            CurrentTile = MouseCoords.Grid.GetTile(MouseCoords);
            var tileSize = MouseCoords.Grid.TileSize;

            if (!RangeCheck())
            {
                return(false);
            }

            if (pManager.CurrentPermission.IsTile)
            {
                MouseCoords = new LocalCoordinates(CurrentTile.X + tileSize / 2,
                                                   CurrentTile.Y + tileSize / 2,
                                                   MouseCoords.Grid);
            }
            else
            {
                MouseCoords = new LocalCoordinates(CurrentTile.X + tileSize / 2 + pManager.CurrentPrototype.PlacementOffset.X,
                                                   CurrentTile.Y + tileSize / 2 + pManager.CurrentPrototype.PlacementOffset.Y,
                                                   MouseCoords.Grid);
            }
            MouseScreen = pManager.eyeManager.WorldToScreen(MouseCoords);

            return(true);
        }
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapManager.NULLSPACE)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseCoords = CluwneLib.ScreenToCoordinates(mouseScreen);

            var snapsize = mouseCoords.Grid.SnapSize; //Find snap size.

            var mouselocal = new Vector2(             //Round local coordinates onto the snap grid
                (float)(Math.Round((mouseCoords.Position.X / (double)snapsize - 0.5), MidpointRounding.AwayFromZero) + 0.5) * snapsize,
                (float)(Math.Round((mouseCoords.Position.Y / (double)snapsize - 0.5), MidpointRounding.AwayFromZero) + 0.5) * snapsize);

            //Adjust mouseCoords to new calculated position
            mouseCoords = new LocalCoordinates(mouselocal + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y), mouseCoords.Grid);
            mouseScreen = CluwneLib.WorldToScreen(mouseCoords);

            if (!RangeCheck())
            {
                return(false);
            }

            return(true);
        }
 void IAfterAttack.Afterattack(IEntity user, LocalCoordinates clicklocation, IEntity attacked)
 {
     if (UserCanFire(user) && WeaponCanFire())
     {
         Fire(user, clicklocation);
     }
 }
Exemplo n.º 11
0
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapManager.NULLSPACE)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseCoords = CluwneLib.ScreenToCoordinates(mouseScreen);

            currentTile = mouseCoords.Grid.GetTile(mouseCoords);
            var tilesize = mouseCoords.Grid.TileSize;

            if (!RangeCheck())
            {
                return(false);
            }

            if (pManager.CurrentPermission.IsTile)
            {
                mouseCoords = new LocalCoordinates(currentTile.X + tilesize / 2,
                                                   currentTile.Y + tilesize / 2,
                                                   mouseCoords.Grid);
                mouseScreen = CluwneLib.WorldToScreen(mouseCoords);
            }
            else
            {
                mouseCoords = new LocalCoordinates(currentTile.X + tilesize / 2 + pManager.CurrentPrototype.PlacementOffset.X,
                                                   currentTile.Y + tilesize / 2 + pManager.CurrentPrototype.PlacementOffset.Y,
                                                   mouseCoords.Grid);
                mouseScreen = CluwneLib.WorldToScreen(mouseCoords);
            }

            return(true);
        }
Exemplo n.º 12
0
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapManager.NULLSPACE)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseCoords = CluwneLib.ScreenToCoordinates(mouseScreen);

            var snapsize = mouseCoords.Grid.SnapSize; //Find snap size.

            var mouselocal = new Vector2(             //Round local coordinates onto the snap grid
                (float)Math.Round((mouseCoords.X / (double)snapsize), MidpointRounding.AwayFromZero) * snapsize,
                (float)Math.Round((mouseCoords.Y / (double)snapsize), MidpointRounding.AwayFromZero) * snapsize);

            //Convert back to original world and screen coordinates after applying offset
            mouseCoords = new LocalCoordinates(mouselocal + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y), mouseCoords.Grid);
            mouseScreen = CluwneLib.WorldToScreen(mouseCoords);

            if (!RangeCheck())
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 13
0
        public override bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapId.Nullspace)
            {
                onGrid = false;
                return(false);
            }

            MouseScreen = mouseS;
            MouseCoords = pManager.eyeManager.ScreenToWorld(MouseScreen);

            snapSize = MouseCoords.Grid.SnapSize; //Find snap size.
            onGrid   = true;

            var mouseLocal = new Vector2( //Round local coordinates onto the snap grid
                (float)(Math.Round((MouseCoords.Position.X / (double)snapSize - 0.5f), MidpointRounding.AwayFromZero) + 0.5) * snapSize,
                (float)(Math.Round((MouseCoords.Position.Y / (double)snapSize - 0.5f), MidpointRounding.AwayFromZero) + 0.5) * snapSize);

            //Adjust mouseCoords to new calculated position
            MouseCoords = new LocalCoordinates(mouseLocal + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y), MouseCoords.Grid);
            MouseScreen = pManager.eyeManager.WorldToScreen(MouseCoords);

            if (!RangeCheck())
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 14
0
        /// <inheritdoc />
        public IEntity ForceSpawnEntityAt(string EntityType, LocalCoordinates coordinates)
        {
            IEntity entity = SpawnEntity(EntityType);

            entity.GetComponent <TransformComponent>().LocalPosition = coordinates;
            entity.Initialize();
            return(entity);
        }
Exemplo n.º 15
0
        public override bool IsValidPosition(LocalCoordinates position)
        {
            if (!RangeCheck(position))
            {
                return(false);
            }

            return(true);
        }
 /// <summary>
 ///     Constructs a new state snapshot of a TransformComponent.
 /// </summary>
 /// <param name="position">Current position offset of the entity.</param>
 /// <param name="rotation">Current direction offset of the entity.</param>
 /// <param name="parent">Current parent transform of this entity.</param>
 public TransformComponentState(LocalCoordinates position, Angle rotation, int?parentID)
     : base(NetIDs.TRANSFORM)
 {
     Position = position.Position;
     MapID    = position.MapID;
     GridID   = position.GridID;
     Rotation = rotation;
     ParentID = parentID;
 }
Exemplo n.º 17
0
        /// <summary>
        /// We didn't click on any entity, try doing an afterattack on the click location
        /// </summary>
        /// <param name="user"></param>
        /// <param name="weapon"></param>
        /// <param name="clicklocation"></param>
        private void InteractAfterattack(IEntity user, IEntity weapon, LocalCoordinates clicklocation)
        {
            List <IAfterAttack> afterattacks = weapon.GetComponents <IAfterAttack>().ToList();

            for (var i = 0; i < afterattacks.Count; i++)
            {
                afterattacks[i].Afterattack(user, clicklocation);
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Gets all players inside of a circle.
 /// </summary>
 /// <param name="position">Position of the circle in world-space.</param>
 /// <param name="range">Radius of the circle in world units.</param>
 /// <returns></returns>
 public List <IPlayerSession> GetPlayersInRange(LocalCoordinates position, int range)
 {
     //TODO: This needs to be moved to the PVS system.
     return
         (_sessions.Values.Where(x =>
                                 x.attachedEntity != null &&
                                 position.InRange(x.attachedEntity.GetComponent <ITransformComponent>().LocalPosition, range))
          .Cast <IPlayerSession>()
          .ToList());
 }
Exemplo n.º 19
0
        /// <summary>
        ///     Play an audio file at a static position.
        /// </summary>
        /// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
        /// <param name="coordinates">The coordinates at which to play the audio.</param>
        public void Play(string filename, LocalCoordinates coordinates, AudioParams?audioParams = null)
        {
            var msg = new PlayAudioPositionalMessage
            {
                FileName    = filename,
                Coordinates = coordinates,
                AudioParams = audioParams ?? AudioParams.Default
            };

            RaiseNetworkEvent(msg);
        }
Exemplo n.º 20
0
        /// <inheritdoc />
        public IEntity ForceSpawnEntityAt(string entityType, LocalCoordinates coordinates)
        {
            Entity entity = SpawnEntity(entityType);

            entity.GetComponent <TransformComponent>().LocalPosition = coordinates;
            if (Started)
            {
                InitializeEntity(entity);
            }
            return(entity);
        }
        protected override void Fire(IEntity user, LocalCoordinates clicklocation)
        {
            var userposition = user.GetComponent <TransformComponent>().WorldPosition; //Remember world positions are ephemeral and can only be used instantaneously
            var angle        = new Angle(clicklocation.Position - userposition);

            var ray            = new Ray(userposition, angle.ToVec());
            var raycastresults = IoCManager.Resolve <ICollisionManager>().IntersectRay(ray, 20, Owner.GetComponent <TransformComponent>().GetMapTransform().Owner);

            Hit(raycastresults);
            AfterEffects(user, raycastresults, angle);
        }
Exemplo n.º 22
0
    public void AssignFunctions(RiverGenerator rg)
    {
        this.rg = rg;

        lc = rg.localCoordinates;
        //globalRiverC = rg.globalRiverC;

        lt = rg.lt;
        fmc = rg.fmc;
        ftm = rg.ftm;
        fd = rg.fd;
    }
Exemplo n.º 23
0
 public IEnumerable <IEntity> GetEntitiesInRange(IEntity entity, float range)
 {
     if (entity.TryGetComponent <BoundingBoxComponent>(out var component))
     {
         return(GetEntitiesInRange(entity.GetComponent <ITransformComponent>().MapID, component.WorldAABB, range));
     }
     else
     {
         LocalCoordinates coords = entity.GetComponent <ITransformComponent>().LocalPosition;
         return(GetEntitiesInRange(coords, range));
     }
 }
Exemplo n.º 24
0
        public override bool IsValidPosition(LocalCoordinates position)
        {
            if (!RangeCheck(position))
            {
                return(false);
            }

            var entitymanager = IoCManager.Resolve <IClientEntityManager>();

            return(!(entitymanager.AnyEntitiesIntersecting(MouseCoords.MapID,
                                                           new Box2(new Vector2(CurrentTile.X, CurrentTile.Y), new Vector2(CurrentTile.X + 0.99f, CurrentTile.Y + 0.99f)))));
        }
Exemplo n.º 25
0
    public RiverGenerator(LocalTerrain localTerrain)
    {
        lt = localTerrain;

        //globalRiverC = new GlobalCoordinates(100);
        localCoordinates = lt.localTerrainC;

        //currentRiver = new RiverInfo(this);

        rivers = new List<RiverInfo>();
        //localRiverC = new LocalCoordinates(globalRiverC, new Vector3(0, 0, 0), 200, 200);
    }
Exemplo n.º 26
0
        /// <inheritdoc />
        public IEnumerable <IEntity> GetEntitiesInArc(LocalCoordinates coordinates, float range, Angle direction, float arcwidth)
        {
            var entities = GetEntitiesInRange(coordinates, range);

            foreach (var entity in entities)
            {
                var angle = new Angle(entity.GetComponent <TransformComponent>().WorldPosition - coordinates.ToWorld().Position);
                if (angle.Degrees < direction.Degrees + arcwidth / 2 && angle.Degrees > direction.Degrees - arcwidth / 2)
                {
                    yield return(entity);
                }
            }
        }
Exemplo n.º 27
0
        public override bool IsValidPosition(LocalCoordinates position)
        {
            if (pManager.CurrentPermission.IsTile)
            {
                return(false);
            }
            else if (!RangeCheck(position))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 28
0
        public override void AlignPlacementMode(ScreenCoordinates mouseScreen)
        {
            MouseCoords = ScreenToPlayerGrid(mouseScreen);
            CurrentTile = MouseCoords.Grid.GetTile(MouseCoords);

            if (pManager.CurrentPermission.IsTile)
            {
                return;
            }

            if (!RangeCheck(MouseCoords))
            {
                return;
            }

            var manager = IoCManager.Resolve <IClientEntityManager>();

            var snapToEntities = manager.GetEntitiesInRange(MouseCoords, SnapToRange)
                                 .Where(entity => entity.Prototype == pManager.CurrentPrototype && entity.GetComponent <ITransformComponent>().MapID == MouseCoords.MapID)
                                 .OrderBy(entity => (entity.GetComponent <ITransformComponent>().WorldPosition - MouseCoords.ToWorld().Position).LengthSquared)
                                 .ToList();

            if (snapToEntities.Any())
            {
                var closestEntity = snapToEntities.First();
                if (closestEntity.TryGetComponent <ISpriteComponent>(out var component))
                {
                    var closestBounds = component.BaseRSI.Size;

                    var closestRect =
                        Box2.FromDimensions(
                            closestEntity.GetComponent <ITransformComponent>().WorldPosition.X - closestBounds.X / 2f,
                            closestEntity.GetComponent <ITransformComponent>().WorldPosition.Y - closestBounds.Y / 2f,
                            closestBounds.X, closestBounds.Y);

                    var sides = new[]
                    {
                        new Vector2(closestRect.Left + closestRect.Width / 2f, closestRect.Top - closestBounds.Y / 2f),
                        new Vector2(closestRect.Left + closestRect.Width / 2f, closestRect.Bottom + closestBounds.Y / 2f),
                        new Vector2(closestRect.Left - closestBounds.X / 2f, closestRect.Top + closestRect.Height / 2f),
                        new Vector2(closestRect.Right + closestBounds.X / 2f, closestRect.Top + closestRect.Height / 2f)
                    };

                    var closestSide =
                        (from Vector2 side in sides orderby(side - MouseCoords.Position).LengthSquared select side).First();

                    MouseCoords = new LocalCoordinates(closestSide, MouseCoords.Grid);
                }
            }
        }
Exemplo n.º 29
0
        public IEnumerable <IEntity> GetEntitiesInRange(LocalCoordinates worldPos, float Range)
        {
            Range *= Range; // Square it here to avoid Sqrt

            foreach (var entity in GetEntities())
            {
                var transform        = entity.GetComponent <ITransformComponent>();
                var relativePosition = worldPos.Position - transform.WorldPosition;
                if (relativePosition.LengthSquared <= Range)
                {
                    yield return(entity);
                }
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Checks if the player is spawning within a certain range of his character if range is required on this mode
        /// </summary>
        /// <returns></returns>
        public bool RangeCheck(LocalCoordinates coordinates)
        {
            if (!RangeRequired)
            {
                return(true);
            }
            var range = pManager.CurrentPermission.Range;

            if (range > 0 && !pManager.PlayerManager.LocalPlayer.ControlledEntity.GetComponent <ITransformComponent>().LocalPosition.InRange(coordinates, range))
            {
                return(false);
            }
            return(true);
        }
        public ReadResults Parse(out ICoordinates result)
        {
            result = default;

            ReadResults readResults = ReadDouble(out double left);

            if (!readResults.Successful)
            {
                return(readResults);
            }
            if (UseBedrock)
            {
                StringReader.SkipWhitespace();
            }
            else
            {
                if (!StringReader.AtEndOfArgument())
                {
                    StringReader.SetCursor(Start);
                    return(ReadResults.Failure(CommandError.Vec3CoordinatesIncomplete().WithContext(StringReader)));
                }
                StringReader.Skip();
            }

            readResults = ReadDouble(out double up);
            if (!readResults.Successful)
            {
                return(readResults);
            }
            if (UseBedrock)
            {
                StringReader.SkipWhitespace();
            }
            else
            {
                if (!StringReader.AtEndOfArgument())
                {
                    StringReader.SetCursor(Start);
                    return(ReadResults.Failure(CommandError.Vec3CoordinatesIncomplete().WithContext(StringReader)));
                }
                StringReader.Skip();
            }

            readResults = ReadDouble(out double forwards);
            if (readResults.Successful)
            {
                result = new LocalCoordinates(left, up, forwards);
            }
            return(readResults);
        }
Exemplo n.º 32
0
    public LocalTerrain(int terrainWidth, int terrainHeight, int stepSize, GlobalTerrain globalTerrain, LayerManager layerManager)
    {
        gt = globalTerrain;
        gt.lt = this;
        lm = layerManager;

        localTerrainC = new LocalCoordinates(new Vector3(0, 0, 0), terrainWidth, terrainHeight);

        //visibleTerrain = new float[terrainHeight, terrainWidth];
        this.terrainHeight = terrainHeight;
        this.terrainWidth = terrainWidth;

        this.stepSize = stepSize;
    }
Exemplo n.º 33
0
        /// <inheritdoc />
        public bool TrySpawnEntityAt(string EntityType, LocalCoordinates coordinates, out IEntity entity)
        {
            var prototype = _protoManager.Index <EntityPrototype>(EntityType);

            if (prototype.CanSpawnAt(coordinates.Grid, coordinates.Position))
            {
                entity = SpawnEntity(EntityType);
                entity.GetComponent <TransformComponent>().LocalPosition = coordinates;
                entity.Initialize();
                return(true);
            }
            entity = null;
            return(false);
        }
Exemplo n.º 34
0
    public FilterGenerator(int quadrantSize, LocalTerrain localTerrain)
    {
        globalFilterMountainC = new GlobalCoordinates(100);
        globalFilterAverageC = new GlobalCoordinates(100);
        globalFilterMedianC = new GlobalCoordinates(100);
        globalFilterSpikeC = new GlobalCoordinates(100);
        globalFilterGaussianC = new GlobalCoordinates(100);
        globalFilterMinThresholdC = new GlobalCoordinates(100);
        globalFilterMaxThresholdC = new GlobalCoordinates(100);

        lt = localTerrain;
        localCoordinates = lt.localTerrainC;

        mf = new MountainFilter(this);
        af = new AverageFilter(this);
        mdf = new MedianFilter(this);
        sf = new SpikeFilter(this);
        gf = new GaussianFilter(this);
        tf = new ThresholdFilter(this);
    }