Exemple #1
0
 public override void HandleAction(ISystemContainer systemContainer, ActionEventData action)
 {
     if (action != null && action.Action == ActionType.Select)
     {
         Select();
     }
 }
Exemple #2
0
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            if (!sender.Has <FollowPathBehaviour>())
            {
                var coordinates = eventData.Parameters.Split(';').Select(e =>
                {
                    var mapCoordinate = new MapCoordinate();
                    mapCoordinate.Deserialize(e);
                    return(mapCoordinate);
                }).ToList();

                var behaviour = new FollowPathBehaviour(_systemContainer)
                {
                    Path = coordinates, Priority = 999
                };

                _systemContainer.EntityEngine.AddComponent(sender, behaviour);

                var firstStep = behaviour.ChooseAction(sender);

                if (firstStep != null)
                {
                    _systemContainer.EventSystem.Try(EventType.Action, sender, firstStep);
                }
            }

            return(true);
        }
        private void DoEquipmentStuff(MenuItem selectedItem, MenuAction selectedAction)
        {
            if (selectedItem.Text == "Cancel")
            {
                CloseActivity();
                return;
            }

            var item = _systemContainer.EntityEngine.Get((uint)selectedItem.Value);

            switch (selectedAction)
            {
            case MenuAction.Unequip:
                var done = _systemContainer.EquipmentSystem.Unequip(_systemContainer.PlayerSystem.Player, item);

                if (done)
                {
                    SpendATurn();
                    CloseActivity();
                    _systemContainer.MessageSystem.Write($"You unequip the {item.DescriptionName}.");
                }

                break;

            case MenuAction.Examine:
                var actionData = new ActionEventData {
                    Action = ActionType.Examine, Parameters = item.EntityId.ToString()
                };
                _systemContainer.EventSystem.Try(EventType.Action, _systemContainer.PlayerSystem.Player, actionData);
                break;

            default:
                throw new ApplicationException($"Unknown MenuAction in {nameof(EquipmentMenu)}");
            }
        }
