public override void Run(RenderWorld context, FixPoint current_time, FixPoint delta_time_fp)
        {
            bool  over       = false;
            float delta_time = (float)delta_time_fp;

            if (delta_time > m_remain_predict_time)
            {
                delta_time            = m_remain_predict_time;
                m_remain_predict_time = -1f;
                over = true;
            }
            else
            {
                m_remain_predict_time -= delta_time;
            }
            LocomotorComponent locomotor_component = m_predict_component.GetLocomotorComponent();

            if (m_predict_component.CanPredictLocomotor && locomotor_component.IsEnable())
            {
                Vector3 offset = m_direction * (float)locomotor_component.MaxSpeed * delta_time;
                m_predict_component.AddPredictOffset(offset);
            }
            if (!over)
            {
                Schedule(current_time, FixPoint.PrecisionFP);
            }
        }
예제 #2
0
        protected override void PostInitializeComponent()
        {
            ModelComponent model_component = ParentObject.GetComponent(ModelComponent.ID) as ModelComponent;

            if (model_component == null)
            {
                return;
            }
            GameObject go = model_component.GetUnityGameObject();

            if (go == null)
            {
                return;
            }
            Transform child = go.transform.FindChild(m_animator_path);

            if (child == null)
            {
                return;
            }
            m_unity_animator_cmp = child.GetComponent <Animator>();

            LocomotorComponent locomotor_componnet = GetLogicEntity().GetComponent(LocomotorComponent.ID) as LocomotorComponent;

            if (locomotor_componnet != null)
            {
                m_locomotor_animation_speed = (float)locomotor_componnet.LocomotorSpeedRate;
            }
        }
        protected override void OnActionUpdate(FixPoint delta_time)
        {
            int current_target_id = (int)(m_context.GetData(BTContextKey.CurrentTargetID));

            if (current_target_id <= 0)
            {
                return;
            }
            Entity current_target = GetLogicWorld().GetEntityManager().GetObject(current_target_id);

            if (current_target == null)
            {
                return;
            }
            Entity owner_entity = GetOwnerEntity();

            if (owner_entity == null)
            {
                return;
            }
            PositionComponent  position_cmp        = owner_entity.GetComponent(PositionComponent.ID) as PositionComponent;
            LocomotorComponent locomotor_cmp       = owner_entity.GetComponent(LocomotorComponent.ID) as LocomotorComponent;
            PositionComponent  target_position_cmp = current_target.GetComponent(PositionComponent.ID) as PositionComponent;

            Vector3FP direction = target_position_cmp.CurrentPosition - position_cmp.CurrentPosition;
            FixPoint  distance  = direction.FastLength() - target_position_cmp.Radius - position_cmp.Radius; //ZZWTODO 多处距离计算

            if (distance <= m_range)
            {
                return;
            }

            PathFindingComponent pathfinding_component = owner_entity.GetComponent(PathFindingComponent.ID) as PathFindingComponent;

            if (pathfinding_component != null)
            {
                if (pathfinding_component.FindPath(target_position_cmp.CurrentPosition))
                {
                    locomotor_cmp.GetMovementProvider().FinishMovementWhenTargetInRange(target_position_cmp, m_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, m_range);
            }
        }
        protected override void PostInitializeComponent()
        {
            LogicWorld logic_world = GetLogicWorld();
            var        enumerator  = m_index2id.GetEnumerator();

            while (enumerator.MoveNext())
            {
                int skill_index = enumerator.Current.Key;
                int skill_cfgid = enumerator.Current.Value;
                CreateSkill(skill_index, skill_cfgid);
            }
            m_locomotor_cmp    = ParentObject.GetComponent(LocomotorComponent.ID) as LocomotorComponent;
            m_listener_context = SignalListenerContext.CreateForEntityComponent(logic_world.GenerateSignalListenerID(), ParentObject.ID, m_component_type_id);
            ParentObject.AddListener(SignalType.StartMoving, m_listener_context);
        }
예제 #5
0
        bool HandleEntityMove(EntityMoveCommand cmd)
        {
            Entity entity = m_logic_world.GetEntityManager().GetObject(cmd.m_entity_id);

            if (entity == null)
            {
                return(false);
            }
            LocomotorComponent locomotor_component = entity.GetComponent(LocomotorComponent.ID) as LocomotorComponent;

            if (locomotor_component == null)
            {
                return(false);
            }
            if (cmd.m_move_type != EntityMoveCommand.StopMoving)
            {
                TargetingComponent targeting_component = entity.GetComponent(TargetingComponent.ID) as TargetingComponent;
                if (targeting_component != null)
                {
                    targeting_component.StopTargeting();
                }
            }
            if (cmd.m_move_type == EntityMoveCommand.DestinationType)
            {
                PathFindingComponent pathfinding_component = entity.GetComponent(PathFindingComponent.ID) as PathFindingComponent;
                if (pathfinding_component != null)
                {
                    return(pathfinding_component.FindPath(cmd.m_vector));
                }
                else
                {
                    PositionComponent position_component = entity.GetComponent(PositionComponent.ID) as PositionComponent;
                    List <Vector3FP>  path = new List <Vector3FP>();
                    path.Add(position_component.CurrentPosition);
                    path.Add(cmd.m_vector);
                    locomotor_component.MoveAlongPath(path, true);
                }
            }
            else if (cmd.m_move_type == EntityMoveCommand.DirectionType)
            {
                locomotor_component.MoveByDirection(cmd.m_vector);
            }
            else if (cmd.m_move_type == EntityMoveCommand.StopMoving)
            {
                locomotor_component.StopMoving(true);
            }
            return(true);
        }
        protected override void OnDestruct()
        {
            m_locomotor_cmp = null;
            ParentObject.RemoveListener(SignalType.StartMoving, m_listener_context.ID);
            SignalListenerContext.Recycle(m_listener_context);
            m_listener_context = null;

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

            while (enumerator.MoveNext())
            {
                int skill_id = enumerator.Current.Value;
                skill_manager.DestroyObject(skill_id);
            }
        }
        protected override void PostInitializeComponent()
        {
            m_model_component = ParentObject.GetComponent(ModelComponent.ID) as ModelComponent;
            if (m_model_component == null)
            {
                return;
            }
            GameObject go = m_model_component.GetUnityGameObject();

            if (go == null)
            {
                return;
            }
            m_interpolation_tr = go.transform;
            m_model_component.SetPredictComponent(this);
            Entity entity = GetLogicEntity();

            m_position_component  = entity.GetComponent(PositionComponent.ID) as PositionComponent;
            m_locomotor_component = entity.GetComponent(LocomotorComponent.ID) as LocomotorComponent;
        }
예제 #8
0
        //FixPoint m_tolerance = FixPoint.One / FixPoint.Ten;
        //Vector3FP m_destination = new Vector3FP(new FixPoint(99999), FixPoint.Zero, new FixPoint(99999));

        public bool FindPath(Vector3FP destination)
        {
            if (!IsEnable())
            {
                return(false);
            }
            //if (FixPoint.Abs(destination.x - m_destination.x) + FixPoint.Abs(destination.z - m_destination.z) < m_tolerance)
            //    return true;
            LocomotorComponent locomotor_cmp = ParentObject.GetComponent(LocomotorComponent.ID) as LocomotorComponent;

            if (locomotor_cmp == null)
            {
                return(false);
            }
            PositionComponent position_cmp = ParentObject.GetComponent(PositionComponent.ID) as PositionComponent;

            if (position_cmp == null)
            {
                return(false);
            }
            GridGraph graph = position_cmp.GetGridGraph();

            if (graph == null)
            {
                return(false);
            }
            if (!graph.FindPath(position_cmp.CurrentPosition, destination))
            {
                locomotor_cmp.StopMoving();
                return(false);
            }
            List <Vector3FP> path = graph.GetPath();

            if (!locomotor_cmp.MoveAlongPath(path, false))
            {
                return(false);
            }
            //m_destination = destination;
            return(true);
        }
예제 #9
0
        void OnPick(RaycastHit hit)
        {
            GameObject         go      = hit.transform.gameObject;
            UnityObjectBinding binding = go.GetComponent <UnityObjectBinding>();

            if (binding == null)
            {
                Debug.Log("RenderWorld.OnPick(), YOU CHOOSE A POINT" + hit.point.ToString());
                if (m_current_operate_entityi_id < 0)
                {
                    return;
                }
                RenderEntity render_entity = m_render_entity_manager.GetObject(m_current_operate_entityi_id);
                if (render_entity == null)
                {
                    return;
                }
                LocomotorComponent locomotor_component = render_entity.GetLogicEntity().GetComponent(LocomotorComponent.ID) as LocomotorComponent;
                if (locomotor_component == null || !locomotor_component.IsEnable())
                {
                    return;
                }
                EntityMoveCommand cmd = Command.Create <EntityMoveCommand>();
                cmd.ConstructAsDestination(m_current_operate_entityi_id, Vector3_To_Vector3FP(hit.point));
                PushLocalCommand(cmd);
#if UNITY_EDITOR
                if (m_draw_grid && m_grid_graph != null)
                {
                    PositionComponent position_component = render_entity.GetLogicEntity().GetComponent(PositionComponent.ID) as PositionComponent;
                    if (!m_grid_graph.FindPath(position_component.CurrentPosition, Vector3_To_Vector3FP(hit.point)))
                    {
                        Debug.LogError("FindPath Failed!");
                    }
                    else
                    {
                        List <Vector3FP> path = m_grid_graph.GetPath();
                        m_current_path.Clear();
                        for (int i = 0; i < path.Count; ++i)
                        {
                            m_current_path.Add(Vector3FP_To_Vector3(path[i]));
                        }
                    }
                }
#endif
            }
            else
            {
                RenderEntity render_entity = m_render_entity_manager.GetObject(binding.EntityID);
                if (render_entity == null)
                {
                    return;
                }
                if (m_combat_client.LocalPlayerPstid == m_logic_world.GetPlayerManager().Objectid2Pstid(render_entity.GetOwnerPlayerID()))
                {
                    m_current_operate_entityi_id = binding.EntityID;
                    Debug.Log("RenderWorld.OnPick(), YOU CHOOSE YOUR ENTITY " + hit.transform.parent.name);
                }
                else
                {
                    Debug.Log("RenderWorld.OnPick(), YOU CHOOSE AN ENEMY " + hit.transform.parent.name);
                    if (m_current_operate_entityi_id < 0)
                    {
                        return;
                    }
                    EntityTargetCommand cmd = Command.Create <EntityTargetCommand>();
                    cmd.Construct(m_current_operate_entityi_id, render_entity.ID);
                    PushLocalCommand(cmd);
#if UNITY_EDITOR
                    if (m_draw_grid && m_grid_graph != null)
                    {
                        RenderEntity      self_entity               = m_render_entity_manager.GetObject(m_current_operate_entityi_id);
                        PositionComponent self_position_component   = self_entity.GetLogicEntity().GetComponent(PositionComponent.ID) as PositionComponent;
                        PositionComponent target_position_component = render_entity.GetLogicEntity().GetComponent(PositionComponent.ID) as PositionComponent;
                        if (!m_grid_graph.FindPath(self_position_component.CurrentPosition, target_position_component.CurrentPosition))
                        {
                            Debug.LogError("FindPath Failed!");
                        }
                        else
                        {
                            List <Vector3FP> path = m_grid_graph.GetPath();
                            m_current_path.Clear();
                            for (int i = 0; i < path.Count; ++i)
                            {
                                m_current_path.Add(Vector3FP_To_Vector3(path[i]));
                            }
                        }
                    }
#endif
                }
            }
        }
예제 #10
0
        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);
                }
            }
        }
