/// <summary>
 /// Creates a new instance of <see cref="ActionBuilderWithPreviousResult{TAction, TResult, TPreviousAction, TPReviousResult}"/>
 /// </summary>
 /// <param name="previousAction">A function that returns the previous action</param>
 /// <param name="executableAction">The previous executable action</param>
 /// <param name="actionFactory">The action factory</param>
 /// <param name="previousActionName">The previous action name</param>
 public ActionBuilderWithPreviousResult(
     Func <IActor, TPreviousAction> previousAction,
     CompositeAction executableAction,
     Func <ActionResult <TPreviousAction, TPreviousResult>, TAction> actionFactory,
     string previousActionName) : this(previousAction, executableAction, actionFactory, previousActionName, "")
 {
 }
Пример #2
0
 public ScanRequest()
 {
     roots = new List<string>();
     filter = new List<string>();
     excludes = new List<string>();
     onFound = new CompositeAction<FileFound>();
 }
        internal QualifierVisualizer(IQualifier q, SelectorVisualizer parent)
        {
            this._qualifier = q;
            this._parent    = parent;
            SelectorAction      selectorAction     = q.action as SelectorAction;
            AILinkAction        aILinkAction       = q.action as AILinkAction;
            CompositeAction     compositeAction    = q.action as CompositeAction;
            IRequireTermination requireTermination = q.action as IRequireTermination;

            if (selectorAction != null)
            {
                this._action = new SelectorActionVisualizer(selectorAction, this);
                return;
            }
            if (aILinkAction != null)
            {
                this._action = new AILinkActionVisualizer(aILinkAction, this);
                return;
            }
            if (compositeAction != null)
            {
                this._action = new CompositeActionVisualizer(compositeAction, this);
                return;
            }
            if (requireTermination != null)
            {
                this._action = new ActionRequiresTerminationVisualizer(q.action, this);
                return;
            }
            if (q.action != null)
            {
                this._action = new ActionVisualizer(q.action, this);
            }
        }
Пример #4
0
 public ScanRequest()
 {
     _roots    = new List <string>();
     _filter   = new List <string>();
     _excludes = new List <string>();
     _onFound  = new CompositeAction <FileFound>();
 }
Пример #5
0
 public TemplateFinder(IFileScanner fileScanner, IEnumerable <IPackageInfo> packages)
 {
     _fileScanner   = fileScanner;
     _packages      = packages;
     _requestConfig = new CompositeAction <ScanRequest>();
     _hostExcludes  = new CompositeAction <ScanRequest>();
 }
        private ActionBuilderWithPreviousResult(
            Func <IActor, TPreviousAction> previousAction,
            CompositeAction executableAction,
            Func <ActionResult <TPreviousAction, TPreviousResult>, TAction> actionFactory,
            string previousActionName,
            string name)
        {
            if (actionFactory == null)
            {
                throw new ArgumentNullException(nameof(actionFactory));
            }

            if (previousAction == null)
            {
                throw new ArgumentNullException(nameof(previousAction));
            }

            if (executableAction == null)
            {
                throw new ArgumentNullException(nameof(executableAction));
            }

            if (previousActionName == null)
            {
                throw new ArgumentNullException(nameof(previousActionName));
            }

            ActionFactory      = actionFactory;
            PreviousAction     = previousAction;
            PreviousActionName = previousActionName;
            _executableAction  = executableAction;
            _name = name;
        }
