| | 1 | | using System; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | [Serializable] |
| | 8 | | public class AvatarModel : BaseModel |
| | 9 | | { |
| | 10 | | [Serializable] |
| | 11 | | public class AvatarEmoteEntry |
| | 12 | | { |
| | 13 | | public int slot; |
| | 14 | | public string urn; |
| | 15 | | } |
| | 16 | |
|
| | 17 | | public string id; |
| | 18 | | public string name; |
| | 19 | | public string bodyShape; |
| | 20 | | public Color skinColor; |
| | 21 | | public Color hairColor; |
| | 22 | | public Color eyeColor; |
| 2232 | 23 | | public List<string> wearables = new List<string>(); |
| | 24 | |
|
| 2232 | 25 | | public List<AvatarEmoteEntry> emotes = new List<AvatarEmoteEntry>(); |
| | 26 | |
|
| | 27 | | public string expressionTriggerId = null; |
| 2232 | 28 | | public long expressionTriggerTimestamp = -1; |
| | 29 | | public string stickerTriggerId = null; |
| 2232 | 30 | | public long stickerTriggerTimestamp = -1; |
| | 31 | | public bool talking = false; |
| | 32 | |
|
| | 33 | | public bool HaveSameWearablesAndColors(AvatarModel other) |
| | 34 | | { |
| 5 | 35 | | if (other == null) |
| 0 | 36 | | return false; |
| | 37 | |
|
| | 38 | | //wearables are the same |
| 5 | 39 | | if (!(wearables.Count == other.wearables.Count |
| | 40 | | && wearables.All(other.wearables.Contains) |
| | 41 | | && other.wearables.All(wearables.Contains))) |
| 4 | 42 | | return false; |
| | 43 | |
|
| | 44 | | //emotes are the same |
| 1 | 45 | | if (emotes == null && other.emotes != null) |
| 0 | 46 | | return false; |
| 1 | 47 | | if (emotes != null && other.emotes == null) |
| 0 | 48 | | return false; |
| 1 | 49 | | if (emotes != null && other.emotes != null) |
| | 50 | | { |
| 1 | 51 | | if (emotes.Count != other.emotes.Count) |
| 0 | 52 | | return false; |
| | 53 | |
|
| 2 | 54 | | for (var i = 0; i < emotes.Count; i++) |
| | 55 | | { |
| 0 | 56 | | AvatarEmoteEntry emote = emotes[i]; |
| 0 | 57 | | if (other.emotes.FirstOrDefault(x => x.urn == emote.urn) == null) |
| 0 | 58 | | return false; |
| | 59 | | } |
| | 60 | | } |
| | 61 | |
|
| 1 | 62 | | return bodyShape == other.bodyShape && |
| | 63 | | skinColor == other.skinColor && |
| | 64 | | hairColor == other.hairColor && |
| | 65 | | eyeColor == other.eyeColor; |
| | 66 | | } |
| | 67 | |
|
| | 68 | | public bool HaveSameExpressions(AvatarModel other) |
| | 69 | | { |
| 0 | 70 | | return expressionTriggerId == other.expressionTriggerId && |
| | 71 | | expressionTriggerTimestamp == other.expressionTriggerTimestamp && |
| | 72 | | stickerTriggerTimestamp == other.stickerTriggerTimestamp; |
| | 73 | | } |
| | 74 | |
|
| | 75 | | public bool Equals(AvatarModel other) |
| | 76 | | { |
| 0 | 77 | | bool wearablesAreEqual = wearables.All(other.wearables.Contains) |
| | 78 | | && other.wearables.All(wearables.Contains) |
| | 79 | | && wearables.Count == other.wearables.Count; |
| | 80 | |
|
| 0 | 81 | | return id == other.id && |
| | 82 | | name == other.name && |
| | 83 | | bodyShape == other.bodyShape && |
| | 84 | | skinColor == other.skinColor && |
| | 85 | | hairColor == other.hairColor && |
| | 86 | | eyeColor == other.eyeColor && |
| | 87 | | expressionTriggerId == other.expressionTriggerId && |
| | 88 | | expressionTriggerTimestamp == other.expressionTriggerTimestamp && |
| | 89 | | stickerTriggerTimestamp == other.stickerTriggerTimestamp && |
| | 90 | | wearablesAreEqual; |
| | 91 | | } |
| | 92 | |
|
| | 93 | | public void CopyFrom(AvatarModel other) |
| | 94 | | { |
| 560 | 95 | | if (other == null) |
| 476 | 96 | | return; |
| | 97 | |
|
| 84 | 98 | | id = other.id; |
| 84 | 99 | | name = other.name; |
| 84 | 100 | | bodyShape = other.bodyShape; |
| 84 | 101 | | skinColor = other.skinColor; |
| 84 | 102 | | hairColor = other.hairColor; |
| 84 | 103 | | eyeColor = other.eyeColor; |
| 84 | 104 | | expressionTriggerId = other.expressionTriggerId; |
| 84 | 105 | | expressionTriggerTimestamp = other.expressionTriggerTimestamp; |
| 84 | 106 | | stickerTriggerId = other.stickerTriggerId; |
| 84 | 107 | | stickerTriggerTimestamp = other.stickerTriggerTimestamp; |
| 84 | 108 | | wearables = new List<string>(other.wearables); |
| 84 | 109 | | emotes = other.emotes.Select(x => new AvatarEmoteEntry() { slot = x.slot, urn = x.urn }).ToList(); |
| | 110 | |
|
| | 111 | |
|
| 84 | 112 | | } |
| | 113 | |
|
| 5 | 114 | | public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<AvatarModel>(json); } |
| | 115 | | } |