예제 #11
0
        CastSkillResult CheckActivate(bool just_test)
        {
            if (!IsReady())
            {
                return(CastSkillResult.InCooldown);
            }

            if (!m_owner_component.CanActivateSkill())
            {
                if (!m_definition_component.CanActivateWhenDisabled)
                {
                    return(CastSkillResult.SkillDisabled);
                }
            }

            FixPoint mana_cost = m_definition_component.ManaCost;

            if (mana_cost > FixPoint.Zero)
            {
                if (m_mana_component.GetCurrentManaPoint(m_definition_component.ManaType) < mana_cost)
                {
                    return(CastSkillResult.NotEnoughMana);
                }
            }

            bool built_targets = false;

            LocomotorComponent locomotor_cmp = m_owner_component.GetLocomotorComponent();

            if (locomotor_cmp != null && locomotor_cmp.IsMoving)
            {
                if (!m_definition_component.CanActivateWhileMoving)
                {
                    return(CastSkillResult.ObjectIsMoving);
                }
                if (just_test && m_definition_component.MovingActivatingMustHaveTarget)
                {
                    if (!built_targets)
                    {
                        BuildSkillTargets();
                        built_targets = true;
                    }
                    if (m_skill_targets.Count == 0)
                    {
                        return(CastSkillResult.NotEnoughTargets);
                    }
                }
            }

            if (m_definition_component.ExternalDataType == SkillDefinitionComponent.NeedExternalOffset)
            {
                if (m_definition_component.ExternalVector.Length() > m_definition_component.AimParam1)
                {
                    return(CastSkillResult.CheatedExternalData);
                }
            }

            if (m_definition_component.TargetsMinCountForActivate > 0)
            {
                if (!built_targets)
                {
                    BuildSkillTargets();
                    built_targets = true;
                }
                if (m_skill_targets.Count < m_definition_component.TargetsMinCountForActivate)
                {
                    return(CastSkillResult.NotEnoughTargets);
                }
            }

            var enumerator = m_components.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SkillComponent cmp = enumerator.Current.Value as SkillComponent;
                if (cmp != null && !cmp.CanActivate())
                {
                    return(CastSkillResult.ComponnetUnavailable);
                }
            }

            return(CastSkillResult.Success);
        }
예제 #12
0
 public override void OnReset()
 {
     m_component = null;
 }
예제 #13
0
 public void Construct(LocomotorComponent component)
 {
     m_component = component;
 }