/// <summary> /// Default Constructor for the Type Mapper. /// </summary> /// <param name="item">Related Engine Item</param> /// <param name="property">Related Engine Property</param> public CarrierState(Item item, CarrierProperty property) : base(item, property) { // Bind Strength to the Item Strength CarrierStrength = property.CarrierStrength; property.OnCarrierStrengthChanged += (i, v) => { CarrierStrength = v; }; }
private void InitItem(Vector2 carrier1, Vector2 portable1, Vector2?carrier2, Vector2?portable2) { Item1 = new DebugCarrierItem(carrier1); Moving1 = Item1.GetProperty <WalkingProperty>(); Collidable1 = Item1.GetProperty <CollidableProperty>(); Carrier1 = Item1.GetProperty <CarrierProperty>(); Item3 = new DebugPortableItem(portable1); Moving3 = Item3.GetProperty <WalkingProperty>(); Collidable3 = Item3.GetProperty <CollidableProperty>(); Portable3 = Item3.GetProperty <PortableProperty>(); if (carrier2.HasValue) { Item2 = new DebugCarrierItem(carrier2.Value); Moving2 = Item2.GetProperty <WalkingProperty>(); Collidable2 = Item2.GetProperty <CollidableProperty>(); Carrier2 = Item2.GetProperty <CarrierProperty>(); } if (portable2.HasValue) { Item4 = new DebugPortableItem(portable2.Value); Moving4 = Item4.GetProperty <WalkingProperty>(); Collidable4 = Item4.GetProperty <CollidableProperty>(); Portable4 = Item4.GetProperty <PortableProperty>(); } }
public DebugCarrierItem(ITypeResolver resolver, Vector2 pos) : base(resolver, pos) { carrier = new CarrierProperty(this, 10f); AddProperty(carrier); }
private void portable_OnLostCarrierItem(CarrierProperty item) { // Entfernt den Träger int id = item.Item.Id; if (!items.ContainsKey(id)) { throw new IndexOutOfRangeException("Item does not exist"); } clusterUnits.Remove(items[id]); Recalc(); }
private void portable_OnNewCarrierItem(CarrierProperty item) { // Fügt den Träger hinzu int id = item.Item.Id; if (!items.ContainsKey(id)) { throw new IndexOutOfRangeException("Item does not exist"); } clusterUnits.Add(items[id]); Recalc(); }
public PhysicsUnit(Item item, Dictionary<int, PhysicsUnit> items) { this.item = item; this.items = items; moving = item.GetProperty<WalkingProperty>(); collidable = item.GetProperty<CollidableProperty>(); carrier = item.GetProperty<CarrierProperty>(); portable = item.GetProperty<PortableProperty>(); map = item.Engine.Map; mapSize = map.GetSize(); // Attach Item Stuff item.CellChanged += item_CellChanged; // Attach Moving Stuff if (moving != null) { moving.OnMaximumMoveSpeedChanged += moving_OnMaximumMoveSpeedChanged; moving.OnMoveDirectionChanged += moving_OnMoveDirectionChanged; moving.OnMoveSpeedChanged += moving_OnMoveSpeedChanged; moving.MoveMalus = 1; } // Attach Collision Stuff if (collidable != null) { collidable.OnCollisionMassChanged += collidable_OnCollisionMassChanged; collidable.OnCollisionFixedChanged += collidable_OnCollisionFixedChanged; } // Attach Carrier Stuff if (carrier != null) { carrier.OnCarrierLoadChanged += carrier_OnCarrierLoadChanged; carrier.OnCarrierStrengthChanged += carrier_OnCarrierStrengthChanged; } // Attach Portable Stuff if (portable != null) { portable.OnPortableWeightChanged += portable_OnPortableMassChanged; portable.OnNewCarrierItem += portable_OnNewCarrierItem; portable.OnLostCarrierItem += portable_OnLostCarrierItem; clusterUnits = new HashSet<PhysicsUnit>(); } Recalc(); }
public PhysicsUnit(Item item, Dictionary <int, PhysicsUnit> items) { this.item = item; this.items = items; moving = item.GetProperty <WalkingProperty>(); collidable = item.GetProperty <CollidableProperty>(); carrier = item.GetProperty <CarrierProperty>(); portable = item.GetProperty <PortableProperty>(); map = item.Engine.Map; mapSize = map.GetSize(); // Attach Item Stuff item.CellChanged += item_CellChanged; // Attach Moving Stuff if (moving != null) { moving.OnMaximumMoveSpeedChanged += moving_OnMaximumMoveSpeedChanged; moving.OnMoveDirectionChanged += moving_OnMoveDirectionChanged; moving.OnMoveSpeedChanged += moving_OnMoveSpeedChanged; moving.MoveMalus = 1; } // Attach Collision Stuff if (collidable != null) { collidable.OnCollisionMassChanged += collidable_OnCollisionMassChanged; collidable.OnCollisionFixedChanged += collidable_OnCollisionFixedChanged; } // Attach Carrier Stuff if (carrier != null) { carrier.OnCarrierLoadChanged += carrier_OnCarrierLoadChanged; carrier.OnCarrierStrengthChanged += carrier_OnCarrierStrengthChanged; } // Attach Portable Stuff if (portable != null) { portable.OnPortableWeightChanged += portable_OnPortableMassChanged; portable.OnNewCarrierItem += portable_OnNewCarrierItem; portable.OnLostCarrierItem += portable_OnLostCarrierItem; clusterUnits = new HashSet <PhysicsUnit>(); } Recalc(); }
public void CleanupEngine() { Item1 = null; Moving1 = null; Collidable1 = null; Carrier1 = null; Item2 = null; Moving2 = null; Collidable2 = null; Carrier2 = null; Item3 = null; Moving3 = null; Collidable3 = null; Portable3 = null; Item4 = null; Moving4 = null; Collidable4 = null; Portable4 = null; Map = null; Engine = null; }
public void CheckPortableItemAddedAndRemoved() { InitItem(new Vector2(50, 100), new Vector2(150, 50), new Vector2(150, 150), null); InitFlat(true); Portable3.PortableRadius = 1000f; int triggeredNew = 0; int triggeredLost = 0; CarrierProperty expected = null; bool result = false; Portable3.OnNewCarrierItem += (v) => { Assert.AreEqual(expected, v); triggeredNew++; }; Portable3.OnLostCarrierItem += (v) => { Assert.AreEqual(expected, v); triggeredLost++; }; // Item1 aufnehmen expected = Carrier1; result = Carrier1.Carry(Portable3); Assert.AreEqual(true, result); Assert.AreEqual(1, triggeredNew); Assert.AreEqual(0, triggeredLost); triggeredNew = 0; triggeredLost = 0; Assert.AreEqual(1, Portable3.CarrierItems.Count); Assert.AreEqual(true, Portable3.CarrierItems.Contains(Carrier1)); Assert.AreEqual(false, Portable3.CarrierItems.Contains(Carrier2)); // Item1 fallen lassen expected = Carrier1; Carrier1.Drop(); Assert.AreEqual(0, triggeredNew); Assert.AreEqual(1, triggeredLost); triggeredNew = 0; triggeredLost = 0; Assert.AreEqual(0, Portable3.CarrierItems.Count); Assert.AreEqual(false, Portable3.CarrierItems.Contains(Carrier1)); Assert.AreEqual(false, Portable3.CarrierItems.Contains(Carrier2)); // Item2 aufnehmen expected = Carrier2; result = Carrier2.Carry(Portable3); Assert.AreEqual(true, result); Assert.AreEqual(1, triggeredNew); Assert.AreEqual(0, triggeredLost); triggeredNew = 0; triggeredLost = 0; Assert.AreEqual(1, Portable3.CarrierItems.Count); Assert.AreEqual(false, Portable3.CarrierItems.Contains(Carrier1)); Assert.AreEqual(true, Portable3.CarrierItems.Contains(Carrier2)); // Item1 aufnehmen expected = Carrier1; result = Carrier1.Carry(Portable3); Assert.AreEqual(true, result); Assert.AreEqual(1, triggeredNew); Assert.AreEqual(0, triggeredLost); triggeredNew = 0; triggeredLost = 0; Assert.AreEqual(2, Portable3.CarrierItems.Count); Assert.AreEqual(true, Portable3.CarrierItems.Contains(Carrier1)); Assert.AreEqual(true, Portable3.CarrierItems.Contains(Carrier2)); // Item2 fallen lassen expected = Carrier2; Carrier2.Drop(); Assert.AreEqual(0, triggeredNew); Assert.AreEqual(1, triggeredLost); triggeredNew = 0; triggeredLost = 0; Assert.AreEqual(1, Portable3.CarrierItems.Count); Assert.AreEqual(true, Portable3.CarrierItems.Contains(Carrier1)); Assert.AreEqual(false, Portable3.CarrierItems.Contains(Carrier2)); }
private void portable_OnNewCarrierItem(CarrierProperty item) { // Fügt den Träger hinzu int id = item.Item.Id; if (!items.ContainsKey(id)) throw new IndexOutOfRangeException("Item does not exist"); clusterUnits.Add(items[id]); Recalc(); }
private void portable_OnLostCarrierItem(CarrierProperty item) { // Entfernt den Träger int id = item.Item.Id; if (!items.ContainsKey(id)) throw new IndexOutOfRangeException("Item does not exist"); clusterUnits.Remove(items[id]); Recalc(); }
/// <summary> /// Default Constructor for the Type Mapper. /// </summary> /// <param name="faction">Faction</param> /// <param name="item">Item</param> /// <param name="interop">UnitInterop</param> public InteractionInterop(Faction faction, FactionItem item, UnitInterop interop) : base(faction, item, interop) { #region Collector sugar = item.GetProperty <SugarCollectorProperty>(); if (sugar == null) { throw new ArgumentException("Item does not contain SugarCollector"); } apple = item.GetProperty <AppleCollectorProperty>(); if (apple == null) { throw new ArgumentException("Item does not contain AppleCollector"); } #endregion #region Carrier carrier = item.GetProperty <CarrierProperty>(); if (carrier == null) { throw new ArgumentException("Item does not contain CarrierProperty"); } #endregion #region Attackable attackable = item.GetProperty <AttackableProperty>(); if (attackable == null) { throw new ArgumentException("Item does not contain AttackableProperty"); } attackable.OnKill += i => { if (OnKill != null) { OnKill(); } }; attackable.OnAttackerHit += (i, value) => { if (OnHit != null) { OnHit(value); } }; attackable.OnNewAttackerItem += i => { var info = Item.GetItemInfo(i.Item); if (!attackerItems.Contains(info)) { attackerItems.Add(info); } }; attackable.OnLostAttackerItem += i => { var info = Item.GetItemInfo(i.Item); if (attackerItems.Contains(info)) { attackerItems.Remove(info); } }; #endregion #region Attacker attacker = item.GetProperty <AttackerProperty>(); if (attacker == null) { throw new ArgumentException("Item does not contain AttackerProperty"); } #endregion // Automatic Resource Transfer on Anthill Collision. var collidable = item.GetProperty <CollidableProperty>(); if (collidable == null) { throw new ArgumentException("Item does not contain AttackerProperty"); } collidable.OnCollision += (i, value) => { // Ignore if it's not a Anthill if (!(value is AnthillItem)) { return; } var anthill = value as AnthillItem; // Ignore if it's not the right faction if (anthill.Faction != item.Faction) { return; } // Transfer all collectables Give(anthill); }; }
/// <summary> /// Internal Call to remove a Carrier. /// </summary> /// <param name="carrier">Lost Carrier</param> internal void RemoveCarrier(CarrierProperty carrier) { if (!carrierItems.Contains(carrier)) return; carrierItems.Remove(carrier); if (OnLostCarrierItem != null) OnLostCarrierItem(carrier); }
/// <summary> /// Internal Call to add another Carrier to the List. /// </summary> /// <param name="carrier">New Item</param> internal void AddCarrier(CarrierProperty carrier) { if (carrierItems.Contains(carrier)) return; carrierItems.Add(carrier); if (OnNewCarrierItem != null) OnNewCarrierItem(carrier); }
/// <summary> /// Registers Ants /// </summary> /// <param name="typeMapper">Type Mapper</param> /// <param name="settings">Settings</param> private void RegisterAnt(ITypeMapper typeMapper, KeyValueStore settings) { // Ant Item settings.Set <AntItem>("ZickZackAngle", 10, "Correction Angle after Sprint"); settings.Set <AntItem>("ZickZackRange", 30f, "Distance to go every Sprint"); settings.Set <AntItem>("RotationSpeed", 20, "Maximum Rotation Angle per Round"); settings.Set <AntItem>("DropSugar", false, "Will an Ant leave a small Sugar on Drop"); settings.Set <AntItem>("MarkerDelay", 10, "Time in Rounds between Marker-Drops"); typeMapper.RegisterItem <AntItem, AntState, AntInfo>(this, "Ant"); // Walking settings.Set <AntItem>("MaxSpeed", 1f, "Maximum Speed of an Ant"); typeMapper.AttachItemProperty <AntItem, WalkingProperty>(this, "Ant Walking", (i) => { WalkingProperty property = new WalkingProperty(i); // Set Maximum Speed based on the current Settings // TODO: Check for Castes property.MaximumSpeed = i.Settings.GetFloat <AntItem>("MaxSpeed").Value; // Bind Item Orientation to Walk-Direction property.Direction = i.Orientation; i.OrientationChanged += (item, v) => { property.Direction = v; }; return(property); }); // Collision settings.Set <AntItem>("Mass", 1f, "Collision Mass of an Ant"); typeMapper.AttachItemProperty <AntItem, CollidableProperty>(this, "Ant Collidable", (i) => { CollidableProperty property = new CollidableProperty(i); // Set Mass to Settings property.CollisionFixed = false; property.CollisionMass = i.Settings.GetFloat <AntItem>("Mass").Value; // Bind Collision Radius to Item Radius property.CollisionRadius = i.Radius; i.RadiusChanged += (item, v) => { property.CollisionRadius = v; }; return(property); }); // Visibility typeMapper.AttachItemProperty <AntItem, VisibleProperty>(this, "Ant Visible", (i) => { VisibleProperty property = new VisibleProperty(i); // Bind Visibility Radius to the Item Radius property.VisibilityRadius = i.Radius; i.RadiusChanged += (item, v) => { property.VisibilityRadius = v; }; return(property); }); // Sighting settings.Set <AntItem>("ViewRange", 20f, "View Range of an Ant"); settings.Set <AntItem>("ViewAngle", 360, "View Angle of an Ant"); typeMapper.AttachItemProperty <AntItem, SightingProperty>(this, "Ant Sighting", (i) => { SightingProperty property = new SightingProperty(i); // Set View Range and Angle property.ViewRange = i.Settings.GetFloat <AntItem>("ViewRange").Value; property.ViewAngle = i.Settings.GetFloat <AntItem>("ViewAngle").Value; // Bind View Direction to the Item Orientation property.ViewDirection = i.Orientation; i.OrientationChanged += (item, v) => { property.ViewDirection = v; }; return(property); }); // Sniffer typeMapper.AttachItemProperty <AntItem, SnifferProperty>(this, "Ant Sniffer"); // Carrier settings.Set <AntItem>("CarrierStrength", 10f, "Carrier Strength of an Ant"); typeMapper.AttachItemProperty <AntItem, CarrierProperty>(this, "Ant Carrier", (i) => { CarrierProperty property = new CarrierProperty(i); property.CarrierStrength = i.Settings.GetFloat <AntItem>("CarrierStrength").Value; return(property); }); // Attackable settings.Set <AntItem>("MaxHealth", 100f, "Maximum Health for an Ant"); typeMapper.AttachItemProperty <AntItem, AttackableProperty>(this, "Ant Attackable", (i) => { AttackableProperty property = new AttackableProperty(i); // Bind Attackable Radius to Item Radius property.AttackableRadius = i.Radius; i.RadiusChanged += (item, v) => { property.AttackableRadius = v; }; // Health property.AttackableMaximumHealth = settings.GetInt <AntItem>("MaxHealth").Value; property.AttackableHealth = settings.GetInt <AntItem>("MaxHealth").Value; return(property); }); // Attacker settings.Set <AntItem>("AttackRange", 3f, "Attack Range for a Bug"); settings.Set <AntItem>("RecoveryTime", 2, "Recovery Time in Rounds for a Bug"); settings.Set <AntItem>("AttackStrength", 5, "Attach Strength for a Bug"); typeMapper.AttachItemProperty <AntItem, AttackerProperty>(this, "Ant Attacker", (i) => { AttackerProperty property = new AttackerProperty(i); property.AttackRange = i.Settings.GetFloat <AntItem>("AttackRange").Value; property.AttackRecoveryTime = i.Settings.GetInt <AntItem>("RecoveryTime").Value; property.AttackStrength = i.Settings.GetInt <AntItem>("AttackStrength").Value; return(property); }); // Collector settings.Set <AntItem>("SugarCapacity", 5, "Maximum Capacity for Sugar"); settings.Set <AntItem>("AppleCapacity", 2, "Maximum Capacity for Apple"); typeMapper.AttachItemProperty <AntItem, SugarCollectorProperty>(this, "Ant Sugar Collectable", (i) => { SugarCollectorProperty property = new SugarCollectorProperty(i); property.Capacity = i.Settings.GetInt <AntItem>("SugarCapacity").Value; return(property); }); typeMapper.AttachItemProperty <AntItem, AppleCollectorProperty>(this, "Ant Apple Collectable", (i) => { AppleCollectorProperty property = new AppleCollectorProperty(i); property.Capacity = i.Settings.GetInt <AntItem>("AppleCapacity").Value; return(property); }); // TODO: Optional, wenn _settings.ANT_APPLECOLLECT | _settings.ANT_APPLE_CAPACITY, 0); }