| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using DCL.Helpers; |
| | 4 | |
|
| | 5 | | public static class QuestsLiterals |
| | 6 | | { |
| | 7 | | public static class Status |
| | 8 | | { |
| | 9 | | public const string BLOCKED = "blocked"; |
| | 10 | | public const string NOT_STARTED = "not_started"; |
| | 11 | | public const string ON_GOING = "on_going"; |
| | 12 | | public const string COMPLETED = "completed"; |
| | 13 | | public const string FAILED = "failed"; |
| | 14 | | } |
| | 15 | |
|
| | 16 | | public static class RewardStatus |
| | 17 | | { |
| | 18 | | public const string NOT_GIVEN = "not_given"; |
| | 19 | | public const string OK = "ok"; |
| | 20 | | public const string ALREADY_GIVEN = "already_given"; |
| | 21 | | public const string TASK_ALREADY_COMPLETED = "task_already_completed"; |
| | 22 | | public const string FAILED = "failed"; |
| | 23 | | } |
| | 24 | |
|
| | 25 | | public static class Visibility |
| | 26 | | { |
| | 27 | | public const string VISIBLE = "visible"; |
| | 28 | | public const string VISIBLE_IF_CAN_START = "visible_if_can_start"; |
| | 29 | | public const string SECRET = "secret"; |
| | 30 | | } |
| | 31 | | } |
| | 32 | |
|
| | 33 | | [System.Serializable] |
| | 34 | | public class QuestModel : BaseModel |
| | 35 | | { |
| | 36 | | public string id; |
| | 37 | | public string name; |
| | 38 | | public string description; |
| | 39 | | public string thumbnail_entry; |
| | 40 | | public string status; |
| | 41 | | public string visibility; |
| | 42 | | public string thumbnail_banner; |
| | 43 | | public QuestSection[] sections; |
| 99 | 44 | | public DateTime assignmentTime = DateTime.Now; //TODO remove this once kernel send the data properly |
| 99 | 45 | | public DateTime completionTime = DateTime.Now; //TODO remove this once kernel send the data properly |
| | 46 | | public QuestReward[] rewards; |
| | 47 | |
|
| | 48 | | [NonSerialized] |
| | 49 | | public float oldProgress = 0; |
| | 50 | |
|
| | 51 | | public bool TryGetSection(string sectionId, out QuestSection section) |
| | 52 | | { |
| 10 | 53 | | section = sections.FirstOrDefault(x => x.id == sectionId); |
| 5 | 54 | | return section != null; |
| | 55 | | } |
| | 56 | |
|
| | 57 | | public bool TryGetReward(string rewardId, out QuestReward reward) |
| | 58 | | { |
| 12 | 59 | | reward = rewards?.FirstOrDefault(x => x.id == rewardId); |
| 7 | 60 | | return reward != null; |
| | 61 | | } |
| | 62 | |
|
| 11 | 63 | | public bool canBePinned => !isCompleted && status != QuestsLiterals.Status.BLOCKED; |
| 99 | 64 | | public bool isCompleted => status == QuestsLiterals.Status.COMPLETED; |
| 51 | 65 | | public bool hasAvailableTasks => sections.Any(x => x.tasks.Any(y => y.status != QuestsLiterals.Status.BLOCKED)); |
| 15 | 66 | | public bool justProgressed => sections.Any(x => x.tasks.Any(y => y.status != QuestsLiterals.Status.BLOCKED && y.just |
| 125 | 67 | | public float progress => sections.Average(x => x.progress); |
| | 68 | |
|
| 4 | 69 | | public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<QuestModel>(json); } |
| | 70 | | } |