// DELETE: api/CropStage/5
 public void Delete(int id)
 {
     using (CropStage db = new CropStage()) {
         db.CropDailyStages.Remove(db.CropDailyStages.FirstOrDefault(d => d.ID == id));
         db.SaveChanges();
     }
 }
        // PUT: api/CropStage/5
        public void Put(int id, [FromBody] CropStageViewModel value)
        {
            CropStage      db  = new CropStage();
            CropDailyStage cds = new CropDailyStage();

            cds.ID           = id;
            cds.DistBbsId    = value.District;
            cds.Recovry      = value.stg_rcv;
            cds.Tillering    = value.stg_tlr;
            cds.P_I          = value.stg_pni;
            cds.Booting      = value.stg_btg;
            cds.Flowering    = value.stg_flr;
            cds.SoftDough    = value.stg_sdf;
            cds.HardDough    = value.stg_hdf;
            cds.Ripening     = value.stg_rpn;
            cds.Harvesting   = value.stg_hrv;
            cds.SeasonID     = this.GetSeasonId(value.Season);
            cds.SeasonCode   = value.Season;
            cds.FiscalCode   = value.FiscalCode;
            cds.FiscalYearID = this.GetFiscalId(value.FiscalCode);
            cds.DistrictID   = this.GetDistId(value.District);

            //var crop = db.CropDailyStages.Where(x => x.ID == id).FirstOrDefault();

            db.CropDailyStages.Attach(cds);
            db.Entry(cds).State = EntityState.Modified;
            var bl = db.SaveChanges() > 0;
        }
示例#3
0
    private void OnMouseDown()
    {
        if (CropHarvestMiniGame.selectedTool != null)
        {
            if (CropHarvestMiniGame.selectedTool.toolType == MiniGameToolType.Clippers && !isTrimmed)
            {
                isTrimmed = true;
                Vector3 deadLeafPosition = transform.position;
                deadLeafPosition.y -= 1.5f;
                Instantiate(deadLeavesPrefab, deadLeafPosition, new Quaternion(), transform.parent);

                //Let mini game manager know that dead leaves are required to be thrown away in order to win.
                miniGameManager.IncrementRequiredScore();
                pruneLevel = maxPruneLevel;

                AudioManager.instance.PlaySFX(trimCropSFX[Random.Range(0, trimCropSFX.Length)]);
            }
            if (CropHarvestMiniGame.selectedTool.toolType == MiniGameToolType.WateringCan && !isWatered)
            {
                isWatered  = true;
                waterLevel = maxWaterLevel;
                AudioManager.instance.PlaySFX(waterCropSFX[Random.Range(0, waterCropSFX.Length)]);
            }
            if (CropHarvestMiniGame.selectedTool.toolType == MiniGameToolType.Fertilizer && !isFertilized)
            {
                isFertilized = true;
                AudioManager.instance.PlaySFX(fertilizeCropSFX[Random.Range(0, fertilizeCropSFX.Length)]);
            }
            if (CropHarvestMiniGame.selectedTool.toolType == MiniGameToolType.Seed && stage == CropStage.Unplanted)
            {
                stage = CropStage.Seedling;
                AudioManager.instance.PlaySFX(plantCropSFX[Random.Range(0, plantCropSFX.Length)]);
            }
        }
    }
示例#4
0
    private void NextStage()
    {
        currentStage    = nextStage;
        stageGrowthDays = 0;
        if (currentStage.HarvestAble)
        {
            HarvestAble = true;
        }
        int currentIndex = Info.Stages.IndexOf(currentStage);
        int nextIndex    = -1;

        if (currentIndex < Info.Stages.Count - 1)
        {
            if (currentStage.RepeatAble && currentIndex == currentStage.IndexToReturn && (currentHarvestTimes < currentStage.RepeatTimes || currentStage.RepeatTimes < 0))
            {
                nextIndex = currentStage.IndexToReturn;
            }
            else
            {
                nextIndex = currentIndex + 1;
            }
        }
        if (nextIndex > -1 && nextIndex < Info.Stages.Count)
        {
            nextStage = Info.Stages[nextIndex];
        }
        else
        {
            nextStage = null;
        }
    }
示例#5
0
    private bool ToNextStage()
    {
        if (currentStage.LastingDays < 1)
        {
            return(false);
        }

        stageTime -= TimeManager.Instance.ScaleDayToReal * currentStage.LastingDays;
        stageTime  = stageTime < 0 ? 0 : stageTime;
        stageDays  = Mathf.CeilToInt(stageTime / TimeManager.Instance.ScaleDayToReal);

        currentStage = nextStage;
        OnStageChanged?.Invoke(currentStage);
        if (!currentStage)
        {
            parent.RemoveCrop(this);
            return(false);
        }
        currentStageIndex = Info.Stages.IndexOf(currentStage);

        harvestTimes++;
        HandlingNextStage();

        return(true);
    }