Пример #7
0
        public void GetTransactionList()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var stock = new Stock(Guid.NewGuid());

            stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks);

            var holding = mockRepository.Create <IReadOnlyHolding>();

            var stockResolver = mockRepository.Create <IStockResolver>();

            stockResolver.Setup(x => x.GetStock(stock.Id)).Returns(stock);

            var t1 = mockRepository.Create <IPortfolioTransaction>();
            var t2 = mockRepository.Create <IPortfolioTransaction>();
            var t3 = mockRepository.Create <IPortfolioTransaction>();

            var firstAction = mockRepository.Create <ICorporateAction>();

            firstAction.Setup(x => x.GetTransactionList(holding.Object, stockResolver.Object)).Returns(new IPortfolioTransaction[] { t1.Object }).Verifiable();
            var secondAction = mockRepository.Create <ICorporateAction>();

            secondAction.Setup(x => x.GetTransactionList(holding.Object, stockResolver.Object)).Returns(new IPortfolioTransaction[] { t2.Object, t3.Object }).Verifiable();
            var childActions    = new ICorporateAction[] { firstAction.Object, secondAction.Object };
            var compositeAction = new CompositeAction(Guid.NewGuid(), stock, new Date(2020, 01, 01), "Test Composite Action", childActions);

            var result = compositeAction.GetTransactionList(holding.Object, stockResolver.Object).ToList();

            result.Should().Equal(new IPortfolioTransaction[] { t1.Object, t2.Object, t3.Object });

            mockRepository.Verify();
        }
        internal CompositeActionVisualizer(CompositeAction action, IQualifierVisualizer parent)
            : base(action, parent)
        {
            _actions = new List <ActionVisualizer>(action.actions.Count);
            foreach (var a in action.actions)
            {
                var ca = a as CompositeAction;
                if (ca != null)
                {
                    _actions.Add(new CompositeActionVisualizer(ca, parent));
                }
                else
                {
                    _actions.Add(new ActionVisualizer(a, parent));
                }
            }

            var sa = action.connectorAction as SelectorAction;
            var la = action.connectorAction as AILinkAction;

            if (sa != null)
            {
                _connectorAction = new SelectorActionVisualizer(sa, parent);
            }
            else if (la != null)
            {
                _connectorAction = new AILinkActionVisualizer(la, parent);
            }
        }
Пример #9
0
 public FileSystemTemplateFinder(IFileScanner fileScanner, IRootPathProvider rootPathProvider, IFindModelFromViewCollection findModelFromViewCollection)
 {
     this.fileScanner = fileScanner;
     this.rootPathProvider = rootPathProvider;
     this.findModelFromViewCollection = findModelFromViewCollection;
     requestConfig = new CompositeAction<ScanRequest>();
 }
Пример #10
0
 public TemplateFinder(IFileScanner fileScanner, IEnumerable<IPackageInfo> packages)
 {
     _fileScanner = fileScanner;
     _packages = packages;
     _requestConfig = new CompositeAction<ScanRequest>();
     _hostExcludes = new CompositeAction<ScanRequest>();
 }
Пример #11
0
        private CorporateAction CorporateActionFromEvent(CompositeActionAddedEvent @event)
        {
            var childActions    = @event.ChildActions.Select(x => CorporateActionFromEvent(x));
            var compositeAction = new CompositeAction(@event.ActionId, Stock, @event.ActionDate, @event.Description, childActions);

            return(compositeAction);
        }
        internal CompositeActionVisualizer(CompositeAction action, IQualifierVisualizer parent) : base(action, parent)
        {
            this._actions = new List <ActionVisualizer>(action.actions.Count);
            for (int i = 0; i < action.actions.Count; i++)
            {
                IAction         item            = action.actions[i];
                CompositeAction compositeAction = item as CompositeAction;
                if (compositeAction == null)
                {
                    this._actions.Add(new ActionVisualizer(item, parent));
                }
                else
                {
                    this._actions.Add(new CompositeActionVisualizer(compositeAction, parent));
                }
            }
            SelectorAction selectorAction = action.connectorAction as SelectorAction;
            AILinkAction   aILinkAction   = action.connectorAction as AILinkAction;

            if (selectorAction != null)
            {
                this._connectorAction = new SelectorActionVisualizer(selectorAction, parent);
                return;
            }
            if (aILinkAction != null)
            {
                this._connectorAction = new AILinkActionVisualizer(aILinkAction, parent);
            }
        }
Пример #13
0
        [SetUp] public void SetUp()
        {
            _environment = _environment;
            InitStorage();
            RegisterResourcesAndProperties();
            _environment = new MockPluginEnvironment(_storage);
            _composite   = new CompositeAction("Delete");

            _storage.NewResource("Person");
            _storage.NewResource("Email");
        }
