示例#1
0
        static void MarkDirtyStatic(AttributeManagerComponent owner_component, int attribute_id)
        {
            Attribute attribute = owner_component.GetAttributeByID(attribute_id);

            if (attribute == null)
            {
                return;
            }
            attribute.ComputeValue();
            AttributeDefinition definition = AttributeSystem.Instance.GetDefinitionByID(attribute_id);
            Object owner = owner_component.ParentObject;

            definition.Reflect(owner, attribute);
            List <int> static_dependent_attributes = definition.GetStaticDependentAttributes();

            for (int i = 0; i < static_dependent_attributes.Count; ++i)
            {
                MarkDirtyStatic(owner_component, static_dependent_attributes[i]);
            }
            if (attribute.m_dynamic_dependent_attributes != null)
            {
                var enumerator = attribute.m_dynamic_dependent_attributes.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    MarkDirtyStatic(owner_component, enumerator.Current.Key);
                }
            }
        }
示例#2
0
        public void Construct(AttributeManagerComponent owner_component, AttributeDefinition definition, string base_value)
        {
            m_owner_component    = owner_component;
            m_definition         = definition;
            m_base_value_formula = RecyclableObject.Create <Formula>();
            m_base_value_formula.Compile(base_value);

            int count = 0;
            List <ExpressionVariable> variables = m_base_value_formula.GetAllVariables();

            if (variables != null)
            {
                count = variables.Count;
            }
            for (int i = 0; i < count; ++i)
            {
                ExpressionVariable variable = variables[i];
                if (variable.MaxIndex == 1 && variable[0] == ExpressionVariable.VID_LevelTable)
                {
                    m_is_level_based = true;
                }
            }

            ComputeValue();
            m_definition.Reflect(m_owner_component.ParentObject, this, true);
        }
示例#3
0
        void InitializeComponents(ObjectCreationContext context)
        {
            List <ComponentData> components_data = context.m_type_data.m_components_data;

            for (int i = 0; i < components_data.Count; ++i)
            {
                AddComponent(components_data[i]);
            }

            if (context.m_proto_data != null)
            {
                var attributes = context.m_proto_data.m_attributes;
                if (attributes != null && attributes.Count > 0)
                {
                    AttributeManagerComponent cmp = GetComponent(AttributeManagerComponent.ID) as AttributeManagerComponent;
                    if (cmp != null)
                    {
                        var enumerator = attributes.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            cmp.SetAttributeBaseValue(enumerator.Current.Key, enumerator.Current.Value);
                        }
                    }
                }

                var skills = context.m_proto_data.m_skills;
                if (skills != null && skills.Count > 0)
                {
                    SkillManagerComponent cmp = GetComponent(SkillManagerComponent.ID) as SkillManagerComponent;
                    if (cmp != null)
                    {
                        var enumerator = skills.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            cmp.AddSkill(enumerator.Current.Key, enumerator.Current.Value);
                        }
                    }
                }
            }

            for (int i = 0; i < components_data.Count; ++i)
            {
                Component component = GetComponent(components_data[i].m_component_type_id);
                if (component == null)
                {
                    continue;
                }
                component.InitializeComponent();
            }

            for (int i = 0; i < components_data.Count; ++i)
            {
                Component component = GetComponent(components_data[i].m_component_type_id);
                if (component == null)
                {
                    continue;
                }
                component.OnObjectCreated();
            }
        }
示例#4
0
        public static Attribute GetAttribute(Entity entity, int attribute_id)
        {
            if (entity == null)
            {
                return(null);
            }
            AttributeManagerComponent attribute_manager_component = entity.GetComponent(AttributeManagerComponent.ID) as AttributeManagerComponent;

            if (attribute_manager_component == null)
            {
                return(null);
            }
            Attribute attribute = attribute_manager_component.GetAttributeByID(attribute_id);

            return(attribute);
        }
