/// <summary>
        /// Default Constructor for the Type Mapper.
        /// </summary>
        /// <param name="faction">Faction</param>
        /// <param name="item">Item</param>
        /// <param name="interop">UnitInterop</param>
        public RecognitionInterop(Faction faction, FactionItem item, UnitInterop interop)
            : base(faction, item, interop)
        {
            // Get Sniffer Reference
            var sniffer = Item.GetProperty<SnifferProperty>();
            if (sniffer == null)
                throw new ArgumentException("Item does not contain SnifferProperty");

            // Insert sniffed Items into the List.
            sniffer.OnNewSmellableItem += property =>
            {
                var info = property.Item.GetItemInfo(Item);
                if (!smellableItems.Contains(info))
                    smellableItems.Add(info);
            };

            // Remove sniffed Items from List.
            sniffer.OnLostSmellableItem += property =>
            {
                var info = property.Item.GetItemInfo(Item);
                if (smellableItems.Contains(info))
                    smellableItems.Remove(info);
            };

            // Get Sighting Property
            sighting = Item.GetProperty<SightingProperty>();
            if (sighting == null)
                throw new ArgumentException("Item does not contain SightingProperty");

            // Add visible items to List.
            sighting.OnNewVisibleItem += property =>
            {
                var info = property.Item.GetItemInfo(Item);
                if (!visibleItems.Contains(info))
                    visibleItems.Add(info);
            };

            // Remove visible Items from List.
            sighting.OnLostVisibleItem += property =>
            {
                var info = property.Item.GetItemInfo(Item);
                if (visibleItems.Contains(info))
                    visibleItems.Remove(info);
            };

            // Set new Environment on Cell Switch
            sighting.OnEnvironmentChanged += (i, value) =>
            {
                if (OnEnvironmentChanged != null)
                    OnEnvironmentChanged(value);
            };
        }
Example #2
0
        /// <summary>
        /// Default Constructor for the Type Mapper.
        /// </summary>
        /// <param name="faction">Faction</param>
        /// <param name="item">Item</param>
        /// <param name="interop">UnitInterop</param>
        public AntMovementInterop(Faction faction, FactionItem item, UnitInterop interop) : base(faction, item, interop)
        {
            // Get Walking Property
            walking = Item.GetProperty <WalkingProperty>();
            if (walking == null)
            {
                throw new NotSupportedException("There is no Walking Property");
            }

            // Get Collision Property
            collidable = Item.GetProperty <CollidableProperty>();
            if (collidable == null)
            {
                throw new NotSupportedException("There is no Collidable Property");
            }

            // Handle Collisions with Walls and Borders.
            walking.OnHitBorder += (i, v) => { if (OnHitWall != null)
                                               {
                                                   OnHitWall(v);
                                               }
            };
            walking.OnHitWall += (i, v) => { if (OnHitWall != null)
                                             {
                                                 OnHitWall(v);
                                             }
            };

            // Kollisionen mit anderen Items füllt die Liste der Kollisionsitems
            // und prüft, ob es sich beim getroffenen Item um das Ziel handelt.
            collidable.OnCollision += (i, v) =>
            {
                // Zur Liste der kollidierten Items hinzufügen.
                collidedItems.Add(v.GetItemInfo(Item));

                // Prüfen, ob es sich um das aktuelle Ziel handelt.
                if (CurrentDestination != null &&
                    Item == Item.GetItemFromInfo(CurrentDestination))
                {
                    // Alles anhalten und Reach melden
                    Stop();
                    if (OnTargetReched != null)
                    {
                        OnTargetReched(i.GetItemInfo(Item));
                    }
                }
            };
        }