Exemple #4
0
        public override void HandleAction(ISystemContainer systemContainer, ActionEventData action)
        {
            if (action != null)
            {
                switch (action.Action)
                {
                case ActionType.Move:
                    var vector = Vector.Parse(action.Parameters);

                    if (vector == Vector.Right)
                    {
                        MoveNext();
                    }
                    if (vector == Vector.Left)
                    {
                        MovePrevious();
                    }
                    if (vector == Vector.Up)
                    {
                        MoveUp();
                    }
                    if (vector == Vector.Down)
                    {
                        MoveDown();
                    }
                    break;

                case ActionType.Select:
                    Select();
                    break;
                }
            }
        }
 public override void HandleAction(ISystemContainer systemContainer, ActionEventData action)
 {
     if (systemContainer.TimeSystem.WaitingForInput && action != null)
     {
         systemContainer.EventSystem.Try(EventType.Action, systemContainer.PlayerSystem.Player, action);
     }
 }
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var senderMapCoordinate = _systemContainer.PositionSystem.CoordinateOf(sender);

            var items = _systemContainer.PositionSystem.EntitiesAt(senderMapCoordinate)
                        .Except(new[] { sender })
                        .Where(e => e.Has <Item>() || e.Has <Wealth>())
                        .OrderBy(e => e.EntityId);

            var firstItem = items.FirstOrDefault();

            if (firstItem != null)
            {
                eventData.IsAction = true;

                if (firstItem.Has <Wealth>())
                {
                    var wealth = firstItem.Get <Wealth>();

                    var wealthEventData = new PickupWealthEventData {
                        Item = firstItem
                    };

                    var ok = _systemContainer.EventSystem.Try(EventType.PickUpWealth, sender, wealthEventData);

                    if (ok)
                    {
                        _systemContainer.MessageSystem.Write($"{sender.DescriptionName} picks up the {firstItem.Get<Description>().Name}. {sender.DescriptionName} gains {wealth.Amount} {wealth.Currency}.");

                        _systemContainer.ItemSystem.TransferWealth(firstItem, sender, wealth.Currency, wealth.Amount);

                        _systemContainer.EntityEngine.Destroy(firstItem);
                    }
                }
                else
                {
                    var itemEventData = new PickupItemEventData {
                        Item = firstItem
                    };

                    var ok = _systemContainer.EventSystem.Try(EventType.PickUpItem, sender, itemEventData);

                    if (ok)
                    {
                        var inventory = sender.Get <Inventory>();

                        var done = _systemContainer.ItemSystem.MoveToInventory(firstItem, inventory);

                        if (done)
                        {
                            _systemContainer.MessageSystem.Write($"{sender.DescriptionName} picks up the {firstItem.Get<Description>().Name}.");
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
Exemple #7
0
        private void DoSkillStuff(MenuItem selectedItem, MenuAction selectedAction)
        {
            if (selectedItem.Text == "Cancel")
            {
                CloseActivity();
                return;
            }

            switch (selectedAction)
            {
            case MenuAction.Use:
                CloseActivity();

                KnownSkill knownSkill = (KnownSkill)selectedItem.Value;

                ActionEventData actionEventData = new ActionEventData
                {
                    Action     = ActionType.UseSkill,
                    Parameters = knownSkill.Skill
                };

                _systemContainer.EventSystem.Try(EventType.Action, _entity, actionEventData);

                break;

            default:
                throw new ApplicationException($"Unknown MenuAction in {nameof(SkillMenu)}");
            }
        }
Exemple #8
0
        public virtual void HandleAction(ActionEventData action)
        {
            if (action != null)
            {
                if (action.Action == ActionType.Move)
                {
                    switch (action.Parameters)
                    {
                    case "0,-1":
                        Previous();
                        break;

                    case "0,1":
                        Next();
                        break;

                    case "1,0":
                        NextAction();
                        break;

                    case "-1,0":
                        PreviousAction();
                        break;
                    }
                }

                if (action.Action == ActionType.Select)
                {
                    Select();
                }
            }
        }
Exemple #9
0
        public bool Apply(EventType type, IEntity sender, object eventData)
        {
            if (IsFighter(sender))
            {
                var vector           = (Vector)eventData;
                var targetCoordinate = _positionSystem.CoordinateOf(sender) + vector;

                var entitiesAtPosition = _positionSystem.EntitiesAt(targetCoordinate);

                if (entitiesAtPosition.Any(IsFighter))
                {
                    var defender = entitiesAtPosition.Single(e => IsFighter(e));

                    var action = new ActionEventData {
                        Action = ActionType.MeleeAttack, Parameters = $"{sender.EntityId},{defender.EntityId}", Speed = null, KeyPress = null
                    };

                    if (_eventSystem.Try(EventType.Action, sender, action))
                    {
                        _animatedMovementSystem.StartAnimatedMovement(sender, new List <AnimationMovement> {
                            new AnimationMovement(new VectorDouble((double)vector.X / (double)-2, (double)vector.Y / (double)-2), 750)
                        });
                    }

                    return(false);
                }
            }

            return(true);
        }
Exemple #10
0
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var player = _systemContainer.PlayerSystem.Player;

            _systemContainer.ActivitySystem.Push(new InformationActivity(_systemContainer.ActivitySystem.DefaultPosition, _systemContainer.ActivitySystem.DefaultPadding, _systemContainer.ActivitySystem, StatusHelper.GetStatusConfigurations(player), player, true, true));

            return(false);
        }
Exemple #11
0
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var restBehaviour = sender.Get <PlayerRestBehaviour>();

            restBehaviour.Resting = true;

            return(true);
        }
Exemple #12
0
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var confirmDialog = new ConfirmActivity(_systemContainer.ActivitySystem.DefaultPosition, _systemContainer.ActivitySystem.DefaultPadding, _systemContainer, "Are you sure you want to quit? Unsaved progress will be lost.", CloseGameplayActivity);

            _systemContainer.ActivitySystem.Push(confirmDialog);

            return(true);
        }
Exemple #13
0
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            _systemContainer.ActivitySystem.Push(new MenuActivity(
                                                     _systemContainer.ActivitySystem.DefaultPosition,
                                                     _systemContainer.ActivitySystem.DefaultPadding,
                                                     new SkillMenu(_systemContainer, sender)));

            return(false);
        }
