Ejemplo n.º 1
0
    private bool GohomeHandler(EntityInfo entity, AiStateInfo info, long deltaTime)
    {
        info.Time += deltaTime;
        if (info.Time > c_IntervalTime)
        {
            info.Time = 0;

            EntityInfo leader = AiLogicUtility.GetLivingCharacterInfoHelper(entity, info.LeaderId);
            if (null != leader)
            {
                float minDist = entity.GetRadius() + leader.GetRadius();
                ScriptRuntime.Vector3 targetPos = GetHomePos(entity.GetMovementStateInfo().FormationIndex, leader);
                ScriptRuntime.Vector3 srcPos    = entity.GetMovementStateInfo().GetPosition3D();
                float powDistToHome             = Geometry.DistanceSquare(srcPos, targetPos);
                if (powDistToHome <= (minDist + 1) * (minDist + 1))
                {
                    AiCommand.AiStopPursue(entity);
                    info.ChangeToState((int)PredefinedAiStateId.Idle);
                    return(false);
                }
                else
                {
                    AiCommand.AiPursue(entity, targetPos);
                }
            }
            else
            {
                AiCommand.AiStopPursue(entity);
                info.ChangeToState((int)PredefinedAiStateId.Idle);
                return(false);
            }
        }
        return(true);
    }
Ejemplo n.º 2
0
    private bool GohomeHandler(EntityInfo npc, AiStateInfo info, long deltaTime)
    {
        info.Time += deltaTime;
        if (info.Time > 100)
        {
            info.Time = 0;
        }
        else
        {
            return(true);
        }

        ScriptRuntime.Vector3 targetPos = info.HomePos;
        ScriptRuntime.Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
        float distSqr = Geometry.DistanceSquare(srcPos, info.HomePos);

        if (distSqr <= 1)
        {
            npc.GetMovementStateInfo().IsMoving = false;
            AiCommand.AiStopPursue(npc);
            info.ChangeToState((int)PredefinedAiStateId.Idle);
            return(false);
        }
        else
        {
            npc.GetMovementStateInfo().IsMoving       = true;
            npc.GetMovementStateInfo().TargetPosition = targetPos;
            AiCommand.AiPursue(npc, targetPos);
        }
        return(true);
    }
    public bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, StoryValueParams _params, long delta)
    {
        var args = _params.Values;

        if (!m_ParamReaded)
        {
            m_ObjId     = args[0];
            m_SkillInfo = args[1].ObjectVal as SkillInfo;
        }
        if (!m_SkillCasted)
        {
            EntityInfo npc = PluginFramework.Instance.GetEntityById(m_ObjId);
            if (null != npc && !npc.IsUnderControl())
            {
                int        targetId = npc.GetAiStateInfo().Target;
                EntityInfo target   = PluginFramework.Instance.GetEntityById(targetId);
                if (null != target && !target.IsDead() && Geometry.DistanceSquare(npc.GetMovementStateInfo().GetPosition3D(), target.GetMovementStateInfo().GetPosition3D()) <= m_SkillInfo.Distance * m_SkillInfo.Distance)
                {
                    ScriptRuntime.Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
                    ScriptRuntime.Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D();
                    float dir    = Geometry.GetYRadian(srcPos, targetPos);
                    float curDir = npc.GetMovementStateInfo().GetFaceDir();
                    if (Mathf.Abs(dir - curDir) > 0.157f)
                    {
                        npc.GetMovementStateInfo().SetWantedFaceDir(dir);
                    }
                    else
                    {
                        m_SkillCasted = true;
                        AiCommand.AiStopPursue(npc);
                        AiCommand.AiSkill(npc, m_SkillInfo.SkillId);
                    }
                    return(true);
                }
                else if (!m_SkillInfo.ConfigData.skillData.needTarget)
                {
                    m_SkillCasted = true;
                    AiCommand.AiStopPursue(npc);
                    AiCommand.AiSkill(npc, m_SkillInfo.SkillId);
                }
            }
        }
        else
        {
            EntityInfo npc = PluginFramework.Instance.GetEntityById(m_ObjId);
            if (null != npc)
            {
                AiStateInfo info = npc.GetAiStateInfo();
                if (npc.GetSkillStateInfo().IsSkillActivated())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        return(false);
    }
Ejemplo n.º 4
0
    private bool RandMoveHandler(EntityInfo npc, AiStateInfo info, long deltaTime)
    {
        info.Time        += deltaTime;
        m_PursueInterval += deltaTime;
        if (info.Time > m_Time)
        {
            info.Time = 0;
            npc.GetMovementStateInfo().IsMoving = false;
            AiCommand.AiStopPursue(npc);
            info.ChangeToState((int)PredefinedAiStateId.Idle);
            EntityInfo target = PluginFramework.Instance.GetEntityById(info.Target);
            if (null != target)
            {
                float dir = Geometry.GetYRadian(npc.GetMovementStateInfo().GetPosition3D(), target.GetMovementStateInfo().GetPosition3D());
                npc.GetMovementStateInfo().SetFaceDir(dir);
            }
            return(false);
        }
        if (m_PursueInterval < 100)
        {
            return(true);
        }
        else
        {
            m_PursueInterval = 0;
        }

        ScriptRuntime.Vector3 targetPos = npc.GetMovementStateInfo().TargetPosition;
        ScriptRuntime.Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
        float distSqr = Geometry.DistanceSquare(srcPos, targetPos);

        if (distSqr <= 1)
        {
            if (npc.GetMovementStateInfo().IsMoving)
            {
                npc.GetMovementStateInfo().IsMoving = false;
                AiCommand.AiStopPursue(npc);
                info.ChangeToState((int)PredefinedAiStateId.Idle);
            }
        }
        else
        {
            npc.GetMovementStateInfo().IsMoving = true;
            AiCommand.AiPursue(npc, targetPos);
        }
        return(true);
    }
Ejemplo n.º 5
0
    private bool CombatHandler(EntityInfo npc, AiStateInfo info, long deltaTime)
    {
        if (npc.GetSkillStateInfo().IsSkillActivated())
        {
            return(true);
        }

        EntityInfo leader = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.LeaderId);

        ScriptRuntime.Vector3 srcPos  = npc.GetMovementStateInfo().GetPosition3D();
        ScriptRuntime.Vector3 homePos = ScriptRuntime.Vector3.Zero;
        if (null != leader)
        {
            homePos = GetHomePos(npc.GetMovementStateInfo().FormationIndex, leader);
        }
        float distSqrToHome = Geometry.DistanceSquare(srcPos, homePos);

        if (distSqrToHome > npc.GohomeRange * npc.GohomeRange)
        {
            AiCommand.AiStopPursue(npc);
            info.ChangeToState((int)AiStateId.Gohome);
            return(true);
        }

        ///
        EntityInfo     attackTarget = null;
        SkillStateInfo currSkInfo   = npc.GetSkillStateInfo();
        ///找到可以使用的技能
        SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc);

        AiCommand.AiSelectSkill(npc, skInfo);
        if (skInfo == null)
        {
            //没有可以使用的技能就切换到Idle状态
            info.ChangeToState((int)PredefinedAiStateId.Idle);
            return(false);
        }

        CharacterRelation relation =
            (skInfo.TargetType == SkillTargetType.Friend ||
             skInfo.TargetType == SkillTargetType.RandFriend) ?
            CharacterRelation.RELATION_FRIEND :
            CharacterRelation.RELATION_ENEMY;

        attackTarget = AiLogicUtility.GetNearstTargetHelper(
            npc, skInfo.Distance, relation);

        if (attackTarget != null && null != skInfo)   //攻击范围内找到可攻击目标
        {
            info.Target = attackTarget.GetId();
            AiCommand.AiStopPursue(npc);
            AiCommand.AiSkill(npc, skInfo.SkillId); //攻击目标
            return(true);
        }
        attackTarget = AiLogicUtility.GetNearstTargetHelper(
            npc, npc.ViewRange, relation);
        if (attackTarget != null)                                                         //视野范围内找到可攻击目标
        {
            AiCommand.AiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D()); // 追赶目标
            return(true);
        }

        currSkInfo.SetCurSkillInfo(0);
        AiCommand.AiStopPursue(npc);
        info.ChangeToState((int)AiStateId.Gohome);
        return(true);
    }
