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); }
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; } }
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); }
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); }
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); }
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); }
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)); }
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); } } } }
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(); }
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); }