Exemplo n.º 1
0
 public static float FSM_Avoid_Battle(AIEntity pEntity)
 {
     if (pEntity.GetComponent <ObstacleComponent> ().hitObject.tag == "Battleable")
     {
         return(1.0f);
     }
     else
     {
         return(0.0f);
     }
 }
Exemplo n.º 2
0
 public void Run(AIEntity pEntity)
 {
     pEntity.GetComponent <AIState> ().LastEntityData.GetComponent <AIMove> ().mDirection = pEntity.GetComponent <AIMove> ().mDirection;
     pEntity.GetComponent <AIState> ().LastEntityData.GetComponent <AIMove> ().mVelocity  = pEntity.GetComponent <AIMove> ().mVelocity;
     pEntity.GetComponent <AIState> ().LastEntityData.GetComponent <AIMove> ().mMoveFunc  = pEntity.GetComponent <AIMove> ().mMoveFunc;
     pEntity.GetComponent <AIState> ().LastEntityData.AIPos     = pEntity.AIPos;
     pEntity.GetComponent <AIState> ().LastEntityData.PlayerPos = pEntity.PlayerPos;
     pEntity.GetComponent <AIState> ().LastEntityData.GetComponent <AIAnimation> ().mtempAnim = pEntity.GetComponent <AIAnimation> ().mtempAnim;
 }
Exemplo n.º 3
0
        public static void FSM_Avoid(AIEntity pEntity)
        {
            if (pEntity.GetComponent <ObstacleComponent> ().target == Vector3.zero)
            {
                Vector3 v1 = pEntity.GetComponent <ObstacleComponent> ().hitObject.transform.position - pEntity.AIPos;
                v1.y = 0.0f;
                Vector3 v2 = new Vector3(1.0f, 0.0f, -v1.x / v1.z);
                v2.Normalize();
                Vector3 v3 = -v2;
                for (int i = 0; i <= 10; i++)
                {
                    float   tempRate = (float)i / 10.0f;
                    Vector3 vdir1    = Vector3.Lerp(v1, v2, tempRate);
                    vdir1.Normalize();
                    Vector3 vdir2 = Vector3.Lerp(v1, v3, tempRate);
                    vdir2.Normalize();
                    float      maxDis     = 2.0f;
                    LayerMask  layoutmask = 1 << LayerMask.NameToLayer("Collision");
                    RaycastHit hit        = new RaycastHit();
                    if (!Physics.Raycast(pEntity.GetComponent <BaseAIComponent> ().mAIRT.transform.position, vdir1, out hit, maxDis, layoutmask))
                    {
                        pEntity.GetComponent <ObstacleComponent> ().target = pEntity.GetComponent <BaseAIComponent> ().mAIRT.transform.position + vdir1 * maxDis;
                        break;
                    }
                    if (!Physics.Raycast(pEntity.GetComponent <BaseAIComponent> ().mAIRT.transform.position, vdir2, out hit, maxDis, layoutmask))
                    {
                        pEntity.GetComponent <ObstacleComponent> ().target = pEntity.GetComponent <BaseAIComponent> ().mAIRT.transform.position + vdir2 * maxDis;
                        break;
                    }
                }
            }
            float tdis = Vector3.Distance(pEntity.GetComponent <ObstacleComponent>().target, pEntity.AIPos);

            if (tdis < 0.15f)
            {
                pEntity.GetComponent <AIMove> ().mDirection = Vector3.zero;
                pEntity.GetComponent <AIMove> ().mVelocity  = 0.0f;
                return;
            }
            Vector3 tdir = pEntity.GetComponent <ObstacleComponent> ().target - pEntity.AIPos;

            tdir.y = 0.0f;
            pEntity.GetComponent <AIMove> ().mDirection = tdir.normalized;
            pEntity.GetComponent <AIMove> ().mVelocity  = 5.0f;
        }
Exemplo n.º 4
0
 public static void Strategy_Enter(AIEntity pEntity)
 {
     pEntity.GetComponent <ObstacleComponent> ().target = Vector3.zero;
 }
