Exemplo n.º 1
0
        public void DoRun(SimpleAI sAI, string code)
        {
            if (code == "Die")
            {
                sAI.Destroy();
            }

            TreeObject to = (TreeObject)sAI.mCharacter;

            if (to.timer < 1.0f)
            {
                to.timer += Time.deltaTime;
                return;
            }
            SimpleAI[] SimpleAIs = SimpleAISetSingleton.getInstance().GetComponent <SimpleAISet> ().FindAIsWithRiaus(sAI.mAIRT.transform.position, 5.0f, 1 << LayerMask.NameToLayer("Default"), "Glass");
            to.timer      = 0.0f;
            to.mTempLife -= 180 + (int)(30 * to.mStrongRate);
            for (int i = 0; i < SimpleAIs.Length; i++)
            {
                glassObject go = (glassObject)SimpleAIs [i].mCharacter;
                if (go.mHp > 500)
                {
                    to.mTempLife += (int)(go.mHp / 500.0f);
                    //Debug.Log ("Grass");
                }
            }
        }
Exemplo n.º 2
0
        public override void Update(UEntity uEntity)
        {
            base.Update(uEntity);
            Vector3 pos      = uEntity.GetComponent <ZoologyComponent> ().mPosition;
            float   maxRiaus = Mathf.Max(uEntity.GetComponent <ZoologyComponent>().mSize.x, uEntity.GetComponent <ZoologyComponent>().mSize.y);

            SimpleAI[]          tSimpleAIs = SimpleAISetSingleton.getInstance().GetComponent <SimpleAISet> ().FindAIsWithRiaus(pos, maxRiaus, 1 << LayerMask.NameToLayer("Default"), "AI");
            List <GAPopulation> tList      = new List <GAPopulation> ();

            for (int i = 0; i < tSimpleAIs.Length; i++)
            {
                if (!tList.Contains(GAPopulation.allDic[tSimpleAIs[i].mType]))
                {
                    tList.Add(GAPopulation.allDic[tSimpleAIs[i].mType]);
                }
            }
            float avgRate = 0.0f;

            foreach (var v in tList)
            {
                avgRate += v.lifeRate;
            }
            avgRate /= tList.Count;
            if (avgRate < 0.2f)
            {
                uEntity.GetComponent <ZoologyComponent> ().mState = false;
            }
            else
            {
                uEntity.GetComponent <ZoologyComponent> ().mState = true;
            }
        }
Exemplo n.º 3
0
        public void DoRun(SimpleAI sAI, string code)
        {
            if (code == "Die")
            {
                sAI.Destroy();
            }
            glassObject go = (glassObject)sAI.mCharacter;

            if (go.timer < 1.0f)
            {
                go.timer += Time.deltaTime;
                return;
            }
            SimpleAI[] SimpleAIs = SimpleAISetSingleton.getInstance().GetComponent <SimpleAISet> ().FindAIsWithRiaus(sAI.mAIRT.transform.position, 5.0f, 1 << LayerMask.NameToLayer("Default"), "Tree");
            go.timer = 0.0f;

            go.mHp -= 50;
            for (int i = 0; i < SimpleAIs.Length; i++)
            {
                TreeObject to = (TreeObject)SimpleAIs [i].mCharacter;
                if (to.mTempLife > 1500)
                {
                    go.mHp += (int)(to.mTempLife / 50.0f);
                }
            }
        }
Exemplo n.º 4
0
        public void RePairRTObject()
        {
            if (mRTObjectSet != null)
            {
                for (int i = 0; i < mRTObjectSet.Length; i++)
                {
                    GameObject.Destroy(mRTObjectSet [i].mAIRT);
                    SimpleAISetSingleton.getInstance().GetComponent <SimpleAISet> ().Delete(mRTObjectSet [i]);
                }
            }

            mRTObjectSet = new SimpleAI[mGAObjectSet.Length];

            for (int i = 0; i < mRTObjectSet.Length; i++)
            {
                mRTObjectSet [i] = new SimpleAI();
                mRTObjectSet [i].Init(mRTObjectRunner, mRTObjectJudger, mPrefab, mPlayer, mGAObjectSet[i].mPosition);
                mRTObjectSet [i].mSimpleAIDestroyer = mRTObjectDestroyer;
                mRTObjectSet [i].mSimpleAIRepairer  = mSimpleAIRePairer;
                mRTObjectSet [i].mType      = mRTType;
                mRTObjectSet [i].mCharacter = mGAObjectSet [i];
                mRTObjectSet [i].mSimpleAIRepairer.DoRePair(mRTObjectSet[i]);
                mRTObjectSet [i].mName = mRTType + "index" + i;
            }
        }
