Ejemplo n.º 1
0
    private int TakeDamage(CharacterDoll _atk)
    {
        int damage = (int)(_atk.attackPower - this.defensePower);

        if (defMode)
        {
            damage = (int)(damage * 0.2f);
        }
        if (damage < 1)
        {
            damage = 1;
        }
        curHp -= damage;
        float power = damage / (maxHp * 0.5f) * 0.25f;

        GameUIManager.Instance.ShakeCamera(power);
        if (!this.faction.isPlayer)
        {
            GameManager.Instance.gainGold += damage;
        }
        GameUIManager.Instance.ShowDamage(damage, Camera.main.WorldToScreenPoint(this.transform.position));

        SoundManager.Instance.PlayFX(GameManager.Instance.hitFx);
        portrait.UpdateHpBar((float)curHp / maxHp);

        if (curHp <= 0)
        {
            Die();
            return(damage);
        }

        return(damage);
    }
Ejemplo n.º 2
0
    public void OpenActSelect(CharacterDoll _doll)
    {
        Vector2 scrnPos = Camera.main.WorldToScreenPoint(_doll.transform.position);

        scrnPos = ToCanvasPosition(scrnPos);
        float margin = ActSelect.MARGIN_X + 100f;

        scrnPos.x = Mathf.Clamp(scrnPos.x, margin, 1080f - margin);
        rtActSelect.anchoredPosition = scrnPos;
        actSelect.gameObject.SetActive(true);
        actSelect.Open();
        Skill skill = _doll.chaInfo.skillPrefab;

        if (skill != null && !(_doll.moveLock > 0 && skill.targeting))
        {
            actSelect.SetSkillIcon(skill.icon);
            if (_doll.skillCoolDown > 0)
            {
                actSelect.EnableCoolDown(_doll.skillCoolDown);
            }
        }
        else
        {
            actSelect.DisableSkill();
        }

        if (_doll.moveLock > 0)
        {
            actSelect.DisableAttack();
        }
        else
        {
            actSelect.EnableAttack();
        }
    }
Ejemplo n.º 3
0
    public static Quaternion CalculateLookRotation(CharacterDoll _me, CharacterDoll _tar)
    {
        Vector3 posStart = _me.transform.position;
        Vector3 posEnd   = _tar.transform.position;

        return(Quaternion.Euler(0, 0, -Mathf.Atan2(posEnd.x - posStart.x, posEnd.y - posStart.y) * Mathf.Rad2Deg));
    }
Ejemplo n.º 4
0
    public void OnTriggerEnter2D(Collider2D _col)
    {
        if (_col.gameObject == owner.gameObject)
        {
            return;
        }

        if (_col.gameObject.layer != LayerMask.NameToLayer("Doll"))
        {
            return;
        }

        CharacterDoll tar = _col.gameObject.GetComponent <CharacterDoll>();

        if (tar.faction.isPlayer == owner.faction.isPlayer)
        {
            return;
        }

        float damage = owner.chaInfo.attackPower * 0.75f;

        if (state > 0)
        {
            damage = owner.chaInfo.attackPower * 2f;
        }
        else
        {
            tar.moveLock += 1;
        }
        tar.TakeDamage((int)damage);

        tar.rb.velocity = Vector2.zero;
        End();
    }
