Example #1
0
        public void Mine(bool clear = false)
        {
            if (this.IsMined)
            {
                return;
            }

            this.IsMined = true;
            OnMined?.Invoke();

            if (!clear)
            {
                return;
            }

            if (this.Type == TileType.Mine || this.Type == TileType.AncientTechnology)
            {
                return;
            }

            if (this.AdjMineCount != 0)
            {
                return;
            }

            foreach (var tile in AdjTiles)
            {
                tile.Mine(false);
            }
        }
Example #2
0
    public virtual void Smash(int power, Side hitFrom, bool obliterate = false)
    {
        //Debug.Log($"smash2? {power} {hitFrom}");
        // if hit from the left, destroy left sprite first
        power = Mathf.Clamp(power - hardness, 0, maxHp);
        int damageDone = Mathf.Min(currentHp, power);

        bool midActiveBefore = midSprite.activeSelf;

        if (damageDone > 0)
        {
            switch (hitFrom)
            {
            case Side.Left:
                SmashFromLeft(damageDone);
                break;

            case Side.Top:
                SmashFromTop(damageDone);
                break;

            case Side.Right:
                SmashFromRight(damageDone);
                break;

            case Side.Bottom:
                SmashFromBottom(damageDone);
                break;

            case Side.Mid:
                SmashFromSide(damageDone);
                break;
            }
        }
        else
        {
            // ore was too hard
            // send a message?
            //return 0?
        }
        currentHp -= damageDone;
        if (!obliterate)
        {
            OnMined?.Invoke(oreType, damageDone);
            if (midActiveBefore && !midSprite.activeSelf)
            {
                // active before and not now
                OnMidMined?.Invoke(oreType);
            }
        }
    }