예제 #1
0
    public void SetIndex(int index)
    {
        this.index = index;

        var gamePlanted = PlayerPrefs.GetInt(PlantPref(), -1);
        var plantType   = PlayerPrefs.GetInt(PlantPref() + "-type", -1);

        Status = PlantStatus.Empty;

        renderer.sprite = emptySprite;

        if (gamePlanted > -1)
        {
            plant           = plantTypes.GetPlant(plantType);
            Status          = PlantStatus.Planted;
            renderer.sprite = growingSprite;

            turnsLeft = plant.TurnsToGrow - (gameManager.GamesPlayed - gamePlanted);

            if (turnsLeft <= 0)
            {
                Status          = PlantStatus.Ready;
                renderer.sprite = grownSprite;
            }
        }
    }
예제 #2
0
 private void Awake()
 {
     gameController = GameObject.Find("GameController").GetComponent <GameController>();
     fireTimer      = 0;
     plantStatus    = PlantStatus.Base;
     SwitchColor();
 }
예제 #3
0
 // Event invocations.
 private void OnDied(PlantStatus ps)
 {
     if (Died != null)
     {
         Died(ps);
     }
 }
예제 #4
0
 // Event invocations.
 private void OnCropDied(PlantStatus victim)
 {
     if (CropDied != null)
     {
         CropDied(victim);
     }
 }
예제 #5
0
 private void OnCropGrown(PlantStatus crop)
 {
     if (CropGrown != null)
     {
         CropGrown(crop);
     }
 }
예제 #6
0
 private void OnGrown(PlantStatus ps)
 {
     if (Grown != null)
     {
         Grown(ps);
     }
 }
예제 #7
0
    void SetPlantStatus(PlantStatus status)
    {
        Renderer renderer = plantBody.GetComponent <Renderer>();

        switch (status)
        {
        case PlantStatus.Healthy:
            renderer.material.color = new Color(0.13f, 0.54f, 0.13f);
            StopCoroutine("BurnCountdown");
            StopCoroutine("SpreadFire");
            //I was going to stop all coroutines, but I think in the future a "grow" coroutine might be cool, so I'll stop them by name now
            break;

        case PlantStatus.OnFire:
            if (plantStatus == PlantStatus.Healthy)
            {
                renderer.material.color = new Color(0.50f, 0.0f, 0.0f);
                plantStatus             = PlantStatus.OnFire;
                StartCoroutine("BurnCountdown");
                StartCoroutine("SpreadFire");
            }
            break;

        case PlantStatus.Burnt:
            renderer.material.color = new Color(0.0f, 0.0f, 0.0f);
            StopCoroutine("BurnCountdown");
            StopCoroutine("SpreadFire");
            break;

        default:
            break;
        }
    }
예제 #8
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
            case 1:
            {
                m_Level = (SecureLevel)reader.ReadInt();
                goto case 0;
            }

            case 0:
            {
                if (version < 1)
                {
                    m_Level = SecureLevel.CoOwners;
                }

                m_PlantStatus = (PlantStatus)reader.ReadInt();
                m_PlantType   = (PlantType)reader.ReadInt();
                m_PlantHue    = (PlantHue)reader.ReadInt();
                m_ShowType    = reader.ReadBool();

                if (m_PlantStatus < PlantStatus.DecorativePlant)
                {
                    m_PlantSystem = new PlantSystem(this, reader);
                }

                break;
            }
            }
        }
예제 #9
0
    IEnumerator BurnCountdown()
    {
        yield return(new WaitForSeconds(UnityEngine.Random.Range(3, burnDuration)));

        plantStatus = PlantStatus.Burnt;
        SetPlantStatus(PlantStatus.Burnt);
    }
예제 #10
0
 public void SetFire()
 {
     if (plantStatus != PlantStatus.Burnt)
     {
         plantStatus = PlantStatus.Burning;
         SwitchColor();
     }
 }
예제 #11
0
 private void CheckIfBurnt()
 {
     if (fireTimer >= timeToBurnt)
     {
         plantStatus = PlantStatus.Burnt;
         SwitchColor();
     }
 }
예제 #12
0
        public PlantItem(bool fertileDirt) : base(0x1602)
        {
            Weight = 1.0;

            m_PlantStatus = PlantStatus.BowlOfDirt;
            m_PlantSystem = new PlantSystem(this, fertileDirt);
            m_Level       = SecureLevel.CoOwners;
        }