Ejemplo n.º 5
0
    public override void Use()
    {
        base.Use();

        for (int i = 0; i < 5; ++i)
        {
            CharacterDoll doll = null;
            if (owner.faction.isPlayer)
            {
                doll = GameManager.Instance.playerDoll[i];
            }
            else
            {
                doll = GameManager.Instance.enemyDoll[i];
            }

            if (doll.dead)
            {
                if (resurrect < 0)
                {
                    resurrect = i;
                }
                else if (Random.Range(0, 2) == 1)
                {
                    resurrect = i;
                }
            }
            else
            {
                doll.Heal((int)(doll.maxHp * 0.4f));
                heal[i].gameObject.SetActive(true);
                heal[i].transform.position = doll.transform.position + new Vector3(0f, 0f, -1f);
                heal[i].Play("Heal");
            }

            SoundManager.Instance.PlayFX(fx);
        }

        if (resurrect != -1)
        {
            CharacterDoll doll = null;
            if (owner.faction.isPlayer)
            {
                doll = GameManager.Instance.playerDoll[resurrect];
            }
            else
            {
                doll = GameManager.Instance.enemyDoll[resurrect];
            }

            doll.curHp = (int)(doll.maxHp * 0.2f);
            doll.portrait.SetNormalPortrait();
            doll.portrait.UpdateHpBar((float)doll.curHp / doll.maxHp);
            doll.dead = false;
            doll.gameObject.SetActive(true);
            resSpr.gameObject.SetActive(true);
            resSpr.transform.position = doll.transform.position + new Vector3(0f, 0f, -1f);
        }
    }
Ejemplo n.º 6
0
    private Vector2 CalculateVelocity(CharacterDoll _atk, CharacterDoll _hit)
    {
        float   push   = Mathf.Clamp(_atk.pushPower - _hit.defensePower, 1.5f, 10f);
        Vector2 hitVel = _hit.rb.velocity;
        Vector2 v      = hitVel.normalized * DollController.ONE_GRID_VELOCITY * push;

        return(v);
    }
Ejemplo n.º 7
0
    private CharacterDoll CreateCharacterDoll(int _id)
    {
        GameObject    prefab = CharacterDB.Instance.GetCharacterDollPrefab(_id);
        GameObject    dupe   = Instantiate(prefab, characterBoard.transform);
        CharacterDoll doll   = dupe.GetComponent <CharacterDoll>();

        doll.transform.localPosition = board.GetGridPosition(1, 1);
        doll.faction = new Faction(false, 0);
        return(doll);
    }
Ejemplo n.º 8
0
    private void RandomPlace(bool _isPlayer, int _order)
    {
        int           rand = Random.Range(0, remainPlace.Count);
        Vector2       v    = remainPlace[rand];
        CharacterDoll doll = g.GetDoll(_isPlayer, _order);

        doll.transform.localPosition = Board.Instance.GetGridPosition((int)v.x, (int)v.y);
        if (!_isPlayer)
        {
            doll.transform.localRotation = Quaternion.Euler(0f, 0f, 180f);
        }
        doll.gameObject.SetActive(true);
        remainPlace.RemoveAt(rand);
        SoundManager.Instance.PlayFX(placeFx);
    }
Ejemplo n.º 9
0
    private void PushAllDolls()
    {
        Vector2 hidePos = new Vector2(-999f, -999f);

        for (int i = 0; i < 5; ++i)
        {
            Character     c       = PlayerData.Instance.characters[i];
            int           lv      = PlayerData.Instance.chaLevel[c.id - 1];
            Character     cha     = c.CalculateLevel(lv);
            int           id      = cha.id;
            Faction       faction = new Faction(true, i);
            CharacterDoll doll    = CreateCharacterDoll(id);
            doll.transform.localPosition = hidePos;
            doll.faction = faction;
            doll.Initialize(cha);
            dolls.Add(doll);
            playerDoll.Add(doll);
            doll.gameObject.SetActive(false);
        }
        List <Character> ec = LoadEnemyCharacters();

        for (int i = 0; i < 5; ++i)
        {
            bool      dark = true;
            Character cha  = ec[i];
            int       id   = cha.id;
            if (id == unlockTarget)
            {
                dark = false;
            }
            Faction       faction = new Faction(false, i);
            CharacterDoll doll    = CreateCharacterDoll(id);
            doll.transform.localPosition = hidePos;
            doll.faction = faction;
            doll.Initialize(cha);
            dolls.Add(doll);
            if (dark)
            {
                doll.MakeDarkSprite();
            }
            else
            {
                doll.MakeRedSprite();
            }
            enemyDoll.Add(doll);
            doll.gameObject.SetActive(false);
        }
    }
