Exemple #1
0
    void Shoot()
    {
        if (State == AbilityState.Ready && Core.GetHealth()[2] >= energyCost && !Core.GetIsDead()) // if energy is sufficient, core isn't dead and key is pressed
        {
            Transform target = targetingSystem.GetTarget();
            if (target == null || !target || target.GetComponent <IDamageable>().GetIsDead() || !DistanceCheck(target))
            {
                TargetManager.Enqueue(targetingSystem, category);
            }
            else if (target && target.GetComponent <IDamageable>() != null)
            {                         // check if there is a target
                Core.SetIntoCombat(); // now in combat
                IDamageable tmp = target.GetComponent <IDamageable>();

                // check if allied
                if (!FactionManager.IsAllied(tmp.GetFaction(), Core.faction))
                {
                    if (targetingSystem.GetTarget() && Core.RequestGCD())
                    {
                        bool success = Execute(target.position); // execute ability using the position to fire
                        if (success)
                        {
                            Core.TakeEnergy(energyCost); // take energy, if the ability was executed
                            startTime = Time.time;
                        }
                    }
                }
            }
        }
    }
    /// <summary>
    /// Override for tick that integrates the targeting system of the core for players
    /// and adjusted for the new isActive behaviour
    /// </summary>
    /// <param name="key">the associated trigger key of the ability</param>
    public override void Tick(int key)
    {
        if (isDestroyed)
        {
            return; // Part has been destroyed, ability can't be used
        }
        if (Core.IsInvisible || Core.isAbsorbing)
        {
            return; // Core is in stealth mode, weapons are disabled
        }
        if (key == 1)
        {                    // toggle ability
            Core.MakeBusy(); // make core busy
            isActive = !isActive;
        }
        if (isOnCD)                                                                  // on cooldown
        {
            TickDown(cooldownDuration, ref CDRemaining, ref isOnCD);                 // tick the cooldown time
        }
        else if (isActive && Core.GetHealth()[2] >= energyCost && !Core.GetIsDead()) // if energy is sufficient, core isn't dead and key is pressed
        {
            Transform target = targetingSystem.GetTarget();
            if (target == null || !target || target.GetComponent <IDamageable>().GetIsDead() || !DistanceCheck(target))
            {
                TargetManager.Enqueue(targetingSystem, category);
            }
            else if (target && target.GetComponent <IDamageable>() != null) // check if there is a target
            {
                Core.SetIntoCombat();                                       // now in combat
                IDamageable tmp = target.GetComponent <IDamageable>();

                // check if allied
                if (!FactionManager.IsAllied(tmp.GetFaction(), Core.faction))
                {
                    bool success = Execute(target.position); // execute ability using the position to fire
                    if (success)
                    {
                        Core.TakeEnergy(energyCost); // take energy, if the ability was executed
                    }
                }
            }
        }
    }
Exemple #3
0
    void Update()
    {
        line.gameObject.transform.position = gameObject.transform.position;
        if (initialized && targetingSystem.GetTarget() && !Core.IsInvisible && duration > 0)
        {
            if (Core.GetHealth()[2] < energyCost * Time.deltaTime)
            {
                duration = 0;
                return;
            }

            duration -= Time.deltaTime;
            var pos = targetingSystem.GetTarget().position;
            line.positionCount = 2;
            line.SetPosition(0, line.gameObject.transform.position);
            var vec = (pos - line.gameObject.transform.position).normalized;
            //var angle = Mathf.Atan(vec.y / vec.x);
            var targetBearing = GetBearingFromVector(vec);


            // vec = (GetMousePos() - transform.position).normalized;
            var originalBearing = beamBearing;

            var diff = targetBearing - originalBearing;

            var  c          = 65 * Time.deltaTime;
            bool goForwards = false;

            if (originalBearing < 180)
            {
                goForwards = targetBearing - originalBearing < 180 && targetBearing - originalBearing > 0;
            }
            else
            {
                var limit = originalBearing + 180 - 360;
                goForwards = targetBearing < 180 ? (targetBearing < limit) : (targetBearing > originalBearing);
            }

            if (Mathf.Abs(diff) <= c)
            {
                originalBearing = targetBearing;
            }
            else
            {
                originalBearing += goForwards ? c : -c;
            }

            beamBearing = originalBearing;
            if (beamBearing > 360)
            {
                beamBearing -= 360;
            }

            if (beamBearing < 0)
            {
                beamBearing += 360;
            }

            var newAngle = GetAngleFromBearing(originalBearing) * Mathf.Deg2Rad;

            // Debug.LogError(angle * Mathf.Rad2Deg + " " + GetBearingFromVector(vec) + " " + GetAngleFromBearing(GetBearingFromVector(vec)));
            line.SetPosition(1, transform.position + GetVectorByBearing(originalBearing) * range);
            ThickenLine(0.005F);

            var dps         = damage * Time.deltaTime;
            var raycastHits = Physics2D.RaycastAll(transform.position, GetVectorByBearing(originalBearing), range);
            for (int i = 0; i < raycastHits.Length; i++)
            {
                var damageable = raycastHits[i].transform.GetComponentInParent <IDamageable>();
                if (raycastHits[i].transform && damageable != null && damageable.GetFaction() != Core.faction && !damageable.GetIsDead() && damageable.GetTerrain() != Entity.TerrainType.Ground)
                {
                    var hitTransform = raycastHits[i].transform;

                    var magnitude = (hitTransform.position - transform.position).magnitude;
                    line.SetPosition(1, transform.position + GetVectorByBearing(originalBearing) * magnitude);
                    Core.TakeEnergy(energyCost * Time.deltaTime);

                    var part = hitTransform.GetComponentInChildren <ShellPart>();

                    var residue = damageable.TakeShellDamage(dps, 0, GetComponentInParent <Entity>());

                    // deal instant damage

                    if (part)
                    {
                        part.TakeDamage(residue);
                    }

                    break;
                }
            }

            if (!hitPrefab)
            {
                hitPrefab = ResourceManager.GetAsset <GameObject>("weapon_hit_particle");
            }

            if (line.positionCount > 1)
            {
                Instantiate(hitPrefab, line.GetPosition(1), Quaternion.identity); // instantiate hit effect
            }
        }
        else
        {
            if (!targetingSystem.GetTarget() && duration > 0)
            {
                duration = 0;
            }

            if (line.startWidth > startWidth)
            {
                ThickenLine(-0.01F);
            }

            if (duration <= 0)
            {
                if (transform.parent.GetComponentInChildren <AudioSource>())
                {
                    Destroy(transform.parent.GetComponentInChildren <AudioSource>().gameObject);
                }
            }
        }
    }
Exemple #4
0
 public Transform GetTarget()
 {
     return(targetingSystem.GetTarget());
 }