public void CheckEnergyRecover(bool isFirst) { WealthInfo energyInfo = GetWealth((int)WealthTypeEnum.Energy); if (energyInfo.count < energyInfo.limit) { if (ClockModel.Instance.GetClock((int)WealthTypeEnum.Energy) == null) { int energyRestoreTime; if (isFirst) { int getTime = PlayerPrefsUtil.GetInt(PlayerPrefsUtil.ENERGY_OUT_TIME); if (getTime > 0) { energyRestoreTime = getTime; } else { energyRestoreTime = ClockModel.ConvertDateTimeInt(DateTime.Now); PlayerPrefsUtil.SetInt(PlayerPrefsUtil.ENERGY_OUT_TIME, energyRestoreTime); } ClockModel.Instance.SetClock(new ClockInfo((int)WealthTypeEnum.Energy, 0, energyRestoreTime)); } else { energyRestoreTime = ClockModel.ConvertDateTimeInt(DateTime.Now); PlayerPrefsUtil.SetInt(PlayerPrefsUtil.ENERGY_OUT_TIME, energyRestoreTime); ClockModel.Instance.SetClock(new ClockInfo((int)WealthTypeEnum.Energy, 0, energyRestoreTime)); } } } }
public ClockInfo(int idP, int valueP = 0, int secondP = -1) { id = idP; value = valueP; if (secondP == -1) { second = ClockModel.ConvertDateTimeInt(System.DateTime.Now); } else { second = secondP; } }
private void OnClockEvent(List <ClockInfo> clocks) { for (int i = 0; i < clocks.Count; i++) { ClockInfo clock = clocks[i]; if (clock.id == (int)WealthTypeEnum.Energy) { WealthInfo energyInfo = GetWealth((int)WealthTypeEnum.Energy); if (energyInfo.count < energyInfo.limit) { float ENERGY_RECOVER = GameModel.Instance.GetGameConfig(1004); if (clock.value >= ENERGY_RECOVER) { int recoverCount = (int)Math.Floor(clock.value / ENERGY_RECOVER); if ((energyInfo.limit - energyInfo.count) > recoverCount) { energyInfo.count = energyInfo.count + (int)recoverCount; } else { energyInfo.count = energyInfo.limit; } PlayerModel.Instance.SaveWealths(); PlayerPrefsUtil.SetInt(PlayerPrefsUtil.ENERGY_OUT_TIME, ClockModel.ConvertDateTimeInt(System.DateTime.Now)); int leftTime = (int)(clock.value % ENERGY_RECOVER); ClockModel.Instance.SetClock(new ClockInfo((int)WealthTypeEnum.Energy, leftTime)); } } else { ClockModel.Instance.RemoveClock(clock.id); } return; } } }