Exemple #1
0
    /// <summary>
    /// attack a target and do everything needed
    /// </summary>
    /// <param name="target"></param>
    bool Attack(Unit target)
    {
        if (AttackInfo.CanAttack(this, target))
        {
            float dx = transform.position.x - target.transform.position.x;
            if (dx > 0)
            {
                FaceRight = false;
            }
            else if (dx < 0)
            {
                FaceRight = true;
            }

            Stats      s       = GetStatsAt(Tile, target);
            Stats      es      = target.GetStatsAt(target.Tile, this);
            float      roll    = UnityEngine.Random.Range(0f, 1f);
            DamageData dmgData = new DamageData();
            dmgData.hitChance  = s.HitVersus(es);
            dmgData.critChance = s.CritVersus(es);
            dmgData.hit        = roll < dmgData.hitChance;      //ModifiedStats.Hit-target.ModifiedStats.Dodge;
            dmgData.crit       = roll < dmgData.critChance;     //(ModifiedStats.crit - target.ModifiedStats.critDodge);
            dmgData.target     = target;
            dmgData.source     = this;
            attackData         = dmgData;
            AttackModifiers(dmgData);             // run the attack through modifiers
            AnimateAttack();
            AddDamageData(dmgData);
            return(true);
        }
        return(false);
    }