Ejemplo n.º 1
0
        private FloorTile TileToSpread()
        {
            //("start: tiles to spread to: " + tilesToSpread.Count + " Neighbours: " + neighbourTiles.Count);
            tilesToSpread.Clear();

            foreach (Transform neighbourTile in neighbourTiles)
            {
                FloorTile neighbourTileCheck = neighbourTile.GetComponent <FloorTile>();
                if (!neighbourTileCheck.IsOnFire)
                {
                    tilesToSpread.Add(neighbourTile);
                }
            }

            // return null if there are no tiles around available to spread to
            if (tilesToSpread.Count < 1)
            {
                return(null);
            }

            int randomTileIndex = Random.Range(0, tilesToSpread.Count);

            FloorTile tile = tilesToSpread[randomTileIndex].GetComponent <FloorTile>();

            return(tile);
        }
Ejemplo n.º 2
0
        IEnumerator Spread()
        {
            while (true)
            {
                spreadTime -= Time.deltaTime;

                if (spreadTime <= 0)
                {
                    spreadTime = TIME_TO_SPREAD;

                    // apply DAMAGE
                    room.TakeDamage(DAMAGE);

                    // get tile to spread
                    FloorTile tileToSpread = TileToSpread();

                    // add fire to it, if there's any tile to spread to
                    if (tileToSpread != null)
                    {
                        tileToSpread.AddFire();
                    }
                }

                yield return(0);
            }
        }
Ejemplo n.º 3
0
        private bool Hit(FloorTile target)
        {
            // here we get all the information needed to calculate the damage output to the target
            // gathering the C constant for the shot's pseudo-random probability of hitting its target
            // the finaldamage only refers to the weapon's projectile,
            // the actual damage is calculated on the ship's floor tile considering the ship's armor (damage reduction)

            float shooterMarksmanLevel;

            if (sourceWeapon.handler != null)
            {
                shooterMarksmanLevel = sourceWeapon.handler.crewmemberStats.marksmanLevel;
            }
            else
            {
                shooterMarksmanLevel = 0;
            }

            float accuracy = BattleManager.ProjectileAccuracy(weapon.aim, shooterMarksmanLevel, target.shipManager.evasion);

            decimal c = BattleManager.CfromP((decimal)accuracy);

            float chanceToHit = (float)c * sourceWeapon.shotsBeforeHit;

            int rgn = GameManager.RGN(100);

            print(owner.gameObject.name + " shot " + target.shipManager.gameObject.name + " with " + accuracy + " of accuracy. Chance to hit is " + chanceToHit + ". RGN: " + rgn + " with its " + finalDamage + " of damage");

            return(chanceToHit > rgn ? true : false);
        }
Ejemplo n.º 4
0
        void Update()
        {
            // apply es to damage
            finalDamage = (damage + sourceWeapon.Ship.shipEffects.WeaponsDMG) * (1 + sourceWeapon.Ship.shipEffects.WeaponsDMG_P);
            finalSpeed  = (speed + sourceWeapon.Ship.shipEffects.WeaponsSPD) * (1 + sourceWeapon.Ship.shipEffects.WeaponsSPD_P);

            if (target != null)
            {
                // rotate towards the target.
                RotateTowardsTarget();

                // move towards target
                transform.position = Vector3.MoveTowards(transform.position, target.position, finalSpeed * Time.deltaTime);

                // when target is reached
                if (transform.position == target.position)
                {
                    if (target.GetComponent <FloorTile>() != null)
                    {
                        FloorTile tile = target.GetComponent <FloorTile>();

                        // random dodge number
                        //int randomDodgeNumber = Random.Range(0, 100);

                        // if hits target
                        //if (randomDodgeNumber > tile.shipManager.evasion) {
                        if (Hit(tile))
                        {
                            tile.TakeDamage(finalDamage, weapon);
                            // destroy itself
                            Destroy(this.gameObject);

                            sourceWeapon.shotsBeforeHit = 1;
                        }
                        else
                        {
                            //miss
                            target = null;

                            sourceWeapon.shotsBeforeHit++;
                        }
                    }
                    else
                    {
                        Debug.LogError("FloorTile script component is missing on: " + this.name);
                    }

                    sourceWeapon.DestroyAim();
                }
            }
            else
            {
                transform.position += normalizedDirection * finalSpeed * Time.deltaTime;
                camManager.CheckIfOutOfBounds(this.gameObject);
            }
        }
Ejemplo n.º 5
0
        private void InstantiateTile(Vector3 currentPos)
        {
            // instantiate.
            GameObject tile = Instantiate(tilePF, currentPos, Quaternion.identity);

            // group up.
            tile.transform.SetParent(this.transform);
            // set tile hp and armor.
            FloorTile tileScript = tile.GetComponent <FloorTile>();

            tileScript.hp = shipManager.tileHP;
            // pass ship (manager) reference.
            tileScript.shipManager = shipManager;
            // add tile to the list of tiles.
            tiles.Add(tile);
        }
Ejemplo n.º 6
0
        private void CheckNeighbourRooms()
        {
            foreach (Transform neighbour in neighbourTiles)
            {
                if (this.room == null)
                {
                    Debug.LogError("this tile " + this.name + " doesn't have a room? : " + transform.parent.name);
                    return;
                }

                FloorTile neighbourTile = neighbour.GetComponent <FloorTile>();

                if (neighbourTile.room == null)
                {
                    Debug.LogError("neighbour tile " + neighbourTile.name + " doesn't have a room? : " + neighbourTile.transform.parent.name);
                    return;
                }

                if (this.room.gameObject.name != neighbourTile.room.gameObject.name)
                {
                    this.room.neighbourRooms.Add(neighbourTile.room);
                }
            }
        }