Пример #14
0
        internal ActionBuilder(TAction currentAction, CompositeAction executableAction, string name)
        {
            if (currentAction == null)
            {
                throw new ArgumentNullException(nameof(currentAction));
            }

            Action            = currentAction;
            _executableAction = executableAction;
            Name = name;
        }
Пример #15
0
        public void And_ShouldAddAction(
            CompositeAction sut,
            IAction <Unit> expected
            )
        {
            //arrange
            var existingActions = sut.Actions.ToArray();
            //act
            var actual = sut.And(expected);

            //assert
            actual.Actions.Except(existingActions).Single().Should().Be(expected);
        }
Пример #16
0
 public void ExecuteWhenAs_ShouldCallActorExecute(
     CompositeAction sut,
     Mock <IActor> actor
     )
 {
     //arrange
     //act
     sut.ExecuteWhenAs(actor.Object);
     //assert
     foreach (var action in sut.Actions)
     {
         actor.Verify(a => a.Execute(action), Times.Once());
     }
 }
        void Apex.AI.Visualization.ICompositeVisualizer.Add(object item)
        {
            IAction         action          = item as IAction;
            CompositeAction compositeAction = item as CompositeAction;

            if (compositeAction != null)
            {
                this._actions.Add(new CompositeActionVisualizer(compositeAction, base.parent));
                return;
            }
            if (action != null)
            {
                this._actions.Add(new ActionVisualizer(action, base.parent));
            }
        }
Пример #18
0
        public TemplateFinder(IFileScanner fileScanner, IEnumerable<IPackageInfo> packages)
        {
            _fileScanner = fileScanner;
            _packages = packages;
            _requestConfig = new CompositeAction<ScanRequest>();
            _hostExcludes = new CompositeAction<ScanRequest>();

            // TODO: Preferably set this on the Finder from the SparkExtension (as a default convention).

            IncludeFile("*spark");
            // TODO: This is not automatically synched with what the attacher looks for.
            IncludeFile("bindings.xml");

            ExcludeHostDirectory(FubuMvcPackageFacility.FubuPackagesFolder);
            ExcludeHostDirectory(FubuMvcPackageFacility.FubuPackagesFolder, FubuMvcPackageFacility.FubuContentFolder);
            ExcludeHostDirectory(FubuMvcPackageFacility.FubuContentFolder);
        }
Пример #19
0
        public TemplateFinder(IFileScanner fileScanner, IEnumerable <IPackageInfo> packages)
        {
            _fileScanner   = fileScanner;
            _packages      = packages;
            _requestConfig = new CompositeAction <ScanRequest>();
            _hostExcludes  = new CompositeAction <ScanRequest>();

            // TODO: Preferably set this on the Finder from the SparkExtension (as a default convention).

            IncludeFile("*spark");
            // TODO: This is not automatically synched with what the attacher looks for.
            IncludeFile("bindings.xml");

            ExcludeHostDirectory(FubuMvcPackageFacility.FubuPackagesFolder);
            ExcludeHostDirectory(FubuMvcPackageFacility.FubuPackagesFolder, FubuMvcPackageFacility.FubuContentFolder);
            ExcludeHostDirectory(FubuMvcPackageFacility.FubuContentFolder);
        }
Пример #20
0
        public void DeserializeCompositeAction()
        {
            var serializer = new RestClientSerializer();

            var actionId = Guid.NewGuid();
            var stockId  = Guid.NewGuid();

            var json = "{\"id\":\"" + actionId + "\","
                       + "\"stock\":\"" + stockId + "\","
                       + "\"type\":\"compositeAction\","
                       + "\"actionDate\":\"2000-01-10\","
                       + "\"description\":\"description\","
                       + "\"childActions\":["
                       + "{\"id\":\"" + actionId + "\","
                       + "\"stock\":\"" + stockId + "\","
                       + "\"type\":\"capitalReturn\","
                       + "\"actionDate\":\"2000-01-10\","
                       + "\"description\":\"description\","
                       + "\"paymentDate\":\"2000-02-01\","
                       + "\"amount\":12.00}"
                       + "]}";

            var transaction = serializer.Deserialize <CorporateAction>(json);

            var expected = new CompositeAction()
            {
                Id          = actionId,
                Stock       = stockId,
                ActionDate  = new Date(2000, 01, 10),
                Description = "description"
            };

            expected.ChildActions.Add(new CapitalReturn()
            {
                Id          = actionId,
                Stock       = stockId,
                ActionDate  = new Date(2000, 01, 10),
                Description = "description",
                PaymentDate = new Date(2000, 02, 01),
                Amount      = 12.00m
            });

            transaction.Should().BeEquivalentTo(expected);
        }
