Пример #1
0
    // Use this for initialization
    void Awake()
    {
        if (gameObject.GetComponent <ObjectTypeVisible>())
        {
            _otv = gameObject.GetComponent <ObjectTypeVisible>();
        }

        _HP = gameObject.GetComponent <HealthModule>();
        if (!NonPhysicalMovement)
        {
            _agent = gameObject.GetComponent <MoveComponent>();
        }

        GameObject SenObj = Instantiate(SensorsLine, gameObject.transform.position, gameObject.transform.rotation);

        SensorsLine = SenObj;
        _scr        = SenObj.GetComponent <CircleRenderer>();
        _sespa      = SenObj.GetComponent <EnterSelectPlaneActive>();
        GameObject WepObj = Instantiate(WeaponLine, gameObject.transform.position, gameObject.transform.rotation);

        WeaponLine = WepObj;
        _wcr       = WepObj.GetComponent <CircleRenderer>();
        _wespa     = WepObj.GetComponent <EnterSelectPlaneActive>();

        _sespa.Owner = gameObject;

        _wespa.Owner = gameObject;

        _es = gameObject.GetComponent <SensorModule>();

        if (StartLocation == null)
        {
            targetVector = transform.position;
        }
        else
        {
            _agent.Movement(StartLocation.transform.position);
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (BuildFroze)
        {
            if (FixTarget != null)
            {
                BuildModule.Fixing = true;
            }
            else
            {
                BuildModule.Fixing = false;
            }
        }
        if (FixTarget != null)
        {
            if (FixTarget.GetComponent <Stats>().StopOrder)
            {
                if (R1)
                {
                    R1        = false;
                    Repair    = false;
                    FixTarget = null;
                }
                if (R2)
                {
                    R2 = false;
                    R3 = true;

                    EnteringProcess = 0;
                    MSPAccepted     = false;
                }
            }
            else
            {
                Repair = true;
                if (!R1 && !R2 && !R3)
                {
                    R1 = true;
                }
            }
        }
        else
        {
            R1     = false;
            R2     = false;
            R3     = false;
            Repair = false;

            EnteringProcess = 0;
            MSPAccepted     = false;
        }
        if (ShipsToFix.Count > 0)
        {
            CreateWaitingPoints();

            foreach (GameObject obj in ShipsToFix)
            {
                if (obj.GetComponent <Stats>().StopOrder)
                {
                    ShipsToFix.Remove(obj);
                    obj.GetComponent <ActiveState>().ForcedFix   = false;
                    obj.GetComponent <ActiveState>().curShipYard = null;
                }
            }
        }

        if (!_sb.AI && !_sb.FreandAI && !_sb.Neutral && !_sb.NeutralAgrass)
        {
            if (_sb.Hovering)
            {
                if (Input.GetMouseButtonDown(1))
                {
                    FindAndAddShips();
                }
            }
        }

        if (Repair)
        {
            if (FixTarget != null)
            {
                MoveComponent _tmc = FixTarget.GetComponent <MoveComponent>();
                HealthModule  _SHM = FixTarget.GetComponent <HealthModule>();
                if (R1)
                {
                    if (Vector3.Distance(FixTarget.transform.position, RPoint1.transform.position) > (_SHM.ShipRadius / 1.5f) + (_tmc.ForwardSpeed * _tmc.ForwardSpeed / 2) / _tmc.MaxAcceleration)
                    {
                        _tmc.Movement(RPoint1.transform.position);
                        if (Vector3.Distance(_tmc.transform.position, RPoint1.transform.position) <= _SHM.ShipRadius)
                        {
                            Vector3 rpos = RPoint2.transform.position - _tmc.transform.position;

                            Quaternion rotation = Quaternion.LookRotation(rpos);

                            float Amount = 0;
                            if (Amount < 1)
                            {
                                Amount += Time.deltaTime / _tmc.RotationAcceleration;
                            }

                            _tmc.RotateShipAndMoveToTarget(rotation.eulerAngles, RPoint1.transform.position, Amount, true, true);
                        }
                    }
                    else
                    {
                        R2 = true;
                        R1 = false;
                    }
                    FixTarget.GetComponent <Stats>().IsFix = true;
                    if (R3)
                    {
                        R3 = false;
                    }
                }
                if (R2)
                {
                    gameObject.GetComponent <ShipBuild>().CurOpenTimer = 1;
                    if (Vector3.Distance(FixTarget.transform.position, RPoint2.transform.position) > 1)
                    {
                        FixTarget.GetComponent <Rigidbody>().isKinematic = true;

                        Vector3 LookVector = (RPoint2.transform.position - FixTarget.transform.position);
                        FixTarget.transform.rotation = Quaternion.Slerp(FixTarget.transform.rotation, Quaternion.LookRotation(LookVector), 0.03f);

                        Vector3 dirFromAtoB = (RPoint2.transform.position - FixTarget.transform.position).normalized;
                        float   dotProd     = Vector3.Dot(dirFromAtoB, FixTarget.transform.forward);

                        if (dotProd > 0.95)
                        {
                            if (!MSPAccepted)
                            {
                                MovementStart = FixTarget.transform.position;
                                MSPAccepted   = true;
                            }

                            if (EnteringProcess < 1)
                            {
                                EnteringProcess += Time.deltaTime * (1 / FixTarget.GetComponent <MoveComponent>().MovementSpeed *AnimationSpeed);
                            }
                            else
                            {
                                EnteringProcess = 1;
                            }

                            FixTarget.transform.position = Vector3.Lerp(MovementStart, RPoint2.transform.position, EnteringProcess);
                        }

                        gameObject.GetComponent <ShipBuild>().CurOpenTimer = 1;
                    }
                    if (Vector3.Distance(FixTarget.transform.position, RPoint2.transform.position) <= 1)
                    {
                        EnteringProcess = 0;
                        MSPAccepted     = false;

                        Vector3 LookVector = (FixTarget.transform.position - RPoint2.transform.position);
                        FixTarget.transform.rotation = Quaternion.Slerp(FixTarget.transform.rotation, Quaternion.LookRotation(LookVector), 0.03f);

                        if (_SHM.curHealth < _SHM.maxHealth)
                        {
                            if (_GDB.Titanium > 0)
                            {
                                _GDB.Titanium -= Time.deltaTime * 2;
                                if (_SHM.curHealth < _SHM.maxHealth)
                                {
                                    _SHM.curHealth += Time.deltaTime * 2;
                                }
                                else
                                {
                                    _SHM.curHealth = _SHM.maxHealth;
                                }

                                if (_SHM.curImpulseSystemHealth < _SHM.maxImpulseSystemHealth)
                                {
                                    _SHM.curImpulseSystemHealth += Time.deltaTime * 2;
                                }
                                else
                                {
                                    _SHM.curImpulseSystemHealth = _SHM.maxImpulseSystemHealth;
                                }

                                if (_SHM.curLifeSupportSystemHealth < _SHM.maxLifeSupportSystemHealth)
                                {
                                    _SHM.curLifeSupportSystemHealth += Time.deltaTime * 2;
                                }
                                else
                                {
                                    _SHM.curLifeSupportSystemHealth = _SHM.maxLifeSupportSystemHealth;
                                }

                                if (_SHM.curPrimaryWeaponSystemHealth < _SHM.maxPrimaryWeaponSystemHealth)
                                {
                                    _SHM.curPrimaryWeaponSystemHealth += Time.deltaTime * 2;
                                }
                                else
                                {
                                    _SHM.curPrimaryWeaponSystemHealth = _SHM.maxPrimaryWeaponSystemHealth;
                                }

                                if (_SHM.curSensorsSystemHealth < _SHM.maxSensorsSystemHealth)
                                {
                                    _SHM.curSensorsSystemHealth += Time.deltaTime * 2;
                                }
                                else
                                {
                                    _SHM.curSensorsSystemHealth = _SHM.maxSensorsSystemHealth;
                                }

                                if (_SHM.curTractorBeamSystemHealth < _SHM.maxTractorBeamSystemHealth)
                                {
                                    _SHM.curTractorBeamSystemHealth += Time.deltaTime * 2;
                                }
                                else
                                {
                                    _SHM.curTractorBeamSystemHealth = _SHM.maxTractorBeamSystemHealth;
                                }

                                if (_SHM.curWarpEngingSystemHealth < _SHM.maxWarpEngingSystemHealth)
                                {
                                    _SHM.curWarpEngingSystemHealth += Time.deltaTime * 2;
                                }
                                else
                                {
                                    _SHM.curWarpEngingSystemHealth = _SHM.maxWarpEngingSystemHealth;
                                }

                                if (_SHM.curWarpCoreHealth < _SHM.maxWarpCoreHealth)
                                {
                                    _SHM.curWarpCoreHealth += Time.deltaTime * 2;
                                }
                                else
                                {
                                    _SHM.curWarpCoreHealth = _SHM.maxWarpCoreHealth;
                                }

                                if (_SHM.curSecondaryWeaponSystemHealth < _SHM.maxSecondaryWeaponSystemHealth)
                                {
                                    _SHM.curSecondaryWeaponSystemHealth += Time.deltaTime * 2;
                                }
                                else
                                {
                                    _SHM.curSecondaryWeaponSystemHealth = _SHM.maxSecondaryWeaponSystemHealth;
                                }

                                if (_SHM.CurShilds < _SHM.Shilds)
                                {
                                    _SHM.CurShilds += Time.deltaTime * 20;
                                }
                                else
                                {
                                    _SHM.CurShilds = _SHM.Shilds;
                                }

                                if (_GDB.Humans > 0)
                                {
                                    if (_SHM.curCrew < _SHM.maxCrew)
                                    {
                                        _GDB.Humans  -= Time.deltaTime * 4;
                                        _SHM.curCrew += Time.deltaTime * 4;
                                    }
                                    else
                                    {
                                        _SHM.curCrew = _SHM.maxCrew;
                                    }
                                }

                                if (_SHM.curHealth >= _SHM.maxHealth && _SHM.curImpulseSystemHealth >= _SHM.maxImpulseSystemHealth && _SHM.curLifeSupportSystemHealth >= _SHM.maxLifeSupportSystemHealth && _SHM.curPrimaryWeaponSystemHealth >= _SHM.maxPrimaryWeaponSystemHealth && _SHM.curTractorBeamSystemHealth >= _SHM.maxTractorBeamSystemHealth && _SHM.curWarpEngingSystemHealth >= _SHM.maxWarpEngingSystemHealth && _SHM.curWarpCoreHealth >= _SHM.maxWarpCoreHealth && _SHM.curSecondaryWeaponSystemHealth >= _SHM.maxSecondaryWeaponSystemHealth && _SHM.curCrew >= _SHM.maxCrew && _SHM.CurShilds >= _SHM.Shilds)
                                {
                                    R3 = true;
                                    R2 = false;
                                }
                            }
                            else
                            {
                                R3 = true;
                                R2 = false;
                            }
                        }
                    }
                    FixTarget.GetComponent <Stats>().IsFix = true;
                }
                if (R3)
                {
                    if (Vector3.Distance(FixTarget.transform.position, RPoint3.transform.position) > 1)
                    {
                        Vector3 LookVector = (RPoint3.transform.position - FixTarget.transform.position);
                        FixTarget.transform.rotation = Quaternion.Slerp(FixTarget.transform.rotation, Quaternion.LookRotation(LookVector), 0.03f);

                        Vector3 dirFromAtoB = (RPoint3.transform.position - FixTarget.transform.position).normalized;
                        float   dotProd     = Vector3.Dot(dirFromAtoB, FixTarget.transform.forward);

                        if (dotProd > 0.95)
                        {
                            if (!MSPAccepted)
                            {
                                MovementStart = FixTarget.transform.position;
                                MSPAccepted   = true;
                            }

                            if (EnteringProcess < 1)
                            {
                                EnteringProcess += Time.deltaTime * (1 / FixTarget.GetComponent <MoveComponent>().MovementSpeed *AnimationSpeed);
                            }
                            else
                            {
                                EnteringProcess = 1;
                            }

                            FixTarget.transform.position = Vector3.Lerp(MovementStart, RPoint3.transform.position, EnteringProcess);
                        }

                        gameObject.GetComponent <ShipBuild>().CurOpenTimer = 1;
                    }
                    if (Vector3.Distance(FixTarget.transform.position, RPoint3.transform.position) <= 1)
                    {
                        EnteringProcess = 0;
                        MSPAccepted     = false;

                        FixTarget.GetComponent <Rigidbody>().isKinematic = false;

                        FixTarget.GetComponent <Stats>().SelectLock = false;
                        if (STDLCMethods.FindInList(FixTarget, ShipsToFix))
                        {
                            ShipsToFix.Remove(FixTarget);
                        }
                        FixTarget = null;
                        Repair    = false;
                        R3        = false;
                    }
                    FixTarget.GetComponent <Stats>().IsFix             = false;
                    FixTarget.GetComponent <ActiveState>().ForcedFix   = false;
                    FixTarget.GetComponent <ActiveState>().curShipYard = null;
                }
            }
            else
            {
                Repair = false;
            }
        }
    }
Пример #3
0
    void CreateWaitingPoints()
    {
        if (FixTarget == null)
        {
            FixTarget = ShipsToFix[0];
        }

        Vector3 waitingPointsOrigin = WaitingPoint.transform.position;                   // начальная точка, откуда начинается очередь
        Vector3 rotationVector      = WaitingPoint.transform.rotation * Vector3.forward; // нормаль, вдоль которой будут строиться корабли (длина 1 метр/единица)
        Vector3 waitingPointOffset  = waitingPointsOrigin;                               // временная точка которая как раз и поможет выстраивать корабли, при этом не нужно лишний раз лезть к предыдущему кораблю

        for (int i = 1; i < ShipsToFix.Count; i++)                                       //цикл по кораблям - можно переписать на foreach
        {
            float shipRadius = ShipsToFix[i].GetComponent <HealthModule>().ShipRadius;   // нам нужен только радиус корабля

            if (i == 1)                                                                  // если это первый в ожидании корабль
            {                                                                            // то говорим тчо он должен стоять на начальной точке
                waitingPointOffset = waitingPointsOrigin;
            }
            else                                                    // иначе
            {                                                       // от предыдущей границы мы отобдвинемся на радиус корабля
                waitingPointOffset = waitingPointOffset + rotationVector * (shipRadius + 5);
            }

            MoveComponent _mc = ShipsToFix[i].GetComponent <MoveComponent>();


            _mc.Movement(new Vector3(waitingPointOffset.x, gameObject.transform.position.y, waitingPointOffset.z));             // говорим лететь

            if (Vector3.Distance(_mc.transform.position, new Vector3(waitingPointOffset.x, gameObject.transform.position.y, waitingPointOffset.z)) <= ShipsToFix[i].GetComponent <HealthModule>().ShipRadius)
            {
                if (i == 1)
                {
                    Vector3 rpos = RPoint1.transform.position - _mc.transform.position;

                    Quaternion rotation = Quaternion.LookRotation(rpos);

                    float Amount = 0;
                    if (Amount < 1)
                    {
                        Amount += Time.deltaTime / _mc.RotationAcceleration;
                    }

                    _mc.RotateShipAndMoveToTarget(rotation.eulerAngles, new Vector3(waitingPointOffset.x, gameObject.transform.position.y, waitingPointOffset.z), Amount, true, true);
                }
                else
                {
                    Vector3 rpos = WaitingPoint.transform.position - _mc.transform.position;

                    Quaternion rotation = Quaternion.LookRotation(rpos);

                    float Amount = 0;
                    if (Amount < 1)
                    {
                        Amount += Time.deltaTime / _mc.RotationAcceleration;
                    }

                    _mc.RotateShipAndMoveToTarget(rotation.eulerAngles, new Vector3(waitingPointOffset.x, gameObject.transform.position.y, waitingPointOffset.z), Amount, true, true);
                }
            }

            waitingPointOffset = waitingPointOffset + rotationVector * (shipRadius + 5);                // отодвигаем границу ещё на один радиус ткущего корабля
        }
    }
Пример #4
0
    void Update()
    {
        if (BuilderTarget != null)
        {
            DistanceToBuilding = Vector3.Distance(gameObject.transform.position, BuilderTarget.transform.position);
            if (!_st.AI & !_st.FreandAI)
            {
                if (BuilderTarget.tag == "BuildingBuilding")
                {
                    if (Vector3.Distance(gameObject.transform.position, BuilderTarget.transform.position) > BuilderTarget.GetComponent <BuildingStationScript> ().BuildDistance)
                    {
                        Build = false;
                        _agent.Movement(BuilderTarget.transform.position);
                    }
                    if (Vector3.Distance(gameObject.transform.position, BuilderTarget.transform.position) <= BuilderTarget.GetComponent <BuildingStationScript> ().BuildDistance)
                    {
                        if (!StopBool)
                        {
                            gameObject.GetComponent <Stats> ().targetVector = gameObject.transform.position;
                            _agent.Stop();
                            //_agent.ResetPath ();
                            StopBool = true;
                        }
                        Build = true;
                    }
                }
                if (BuilderTarget.tag != "BuildingBuilding")
                {
                    Build         = false;
                    BuilderTarget = null;
                }
            }
            if (_st.AI)
            {
                if (BuilderTarget.tag == "BuildingBuildingEnemy")
                {
                    if (Vector3.Distance(gameObject.transform.position, BuilderTarget.transform.position) > BuilderTarget.GetComponent <BuildingStationScript> ().BuildDistance)
                    {
                        Build = false;
                        _agent.Movement(BuilderTarget.transform.position);
                    }
                    if (Vector3.Distance(gameObject.transform.position, BuilderTarget.transform.position) <= BuilderTarget.GetComponent <BuildingStationScript> ().BuildDistance)
                    {
                        Build = true;
                        if (!StopBool)
                        {
                            gameObject.GetComponent <Stats> ().targetVector = gameObject.transform.position;
                            _agent.Stop();
                            //_agent.ResetPath ();
                            StopBool = true;
                        }
                    }
                }
                if (BuilderTarget.tag != "BuildingBuildingEnemy")
                {
                    Build         = false;
                    BuilderTarget = null;
                }
            }
            if (_st.FreandAI)
            {
                if (BuilderTarget.tag == "BuildingBuildingFreand")
                {
                    if (Vector3.Distance(gameObject.transform.position, BuilderTarget.transform.position) > BuilderTarget.GetComponent <BuildingStationScript> ().BuildDistance)
                    {
                        Build = false;
                        _agent.Movement(BuilderTarget.transform.position);
                    }
                    if (Vector3.Distance(gameObject.transform.position, BuilderTarget.transform.position) <= BuilderTarget.GetComponent <BuildingStationScript> ().BuildDistance)
                    {
                        Build = true;
                        if (!StopBool)
                        {
                            gameObject.GetComponent <Stats> ().targetVector = gameObject.transform.position;
                            _agent.Stop();
                            //_agent.ResetPath ();
                            StopBool = true;
                        }
                    }
                }
                if (BuilderTarget.tag != "BuildingBuildingFreand")
                {
                    Build         = false;
                    BuilderTarget = null;
                }
            }
        }
        if (Build)
        {
            if (BuilderTarget != null)
            {
                if (!STDLCMethods.FindInList(gameObject, BuilderTarget.GetComponent <BuildingStationScript>().Builders))
                {
                    BuilderTarget.GetComponent <BuildingStationScript> ().Builders.Add(gameObject);
                    _GDB.gameObject.GetComponent <Select> ().PlayComputerSound(_GDB.PlayerRace, "stationConstructingBegan");
                }
                if (_st.WasSelect)
                {
                    if (!_st.AI & !_st.FreandAI)
                    {
                        if (Input.GetMouseButtonDown(1))
                        {
                            BuilderTarget.GetComponent <BuildingStationScript> ().Builders.Remove(gameObject);
                            //BuilderTarget = null;
                            Build = false;
                        }
                    }
                }
            }
        }
        if (BuilderTarget != null & !Build)
        {
            BuilderTarget.GetComponent <BuildingStationScript> ().Builders.Remove(gameObject);
        }
        if (BuilderTarget != null)
        {
            if (BuilderTarget.GetComponent <BuildingStationScript> ().Timer <= 0)
            {
                StopBool = false;
            }
        }
        if (!Build)
        {
            StopBool = false;
        }
        if (BuilderTarget == null)
        {
            Build = false;
        }
        if (BuilderTarget != null)
        {
            if (_st.AI || _st.FreandAI)
            {
                BuilderTarget.GetComponent <BuildingStationScript> ().Owner = _st.Owner;
            }
            if (BuilderTarget.GetComponent <BuildingStationScript> ().Timer <= 0)
            {
                if (!BuilderTarget.GetComponent <BuildingStationScript> ().AI&& !BuilderTarget.GetComponent <BuildingStationScript> ().FreandAI)
                {
                    _GDB.gameObject.GetComponent <Select>().PlayComputerSound(_GDB.PlayerRace, "stationConstructingEnd");
                }
            }
        }
        if (_st.AI || _st.FreandAI)
        {
            if (_st.Owner != null)
            {
                if (!gameObject.GetComponent <ShipAI>().DilithiumMiner&& !gameObject.GetComponent <ShipAI>().TitaniumMiner)
                {
                    if (!STDLCMethods.FindInList(gameObject, _st.Owner.GetComponent <GlobalAI>().Builders))
                    {
                        _st.Owner.GetComponent <GlobalAI>().Builders.Add(gameObject);
                    }

                    if (BuilderTarget == null)
                    {
                        if (!STDLCMethods.FindInList(gameObject, _st.Owner.GetComponent <GlobalAI>().FreeBuilders))
                        {
                            _st.Owner.GetComponent <GlobalAI>().FreeBuilders.Add(gameObject);
                        }
                    }
                    else
                    {
                        if (STDLCMethods.FindInList(gameObject, _st.Owner.GetComponent <GlobalAI>().FreeBuilders))
                        {
                            _st.Owner.GetComponent <GlobalAI>().FreeBuilders.Remove(gameObject);
                        }
                    }
                }
                else
                {
                    if (STDLCMethods.FindInList(gameObject, _st.Owner.GetComponent <GlobalAI>().Builders))
                    {
                        _st.Owner.GetComponent <GlobalAI>().Builders.Remove(gameObject);
                    }

                    if (STDLCMethods.FindInList(gameObject, _st.Owner.GetComponent <GlobalAI>().FreeBuilders))
                    {
                        _st.Owner.GetComponent <GlobalAI>().FreeBuilders.Remove(gameObject);
                    }
                }
            }
        }
    }
Пример #5
0
 // Update is called once per frame
 void Update()
 {
     if (OnMine)
     {
         if (FindClosestMine() != null)
         {
             _agent.Movement(FindClosestMine().transform.position);
             gameObject.GetComponent <Stats> ().targetVector = FindClosestMine().transform.position;
             if (Vector3.Distance(gameObject.transform.position, FindClosestMine().transform.position) < 6)
             {
                 curAs    += Time.deltaTime * 10;
                 Titanium  = FindClosestMine().GetComponent <As> ().Titanium;
                 Dilithium = FindClosestMine().GetComponent <As> ().Dilithium;
                 Human     = FindClosestMine().GetComponent <As> ().Human;
                 FindClosestMine().GetComponent <As> ().Ass -= Time.deltaTime * 10;
             }
         }
     }
     if (ListReloadTimer > 0)
     {
         ListReloadTimer -= Time.deltaTime;
     }
     else
     {
         Mine.Clear();
         MineBase.Clear();
         ListReloadTimer = 0.1f;
     }
     CMine     = FindClosestMine();
     CMineBase = FindClosestMineBase();
     if (Mine.Count == 0)
     {
         if (TargetDilithium)
         {
             foreach (GameObject Test in GameObject.FindGameObjectsWithTag("DilitiumMine"))
             {
                 Mine.Add(Test);
             }
         }
         if (TargetHuman)
         {
             foreach (GameObject Test in GameObject.FindGameObjectsWithTag("HumanCrashShip"))
             {
                 Mine.Add(Test);
             }
         }
         if (TargetTitanium)
         {
             foreach (GameObject Test in GameObject.FindGameObjectsWithTag("TitaniumMine"))
             {
                 Mine.Add(Test);
             }
         }
     }
     if (MineBase.Count == 0)
     {
         if (gameObject.GetComponent <Stats> ().AI)
         {
             foreach (GameObject Test in GameObject.FindGameObjectsWithTag("EnemySB"))
             {
                 MineBase.Add(Test);
             }
         }
         if (gameObject.GetComponent <Stats> ().FreandAI)
         {
             foreach (GameObject Test in GameObject.FindGameObjectsWithTag("FreandSB"))
             {
                 MineBase.Add(Test);
             }
         }
         if (!gameObject.GetComponent <Stats> ().AI&& !gameObject.GetComponent <Stats> ().FreandAI)
         {
             foreach (GameObject Test in GameObject.FindGameObjectsWithTag("SB"))
             {
                 MineBase.Add(Test);
             }
         }
     }
     if (curAs <= 0)
     {
         OnMine = true;
         OnBase = false;
         curAs  = 0;
         if (!gameObject.GetComponent <Stats> ().AI)
         {
             if (!gameObject.GetComponent <Stats> ().FreandAI)
             {
                 //FindClosestMineBase().GetComponent<Miner2> ().As = 0;
             }
             if (gameObject.GetComponent <Stats> ().FreandAI)
             {
                 if (FindClosestMineBase() != null)
                 {
                     //	FindClosestMineBase().GetComponent<Miner2> ().As = 0;
                 }
             }
         }
         if (gameObject.GetComponent <Stats> ().AI)
         {
             if (FindClosestMineBase() != null)
             {
                 //FindClosestMineBase().GetComponent<Miner2> ().As = 0;
             }
         }
     }
     if (curAs >= maxAs)
     {
         OnMine = false;
         OnBase = true;
     }
     if (OnBase)
     {
         if (!gameObject.GetComponent <Stats> ().AI)
         {
             if (!gameObject.GetComponent <Stats> ().FreandAI)
             {
                 _agent.Movement(FindClosestMineBase().transform.parent.transform.position);
                 gameObject.GetComponent <Stats> ().targetVector = FindClosestMineBase().transform.parent.transform.position;
                 if (Vector3.Distance(gameObject.transform.position, FindClosestMineBase().transform.parent.transform.position) < FindClosestMineBase().transform.parent.transform.gameObject.GetComponent <HealthModule>().ShipRadius + 10)
                 {
                     if (FindClosestMineBase().GetComponent <Miner2> ().currentMiner == null || FindClosestMineBase().GetComponent <Miner2> ().currentMiner == gameObject)
                     {
                         FindClosestMineBase().GetComponent <Miner2> ().currentMiner = gameObject;
                         curAs -= Time.deltaTime * 20;
                         FindClosestMineBase().GetComponent <Miner2> ().Titanium  = Titanium;
                         FindClosestMineBase().GetComponent <Miner2> ().Dilithium = Dilithium;
                         FindClosestMineBase().GetComponent <Miner2> ().Human     = Human;
                         FindClosestMineBase().GetComponent <Miner2> ().As       += Time.deltaTime * 20;
                     }
                 }
             }
         }
         if (!gameObject.GetComponent <Stats> ().AI)
         {
             if (gameObject.GetComponent <Stats> ().FreandAI)
             {
                 _agent.Movement(FindClosestMineBase().transform.parent.transform.position);
                 gameObject.GetComponent <Stats> ().targetVector = FindClosestMineBase().transform.parent.transform.position;
                 if (Vector3.Distance(gameObject.transform.position, FindClosestMineBase().transform.parent.transform.position) < FindClosestMineBase().transform.parent.transform.gameObject.GetComponent <HealthModule>().ShipRadius + 10)
                 {
                     if (FindClosestMineBase().GetComponent <Miner2> ().currentMiner == null || FindClosestMineBase().GetComponent <Miner2> ().currentMiner == gameObject)
                     {
                         FindClosestMineBase().GetComponent <Miner2> ().currentMiner = gameObject;
                         curAs -= Time.deltaTime * 20;
                         FindClosestMineBase().GetComponent <Miner2> ().Titanium  = Titanium;
                         FindClosestMineBase().GetComponent <Miner2> ().Dilithium = Dilithium;
                         FindClosestMineBase().GetComponent <Miner2> ().Human     = Human;
                         FindClosestMineBase().GetComponent <Miner2> ().As       += Time.deltaTime * 20;
                     }
                 }
             }
         }
         if (gameObject.GetComponent <Stats> ().AI)
         {
             if (FindClosestMineBase() != null)
             {
                 _agent.Movement(FindClosestMineBase().transform.parent.transform.position);
                 gameObject.GetComponent <Stats> ().targetVector = FindClosestMineBase().transform.parent.transform.position;
                 if (Vector3.Distance(gameObject.transform.position, FindClosestMineBase().transform.parent.transform.position) < FindClosestMineBase().transform.parent.transform.gameObject.GetComponent <HealthModule>().ShipRadius + 10)
                 {
                     if (FindClosestMineBase().GetComponent <Miner2> ().currentMiner == null || FindClosestMineBase().GetComponent <Miner2> ().currentMiner == gameObject)
                     {
                         FindClosestMineBase().GetComponent <Miner2> ().currentMiner = gameObject;
                         curAs -= Time.deltaTime * 20;
                         FindClosestMineBase().GetComponent <Miner2> ().Titanium  = Titanium;
                         FindClosestMineBase().GetComponent <Miner2> ().Dilithium = Dilithium;
                         FindClosestMineBase().GetComponent <Miner2> ().Human     = Human;
                         FindClosestMineBase().GetComponent <Miner2> ().As       += Time.deltaTime * 20;
                     }
                 }
             }
         }
     }
     if (gameObject.GetComponent <Stats> ().WasSelect)
     {
         if (OnMine)
         {
             if (Input.GetMouseButtonDown(1))
             {
                 gameObject.GetComponent <Miner> ().enabled = false;
             }
         }
         else if (OnBase)
         {
             if (Input.GetMouseButtonDown(1))
             {
                 gameObject.GetComponent <Miner> ().enabled = false;
             }
         }
     }
 }
Пример #6
0
    public void UpdateOrders()
    {
        if (!StopReaction)
        {
            if (BattleShip)
            {
                if (!DefenceFleetShip && !AttackFleetShip && !AttackFleet2Ship && !AttackFleet3Ship && !ScoutFleetShip)
                {
                    if (_GAI.NeedAttackFleet3)
                    {
                        DefenceFleetShip = false;
                        ScoutFleetShip   = false;
                        AttackFleetShip  = false;
                        AttackFleet2Ship = false;
                        AttackFleet3Ship = true;

                        StopReaction = true;
                    }
                    if (_GAI.NeedAttackFleet2)
                    {
                        DefenceFleetShip = false;
                        ScoutFleetShip   = false;
                        AttackFleetShip  = false;
                        AttackFleet2Ship = true;
                        AttackFleet3Ship = false;

                        StopReaction = true;
                    }
                    if (_GAI.NeedAttackFleet)
                    {
                        DefenceFleetShip = false;
                        ScoutFleetShip   = false;
                        AttackFleetShip  = true;
                        AttackFleet2Ship = false;
                        AttackFleet3Ship = false;

                        StopReaction = true;
                    }

                    if (_GAI.NeedScoutFleet)
                    {
                        DefenceFleetShip = false;
                        ScoutFleetShip   = true;
                        AttackFleetShip  = false;
                        AttackFleet2Ship = false;
                        AttackFleet3Ship = false;

                        StopReaction = true;
                    }
                    if (_GAI.NeedDefenceFleet)
                    {
                        DefenceFleetShip = true;
                        ScoutFleetShip   = false;
                        AttackFleetShip  = false;
                        AttackFleet2Ship = false;
                        AttackFleet3Ship = false;

                        StopReaction = true;
                    }
                }
            }
            if (!BattleShip)
            {
                if (!Builder && !DilithiumMiner && !TitaniumMiner)
                {
                    if (DilithiumMinerActive)
                    {
                        if (_GAI.NeedDilithiumMiners)
                        {
                            DilithiumMiner = true;
                            StopReaction   = true;
                        }
                    }
                    else
                    {
                        if (_GAI.NeedTitaniumMiners)
                        {
                            TitaniumMiner = true;
                            StopReaction  = true;
                        }
                    }
                    if (_GAI.NeedBuilders)
                    {
                        Builder      = true;
                        StopReaction = true;
                    }
                }
            }
            if (Scouting)
            {
                _agent.Movement(ScoutVec);
            }
        }
        if (!DontReaction)
        {
            if (ScoutFleetShip)
            {
                if (!Scouting)
                {
                    if (ChangeArea)
                    {
                        gameObject.GetComponent <MoveComponent> ().Movement(_GAI.gameObject.transform.position + new Vector3(Random.Range(-1000, 1000), 0, Random.Range(-1000, 1000)));
                    }
                    else
                    {
                        gameObject.GetComponent <MoveComponent> ().Movement(gameObject.transform.position + new Vector3(Random.Range(-200, 200), 0, Random.Range(-200, 200)));
                    }
                }
            }
            if (DefenceFleetShip)
            {
                if (_st.targetTransform == null)
                {
                    if (_GAI.StarBases.Count > 0)
                    {
                        gameObject.GetComponent <MoveComponent> ().Movement(_GAI.StarBases [0].transform.position + new Vector3(Random.Range(-200, 200), 0, Random.Range(-200, 200)));
                    }
                }
            }
            if (AttackFleetShip || AttackFleet2Ship || AttackFleet3Ship)
            {
                if (_st.targetTransform == null)
                {
                    gameObject.GetComponent <MoveComponent> ().Movement(_GAI.StarBases [0].transform.position + new Vector3(Random.Range(-200, 200), 0, Random.Range(-200, 200)));
                }
            }
        }
        else
        {
            DontReaction = false;
        }
        if (AttackFleetShip)
        {
            if (EnemyPrioritet > fleet1Pr)
            {
                _GAI.NeedHelp(_st.targetTransform.gameObject);
            }
        }
        if (AttackFleetShip || AttackFleet2Ship || AttackFleet3Ship)
        {
            if (EnemyPrioritet > fleet1Pr + fleet2Pr + fleet3Pr)
            {
                _GAI.MustGoAway();
            }
        }
    }
Пример #7
0
    // Update is called once per frame
    void Update()
    {
        if (TypeChangerTimer > 0)
        {
            TypeChangerTimer -= Time.deltaTime;

            type = 0;
        }
        else
        {
            if (type == 0)
            {
                if (BPType)
                {
                    type = Random.Range(1, 2);
                }
                if (CType)
                {
                    type = 4;
                }
                if (Type1)
                {
                    type = Random.Range(1, 3);
                }
                if (Type2)
                {
                    type = Random.Range(1, 4);
                }
                if (Type3)
                {
                    type = Random.Range(2, 4);
                }
            }
            else
            {
                if (BPType)
                {
                    if (type == 1)
                    {
                        TypeChangerTimer = Random.Range(30, 300);
                    }
                    if (type == 2)
                    {
                        TypeChangerTimer = Random.Range(10, 100);
                    }
                }
                if (CType)
                {
                    TypeChangerTimer = Random.Range(30, 300);
                }
                if (Type1)
                {
                    if (type == 1)
                    {
                        TypeChangerTimer = Random.Range(5, 60);
                    }
                    if (type == 2)
                    {
                        TypeChangerTimer = Random.Range(20, 200);
                    }
                    if (type == 3)
                    {
                        TypeChangerTimer = Random.Range(30, 300);
                    }
                }
                if (Type2)
                {
                    if (type == 1)
                    {
                        TypeChangerTimer = Random.Range(5, 60);
                    }
                    if (type == 2)
                    {
                        TypeChangerTimer = Random.Range(20, 200);
                    }
                    if (type == 3)
                    {
                        TypeChangerTimer = Random.Range(30, 300);
                    }
                    if (type == 4)
                    {
                        TypeChangerTimer = Random.Range(5, 60);
                    }
                }
                if (Type3)
                {
                    if (type == 2)
                    {
                        TypeChangerTimer = Random.Range(10, 100);
                    }
                    if (type == 3)
                    {
                        TypeChangerTimer = Random.Range(20, 200);
                    }
                    if (type == 4)
                    {
                        TypeChangerTimer = Random.Range(30, 300);
                    }
                }
            }
        }
        if (type == 1)
        {
            CurMane = "DefiantImpulseAttack";
        }
        if (type == 2)
        {
            CurMane = "AroundTarget";
        }
        if (type == 3)
        {
            CurMane = "Flower";
        }
        if (type == 4)
        {
            CurMane = "DONOTMOVE";
        }
        if ((_as.Protact && _st.Order) || _as.Agrass || (_as.Idle && _st.Order))
        {
            if (_st.targetTransform != null)
            {
                if (BPType)
                {
                    if (WeaponIsReady)
                    {
                        BlockManSys = true;
                        _mc.Movement(_st.targetTransform.position);
                        ManeuversSpeed = _mc.RotationSpeed;

                        if (Delay > 0)
                        {
                            Delay -= Time.deltaTime;
                        }
                        else
                        {
                            OpenTheFire = true;
                            Delay       = 3;
                        }
                    }
                    if (OpenTheFire)
                    {
                        if (FireCompleate)
                        {
                            BlockManSys   = false;
                            WeaponIsReady = false;
                            FireCompleate = false;
                            OpenTheFire   = false;
                        }
                    }
                }
                if (!BlockManSys)
                {
                    if (CurMane == "DefiantImpulseAttack")
                    {
                        ManeuversSpeed = _mc.RotationSpeed / BPObject.transform.lossyScale.x;
                        _WPT.enabled   = true;
                        _WPT.circuit   = BPObject.GetComponent <WaypointCircuit>();
                        if (_st.targetTransform != null)
                        {
                            HealthModule _ehm = _st.targetTransform.gameObject.GetComponent <HealthModule>();

                            if (Vector3.Distance(gameObject.transform.position, _st.targetTransform.position) > (_as.radiuse + _h.ShipRadius + _ehm.ShipRadius))
                            {
                                _mc.Movement(_st.targetTransform.position);
                            }
                            else
                            {
                                BPObject.transform.localScale = new Vector3(_ehm.ShipRadius, _ehm.ShipRadius, _ehm.ShipRadius);
                                BPObject.transform.parent     = null;
                                BPObject.transform.position   = _st.targetTransform.position;
                                if (WayChangeTimer > 0)
                                {
                                    WayChangeTimer -= Time.deltaTime;
                                }
                                else
                                {
                                    _mc.Movement(_WPT.target.position);
                                    WayChangeTimer = StartWCT;
                                }
                            }
                        }
                        else
                        {
                            BPObject.transform.parent = gameObject.transform;
                        }

                        RoundObject.transform.parent  = gameObject.transform;
                        FlowerObject.transform.parent = gameObject.transform;
                    }
                    if (CurMane == "AroundTarget")
                    {
                        ManeuversSpeed = _mc.RotationSpeed / RoundObject.transform.lossyScale.x;
                        _WPT.enabled   = true;
                        _WPT.circuit   = RoundObject.GetComponent <WaypointCircuit>();
                        if (_st.targetTransform != null)
                        {
                            HealthModule _ehm = _st.targetTransform.gameObject.GetComponent <HealthModule>();

                            if (Vector3.Distance(gameObject.transform.position, _st.targetTransform.position) > (_as.radiuse + _h.ShipRadius + _ehm.ShipRadius))
                            {
                                _mc.Movement(_st.targetTransform.position);
                            }
                            else
                            {
                                RoundObject.transform.localScale = new Vector3(_ehm.ShipRadius, _ehm.ShipRadius, _ehm.ShipRadius);
                                RoundObject.transform.parent     = null;
                                RoundObject.transform.position   = _st.targetTransform.position;
                                if (WayChangeTimer > 0)
                                {
                                    WayChangeTimer -= Time.deltaTime;
                                }
                                else
                                {
                                    _mc.Movement(_WPT.target.position);
                                    WayChangeTimer = StartWCT;
                                }
                            }
                        }
                        else
                        {
                            RoundObject.transform.parent = gameObject.transform;
                        }

                        BPObject.transform.parent     = gameObject.transform;
                        FlowerObject.transform.parent = gameObject.transform;
                    }
                    if (CurMane == "Flower")
                    {
                        ManeuversSpeed = _mc.RotationSpeed / FlowerObject.transform.lossyScale.x;
                        _WPT.enabled   = true;
                        _WPT.circuit   = FlowerObject.GetComponent <WaypointCircuit>();
                        if (_st.targetTransform != null)
                        {
                            HealthModule _ehm = _st.targetTransform.gameObject.GetComponent <HealthModule>();

                            if (Vector3.Distance(gameObject.transform.position, _st.targetTransform.position) > (_as.radiuse + _h.ShipRadius + _ehm.ShipRadius))
                            {
                                _mc.Movement(_st.targetTransform.position);
                            }
                            else
                            {
                                FlowerObject.transform.localScale = new Vector3(_ehm.ShipRadius, _ehm.ShipRadius, _ehm.ShipRadius);
                                FlowerObject.transform.parent     = null;
                                FlowerObject.transform.position   = _st.targetTransform.position;
                                if (WayChangeTimer > 0)
                                {
                                    WayChangeTimer -= Time.deltaTime;
                                }
                                else
                                {
                                    _mc.Movement(_WPT.target.position);
                                    WayChangeTimer = StartWCT;
                                }
                            }
                        }
                        else
                        {
                            FlowerObject.transform.parent = gameObject.transform;
                        }

                        BPObject.transform.parent    = gameObject.transform;
                        RoundObject.transform.parent = gameObject.transform;
                    }
                    if (CurMane == "DONOTMOVE")
                    {
                        _WPT.enabled = false;
                        _WPT.circuit = RoundObject.GetComponent <WaypointCircuit>();
                        if (Vector3.Distance(gameObject.transform.position, _st.targetTransform.position) > (_as.radiuse + _h.ShipRadius + _st.targetTransform.gameObject.GetComponent <HealthModule>().ShipRadius))
                        {
                            _mc.Movement(_st.targetTransform.position);
                        }
                        else
                        {
                            _mc.Stop();
                        }

                        BPObject.transform.parent     = gameObject.transform;
                        RoundObject.transform.parent  = gameObject.transform;
                        FlowerObject.transform.parent = gameObject.transform;
                    }
                }
            }
            else
            {
                _WPT.enabled = false;
                _WPT.circuit = RoundObject.GetComponent <WaypointCircuit>();

                BPObject.transform.parent     = gameObject.transform;
                RoundObject.transform.parent  = gameObject.transform;
                FlowerObject.transform.parent = gameObject.transform;
            }
        }
        else
        {
            _WPT.enabled = false;
            _WPT.circuit = RoundObject.GetComponent <WaypointCircuit>();

            BPObject.transform.parent     = gameObject.transform;
            RoundObject.transform.parent  = gameObject.transform;
            FlowerObject.transform.parent = gameObject.transform;
        }
    }
    void GuartShip()
    {
        bool IsShip;

        if (_st.GuartTarget.GetComponent <MoveComponent>())
        {
            IsShip = true;
        }
        else
        {
            IsShip = false;
        }

        if (IsShip)
        {
            HealthModule _gthm = _st.GuartTarget.GetComponent <HealthModule>();

            if (_st.targetTransform == null)
            {
                Quaternion rotation     = _st.GuartTarget.transform.rotation;
                Vector3    rotateVector = _st.GuartTarget.transform.position + (rotation * new Vector3(_gthm.ProtectPosition[DefenceNumber].x, 0, _gthm.ProtectPosition[DefenceNumber].y));

                if (Vector3.Distance(gameObject.transform.position, _st.GuartTarget.transform.position) > 1)
                {
                    _agent.Movement(new Vector3(rotateVector.x, _st.GuartTarget.transform.position.y, rotateVector.z));
                }

                if (!_agent.Move)
                {
                    if (correct < 1)
                    {
                        correct += 0.01f;
                    }
                    else
                    {
                        correct = 1;
                    }
                }
                else
                {
                    correct = 0;
                }
            }
            else
            {
                if (Vector3.Distance(gameObject.transform.position, _st.GuartTarget.transform.position) > (_h.NormalSensors / 4) * 2)
                {
                    setwaytotarget = true;
                    _agent.Movement(new Vector3(_st.GuartTarget.transform.position.x + _gthm.ProtectPosition[DefenceNumber].x, _st.GuartTarget.transform.position.y, _st.GuartTarget.transform.position.z + _gthm.ProtectPosition[DefenceNumber].y));
                }
                else
                {
                    if (setwaytotarget)
                    {
                        _agent.Stop();
                        setwaytotarget = false;
                    }
                }
            }
        }
    }