Beispiel #1
0
        public void TapFeeder(Feeder feeder)
        {
            if (UIOpen)
            {
                return;
            }

            NavigationManager.OpenFeederMenu(feeder);
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        public void InitFeederModal(Feeder feeder, GardenManager gardenManager)
        {
            FeederRef        = feeder;
            GardenManagerRef = gardenManager;

            Dictionary <int, int> seedInventory = GardenManagerRef.GetSeeds();

            foreach (int seedId in seedInventory.Keys)
            {
                Seed       seedtype = GardenManagerRef.GetSeedTypeById(seedId);
                FeederItem item     = Instantiate <FeederItem>(FeederItemPrefab, ContentRoot.transform);
                item.InitFeederItem(seedtype, seedInventory[seedId], this);
            }
        }
Beispiel #4
0
        Feeder GetFeederById(int feederId)
        {
            Feeder feeder = null;

            foreach (Feeder test in PossibleFeeders)
            {
                if (test.FeederId == feederId)
                {
                    feeder = test;
                    break;
                }
            }

            return(feeder);
        }
Beispiel #5
0
 void TapFeeder(Feeder feeder)
 {
 }
Beispiel #6
0
        // Update is called once per frame
        void Update()
        {
            float frameDeltaTime = Time.deltaTime;

            TimeSinceLastSpawn += frameDeltaTime;
            if (TimeSinceLastSpawn >= TimeBetweenSpawns)
            {
                AttemptSpawn();

                TimeSinceLastSpawn = 0.0f;
                TimeBetweenSpawns  = Random.Range(MinTimeBetweenSpawns, MaxTimeBetweenSpawns);
            }

            List <GardenVisitor> pendingDestroy = new List <GardenVisitor>();

            foreach (GardenVisitor visitor in CurrentGardenVisitors)
            {
                Feeder feeder  = GetFeederById(visitor.GetFeederId());
                bool   eating  = visitor.GetIsEating();
                bool   leaving = visitor.GetPendingLeave();

                visitor.UpdateGardenVisitor(frameDeltaTime);
                int amountToConsume = visitor.GetPendingEatAmount();

                if (!eating)
                {
                    // t = 0 is a (feeder)
                    // t = 1 is b (spawner)
                    // Vector2.Lerp(Vector2 a, Vector2 b, float t)
                    FeederLandingSpot landingSpot = null;
                    if (visitor.IsGround)
                    {
                        landingSpot = feeder.GetGroundLandingSpotById(visitor.GetFeederLandingSpotId());
                    }
                    else
                    {
                        landingSpot = feeder.GetAirLandingSpotById(visitor.GetFeederLandingSpotId());
                    }
                    Vector2 landingSpotPosition2d = landingSpot.transform.position;

                    Spawner spawner           = GetSpawnerById(visitor.GetSpawnerId());
                    Vector2 spawnerPosition2d = spawner.transform.position;

                    float visitorLerpPosition = visitor.GetLerpPosition();
                    visitor.transform.position = Vector2.Lerp(landingSpotPosition2d, spawnerPosition2d, visitorLerpPosition);

                    if (visitor.GetPendingLeave())
                    {
                        if (visitorLerpPosition >= 1.0f)
                        {
                            pendingDestroy.Add(visitor);
                        }
                    }
                    else
                    {
                        if (visitorLerpPosition <= 0.0f)
                        {
                            visitor.BeginEating();
                            if (feeder.GetIsEmpty())
                            {
                                visitor.SetAnimState(EVisitorAnimState.EVAS_Idle);
                            }
                            else
                            {
                                float direction = spawnerPosition2d.x * landingSpotPosition2d.x;
                                if (direction < 0.0f)
                                {
                                    visitor.transform.Rotate(Vector3.up, 180);
                                    visitor.SetFlippedToEat(true);
                                }
                                visitor.SetAnimState(EVisitorAnimState.EVAS_Eat);
                            }
                        }
                    }
                }

                switch (visitor.EatType)
                {
                case EResourceType.ERT_Seed:
                    feeder.Consume(amountToConsume);
                    if (feeder.GetIsEmpty())
                    {
                        foreach (GardenVisitor gv in CurrentGardenVisitors.Where(gardenVisitor => gardenVisitor.GetFeederId() == feeder.FeederId))
                        {
                            if (gv.MinRarity >= 0)
                            {
                                gv.Leave();
                            }
                        }
                    }
                    break;

                case EResourceType.ERT_Money:
                    PlayerInventory.UpdateMoney(-1 * amountToConsume);
                    break;
                }
                visitor.ConsumePending();
            }

            foreach (GardenVisitor visitor in pendingDestroy)
            {
                CurrentGardenVisitors.Remove(visitor);

                Feeder feeder = GetFeederById(visitor.GetFeederId());
                feeder.ReleaseSlot(visitor.IsGround, visitor.GetFeederLandingSpotId());

                Destroy(visitor.gameObject);
            }

            pendingDestroy.Clear();

            foreach (Feeder feeder in PossibleFeeders)
            {
                feeder.UpdateFeeder(frameDeltaTime);
            }

            //Update Money in real time
            TextField.text = "$" + GetMoney().ToString();
        }
Beispiel #7
0
 public void FillFeederWithSeed(Feeder feeder, Seed seed)
 {
     feeder.FillFeeder(seed.Rarity);
     RemoveSeed(seed.SeedId, 1);
 }