Ejemplo n.º 10
0
    public void OnTriggerEnter2D(Collider2D _col)
    {
        if (state != 0)
        {
            return;
        }

        if (_col.gameObject == owner.gameObject)
        {
            return;
        }

        if (_col.gameObject.layer != LayerMask.NameToLayer("Doll"))
        {
            return;
        }

        CharacterDoll tar = _col.gameObject.GetComponent <CharacterDoll>();

        if (tar.faction.isPlayer == owner.faction.isPlayer)
        {
            return;
        }

        shadow.transform.position = owner.transform.position;
        slash.transform.position  = tar.transform.position;
        shadow.gameObject.SetActive(true);
        slash.gameObject.SetActive(true);
        slash.Play("Slash");
        ++state;
        timer = 0f;

        float damage = owner.chaInfo.attackPower * 2f;

        tar.TakeDamage((int)damage);

        float   rad = tar.col.radius + owner.col.radius + 0.1f;
        Vector3 pos = tar.transform.position + (tar.transform.up * -rad);

        owner.transform.position = pos;
        owner.rb.velocity        = Vector2.zero;
        owner.transform.rotation = GameManager.CalculateLookRotation(owner, tar);

        SoundManager.Instance.PlayFX(fx);
    }
Ejemplo n.º 11
0
    private void AIThink()
    {
        int randIndex = Random.Range(0, 5);

        if (enemyDoll[randIndex].dead)
        {
            for (int i = 0; i < 5; ++i)
            {
                if (!enemyDoll[i].dead)
                {
                    randIndex = i;
                    break;
                }
            }
        }
        float         randPower = Random.Range(5.5f, 10f);
        CharacterDoll ed        = enemyDoll[randIndex];

        randIndex = Random.Range(0, 5);
        if (playerDoll[randIndex].dead)
        {
            for (int i = 0; i < 5; ++i)
            {
                if (!playerDoll[i].dead)
                {
                    randIndex = i;
                    break;
                }
            }
        }
        CharacterDoll tar = playerDoll[randIndex];

        float       randAngle = Random.Range(0f, 360f) * Mathf.Deg2Rad;
        Rigidbody2D rb        = ed.GetComponent <Rigidbody2D>();

        ed.transform.rotation = CalculateLookRotation(ed, tar);

        rb.AddForce(ed.transform.up * (randPower * 1280f));
        attacker = ed;
        NextTurn();
    }
Ejemplo n.º 12
0
 public void ShowCharacters()
 {
     for (int i = 0; i < 5; ++i)
     {
         CharacterDoll doll = GameManager.Instance.playerDoll[i];
         Portrait      p    = playerPortrait[i];
         p.image.sprite = doll.chaInfo.portrait;
         p.hpBar.Initialize();
         p.doll        = doll;
         doll.portrait = p;
     }
     for (int i = 0; i < 5; ++i)
     {
         CharacterDoll doll = GameManager.Instance.enemyDoll[i];
         Portrait      p    = enemyPortrait[i];
         p.image.sprite = doll.chaInfo.portrait;
         p.hpBar.Initialize();
         p.doll        = doll;
         doll.portrait = p;
     }
 }
Ejemplo n.º 13
0
    private void ShotDoll()
    {
        touchStarted = false;
        attacking    = false;
        // CancleControl
        // u.CloseCancelControl();
        u.SetDollControlAimActive(false);
        if (cancelAct)
        {
            g.DeselectDoll();
            return;
        }
        CharacterDoll selectedDoll = g.selectedDoll;
        Rigidbody2D   rb           = selectedDoll.GetComponent <Rigidbody2D>();

        selectedDoll.defMode        = false;
        selectedDoll.rb.isKinematic = false;
        rb.AddForce(selectedDoll.transform.up * (powerScale * ONE_GRID_FORCE));
        g.attacker = selectedDoll;
        g.NextTurn();
    }
