Skill CreateSkill(int skill_index, int skill_cfgid)
        {
            LogicWorld      logic_world   = GetLogicWorld();
            SkillManager    skill_manager = logic_world.GetSkillManager();
            IConfigProvider config        = logic_world.GetConfigProvider();
            ObjectTypeData  skill_data    = config.GetSkillData(skill_cfgid);

            if (skill_data == null)
            {
                m_index2id[skill_index] = -1;
                return(null);
            }
            ObjectCreationContext object_context = new ObjectCreationContext();

            object_context.m_object_type_id = skill_cfgid;
            object_context.m_type_data      = skill_data;
            object_context.m_logic_world    = logic_world;
            object_context.m_owner_id       = ParentObject.ID;
            Skill skill = skill_manager.CreateObject(object_context);

            m_index2id[skill_index] = skill.ID;
            if (skill_index == DEFAULT_SKILL_INDEX)
            {
                m_default_skill_id = skill.ID;
            }
            if (skill.GetDefinitionComponent().StartsActive)
            {
                skill.Activate(GetCurrentTime());
            }
            return(skill);
        }
Exemple #2
0
        public void Impact()
        {
#if COMBAT_CLIENT
            if (m_render_effect_cfgid > 0)
            {
                if (m_remain_attack_cnt != m_combo_attack_cnt)
                {
                    PlayRenderEffectMessage stop_msg = RenderMessage.Create <PlayRenderEffectMessage>();
                    stop_msg.ConstructAsStop(GetOwnerEntityID(), m_render_effect_cfgid);
                    GetLogicWorld().AddRenderMessage(stop_msg);
                }
                PlayRenderEffectMessage start_msg = RenderMessage.Create <PlayRenderEffectMessage>();
                start_msg.ConstructAsPlay(GetOwnerEntityID(), m_render_effect_cfgid, FixPoint.MinusOne);
                GetLogicWorld().AddRenderMessage(start_msg);
            }
#endif
            --m_remain_attack_cnt;
            if (m_remain_attack_cnt <= 0)
            {
                if (m_combo_task != null)
                {
                    m_combo_task.Cancel();
                }
            }
            Skill skill = GetOwnerSkill();
            if (!skill.GetDefinitionComponent().NeedGatherTargets)
            {
                skill.BuildSkillTargets();
            }
            Entity        attacker    = GetOwnerEntity();
            List <Target> targets     = skill.GetTargets();
            LogicWorld    logic_world = GetLogicWorld();
            for (int i = 0; i < targets.Count; ++i)
            {
                m_current_target = targets[i].GetEntity(logic_world);
                if (m_current_target == null)
                {
                    continue;
                }
                DamagableComponent damageable_component = m_current_target.GetComponent(DamagableComponent.ID) as DamagableComponent;
                if (damageable_component == null)
                {
                    continue;
                }
                Damage damage = RecyclableObject.Create <Damage>();
                damage.m_attacker_id         = attacker.ID;
                damage.m_defender_id         = m_current_target.ID;
                damage.m_damage_type         = m_damage_type_id;
                damage.m_damage_amount       = m_damage_amount.Evaluate(this);
                damage.m_damage_amount       = DamageSystem.Instance.CalculateDamageAmount(m_damage_type_id, damage.m_damage_amount, attacker, m_current_target);
                damage.m_render_effect_cfgid = m_damage_render_effect_cfgid;
                damage.m_sound_cfgid         = m_damage_sound_cfgid;
                damageable_component.TakeDamage(damage);
            }
            m_current_target = null;
        }
        public void OnSkillActivated(Skill skill)
        {
            SkillDefinitionComponent def_cmp = skill.GetDefinitionComponent();

            if (def_cmp.StartsActive)
            {
                return;
            }
            if (def_cmp.BlocksMovementWhenActive)
            {
                ++m_move_block_count;
                if (m_move_block_count == 1)
                {
                    if (m_locomotor_cmp != null)
                    {
                        m_locomotor_cmp.Disable();
                    }
                }
            }
            else
            {
                if (def_cmp.BlocksRotatingWhenActive)
                {
                    PositionComponent position_component = skill.GetOwnerEntity().GetComponent(PositionComponent.ID) as PositionComponent;
                    if (position_component != null)
                    {
                        position_component.DisableRotating();
                    }
                }
                if (def_cmp.DeactivateWhenMoving)
                {
                    if (m_locomotor_cmp != null)
                    {
                        m_locomotor_cmp.StopMoving();
                    }
                }
                else
                {
                    if (def_cmp.m_main_animation != null && m_locomotor_cmp != null)
                    {
                        m_locomotor_cmp.BlockAnimation();
                    }
                }
            }
            if (def_cmp.BlocksOtherSkillsWhenActive)
            {
                ++m_active_block_count;
            }
            m_active_skill_ids.Add(skill.ID);
        }
        protected override void OnDisable()
        {
            SkillManager skill_manager = GetLogicWorld().GetSkillManager();

            for (int i = 0; i < m_active_skill_ids.Count; ++i)
            {
                Skill skill = skill_manager.GetObject(m_active_skill_ids[i]);
                if (skill != null && !skill.GetDefinitionComponent().StartsActive)
                {
                    m_skill_to_interrupt.Add(skill);
                }
            }
            for (int i = 0; i < m_skill_to_interrupt.Count; ++i)
            {
                m_skill_to_interrupt[i].Interrupt();
            }
            m_skill_to_interrupt.Clear();
        }
        public override void OnResurrect()
        {
            SkillManager skill_manager = GetLogicWorld().GetSkillManager();
            var          enumerator    = m_index2id.GetEnumerator();

            while (enumerator.MoveNext())
            {
                int   skill_id = enumerator.Current.Value;
                Skill skill    = skill_manager.GetObject(skill_id);
                if (skill == null)
                {
                    continue;
                }
                if (skill.GetDefinitionComponent().StartsActive)
                {
                    skill.Activate(GetCurrentTime());
                }
            }
        }
        public override void OnDeletePending()
        {
            //StateSystem.DEAD_STATE

            SkillManager skill_manager = GetLogicWorld().GetSkillManager();
            var          enumerator    = m_index2id.GetEnumerator();

            while (enumerator.MoveNext())
            {
                Skill skill = skill_manager.GetObject(enumerator.Current.Value);
                if (skill == null)
                {
                    continue;
                }
                if (skill.GetDefinitionComponent().StartsActive)
                {
                    skill.Interrupt();
                }
            }
        }
        void OnMovementStart()
        {
            SkillManager skill_manager = GetLogicWorld().GetSkillManager();

            for (int i = 0; i < m_active_skill_ids.Count; ++i)
            {
                Skill skill = skill_manager.GetObject(m_active_skill_ids[i]);
                if (skill != null)
                {
                    SkillDefinitionComponent def_cmp = skill.GetDefinitionComponent();
                    if (def_cmp.DeactivateWhenMoving)
                    {
                        m_skill_to_interrupt.Add(skill);
                    }
                }
            }
            for (int i = 0; i < m_skill_to_interrupt.Count; ++i)
            {
                m_skill_to_interrupt[i].Interrupt();
            }
            m_skill_to_interrupt.Clear();
        }
        public override void Inflict(FixPoint start_time)
        {
            Skill owner_skill = GetOwnerSkill();
            SkillDefinitionComponent definition_component = owner_skill.GetDefinitionComponent();

            m_actual_distance = m_distance;
            if (m_distance == FixPoint.Zero)
            {
                if (definition_component.ExternalDataType == SkillDefinitionComponent.NeedExternalOffset)
                {
                    m_actual_distance = definition_component.ExternalVector.Length();
                }
            }
            m_actual_time = m_time;
            if (definition_component.NormalAttack)
            {
                m_actual_time = m_time / owner_skill.GetSkillManagerComponent().AttackSpeedRate;
            }

            if (m_task == null)
            {
                m_task = LogicTask.Create <ComponentCommonTaskWithLastingTime>();
            }
            m_task.Construct(this, m_actual_time);
            var schedeler = GetLogicWorld().GetTaskScheduler();

            schedeler.Schedule(m_task, GetCurrentTime(), LOGIC_UPDATE_INTERVAL, LOGIC_UPDATE_INTERVAL);
#if COMBAT_CLIENT
            LocomoteRenderMessage msg = RenderMessage.Create <LocomoteRenderMessage>();
            msg.ConstructAsStartMoving(GetOwnerEntityID(), true, LocomoteRenderMessage.NotLocomotion);
            GetLogicWorld().AddRenderMessage(msg);
#endif

            if (m_enable_hide)
            {
                GetLogicWorld().AddSimpleRenderMessage(RenderMessageType.Hide, GetOwnerEntityID());
            }
        }
        void Impact()
        {
            Skill skill = GetOwnerSkill();

            if (!skill.GetDefinitionComponent().NeedGatherTargets)
            {
                skill.BuildSkillTargets();
            }
            List <Target>         targets  = skill.GetTargets();
            Entity                caster   = GetOwnerEntity();
            EffectApplicationData app_data = RecyclableObject.Create <EffectApplicationData>();

            app_data.m_original_entity_id = caster.ID;
            app_data.m_source_entity_id   = caster.ID;
            m_generator.Activate(app_data, targets);
            m_current_target = null;
            RecyclableObject.Recycle(app_data);
#if COMBAT_CLIENT
            if (m_render_effect_cfgid > 0 && m_render_delay_time <= FixPoint.Zero)
            {
                PlayRenderEffect();
            }
#endif
        }
