Beispiel #1
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();
            }
        }
Beispiel #2
0
 protected override void OnDestruct()
 {
     m_owner_component      = null;
     m_mana_component       = null;
     m_definition_component = null;
     ClearTargets();
 }
Beispiel #3
0
        protected override void PreInitializeObject(ObjectCreationContext context)
        {
            Entity owner_entity = context.m_logic_world.GetEntityManager().GetObject(m_context.m_owner_id);

            if (owner_entity != null)
            {
                m_owner_component = owner_entity.GetComponent(SkillManagerComponent.ID) as SkillManagerComponent;
                m_mana_component  = owner_entity.GetComponent(ManaComponent.ID) as ManaComponent;
            }
        }
        public void StartExpirationTimer(FixPoint start_time, SkillManagerComponent manager)
        {
            SkillTimer timer       = m_timers[SkillTimer.ExpirationTimer];
            FixPoint   update_rate = FixPoint.One;

            if (m_normal_attack)
            {
                update_rate = manager.AttackSpeedRate;
            }
            timer.Start(start_time, ExpirationTime, update_rate);
        }
        public void StartCooldownTimer(FixPoint start_time, SkillManagerComponent manager)
        {
            SkillTimer timer = m_timers[SkillTimer.CooldownTimer];
            FixPoint   update_rate;

            if (m_normal_attack)
            {
                update_rate = manager.AttackSpeedRate;
            }
            else
            {
                update_rate = manager.CoolDownSpeedUpRate;
            }
            timer.Start(start_time, CooldownTime, update_rate);
        }
        public void OnTaskService(FixPoint delta_time)
        {
            PositionComponent     position_cmp  = ParentObject.GetComponent(PositionComponent.ID) as PositionComponent;
            LocomotorComponent    locomotor_cmp = ParentObject.GetComponent(LocomotorComponent.ID) as LocomotorComponent;
            SkillManagerComponent skill_cmp     = ParentObject.GetComponent(SkillManagerComponent.ID) as SkillManagerComponent;
            Skill skill = skill_cmp.GetSkill(m_skill_index);

            if (skill == null)
            {
                StopTargeting();
                return;
            }

            if (!skill.IsReady() && locomotor_cmp != null && locomotor_cmp.IsMoving)
            {
                FixPoint delay = skill.GetNextReadyTime();
                if (delay == FixPoint.Zero)
                {
                    delay = FixPoint.PrecisionFP;
                }
                ScheduleTargeting(delay);
                return;
            }

            bool              move_required       = false;
            FixPoint          max_range           = skill.GetDefinitionComponent().MaxRange;
            PositionComponent target_position_cmp = m_current_target.GetComponent(PositionComponent.ID) as PositionComponent;
            Vector3FP         direction           = target_position_cmp.CurrentPosition - position_cmp.CurrentPosition;

            if (max_range > 0)
            {
                FixPoint distance = direction.FastLength() - target_position_cmp.Radius - position_cmp.Radius;  //ZZWTODO 多处距离计算
                if (distance > max_range)
                {
                    move_required = true;
                    if (locomotor_cmp == null)
                    {
                        //ZZWTODO
                        ScheduleTargeting(TARGETING_UPDATE_MAX_FREQUENCY);
                    }
                    else if (!locomotor_cmp.IsEnable())
                    {
                        ScheduleTargeting(TARGETING_UPDATE_MIN_FREQUENCY);
                    }
                    else
                    {
                        FixPoint delay = (distance - max_range) / locomotor_cmp.MaxSpeed;
                        if (delay > TARGETING_UPDATE_MAX_FREQUENCY)
                        {
                            delay = TARGETING_UPDATE_MAX_FREQUENCY;
                        }
                        else if (delay < TARGETING_UPDATE_MIN_FREQUENCY)
                        {
                            delay = TARGETING_UPDATE_MIN_FREQUENCY;
                        }
                        PathFindingComponent pathfinding_component = ParentObject.GetComponent(PathFindingComponent.ID) as PathFindingComponent;
                        if (pathfinding_component != null)
                        {
                            if (pathfinding_component.FindPath(target_position_cmp.CurrentPosition))
                            {
                                locomotor_cmp.GetMovementProvider().FinishMovementWhenTargetInRange(target_position_cmp, max_range);
                            }
                        }
                        else
                        {
                            List <Vector3FP> path = new List <Vector3FP>();
                            path.Add(position_cmp.CurrentPosition);
                            path.Add(target_position_cmp.CurrentPosition);
                            locomotor_cmp.MoveAlongPath(path, false);
                            locomotor_cmp.GetMovementProvider().FinishMovementWhenTargetInRange(target_position_cmp, max_range);
                        }
                        ScheduleTargeting(delay);
                    }
                }
            }
            if (!move_required)
            {
                if (skill.CanActivate(false))
                {
                    position_cmp.SetFacing(direction);
                    skill.GetDefinitionComponent().ExternalID = m_current_target.ID;
                    skill.Activate(GetCurrentTime());
                    if (m_attack_once)
                    {
                        StopTargeting();
                        return;
                    }
                    FixPoint delay = skill.GetDefinitionComponent().CooldownTime + FixPoint.PrecisionFP;
                    if (delay > TARGETING_UPDATE_MAX_FREQUENCY)
                    {
                        delay = TARGETING_UPDATE_MAX_FREQUENCY;
                    }
                    ScheduleTargeting(delay);
                }
                else
                {
                    FixPoint delay = skill.GetNextReadyTime();
                    if (delay < TARGETING_UPDATE_MIN_FREQUENCY)
                    {
                        delay = TARGETING_UPDATE_MIN_FREQUENCY;
                    }
                    ScheduleTargeting(delay);
                }
            }
        }