Example #1
0
 IEnumerator siphon(CharacterController user)
 {
     if (!DialogueManager.InConversation && !TimelineController.InCutscene)
     {
         Vector3      dir = Vector3.Normalize(mainCamera.ScreenToWorldPoint(Input.mousePosition) - user.transform.position);
         RaycastHit2D hit = Physics2D.Raycast(user.transform.position, dir, spellStats.range);
         if (hit.collider != null)
         {
             ISiphonable target = hit.transform.GetComponent <ISiphonable>();
             if (target != null && target.IsSiphonable && user.energy.quantity >= energyCostPerTick)
             {
                 particles.particleSource = hit.transform;
                 active = true;
                 originSprite.enabled = true;
                 particles.Play();
                 Vector3 hitOffset = target.transform.position - (Vector3)hit.point;
                 while (active && (hitOffset + user.transform.position - target.transform.position).magnitude <= spellStats.range && target.IsSiphonable && user.energy.quantity >= energyCostPerTick && user.IsAlive)
                 {
                     AudioManager.instance.Play("Siphon");
                     target.Siphon(healthPerTick);
                     user.AddHealth((int)(healthPerTick * stealPercentage));
                     user.AddEnergy(-energyCostPerTick);
                     yield return(new WaitForSeconds(tickRate));
                 }
                 active = false;
                 originSprite.enabled = false;
                 particles.Stop();
             }
         }
     }
 }