コード例 #1
0
ファイル: Garden.cs プロジェクト: kddean/Hocus-Potions
    //Handles harvesting plots and adding ingredients to inventory
    void Harvest(GardenPlot plot)
    {
        PlotData data = plots[plot.gameObject.name];

        Inventory.Add(rl.ingredients[data.type], 1, true);
        SpriteRenderer[] sr = plot.gameObject.GetComponentsInChildren <SpriteRenderer>();
        for (int i = 1; i < 4; i++)
        {
            sr[i].sprite = null;
        }
        plots.Remove(plot.gameObject.name);
    }
コード例 #2
0
ファイル: Garden.cs プロジェクト: kddean/Hocus-Potions
    public void SpellCast(GardenPlot plot)
    {
        PlotData data;
        Mana     mana = GameObject.FindObjectOfType <Mana>();

        if (!plots.TryGetValue(plot.gameObject.name, out data))
        {
            return;
        }
        if (rl.activeSpell.SpellName.Equals("Wild Growth") && data.stage == Status.harvestable)
        {
            return;
        }

        if (rl.activeSpell.SpellName.Equals("Wild Growth"))
        {
            plot.gameObject.GetComponents <AudioSource>()[2].Play();
            data.index++;
            if (data.index == (rl.seeds[data.type].GrowthStages - 1))
            {
                data.stage = Status.harvestable;
            }

            SpriteRenderer[] renderers = GameObject.Find(plot.gameObject.name).GetComponentsInChildren <SpriteRenderer>();
            for (int i = 1; i < 4; i++)
            {
                renderers[i].sprite = Resources.LoadAll <Sprite>("Plants/" + data.type)[data.index];
            }

            plot.gameObject.GetComponentInChildren <Animator>().SetTrigger("Growth");
            plots[plot.gameObject.name] = data;
        }
        else if (rl.activeSpell.SpellName.Equals("Ignite"))
        {
            if (GameObject.FindObjectOfType <SteamAchievementManager>() != null)
            {
                sam.UnlockAchievement(sam.m_Achievements[8]);
            }
            plot.gameObject.GetComponents <AudioSource>()[1].Play();
            plot.gameObject.GetComponentInChildren <Animator>().SetTrigger("Ignite");
            SpriteRenderer[] renderers = GameObject.Find(plot.gameObject.name).GetComponentsInChildren <SpriteRenderer>();
            for (int i = 1; i < 4; i++)
            {
                renderers[i].sprite = null;
            }
            plots.Remove(plot.gameObject.name);
            Inventory.Add(rl.ingredients["ash"], 1, true);
        }

        mana.UpdateMana(rl.activeSpell.Cost);
    }
コード例 #3
0
ファイル: Garden.cs プロジェクト: kddean/Hocus-Potions
    //Handles clicking on garden plots
    public void Farm(GardenPlot plot, Seed seed, InventorySlot slot)
    {
        PlotData data;

        if (plots.TryGetValue(plot.gameObject.name, out data))
        {
            if (data.stage == Status.harvestable)
            {
                Harvest(plot);
            }
            else
            {
                return;
            }
        }
        else
        {
            if (seed == null)
            {
                GameObject inv = GameObject.FindGameObjectWithTag("inventory");
                inv.GetComponent <CanvasGroup>().alpha          = 1;
                inv.GetComponent <CanvasGroup>().interactable   = true;
                inv.GetComponent <CanvasGroup>().blocksRaycasts = true;
                return;
            }
            plot.gameObject.GetComponent <AudioSource>().Play();
            PlotData newData = new PlotData();
            //Set values for plot
            newData.stage       = Status.growing;
            newData.type        = seed.SeedType;
            newData.growthTime  = seed.GrowthTime;
            newData.currentTime = 0;
            newData.index       = 0;
            newData.plotScene   = SceneManager.GetActiveScene().name;
            //Add plot to dict
            plots.Add(plot.gameObject.name, newData);
            //Remove seed from inv
            Inventory.RemoveItem(slot);
            //Set plot sprite
            SpriteRenderer[] sr = plot.gameObject.GetComponentsInChildren <SpriteRenderer>();
            for (int i = 1; i < 4; i++)
            {
                sr[i].sprite = Resources.Load <Sprite>("Plants/" + seed.SeedType);
            }
        }
    }
コード例 #4
0
        public async Task <IActionResult> PostGardenPlot([FromBody] GardenPlotModel gardenPlotModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var gardenPlot = new GardenPlot()
            {
                Length = gardenPlotModel.Length,
                Width  = gardenPlotModel.Width
            };

            _context.GardenPlots.Add(gardenPlot);
            await _context.SaveChangesAsync();

            gardenPlotModel.GardenPlotId = gardenPlot.GardenPlotId;

            return(CreatedAtAction("GetGardenPlot", new { id = gardenPlotModel.GardenPlotId }, gardenPlotModel));
        }