Exemplo n.º 5
0
 public static SimpleAISetSingleton getInstance()
 {
     if (mSimpleAISetSingleton == null)
     {
         mSimpleAISetSingleton = new SimpleAISetSingleton();
     }
     return(mSimpleAISetSingleton);
 }
Exemplo n.º 6
0
 public void Init(SimpleAIRunner pSimpleAIRunner, SimpleAIStateJudger pSimpleAIStateJudger, GameObject pAITemplete, GameObject pPlayer, Vector3 pPos)
 {
     ECSWorld.MainWorld.registerEntityAfterInit(this);
     mSimpleAIRunner      = pSimpleAIRunner;
     mSimpleAIStateJudger = pSimpleAIStateJudger;
     mAITemplate          = pAITemplete;
     mPlayer     = pPlayer;
     GeneratePos = pPos;
     mAIRT       = GameObject.Instantiate(mAITemplate, GeneratePos, Quaternion.identity) as GameObject;
     this.AddComponent <LODComponent> (new LODComponent());
     SimpleAISetSingleton.getInstance().GetComponent <SimpleAISet> ().mSimpleAIList.Add(this);
     this.AddComponent <AIMove> (new AIMove());
 }
Exemplo n.º 7
0
 // register all entity default
 public override void registerAllEntity()
 {
     base.registerAllEntity();
     registerEntity(SimpleAISetSingleton.getInstance());
     registerEntity(InfluenceMapSingleton.getInstance());
     GameObject[] allCollision = GameObject.FindGameObjectsWithTag("Collision");
     GameObject[] allBarrier   = GameObject.FindGameObjectsWithTag("Barrier");
     for (int i = 0; i < allCollision.Length; i++)
     {
         CollisionEntity tEntity = new CollisionEntity();
         tEntity.mGameObject = allCollision [i];
         registerEntity(tEntity);
     }
     for (int i = 0; i < allBarrier.Length; i++)
     {
         CollisionEntity tEntity = new CollisionEntity();
         tEntity.mGameObject = allBarrier [i];
         registerEntity(tEntity);
     }
     //	registerEntity (GroupManagerEntity.getInstance());
     registerEntity(GroupManagerEntity.getInstance());
     registerEntity(AntPopulationEntity.getInstance());
 }
