Exemplo n.º 1
0
 public void commonInit()
 {
     gameObject.SetActive(true);
     gameObject.GetComponent <Image>().enabled = true;
     line.StopAnimation();
     line.img.gameObject.SetActive(true);
     line.img.GetComponent <Image>().enabled = true;
     borderX = -GetComponent <RectTransform>().rect.width / 2;
 }
Exemplo n.º 2
0
 public void initFade()
 {
     if (!finishingFade)
     {
         finishingFade    = true;
         line.img.enabled = false;
         line.StopAnimation();
         slice.StopAnimation();
         // Arena resizes to a small default size in most regular battles before entering actual defense state
     }
 }
Exemplo n.º 3
0
 public void Remove()
 {
     if (!isactive)
     {
         return;
     }
     Transform[] pcs = UnitaleUtil.GetFirstChildren(p.transform);
     for (int i = 1; i < pcs.Length; i++)
     {
         try { pcs[i].GetComponent <Projectile>().ctrl.Remove(); }
         catch { new LuaSpriteController(pcs[i].GetComponent <Image>()).Remove(); }
     }
     lastX    = x;
     lastY    = y;
     lastAbsX = absx;
     lastAbsY = absy;
     if (p.gameObject.GetComponent <KeyframeCollection>() != null)
     {
         Object.Destroy(p.gameObject.GetComponent <KeyframeCollection>());
     }
     p.gameObject.GetComponent <Mask>().enabled       = false;
     p.gameObject.GetComponent <RectMask2D>().enabled = false;
     spr.StopAnimation();
     BulletPool.instance.Requeue(p);
     p = null;
 }
Exemplo n.º 4
0
    public void Init(EnemyController target)
    {
        gameObject.SetActive(true);
        line.StopAnimation();
        line.img.gameObject.SetActive(true);
        line.img.enabled = true;
        lifeBar.setVisible(false);
        finishingFade             = false;
        enemy                     = target;
        enePos                    = enemy.GetComponent <RectTransform>().position;
        targetRt.anchoredPosition = new Vector2(GetComponent <RectTransform>().rect.width / 2, 0);
        Vector3 slicePos = target.GetComponent <RectTransform>().position;

        slicePos.Set(slicePos.x, slicePos.y + target.GetComponent <RectTransform>().rect.height / 2 - 55, slicePos.z); // lol hardcoded offsets
        slice.img.GetComponent <RectTransform>().position = slicePos;
        borderX         = -GetComponent <RectTransform>().rect.width / 2;
        stopped         = false;
        shakeInProgress = false;
        shakeTimer      = 0;
        // damageTextRt.position = target.GetComponent<RectTransform>().position;
        setAlpha(1.0f);
    }
 public void Remove()
 {
     if (isactive)
     {
         Transform[] pcs = UnitaleUtil.GetFirstChildren(p.transform);
         for (int i = 1; i < pcs.Length; i++)
         {
             try { pcs[i].GetComponent <Projectile>().ctrl.Remove(); }
             catch { new LuaSpriteController(pcs[i].GetComponent <Image>()).Remove(); }
         }
         lastX    = x;
         lastY    = y;
         lastAbsX = absx;
         lastAbsY = absy;
         spr.StopAnimation();
         BulletPool.instance.Requeue(p);
         p = null;
     }
 }
