| | |
| | | public class FestivalRedpackModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
| | | {
|
| | | Dictionary<int, FestivalRedpack> festivalRedpacks = new Dictionary<int, FestivalRedpack>();
|
| | | Dictionary<int, List<int>> achievements = new Dictionary<int, List<int>>();
|
| | | Dictionary<int, List<FestivalRedpackAchievement>> achievements = new Dictionary<int, List<FestivalRedpackAchievement>>();
|
| | | List<int> taskRedpacks = new List<int>();
|
| | |
|
| | | bool serverInited = false;
|
| | |
| | | var configs = Config.Instance.GetAllValues<FestivalRedpackTaskConfig>();
|
| | | foreach (var config in configs)
|
| | | {
|
| | | List<int> list;
|
| | | List<FestivalRedpackAchievement> list;
|
| | | if (!achievements.TryGetValue(config.FeastDay, out list))
|
| | | {
|
| | | list = new List<int>();
|
| | | list = new List<FestivalRedpackAchievement>();
|
| | | achievements.Add(config.FeastDay, list);
|
| | | }
|
| | | list.Add(config.achievementId);
|
| | | list.Add(new FestivalRedpackAchievement()
|
| | | {
|
| | | id = config.ID,
|
| | | achievements = config.achievements,
|
| | | });
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | public bool IsContainsAchievement(List<FestivalRedpackAchievement> list, int achievementId)
|
| | | {
|
| | | foreach (var festivalRedpackAchievement in list)
|
| | | {
|
| | | if (festivalRedpackAchievement.Contains(achievementId))
|
| | | {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | public bool TryGetRedpack(int id, out FestivalRedpack redpack)
|
| | | {
|
| | | return festivalRedpacks.TryGetValue(id, out redpack);
|
| | | }
|
| | |
|
| | | public bool TryGetAchievements(out List<int> list)
|
| | | public bool TryGetAchievements(out List<FestivalRedpackAchievement> list)
|
| | | {
|
| | | return achievements.TryGetValue(festivalDay + 1, out list);
|
| | | }
|
| | |
| | | return festivalRedpacks[lhs].openTime.CompareTo(festivalRedpacks[rhs].openTime);
|
| | | }
|
| | | return 0;
|
| | | }
|
| | |
|
| | | public int AchievementSort(FestivalRedpackAchievement lhs, FestivalRedpackAchievement rhs)
|
| | | {
|
| | | Achievement lhsAchievement;
|
| | | Achievement rhsAchievement;
|
| | | if (achievementModel.TryGetAchievement(lhs.CurrentAchieve, out lhsAchievement)
|
| | | && achievementModel.TryGetAchievement(rhs.CurrentAchieve, out rhsAchievement))
|
| | | {
|
| | | if (lhsAchievement.completed.CompareTo(rhsAchievement.completed) != 0)
|
| | | {
|
| | | return lhsAchievement.completed.CompareTo(rhsAchievement.completed);
|
| | | }
|
| | | bool xReach = Achievement.IsReach(lhsAchievement.id, lhsAchievement.progress);
|
| | | bool yReach = Achievement.IsReach(rhsAchievement.id, rhsAchievement.progress);
|
| | | if (xReach.CompareTo(yReach) != 0)
|
| | | {
|
| | | return -xReach.CompareTo(yReach);
|
| | | }
|
| | | }
|
| | | return lhs.id.CompareTo(rhs.id);
|
| | | }
|
| | |
|
| | | public void OnReceivePackage(HAB25_tagMCFeastRedPackInfo package)
|
| | |
| | |
|
| | | private void AchievementCompletedEvent(int _achieve)
|
| | | {
|
| | | List<int> list;
|
| | | if (TryGetAchievements(out list) && list.Contains(_achieve))
|
| | | List<FestivalRedpackAchievement> list;
|
| | | if (TryGetAchievements(out list) && IsContainsAchievement(list, _achieve))
|
| | | {
|
| | | if (achievementRefresh != null)
|
| | | {
|
| | |
| | |
|
| | | private void AchievementProgressUpdateEvent(int _achieve)
|
| | | {
|
| | | List<int> list;
|
| | | if (TryGetAchievements(out list) && list.Contains(_achieve))
|
| | | List<FestivalRedpackAchievement> list;
|
| | | if (TryGetAchievements(out list) && IsContainsAchievement(list, _achieve))
|
| | | {
|
| | | if (achievementRefresh != null)
|
| | | {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | List<int> list;
|
| | | List<FestivalRedpackAchievement> list;
|
| | | if (TryGetAchievements(out list))
|
| | | {
|
| | | foreach (var achievementId in list)
|
| | | foreach (var festivalRedpackAchievement in list)
|
| | | {
|
| | | Achievement achievement;
|
| | | if (achievementModel.TryGetAchievement(achievementId, out achievement))
|
| | | if (achievementModel.TryGetAchievement(festivalRedpackAchievement.CurrentAchieve, out achievement))
|
| | | {
|
| | | if (Achievement.IsReach(achievementId, achievement.progress) && !achievement.completed)
|
| | | if (Achievement.IsReach(festivalRedpackAchievement.CurrentAchieve, achievement.progress) && !achievement.completed)
|
| | | {
|
| | | existFinishTask = true;
|
| | | break;
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public class FestivalRedpackAchievement
|
| | | {
|
| | | public int id;
|
| | | public int[] achievements;
|
| | |
|
| | | public AchievementModel model { get { return ModelCenter.Instance.GetModel<AchievementModel>(); } }
|
| | |
|
| | | public int CurrentAchieve
|
| | | {
|
| | | get
|
| | | {
|
| | | for (int i = 0; i < achievements.Length; i++)
|
| | | {
|
| | | Achievement achievement;
|
| | | if (model.TryGetAchievement(achievements[i], out achievement))
|
| | | {
|
| | | if (!achievement.completed)
|
| | | {
|
| | | return achievements[i];
|
| | | }
|
| | | }
|
| | | }
|
| | | return achievements[achievements.Length - 1];
|
| | | }
|
| | | }
|
| | |
|
| | | public bool Contains(int _achieve)
|
| | | {
|
| | | for (int i = 0; i < achievements.Length; i++)
|
| | | {
|
| | | if (achievements[i] == _achieve)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | public struct FestivalRedpack
|
| | | {
|
| | | public int id;
|