コード例 #1
0
        public void Equip_EquipItemEventFails_DoesNotEquip()
        {
            var item = GiveHelmTestItem(3);

            eventSystem.Try(EventType.EquipItem, entity, Arg.Any <object>()).Returns(false);

            var result = equipmentSystem.Equip(entity, item);

            result.Should().BeFalse();

            var expected = new EquipmentMappingList {
            };

            entity.Get <Equipped>().EquippedItems.Should().BeEquivalentTo(expected);
        }
コード例 #2
0
ファイル: TimeSystem.cs プロジェクト: fortyCakes/data-rogue
        private void TickActor(IEntity entity)
        {
            var actor = entity.Get <Actor>();

            var behaviours = GetBehaviours(entity);

            foreach (IBehaviour behaviour in behaviours.OrderByDescending(b => b.BehaviourPriority))
            {
                if (_systemContainer.Random.PercentageChance(behaviour.BehaviourChance))
                {
                    var chosenAction = behaviour.ChooseAction(entity);

                    if (chosenAction != null)
                    {
                        if (chosenAction.Action == ActionType.WaitForInput)
                        {
                            WaitingForInput = true;
                            break;
                        }

                        _eventSystem.Try(EventType.Action, entity, chosenAction);
                    }

                    if (actor.NextTick > CurrentTime)
                    {
                        break;
                    }
                }
            }

            if (actor.NextTick <= CurrentTime)
            {
                actor.NextTick = CurrentTime + actor.Speed;
            }
        }
コード例 #3
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);
        }
コード例 #4
0
        public static decimal GetStat(this IEventSystem eventSystem, IEntity sender, string stat)
        {
            GetStatEventData data = new GetStatEventData {
                Stat = stat
            };

            eventSystem.Try(EventType.GetStat, sender, data);

            return(data.Value);
        }
コード例 #5
0
        public bool Apply(EventType type, IEntity sender, object eventData)
        {
            var killer = (eventData as DeathEventData).Killer;

            var ok = EventSystem.Try(EventType.GainXP, killer, new GainXPEventData {
                Amount = 1
            });

            return(true);
        }
コード例 #6
0
        public bool Apply(EventType type, IEntity sender, object eventData)
        {
            var vector = (Vector)eventData;

            positionSystem.Move(sender, vector);
            _animatedMovementSystem.StartAnimatedMovement(sender, vector, 500);

            eventRuleSystem.Try(EventType.SpendTime, sender, new SpendTimeEventData()
            {
                Ticks = sender.Get <Actor>().Speed
            });

            return(true);
        }
コード例 #7
0
        public bool Attack(IEntity attacker, IEntity defender, string attackClass = null, int?attackDamage = null, string[] attackTags = null, bool spendTime = true, IEntity weapon = null)
        {
            var attack = new AttackEventData
            {
                Attacker    = attacker,
                Defender    = defender,
                AttackClass = attackClass,
                Damage      = attackDamage,
                Tags        = attackTags,
                SpendTime   = spendTime,
                Weapon      = weapon
            };

            return(_eventRuleSystem.Try(EventType.Attack, attacker, attack));
        }
コード例 #8
0
ファイル: ItemSystem.cs プロジェクト: fortyCakes/data-rogue
        private void ApplyConsumption(IEntity item)
        {
            if (item.Has <Consumable>())
            {
                var consumable = item.Get <Consumable>();

                consumable.Uses.Subtract(1);

                if (consumable.Uses.Current == 0)
                {
                    if (eventSystem.Try(EventType.ConsumableRunOut, item, null))
                    {
                        DestroyItem(item);
                    }
                }
            }
        }
コード例 #9
0
        public void Use_Consumable_NoUsesRemaining_DestroysItem()
        {
            var item = GetTestItem();

            itemSystem.MoveToInventory(item, inventory);

            item.Get <Item>().UseScript = "TestScript";
            item.Components.Add(new Consumable {
                Uses = new Counter {
                    Current = 1, Max = 2
                }
            });
            eventSystem.Try(EventType.ConsumableRunOut, item, Arg.Any <object>()).Returns(true);

            itemSystem.Use(entity, item);

            inventory.Contents.Should().BeEmpty();
        }
コード例 #10
0
        public bool Apply(EventType type, IEntity sender, object eventData)
        {
            var vector           = (Vector)eventData;
            var targetCoordinate = _positionSystem.CoordinateOf(sender);

            var entitiesAtPosition = _positionSystem.EntitiesAt(targetCoordinate);

            if (entitiesAtPosition.Any(IsAutoPortal))
            {
                var portal = entitiesAtPosition.Single(e => IsAutoPortal(e));

                var action = new ActionEventData {
                    Action = ActionType.Enter, Parameters = $"{StairDirection.Down}", Speed = null, KeyPress = null
                };

                if (_eventSystem.Try(EventType.Action, sender, action))
                {
                }

                return(false);
            }

            return(true);
        }