/// <summary> /// 获取需要的cd /// </summary> public int GetCDTimeByType(eCounterType type) { StdCounterInfo info = CounterConfig.Instance.GetInfo((int)type); if (info == null) { return(0); } int cd_time = 0; switch ((eCounterCDType)info.cd_type) { case eCounterCDType.Without: break; case eCounterCDType.Fixed: cd_time = info.cd_value[0]; break; case eCounterCDType.Increase: //TODO break; case eCounterCDType.Config: //TODO break; } return(cd_time); }
/// <summary> /// 获取类型最大次数,主要是考虑属性加成或等级加成 /// </summary> public ushort GetMaxCounterByType(eCounterType type) { StdCounterInfo info = CounterConfig.Instance.GetInfo((int)type); if (info == null) { return(0); } //TODO:属性加成 return(info.value); }
private void OnLoad(CSVDocument doc) { int totalCount = (int)doc.TableRows(); for (int i = 0; i < totalCount; ++i) { StdCounterInfo info = new StdCounterInfo(); info.idx = doc.GetValue(i, "idx").ToUInt16(); info.value = doc.GetValue(i, "value").ToUInt16(); info.reset = doc.GetValue(i, "reset").ToBool(); info.cd_type = doc.GetValue(i, "cd_type").ToUInt16(); string cd = doc.GetValue(i, "cd_value").ToString(); switch (info.cd_type) { case 2: info.cd_value = new Dictionary <int, int>(); info.cd_value.Add(0, int.Parse(cd)); break; case 3: info.cd_value = new Dictionary <int, int>(); string[] arr_cds = cd.Split(','); if (arr_cds.Length > 0) { for (int j = 0; j < arr_cds.Length; ++j) { string[] arr_cd = arr_cds[j].Split('|'); info.cd_value.Add(int.Parse(arr_cd[0]), int.Parse(arr_cd[1])); } } break; } if (info.idx > 0) { m_infos.Add(info.idx, info); } } }
/// <summary> /// 获取并修改次数 /// </summary> /// <param name="type"></param> /// <returns></returns> public ushort GetAndModifyCounter(eCounterType type) { if (!m_counters.ContainsKey(type)) { return(0); } long count = 0;//之所以定义long,防止下面计时溢出 ushort max_count = GetMaxCounterByType(type); CounterInfo counter_info; if (m_counters.TryGetValue(type, out counter_info)) { StdCounterInfo info = CounterConfig.Instance.GetInfo((int)type); if (info == null) { return(0); } switch ((eCounterCDType)info.cd_type) { case eCounterCDType.Without: count = counter_info.count; break; case eCounterCDType.Fixed: count = counter_info.count; if (count < max_count) { //上次cd到现在经过的秒数 long offset_seconds = Time.second_time - counter_info.cd_time; int cd_time = this.GetCDTimeByType(type); long multiple_count = (long)(offset_seconds / (long)cd_time); count += multiple_count; if (count >= max_count) { counter_info.cd_time = Time.second_time; } else { counter_info.cd_time += multiple_count * cd_time; //修正开始cd时间 } } else { counter_info.cd_time = Time.second_time; } break; case eCounterCDType.Increase: break; case eCounterCDType.Config: break; } } //修正到有效次数 if (count > max_count) { count = max_count; } counter_info.count = (ushort)count; //修改数据 m_counters[type] = counter_info; return((ushort)count); }