public void Drop_UnitCannotDropObject_NoActionTaken()
        {
            //Setup
            var unit    = CreateUnit();
            var dropper = unit.As <IDropper>();
            var state   = CreateStateMock(CreateUnitList(unit));

            AddUnitToState(unit, state);

            var subject = new ActionExecutor(state.Object);

            var transferObject = new Mock <WorldObject>();
            var transferable   = transferObject.As <ITransferable>();

            transferable.Setup(tr => tr.Owner).Returns(unit.Object.Id);
            var transferGuid = Guid.NewGuid();
            var action       = new DropAction(transferGuid);

            state.Setup(s => s.FindObject(transferGuid)).Returns(transferObject.Object);

            //Unit will not drop on its end
            dropper.Setup(d => d.Drop(transferable.Object)).Returns(false);

            UnitActionCollection actions = new UnitActionCollection();

            actions.AddAction(unit.Object.Id, action);

            //Act
            subject.Execute(actions);

            //Assert
            //Dropper asked to drop but transfer object not asked to drop
            dropper.Verify(d => d.Drop(transferable.Object));
            transferable.Verify(t => t.Drop(), Times.Never);
        }
        public void Drop_UnownedObject_FailAction()
        {
            //Setup
            var unit    = CreateUnit();
            var dropper = unit.As <IDropper>();
            var state   = CreateStateMock(CreateUnitList(unit));

            AddUnitToState(unit, state);

            var subject = new ActionExecutor(state.Object);

            var transferObject = new Mock <WorldObject>();
            var transferable   = transferObject.As <ITransferable>();

            //Has no owner
            transferable.Setup(tr => tr.Owner).Returns(null);

            var transferGuid = Guid.NewGuid();
            var action       = new DropAction(transferGuid);

            state.Setup(s => s.FindObject(transferGuid)).Returns(transferObject.Object);

            UnitActionCollection actions = new UnitActionCollection();

            actions.AddAction(unit.Object.Id, action);

            //Act & Assert
            Assert.Throws <BadActionException>(() => subject.Execute(actions));
        }
示例#3
0
 public MouseDrop <T> Create(Cursor cursor, DropAction drop, Action cancel = null)
 {
     dropCursor   = cursor;
     dropAction   = drop;
     cancelAction = cancel;
     return(this);
 }
        public void Drop_NonTransferableObject_FailsAction()
        {
            //Setup
            var unit    = CreateUnit();
            var dropper = unit.As <IDropper>();
            var state   = CreateStateMock(CreateUnitList(unit));

            AddUnitToState(unit, state);

            var transferObject = new Mock <WorldObject>();
            //Object not given the ITransferable interface so it will fail
            var transferGuid = Guid.NewGuid();
            var action       = new DropAction(transferGuid);

            state.Setup(s => s.FindObject(transferGuid)).Returns(transferObject.Object);

            var subject = new ActionExecutor(state.Object);

            UnitActionCollection actions = new UnitActionCollection();

            actions.AddAction(unit.Object.Id, action);

            //Act & Assert
            Assert.Throws <BadActionException>(() => subject.Execute(actions));
        }
    private void DropArea_Drop(object sender, DragEventArgs e)
    {
        if (!e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            SystemSounds.Asterisk.Play();
            return;
        }

        string[] paths = (string[])e.Data.GetData(DataFormats.FileDrop);

        DropAction dropAction = sender.CastTo <FrameworkElement>()
                                .Tag.CastTo <DropAction>();

        NewGroupDataCreator groupDataCreator = new();

        groupDataCreator.ThresholdValidation = ShowMessageBoxIfAboveThreshhold;

        IEnumerable <NewGroupData> newGroupDatas = dropAction switch
        {
            DropAction.None => throw new InvalidOperationException("DropAction.None is not a valid action for adding assets."),
                  DropAction.Files or DropAction.Folders => groupDataCreator.Create(paths),
                  DropAction.FoldersAndSubfolders => groupDataCreator.Create(paths, includeSubfolders: true),
                  _ => throw new NotSupportedException(),
        };

        AddAssetsCommand.Execute(() => newGroupDatas);
    }
示例#6
0
        private void OnDrag(object sender, EventArgs e)
        {
            // Start the drag and drop but setting the object slot index in Drag and Drop data
            var dropAction = new DropAction(DropAction.ActionType.Mario, Config.Mario.StructAddress);

            (sender as Control).DoDragDrop(dropAction, DragDropEffects.All);
        }
