Exemplo n.º 1
0
        public InfoOverlay(LogicalMap2D logicalMap)
        {
            _logicalMap = logicalMap ?? throw new ArgumentNullException(nameof(logicalMap));
            // 1 tile padding all around so we don't have to worry about edge conditions in the shader
            _tiles             = new byte[Width * Height];
            _logicalMap.Dirty += (sender, args) =>
            {
                if (args.Type != IconChangeType.Trigger)
                {
                    return;
                }

                int index    = _logicalMap.Index(args.X, args.Y);
                var zone     = _logicalMap.GetZone(index);
                var triggers = zone?.Trigger ?? 0;
                _tiles[Index(args.X, args.Y)] = BuildTile(triggers);
                BufferDirty = true;
            };
            On <BeginFrameEvent>(_ => _flags = 0);
            On <CursorModeEvent>(e
                                 => _flags |= e.Mode switch
            {
                CursorMode.Examine => InfoOverlayFlags.VerbExamine,
                CursorMode.Manipulate => InfoOverlayFlags.VerbManipulate,
                CursorMode.Talk => InfoOverlayFlags.VerbTalk,
                CursorMode.Take => InfoOverlayFlags.VerbTake,
                _ => 0
            });
Exemplo n.º 2
0
        void OnNpcEnteredTile(NpcEnteredTileEvent e)
        {
            MapEventZone zone;

            while (true)
            {
                zone = _logicalMap.GetZone(e.X, e.Y);
                if (zone == null || !zone.Trigger.HasFlag(TriggerTypes.Npc))
                {
                    return;
                }

                if (!(zone.Chain.FirstEvent.Event is OffsetEvent offset))
                {
                    break;
                }
                e = new NpcEnteredTileEvent(e.Id, e.X + offset.X, e.Y + offset.Y);
            }

            if (zone.Chain.Enabled)
            {
                Raise(new TriggerChainEvent(zone.Chain, zone.Node, new EventSource(_mapData.Id, _mapData.Id.ToMapText(), TriggerTypes.Npc, e.X, e.Y)));
            }
        }
Exemplo n.º 3
0
        bool OnSelect(WorldCoordinateSelectEvent e, Action <Selection> continuation)
        {
            float denominator = Vector3.Dot(Normal, e.Direction);

            if (Math.Abs(denominator) < 0.00001f)
            {
                return(false);
            }

            float t = Vector3.Dot(-e.Origin, Normal) / denominator;

            if (t < 0)
            {
                return(false);
            }

            Vector3 intersectionPoint = e.Origin + t * e.Direction;
            int     x = (int)(intersectionPoint.X / _renderable.TileSize.X);
            int     y = (int)(intersectionPoint.Y / _renderable.TileSize.Y);

            int highlightIndex = y * _map.Width + x;
            var underlayTile   = _map.GetUnderlay(x, y);
            var overlayTile    = _map.GetOverlay(x, y);

            continuation(new Selection(e.Origin, e.Direction, t, new MapTileHit(
                                           new Vector2(x, y),
                                           intersectionPoint,
                                           _renderable.GetWeakUnderlayReference(x, y),
                                           _renderable.GetWeakOverlayReference(x, y))));

            if (underlayTile != null)
            {
                continuation(new Selection(e.Origin, e.Direction, t, underlayTile));
            }
            if (overlayTile != null)
            {
                continuation(new Selection(e.Origin, e.Direction, t, overlayTile));
            }
            continuation(new Selection(e.Origin, e.Direction, t, this));

            var zone = _map.GetZone(x, y);

            if (zone != null)
            {
                continuation(new Selection(e.Origin, e.Direction, t, zone));
            }

            var chain = zone?.Chain;

            if (chain != null)
            {
                foreach (var zoneEvent in chain.Events)
                {
                    continuation(new Selection(e.Origin, e.Direction, t, zoneEvent));
                }
            }

            if (_lastHighlightIndex != highlightIndex)
            {
                HighlightIndexChanged?.Invoke(this, highlightIndex);
                _lastHighlightIndex = highlightIndex;
            }

            return(true);
        }