Пример #21
0
        public static void SlideTest()
        {
            var world = new World(5, 5);
            var p_fact = new EntityFactory<Entity>()
                .AddBehavior(Acting.Preset(new Acting.Config(Algos.SimpleAlgo)))
                .AddBehavior(Attacking.Preset)
                .AddBehavior(Moving.Preset)
                .AddBehavior(Displaceable.DefaultPreset)
                .AddBehavior(Statused.Preset)
                .Retouch(Hopper.Core.Retouchers.Reorient.OnDisplace)
                .Retouch(Hopper.Core.Retouchers.Skip.EmptyAttack);

            var player = world.SpawnPlayer(p_fact, new IntVector2(1, 1));
            var ice_fact = IceFloor.CreateFactory();
            var ice1 = world.SpawnEntity(ice_fact, new IntVector2(2, 1));
            var ice2 = world.SpawnEntity(ice_fact, new IntVector2(3, 1));
            var action = new CompositeAction(
                Action.CreateBehavioral<Attacking>(),
                Action.CreateBehavioral<Moving>()
            );
            void SetAction(IntVector2 vec) => player.Behaviors.Get<Acting>().NextAction
                = action.Copy().WithDir(vec);
            void Print()
            {
                System.Console.WriteLine($"Is status applied? {SlideStatus.Status.IsApplied(player)}");
                System.Console.WriteLine($"Position: {player.Pos}");
            }

            SetAction(IntVector2.Right);
            world.Loop();
            Print();

            SetAction(IntVector2.Down);
            world.Loop();
            Print();

            SetAction(IntVector2.Down);
            world.Loop();
            Print();

            SetAction(IntVector2.Down);
            world.Loop();
            Print();
        }
Пример #22
0
        public void HasBeenAppliedNoChildActions()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var stock = new Stock(Guid.NewGuid());

            stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks);

            var transactions = mockRepository.Create <IPortfolioTransactionList>();

            var childActions    = new ICorporateAction[] { };
            var compositeAction = new CompositeAction(Guid.NewGuid(), stock, new Date(2020, 01, 01), "Test Composite Action", childActions);

            var result = compositeAction.HasBeenApplied(transactions.Object);

            result.Should().BeFalse();

            mockRepository.Verify();
        }
Пример #23
0
        public void Execute_Action1ChangesPassedReferenceArgument_DoesChangeArgumentPassedToAction2()
        {
            var refActions = new CompositeAction <ReferenceType>();

            const int originalIdentity = 0;
            const int newIdentity      = 1;

            ReferenceType passedToAction2 = null;

            Action <ReferenceType> action1 = refArg => refArg.Identity = newIdentity;
            Action <ReferenceType> action2 = refArg => passedToAction2 = refArg;

            refActions
            .RegisterAction(action1)
            .RegisterAction(action2)
            .Invoke(new ReferenceType(originalIdentity));

            Assert.That(passedToAction2.Identity, Is.EqualTo(newIdentity));
        }
Пример #24
0
 public void ResetComposerConfiguration()
 {
     _configurations = new CompositeAction <TemplateComposer <ITemplate> >();
 }
Пример #25
0
 public void ExcludeHostDirectory(string path)
 {
     _hostExcludes += r => r.ExcludeDirectory(Path.Combine(HostPath, path));
 }
Пример #26
0
 private void excludeDirectory(string path)
 {
     _hostExcludes += r => r.ExcludeDirectory(path);
 }