Ejemplo n.º 14
0
    public void OnCollisionEnter2D(Collision2D col)
    {
        GameManager g = GameManager.Instance;

        Vector3 posStart = this.transform.position;
        Vector3 n        = rb.velocity.normalized;
        Vector3 posEnd   = posStart + n;

        this.transform.rotation = Quaternion.Euler(0, 0, -Mathf.Atan2(posEnd.x - posStart.x, posEnd.y - posStart.y) * Mathf.Rad2Deg);

        if (col.gameObject.layer == LayerMask.NameToLayer("Doll") &&
            g.attacker == this)
        {
            CharacterDoll hit = col.gameObject.GetComponent <CharacterDoll>();
            if (hit.faction.isPlayer != this.faction.isPlayer)
            {
                if (hit.defMode)
                {
                    col.rigidbody.velocity = Vector2.zero;
                }
                else
                {
                    col.rigidbody.velocity = CalculateVelocity(this, hit);
                }
                hit.receivedDamage = hit.TakeDamage(this);
                g.victim           = hit;
                g.attacker         = null;
            }
        }
        else if (col.gameObject.layer == LayerMask.NameToLayer("Wall") && receivedDamage > 0)
        {
            int wallDmg = (int)(receivedDamage * 0.2f);
            if (wallDmg < 1)
            {
                wallDmg = 1;
            }
            TakeDamage(wallDmg);
            receivedDamage = 0;
        }
    }
Ejemplo n.º 15
0
 public void DeselectDoll()
 {
     selectedDoll.gameObject.layer = LayerMask.NameToLayer("Doll");
     selectedDoll = null;
     DollController.Instance.attackType = 0;
 }
Ejemplo n.º 16
0
 public void SelectDoll(CharacterDoll _doll)
 {
     selectedDoll = _doll;
     selectedDoll.gameObject.layer = LayerMask.NameToLayer("SelectedDoll");
     u.OpenActSelect(_doll);
 }
Ejemplo n.º 17
0
    private void UpdatePreview(float _touchDis)
    {
        CharacterDoll selectedDoll = g.selectedDoll;

        if (cancelAct)
        {
            lineRenderer[PREVIEW_INCOMING].gameObject.SetActive(false);
            lineRenderer[PREVIEW_REFLECT].gameObject.SetActive(false);
            lineRenderer[PREVIEW_TARGETGO].gameObject.SetActive(false);
            lineRenderer[PREVIEW_CIRCLE].gameObject.SetActive(false);
            return;
        }

        float bw    = Board.BOARD_WIDTH;
        float power = _touchDis * 2f;

        powerScale = power / bw;

        Transform        trans     = selectedDoll.transform;
        int              layerMask = -1 - (1 << LayerMask.NameToLayer("Background")) - (1 << LayerMask.NameToLayer("SelectedDoll"));
        CircleCollider2D col       = selectedDoll.GetComponent <CircleCollider2D>();
        RaycastHit2D     hit       = Physics2D.CircleCast(trans.position, col.radius - 0.01f, trans.up, power, layerMask);

        if (hit.collider != null)
        {
            Vector3 hpos = hit.point;
            Vector3 spos = selectedDoll.transform.position;
            hpos.z = PREVIEW_Z;
            spos.z = PREVIEW_Z;

            Vector3   i     = hpos - spos;                      // Incoming Vector.
            Vector3   n     = hit.normal;                       // Hit Vector Normalize.
            Vector3   tc    = hit.normal * col.radius;          // To Center Vector.
            Vector3   c     = hpos + tc;                        // Center Position.
            Vector3[] vecs1 = { spos, c };

            if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Doll"))
            {
                Vector3 tar = hit.collider.gameObject.transform.TransformPoint(hit.collider.offset);
                Vector3 res = tar + -n * 1f;
                res.z = PREVIEW_Z;

                Vector3[] vecs2 = { tar, res };
                lineRenderer[PREVIEW_INCOMING].SetPositions(vecs1);
                lineRenderer[PREVIEW_TARGETGO].SetPositions(vecs2);
                lineRenderer[PREVIEW_INCOMING].gameObject.SetActive(true);
                lineRenderer[PREVIEW_TARGETGO].gameObject.SetActive(true);
                lineRenderer[PREVIEW_REFLECT].gameObject.SetActive(false);
            }
            else
            {
                Vector3 r   = Vector3.Reflect(-i, n).normalized;
                Vector3 res = c + -r * 1f;
                res.z = PREVIEW_Z;

                Vector3[] vecs2 = { c, res };
                lineRenderer[PREVIEW_INCOMING].SetPositions(vecs1);
                lineRenderer[PREVIEW_REFLECT].SetPositions(vecs2);
                lineRenderer[PREVIEW_INCOMING].gameObject.SetActive(true);
                lineRenderer[PREVIEW_REFLECT].gameObject.SetActive(true);
                lineRenderer[PREVIEW_TARGETGO].gameObject.SetActive(false);
            }

            DrawPreviewCircle(c, col.radius);
        }
        else
        {
            Vector3 spos = selectedDoll.transform.position;
            Vector3 dpos = spos + selectedDoll.transform.up * power;
            spos.z = PREVIEW_Z;
            dpos.z = PREVIEW_Z;

            Vector3[] vecs = { spos, dpos };
            lineRenderer[PREVIEW_INCOMING].SetPositions(vecs);
            lineRenderer[PREVIEW_INCOMING].gameObject.SetActive(true);
            lineRenderer[PREVIEW_REFLECT].gameObject.SetActive(false);
            lineRenderer[PREVIEW_TARGETGO].gameObject.SetActive(false);

            DrawPreviewCircle(dpos, col.radius);
        }
        Vector2 offset = lineRenderer[PREVIEW_INCOMING].material.mainTextureOffset;

        offset.x -= (64f * Time.deltaTime * previewMaterialSpeed) % 64f;
        lineRenderer[PREVIEW_INCOMING].material.mainTextureOffset = offset;
        lineRenderer[PREVIEW_REFLECT].material.mainTextureOffset  = offset;
        attacking = true;
    }
