Esempio n. 1
0
    private void Start()
    {
        StationaryMissScript _smc = Resources.Load <StationaryMissScript>("Prefabs/StationaryMiss");

        if (_smc != null && _smc.ToString().ToLower() != "null")
        {
            smc = _smc;
        }
        GameObject go = Resources.Load <GameObject>("Prefabs/FightInstance");

        if (go != null && go.ToString().ToLower() != "null")
        {
            FightInstance = go;
        }
        line.Set("UI/Battle/spr_targetchoice_0");
        instance = this;
    }
    // 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 (ArenaManager.instance.firstTurn)
        {
            return;
        }
        for (int i = 0; i < allFightUiInstances.Count; i++)
        {
            if (!boundFightUiInstances.Contains(allFightUiInstances[i]))
            {
                if (allFightUiInstances[i].Finished())
                {
                    allFightUiInstances[i].slice.Remove();
                    if (allFightUiInstances[i].lifeBar)
                    {
                        Destroy(allFightUiInstances[i].lifeBar.gameObject);
                        Destroy(allFightUiInstances[i].damageText.gameObject);
                        Destroy(allFightUiInstances[i].gameObject);
                    }
                    allFightUiInstances.RemoveAt(i);
                    i--;
                }
            }
        }

        if (finishingFade)
        {
            float resizeProg = 1.0f - ArenaManager.instance.getProgress();
            setAlpha(resizeProg);
            if (resizeProg != 0.0f)
            {
                return;
            }
            while (boundFightUiInstances.Count != 0)
            {
                allFightUiInstances.Remove(boundFightUiInstances[boundFightUiInstances.Count - 1]);
                Destroy(boundFightUiInstances[boundFightUiInstances.Count - 1].lifeBar.gameObject);
                Destroy(boundFightUiInstances[boundFightUiInstances.Count - 1].damageText.gameObject);
                Destroy(boundFightUiInstances[boundFightUiInstances.Count - 1].gameObject);
                boundFightUiInstances.RemoveAt(boundFightUiInstances.Count - 1);
            }
            targetRt.gameObject.SetActive(true);
            gameObject.GetComponent <Image>().enabled = true;
            finishingFade = false;
            if (allFightUiInstances.Count == 0)
            {
                gameObject.SetActive(false);
            }
            return;
        }
        if (boundFightUiInstances.Count != 0)
        {
            bool pass = boundFightUiInstances.All(t => t.slice.animcomplete && !t.slice.keyframes.enabled && stopped && t.waitingToFade);
            if (pass && boundFightUiInstances.All(fightUi => !fightUi.shakeInProgress))
            {
                initFade();
            }
        }

        if (stopped)
        {
            return;
        }

        float mv = xSpeed * Time.deltaTime;

        targetRt.anchoredPosition = new Vector2(targetRt.anchoredPosition.x + mv, 0);
        if (!Finished() || boundFightUiInstances.Count == 0)
        {
            return;
        }
        stopped = true;
        StationaryMissScript smc = Resources.Load <StationaryMissScript>("Prefabs/StationaryMiss");

        foreach (FightUI fightUi in boundFightUiInstances)
        {
            fightUi.enemy.HandleAttack(-1);
            StationaryMissScript smc2 = Instantiate(smc);
            if (fightUi.enemy.NoAttackMissText != null)
            {
                smc2.SetText(fightUi.enemy.NoAttackMissText);
            }
            smc2.transform.SetParent(GameObject.Find("Canvas").transform);
            if (fightUi.enemy.NoAttackMissText != null)
            {
                smc2.setXPosition(fightUi.enePos.x - 10 * fightUi.enemy.NoAttackMissText.Length + 20);
            }
            else
            {
                smc2.setXPosition(fightUi.enePos.x);
            }
        }
        initFade();
    }
