Example #1
0
    /// <summary>
    /// Is called when walls next to the main dmaged walls are damaged by proxy. Doesn't call damageConnectedWalls, hence the "non recursive". Will NOT update corners.
    /// </summary>
    /// <param name="damage"></param>
    /// <param name="damageType"></param>
    public void nonRecursiveDealDamage(float damage, Elements.DamageType damageType)
    {
        //No damage is dealt if the block's damage type is equal to the source's damage type, as long as they aren't the normal types (blunt/sharp)
        float finalDamage = damage - armor;

        if (finalDamage < 1)
        {
            return;
        }
        if (damageType != Elements.DamageType.Blunt && damageType != Elements.DamageType.Sharp && damageType == getDamageType())
        {
            return;
        }
        finalDamage *= elementEffectiveness(damageType);
        life        -= finalDamage;

        if (life <= 0)
        {
            destroy();
        }
        else
        {
            updateChildCracks();
        }
    }
Example #2
0
 public override void initStats()
 {
     damageType = Elements.DamageType.Blunt;
     cooldown   = 0.55f - Mathf.Min(0.02f * user.FITNESS, 0.15f);
     cost       = 1.5f;
     range      = 0.6f;
     damage     = 3 + user.STRENGTH * 0.7f; // it's fine
     pushback   = 3 + user.STRENGTH * 1.5f;
 }
Example #3
0
    /// <summary>
    /// Deals damage to this block (will only be called for walls). the controller should be a Person's object, not a projectile/ability. Will update corners (and might damage connected walls).
    /// </summary>
    public void dealDamage(float damage, float pushback, GameObject damageSourceController, Elements.DamageType damageType)
    {
        //No damage is dealt if the block's damage type is equal to the source's damage type, as long as they aren't the normal types (blunt/sharp)
        float finalDamage = damage + pushback - armor;

        if (finalDamage < 1)
        {
            return;
        }
        if (damageType != Elements.DamageType.Blunt && damageType != Elements.DamageType.Sharp && damageType == getDamageType())
        {
            return;
        }
        finalDamage *= elementEffectiveness(damageType);
        life        -= finalDamage;

        if (life <= 0)
        {
            destroy();
        }
        else
        {
            updateChildCracks();
        }
        if (finalDamage >= 30 - armor)
        {
            damageConnectedWalls(finalDamage + armor, damageSourceController, damageType);
        }
        updateCorners();
    }
Example #4
0
    /// <summary>
    /// Returns the effectiveness multiplier. Default is 1. Is 2 if the attack is super-effective (e.g. Fire VS Plant) and 0.5 if it's not efective (e.g. Acid VS Cement). Hard-coded!
    /// </summary>
    /// <param name="damageType"></param>
    /// <returns></returns>
    public float elementEffectiveness(Elements.DamageType damageType)
    {
        switch (damageType)
        {
        case Elements.DamageType.Blunt:
            return(1);

        case Elements.DamageType.Sharp:
            return(1);

        case Elements.DamageType.Burn:
            if (type == Type.wPlant)
            {
                return(2);
            }
            if (type == Type.wIce)
            {
                return(2);
            }
            if (type == Type.wFlesh)
            {
                return(2f);
            }
            if (type == Type.wMetal)
            {
                return(0.5f);
            }
            if (type == Type.wCement)
            {
                return(0.5f);
            }
            if (type == Type.wEarth)
            {
                return(0.5f);
            }
            return(1);

        case Elements.DamageType.Acid:
            if (type == Type.wFlesh)
            {
                return(2);
            }
            if (type == Type.wMetal)
            {
                return(2f);
            }
            if (type == Type.wIce)
            {
                return(0.5f);
            }
            if (type == Type.wCement)
            {
                return(0.5f);
            }
            return(1);

        case Elements.DamageType.Shock:
            if (type == Type.wFlesh)
            {
                return(2);
            }
            if (type == Type.wMetal)
            {
                return(0f);
            }
            return(0.5f);

        default:
            Debug.LogError("Weird damage type for the damage of the damag source that dealt damage to this damaged block pls halp");
            return(10);
        }
    }
Example #5
0
    /// <summary>
    /// Is called when the wall is heavily damaged (30+ damage). Will damage nearby walls. Will update corners.
    /// </summary>
    public void damageConnectedWalls(float damage, GameObject damageSourceController, Elements.DamageType damageType)
    {
        float radius = damage / 11; //why 11? I dunno

        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, radius, LayerMask.NameToLayer("Walls"));
        float        minX = transform.position.x, minY = transform.position.y, maxX = transform.position.x, maxY = transform.position.y;

        foreach (Collider2D c in colliders)
        {
            Block wall = c.gameObject.GetComponent <Block>();
            if (wall == null)
            {
                Debug.LogError("Pastramamia! " + c.gameObject.name);
            }
            if (wall.transform.position == this.transform.position)
            {
                continue;
            }
            //damage = damage divided by the distance
            float itsDamage = damage / (c.gameObject.transform.position - transform.position).magnitude;
            wall.nonRecursiveDealDamage(itsDamage, damageType);

            minX = Mathf.Min(minX, c.transform.position.x);
            minY = Mathf.Min(minY, c.transform.position.y);
            maxX = Mathf.Max(maxX, c.transform.position.x);
            maxY = Mathf.Max(maxY, c.transform.position.y);
        }
        Environment env = GetComponentInParent <Environment>();                //neat function!

        env.updateCornersStandard((int)minX, (int)minY, (int)maxX, (int)maxY); //TODO make sure I don't need to add 0.5 or something, because of chunk offset
    }