Exemple #14
0
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var entityId = uint.Parse(eventData.Parameters);
            var entity   = _systemContainer.EntityEngine.Get(entityId);

            _systemContainer.ActivitySystem.Push(new InformationActivity(_systemContainer.ActivitySystem.DefaultPosition, _systemContainer.ActivitySystem.DefaultPadding, _systemContainer.ActivitySystem, StatusHelper.GetStatusConfigurations(entity), entity, true, false));

            return(false);
        }
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            if (_systemContainer.ActivitySystem.Count > 1)
            {
                _systemContainer.ActivitySystem.RemoveActivity(_systemContainer.ActivitySystem.Peek());
            }

            return true;
        }
Exemple #16
0
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var mapEditorActivity = _systemContainer.ActivitySystem.MapEditorActivity;

            mapEditorActivity.SetTool(eventData.Parameters);
            _systemContainer.MessageSystem.Write($"Change tool: {eventData.Parameters}");

            return(true);
        }
Exemple #17
0
        public void HandleAction_Move_NoCurrentTarget_MovesFromOrigin()
        {
            var action = new ActionEventData {
                Action = ActionType.Move, Parameters = "1,0"
            };

            _targetingActivity.HandleAction(_systemContainer, action);

            TargetShouldBe(1, 0);
        }
Exemple #18
0
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var vector = Vector.Parse(eventData.Parameters);

            if (_systemContainer.EventSystem.Try(EventType.Move, sender, vector))
            {
                eventData.IsAction = true;
            }

            return(true);
        }
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var inventory = sender.Get <Inventory>();

            _systemContainer.ActivitySystem.Push(new MenuActivity(
                                                     _systemContainer.ActivitySystem.DefaultPosition,
                                                     _systemContainer.ActivitySystem.DefaultPadding,
                                                     new InventoryMenu(_systemContainer, inventory)));

            return(false);
        }
Exemple #20
0
        public void HandleAction_Escape_ClosesActivity()
        {
            var action = new ActionEventData {
                Action = ActionType.EscapeMenu
            };

            _targetingActivity.HandleAction(_systemContainer, action);

            _callbackHappened.Should().BeFalse();
            _activitySystem.Received(1).RemoveActivity(_targetingActivity);
        }
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var interaction = _systemContainer.InteractableSystem.GetCurrentInteractionFor(sender);

            if (interaction.Item1 != null)
            {
                _systemContainer.ScriptExecutor.ExecuteByName(interaction.Item1, interaction.Item2.Script, sender);
            }

            return(false);
        }
Exemple #22
0
        public void HandleAction_Select_CallsBack()
        {
            _targetingActivity.CurrentTarget = new MapCoordinate("Map", 1, 0);

            var action = new ActionEventData {
                Action = ActionType.Select
            };

            _targetingActivity.HandleAction(_systemContainer, action);

            _callbackHappened.Should().BeTrue();
        }
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var splits   = eventData.Parameters.Split(',');
            var attacker = _systemContainer.EntityEngine.Get(uint.Parse(splits[0]));
            var defender = _systemContainer.EntityEngine.Get(uint.Parse(splits[1]));

            var hit = _systemContainer.FighterSystem.BasicAttack(attacker, defender);

            eventData.IsAction = true;

            return(true);
        }
Exemple #24
0
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var index = int.Parse(eventData.Parameters);

            var skills = _systemContainer.SkillSystem.KnownSkills(sender).ToList();

            if (skills.Count() > index)
            {
                _systemContainer.SkillSystem.Use(sender, skills[index]);
            }

            return(false);
        }
Exemple #25
0
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var waitTime = int.Parse(eventData.Parameters ?? "1");

            if (_systemContainer.EventSystem.Try(EventType.SpendTime, sender, new SpendTimeEventData {
                Ticks = (ulong)waitTime * sender.Get <Actor>().Speed
            }))
            {
                eventData.IsAction = true;
            }

            return(true);
        }