Ejemplo n.º 18
0
    public void UpdatePlaceMode()
    {
        if (g.myTurn)
        {
            bool    touched  = false;
            Vector3 touchPos = new Vector3();
#if UNITY_ANDROID && !UNITY_EDITOR
            if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
            {
                touched  = true;
                touchPos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
            }
#else
            if (Input.GetMouseButtonDown(0))
            {
                touched  = true;
                touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            }
#endif
            if (touched)
            {
                Board   b        = Board.Instance;
                Vector3 boardPos = b.transform.InverseTransformPoint(touchPos);
                Vector2 aim      = b.GetNearGrid(boardPos.x, boardPos.y);
                Vector2 nearPos  = b.GetNearGridPosition(boardPos.x, boardPos.y);

                if (aim == lastAim)
                {
                    CharacterDoll doll = g.GetDoll(true, order);
                    doll.transform.localPosition = nearPos;
                    doll.gameObject.SetActive(true);
                    u.placeModeAim.rectTransform.localPosition = new Vector2(-9999f, -9999f);
                    remainPlace.RemoveAt(aimIndex);
                    lastAim = Vector2.zero;
                    SoundManager.Instance.PlayFX(placeFx);
                    ContinuePlaceMode();
                }
                else
                {
                    bool canPlace = false;
                    for (int i = 0; i < remainPlace.Count; ++i)
                    {
                        if (remainPlace[i] == aim)
                        {
                            canPlace = true;
                            aimIndex = i;
                            break;
                        }
                    }
                    if (canPlace)
                    {
                        float   res      = ((float)Screen.width / Screen.height) / (9f / 16f);
                        Vector3 worldPos = b.transform.TransformPoint(nearPos);
                        Vector2 scrnPos  = Camera.main.WorldToScreenPoint(worldPos) - new Vector3(Screen.width * 0.5f, 0f);
                        scrnPos.x /= u.resolutionScale.x / res;
                        scrnPos.y /= u.resolutionScale.y;
                        u.placeModeAim.rectTransform.localPosition = scrnPos;
                        lastAim = aim;
                    }
                }
            }

            if (g.timer <= 0f)
            {
                RandomPlace(true, order);
                ContinuePlaceMode();
            }
        }
        else
        {
            if (g.timer <= 39f)
            {
                RandomPlace(false, order);
                ContinuePlaceMode();
            }
        }
    }