예제 #13
0
        public void GetInstantStatus()
        {
            //PlantStatus instantPlantStatus = ArduinoManager.GetParameters();
            PlantStatus instantPlantStatus = new PlantStatus(1, 1, 1, (x++).ToString());

            PlantStatusRepository.AddStatus(instantPlantStatus);
            GlobalHost.ConnectionManager.GetHubContext <PlantStatusHub>().Clients.All.publishPost(instantPlantStatus);
        }
예제 #14
0
        public PlantItem(int itemID, bool fertileDirt) : base(itemID)
        {
            Weight = 1.0;

            m_PlantStatus = PlantStatus.BowlOfDirt;
            m_PlantSystem = new PlantSystem(this, fertileDirt);
            m_Level       = SecureLevel.Owner;

            m_Instances.Add(this);
        }
예제 #15
0
        public PlantItem(bool fertileDirt = false) : base(0x1602)
        {
            Weight = 1.0;

            m_PlantStatus = PlantStatus.BowlOfDirt;
            PlantSystem   = new PlantSystem(this, fertileDirt);
            Level         = SecureLevel.Owner;

            Plants.Add(this);
        }
예제 #16
0
        public PlantItem( bool fertileDirt )
            : base(0x1602)
        {
            Weight = 1.0;

            m_PlantStatus = PlantStatus.BowlOfDirt;
            m_PlantSystem = new PlantSystem( this, fertileDirt );
            m_Level = SecureLevel.CoOwners;

            m_Instances.Add( this );
        }
예제 #17
0
        public PlantItem(bool fertileDirt)
            : base(0x1602)
        {
            this.Weight = 1.0;

            this.m_PlantStatus = PlantStatus.BowlOfDirt;
            this.m_PlantSystem = new PlantSystem(this, fertileDirt);
            this.m_Level       = SecureLevel.Owner;

            m_Instances.Add(this);
        }
 private void FoodController_CropGrown(PlantStatus crop)
 {
     if (compVillagerMovement.cropTarget != null)
     {
         // If the new crop is closer than the current crop target, target the new crop.
         if (Vector3.Distance(transform.position, crop.transform.position)
             < Vector3.Distance(transform.position, compVillagerMovement.cropTarget.transform.position))
         {
             compVillagerMovement.cropTarget = crop;
         }
     }
 }
예제 #19
0
    public void Plant()
    {
        Status = PlantStatus.Planted;

        var plantIndex = plantTypes.GetRandomPlantIndex();

        plant = plantTypes.GetPlant(plantIndex);

        PlayerPrefs.SetInt(PlantPref(), gameManager.GamesPlayed + 1);
        PlayerPrefs.SetInt(PlantPref() + "-type", plantIndex);

        PlayerPrefs.Save();
    }
예제 #20
0
        static void Main()
        {
            ArduinoManager = new ArduinoManager();

            while (true)
            {
                while (DateTime.Now < startTime + spanTime)
                {
                    ;
                }
                PlantStatus CurrentPlantStatus = ArduinoManager.GetPlantStatus();
                PostAsync(CurrentPlantStatus).Wait();
                startTime = DateTime.Now;
            }
        }
예제 #21
0
    public void CreateCrop(Vector3 location)
    {
        // Instantiate the crop.
        GameObject cropInstance = Instantiate(prefabCrop, location, Quaternion.identity);
        // Pass the time controller reference to the crop.
        TimeControllable tc = cropInstance.GetComponent <TimeControllable>();

        tc.timeController = GetComponent <TimeControllable>().timeController;
        TimeScale.PassTimeScale(cropInstance, gameObject);
        // Pass the food controller reference to the crop.
        PlantStatus ps = cropInstance.GetComponent <PlantStatus>();

        ps.foodController = this;
        // Play crop planting sound.
        audioSource.PlayOneShot(soundPlant);
    }
 // Callback function for when a plant dies.
 private void FoodController_CropDied(PlantStatus victim)
 {
     // If the plant is the villager's current target...
     if (victim == compVillagerMovement.cropTarget)
     {
         // Check if there are any crops left and act accordingly.
         if (foodController.GetViableCropCount() == 0)
         {
             // No crops left. No target. Stop looking for food.
             compVillagerMovement.cropTarget        = null;
             compVillagerMovement.destinationIsFood = false;
         }
         else
         {
             SetCropTargetToClosest();
         }
     }
 }