示例#5
0
        public static FixPoint GetAttributeValue(Entity entity, int attribute_id)
        {
            if (entity == null)
            {
                return(FixPoint.Zero);
            }
            AttributeManagerComponent attribute_manager_component = entity.GetComponent(AttributeManagerComponent.ID) as AttributeManagerComponent;

            if (attribute_manager_component == null)
            {
                return(FixPoint.Zero);
            }
            Attribute attribute = attribute_manager_component.GetAttributeByID(attribute_id);

            if (attribute == null)
            {
                return(FixPoint.Zero);
            }
            return(attribute.Value);
        }
示例#6
0
 public void Reset()
 {
     m_owner_component = null;
     m_definition      = null;
     RecyclableObject.Recycle(m_base_value_formula);
     m_base_value_formula = null;
     m_is_level_based     = false;
     m_base_value         = FixPoint.Zero;
     m_value = FixPoint.Zero;
     if (m_dynamic_dependent_attributes != null)
     {
         m_dynamic_dependent_attributes.Clear();
     }
     if (m_modifiers != null)
     {
         var enumerator = m_modifiers.GetEnumerator();
         while (enumerator.MoveNext())
         {
             RecyclableObject.Recycle(enumerator.Current.Value);
         }
         m_modifiers.Clear();
     }
 }
示例#7
0
        public FixPoint GetVariable(ExpressionVariable variable, int index)
        {
            int vid = variable[index];

            if (index == variable.MaxIndex)
            {
                return(ObjectUtil.GetVariable(this, vid));
            }
            else if (vid == ExpressionVariable.VID_LevelTable)
            {
                return(GetLogicWorld().GetConfigProvider().GetLevelBasedNumber(variable[index + 1], ObjectUtil.GetLevel(this)));
            }
            else if (vid == ExpressionVariable.VID_Attribute)
            {
                AttributeManagerComponent cmp = GetComponent(AttributeManagerComponent.ID) as AttributeManagerComponent;
                if (cmp != null)
                {
                    return(cmp.GetVariable(variable, index + 1));
                }
            }
            else if (vid == ExpressionVariable.VID_Object)
            {
                Object owner_object = GetOwnerObject();
                if (owner_object != null)
                {
                    return(owner_object.GetVariable(variable, index + 1));
                }
            }
            else if (vid == ExpressionVariable.VID_Entity)
            {
                Object owner_entity = GetOwnerEntity();
                if (owner_entity != null)
                {
                    return(owner_entity.GetVariable(variable, index + 1));
                }
            }
            else if (vid == ExpressionVariable.VID_Player)
            {
                Object owner_player = GetOwnerPlayer();
                if (owner_player != null)
                {
                    return(owner_player.GetVariable(variable, index + 1));
                }
            }
            else if (vid == ExpressionVariable.VID_Master)
            {
                Object master = GetOwnerEntity();
                SummonedEntityComponent summoned_component = GetComponent(SummonedEntityComponent.ID) as SummonedEntityComponent;
                if (summoned_component != null)
                {
                    Entity entity = GetLogicWorld().GetEntityManager().GetObject(summoned_component.MasterID);
                    if (entity != null)
                    {
                        master = entity;
                    }
                }
                return(master.GetVariable(variable, index + 1));
            }
            else if (vid == ExpressionVariable.VID_UltimateMaster)
            {
                Object master = GetOwnerEntity();
                SummonedEntityComponent summoned_component = GetComponent(SummonedEntityComponent.ID) as SummonedEntityComponent;
                while (summoned_component != null)
                {
                    Entity entity = GetLogicWorld().GetEntityManager().GetObject(summoned_component.MasterID);
                    if (entity == null)
                    {
                        break;
                    }
                    master             = entity;
                    summoned_component = entity.GetComponent(SummonedEntityComponent.ID) as SummonedEntityComponent;
                }
                return(master.GetVariable(variable, index + 1));
            }
            Object owner = GetOwnerObject();

            if (owner != null)
            {
                return(owner.GetVariable(variable, index));
            }
            else
            {
                return(FixPoint.Zero);
            }
        }