Exemplo n.º 8
0
        public void DoRun(SimpleAI sAI, string code)
        {
            string s = code;

            ((CowObject)sAI.mCharacter).timer += Time.deltaTime;
            if (((int)((CowObject)sAI.mCharacter).timer) - ((CowObject)sAI.mCharacter).lastTime > 0)
            {
                ((CowObject)sAI.mCharacter).mTempLife -= 30 + (int)(10 * ((CowObject)sAI.mCharacter).mStrongRate);
                ((CowObject)sAI.mCharacter).lastTime   = ((int)((CowObject)sAI.mCharacter).timer);
            }
            if (code == "Die")
            {
                sAI.Destroy();
            }
            else if (code == "Round")
            {
                ((CowObject)sAI.mCharacter).mGlassTarget = null;
                if (((CowObject)sAI.mCharacter).RoundTimer > 0.0f && (((CowObject)sAI.mCharacter)).RoundTarget != Vector3.zero)
                {
                    float distance = Vector3.Distance(sAI.mAIRT.transform.position, ((CowObject)sAI.mCharacter).RoundTarget);
                    if (distance > 1.5f)
                    {
                        sAI.GetComponent <AIMove> ().mDirection   = ((CowObject)sAI.mCharacter).RoundTarget - sAI.mAIRT.transform.position;
                        sAI.GetComponent <AIMove> ().mDirection.y = 0.0f;
                        sAI.GetComponent <AIMove> ().mVelocity    = ((CowObject)sAI.mCharacter).mVelocity;
                    }
                    else
                    {
                        sAI.GetComponent <AIMove> ().mVelocity = 0.0f;
                    }
                    ((CowObject)sAI.mCharacter).RoundTimer -= Time.deltaTime;
                }
                else
                {
                    ((CowObject)sAI.mCharacter).RoundTimer  = 4.5f;
                    ((CowObject)sAI.mCharacter).RoundTarget = sAI.GeneratePos + new Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10));
                }
            }
            else
            {
                ((CowObject)sAI.mCharacter).RoundTarget = Vector3.zero;
                ((CowObject)sAI.mCharacter).RoundTimer  = 0.0f;
                if (((CowObject)sAI.mCharacter).mGlassTarget == null || ((CowObject)sAI.mCharacter).mGlassTarget.mAIRT == null)
                {
                    SimpleAI[] SimpleAIs  = SimpleAISetSingleton.getInstance().GetComponent <SimpleAISet> ().FindAIsWithRiaus(sAI.mAIRT.transform.position, 9.5f, 1 << LayerMask.NameToLayer("Default"), "Glass");
                    int        startIndex = Random.Range(0, SimpleAIs.Length);
                    bool       Type       = ((CowObject)sAI.mCharacter).Type;
                    for (int i = startIndex; i < SimpleAIs.Length; i++)
                    {
                        float f2 = ComputeGreen(SimpleAIs[i]);
                        if (f2 > 0.5f && f2 < 0.75f)
                        {
                            f2 += 0.25f;
                        }
                        else if (f2 < 0.5f && f2 > 0.25f)
                        {
                            f2 -= 0.25f;
                        }

                        if (Type)
                        {
                            f2 = f2;
                            if (f2 < 0.15f)
                            {
                                f2 -= 0.11f;
                            }
                        }
                        else
                        {
                            f2 = 1.0f - f2;
                            if (f2 < 0.15f)
                            {
                                f2 -= 0.11f;
                            }
                        }

                        if (Random.Range(0.0f, 1.0f) < f2)
                        {
                            ((CowObject)sAI.mCharacter).mGlassTarget = SimpleAIs [i];
                            //Debug.Log (SimpleAIs[i].mAIRT.GetComponent<MeshRenderer>().material.color+"  "+Type.ToString());
                            break;
                        }
                    }
                    s += "Finding";
                }
                else
                {
                    float distance = Vector3.Distance(sAI.mAIRT.transform.position, ((CowObject)sAI.mCharacter).mGlassTarget.mAIRT.transform.position);
                    if (distance > 1.5f)
                    {
                        sAI.GetComponent <AIMove> ().mDirection   = ((CowObject)sAI.mCharacter).mGlassTarget.mAIRT.transform.position - sAI.mAIRT.transform.position;
                        sAI.GetComponent <AIMove> ().mDirection.y = 0.0f;
                        sAI.GetComponent <AIMove> ().mVelocity    = ((CowObject)sAI.mCharacter).mVelocity;
                    }
                    else
                    {
                        sAI.GetComponent <AIMove> ().mVelocity = 0.0f;
                        if (((CowObject)sAI.mCharacter).EatTimer < 1.0f)
                        {
                            ((CowObject)sAI.mCharacter).EatTimer += Time.deltaTime;
                        }
                        else
                        {
                            ((CowObject)sAI.mCharacter).mTempLife += 40;
                            ((CowObject)sAI.mCharacter).mTempLife  = Mathf.Min(((CowObject)sAI.mCharacter).mTempLife, ((CowObject)sAI.mCharacter).mLife);
                            ((glassObject)((CowObject)sAI.mCharacter).mGlassTarget.mCharacter).mHp -= 120;
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
 public void DoDestroy(SimpleAI sAI)
 {
     SimpleAISetSingleton.getInstance().GetComponent <SimpleAISet> ().Delete(sAI);
     GameObject.Destroy(sAI.mAIRT);
     GAPopulation.allDic [sAI.mType].Delete(sAI);
 }
Exemplo n.º 10
0
 public void Create()
 {
     ECSWorld.MainWorld.registerEntityAfterInit(this);
     SimpleAISetSingleton.getInstance().GetComponent <SimpleAISet> ().mSimpleAIList.Add(this);
     GAPopulation.allDic [this.mType].Add(this);
 }
Exemplo n.º 11
0
 public void Destroy()
 {
     SimpleAISetSingleton.getInstance().GetComponent <SimpleAISet> ().Delete(this);
     GAPopulation.allDic [this.mType].Delete(this);
 }
Exemplo n.º 12
0
 public override void Init()
 {
     base.Init();
     SimpleAISetSingleton.getInstance().AddComponent <SimpleAISet> (new SimpleAISet());
 }