Exemplo n.º 6
0
    // Update is called once per frame
    private void Update()
    {
        // do not update the attack UI if the ATTACKING state is frozen
        if (UIController.instance.frozenState != UIController.UIState.PAUSE)
        {
            return;
        }

        if (shakeInProgress)
        {
            int shakeidx = (int)Mathf.Floor(shakeTimer * shakeX.Length / totalShakeTime);
            if (Damage > 0 && shakeIndex != shakeidx)
            {
                if (shakeIndex != shakeidx && shakeIndex >= shakeX.Length)
                {
                    shakeIndex = shakeX.Length - 1;
                }
                shakeIndex = shakeidx;
                Vector2 localEnePos = enemy.GetComponent <RectTransform>().anchoredPosition; // get local position to do the shake
                enemy.GetComponent <RectTransform>().anchoredPosition = new Vector2(localEnePos.x + shakeX[shakeIndex], localEnePos.y);

                /*#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
                 *  if (StaticInits.ENCOUNTER == "01 - Two monsters" && StaticInits.MODFOLDER == "Examples")
                 *      Misc.MoveWindow(shakeX[shakeIndex] * 2, 0);
                 #endif*/
            }
            if (shakeTimer < 1.5f)
            {
                damageTextRt.localPosition = new Vector2(damageTextRt.localPosition.x, enemy.offsets[2].y + 40 * (2 + Mathf.Sin(shakeTimer * Mathf.PI * 0.75f)));
            }
            shakeTimer += Time.deltaTime;
            if (shakeTimer >= totalShakeTime)
            {
                shakeInProgress = false;
            }
        }
        else if ((slice.animcomplete && !slice.img.GetComponent <KeyframeCollection>().enabled&& stopped && !showedup) || needAgain)
        {
            needAgain = true;
            if (!wait1frame)
            {
                wait1frame = true;
                slice.StopAnimation();
                slice.Set("empty");
                enemy.TryCall("BeforeDamageValues", new[] { DynValue.NewNumber(Damage) });
                if (Damage > 0)
                {
                    AudioSource aSrc = GetComponent <AudioSource>();
                    aSrc.clip = AudioClipRegistry.GetSound("hitsound");
                    aSrc.Play();
                }
                // set damage numbers and positioning
                string damageTextStr;
                if (Damage == 0)
                {
                    if (enemy.DefenseMissText == null)
                    {
                        damageTextStr = "[color:c0c0c0]MISS";
                    }
                    else
                    {
                        damageTextStr = "[color:c0c0c0]" + enemy.DefenseMissText;
                    }
                }
                else if (Damage > 0)
                {
                    damageTextStr = "[color:ff0000]" + Damage;
                }
                else
                {
                    damageTextStr = "[color:00ff00]" + Damage;
                }
                damageTextRt.localPosition = new Vector3(0, 0, 0);
                damageText.SetText(new TextMessage(damageTextStr, false, true));
                damageTextRt.localPosition = new Vector3(-UnitaleUtil.CalcTextWidth(damageText) / 2 + enemy.offsets[2].x, 40 + enemy.offsets[2].y);

                // initiate lifebar and set lerp to its new health value
                if (Damage != 0)
                {
                    int newHP = enemy.HP - Damage;
                    try {
                        lifeBar.GetComponent <RectTransform>().localPosition = new Vector2(enemy.offsets[2].x, 20 + enemy.offsets[2].y);
                        lifeBar.GetComponent <RectTransform>().sizeDelta     = new Vector2(enemy.GetComponent <RectTransform>().rect.width, 13);
                        lifeBar.whenDamageValue = enemy.GetComponent <RectTransform>().rect.width;
                        lifeBar.setInstant(enemy.HP < 0 ? 0 : enemy.HP / (float)enemy.MaxHP);
                        lifeBar.setLerp(enemy.HP / (float)enemy.MaxHP, newHP / (float)enemy.MaxHP);
                        lifeBar.setVisible(true);
                        enemy.doDamage(Damage);
                    } catch { return; }
                }
                enemy.HandleAttack(Damage);
            }
            else
            {
                // finally, damage enemy and call its attack handler in case you wanna stop music on death or something
                shakeInProgress = true;
                waitingToFade   = true;
                needAgain       = false;
                totalShakeTime  = shakeX.Length * (1.5f / 8.0f);
                showedup        = true;
            }
        }
        else if (!slice.animcomplete)
        {
            slice.img.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(slice.img.GetComponent <Image>().sprite.rect.width, slice.img.GetComponent <Image>().sprite.rect.height);
        }
    }
Exemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        if (shakeInProgress)
        {
            int  shakeidx = (int)Mathf.Floor(shakeTimer * shakeX.Length / totalShakeTime);
            bool wentIn   = false;
            if (Damage > 0 && shakeIndex != shakeidx || wentIn)
            {
                if (shakeIndex != shakeidx && shakeIndex >= shakeX.Length)
                {
                    shakeIndex = shakeX.Length - 1;
                }
                shakeIndex = shakeidx;
                wentIn     = true;
                Vector2 localEnePos = enemy.GetComponent <RectTransform>().anchoredPosition; // get local position to do the shake
                enemy.GetComponent <RectTransform>().anchoredPosition = new Vector2(localEnePos.x + shakeX[shakeIndex], localEnePos.y);

                /*#if UNITY_STANDALONE_WIN || UNITY_EDITOR
                 *  if (StaticInits.ENCOUNTER == "01 - Two monsters" && StaticInits.MODFOLDER == "Examples")
                 *      Misc.MoveWindow(shakeX[shakeIndex] * 2, 0);
                 #endif*/
            }
            if (shakeTimer < 1.5f)
            {
                damageTextRt.localPosition = new Vector2(damageTextRt.localPosition.x, enemy.offsets[2].y + 40 * (2 + Mathf.Sin(shakeTimer * Mathf.PI * 0.75f)));
            }
            shakeTimer += Time.deltaTime;
            if (shakeTimer >= totalShakeTime)
            {
                shakeInProgress = false;
            }
        }
        else if ((slice.animcomplete && !slice.img.GetComponent <KeyframeCollection>().enabled&& stopped && !showedup) || needAgain)
        {
            needAgain = true;
            if (!wait1frame)
            {
                wait1frame = true;
                slice.StopAnimation();
                slice.Set("empty");
                enemy.TryCall("BeforeDamageValues");
                if (Damage > 0)
                {
                    AudioSource aSrc = GetComponent <AudioSource>();
                    aSrc.clip = AudioClipRegistry.GetSound("hitsound");
                    aSrc.Play();
                }
                // set damage numbers and positioning
                string damageTextStr = "";
                if (Damage == 0)
                {
                    damageTextStr = "[color:c0c0c0]MISS";
                }
                else if (Damage > 0)
                {
                    damageTextStr = "[color:ff0000]" + Damage;
                }
                else
                {
                    damageTextStr = "[color:00ff00]" + Damage;
                }
                // the -14 is to compensate for the 14 characters that [color:rrggbb] is worth until commands no longer count for text length. soon
                int damageTextWidth = (damageTextStr.Length - 14) * 29 + (damageTextStr.Length - 1 - 14) * 3; // lol hardcoded offsets
                foreach (char c in damageTextStr)
                {
                    if (c == '1')
                    {
                        damageTextWidth -= 12; // lol hardcoded offsets
                    }
                }
                damageTextRt.localPosition = new Vector2(-0.5f * damageTextWidth + enemy.offsets[2].x, 40 + enemy.offsets[2].y);
                damageText.SetText(new TextMessage(damageTextStr, false, true));

                // initiate lifebar and set lerp to its new health value
                if (Damage != 0)
                {
                    int newHP = enemy.HP - Damage;
                    try {
                        lifeBar.GetComponent <RectTransform>().localPosition = new Vector2(enemy.offsets[2].x, 20 + enemy.offsets[2].y);
                        lifeBar.GetComponent <RectTransform>().sizeDelta     = new Vector2(enemy.GetComponent <RectTransform>().rect.width, 13);
                        lifeBar.whenDamageValue = enemy.GetComponent <RectTransform>().rect.width;
                        lifeBar.setInstant(enemy.HP < 0 ? 0 : (float)enemy.HP / (float)enemy.MaxHP);
                        lifeBar.setLerp((float)enemy.HP / (float)enemy.MaxHP, (float)newHP / (float)enemy.MaxHP);
                        lifeBar.setVisible(true);
                        enemy.doDamage(Damage);
                    } catch { return; }
                }
                enemy.HandleAttack(Damage);
            }
            else
            {
                // finally, damage enemy and call its attack handler in case you wanna stop music on death or something
                shakeInProgress = true;
                waitingToFade   = true;
                needAgain       = false;
                totalShakeTime  = shakeX.Length * (1.5f / 8.0f);
                showedup        = true;
            }
        }
        else if (!slice.animcomplete)
        {
            slice.img.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(slice.img.GetComponent <Image>().sprite.rect.width, slice.img.GetComponent <Image>().sprite.rect.height);
        }
    }