예제 #23
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
            case 2:
            case 1:
            {
                m_Level = (SecureLevel)reader.ReadInt();
                goto case 0;
            }

            case 0:
            {
                if (version < 1)
                {
                    m_Level = SecureLevel.CoOwners;
                }

                m_PlantStatus = (PlantStatus)reader.ReadInt();
                m_PlantType   = (PlantType)reader.ReadInt();
                m_PlantHue    = (PlantHue)reader.ReadInt();
                m_ShowType    = reader.ReadBool();

                if (m_PlantStatus < PlantStatus.DecorativePlant)
                {
                    m_PlantSystem = new PlantSystem(this, reader);
                }

                if (version < 2 && PlantHueInfo.IsCrossable(m_PlantHue))
                {
                    m_PlantHue |= PlantHue.Reproduces;
                }

                break;
            }
            }

            m_Instances.Add(this);
        }
예제 #24
0
    // Get the crop that's closest to a certain position.
    public PlantStatus GetClosestViableCrop(Vector3 position)
    {
        PlantStatus closestObject   = null;
        float       closestDistance = Mathf.Infinity;

        foreach (PlantStatus crop in crops)
        {
            if (crop.GetIsGrown())
            {
                float distance = Vector3.Distance(position, crop.transform.position);
                if (distance < closestDistance)
                {
                    closestDistance = distance;
                    closestObject   = crop;
                }
            }
        }
        return(closestObject);
    }
예제 #25
0
        static async Task PostAsync(PlantStatus plantStatus)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:56284");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                //Http post
                HttpResponseMessage response = await client.PostAsJsonAsync("api/PlantStatuses/AddNewStatus", plantStatus);

                if (response.IsSuccessStatusCode)
                {
                    System.Console.WriteLine("Status Posted succesfully!");
                    PrintPost(plantStatus);
                }
                else
                {
                    System.Console.WriteLine("Attept unsuccesfull!");
                }
            }
        }
예제 #26
0
        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );

            int version = reader.ReadInt();

            switch ( version )
            {
                case 2:
                case 1:
                    {
                        m_Level = (SecureLevel) reader.ReadInt();
                        goto case 0;
                    }
                case 0:
                    {
                        if ( version < 1 )
                            m_Level = SecureLevel.CoOwners;

                        m_PlantStatus = (PlantStatus) reader.ReadInt();
                        m_PlantType = (PlantType) reader.ReadInt();
                        m_PlantHue = (PlantHue) reader.ReadInt();
                        m_ShowType = reader.ReadBool();

                        if ( m_PlantStatus < PlantStatus.DecorativePlant )
                            m_PlantSystem = new PlantSystem( this, reader );

                        if ( version < 2 && PlantHueInfo.IsCrossable( m_PlantHue ) )
                            m_PlantHue |= PlantHue.Reproduces;

                        break;
                    }
            }

            m_Instances.Add( this );
        }
예제 #27
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch ( version )
            {
                case 1:
                    {
                        this.m_Level = (SecureLevel)reader.ReadInt();
                        goto case 0;
                    }
                case 0:
                    {
                        if (version < 1)
                            this.m_Level = SecureLevel.CoOwners;

                        this.m_PlantStatus = (PlantStatus)reader.ReadInt();
                        this.m_PlantType = (PlantType)reader.ReadInt();
                        this.m_PlantHue = (PlantHue)reader.ReadInt();
                        this.m_ShowType = reader.ReadBool();

                        if (this.m_PlantStatus < PlantStatus.DecorativePlant)
                            this.m_PlantSystem = new PlantSystem(this, reader);

                        break;
                    }
            }

            m_Instances.Add(this);
        }
예제 #28
0
 public void AddCrop(PlantStatus crop)
 {
     crop.Died  += PlantStatus_Died;
     crop.Grown += PlantStatus_Grown;
     crops.Add(crop);
 }
예제 #29
0
 public void RemoveCrop(PlantStatus crop)
 {
     CropUnsubscribe(crop);
     crops.Remove(crop);
 }
