void TryAttack()
    {
        bool isAttack = RBInput.GetButtonDownForPlayer(InputStrings.FIRE, PlayerIndex, playerDevice);

        if (isAttack)
        {
            fighter.SwingWeapon(Fighter.AttackType.Weak);
        }
        else
        {
            bool isHeavyAttack = Input.GetKeyDown(KeyCode.Mouse1);
            if (isHeavyAttack)
            {
                fighter.SwingWeapon(Fighter.AttackType.Strong);
            }
        }
        bool test = Input.GetKeyDown(KeyCode.Backspace);

        if (test)
        {
            int i = 0;
            while (i < 1000)
            {
                Debug.Log("Yes or no:" + RBRandom.PercentageChance(24.5f).ToString());
                i++;
            }
        }
    }
    /*
     * Spawn the tile, set it up according to the Terrain parameters,
     * and parent it to the FarmTerrain for grouping purposes
     */
    private void SpawnGroundTileAtRowAndCol(Vector3 localOrigin, float row, float col)
    {
        // Tile edges should align with the terrain, not their centers, so we must shift them by their "radius"
        Vector3 TILE_OFFSET = new Vector3(GroundTile.SIZE_XZ / 2.0f, GroundTile.SIZE_Y / 2.0f, GroundTile.SIZE_XZ / 2.0f);
        // Convert row and column to local x and z coordinates
        Vector3 xyzPosition = new Vector3(row * GroundTile.SIZE_XZ, 0, col * GroundTile.SIZE_XZ);

        GameObject tile = (GameObject)Instantiate(groundTilePrefab,
                                                  (localOrigin + TILE_OFFSET + xyzPosition), Quaternion.identity);

        tile.transform.parent = transform;

        // Turn this tile into a grass or dirt tile based on settings
        GroundTile tileScript = tile.GetComponent <GroundTile> ();

        if (RBRandom.PercentageChance(grassPercent))
        {
            tileScript.SetState(GroundTile.GroundState.Grass);
            // Check if we should spawn a wildflower
            if (RBRandom.PercentageChance(wildflowerSpawnPercent))
            {
                SpawnWildFruitOnTile(tile);
            }
        }
        else
        {
            tileScript.SetState(GroundTile.GroundState.Dirt);
        }
    }
 /*
  * Performs nightly decay on all ground tiles
  */
 public void DoNightlyDecay()
 {
     //TODO: This could really be optimized
     // Spawn wild fruit
     foreach (Transform child in transform)
     {
         if (child.GetComponent <GroundTile> ().isGrass())
         {
             if (RBRandom.PercentageChance(wildflowerNightlySpawnPercent))
             {
                 SpawnWildFruitOnTile(child.gameObject);
             }
         }
     }
 }
Exemple #4
0
    /*
     * Using the provided list of sections, find one that is compatible and return it.
     * If none is found, return an empty section.
     */
    GameObject GetRandomSectionFromBucket(List <GameObject> sectionsToPickFrom)
    {
        // Set up a bag of indexes to draw from for the provided sectionsToPickFrom
        List <int> bagOfIndexes = new List <int> (sectionsToPickFrom.Count);

        for (int i = 0; i < sectionsToPickFrom.Count; i++)
        {
            bagOfIndexes.Add(i);
        }
        RBRandom.Shuffle <int> (bagOfIndexes);
        // Just take the first you get if it's the first one drawn
        if (GetLastSectionInPlay() == null)
        {
            return(sectionsToPickFrom[bagOfIndexes[0]]);
        }

        // Iterate through our random bag until we pick a section that is compatible.
        Section sectionToCheck;
        Section lastSection            = (Section)GetLastSectionInPlay().GetComponent <Section> ();
        int     compatibleSectionIndex = -1;

        foreach (int index in bagOfIndexes)
        {
            sectionToCheck = sectionsToPickFrom[index].GetComponent <Section> ();
            if (lastSection.CanBeFollowedBy(sectionToCheck))
            {
                compatibleSectionIndex = index;
                break;
            }
        }

        if (compatibleSectionIndex == -1)
        {
            Debug.LogWarning("Couldn't find a compatible section in the bucket. This can " +
                             "be fixed by adding a section prefab with open exits and entrances.");
            return(emptySection);
        }
        return(sectionsToPickFrom [compatibleSectionIndex]);
    }
Exemple #5
0
    void Start()
    {
        // Create an empty object to parent prefabs to (for some reason, the children prefabs can't
        // be attached to this section itself.
        tempPrefabHolder = new GameObject("Prefabs");
        // Move our prefabs now that they've been created
        tempPrefabHolder.transform.parent = transform;

        // Shuffle the three crystal prefabs
        List <GameObject> threeCrystals = new List <GameObject> {
            redCrystalPrefab, greenCrystalPrefab, blueCrystalPrefab
        };

        RBRandom.Shuffle <GameObject> (threeCrystals);
        GameObject randomCrystalForPickupA = threeCrystals[0];
        GameObject randomCrystalForPickupB = threeCrystals[1];
        GameObject randomCrystalForPickupC = threeCrystals[2];

        // Place all our prefabs on the section
        InstantiatePrefabsFromArray(blockPrefab, blockPlaceholders, tempPrefabHolder.transform);
        InstantiatePrefabsFromArray(randomCrystalForPickupA, pickupAPlaceholders, tempPrefabHolder.transform);
        InstantiatePrefabsFromArray(randomCrystalForPickupB, pickupBPlaceholders, tempPrefabHolder.transform);
        InstantiatePrefabsFromArray(randomCrystalForPickupC, pickupCPlaceholders, tempPrefabHolder.transform);
        InstantiatePrefabsFromArray(redCrystalPrefab, redPickupPlaceholders, tempPrefabHolder.transform);
        InstantiatePrefabsFromArray(greenCrystalPrefab, greenPickupPlaceholders, tempPrefabHolder.transform);
        InstantiatePrefabsFromArray(blueCrystalPrefab, bluePickupPlaceholders, tempPrefabHolder.transform);
        if (treadmill.NeedsWildcard())
        {
            foreach (Vector3 wildcardPostion in wildcardPlaceholders)
            {
                GameObject clonedPrefab = (GameObject)Instantiate(wildcardPrefab, transform.position + wildcardPostion,
                                                                  Quaternion.identity);
                clonedPrefab.transform.parent = tempPrefabHolder.transform;
                treadmill.OnWildcardSpawn();
            }
        }
    }