Esempio n. 1
0
    public void Damage(int _iAttack, string _strAttribute)
    {
        // 減るHPがないときはダメージを受けない

        //Debug.Log(string.Format("hp={0} is_dead={1}", DataManager.Instance.dataChara.is_dead, DataManager.Instance.dataChara.hp));
        if (DataManager.Instance.dataChara.hp < 0 || DataManager.Instance.dataChara.is_dead)
        {
            return;
        }

        const float DAMAGE_VECTOR_BASE  = -0.2f;
        const float DAMAGE_VECTOR_SWING = 0.1f;

        /*
         * float fDamage = (float)(_iAttack * _iAttack) / (float)DataManager.Instance.dataChara.defence * (DAMAGE_RATE + (UtilRand.GetRange(DAMAGE_SWING) - DAMAGE_SWING * 0.5f));
         * fDamage *= Defines.GetAttributeRate(DataManager.Instance.dataChara.attribute_defence, _strAttribute);
         * if (fDamage < 1.0f)
         * {
         *      fDamage = 1.0f;
         * }
         * int iDamageResult = (int)fDamage;
         */

        int iDamageResult = CalcDamage.Damage(_iAttack, _strAttribute, DataManager.Instance.dataChara.defence, DataManager.Instance.dataChara.attribute_defence);

        //Debug.Log(string.Format("chara attack={0} defence={1}", _iAttack, DataManager.Instance.dataChara.defence));

        Defines.ATTRIBUTE_CONDITION condition = Defines.GetAttributeCondition(DataManager.Instance.dataChara.attribute_defence, _strAttribute);
        Color damage_color = Defines.GetAttributeDamageColor(condition);


        //Debug.Log("player damage :" + iDamageResult.ToString());
        Quaternion rot = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f);
        GameObject obj = Instantiate(m_prefDamageText, Vector3.zero, rot, m_goRootDamageText.transform) as GameObject;

        obj.SetActive(true);
        obj.transform.localPosition = Vector3.zero;
        //obj.GetComponent<Animator>().SetInteger("damage_level", 1);
        obj.GetComponent <TMPro.TextMeshPro>().text  = iDamageResult.ToString();
        obj.GetComponent <TMPro.TextMeshPro>().color = damage_color;

        Vector2 dir = new Vector2(
            DAMAGE_VECTOR_BASE - (UtilRand.GetRange(DAMAGE_VECTOR_SWING) + DAMAGE_VECTOR_SWING * 0.5f),
            1.0f + (UtilRand.GetRange(DAMAGE_VECTOR_SWING) + DAMAGE_VECTOR_SWING * 0.5f));

        obj.GetComponent <Rigidbody2D>().AddForce(200f * dir);
        Destroy(obj, 2);
        DataManager.Instance.dataChara.hp -= iDamageResult;
        GameMain.Instance.BattleLog(string.Format("<color=red>{0}</color>のダメージを受けた!", iDamageResult));
    }
Esempio n. 2
0
    //public const float DAMAGE_RATE = 1.0f;
    //public const float DAMAGE_SWING = 0.25f;

    public int Damage(int _iAttack, string _strAttribute)
    {
        //float fDamage = (float)(_iAttack * _iAttack) / (float)defence * (DAMAGE_RATE + (UtilRand.GetRange(DAMAGE_SWING) - DAMAGE_SWING * 0.5f));

        /*
         * Debug.Log((float)(_iAttack * _iAttack));
         * Debug.Log((float)defence);
         * Debug.Log((float)(_iAttack * _iAttack) / (float)defence);
         * Debug.Log((DAMAGE_RATE + (UtilRand.GetRange(DAMAGE_SWING) - DAMAGE_SWING * 0.5f)));
         * Debug.Log(fDamage);
         *
         * float temp = 0;
         * for( int i = 0; i < 100; i++)
         * {
         *      temp += UtilRand.GetRange(DAMAGE_SWING);
         * }
         * Debug.Log(temp * 0.01f);
         */
        /*
         * fDamage *= Defines.GetAttributeRate(attribute, _strAttribute);
         *
         * if( fDamage < 1.0f)
         * {
         *      fDamage = 1.0f;
         * }
         *
         * // 属性補正
         *
         * int iDamageResult = (int)fDamage;
         */

        int iDamageResult = CalcDamage.Damage(_iAttack, _strAttribute, defence, attribute);

        //Debug.Log(string.Format("enemydamage attack={0} defence={1}", _iAttack, defence));


        //Debug.Log(string.Format("hp={0} damage={1}", hp, iDamageResult));
        hp -= iDamageResult;
        return(iDamageResult);
    }