Exemple #10
0
        public static Entity CreateEntityForSkillAndEffect(Component caller_component, Entity owner_entity, Target projectile_target, Vector3FP position_offset, FixPoint angle_offset, int object_type_id, int object_proto_id, FixPoint object_life_time, EffectGenerator attached_generator)
        {
            LogicWorld      logic_world = owner_entity.GetLogicWorld();
            IConfigProvider config      = logic_world.GetConfigProvider();
            ObjectTypeData  type_data   = config.GetObjectTypeData(object_type_id);

            if (type_data == null)
            {
                return(null);
            }

            PositionComponent owner_position_cmp = owner_entity.GetComponent(PositionComponent.ID) as PositionComponent;
            Vector3FP         source_pos         = owner_position_cmp.CurrentPosition;

            Vector2FP xz_facing;
            FixPoint  angle;
            Vector3FP facing;

            if (projectile_target == null)
            {
                xz_facing = owner_position_cmp.Facing2D;
                angle     = owner_position_cmp.FacingAngle;
                facing.x  = xz_facing.x;
                facing.y  = FixPoint.Zero;
                facing.z  = xz_facing.z;
            }
            else
            {
                Vector3FP target_pos = projectile_target.GetPosition(logic_world);
                xz_facing.x = target_pos.x - source_pos.x;
                xz_facing.z = target_pos.z - source_pos.z;
                xz_facing.Normalize();
                angle  = xz_facing.ToDegree();
                facing = target_pos - source_pos;
                facing.Normalize();
            }
            Vector2FP side      = xz_facing.Perpendicular();
            Vector2FP xz_offset = xz_facing * position_offset.z + side * position_offset.x;

            if (angle_offset != FixPoint.Zero)
            {
                angle += angle_offset;
                FixPoint radian = FixPoint.Degree2Radian(-angle);
                facing.x = FixPoint.Cos(radian);
                facing.z = FixPoint.Sin(radian);
            }

            Vector3FP         birth_position = new Vector3FP(source_pos.x + xz_offset.x, source_pos.y + position_offset.y, source_pos.z + xz_offset.z);
            BirthPositionInfo birth_info     = new BirthPositionInfo(birth_position.x, birth_position.y, birth_position.z, angle, owner_position_cmp.GetCurrentSceneSpace());

            ProjectileComponent owner_entity_projectile_component = owner_entity.GetComponent(ProjectileComponent.ID) as ProjectileComponent;

            if (owner_entity_projectile_component != null)
            {
                Entity original_owner = logic_world.GetEntityManager().GetObject(owner_entity_projectile_component.SourceEntityID);
                if (original_owner != null)
                {
                    owner_entity = original_owner;
                }
            }

            Player owner_player = owner_entity.GetOwnerPlayer();
            ObjectCreationContext object_context = new ObjectCreationContext();

            object_context.m_object_proxy_id = owner_player.ProxyID;
            object_context.m_object_type_id  = object_type_id;
            object_context.m_object_proto_id = object_proto_id;
            object_context.m_birth_info      = birth_info;
            object_context.m_type_data       = type_data;
            object_context.m_proto_data      = config.GetObjectProtoData(object_proto_id);
            object_context.m_logic_world     = logic_world;
            object_context.m_owner_id        = owner_player.ID;
            object_context.m_is_ai           = true;
            object_context.m_is_local        = owner_player.IsLocal;

            Entity created_entity = logic_world.GetEntityManager().CreateObject(object_context);

            DeathComponent death_component = created_entity.GetComponent(DeathComponent.ID) as DeathComponent;

            if (death_component != null && object_life_time > FixPoint.Zero)
            {
                death_component.SetLifeTime(object_life_time);
            }

            SummonedEntityComponent summoned_component = created_entity.GetComponent(SummonedEntityComponent.ID) as SummonedEntityComponent;

            if (summoned_component != null)
            {
                summoned_component.SetMaster(owner_entity);
            }

            ProjectileComponent projectile_component = created_entity.GetComponent(ProjectileComponent.ID) as ProjectileComponent;

            if (projectile_component != null)
            {
                ProjectileParameters param = RecyclableObject.Create <ProjectileParameters>();
                param.m_start_time       = logic_world.GetCurrentTime();
                param.m_life_time        = object_life_time;
                param.m_source_entity_id = owner_entity.ID;
                param.m_start_position   = birth_position;
                param.m_fixed_facing     = facing;
                if (projectile_target != null)
                {
                    param.m_target_entity_id = projectile_target.GetEntityID();
                    param.m_target_position  = projectile_target.GetPosition(logic_world);
                }
                else
                {
                    Skill          owner_skill     = null;
                    SkillComponent skill_componnet = caller_component as SkillComponent;
                    if (skill_componnet != null)
                    {
                        owner_skill = skill_componnet.GetOwnerSkill();
                    }
                    if (owner_skill != null && owner_skill.GetDefinitionComponent().ExternalDataType == SkillDefinitionComponent.NeedExternalTarget)
                    {
                        param.m_target_entity_id = 0;
                        FixPoint range = owner_skill.GetDefinitionComponent().MaxRange;
                        if (range <= 0)
                        {
                            range = FixPoint.Ten;  //ZZWTODO
                        }
                        if (projectile_component.Speed > FixPoint.Zero)
                        {
                            param.m_life_time = range / projectile_component.Speed;
                        }
                        param.m_target_position = param.m_start_position + param.m_fixed_facing * range;
                    }
                }
                param.m_generator_id = attached_generator == null ? 0 : attached_generator.ID;
                projectile_component.InitParam(param);
            }
            else if (attached_generator != null)
            {
                EffectApplicationData app_data = RecyclableObject.Create <EffectApplicationData>();
                app_data.m_original_entity_id = owner_entity.ID;
                app_data.m_source_entity_id   = owner_entity.ID;
                attached_generator.Activate(app_data, created_entity);
                RecyclableObject.Recycle(app_data);
            }
            return(created_entity);
        }
        public void OnSkillDeactivated(Skill skill)
        {
            SkillDefinitionComponent def_cmp = skill.GetDefinitionComponent();

            if (def_cmp.StartsActive)
            {
                return;
            }
            bool play_idle_animation = true;

            if (def_cmp.BlocksMovementWhenActive)
            {
                --m_move_block_count;
                if (m_move_block_count == 0)
                {
                    if (m_locomotor_cmp != null)
                    {
                        m_locomotor_cmp.Enable();
                    }
                }
            }
            else
            {
                if (def_cmp.BlocksRotatingWhenActive)
                {
                    PositionComponent position_component = skill.GetOwnerEntity().GetComponent(PositionComponent.ID) as PositionComponent;
                    if (position_component != null)
                    {
                        position_component.EnableRotating();
                    }
                    if (m_locomotor_cmp != null && m_locomotor_cmp.IsMoving)
                    {
                        position_component.SetFacing(m_locomotor_cmp.GetMovementProvider().GetCurrentDirection());
                    }
                }
                if (def_cmp.DeactivateWhenMoving)
                {
                }
                else
                {
                    if (def_cmp.m_main_animation != null && m_locomotor_cmp != null)
                    {
                        m_locomotor_cmp.UnblockAnimation();
                        play_idle_animation = false;
                    }
                }
            }
            if (def_cmp.BlocksOtherSkillsWhenActive)
            {
                --m_active_block_count;
            }
            m_active_skill_ids.Remove(skill.ID);

#if COMBAT_CLIENT
            if (play_idle_animation && def_cmp.m_main_animation != null)
            {
                PlayAnimationRenderMessage msg = RenderMessage.Create <PlayAnimationRenderMessage>();
                msg.Construct(GetOwnerEntityID(), AnimationName.IDLE, null, true, FixPoint.One);
                GetLogicWorld().AddRenderMessage(msg);
            }
#endif
        }
        void CreateOneObject(int index)
        {
            --m_remain_attack_cnt;
            Entity owner_entity      = GetOwnerEntity();
            Skill  owner_skill       = GetOwnerSkill();
            Target projectile_target = null;

            if (!m_ignore_target)
            {
                projectile_target = owner_skill.GetMajorTarget();
            }
            Vector3FP position_offset = m_offset;
            FixPoint  angle_offset    = FixPoint.Zero;

            if (m_combo_type_crc == ComboType_Angle)
            {
                if (m_combo_attack_cnt % 2 == 1)
                {
                    angle_offset = m_combo_interval * (FixPoint)((index + 1) / 2);
                    if (index % 2 != 0)
                    {
                        angle_offset = -angle_offset;
                    }
                }
                else
                {
                    angle_offset = m_combo_interval * ((FixPoint)(index / 2) + FixPoint.Half);
                    if (index % 2 != 0)
                    {
                        angle_offset = -angle_offset;
                    }
                }
            }
            else if (m_combo_type_crc == ComboType_Circle)
            {
                if (m_combo_interval == FixPoint.Zero)
                {
                    FixPoint rotate_radian = FixPoint.TwoPi / (FixPoint)m_combo_attack_cnt * (FixPoint)index;
                    position_offset = position_offset.YRotate(rotate_radian);
                }
                else
                {
                    if (m_combo_attack_cnt % 2 == 1)
                    {
                        angle_offset = m_combo_interval * (FixPoint)((index + 1) / 2);
                        if (index % 2 != 0)
                        {
                            angle_offset = -angle_offset;
                        }
                    }
                    else
                    {
                        angle_offset = m_combo_interval * ((FixPoint)(index / 2) + FixPoint.Half);
                        if (index % 2 != 0)
                        {
                            angle_offset = -angle_offset;
                        }
                    }
                    FixPoint rotate_radian = FixPoint.Degree2Radian(angle_offset);
                    position_offset = position_offset.YRotate(rotate_radian);
                    angle_offset    = FixPoint.Zero;
                }
            }

            if (projectile_target == null && !m_ignore_target)
            {
                SkillDefinitionComponent definition_component = owner_skill.GetDefinitionComponent();
                if (definition_component.ExternalDataType == SkillDefinitionComponent.NeedExternalOffset)
                {
                    position_offset.z = definition_component.ExternalVector.Length();
                }
            }

            EntityUtil.CreateEntityForSkillAndEffect(this, owner_entity, projectile_target, position_offset, angle_offset, m_object_type_id, m_object_proto_id, m_object_life_time, m_generator);
        }
        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);
                }
            }
        }