Example #3
0
        public override void Init(UnitInterop interop)
        {
            this.interop = interop as AntUnitInterop;

            movement = interop.GetProperty <AntMovementInterop>();
            if (movement == null)
            {
                throw new ArgumentException("No Movement Interop");
            }

            recognition = interop.GetProperty <RecognitionInterop>();
            if (recognition == null)
            {
                throw new ArgumentException("No Recognition Interop");
            }

            interaction = interop.GetProperty <InteractionInterop>();
            if (interaction == null)
            {
                throw new ArgumentException("No Interaction Interop");
            }

            this.interop.Tick += Interop_Tick;

            movement.OnWaits        += Movement_OnWaits;
            movement.OnHitWall      += Movement_OnHitWall;
            movement.OnCollision    += Movement_OnCollision;
            movement.OnTargetReched += Movement_OnTargetReched;

            recognition.OnEnvironmentChanged += Recognition_OnEnvironmentChanged;
            recognition.Smells += Recognition_Smells;
            recognition.Spots  += Recognition_Spots;

            interaction.OnHit  += Interaction_OnHit;
            interaction.OnKill += Interaction_OnKill;
        }
Example #4
0
        /// <summary>
        /// Default Constructor for the Type Mapper.
        /// </summary>
        /// <param name="faction">Faction</param>
        /// <param name="item">Item</param>
        /// <param name="interop">UnitInterop</param>
        public RecognitionInterop(Faction faction, FactionItem item, UnitInterop interop) : base(faction, item, interop)
        {
            // Get Sniffer Reference
            var sniffer = Item.GetProperty <SnifferProperty>();

            if (sniffer == null)
            {
                throw new ArgumentException("Item does not contain SnifferProperty");
            }

            // Insert sniffed Items into the List.
            sniffer.OnNewSmellableItem += property =>
            {
                var info = property.Item.GetItemInfo(Item);
                if (!smellableItems.Contains(info))
                {
                    smellableItems.Add(info);
                }
            };

            // Remove sniffed Items from List.
            sniffer.OnLostSmellableItem += property =>
            {
                var info = property.Item.GetItemInfo(Item);
                if (smellableItems.Contains(info))
                {
                    smellableItems.Remove(info);
                }
            };

            // Get Sighting Property
            sighting = Item.GetProperty <SightingProperty>();
            if (sighting == null)
            {
                throw new ArgumentException("Item does not contain SightingProperty");
            }

            // Add visible items to List.
            sighting.OnNewVisibleItem += property =>
            {
                var info = property.Item.GetItemInfo(Item);
                if (!visibleItems.Contains(info))
                {
                    visibleItems.Add(info);
                }
            };

            // Remove visible Items from List.
            sighting.OnLostVisibleItem += property =>
            {
                var info = property.Item.GetItemInfo(Item);
                if (visibleItems.Contains(info))
                {
                    visibleItems.Remove(info);
                }
            };

            // Set new Environment on Cell Switch
            sighting.OnEnvironmentChanged += (i, value) =>
            {
                if (OnEnvironmentChanged != null)
                {
                    OnEnvironmentChanged(value);
                }
            };
        }
Example #5
0
 /// <summary>
 /// Default Constructor for the Type Mapper.
 /// </summary>
 /// <param name="faction">Faction</param>
 /// <param name="item">Item</param>
 /// <param name="interop">UnitInterop</param>
 public UnitInteropProperty(Faction faction, FactionItem item, UnitInterop interop)
 {
     Faction = faction;
     Item    = item;
     Interop = interop;
 }
 /// <summary>
 /// Default Constructor for the Type Mapper.
 /// </summary>
 /// <param name="faction">Faction</param>
 /// <param name="item">Item</param>
 /// <param name="interop">UnitInterop</param>
 public UnitInteropProperty(Faction faction, FactionItem item, UnitInterop interop)
 {
     Faction = faction;
     Item = item;
     Interop = interop;
 }
Example #7
0
        /// <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);
            };
        }
Example #8
0
 /// <summary>
 /// Initialisierung der Spieler-Klasse.
 /// </summary>
 /// <param name="interop">Zentrales Interop-Objekt für diese Einheit.</param>
 public abstract void Init(UnitInterop interop);