Exemple #26
0
        public override ActionEventData HandleMouse(MouseData mouse, IDataRogueControlRenderer renderer, ISystemContainer systemContainer)
        {
            MapCoordinate mapCoordinate = GetMapCoordinate(mouse, systemContainer);

            systemContainer.ControlSystem.HoveredCoordinate = mapCoordinate;

            var player = systemContainer.PlayerSystem.Player;

            if (mouse.IsLeftClick && systemContainer.TimeSystem.WaitingForInput && CanAutowalkToCoordinate(systemContainer, mapCoordinate))
            {
                var playerLocation = systemContainer.PositionSystem.CoordinateOf(player);
                var map            = systemContainer.MapSystem.MapCollection[systemContainer.RendererSystem.CameraPosition.Key];
                var path           = _pathfindingAlgorithm.Path(map, playerLocation, mapCoordinate);

                if (path != null)
                {
                    var action = new ActionEventData {
                        Action = ActionType.FollowPath, Parameters = string.Join(";", path.Select(m => m.ToString()))
                    };

                    return(action);
                }
            }

            if (mouse.IsRightClick && systemContainer.TimeSystem.WaitingForInput)
            {
                var map = systemContainer.MapSystem.MapCollection[systemContainer.RendererSystem.CameraPosition.Key];

                if (map.SeenCoordinates.Contains(mapCoordinate))
                {
                    var playerFov = FOVHelper.CalculatePlayerFov(systemContainer);

                    var entities = systemContainer.PositionSystem.EntitiesAt(mapCoordinate);

                    if (!playerFov.Contains(mapCoordinate))
                    {
                        entities = entities.Where(e => e.Has <Memorable>()).ToList();
                    }

                    IEntity entityToShow = entities.OrderByDescending(e => e.Has <Appearance>() ? e.Get <Appearance>().ZOrder : int.MinValue).First();

                    var action = new ActionEventData {
                        Action = ActionType.Examine, Parameters = entityToShow.EntityId.ToString()
                    };

                    return(action);
                }
            }

            return(null);
        }
Exemple #27
0
        public void HandleAction_Move_CurrentTarget_MovesFromCurrentTarget()
        {
            SetTargetableCells(new MapCoordinate("Map", 1, 0), new MapCoordinate("Map", 2, 0));

            _targetingActivity.CurrentTarget = new MapCoordinate("Map", 1, 0);

            var action = new ActionEventData {
                Action = ActionType.Move, Parameters = "1,0"
            };

            _targetingActivity.HandleAction(_systemContainer, action);

            TargetShouldBe(2, 0);
        }
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            if (!AttackerCanMakeRangedAttack(sender))
            {
                return(false);
            }

            _systemContainer.TargetingSystem.GetTarget(sender, new Targeting {
                Range = 10, TargetOrigin = false, CellsHit = new VectorList {
                    new Vector(0, 0)
                }
            }, (mapCoordinate) => ResolveRangedAttack(sender, mapCoordinate));

            return(false);
        }
Exemple #29
0
        public override void HandleAction(ISystemContainer systemContainer, ActionEventData action)
        {
            if (action != null)
            {
                switch (action.Action)
                {
                case ActionType.Move:
                    OkSelected = !OkSelected;
                    SetButtonFocused();
                    break;

                case ActionType.Select:
                    Select();
                    break;
                }
            }
        }
Exemple #30
0
        public override bool ApplyInternal(IEntity sender, ActionEventData eventData)
        {
            var mapCoordinate = sender.Get <Position>().MapCoordinate;
            var direction     = (StairDirection)Enum.Parse(typeof(StairDirection), eventData.Parameters);

            var stairs = _systemContainer.PositionSystem
                         .EntitiesAt(mapCoordinate)
                         .Where(e => e.Has <Stairs>())
                         .Select(e => e.Get <Stairs>())
                         .SingleOrDefault();

            if (stairs != null && stairs.Direction == direction)
            {
                if (_systemContainer.EventSystem.Try(EventType.ChangeFloor, sender, direction))
                {
                    _systemContainer.PositionSystem.SetPosition(sender, stairs.Destination);
                }

                eventData.IsAction = true;
            }
            else
            {
                var portal = _systemContainer.PositionSystem
                             .EntitiesAt(mapCoordinate)
                             .Where(e => e.Has <Portal>())
                             .Select(e => e.Get <Portal>())
                             .SingleOrDefault();

                if (portal != null)
                {
                    if (_systemContainer.EventSystem.Try(EventType.UsePortal, sender, portal))
                    {
                        _systemContainer.PositionSystem.SetPosition(sender, portal.Destination);
                    }

                    eventData.IsAction = true;
                }
            }

            return(true);
        }