Exemplo n.º 5
0
        public override void Update(UEntity uEntity)
        {
            base.Update(uEntity);
            if (!uEntity.GetComponent <AIStrategy> ().isEnable)
            {
                return;
            }
            AIEntity pEntity = (AIEntity)uEntity;
            // get lod now
            int lod = uEntity.GetComponent <LODComponent> ().mLOD;

            // compute logic update velocity
            lod = lod * lod * lod;
            // update logic with lod
            if (pEntity.GetComponent <AIStrategy> ().timer <= 0.2f * lod)
            {
                pEntity.GetComponent <AIStrategy> ().timer += Time.deltaTime;
                return;
            }

            pEntity.GetComponent <AIStrategy> ().timer = 0.0f;
            // having cache ?
            if (pEntity.GetComponent <AIStrategy> ().IDBuffer != -1)
            {
                if (pEntity.GetComponent <AIStrategy> ().BufferFrame != 0)
                {
                    pEntity.GetComponent <AIStrategy> ().BufferFrame--;
                }
                else
                {
                    pEntity.GetComponent <AIStrategy> ().IDBuffer = -1;
                }
                return;
            }
            //the min value of the strategy action
            float minValue = 0.15f;
            // the max
            actionNode tActionNode1 = new actionNode();

            tActionNode1.action = 0.0f;
            tActionNode1.mid    = -1;
            // the second max
            actionNode tActionNode2 = new actionNode();

            tActionNode2.action = 0.0f;
            tActionNode2.mid    = -1;

            for (int i = 0; i < pEntity.GetComponent <AIStrategy> ().tempCount; i++)
            {
                float tempRate = pEntity.GetComponent <AIStrategy> ().mStrategyActioner [i](pEntity);
                tempRate *= pEntity.GetComponent <AIStrategy> ().mPower [i];
                if (tempRate > tActionNode1.action)
                {
                    tActionNode2.action = tActionNode1.action;
                    tActionNode2.mid    = tActionNode1.mid;
                    tActionNode1.action = tempRate;
                    tActionNode1.mid    = i;
                }
                else if (tempRate > tActionNode2.action)
                {
                    tActionNode2.action = tempRate;
                    tActionNode2.mid    = i;
                }
            }

            if (tActionNode1.action > minValue)
            {
                if (tActionNode1.mid == pEntity.GetComponent <AIStrategy> ().tempID)
                {
                    return;
                }
                // transfer, so compute the last frame data
                if (pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter != 10)
                {
                    float sum = 0.0f;
                    for (int i = 0; i < 10 - pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter; i++)
                    {
                        sum += pEntity.GetComponent <AIStrategy> ().bufferdata [i];
                    }
                    sum /= 10 - pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter;
                    pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] += sum;
                    if (pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] > 3.0f)
                    {
                        pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] = 3.0f;
                    }
                    if (pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] < 0.3f)
                    {
                        pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] = 0.3f;
                    }
                    pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter = 10;
                }
                pEntity.GetComponent <AIStrategy> ().LastID             = pEntity.GetComponent <AIStrategy> ().tempID;
                pEntity.GetComponent <AIStrategy> ().mFrameCaptureStart = true;

                for (int i = 0; i < pEntity.GetComponent <AIState> ().mtempCount; i++)
                {
                    for (int j = 0; j < pEntity.GetComponent <AIStrategy> ().mAIState [pEntity.GetComponent <AIStrategy> ().tempID].mPowerEdge [i].Count; j++)
                    {
                        PowerNode pnt = new PowerNode();
                        pnt.id    = pEntity.GetComponent <AIState> ().mPowerEdge [i] [j].id;
                        pnt.power = pEntity.GetComponent <AIState> ().mPowerEdge [i] [j].power;
                        pEntity.GetComponent <AIStrategy> ().mAIState [pEntity.GetComponent <AIStrategy> ().tempID].mPowerEdge [i] [j] = pnt;
                    }
                }
                // update Strategy
                pEntity.GetComponent <AIStrategy> ().mStrategyExit[pEntity.GetComponent <AIStrategy>().tempID](pEntity);
                pEntity.GetComponent <AIStrategy> ().SetEntry(tActionNode1.mid);
                pEntity.GetComponent <AIStrategy> ().mStrategyEnter[pEntity.GetComponent <AIStrategy>().tempID](pEntity);
                // update cache
                if (tActionNode1.action - tActionNode2.action > 0.3f)
                {
                    pEntity.GetComponent <AIStrategy> ().IDBuffer    = pEntity.GetComponent <AIStrategy> ().tempID;
                    pEntity.GetComponent <AIStrategy> ().BufferFrame = 6;
                }
            }
        }
Exemplo n.º 6
0
        /*
         * @param pEntity: Find center Entity
         * @param riaus:Find riaus
         *
         * get all AIEntity in the riaus by the center of Entity
         *
         * @return:the OK AIEntity set
         *
         */

        public static AIEntity[] getAllEntityWithSphere(AIEntity pEntity, float riaus)
        {
            Collider[]      tColliders = Physics.OverlapSphere(pEntity.AIPos, riaus);
            List <AIEntity> tList      = new List <AIEntity> ();

            for (int i = 0; i < tColliders.Length; i++)
            {
                foreach (AIEntity aie in AIEntity.getList())
                {
                    if (aie.GetComponent <BaseAIComponent>().mAIRT == tColliders [i].gameObject && aie.GetComponent <BaseAIComponent>().mAIRT != pEntity.GetComponent <BaseAIComponent>().mAIRT)
                    {
                        tList.Add(aie);
                        break;
                    }
                }
            }
            return(tList.ToArray());
        }