Пример #27
0
 public ITemplateFinder IncludeExtension(string extension)
 {
     requestConfig += r => r.Include(string.Format("*{0}", extension));
     return this;
 }
Пример #28
0
 public void IncludeFile(string filter)
 {
     _requestConfig += r => r.Include(filter);
 }
Пример #29
0
 public void ExcludeHostDirectory(string path)
 {
     _hostExcludes += r => r.ExcludeDirectory(Path.Combine(HostPath, path));
 }
Пример #30
0
 public FubuSparkViewDecorator(IFubuSparkView view)
 {
     _view      = view;
     PreRender  = new CompositeAction <IFubuSparkView>();
     PostRender = new CompositeAction <IFubuSparkView>();
 }
Пример #31
0
 private void excludeDirectory(string path)
 {
     _hostExcludes += r => r.ExcludeDirectory(path);
 }
Пример #32
0
 public void Sut_ShouldBeAction(CompositeAction sut)
 {
     sut.Should().BeAssignableTo <IAction <Unit> >();
 }
Пример #33
0
 public void AddAction(Action<MessageChain> value)
 {
     _action += value;
 }
Пример #34
0
 public void IncludeFile(string filter)
 {
     _requestConfig += r => r.Include(filter);
 }
Пример #35
0
        static void Demo()
        {
            var ____ = Spider.Factory;
            var _____ = TestTinkerStuff.tinker;
            var ______ = TestStatusStuff.status;

            System.Console.WriteLine("\n ------ Definition + Instantiation Demo ------ \n");

            World world = new World(5, 5);
            System.Console.WriteLine("Created world");

            // Statused.RegisterStatus(TestStatusTinkerStuff.status, 1);
            var packed = Registry.Default.Tinker.PackModMap();
            Registry.Default.Tinker.SetServerMap(packed);

            var player.Factory = new EntityFactory<Player>();
            player.Factory.AddBehavior(Attackable.DefaultPreset);
            player.Factory.AddBehavior(Attacking.Preset);
            player.Factory.AddBehavior(Displaceable.DefaultPreset);
            player.Factory.AddBehavior(Moving.Preset);
            player.Factory.AddBehavior(Pushable.Preset);
            player.Factory.AddBehavior(Statused.Preset);
            System.Console.WriteLine("Set up player.Factory");

            Acting.Config playerActingConf = new Acting.Config(Algos.SimpleAlgo, null);

            player.Factory.AddBehavior(Acting.Preset(playerActingConf));
            player.Factory.Retouch(Hopper.Core.Retouchers.Skip.EmptyAttack);

            // this one's for the equip demo
            player.Factory.Retouch(Hopper.Core.Retouchers.Equip.OnDisplace);


            var enemy.Factory = new EntityFactory<Entity>();
            enemy.Factory.AddBehavior(Attackable.DefaultPreset);
            enemy.Factory.AddBehavior(Attacking.Preset);
            enemy.Factory.AddBehavior(Displaceable.DefaultPreset);
            enemy.Factory.AddBehavior(Moving.Preset);
            enemy.Factory.AddBehavior(Pushable.Preset);


            Acting.Config enemyActingConf = new Acting.Config(Algos.EnemyAlgo);

            enemy.Factory.AddBehavior(Acting.Preset(enemyActingConf));


            var attackAction = Action.CreateBehavioral<Attacking>();
            var moveAction = Action.CreateBehavioral<Moving>();
            CompositeAction attackMoveAction = new CompositeAction(
                new Action[] { attackAction, moveAction }
            );

            Step[] stepData =
            {
                new Step { action = null },
                new Step { action = attackMoveAction, movs = Movs.Basic }
            };

            var sequenceConfig = new Sequential.Config(stepData);

            enemy.Factory.AddBehavior(Sequential.Preset(sequenceConfig));
            System.Console.WriteLine("Set up enemy.Factory");

            Entity player = player.Factory.Instantiate();
            System.Console.WriteLine("Instantiated Player");

            Entity enemy = enemy.Factory.Instantiate();
            System.Console.WriteLine("Instantiated Enemy");

            enemy.Init(new IntVector2(1, 2), world);
            world.State.AddEntity(enemy);
            world.Grid.Reset(enemy, enemy.Pos);
            System.Console.WriteLine("Enemy set in world");

            player.Init(new IntVector2(1, 1), world);
            world.State.AddPlayer(player);
            world.Grid.Reset(player, player.Pos);
            System.Console.WriteLine("Player set in world");

            var playerNextAction = attackMoveAction.Copy();
            playerNextAction.direction = new IntVector2(0, 1);
            player.Behaviors.Get<Acting>().NextAction = playerNextAction;
            System.Console.WriteLine("Set player action");
            System.Console.WriteLine("\n ------ Modifier Demo ------ \n");

            var mod = Modifier.Create(Attack.Path, new Attack { damage = 1 });//new StatModifier(Attack.Path, new Attack { damage = 1 });
            var attack = player.Stats.Get(Attack.Path);
            System.Console.WriteLine("Attack damage:{0}", attack.damage);
            System.Console.WriteLine("Attack pierce:{0}", attack.pierce);
            System.Console.WriteLine("Adding modifier");
            mod.AddSelf(player.Stats);
            attack = player.Stats.Get(Attack.Path);
            System.Console.WriteLine("Attack damage:{0}", attack.damage);
            System.Console.WriteLine("Attack pierce:{0}", attack.pierce);
            System.Console.WriteLine("Removing modifier");
            mod.RemoveSelf(player.Stats);
            attack = player.Stats.Get(Attack.Path);
            System.Console.WriteLine("Attack damage:{0}", attack.damage);
            System.Console.WriteLine("Attack pierce:{0}", attack.pierce);

            var mod2 = Modifier.Create(Attack.Path, new EvHandler<StatEvent<Attack>>(
                (StatEvent<Attack> eve) =>
                {
                    System.Console.WriteLine("Called handler");
                    eve.file.damage *= 3;
                })
            );
            System.Console.WriteLine("Adding modifier");
            mod2.AddSelf(player.Stats);
            attack = player.Stats.Get(Attack.Path);
            System.Console.WriteLine("Attack damage:{0}", attack.damage);
            System.Console.WriteLine("Attack pierce:{0}", attack.pierce);
            System.Console.WriteLine("Removing modifier");
            player.Stats.RemoveChainModifier(mod2);
            attack = player.Stats.Get(Attack.Path);
            System.Console.WriteLine("Attack damage:{0}", attack.damage);
            System.Console.WriteLine("Attack pierce:{0}", attack.pierce);

            System.Console.WriteLine("\n ------ Pools Demo ------ \n");

            PoolItem[] items = new[]
            {
                new PoolItem(0, 1),
                new PoolItem(1, 1),
                new PoolItem(2, 1),
                new PoolItem(3, 1),
                new PoolItem(4, 10)
            };

            var pool = Pool.CreateNormal<Hopper.Core.Items.IItem>();

            pool.AddRange("zone1/weapons", items.Take(2));
            pool.AddRange("zone1/trinkets", items.Skip(2).Take(2));
            pool.Add("zone1/trinkets", items[4]);

            var poolCopy = pool.Copy();

            var it1 = pool.GetNextItem("zone1/weapons");
            System.Console.WriteLine($"Item Id = {it1.id}, q = {it1.quantity}");
            // var it2 = pool.GetNextItem("zone1/weapons");
            // System.Console.WriteLine($"Item Id = {it2.id}, q = {it2.quantity}");
            var it3 = poolCopy.GetNextItem("zone1/weapons");
            System.Console.WriteLine($"Item Id = {it3.id}, q = {it3.quantity}");
            var it4 = poolCopy.GetNextItem("zone1/weapons");
            System.Console.WriteLine($"Item Id = {it4.id}, q = {it4.quantity}");


            System.Console.WriteLine("\n ------ TargetProvider Demo ------ \n");
            var pattern = new Pattern
            (
                new Piece
                {
                    pos = new IntVector2(1, 0),
                    dir = new IntVector2(1, 0),
                    reach = null
                },
                new Piece
                {
                    pos = new IntVector2(2, 0),
                    dir = new IntVector2(1, 0),
                    reach = new List<int>()
                }
            );
            var weapon = TargetProvider.CreateAtk(pattern, Handlers.GeneralChain);
            System.Console.WriteLine($"Enemy is at {enemy.Pos}");
            var atk = player.Stats.Get(Attack.Path);
            var targets = weapon.GetTargets(player, playerNextAction.direction, atk);
            foreach (var t in targets)
            {
                System.Console.WriteLine($"Entity at {t.targetEntity.Pos} has been considered a potential target");
            }

            System.Console.WriteLine("\n ------ Inventory Demo ------ \n");
            var inventory = (Inventory)player.Inventory;

            var slot = new SizedSlot<CircularItemContainer, Hopper.Core.Items.IItem>("stuff2", 1);

            inventory.AddContainer(slot);

            var tinker = Tinker<TinkerData>.SingleHandlered<Attacking.Event>(
                Attacking.Check,
                e => System.Console.WriteLine("Hello from tinker applied by item")
            );
            var item = new TinkerItem(new ItemMetadata("Test_Tinker_Item"), tinker, slot);

            // inventory.Equip(item) ->         // the starting point
            // item.BeEquipped(entity) ->       // it's interface method
            // tinker.Tink(entity)  ->          // adds the handlers
            // entity.Tinkers.SetStore()        // creates the tinker data
            inventory.Equip(item);

            world.Loop();
            System.Console.WriteLine("Looped");

            // creates excess as the size is 1
            inventory.Equip(item);
            // inventory.DropExcess() ->
            // item.BeUnequipped()    ->
            // tinker.Untink() -> entity.Tinkers.RemoveStore()
            // + world.CreateDroppedItem(id, pos)
            inventory.DropExcess();

            var entities = world.Grid.GetCellAt(player.Pos).m_entities;
            System.Console.WriteLine($"There's {entities.Count} entities in the cell where the player is standing");

            System.Console.WriteLine("\n ------ History Demo ------ \n");
            var enemyUpdates = enemy.History.Updates;
            var playerUpdates = player.History.Updates;
            foreach (var updateInfo in enemyUpdates)
            {
                System.Console.WriteLine($"Enemy did {System.Enum.GetName(typeof(UpdateCode), updateInfo.updateCode)}. Position after: {updateInfo.stateAfter.pos}");
            }
            foreach (var updateInfo in playerUpdates)
            {
                System.Console.WriteLine($"Player did {System.Enum.GetName(typeof(UpdateCode), updateInfo.updateCode)}. Position after: {updateInfo.stateAfter.pos}");
            }

            System.Console.WriteLine("\n ------ Equip on Displace Demo ------ \n");
            // we don't need the entity for the next test
            enemy.Die();

            var playerMoveAction = moveAction.Copy();
            playerMoveAction.direction = IntVector2.Down;
            player.Behaviors.Get<Acting>().NextAction = playerMoveAction;

            var slot2 = new SizedSlot<CircularItemContainer, Hopper.Core.Items.IItem>("stuff3", 1);
            inventory.AddContainer(slot2);

            var chainDefs2 = new IChainDef[0];
            var tinker2 = new Tinker<TinkerData>(chainDefs2);
            var item2 = new TinkerItem(new ItemMetadata("Test_Tinker_Item_2"), tinker2, slot2);

            var droppedItem2 = world.SpawnDroppedItem(item2, player.Pos + IntVector2.Down);

            /*
            this only works because we did
            `player.Factory.AddRetoucher(Core.Retouchers.Equip.OnDisplace);`
            up top.
            */

            System.Console.WriteLine($"Player's position before moving: {player.Pos}");
            world.Loop();
            System.Console.WriteLine($"Player's new position: {player.Pos}");
            System.Console.WriteLine($"There's {world.Grid.GetCellAt(player.Pos).m_entities.Count} entities in the cell where the player is standing");


            System.Console.WriteLine("\n ------ Tinker static reference Demo ------ \n");

            var tinker3 = TestTinkerStuff.tinker; // see the definition below
            tinker3.Tink(player);
            player.Behaviors.Get<Acting>().NextAction = playerMoveAction;
            world.Loop();
            tinker3.Untink(player);


            System.Console.WriteLine("\n ------ Status Demo ------ \n");

            // this has to be rethought for sure
            var status = TestStatusStuff.status;
            status.TryApply(
                player,
                new StatusData(),
                new StatusFile { power = 1, amount = 2 }
            );
            player.Behaviors.Get<Acting>().NextAction = playerMoveAction;
            world.Loop();
            player.Behaviors.Get<Acting>().NextAction = playerMoveAction;
            world.Loop();
            player.Behaviors.Get<Acting>().NextAction = playerMoveAction;
            world.Loop();

            System.Console.WriteLine("\n ------ Spider Demo ------ \n");
            player.ResetPosInGrid(new IntVector2(4, 4));
            var spider = world.SpawnEntity(Spider.Factory, new IntVector2(3, 3));
            world.Loop();
            System.Console.WriteLine($"Tinker is applied? {BindStatuses.NoMove.IsApplied(player)}");
            System.Console.WriteLine("Looped");
            System.Console.WriteLine($"Player's new position: {player.Pos}");
            System.Console.WriteLine($"Spider's new position: {spider.Pos}");

            player.Behaviors.Get<Acting>().NextAction = attackAction;
            world.Loop();
            System.Console.WriteLine("Looped");
            System.Console.WriteLine($"Player's new position: {player.Pos}");
            System.Console.WriteLine($"Spider's new position: {spider.Pos}");

            player.Behaviors.Get<Displaceable>().Activate(new IntVector2(-1, -1), new Move());
            world.Loop();
            System.Console.WriteLine("Looped");
            System.Console.WriteLine($"Player's new position: {player.Pos}");
            System.Console.WriteLine($"Spider's new position: {spider.Pos}");

            System.Console.WriteLine("Killing spider");
            spider.Die();
            world.Loop();
            System.Console.WriteLine($"Tinker is applied? {BindStatuses.NoMove.IsApplied(player)}");

            System.Console.WriteLine("\n ------ Input Demo ------ \n");
            // we also have the possibilty to add behaviors dynamically.
            var Input.Factory = new BehaviorFactory<Controllable>();
            var input = (Controllable)Input.Factory.Instantiate(player,
                new Controllable.Config { defaultAction = attackMoveAction });
            player.Behaviors.Add(typeof(Controllable), input);

            var outputAction0 = input.ConvertVectorToAction(IntVector2.Up);
            System.Console.WriteLine($"Fed Up. Output: {outputAction0.direction}");
            var outputAction1 = input.ConvertInputToAction(InputMapping.Special_0);
            System.Console.WriteLine($"Fed Special_0. Output is null?: {outputAction1 == null}");
        }
Пример #36
0
 public void AddHandler(Action<FileFound> handler)
 {
     onFound += handler;
 }
Пример #37
0
 public FakeTemplatePolicy()
 {
     Filter = new CompositePredicate <ITemplate>();
     Action = new CompositeAction <ITemplate>();
 }
 public void ResetComposerConfiguration()
 {
     _configurations = new CompositeAction<TemplateComposer<IRazorTemplate>>();
 }
 public void Register(Action<TemplateComposer<IRazorTemplate>> alteration)
 {
     _configurations += alteration;
 }
Пример #40
0
 public void Register(Action <TemplateComposer <ITemplate> > alteration)
 {
     _configurations += alteration;
 }
Пример #41
0
 public FakeTemplateBinder()
 {
     Filter = new CompositePredicate <IBindRequest>();
     Action = new CompositeAction <IBindRequest>();
 }
Пример #42
0
 internal ActionBuilder(TAction action, CompositeAction executableAction, string name)
 {
     Action            = action ?? throw new ArgumentNullException(nameof(action));
     _executableAction = executableAction;
     Name = name;
 }
Пример #43
0
 public DefaultHandlerSource ConfigurePool(Action<TypePool> cfg)
 {
     _actions += cfg;
     return this;
 }