Ejemplo n.º 6
0
    private bool CombatHandler(EntityInfo npc, AiStateInfo info, long deltaTime)
    {
        info.Time += deltaTime;
        if (info.Time > 100)
        {
            info.Time = 0;
        }
        else
        {
            return(true);
        }

        if (npc.GetSkillStateInfo().IsSkillActivated())
        {
            return(true);
        }

        ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
        float distSqrToHome          = Geometry.DistanceSquare(srcPos, info.HomePos);

        if (distSqrToHome > npc.GohomeRange * npc.GohomeRange)
        {
            AiCommand.AiStopPursue(npc);
            info.ChangeToState((int)AiStateId.Gohome);
            return(true);
        }

        ///
        EntityInfo     attackTarget = null;
        SkillStateInfo currSkInfo   = npc.GetSkillStateInfo();
        ///找到可以使用的技能
        SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc);

        AiCommand.AiSelectSkill(npc, skInfo);
        if (skInfo == null)
        {
            AiCommand.AiStopPursue(npc);
            info.ChangeToState((int)PredefinedAiStateId.Idle);
            return(false);
        }

        CharacterRelation relation = skInfo.ConfigData.targetType == (int)SkillTargetType.Friend ?
                                     CharacterRelation.RELATION_FRIEND :
                                     CharacterRelation.RELATION_ENEMY;

        attackTarget = AiLogicUtility.GetNearstTargetHelper(
            npc, skInfo.Distance, relation);

        if (attackTarget != null && null != skInfo) //攻击范围内找到可攻击目标
        {
            info.Target = attackTarget.GetId();
            ScriptRuntime.Vector3 targetPos = attackTarget.GetMovementStateInfo().GetPosition3D();
            float dir    = Geometry.GetYRadian(srcPos, targetPos);
            float curDir = npc.GetMovementStateInfo().GetFaceDir();
            if (Mathf.Abs(dir - curDir) > 0.157f)
            {
                npc.GetMovementStateInfo().SetWantedFaceDir(dir);
            }
            else
            {
                AiCommand.AiStopPursue(npc);
                AiCommand.AiSkill(npc, skInfo.SkillId); //攻击目标
            }
            return(true);
        }
        attackTarget = AiLogicUtility.GetNearstTargetHelper(
            npc, npc.ViewRange, relation);
        if (attackTarget != null)                                                         //视野范围内找到可攻击目标
        {
            AiCommand.AiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D()); // 追赶目标
            return(true);
        }

        currSkInfo.SetCurSkillInfo(0);
        AiCommand.AiStopPursue(npc);
        return(true);
    }