Esempio n. 3
0
    // Update is called once per frame
    private void Update()
    {
        if (!ArenaManager.instance.firstTurn)
        {
            for (int i = 0; i < allFightUiInstances.Count; i++)
            {
                if (!boundFightUiInstances.Contains(allFightUiInstances[i]))
                {
                    if (allFightUiInstances[i].Finished())
                    {
                        allFightUiInstances[i].slice.Remove();
                        if (allFightUiInstances[i].lifeBar)
                        {
                            Destroy(allFightUiInstances[i].lifeBar.gameObject);
                            Destroy(allFightUiInstances[i].damageText.gameObject);
                            Destroy(allFightUiInstances[i].gameObject);
                        }
                        allFightUiInstances.RemoveAt(i);
                        i--;
                    }
                }
            }

            if (finishingFade)
            {
                float resizeProg = 1.0f - ArenaManager.instance.getProgress();
                setAlpha(resizeProg);
                if (resizeProg == 0.0f)
                {
                    while (boundFightUiInstances.Count != 0)
                    {
                        allFightUiInstances.Remove(boundFightUiInstances[boundFightUiInstances.Count - 1]);
                        Destroy(boundFightUiInstances[boundFightUiInstances.Count - 1].lifeBar.gameObject);
                        Destroy(boundFightUiInstances[boundFightUiInstances.Count - 1].damageText.gameObject);
                        Destroy(boundFightUiInstances[boundFightUiInstances.Count - 1].gameObject);
                        boundFightUiInstances.RemoveAt(boundFightUiInstances.Count - 1);
                    }
                    targetRt.gameObject.SetActive(true);
                    gameObject.GetComponent <Image>().enabled = true;
                    finishingFade = false;
                    if (allFightUiInstances.Count == 0)
                    {
                        gameObject.SetActive(false);
                    }
                }
                return;
            }
            else if (boundFightUiInstances.Count != 0)
            {
                bool pass = true;
                for (int i = 0; i < boundFightUiInstances.Count; i++)
                {
                    if (!(boundFightUiInstances[i].slice.animcomplete && !boundFightUiInstances[i].slice.keyframes.enabled && stopped && boundFightUiInstances[i].waitingToFade))
                    {
                        pass = false;
                        break;
                    }
                }
                if (pass)
                {
                    int number = 0;
                    for (int i = 0; i < boundFightUiInstances.Count; i++)
                    {
                        if (!boundFightUiInstances[i].shakeInProgress)
                        {
                            number++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (number == boundFightUiInstances.Count)
                    {
                        initFade();
                    }
                }
            }

            if (stopped)
            {
                return;
            }

            float mv = xSpeed * Time.deltaTime;
            targetRt.anchoredPosition = new Vector2(targetRt.anchoredPosition.x + mv, 0);
            if (Finished() && UIController.instance.inited && boundFightUiInstances.Count != 0)
            {
                stopped = true;
                for (int i = 0; i < boundFightUiInstances.Count; i++)
                {
                    boundFightUiInstances[i].enemy.HandleAttack(-1);
                    StationaryMissScript smc2 = Instantiate(smc);
                    smc2.transform.SetParent(GameObject.Find("Canvas").transform);
                    smc2.setXPosition(boundFightUiInstances[i].enePos.x);
                }
                initFade();
            }
        }
    }
Esempio n. 4
0
    // Update is called once per frame
    private void Update()
    {
        if (finishingFade)
        {
            float resizeProg = 1.0f - ArenaSizer.instance.getProgress();
            setAlpha(resizeProg);
            if (resizeProg == 0.0f)
            {
                damageText.destroyText();
                gameObject.SetActive(false);
            }
            return;
        }

        if (shakeInProgress)
        {
            int shakeidx = (int)Mathf.Floor(shakeTimer * shakeX.Length / totalShakeTime);

            if (Damage > 0 && shakeIndex != shakeidx)
            {
                shakeIndex = shakeidx;
                if (shakeIndex >= shakeX.Length)
                {
                    shakeIndex = shakeX.Length - 1;
                }
                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);
            }

            damageTextRt.position = new Vector2(damageTextRt.position.x, 80 + enePos.y + 40 * Mathf.Sin(shakeTimer * Mathf.PI * 0.75f));

            shakeTimer += Time.deltaTime;
            if (shakeTimer >= totalShakeTime)
            {
                shakeInProgress = false;
                initFade();
            }
            return;
        }

        if (!shakeInProgress && slice.animcomplete)
        {
            slice.StopAnimation();
            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
            {
                damageTextStr = "[color:ff0000]" + 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.position = new Vector2(enePos.x - 0.5f * damageTextWidth, 80 + enePos.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;
                if (newHP < 0)
                {
                    newHP = 0;
                }
                lifeBar.GetComponent <RectTransform>().position  = new Vector2(enePos.x, enePos.y + 20);
                lifeBar.GetComponent <RectTransform>().sizeDelta = new Vector2(enemy.GetComponent <RectTransform>().rect.width, 13);
                lifeBar.setInstant((float)enemy.HP / (float)enemy.getMaxHP());
                lifeBar.setLerp((float)enemy.HP / (float)enemy.getMaxHP(), (float)newHP / (float)enemy.getMaxHP());
                lifeBar.setVisible(true);
                enemy.doDamage(Damage);
            }

            // finally, damage enemy and call its attack handler in case you wanna stop music on death or something
            shakeInProgress = true;
            enemy.HandleAttack(Damage);
        }

        if (stopped)
        {
            return;
        }
        float mv = xSpeed * Time.deltaTime;
        targetRt.anchoredPosition = new Vector2(targetRt.anchoredPosition.x + mv, 0);
        if (Finished()) // you didn't press Z or you wouldn't be here
        {
            enemy.HandleAttack(-1);
            StationaryMissScript smc = Resources.Load <StationaryMissScript>("Prefabs/StationaryMiss");
            smc = Instantiate(smc);
            smc.transform.SetParent(GameObject.Find("Canvas").transform);
            smc.setXPosition(320 - enePos.x);
            initFade();
        }
    }