Ejemplo n.º 1
0
        void TargetSelector()
        {
            List <MyBlockInfo> BBList = new List <MyBlockInfo>();
            List <int>         ImportanceMultiplier = new List <int>();

            if (DroneAIType.Value == 1)
            {
                foreach (MyBlockInfo BB in FindObjectsOfType <MyBlockInfo>())
                {
                    NotEvenHavingAFireTag = BB.gameObject.GetComponent <FireTag>() == null;
                    int BBID = BB.gameObject.GetComponent <BlockVisualController>().ID;
                    switch (AIDifficultyValue)
                    {
                    case 0:
                        if (BBID == 23 || BBID == 525 || BBID == 526 || BBID == 540 || BBID == 519)    //Bombs, Tracking Computers
                        {
                            if (NotEvenHavingAFireTag)
                            {
                                BBList.Add(BB);
                                ImportanceMultiplier.Add(15);
                                break;
                            }
                            else if (!BB.gameObject.GetComponent <FireTag>().burning)
                            {
                                BBList.Add(BB);
                                ImportanceMultiplier.Add(15);
                                break;
                            }
                        }
                        else if (BBID == 59 || BBID == 54 || BBID == 43)    //Rocket & Grenade
                        {
                            BBList.Add(BB);
                            ImportanceMultiplier.Add(12);
                            break;
                        }
                        else if (BBID == 14 || BBID == 2 || BBID == 46 || BBID == 39)    //Locomotion && Proplusion
                        {
                            if (BB.gameObject.GetComponent <ConfigurableJoint>() != null)
                            {
                                if (NotEvenHavingAFireTag)
                                {
                                    BBList.Add(BB);
                                    ImportanceMultiplier.Add(10);
                                    break;
                                }
                                else if (!BB.gameObject.GetComponent <FireTag>().burning)
                                {
                                    BBList.Add(BB);
                                    ImportanceMultiplier.Add(10);
                                    break;
                                }
                            }
                        }
                        else if (BBID == 26 || BBID == 55 || BBID == 52)    //Propellers and balloon
                        {
                            BBList.Add(BB);
                            ImportanceMultiplier.Add(8);
                            break;
                        }
                        else if (BBID == 34 || BBID == 25 /**/ || BBID == 28 || BBID == 4 || BBID == 18 || BBID == 27 || BBID == 3 || BBID == 20)      //Large Aero Blocks/Mechanic Blocks
                        {
                            if (BB.gameObject.GetComponent <ConfigurableJoint>() != null)
                            {
                                if (NotEvenHavingAFireTag)
                                {
                                    BBList.Add(BB);
                                    ImportanceMultiplier.Add(4);
                                    break;
                                }
                                else if (!BB.gameObject.GetComponent <FireTag>().burning)
                                {
                                    BBList.Add(BB);
                                    ImportanceMultiplier.Add(4);
                                    break;
                                }
                            }
                        }
                        else if (BBID == 35 || BBID == 16 || BBID == 42 /**/ || BBID == 40 || BBID == 60 || BBID == 38 || BBID == 51 /**/ || BBID == 1 || BBID == 15 || BBID == 41 || BBID == 5)    //Structure Block
                        {
                            if (BB.gameObject.GetComponent <ConfigurableJoint>() != null)
                            {
                                if (NotEvenHavingAFireTag)
                                {
                                    BBList.Add(BB);
                                    ImportanceMultiplier.Add(1);
                                    break;
                                }
                                else if (!BB.gameObject.GetComponent <FireTag>().burning)
                                {
                                    BBList.Add(BB);
                                    ImportanceMultiplier.Add(1);
                                    break;
                                }
                            }
                        }
                        break;

                    case 1:
                        if (BBID == 23 || BBID == 525 || BBID == 526 || BBID == 540 || BBID == 519)    //Bombs, Tracking Computers
                        {
                            if (NotEvenHavingAFireTag)
                            {
                                BBList.Add(BB);
                                ImportanceMultiplier.Add(15);
                                break;
                            }
                            else if (!BB.gameObject.GetComponent <FireTag>().burning)
                            {
                                BBList.Add(BB);
                                ImportanceMultiplier.Add(15);
                                break;
                            }
                        }
                        else if (BBID == 59 || BBID == 54)    //Rocket & Grenade
                        {
                            BBList.Add(BB);
                            ImportanceMultiplier.Add(12);
                            break;
                        }
                        break;

                    default:
                        /*this.currentTarget = null;
                         * this.targetPoint = new Vector3(UnityEngine.Random.value * 1400 - 700, 500, UnityEngine.Random.value * 1400 - 700);
                         * IAmEscaping = true;*/
                        return;
                    }
                }
                foreach (MyBlockInfo BB2 in BBList.ToArray())
                {
                    bool IgnoreAttitude = false;
                    bool IgnoreDistance = false;
                    int  RemoveId;
                    if (!IAmSwitching)
                    {
                        IgnoreAttitude = true;
                        IgnoreDistance = true;
                    }
                    if (!IgnoreAttitude)
                    {
                        if (BB2.gameObject.transform.position.y <= this.rigidBody.velocity.sqrMagnitude * 1.7f)
                        {
                            RemoveId = BBList.IndexOf(BB2);
                            BBList.RemoveAt(RemoveId);
                            ImportanceMultiplier.RemoveAt(RemoveId);
                            continue;
                        }
                    }
                    if (!IgnoreDistance)
                    {
                        if (this.transform.InverseTransformPoint(BB2.gameObject.transform.position).sqrMagnitude <= this.rigidBody.velocity.sqrMagnitude * 2.8f)
                        {
                            RemoveId = BBList.IndexOf(BB2);
                            BBList.RemoveAt(RemoveId);
                            ImportanceMultiplier.RemoveAt(RemoveId);
                            continue;
                        }
                    }
                    if (BB2.gameObject == currentTarget)
                    {
                        RemoveId = BBList.IndexOf(BB2);
                        BBList.RemoveAt(RemoveId);
                        ImportanceMultiplier.RemoveAt(RemoveId);
                        continue;
                    }
                }
                if (BBList.Count == 0)
                {
                    currentTarget = null;
                    targetPoint   = this.transform.TransformPoint(EulerToDirection(this.transform.eulerAngles.x, 45) * 200);
                    if ((this.transform.position - targetPoint).sqrMagnitude <= 100 || targetPoint.y <= 45)
                    {
                        this.targetPoint = new Vector3(UnityEngine.Random.value * 1400 - 700, 500, UnityEngine.Random.value * 1400 - 700);
                    }
                    Debug.Log(targetPoint);
                    IAmEscapingOrReturning = true;
                }
                else
                {
                    foreach (MyBlockInfo BNB in BBList)
                    {
                        int Index = BBList.IndexOf(BNB);
                        if (ImportanceMultiplier.Count == Index + 1)
                        {
                            this.currentTarget = BNB.gameObject;
                            break;
                        }
                        if (ImportanceMultiplier[Index + 1] > ImportanceMultiplier[Index])
                        {
                            continue;
                        }
                        else
                        {
                            this.currentTarget    = BNB.gameObject;
                            NotEvenHavingAJoint   = currentTarget.GetComponent <ConfigurableJoint>() == null;
                            NotEvenHavingAFireTag = currentTarget.GetComponent <FireTag>() == null;
                            if (currentTarget.GetComponent <ConfigurableJoint>() != null)
                            {
                                currentTarget.GetComponent <ConfigurableJoint>().breakForce = Mathf.Min(currentTarget.GetComponent <ConfigurableJoint>().breakForce, 45000);
                            }
                            break;
                        }
                    }
                }
            }

            else
            {
                List <CapsuleCollider> CPlist = new List <CapsuleCollider>();
                GameObject             PS     = GameObject.Find("PHYSICS GOAL");
                GameObject             ahaha;
                if (PS.transform.root.gameObject.GetComponent <SetObjectiveText>())
                {
                    PS.name = "aha";
                    ahaha   = GameObject.Find("PHYSICS GOAL");
                    PS.name = "PHYSICS GOAL";
                }
                else if (PS != null)
                {
                    ahaha = PS;
                }
                else
                {
                    ahaha = this.gameObject;
                }
                foreach (CapsuleCollider CC in ahaha.transform.GetComponentsInChildren <CapsuleCollider>())
                {
                    if (CC.GetComponent <EnemyAISimple>())
                    {
                        if (!CC.GetComponent <EnemyAISimple>().isDead)
                        {
                            CPlist.Add(CC);
                        }
                    }
                    else if (CC.GetComponent <EntityAI>())
                    {
                        if (!CC.GetComponent <EntityAI>().isDead)
                        {
                            CPlist.Add(CC);
                        }
                    }
                }

                foreach (CapsuleCollider BB2 in CPlist.ToArray())
                {
                    bool IgnoreAttitude = false;
                    bool IgnoreDistance = false;
                    int  RemoveId;
                    if (!IAmSwitching)
                    {
                        IgnoreAttitude = true;
                        IgnoreDistance = true;
                    }
                    if (!IgnoreAttitude)
                    {
                        if (BB2.gameObject.transform.position.y <= this.rigidBody.velocity.sqrMagnitude * 1.7f)
                        {
                            RemoveId = CPlist.IndexOf(BB2);
                            CPlist.RemoveAt(RemoveId);
                            continue;
                        }
                    }
                    if (!IgnoreDistance)
                    {
                        if (this.transform.InverseTransformPoint(BB2.gameObject.transform.position).sqrMagnitude <= this.rigidBody.velocity.sqrMagnitude * 2.8f)
                        {
                            RemoveId = CPlist.IndexOf(BB2);
                            CPlist.RemoveAt(RemoveId);
                            continue;
                        }
                    }
                    if (BB2.gameObject == currentTarget)
                    {
                        RemoveId = CPlist.IndexOf(BB2);
                        CPlist.RemoveAt(RemoveId);
                        continue;
                    }
                }
                if (CPlist.Count == 0)
                {
                    currentTarget = null;
                    targetPoint   = this.transform.TransformPoint(EulerToDirection(this.transform.eulerAngles.x, 45) * 200);
                    if ((this.transform.position - targetPoint).sqrMagnitude <= 100 || targetPoint.y <= 45)
                    {
                        this.targetPoint = new Vector3(UnityEngine.Random.value * 800 - 400, 500, UnityEngine.Random.value * 800 - 400);
                    }
                    IAmEscapingOrReturning = true;
                }
                else
                {
                    foreach (CapsuleCollider BNB in CPlist)
                    {
                        this.currentTarget = BNB.gameObject;
                        break;
                    }
                }
            }
        }