Example #1
0
        /// <summary>
        /// Generates a new Anthill.
        /// </summary>
        /// <param name="position">Position</param>
        private AnthillItem CreateAntHill(Vector2 position)
        {
            var hill = new AnthillItem(Context, this, position);

            Level.Engine.InsertItem(hill);
            antHills.Add(hill.Id, hill);
            return(hill);
        }
Example #2
0
        /// <summary>
        /// Initialize a Faction.
        /// </summary>
        protected override void OnInit()
        {
            Level.Engine.OnRemoveItem += Level_RemovedItem;

            // Generate the first group of Anthills (Initial Anthills)
            int hillCount = Settings.GetInt <AntFaction>("InitialAnthillCount").Value;

            hillCount = Math.Min(hillCount, Settings.GetInt <AntFaction>("TotalAnthillCount").Value);
            hillCount = Math.Min(hillCount, Settings.GetInt <AntFaction>("ConcurrentAnthillCount").Value);
            for (int i = 0; i < hillCount; i++)
            {
                if (i == 0)
                {
                    // Generate Primary Hill
                    primaryHill = CreateAntHill(Home);
                }
                else
                {
                    // TODO: Random Positions (on i > 1)
                    CreateAntHill(Home);
                }
            }

            // Generate the first group of Ants (Initial Ants)
            int antCount = Settings.GetInt <AntFaction>("InitialAntCount").Value;

            antCount = Math.Min(antCount, Settings.GetInt <AntFaction>("TotalAntCount").Value);
            antCount = Math.Min(antCount, Settings.GetInt <AntFaction>("ConcurrentAntCount").Value);
            for (var i = 0; i < antCount; i++)
            {
                if (primaryHill != null)
                {
                    CreateAnt(primaryHill);
                }
            }
        }
Example #3
0
 public AnthillInfo(FactionItem item, Item observer)
     : base(item, observer)
 {
     anthillItem = item as AnthillItem;
 }
Example #4
0
 public AnthillState(AnthillItem item) : base(item)
 {
 }
Example #5
0
 public AnthillState(AnthillItem item)
     : base(item)
 {
 }
Example #6
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);
        }