Esempio n. 1
0
        void AttemptSpawn()
        {
            EVisitorPersuasion persuasion = ChooseVisitorPersuasion();

            bool isGround = persuasion == EVisitorPersuasion.EVP_Pest;

            FeederLandingSpot landingSpot    = null;
            Feeder            spawningFeeder = null;

            foreach (Feeder feeder in PossibleFeeders)
            {
                if (feeder != null && feeder.GetIsUnlocked())
                {
                    if (isGround && feeder.CanSpawnGround())
                    {
                        landingSpot    = feeder.GetNextFreeGroundSlot();
                        spawningFeeder = feeder;
                        break;
                    }

                    if (!isGround && feeder.CanSpawnAir())
                    {
                        landingSpot    = feeder.GetNextFreeAirSpot();
                        spawningFeeder = feeder;
                        break;
                    }
                }
            }

            if (spawningFeeder != null && landingSpot != null)
            {
                Spawner spawner       = ChooseSpawner(isGround);
                Vector3 spawnPosition = spawner.transform.position;
                spawnPosition.z = 0;

                GardenVisitor attemptedVisitor = ChooseVisitorType(spawningFeeder.GetCurrentFeedRarity(), persuasion);
                if (attemptedVisitor == null)
                {
                    return;
                }

                GardenVisitor newVisitor = Instantiate(attemptedVisitor, spawnPosition, Quaternion.identity, gameObject.transform);
                if (newVisitor.transform.position.x < 0.0f)
                {
                    newVisitor.transform.Rotate(Vector3.up, 180);
                }

                newVisitor.InitializeGardenVisitor();
                newVisitor.SetFeederId(spawningFeeder.FeederId);
                newVisitor.SetFeederLandingSpotId(landingSpot.LandingSpotId);
                newVisitor.SetSpawnerId(spawner.SpawnerId);

                spawningFeeder.AssignSlot(isGround);

                CurrentGardenVisitors.Add(newVisitor);
            }
        }
Esempio n. 2
0
        GardenVisitor ChooseVisitorType(int rarity, EVisitorPersuasion persuasion)
        {
            GardenVisitor visitorTypePrefab = null;

            IEnumerable <GardenVisitor> filteredList = PossibleGardenVisitorPrefabs.Where(visitor => visitor.MinRarity <= rarity && visitor.MaxRarity >= rarity && visitor.VisitorPersuasion == persuasion);
            int filteredCount = filteredList.Count();

            if (filteredCount > 0)
            {
                int roll = Random.Range(0, filteredCount - 1);
                visitorTypePrefab = filteredList.ElementAt(roll);
            }

            return(visitorTypePrefab);
        }
Esempio n. 3
0
        EVisitorPersuasion ChooseVisitorPersuasion()
        {
            EVisitorPersuasion persuasion = EVisitorPersuasion.EVP_Regular;

            int roll = Random.Range(1, 100);

            if (roll <= (ProbabilityForPests + ProbabilityForSpecial))
            {
                persuasion = EVisitorPersuasion.EVP_Special;
            }

            if (roll <= ProbabilityForPests)
            {
                persuasion = EVisitorPersuasion.EVP_Pest;
            }

            return(persuasion);
        }