Пример #1
0
        /// <summary>
        /// Callback to identify the group key.
        /// </summary>
        /// <param name="item">Item</param>
        /// <param name="group">Group Key</param>
        /// <returns>true if the Item is relevant for this Statistic</returns>
        protected override bool CategorizeItem(Item item, out string group)
        {
            // Only Ant Items are relevant.
            AntItem antItem = item as AntItem;

            if (antItem != null)
            {
                // TODO: Fix this as soon Ants get Castes back
                group = string.Empty;
                return(true);
            }

            group = string.Empty;
            return(false);
        }
Пример #2
0
        protected override void RequestDraw()
        {
            if (_level != null)
            {
                DrawPlayground(_level.Map.GetCellCount(), _level.Map.Tiles);

                foreach (var item in _level.Items)
                {
                    float?bodySpeed       = null;
                    float?bodyDirection   = null;
                    float?bodyRadius      = null;
                    float?smellableRadius = null;
                    float?viewRange       = null;
                    float?viewAngle       = null;
                    float?viewDirection   = null;
                    float?attackRange     = null;

                    // Movement
                    if (item.ContainsProperty <WalkingProperty>())
                    {
                        WalkingProperty prop = item.GetProperty <WalkingProperty>();
                        bodySpeed     = prop.Speed;
                        bodyDirection = prop.Direction;
                    }

                    // Kollisionsradius
                    if (item.ContainsProperty <CollidableProperty>())
                    {
                        CollidableProperty prop = item.GetProperty <CollidableProperty>();
                        bodyRadius = prop.CollisionRadius;
                    }

                    // Sicht
                    if (item.ContainsProperty <SightingProperty>())
                    {
                        SightingProperty prop = item.GetProperty <SightingProperty>();
                        viewRange     = prop.ViewRange;
                        viewDirection = prop.ViewDirection.Radian;
                        viewAngle     = prop.ViewAngle;
                    }

                    // Attack
                    if (item.ContainsProperty <AttackerProperty>())
                    {
                        AttackerProperty prop = item.GetProperty <AttackerProperty>();
                        attackRange = prop.AttackRange;
                    }

                    // Stinkender radius
                    if (item.ContainsProperty <SmellableProperty>())
                    {
                        SmellableProperty prop = item.GetProperty <SmellableProperty>();
                        smellableRadius = prop.SmellableRadius;
                    }

                    Color color       = Color.Gray;
                    Color?borderColor = null;

                    // Farbe
                    if (item is AnthillItem)
                    {
                        color = Color.Brown;
                    }
                    else if (item is SugarItem)
                    {
                        color = Color.White;
                    }
                    else if (item is AppleItem)
                    {
                        color = Color.LightGreen;
                    }
                    else if (item is BugItem)
                    {
                        color = Color.Blue;
                    }
                    else if (item is AntItem)
                    {
                        color = Color.LightGray;
                        AntItem ant = item as AntItem;
                        switch (ant.PlayerIndex)
                        {
                        case 0: borderColor = Color.Orange; break;

                        case 1: borderColor = Color.Red; break;

                        case 2: borderColor = Color.Yellow; break;

                        case 3: borderColor = Color.Green; break;

                        case 4: borderColor = Color.Blue; break;

                        case 5: borderColor = Color.Purple; break;

                        case 6: borderColor = Color.White; break;

                        case 7: borderColor = Color.Black; break;
                        }
                    }
                    else if (item is MarkerItem)
                    {
                        color = Color.LightGray;
                        MarkerItem marker = item as MarkerItem;
                        switch (marker.PlayerIndex)
                        {
                        case 0: borderColor = Color.Orange; break;

                        case 1: borderColor = Color.Red; break;

                        case 2: borderColor = Color.Yellow; break;

                        case 3: borderColor = Color.Green; break;

                        case 4: borderColor = Color.Blue; break;

                        case 5: borderColor = Color.Purple; break;

                        case 6: borderColor = Color.White; break;

                        case 7: borderColor = Color.Black; break;
                        }
                    }

                    // Malen
                    DrawItem(item.Id, item.Position,
                             bodyRadius, bodyDirection, bodySpeed, color,
                             viewRange, viewDirection, viewAngle,
                             attackRange, smellableRadius, borderColor);
                }
            }
        }
