Пример #1
0
    void HandleOnDamageTaken(Guid obj)
    {
        Debug.LogWarning(tag + " take damage from " + obj);

        if (urgentObjective == UrgentObjective.none)
        {
            urgentObjective = UrgentObjective.attack;
            // get target by obj
            allowSetTarget = true;
            SetTarget(obj);
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (allowAI)
        {
            if (firstRun)
            {
                firstRun = false;
                GetAllTargets();
                GetAllBases();
            }
            // follow principle 1
            if (armorScript.totalArmor <= baseArmor / 2)
            {
                Debug.LogWarning("Low health.");
                //urgentObjective = UrgentObjective.retreat;
                // if in ally system > go to base and call for reinforcements
                // if in foes system > call for reinforcements
            }

            if (urgentObjective == UrgentObjective.none)
            {
                if (globalObjecive == GlobalObjecive.protectSystem ||
                    globalObjecive == GlobalObjecive.attackSystem)
                {
                    SetTarget(Guid.Empty);
                    if (!noMoreTargets)
                    {
                        if (target != null)
                        {
                            if (Vector3.Distance(transform.position, target.position) < attackRange)
                            {
                                KillTask();
                                moveSpeed = 0.0f;
                            }
                            else
                            {
                                moveSpeed = moveSpeed1;
                                FollowTask();
                            }
                        }
                        else
                        {
                            allowSetTarget = true;
                        }
                    }
                    else
                    {
                        // if protect > go to base position
                        // if attack > attack planets / station etc
                        target = baseLocation;

                        if (Vector3.Distance(transform.position, target.position) > 2)
                        {
                            moveSpeed = moveSpeed1;
                            FollowTask();
                        }
                        else
                        {
                            moveSpeed = 0.0f;
                        }
                    }
                }

                if (globalObjecive == GlobalObjecive.attackSystem)
                {
                    // get nearest target
                    // if see targets > attack it
                    // if no more targets > attack stations / planets
                }

                if (globalObjecive == GlobalObjecive.tradeInSystem)
                {
                    SetBase(Guid.Empty);
                    if (Vector3.Distance(transform.position, target.position) > 1)
                    {
                        moveSpeed = 4.0f;
                        FollowTask();
                    }
                    else
                    {
                        // delay and select new target
                        allowSetBase = true;
                        moveSpeed    = 0.0f;
                    }
                    // movement between planets / stations
                }
            }
            else if (urgentObjective == UrgentObjective.attack)
            {
                if (target != null)
                {
                    if (Vector3.Distance(transform.position, target.position) < attackRange)
                    {
                        KillTask();
                        moveSpeed = 0.0f;
                    }
                    else
                    {
                        moveSpeed = 10.0f;
                        FollowTask();
                    }
                }
                else
                {
                    urgentObjective = UrgentObjective.none;
                    if (globalObjecive == GlobalObjecive.tradeInSystem)
                    {
                        allowSetBase = true;
                    }
                }
            }

            if (thruster != null)
            {
                thruster.parentSpeed = moveSpeed;
            }
        }
    }