list sort()委托排序(根据一个值,判断多个条件)

排序规则,按以下规则依次判断

  1. 可领奖>未开始>进行中
  2. 高品质>低品质
public List  TreasureTaskDatasList
{
	get
	{
		List list = new List();
		foreach (var v in _datas)
		{
			list.Add(v.Value);
		}
		list.Sort(SortByTaskStatus);
		return list;
	}
}

int SortByTaskStatus(Legend2TreasureTaskData data1, Legend2TreasureTaskData data2)
{
	Legend2TreasureTaskData info1 = data1;
	Legend2TreasureTaskData info2 = data2;
	ConfigHeroTreasureQualityInfo qualityInfo1 = ConfigManager.inst.DB_HeroTreasureQuality.Get(data1.t_id);
	ConfigHeroTreasureQualityInfo qualityInfo2 = ConfigManager.inst.DB_HeroTreasureQuality.Get(data2.t_id);
	
	if (info1 != null && info2 != null)
	{
		if (info2.finished.CompareTo(info1.finished) != 0)
		{
			return info2.finished.CompareTo(info1.finished);
		}
		else if (qualityInfo1._Quality.CompareTo(qualityInfo2._Quality) != 0)
		{
			return qualityInfo2._Quality.CompareTo(qualityInfo1._Quality);
		}
	}
	return 1;
}

//3:可领奖、2:未开始、1:进行中
public long finished
{
	get
	{
		//通过status判断任务是否被领取,通过finish_time和mtime判断任务是否已经完成;
		if (status == 1)
		{
			long realTime = finish_time - mtime;
			long leftTime = finish_time - NetServerTime.inst.ServerTimestamp;
			float progress = leftTime / (float)realTime;
			if (progress <= 0)
			{
				return 3;
			}
			else
			{
				return 1;
			}
		}
		return 2;
	}
}

 

 

 

你可能感兴趣的:(C#)