示例#7
0
        private void OnDrag(object sender, EventArgs e)
        {
            if (!CurrentAddress.HasValue)
            {
                return;
            }

            // Start the drag and drop but setting the object slot index in Drag and Drop data
            var dropAction = new DropAction(DropAction.ActionType.Object, CurrentAddress.Value);

            (sender as Control).DoDragDrop(dropAction, DragDropEffects.All);
        }
示例#8
0
        private void OnDrag(object sender, MouseEventArgs e)
        {
            OnClick(new EventArgs());

            MouseState = MouseStateType.Down;
            UpdateColors();
            Refresh();

            // Start the drag and drop but setting the object slot index in Drag and Drop data
            var objectAddress = Address;
            var dropAction    = new DropAction(DropAction.ActionType.Object, objectAddress);

            DoDragDrop(dropAction, DragDropEffects.All);
        }
示例#9
0
    public virtual void Die()
    {
        Debug.Log("Monster is dead!");

        //Clear tile, so other systems don't try to use a dead monster
        currentTile.currentlyStanding = null;

        //Clear inventory, if it exists
        if (inventory)
        {
            GameAction dropAll = new DropAction(inventory.AllIndices());
            dropAll.Setup(this);
            while (dropAll.action.MoveNext())
            {
            }
        }
    }
示例#10
0
        public void OnSlotDropAction(DropAction dropAction, ObjectSlot objSlot)
        {
            switch (dropAction.Action)
            {
            case DropAction.ActionType.Mario:
                // Move mario to object
                var objectAddress = objSlot.Address;
                MarioActions.MoveMarioToObject(_stream, objectAddress);
                break;

            case DropAction.ActionType.Object:
                break;

            default:
                return;
            }
        }
示例#11
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.E) && currentlyControlled)
     {
         if (carrying)
         {
             DropAction da = new DropAction(this);
             loopTracker.RegisterAction(da);
             da.PlayAction();
         }
         else
         {
             PickupAction pa = new PickupAction(this);
             loopTracker.RegisterAction(pa);
             pa.PlayAction();
         }
     }
 }
        public void Drop_NotIDropper_FailsAction()
        {
            //Setup
            var unit  = CreateUnit();
            var state = CreateStateMock(CreateUnitList(unit));

            AddUnitToState(unit, state);

            var transferGuid             = Guid.NewGuid();
            var action                   = new DropAction(transferGuid);
            UnitActionCollection actions = new UnitActionCollection();

            actions.AddAction(unit.Object.Id, action);

            var subject = new ActionExecutor(state.Object);

            //Act & Assert
            Assert.Throws <BadActionException>(() => subject.Execute(actions));
        }
        public void Drop_InvalidObject_FailAction()
        {
            //Setup
            var unit    = CreateUnit();
            var dropper = unit.As <IDropper>();
            var state   = CreateStateMock(CreateUnitList(unit));

            AddUnitToState(unit, state);

            var subject = new ActionExecutor(state.Object);

            var action = new DropAction(Guid.NewGuid());
            UnitActionCollection actions = new UnitActionCollection();

            actions.AddAction(unit.Object.Id, action);

            //Act & Assert
            //No object setup so it is invalid
            Assert.Throws <BadActionException>(() => subject.Execute(actions));
        }
        protected virtual void ProcessDropAction(DropAction action, List <StackResponseContainerInfo> stackResponses)
        {
            byte count = action.Count;
            Item dropItem;
            StackRequestSlotInfo source = action.Source;

            Item sourceItem = GetContainerItem(source.ContainerId, source.Slot);

            if (sourceItem.Count == count || sourceItem.Count - count <= 0)
            {
                dropItem            = sourceItem;
                sourceItem          = new ItemAir();
                sourceItem.UniqueId = 0;
                SetContainerItem(source.ContainerId, source.Slot, sourceItem);
            }
            else
            {
                dropItem          = (Item)sourceItem.Clone();
                sourceItem.Count -= count;
                dropItem.Count    = count;
                dropItem.UniqueId = Environment.TickCount & Int32.MaxValue;
            }

            _player.DropItem(dropItem);

            stackResponses.Add(new StackResponseContainerInfo
            {
                ContainerId = source.ContainerId,
                Slots       = new List <StackResponseSlotInfo>
                {
                    new StackResponseSlotInfo()
                    {
                        Count          = sourceItem.Count,
                        Slot           = source.Slot,
                        HotbarSlot     = source.Slot,
                        StackNetworkId = sourceItem.UniqueId
                    }
                }
            });
        }
        public void Drop_ValidObject_OwnerChangedAndObjectMoved()
        {
            //Setup
            var unit    = CreateUnit();
            var dropper = unit.As <IDropper>();
            var point   = new Point(5, 5);

            unit.Setup(u => u.Location).Returns(point);
            var state = CreateStateMock(CreateUnitList(unit));

            AddUnitToState(unit, state);

            var subject = new ActionExecutor(state.Object);

            var transferObject = new Mock <WorldObject>();
            var transferable   = transferObject.As <ITransferable>();

            transferable.Setup(tr => tr.Owner).Returns(unit.Object.Id);
            var transferGuid = Guid.NewGuid();
            var action       = new DropAction(transferGuid);

            dropper.Setup(d => d.Drop(transferable.Object)).Returns(true);

            state.Setup(s => s.FindObject(transferGuid)).Returns(transferObject.Object);

            UnitActionCollection actions = new UnitActionCollection();

            actions.AddAction(unit.Object.Id, action);

            //Act
            subject.Execute(actions);

            //Assert
            //Dropper dropped and transfer object knows it has been dropped
            dropper.Verify(d => d.Drop(transferable.Object));
            transferable.Verify(t => t.Drop());
            transferObject.Verify(t => t.Move(point));
        }