示例#6
0
    public CropData(CropInformation info, FieldData field)
    {
        Info         = info;
        growthTime   = 0;
        growthDays   = 1;
        stageTime    = 0;
        stageDays    = 0;
        growthRate   = 1;
        harvestTimes = 0;
        dry          = false;
        pest         = false;
        parent       = field;

        currentStageIndex = 0;
        currentStage      = info.Stages[0];
        HandlingNextStage();

        GameManager.CropDatas.TryGetValue(Info, out var crops);
        if (crops != null)
        {
            entityID = Info.ID + "N" + crops.Count.ToString().PadLeft(4, '0');
            crops.Add(this);
        }
        else
        {
            entityID = Info.ID + "N0000";
            GameManager.CropDatas.Add(Info, new List <CropData>()
            {
                this
            });
        }
    }
        // POST: api/CropStage
        public void Post([FromBody] CropStageViewModel value)
        {
            CropDailyStage cds = new CropDailyStage();

            cds.DistBbsId    = value.District;
            cds.Recovry      = value.stg_rcv;
            cds.Tillering    = value.stg_tlr;
            cds.P_I          = value.stg_pni;
            cds.Booting      = value.stg_btg;
            cds.Flowering    = value.stg_flr;
            cds.SoftDough    = value.stg_sdf;
            cds.HardDough    = value.stg_hdf;
            cds.Ripening     = value.stg_rpn;
            cds.Harvesting   = value.stg_hrv;
            cds.SeasonID     = this.GetSeasonId(value.Season);
            cds.SeasonCode   = value.Season;
            cds.FiscalCode   = value.FiscalCode;
            cds.FiscalYearID = this.GetFiscalId(value.FiscalCode);
            cds.DistrictID   = this.GetDistId(value.District);
            cds.DateCreated  = DateTime.Now;
            cds.MeasureDate  = value.MeasureDate;
            using (CropStage db = new CropStage())
            {
                db.CropDailyStages.Add(cds);
                db.SaveChanges();
            }
        }
        // GET: api/CropStage/5
        public List <CropStageViewModel> Get(string distBbsId)
        {
            CropStageViewModel        result = new CropStageViewModel();
            CropDailyStage            oc     = new CropDailyStage();
            List <CropStageViewModel> data   = new List <CropStageViewModel>();

            using (CropStage db = new CropStage()) {
                oc.CropStageList = db.CropDailyStages.Where(c => c.DistBbsId == distBbsId).ToList();

                data = oc.CropStageList.AsEnumerable().Select(c => new CropStageViewModel
                {
                    Id          = c.ID,
                    Region      = this.GetAreaCode(c.DistBbsId),
                    District    = c.DistBbsId,
                    stg_rcv     = c.Recovry,
                    stg_tlr     = c.Tillering,
                    stg_pni     = c.P_I,
                    stg_btg     = c.Booting,
                    stg_flr     = c.Flowering,
                    stg_sdf     = c.SoftDough,
                    stg_hdf     = c.HardDough,
                    stg_rpn     = c.Ripening,
                    stg_hrv     = c.Harvesting,
                    Season      = c.SeasonCode,
                    FiscalCode  = c.FiscalCode,
                    DateCreated = c.DateCreated,
                    MeasureDate = c.MeasureDate
                }).ToList();
            }
            return(data);
        }
 public int GetFiscalId(string code)
 {
     using (CropStage db = new CropStage())
     {
         var data = db.FiscalYears.FirstOrDefault(a => a.FiscalCode == code);
         return(data.ID);
     }
 }
 public int GetDistId(string code)
 {
     using (CropStage db = new CropStage())
     {
         var data = db.Districts.FirstOrDefault(a => a.DistBbsId == code);
         return(data.DistrictSysID);
     }
 }
 public int GetSeasonId(string code)
 {
     using (CropStage db = new CropStage())
     {
         var data = db.Seasons.FirstOrDefault(a => a.SeasonCode == code);
         return(data.SeasonID);
     }
 }
示例#12
0
 public void OnStageChanged(CropStage stage)
 {
     if (stage != stageBef)
     {
         stageBef = stage;
         Refresh();
     }
 }
 public string GetAreaCode(string code)
 {
     using (CropStage db = new CropStage())
     {
         var area = db.Districts.FirstOrDefault(a => a.DistBbsId == code);
         return(area.AreaBbsId);
     }
 }
示例#14
0
    void AdvancedToNextStage()
    {
        switch (stage)
        {
        case CropStage.Seedling: stage = CropStage.Sprout; break;

        case CropStage.Sprout: stage = CropStage.Midling; break;

        case CropStage.Midling: stage = CropStage.Harvestable; break;
        }
    }
    public GameObject GetCropVisual(CropType _type, CropStage _stage)
    {
        switch (_type)
        {
        default:
        case CropType.Potato: return(PotatoVisuals[(int)_stage]);

        case CropType.Vegetable: return(VegetableVisuals[(int)_stage]);

        case CropType.Wheat: return(WheatVisuals[(int)_stage]);
        }
    }
