public bool Destroy(string key)
        {
            IEntityTemplate found = this.m_Templates.FirstOrDefault(template =>
                                                                    template.CreatureType.Equals(key, StringComparison.OrdinalIgnoreCase));

            return(!(found is null) && this.m_Templates.Remove(found));
        }
Beispiel #2
0
        public IEntity CreateFromTemplate(IEntityTemplate template,
                                          Vector2Int position,
                                          string name = null,
                                          IDictionary <string, IEntityStatistic> statistics = null,
                                          IDictionary <string, IDerivedValue> derivedValues = null,
                                          IDictionary <string, IEntitySkill> skills         = null,
                                          IEnumerable <IAbility> abilities = null,
                                          IEnumerable <ICulture> cultures  = null,
                                          IGender gender       = null,
                                          IBioSex sex          = null,
                                          ISexuality sexuality = null,
                                          IRomance romance     = null,
                                          IJob job             = null,
                                          IEnumerable <ISpriteState> sprites = null,
                                          IWorldInstance world = null,
                                          IDriver driver       = null)
        {
            string     selectedName      = name;
            IJob       selectedJob       = job;
            IGender    selectedGender    = gender;
            IBioSex    selectedSex       = sex;
            ISexuality selectedSexuality = sexuality;
            IRomance   selectedRomance   = romance;
            IEnumerable <ISpriteState> selectedSprites  = sprites;
            List <ICulture>            creatureCultures = new List <ICulture>();
            IDriver selectedDriver = driver;
            IDictionary <string, IEntityStatistic> selectedStatistics = statistics;
            IDictionary <string, IDerivedValue>    selectedDVs        = derivedValues;
            IDictionary <string, IEntitySkill>     selectedSkills     = skills;
            IEnumerable <IAbility> selectedAbilities = abilities;

            if (!(cultures is null))
            {
                creatureCultures.AddRange(cultures);
            }
            List <IEntityTemplate> IEnemyGroupMaker.MakeEnemyGroup(IEntityTemplate forThis)
            {
                int baseThreat = forThis.Rating.GetThreat(null);

                var matchesWithRating = (this as IEntityManager).EnityMatchRating(
                    forThis,
                    baseThreat - m_ratingRange,
                    baseThreat + m_ratingRange);

                int maxThreatRating = baseThreat + m_ratingRange;
                int threatSoFar     = 0;

                var targetEnemies = new List <IEntityTemplate>(matchesWithRating);
                var group         = new List <IEntityTemplate>();

                do
                {
                    int idx        = m_random.Next() % targetEnemies.Count;
                    int thisThreat = targetEnemies[idx].Rating.GetThreat(forThis.Rating);
                    if (thisThreat + threatSoFar <= maxThreatRating)
                    {
                        group.Add(targetEnemies[idx]);
                        threatSoFar += thisThreat;
                    }
                    else
                    {
                        // remove an enemy that will not contribute
                        targetEnemies.RemoveAt(idx);
                    }
                }while (threatSoFar < maxThreatRating && targetEnemies.Count > 0);
                return(group);
            }
Beispiel #4
0
        private static Bitmap GetEntityTemplateImage([NotNull] IEntityTemplate template, ImageSize size)
        {
            Bitmap result;

            switch (size)
            {
            case ImageSize.Small:
                result = template.SmallImage;
                break;

            case ImageSize.Medium:
                result = template.Image;
                break;

            case ImageSize.Big:
                result = template.BigImage;
                break;

            default:
                result = null;
                break;
            }

            return(result);
        }
Beispiel #5
0
        /// <summary>Initializes all.</summary>
        /// <param name="processAttributes">if set to <see langword="true" /> [process attributes].</param>
        /// <param name="assembliesToScan">The assemblies to scan.</param>
        /// <exception cref="Exception">propertyComponentPool is null.</exception>
        internal void InitializeAll(bool processAttributes, IEnumerable <Assembly> assembliesToScan = null)
        {
            if (processAttributes)
            {
                IDictionary <Type, List <Attribute> > types;
                if (assembliesToScan == null)
                {
#if FULLDOTNET || METRO || UNITY5
                    types = AttributesProcessor.Process(AttributesProcessor.SupportedAttributes);
#else
                    types = AttributesProcessor.Process(AttributesProcessor.SupportedAttributes, null);
#endif
                }
                else
                {
                    types = AttributesProcessor.Process(AttributesProcessor.SupportedAttributes, assembliesToScan);
                }

                foreach (KeyValuePair <Type, List <Attribute> > item in types)
                {
#if METRO
                    if (typeof(EntitySystem).GetTypeInfo().IsAssignableFrom(item.Key.GetTypeInfo()))
#else
                    if (typeof(EntitySystem).IsAssignableFrom(item.Key))
#endif
                    {
                        Type type = item.Key;
                        ArtemisEntitySystem pee      = (ArtemisEntitySystem)item.Value[0];
                        EntitySystem        instance = (EntitySystem)Activator.CreateInstance(type);
                        this.SetSystem(instance, pee.GameLoopType, pee.Layer, pee.ExecutionType);
                    }
#if METRO
                    else if (typeof(IEntityTemplate).GetTypeInfo().IsAssignableFrom(item.Key.GetTypeInfo()))
#else
                    else if (typeof(IEntityTemplate).IsAssignableFrom(item.Key))
#endif
                    {
                        Type type = item.Key;
                        ArtemisEntityTemplate pee      = (ArtemisEntityTemplate)item.Value[0];
                        IEntityTemplate       instance = (IEntityTemplate)Activator.CreateInstance(type);
                        this.entityWorld.SetEntityTemplate(pee.Name, instance);
                    }
#if METRO
                    else if (typeof(ComponentPoolable).GetTypeInfo().IsAssignableFrom(item.Key.GetTypeInfo()))
#else
                    else if (typeof(ComponentPoolable).IsAssignableFrom(item.Key))
#endif
                    {
                        this.CreatePool(item.Key, item.Value);
                    }
                }
            }

            for (int index = 0, j = this.mergedBag.Count; index < j; ++index)
            {
                this.mergedBag.Get(index).LoadContent();
            }
        }
        public ProcessTemplateRuleNode(IEntityTemplate entityTemplate) : base(entityTemplate)
        {
            if (entityTemplate.EntityType != EntityType.Process)
            {
                throw new ArgumentException();
            }

            this.Name = "Process Template";
        }
        public DataStoreTemplateRuleNode(IEntityTemplate entityTemplate) : base(entityTemplate)
        {
            if (entityTemplate.EntityType != EntityType.DataStore)
            {
                throw new ArgumentException();
            }

            this.Name = "Data Store Template";
        }
Beispiel #8
0
        private void OnImageChanged([NotNull] IEntityTemplate template, ImageSize size)
        {
            var row = GetRow(template);

            if (row != null)
            {
                row.Cells[0].CellStyles.Default.Image = template.GetImage(ImageSize.Small);
            }
        }
        public ExternalInteractorTemplateRuleNode(IEntityTemplate entityTemplate) : base(entityTemplate)
        {
            if (entityTemplate.EntityType != EntityType.ExternalInteractor)
            {
                throw new ArgumentException();
            }

            Name = "External Interactor Template";
        }
        /// <summary>
        /// Initializes all systems.
        /// </summary>
        /// <param name="processAttributes">if set to <see langword="true" /> [process attributes].</param>
        /// <param name="assembliesToScan">The assemblies to scan.</param>
        /// <exception cref="Exception">propertyComponentPool is null.</exception>
        internal void InitializeAll(
            bool processAttributes,
            IEnumerable <Assembly> assembliesToScan = null)
        {
            if (processAttributes)
            {
                IDictionary <Type, List <Attribute> > types;
                if (assembliesToScan == null)
                {
                    types = AttributesProcessor.Process(
                        supportedAttributes: AttributesProcessor.SupportedAttributes,
                        assembliesToScan: null);
                }
                else
                {
                    types = AttributesProcessor.Process(
                        supportedAttributes: AttributesProcessor.SupportedAttributes,
                        assembliesToScan: assembliesToScan);
                }

                foreach (KeyValuePair <Type, List <Attribute> > item in types)
                {
                    Type             type       = item.Key;
                    List <Attribute> attributes = item.Value;
                    if (typeof(EntitySystem).IsAssignableFrom(type))
                    {
                        EntitySystemAttribute entitySystemAttribute = (EntitySystemAttribute)attributes[0];
                        EntitySystem          instance = (EntitySystem)Activator.CreateInstance(type);
                        SetSystem(
                            instance,
                            entitySystemAttribute.UpdateType,
                            entitySystemAttribute.Layer,
                            entitySystemAttribute.ExecutionType);
                    }

                    else if (typeof(IEntityTemplate).IsAssignableFrom(type))
                    {
                        EntityTemplateAttribute entitySystemAttribute = (EntityTemplateAttribute)attributes[0];
                        IEntityTemplate         instance = (IEntityTemplate)Activator.CreateInstance(type);
                        this.entityWorld.SetEntityTemplate(entitySystemAttribute.Name, instance);
                    }

                    else if (typeof(ComponentPoolable).IsAssignableFrom(type))
                    {
                        CreatePool(type, attributes);
                    }
                }
            }

            for (int index = 0, j = this.mergedBag.Count; index < j; ++index)
            {
                this.mergedBag.Get(index).LoadContent();
            }
        }
Beispiel #11
0
 public IEnumerable <IEntityTemplate> EnityMatchRating(IEntityTemplate forThis, int minRating, int maxRating)
 {
     return(m_enityList.Where((e) =>
     {
         if (e.Faction.IsFriend(forThis.Faction))
         {
             return false;
         }
         return (e.Rating.Threat >= minRating && e.Rating.Threat <= maxRating);
     })
            .AsEnumerable <IEntityTemplate>());
 }
 IEnumerable <IEntityTemplate> IEntityManager.EnityMatchRating(IEntityTemplate forThis, int minRating, int maxRating)
 {
     return(m_enityList.Where((e) =>
     {
         if (e.Faction.IsFriend(forThis.Faction))
         {
             return false;
         }
         int threatForThis = forThis.Rating.GetThreat(e.Rating);
         return (threatForThis >= minRating && threatForThis <= maxRating);
     })
            .AsEnumerable <IEntityTemplate>());
 }
Beispiel #13
0
        public IEnumerable <IAbility> GetAvailableAbilities(
            IEntityTemplate template,
            ICollection <IEntityStatistic> stats,
            ICollection <IEntitySkill> skills,
            ICollection <IDerivedValue> derivedValues)
        {
            List <IBasicValue <int> > data = new List <IBasicValue <int> >();

            data.AddRange(stats);
            data.AddRange(skills);
            data.AddRange(derivedValues);

            return(this.Abilities.Where(ability => ability.MeetsPrerequisites(data)));
        }
        protected void SetUpAbilities(
            IEntityTemplate template,
            ICollection <IEntityStatistic> stats,
            ICollection <IEntitySkill> skills,
            ICollection <IDerivedValue> derivedValues)
        {
            var abilities = this.AbilityHandler.GetAvailableAbilities(
                template,
                stats,
                skills,
                derivedValues);

            this.AbilityList.Points    = ABILITY_PICKS_MAX;
            this.AbilityList.Abilities = abilities.ToArray();
        }
        public void Add([NotNull] IEntityTemplate entityTemplate)
        {
            if (entityTemplate is IThreatModelChild child && child.Model != this)
            {
                throw new ArgumentException();
            }

            if (_entityTemplates == null)
            {
                _entityTemplates = new List <IEntityTemplate>();
            }

            _entityTemplates.Add(entityTemplate);

            SetDirty();
            ChildCreated?.Invoke(entityTemplate);
        }
Beispiel #16
0
        public IEntity AddEntity <T>([Required] string name, IEntityTemplate template) where T : IEntity
        {
            IEntity result = null;

            if (typeof(T) == typeof(IProcess))
            {
                result = new Process(this, name)
                {
                    _templateId = template?.Id ?? Guid.Empty
                }
            }
            ;
            if (typeof(T) == typeof(IExternalInteractor))
            {
                result = new ExternalInteractor(this, name)
                {
                    _templateId = template?.Id ?? Guid.Empty
                }
            }
            ;
            if (typeof(T) == typeof(IDataStore))
            {
                result = new DataStore(this, name)
                {
                    _templateId = template?.Id ?? Guid.Empty
                }
            }
            ;

            if (result != null)
            {
                if (_entities == null)
                {
                    _entities = new List <IEntity>();
                }
                _entities.Add(result);
                RegisterEvents(result);
                Dirty.IsDirty = true;
                ChildCreated?.Invoke(result);
            }

            return(result);
        }
        /// <summary>
        /// Create an entity from a template.
        /// </summary>
        /// <param name="entityUniqueId">ID to give new entity (assigns a new ID if null).</param>
        /// <param name="entityTemplate">Template instance to create the entity from.</param>
        /// <param name="templateArgs">Additional template arguments.</param>
        /// <returns></returns>
        public Entity CreateEntityFromTemplate(
            int?entityUniqueId,
            IEntityTemplate entityTemplate,
            params object[] templateArgs)
        {
            if (entityTemplate == null)
            {
                throw new MissingEntityTemplateException("Entity template was null.");
            }

            Entity entity = entityUniqueId != null
                                ? this.EntityManager.Create(entityUniqueId.Value)
                                : this.EntityManager.Create();

            entity = entityTemplate.BuildEntity(entity, this, templateArgs);
            RefreshEntity(entity);

            return(entity);
        }
Beispiel #18
0
        // REVIEW: This eventually needs to use Html.RenderView with view engine-independent rendering
        public static string DynamicEntity(this HtmlHelper html, object entity, string uiHint, DataBoundControlMode mode)
        {
            // REVIEW: How can we pass along the model to avoid MetaModel.Default?
            var table = MetaModel.Default.GetTable(entity.GetType());

            // REVIEW: MetaTable does not have a UIHint. Should it?
            IEntityTemplate entityTemplate        = MetaModel.Default.GetEntityTemplateFactory().CreateEntityTemplate(table, ref mode, uiHint /* ?? table.UIHint */);
            ViewUserControl entityTemplateControl = entityTemplate as ViewUserControl;

            if (entityTemplateControl == null)
            {
                throw new InvalidOperationException("Cannot render a dynamic entity whose entity template is not a ViewUserControl");
            }

            entityTemplate.SetHost(new SimpleEntityTemplateHost()
            {
                Table = table, Mode = mode
            });
            return(html.RenderViewUserControl(entityTemplateControl, entity));
        }
        protected void SetUpSkills(IEntityTemplate template)
        {
            this.SkillsList.Points = SKILL_POINTS_MAX;
            var skills         = this.SkillHandler.GetDefaultSkillBlock().Values;
            var templateSkills = template.Skills.Values;

            foreach (IEntitySkill skill in skills)
            {
                var found = templateSkills.FirstOrDefault(entitySkill =>
                                                          entitySkill.Name.Equals(skill.Name, StringComparison.OrdinalIgnoreCase));

                if (found is null)
                {
                    continue;
                }

                skill.ModifyValue(found.Value);
            }

            this.SkillsList.Skills = skills;
        }
Beispiel #20
0
    public void Link(Contexts contexts, GameEntity entity, IEntityTemplate template)
    {
        this.contexts  = contexts;
        this.entity    = entity;
        this._template = (UnityEntityTemplate)template;

        var link = this.gameObject.GetEntityLink();

        if (link != null && link.entity != null)
        {
            this.link = link;
        }
        else
        {
            this.link = this.gameObject.Link(entity, contexts.game);
        }

        Initialize(contexts, entity);
        RegisterListeners(entity);
        entity.AddGameToDestroyListener(this);
    }
        protected void OnCultureChange(IEntityTemplate template)
        {
            var culture = this.BasicPlayerInfo.CurrentCulture;

            this.GUIManager.SetUIColours(
                culture.BackgroundColours,
                culture.CursorColours,
                culture.FontColours,
                true,
                true,
                1f);

            this.RandomiseName();

            this.SetUpStatistics(template);
            this.SetUpDerivedValues();
            this.SetUpSkills(template);
            this.SetUpAbilities(
                template,
                this.StatisticsList.Statistics,
                this.SkillsList.Skills,
                this.DerivedValuesList.DerivedValues);
        }
Beispiel #22
0
            public List <IEntityTemplate> MakeEnemyGroup(IEntityTemplate forThis)
            {
                var matches = (this as IEntityManager).EnityMatchRating(
                    forThis,
                    forThis.Rating.Threat - m_ratingRange,
                    forThis.Rating.Threat + m_ratingRange);

                int maxThreatRating = forThis.Rating.Threat + m_ratingRange;
                int threatSoFar     = 0;
                var group           = new List <IEntityTemplate>();

                var targetEnemies = new List <IEntityTemplate>(matches);

                if (targetEnemies.Count == 0)
                {
                    return(group);
                }

                do
                {
                    int idx        = m_random.Next() % targetEnemies.Count;
                    int thisThreat = targetEnemies[idx].Rating.Threat + threatSoFar;
                    thisThreat = Math.Max(1, thisThreat);
                    if (thisThreat + threatSoFar <= maxThreatRating)
                    {
                        group.Add(targetEnemies[idx]);
                        threatSoFar += thisThreat;
                    }
                    else
                    {
                        // remove an enemy that will not contribute
                        targetEnemies.RemoveAt(idx);
                    }
                }while (threatSoFar < maxThreatRating && targetEnemies.Count != 0);
                return(group);
            }
Beispiel #23
0
 public static bool IsPlayer(this IEntityTemplate entityTemplate)
 {
     return(entityTemplate.Entity.Tags.Contain(EntityTags.Player));
 }
 /// <summary>Sets the entity template.</summary>
 /// <param name="entityTag">The entity tag.</param>
 /// <param name="entityTemplate">The entity template.</param>
 public void SetEntityTemplate(string entityTag, IEntityTemplate entityTemplate)
 {
     this.entityTemplates.Add(entityTag, entityTemplate);
 }
 public bool Add(IEntityTemplate value)
 {
     this.m_Templates.Add(value);
     return(true);
 }
Beispiel #26
0
 public void Add(IEntityTemplate e)
 {
     m_enityList.Add(e);
 }
Beispiel #27
0
 public void Remove(IEntityTemplate e)
 {
     m_enityList.Remove(e);
 }
 void IEntityManager.Remove(IEntityTemplate e)
 {
     m_enityList.Remove(e);
 }
 void IEntityManager.Add(IEntityTemplate e)
 {
     m_enityList.Add(e);
 }
Beispiel #30
0
 public void SetEntityTemplate(string entityTag, IEntityTemplate entityTemplate)
 {
     entityTemplates.Add(entityTag, entityTemplate);
 }
Beispiel #31
0
 public EntityTemplateRuleNode(IEntityTemplate entityTemplate)
 {
     this.Name           = "Entity Template";
     this.EntityTemplate = entityTemplate?.Id ?? Guid.Empty;
 }