public void ExecuteActionWithGlobalTrigger_UnitDealsDamageToAnotherUnitWithDamage_EventsWasFiredOnBothActions() { EventManager gem = new EventManager(); ActionManager actman = new ActionManager(gem); Unit A = new Unit(); Unit B = new Unit(); A.ActionManager = actman; B.ActionManager = actman; int dmg = int.MaxValue; int actualTimesFired = 0; Trigger T = new Trigger<UnitTakesDamagePostEvent>(_ => actualTimesFired++); EntityXmasAction ga1 = new DamageUnitTargetAction(B, dmg); EntityXmasAction ga2 = new DamageUnitTargetAction(A, dmg); gem.Register(T); gem.AddEntity(A); gem.AddEntity(B); A.QueueAction(ga1); B.QueueAction(ga2); actman.ExecuteActions(); int expectedTimeFired = 2; Assert.AreEqual(expectedTimeFired, actualTimesFired); }
internal void PopulateWorld(ActionManager actman) { foreach (Func<XmasAction> buildaction in buildactions.ToArray()) { actman.QueueAction(buildaction()); } }
public void AddTrigger_triggerIsAddedToUnitAfterItIsAddedToManagger_EventFired() { EventManager gem = new EventManager(); ActionManager actman = new ActionManager(gem); Unit A = new Unit(); Unit B = new Unit(); A.ActionManager = actman; B.ActionManager = actman; int dmg = int.MaxValue; bool eventFired = false; Trigger T = new Trigger<UnitTakesDamagePostEvent>(_ => eventFired = true); EntityXmasAction ga1 = new DamageUnitTargetAction(B, dmg); gem.AddEntity(B); B.Register(T); A.QueueAction(ga1); actman.ExecuteActions(); Assert.IsTrue(eventFired); }
//[Test] public void SingleUpdate_RecievedGetAllPercepts_PickUpPerceptsAndReturnThemThroughWriter() { ActionManager manager = new ActionManager(new EventManager()); TileWorldBuilder worldBuilder = new TileWorldBuilder(new Size(4, 4)); Agent agent = new Agent("testagent"); worldBuilder.AddEntity(() => agent, new TileSpawnInformation(new TilePosition(new Point(0, 0)))); XmasFactory fact = new XmasFactory(manager); TileWorld world = (TileWorld)worldBuilder.Build(); agent.ActionManager = manager; agent.World = world; agent.Factory = fact; Thread thread1 = new Thread(test2); thread1.Name = "TCP Server"; thread1.Start(); while (lock1) { } TcpClient client = new TcpClient("localhost", 6661); Stream stream = client.GetStream(); StringBuilder sb = new StringBuilder(); EisConversionTool ctool = new EisConversionTool(); ctool.AddConverter(new GetAllPerceptsActionConverter()); ctool.AddConverter(new EISPerceptCollectionSerializer()); ctool.AddConverter(new EisTileVisionSerializer()); ctool.AddConverter(new EISSingleNumeralSerializer()); IILActionParser parser = new IILActionParser(); XmlReaderSettings set = new XmlReaderSettings(); set.ConformanceLevel = ConformanceLevel.Fragment; XmlReader xreader = XmlReader.Create(new StreamReader(stream, Encoding.UTF8)); XmlWriterSettings wset = new XmlWriterSettings(); wset.OmitXmlDeclaration = true; XmlWriter xwriter = XmlWriter.Create(sb, wset); controller = new EISAgentController(agent, client, manager, new PacketStream(stream), new StreamReader(stream), new StreamWriter(stream), ctool, parser); Thread thread2 = new Thread(test1); thread2.Name = "Controller"; thread2.Start(); while (manager.ExecuteActions() == 0) ; string returned = null; do { try { returned = sb.ToString(); } catch { } } while (String.IsNullOrEmpty(returned)); }
/// <summary> /// Builds a full world along with all entities added to it /// </summary> /// <param name="actman">The action manager of the engine</param> /// <returns>The fully built world</returns> public XmasWorld Build(ActionManager actman) { foreach (XmasAction buildaction in buildactions.ToArray()) { actman.QueueAction(buildaction); } return ConstructWorld (); }
/// <summary> /// Instantiates a XmasTimer /// </summary> /// <param name="actman">The ActionManager of the engine</param> /// <param name="owner">The XmasAction that owns the timer</param> /// <param name="action">The action that is queued onto the engine when the timer expires</param> public XmasTimer(ActionManager actman, XmasAction owner, Action action) { this.owner = owner; this.actman = actman; this.action = action; timer.AutoReset = false; timer.Elapsed += timer_Elapsed; }
public EISAgentController(Agent agent, TcpClient client, ActionManager actman, PacketStream packetstream, StreamReader sreader, StreamWriter swriter, EisConversionTool tool, IILActionParser actionparser) : base(agent) { this.client = client; this.packetstream = packetstream; this.sreader = sreader; this.swriter = swriter; PerceptsRecieved += EISAgentController_PerceptsRecieved; this.tool = tool; this.actionparser = actionparser; this.actman = actman; }
public XmasModel(XmasWorld world, ActionManager actman, EventManager evtman, XmasFactory factory) { World = world; ActionManager = actman; EventManager = evtman; Factory = factory; world.EventManager = evtman; EventManager.Register(new Trigger<EngineCloseEvent>(evtman_EngineClose)); ActionManager.ActionQueuing += actman_ActionQueuing; ActionManager.ActionQueued += actman_ActionQueued; foreach (var action in ActionManager.QueuedActions) { this.AddActor(action); } }
/// <summary> /// Instantiates a XmasFactory /// </summary> /// <param name="actman">The action manager used by the engine</param> public XmasFactory(ActionManager actman) { this.actman = actman; }
/// <summary> /// Constructs the factory used inside the engine /// </summary> /// <param name="actman">The action manager of the engine</param> /// <returns></returns> protected virtual XmasFactory ConstructFactory(ActionManager actman) { return new XmasFactory(actman); }
public void RemoveTrigger_triggerIsRemovedFromUnit_NoEventFired() { EventManager gem = new EventManager(); ActionManager actman = new ActionManager(gem); Unit A = new Unit(); Unit B = new Unit(); A.ActionManager = actman; B.ActionManager = actman; int dmg = int.MaxValue; bool eventFired = false; Trigger T = new Trigger<UnitTakesDamagePostEvent>(_ => eventFired = true); EntityXmasAction ga1 = new DamageUnitTargetAction(B, dmg); B.Register(T); gem.AddEntity(B); B.Deregister(T); A.QueueAction(ga1); Assert.IsFalse(eventFired); }
public void ExecuteActionWithSpecificTargetEvent_UnitDealsDamageToAnotherUnit_TheOtherUnitTakesDamage() { EventManager gem = new EventManager(); ActionManager actman = new ActionManager(gem); Unit expectedDealer = new Unit(); Unit expectedTaker = new Unit(); expectedDealer.ActionManager = actman; expectedTaker.ActionManager = actman; int expectedDmg = 10; //ignore initialization values Unit actualDealer = null; Unit actualTaker = null; int actualDmg = new int(); Trigger t = new Trigger<UnitTakesDamagePostEvent>(e => { actualDealer = e.Source; actualTaker = e.Target; actualDmg = e.Damage; }); DamageUnitTargetAction ga = new DamageUnitTargetAction(expectedTaker, expectedDmg); expectedTaker.Register(t); gem.AddEntity(expectedTaker); expectedDealer.QueueAction(ga); actman.ExecuteActions(); Assert.AreEqual(expectedDealer, actualDealer); Assert.AreEqual(expectedTaker, actualTaker); Assert.AreEqual(expectedDmg, actualDmg); }
public void ExecuteActionWithSpecificTargetEvent_UnitDealsDamageToAnotherUnitWithDamagePrevetionImplemented_TheTargetUnitTakesNoDamage() { EventManager gem = new EventManager(); ActionManager actman = new ActionManager(gem); Unit expectedDealer = new Unit(); Unit expectedTaker = new Unit(); expectedDealer.ActionManager = actman; expectedTaker.ActionManager = actman; int dmg = 10; int prevent = 10; int expectedDmg = 10; //ignore initialization values Unit actualDealer = null; Unit actualTaker = null; int actualDmg = new int(); Trigger preT = new Trigger<UnitTakesDamagePreEvent>(e => e.ModDmgPreMultiplier(-prevent)); Trigger postT = new Trigger<UnitTakesDamagePostEvent>(e => { actualDealer = e.Source; actualTaker = e.Target; actualDmg = e.Damage; }); EntityXmasAction ga = new DamageUnitTargetAction(expectedTaker, dmg); expectedTaker.Register(preT); expectedTaker.Register(postT); gem.AddEntity(expectedTaker); expectedDealer.QueueAction(ga); actman.ExecuteActions(); Assert.AreEqual(expectedDealer, actualDealer); Assert.AreEqual(expectedTaker, actualTaker); Assert.AreEqual(expectedDmg, actualDmg); }