示例#16
0
 private void OnStageChange(CropStage stage)
 {
     if (!stage)
     {
         return;
     }
     if (stage.HarvestAble)
     {
         resourceInfo = Data.currentStage.GatherInfo;
     }
     else
     {
         resourceInfo = null;
     }
 }
示例#17
0
    public void HarvestCrop(NPC _npc, bool _ownUse = false)
    {
        stage = CropStage.Seed;
        UpdateCropVisuals();

        if (_ownUse)
        {
            _npc.AssignedHouse.ResetHunger();
        }

        else
        {
            GameManager.Instance.AdjustMoneyAndContentmentLevels(2, 0, 2);
        }
    }
示例#18
0
    public void ShowDescription(SeedItem seed)
    {
        if (!seed)
        {
            HideDescription();
            return;
        }

        descriptionWindow.alpha = 1;
        nameText.text           = seed.Crop.Name;
        int amount = BackpackManager.Instance.GetAmount(seed);

        icon.SetItem(seed, amount > 0 ? amount.ToString() : null);
        StringBuilder str = new StringBuilder("占用田地空间:");

        str.Append(seed.Crop.Size);
        str.Append("\n");
        str.Append(CropInformation.CropSeasonString(seed.Crop.PlantSeason));
        str.Append("\n");
        str.Append("生长阶段:");
        str.Append("\n");
        for (int i = 0; i < seed.Crop.Stages.Count; i++)
        {
            CropStage stage = seed.Crop.Stages[i];
            str.Append(ZetanUtility.ColorText(CropStage.CropStageName(stage.Stage), Color.yellow));
            str.Append("持续");
            str.Append(ZetanUtility.ColorText(stage.LastingDays.ToString(), Color.green));
            str.Append("天");
            if (stage.HarvestAble)
            {
                if (stage.RepeatTimes > 0)
                {
                    str.Append(",可收割");
                    str.Append(ZetanUtility.ColorText(stage.RepeatTimes.ToString(), Color.green));
                    str.Append("次");
                }
                else if (stage.RepeatTimes < 0)
                {
                    str.Append(",可无限收割");
                }
            }
            if (i != seed.Crop.Stages.Count - 1)
            {
                str.Append("\n");
            }
        }
        description.text = str.ToString();
    }
        public CropStageViewModelPub Get(int record_from, int record_to)
        {
            CropStageViewModelPub returnData = new CropStageViewModelPub();

            if (record_to - record_from > 100)
            {
                return(returnData);
            }
            CropStage          db     = new CropStage();
            CropStageViewModel result = new CropStageViewModel();
            CropDailyStage     oc     = new CropDailyStage();

            List <CropStageViewModel> data = new List <CropStageViewModel>();
            var croplist = db.CropDailyStages.OrderBy(x => x.ID).Skip(record_from).Take(record_to).ToList();

            returnData.TotalRecords = db.CropDailyStages.Count();

            data = croplist.AsEnumerable().Select(c => new CropStageViewModel
            {
                Id          = c.ID,
                Region      = this.GetAreaCode(c.DistBbsId),
                District    = c.DistBbsId,
                stg_rcv     = c.Recovry,
                stg_tlr     = c.Tillering,
                stg_pni     = c.P_I,
                stg_btg     = c.Booting,
                stg_flr     = c.Flowering,
                stg_sdf     = c.SoftDough,
                stg_hdf     = c.HardDough,
                stg_rpn     = c.Ripening,
                stg_hrv     = c.Harvesting,
                Season      = c.SeasonCode,
                FiscalCode  = c.FiscalCode,
                DateCreated = c.DateCreated,
                MeasureDate = c.MeasureDate
            }).ToList();
            returnData.CropStageViewModels = data;
            returnData.NextUrl             = "http://localhost:53904/api/cropstage?record_from=" + record_to.ToString() + "&record_to=" + (record_to + 100).ToString();
            return(returnData);
        }
示例#20
0
    private void HandlingNextStage()
    {
        int nextIndex;

        if (currentStage.RepeatAble && (harvestTimes < currentStage.RepeatTimes || currentStage.RepeatTimes < 0))
        {
            nextIndex = currentStage.IndexToReturn;
        }
        else
        {
            nextIndex    = currentStageIndex + 1;
            harvestTimes = 0;
        }
        if (nextIndex > 0 && nextIndex < Info.Stages.Count)
        {
            nextStage = Info.Stages[nextIndex];
        }
        else
        {
            nextStage = null;
        }
    }
示例#21
0
 private void Clear()
 {
     GameManager.Crops.TryGetValue(Info, out var crops);
     if (crops != null)
     {
         crops.Remove(this);
         if (crops.Count < 1)
         {
             GameManager.Crops.Remove(Info);
         }
     }
     HarvestAble = false;
     RuntimeID   = string.Empty;
     Info        = null;
     Parent.Crops.Remove(this);
     Parent              = null;
     currentStage        = null;
     nextStage           = null;
     currentHarvestTimes = -1;
     totalGrowthDays     = -1;
     TimeManager.Instance.OnDayPassed -= UpdateDay;
 }