/// <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 GetCounter(long char_idx, eCounterType type) { PlayerCounter player_counter; if (m_counter_members.TryGetValue(char_idx, out player_counter)) { return(player_counter.GetAndModifyCounter(type)); } return(0); }
/// 外部修改次数 /// </summary> /// <param name="char_idx"></param> /// <param name="type"></param> /// <param name="modify_value">消耗值</param> /// <returns>true表示可以扣除次数</returns> public bool ConsumeCounter(long char_idx, eCounterType type, ushort modify_value) { PlayerCounter player_counter; if (m_counter_members.TryGetValue(char_idx, out player_counter)) { player_counter.ConsumeCounter(type, modify_value); return(true); } return(false); }
/// <summary> /// 获取类型最大次数,主要是考虑属性加成或等级加成 /// </summary> public ushort GetMaxCounterByType(eCounterType type) { StdCounterInfo info = CounterConfig.Instance.GetInfo((int)type); if (info == null) { return(0); } //TODO:属性加成 return(info.value); }
/// <summary> /// 减少次数 /// </summary> public bool ConsumeCounter(eCounterType type, ushort modify_value) { this.GetAndModifyCounter(type); CounterInfo counter_info; if (m_counters.TryGetValue(type, out counter_info)) { ushort max_count = GetMaxCounterByType(type); if (modify_value > max_count || max_count > counter_info.count) { return(false); } if (counter_info.count == max_count) { counter_info.cd_time = Time.second_time;//如果是满次数的情况下扣次数,则从当前时间开始记cd } counter_info.count -= modify_value; m_counters[type] = counter_info; return(true); } return(false); }
public override void Read(ByteArray by) { base.Read(by); type = (eCounterType)by.ReadByte(); value = by.ReadUShort(); }
public long cd_time;//相对2009开始倒计时间 public void Read(ByteArray by) { type = (eCounterType)by.ReadUShort(); count = by.ReadUShort(); cd_time = by.ReadLong(); }
/// <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); }