Пример #3
0
 public AntInfo(AntItem item, Item observer)
     : base(item, observer)
 {
 }
Пример #4
0
 public AntInfo(AntItem item, Item observer)
     : base(item, observer)
 {
 }
Пример #5
0
        /// <summary>
        /// Generates a new Ant at the position of the given Anthill.
        /// </summary>
        private AntItem CreateAnt(AnthillItem anthill)
        {
            // Find Direction
            Angle   direction = Angle.FromDegree(Random.Next(0, 360));
            Vector2 rim       = Vector2.FromAngle(direction) * (anthill.Radius + AntItem.AntRadius);
            Vector2 position  = anthill.Position.ToVector2XY() + rim;

            // Type anfragen
            Type antType = (Factory.Interop as AntFactoryInterop).RequestCreateMember();

            if (antType == null)
            {
                // Spieler will offensichtlich keine Ameise erstellen
                return(null);
            }

            // Prüfen, ob es sich um den richtigen Typen handelt
            if (!antType.IsSubclassOf(typeof(AntUnit)))
            {
                throw new ArgumentException("Given Type is not a primordial Ant");
            }

            // Auf Kasten prüfen
            var caste  = new PrimordialCasteAttribute();
            var castes = antType.GetCustomAttributes(typeof(CasteAttribute), true);

            if (castes.Length > 0 && castes[0] is CasteAttribute)
            {
                var attribute = castes[0] as CasteAttribute;

                // Caste Mapping ermitteln
                Type     casteType = attribute.GetType();
                object[] mappings  = casteType.GetCustomAttributes(typeof(CasteAttributeMappingAttribute), false);
                if (mappings.Length != 1 || !(mappings[0] is CasteAttributeMappingAttribute))
                {
                    throw new ArgumentException("The used Caste-Attribute has no Mapping");
                }

                // Mapping versuchen
                try
                {
                    var mapping   = mappings[0] as CasteAttributeMappingAttribute;
                    var tempCaste = new PrimordialCasteAttribute
                    {
                        Name      = (string)casteType.GetProperty(mapping.NameProperty).GetValue(attribute, null),
                        Attack    = (int)casteType.GetProperty(mapping.AttackProperty).GetValue(attribute, null),
                        Attention = (int)casteType.GetProperty(mapping.AttentionProperty).GetValue(attribute, null),
                        Defense   = (int)casteType.GetProperty(mapping.DefenseProperty).GetValue(attribute, null),
                        Speed     = (int)casteType.GetProperty(mapping.SpeedProperty).GetValue(attribute, null),
                        Strength  = (int)casteType.GetProperty(mapping.StrengthProperty).GetValue(attribute, null)
                    };

                    // Prüfung
                    tempCaste.Check();

                    caste = tempCaste;
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("The mapping of the used Caste-Attribute failed", ex);
                }
            }

            // Namen erzeugen
            string name = names[Random.Next(0, names.Length - 1)];

            // AntItem erstellen
            AntItem antItem = new AntItem(Context, this, position, direction, name);
            AntUnit antUnit = (AntUnit)Activator.CreateInstance(antType);

            CreateUnit(antUnit, antItem);

            Level.Engine.InsertItem(antItem);
            totalAntCount++;

            // TODO: Kosten

            // Stats
            _antRespawnDelay = Settings.GetInt <AntFaction>("AntRespawnDelay").Value;

            return(antItem);
        }
Пример #6
0
 /// <summary>
 /// Default Constructor for the Type Mapper.
 /// </summary>
 /// <param name="faction">Faction</param>
 /// <param name="item">Item</param>
 public AntUnitInterop(AntFaction faction, AntItem item) : base(faction, item)
 {
 }