Esempio 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);
    }
Esempio 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);
    }
Esempio n. 4
0
    private void SelectTargetPos(EntityInfo npc)
    {
        ScriptRuntime.Vector3 pos = npc.GetMovementStateInfo().GetPosition3D();
        float dx = Helper.Random.Next(m_Radius) - m_Radius / 2;
        float dz = Helper.Random.Next(m_Radius) - m_Radius / 2;

        pos.X += dx;
        pos.Z += dz;
        npc.GetMovementStateInfo().TargetPosition = AiCommand.AiGetValidPosition(npc, pos, m_Radius);
    }
Esempio n. 5
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);
    }
Esempio n. 6
0
    public bool ExecCommand(StoryInstance instance, StoryValueParams _params, long delta)
    {
        ArrayList args = _params.Values;

        if (!m_KeepAwayStarted)
        {
            m_KeepAwayStarted = true;

            m_ObjId     = (int)args[0];
            m_SkillInfo = args[1] as SkillInfo;
            m_Ratio     = (float)System.Convert.ChangeType(args[2], typeof(float));
        }
        EntityInfo npc = PluginFramework.Instance.GetEntityById(m_ObjId);

        if (null != npc && !npc.IsUnderControl())
        {
            AiStateInfo info   = npc.GetAiStateInfo();
            EntityInfo  target = PluginFramework.Instance.GetEntityById(info.Target);
            if (null != target && null != m_SkillInfo)
            {
                info.Time += delta;
                if (info.Time > 100)
                {
                    info.Time = 0;
                }
                else
                {
                    return(true);
                }
                ScriptRuntime.Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
                ScriptRuntime.Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D();
                float distSqr             = Geometry.DistanceSquare(srcPos, targetPos);
                ScriptRuntime.Vector3 dir = srcPos - targetPos;
                dir.Normalize();
                targetPos = targetPos + dir * m_Ratio * m_SkillInfo.Distance;
                if (distSqr < m_Ratio * m_Ratio * m_SkillInfo.Distance * m_SkillInfo.Distance)
                {
                    AiCommand.AiPursue(npc, targetPos);
                    return(true);
                }
            }
        }
        return(false);
    }
Esempio n. 7
0
    public bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, StoryValueParams _params, long delta)
    {
        ArrayList args = _params.Values;

        if (!m_ChaseStarted)
        {
            m_ChaseStarted = true;

            m_ObjId     = (int)args[0];
            m_SkillInfo = args[1] as SkillInfo;
        }
        EntityInfo npc = PluginFramework.Instance.GetEntityById(m_ObjId);

        if (null != npc && !npc.IsUnderControl())
        {
            AiStateInfo info   = npc.GetAiStateInfo();
            EntityInfo  target = PluginFramework.Instance.GetEntityById(info.Target);
            if (null != target && null != m_SkillInfo)
            {
                info.Time += delta;
                if (info.Time > 100)
                {
                    info.Time = 0;
                }
                else
                {
                    return(true);
                }
                ScriptRuntime.Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
                ScriptRuntime.Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D();
                float distSqr = Geometry.DistanceSquare(srcPos, targetPos);
                if (distSqr > m_SkillInfo.Distance * m_SkillInfo.Distance)
                {
                    AiCommand.AiPursue(npc, targetPos);
                    return(true);
                }
            }
        }
        return(false);
    }
Esempio n. 8
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);
    }
    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);
    }