Exemple #1
0
    // Called in Health.cs by BroadcastMessage("Die")
    void Die()
    {
        int usedPos = 0;

        positions.Shuffle();

        for (byte i = 0; i < drops.Length && i < chance.Length; ++i)
        {
            if (RandomEx.GetEventWithChance(chance[i]))
            {
                if (drops[i] == null)
                {
                    Debug.LogError($"Can't spawn {drops[i]}, prefab is null");
                    continue;
                }

                GameObject go = Instantiate(drops[i], positions[usedPos].position, Quaternion.Euler(0, 0, Random.Range(0, 360)), transform.parent);

                Rigidbody2D objectRb = go.GetComponent <Rigidbody2D>();
                if (objectRb)
                {
                    objectRb.velocity        += rb.velocity;
                    objectRb.velocity        += (Vector2)positions[usedPos].localPosition.normalized * dropForce.GetRandomValue();
                    objectRb.angularVelocity += rb.angularVelocity;
                }

                ++usedPos;
            }
        }
    }
Exemple #2
0
    private void MakeKast(float damageMultiper, float heal, float defence, int crit)
    {
        bool  critChance    = RandomEx.GetEventWithChance(crit);
        float currentDamage = this.currentMonster.Stats[(int)StatType.Attack];

        this.currentMonster.TakeDamage((critChance) ?(currentDamage * damageMultiper * 1.5f) : currentDamage *damageMultiper);

        this.currentMonster.Heal((critChance) ? heal * crit : heal);
    }
Exemple #3
0
    public float DoDamage()
    {
        currAttackTimer -= oneAttackTime;

        float dmg        = Stats[(int)StatType.Attack];
        bool  isCritical = RandomEx.GetEventWithChance(Mathf.RoundToInt(Stats[(int)StatType.CriticalChance]));

        if (isCritical)
        {
            dmg *= 1.5f;
        }

        return(dmg);
    }
Exemple #4
0
    void Start()
    {
        visualParent               = new GameObject("GridVisual").transform;
        visualParent.parent        = transform;
        visualParent.localPosition = Vector3.zero;
        visualParent.eulerAngles   = Vector3.zero;

        for (int x = 0; x < gridSize.x; ++x)
        {
            for (int y = 0; y < gridSize.y; ++y)
            {
                GameObject go = Instantiate(cellPrefab, visualParent);
                go.name = $"Cell-{x}-{y}";

                Cell cell = go.GetComponent <Cell>();
                cell.MyGrid = this;
                cell.Coord  = new Vector2Int(x, y);

                if (x <= Random.Range(0, 2) || y <= Random.Range(0, 2) || x >= gridSize.x - Random.Range(1, 3) || y >= gridSize.y - Random.Range(1, 3))
                {
                    cell.foregroud  = Cell.CellContentForegroud.Bedrock;
                    cell.background = Cell.CellContentBackground.Bedrock;
                    cell.ore        = Cell.CellContentOre.None;
                }
                else if (y + Random.Range(-2, 2) < gridSize.y / 2)
                {
                    cell.foregroud  = Cell.CellContentForegroud.Stone;
                    cell.background = Cell.CellContentBackground.Stone;
                    cell.ore        = Cell.CellContentOre.None;
                }
                else
                {
                    cell.foregroud  = Cell.CellContentForegroud.Dirt;
                    cell.background = Cell.CellContentBackground.Dirt;
                    cell.ore        = Cell.CellContentOre.None;
                }

                if (cell.background == Cell.CellContentBackground.Stone && RandomEx.GetEventWithChance(1))
                {
                    cell.ore = Cell.CellContentOre.OreGold;
                }
                else if ((cell.background == Cell.CellContentBackground.Stone || cell.background == Cell.CellContentBackground.Dirt) && RandomEx.GetEventWithChance(1))
                {
                    cell.ore = Cell.CellContentOre.OreIron;
                }

                if (startRoom.Contains(new Vector2(x, y)))
                {
                    cell.foregroud = Cell.CellContentForegroud.None;
                    cell.ore       = Cell.CellContentOre.None;
                }

                if (startOreGold.Contains(new Vector2(x, y)))
                {
                    cell.ore = Cell.CellContentOre.OreGold;
                }
                else if (startOreIron.Contains(new Vector2(x, y)))
                {
                    cell.ore = Cell.CellContentOre.OreIron;
                }

                cell.Init();
                cells.Add(cell);

                if (x == playerStartPos.x && y == playerStartPos.y)
                {
                    GameManager.Instance.player.mover.transform.position = cell.transform.position;
                }
            }
        }
    }