Esempio n. 1
0
    private void sendHelp(Transform drone, Transform attacker, Transform victim)
    {
        ShieldDrone d = drone.GetComponent <ShieldDrone>();

        if (d.GetComponent <ShieldingTarget>() == null)
        {
            d.gameObject.AddComponent <ShieldingTarget>();
        }
        ShieldingTarget target = d.GetComponent <ShieldingTarget>();

        target.attacker       = attacker;
        target.defender       = victim;
        target.freeFormation  = freeFormation;
        target.home_formation = this;
        remove_drone(d);
        DirectShieldFormation directShield = active_shields.Find(f => f.follow.Equals(victim));

        if (directShield == null)
        {
            directShield = Instantiate(direct_shield, victim.position, Quaternion.identity);
            directShield.transform.SetParent(transform.parent);
            active_shields.Add(directShield);
            directShield.follow = victim;
        }
        freeFormation.move_drone(d, directShield);
    }
Esempio n. 2
0
    public void reassignShield(ShieldDrone drone)
    {
        ShieldingTarget target = drone.GetComponent <ShieldingTarget>();

        drone.SetShieldPower(false);
        cancelHelp(target.attacker, target.defender);
        if (pending_attackers.Count == 0)
        {
            target.freeFormation.move_drone(drone, target.home_formation);
        }
        else
        {
            helpPending(drone.transform);
        }
    }
Esempio n. 3
0
    public void Update()
    {
        ShieldDrone     d;
        Transform       child;
        ShieldingTarget target;

        int child_count = transform.childCount;

        for (int i = 0; i < child_count; i++)
        {
            target = transform.GetChild(i).GetComponent <ShieldingTarget>();
            if (target.wasted_time >= 0)
            {
                target.wasted_time -= Time.deltaTime / 4;
            }
            for (int j = i + 1; j < child_count; j++)
            {
                if (Vector3.Distance(transform.GetChild(i).position, transform.GetChild(j).position) < duplicate_radius)
                {
                    ShieldDrone drone = transform.GetChild(j).GetComponent <ShieldDrone>();
                    target              = drone.GetComponent <ShieldingTarget>();
                    target.wasted_time += Time.deltaTime;
                    if (target.wasted_time > target.wasted_inertia)
                    {
                        remove_drone(drone);
                        j--;
                        child_count--;
                        drone.GetComponent <ShieldingTarget>().home_formation.reassignShield(drone);
                    }
                }
            }
        }

        for (int i = 0; i < child_count; i++)
        {
            child             = transform.GetChild(i);
            d                 = child.GetComponent <ShieldDrone>();
            target            = child.GetComponent <ShieldingTarget>();
            target.idle_time += Time.deltaTime;
            Vector3 aim       = target.attacker.GetComponent <Laser>().aim - transform.position;
            Vector3 projected = Vector3.ProjectOnPlane(aim, target.attacker.position - transform.position - aim);
            Debug.DrawRay(transform.position, aim, Color.black);
            Debug.DrawRay(transform.position + aim, projected, Color.red);
            Debug.DrawRay(transform.position + aim, target.attacker.position - transform.position - aim, Color.blue);
            if (projected.magnitude > radius)
            {
                d.move_towards_local(Time.deltaTime, (target.attacker.position - transform.position).normalized * radius);
            }
            else
            {
                float   scalar        = Mathf.Sqrt(radius * radius - (projected.magnitude * projected.magnitude));
                Vector3 scaled_vector = (target.attacker.position - transform.position - aim).normalized * scalar;
                d.move_towards_local(Time.deltaTime, scaled_vector + projected);
            }
            d.shieldFrom(target.attacker, transform);
            if (target.idle_time > target.shield_inertia)
            {
                remove_drone(d);
                target.home_formation.reassignShield(d);
                i--;
                child_count--;
            }
        }
    }