예제 #30
0
 // Use this for initialization
 void Start()
 {
     GeneratePlant();
     plantStatus = PlantStatus.Healthy;
 }
예제 #31
0
 private void CropUnsubscribe(PlantStatus crop)
 {
     crop.Died  -= PlantStatus_Died;
     crop.Grown -= PlantStatus_Grown;
 }
예제 #32
0
 public void AddNewStatus(PlantStatus newStatus)
 {
     PlantStatusRepository.AddStatus(newStatus);
     GlobalHost.ConnectionManager.GetHubContext <PlantStatusHub>().Clients.All.publishPost(newStatus);
 }
예제 #33
0
        private void DrawPlant()
        {
            PlantStatus status = m_Plant.PlantStatus;

            if (status < PlantStatus.FullGrownPlant)
            {
                AddImage(110, 85, 0x589);

                AddItem(122, 94, 0x914);
                AddItem(135, 94, 0x914);
                AddItem(120, 112, 0x914);
                AddItem(135, 112, 0x914);

                if (status >= PlantStatus.Stage2)
                {
                    AddItem(127, 112, 0xC62);
                }
                if (status == PlantStatus.Stage3 || status == PlantStatus.Stage4)
                {
                    AddItem(129, 85, 0xC7E);
                }
                if (status >= PlantStatus.Stage4)
                {
                    AddItem(121, 117, 0xC62);
                    AddItem(133, 117, 0xC62);
                }
                if (status >= PlantStatus.Stage5)
                {
                    AddItem(110, 100, 0xC62);
                    AddItem(140, 100, 0xC62);
                    AddItem(110, 130, 0xC62);
                    AddItem(140, 130, 0xC62);
                }
                if (status >= PlantStatus.Stage6)
                {
                    AddItem(105, 115, 0xC62);
                    AddItem(145, 115, 0xC62);
                    AddItem(125, 90, 0xC62);
                    AddItem(125, 135, 0xC62);
                }
            }
            else
            {
                PlantTypeInfo typeInfo = PlantTypeInfo.GetInfo(m_Plant.PlantType);
                PlantHueInfo  hueInfo  = PlantHueInfo.GetInfo(m_Plant.PlantHue);

                // The large images for these trees trigger a client crash, so use a smaller, generic tree.
                if (m_Plant.PlantType == PlantType.CypressTwisted || m_Plant.PlantType == PlantType.CypressStraight)
                {
                    AddItem(130 + typeInfo.OffsetX, 96 + typeInfo.OffsetY, 0x0CCA, hueInfo.Hue);
                }
                else
                {
                    AddItem(130 + typeInfo.OffsetX, 96 + typeInfo.OffsetY, typeInfo.ItemID, hueInfo.Hue);
                }
            }

            if (status != PlantStatus.BowlOfDirt)
            {
                int message = m_Plant.PlantSystem.GetLocalizedHealth();

                switch (m_Plant.PlantSystem.Health)
                {
                case PlantHealth.Dying:
                {
                    AddItem(92, 167, 0x1B9D);
                    AddItem(161, 167, 0x1B9D);

                    AddHtmlLocalized(136, 167, 42, 20, message, 0x00FC00, false, false);

                    break;
                }

                case PlantHealth.Wilted:
                {
                    AddItem(91, 164, 0x18E6);
                    AddItem(161, 164, 0x18E6);

                    AddHtmlLocalized(132, 167, 42, 20, message, 0x00C207, false, false);

                    break;
                }

                case PlantHealth.Healthy:
                {
                    AddItem(96, 168, 0xC61);
                    AddItem(162, 168, 0xC61);

                    AddHtmlLocalized(129, 167, 42, 20, message, 0x008200, false, false);

                    break;
                }

                case PlantHealth.Vibrant:
                {
                    AddItem(93, 162, 0x1A99);
                    AddItem(162, 162, 0x1A99);

                    AddHtmlLocalized(129, 167, 42, 20, message, 0x0083E0, false, false);

                    break;
                }
                }
            }
        }
예제 #34
0
		public PlantItem( int itemID, bool fertileDirt ) : base( itemID )
		{
			Weight = 1.0;

			m_PlantStatus = PlantStatus.BowlOfDirt;
			m_PlantSystem = new PlantSystem( this, fertileDirt );
			m_Level = SecureLevel.Owner;

			m_Instances.Add( this );
		}