示例#16
0
 public NodeEditor()
 {
     InitBluePrintNodeClasses(m_SelectDict);
     OnDropEvent += new DropAction(OnVarDragDrop);
     ShowWindow();
 }
示例#17
0
    public override void HandleInput(PlayerAction action, string inputString)
    {
        switch (queuedAction)
        {
        case ItemAction.INSPECT:
            //Break down input into item types
            foreach (char c in inputString.Where(c => char.IsLetter(c)))
            {
                int index = Conversions.NumberingToInt(c);
                if (index < examinedInventory.capacity && examinedInventory[index] != null)
                {
                    //Display an item!
                    UIController.singleton.OpenItemInspect(examinedInventory, index);
                    break;
                }
            }
            break;

        case ItemAction.EQUIP:
            //Break down input into item types
            foreach (char c in inputString.Where(c => char.IsLetter(c)))
            {
                int index = Conversions.NumberingToInt(c);
                if (index < examinedInventory.capacity && examinedInventory[index] != null && index >= 0)
                {
                    //Equip an item!
                    Player.player.SetAction(new EquipAction(index, queuedEquipmentIndex));
                    ExitAllWindows();
                    break;
                }
            }
            break;


        case ItemAction.PICK_UP:
        case ItemAction.DROP:
            if (action == PlayerAction.ACCEPT)
            {
                //Splitting this up because of the new action system.
                //TODO: Refactor this bit better

                List <int> indices = new List <int>();
                for (int i = 0; i < selected.Length; i++)
                {
                    if (selected[i])
                    {
                        indices.Add(i);
                    }
                }
                GameAction act;
                if (queuedAction == ItemAction.DROP)
                {
                    act = new DropAction(indices);
                }
                else
                {
                    act = new PickupAction(indices);
                }
                Player.player.SetAction(act);
                ExitAllWindows();
            }
            else
            {
                //Flip bits for selected items
                foreach (char c in inputString.Where(c => char.IsLetter(c)))
                {
                    //Attempt to flip the bit
                    int index = Conversions.NumberingToInt(c);
                    selected[index] = !selected[index];
                    for (int i = 0; i < displayed.Count; i++)
                    {
                        ItemPanel current = displayed[i];
                        if (current.index == index)
                        {
                            current.Select();
                            break;
                        }
                    }
                }
            }
            break;

        case ItemAction.APPLY:
            foreach (char c in inputString.Where(c => char.IsLetter(c)))
            {
                int index = Conversions.NumberingToInt(c);
                if (index < examinedInventory.capacity && examinedInventory[index] != null && index >= 0)
                {
                    //Equip an item!
                    Player.player.inventory.Apply(index);
                    ExitAllWindows();
                    break;
                }
            }
            break;
        }
    }