MOGiftlist.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //
  2. // MOGiftlist.m
  3. //
  4. // Created by SuperCabbage on 2023/11/24
  5. // Copyright (c) 2023 __MyCompanyName__. All rights reserved.
  6. //
  7. #import "MOGiftlist.h"
  8. #import "MOGiftInfo.h"
  9. #import "MOEffect.h"
  10. NSString *const kMOGiftlistGiftInfo = @"gift";
  11. NSString *const kMOGiftlistLock = @"lock";
  12. NSString *const kMOGiftlistBasicExp = @"basicExp";
  13. NSString *const kMOGiftlistAdditionExp = @"additionExp";
  14. NSString *const kMOGiftlistAmount= @"amount";
  15. NSString *const kMOGiftlistStore= @"store";
  16. NSString *const kMOGiftlistId= @"id";
  17. NSString *const kMOGiftlistNewUnlock = @"newUnlock";
  18. NSString *const kMOGiftlistNewGet = @"newGet";
  19. NSString *const kMOGiftlistExpireTime = @"expireTime";
  20. NSString *const kMOGiftlistNameingAvatar = @"nameingAvatar";
  21. @interface MOGiftlist ()
  22. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
  23. @end
  24. @implementation MOGiftlist
  25. @synthesize giftInfo = _giftInfo;
  26. @synthesize lock = _lock;
  27. @synthesize basicExp = _basicExp;
  28. @synthesize additionExp = _additionExp;
  29. @synthesize amount = _amount;
  30. @synthesize store = _store;
  31. @synthesize id = _id;
  32. @synthesize newUnlock = _newUnlock;
  33. @synthesize newGet = _newGet;
  34. @synthesize expireTime = _expireTime;
  35. @synthesize nameingAvatar = _nameingAvatar;
  36. + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
  37. return [[self alloc] initWithDictionary:dict];
  38. }
  39. - (instancetype)initWithDictionary:(NSDictionary *)dict {
  40. self = [super init];
  41. // This check serves to make sure that a non-NSDictionary object
  42. // passed into the model class doesn't break the parsing.
  43. if (self && [dict isKindOfClass:[NSDictionary class]]) {
  44. self.giftInfo = [MOGiftInfo modelObjectWithDictionary:[dict objectForKey:kMOGiftlistGiftInfo]];
  45. self.effect = [MOEffect modelObjectWithDictionary:[dict objectForKey:kMOGiftlistGiftInfo]];
  46. self.lock = [[self objectOrNilForKey:kMOGiftlistLock fromDictionary:dict] boolValue];
  47. self.basicExp = [[self objectOrNilForKey:kMOGiftlistBasicExp fromDictionary:dict] doubleValue];
  48. self.additionExp = [[self objectOrNilForKey:kMOGiftlistAdditionExp fromDictionary:dict] doubleValue];
  49. self.amount = [[self objectOrNilForKey:kMOGiftlistAmount fromDictionary:dict] doubleValue];
  50. //背包
  51. self.store = [MOEffect modelObjectWithDictionary:[dict objectForKey:kMOGiftlistStore]];
  52. self.id = [self objectOrNilForKey:kMOGiftlistId fromDictionary:dict];
  53. self.newUnlock = [[self objectOrNilForKey:kMOGiftlistNewUnlock fromDictionary:dict] boolValue];
  54. self.newGet = [[self objectOrNilForKey:kMOGiftlistNewGet fromDictionary:dict] boolValue];
  55. self.expireTime = [[self objectOrNilForKey:kMOGiftlistExpireTime fromDictionary:dict] doubleValue];
  56. self.nameingAvatar = [self objectOrNilForKey:kMOGiftlistNameingAvatar fromDictionary:dict];
  57. }
  58. return self;
  59. }
  60. - (NSDictionary *)dictionaryRepresentation {
  61. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
  62. [mutableDict setValue:[self.giftInfo dictionaryRepresentation] forKey:kMOGiftlistGiftInfo];
  63. [mutableDict setValue:[self.effect dictionaryRepresentation] forKey:kMOGiftlistGiftInfo];
  64. [mutableDict setValue:[NSNumber numberWithBool:self.lock] forKey:kMOGiftlistLock];
  65. [mutableDict setValue:[NSNumber numberWithDouble:self.basicExp] forKey:kMOGiftlistBasicExp];
  66. [mutableDict setValue:[NSNumber numberWithDouble:self.additionExp] forKey:kMOGiftlistAdditionExp];
  67. [mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kMOGiftlistAmount];
  68. [mutableDict setValue:[self.store dictionaryRepresentation] forKey:kMOGiftlistStore];
  69. [mutableDict setValue:self.id forKey:kMOGiftlistId];
  70. [mutableDict setValue:[NSNumber numberWithBool:self.newUnlock] forKey:kMOGiftlistNewUnlock];
  71. [mutableDict setValue:[NSNumber numberWithBool:self.newGet] forKey:kMOGiftlistNewGet];
  72. [mutableDict setValue:[NSNumber numberWithDouble:self.expireTime] forKey:kMOGiftlistExpireTime];
  73. [mutableDict setValue:self.nameingAvatar forKey:kMOGiftlistNameingAvatar];
  74. return [NSDictionary dictionaryWithDictionary:mutableDict];
  75. }
  76. - (NSString *)description {
  77. return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
  78. }
  79. #pragma mark - Helper Method
  80. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
  81. id object = [dict objectForKey:aKey];
  82. return [object isEqual:[NSNull null]] ? nil : object;
  83. }
  84. #pragma mark - NSCoding Methods
  85. - (id)initWithCoder:(NSCoder *)aDecoder {
  86. self = [super init];
  87. self.giftInfo = [aDecoder decodeObjectForKey:kMOGiftlistGiftInfo];
  88. self.effect = [aDecoder decodeObjectForKey:kMOGiftlistGiftInfo];
  89. self.lock = [aDecoder decodeBoolForKey:kMOGiftlistLock];
  90. self.basicExp = [aDecoder decodeDoubleForKey:kMOGiftlistBasicExp];
  91. self.additionExp = [aDecoder decodeDoubleForKey:kMOGiftlistAdditionExp];
  92. self.amount = [aDecoder decodeDoubleForKey:kMOGiftlistAmount];
  93. self.store = [aDecoder decodeObjectForKey:kMOGiftlistStore];
  94. self.id = [aDecoder decodeObjectForKey:kMOGiftlistId];
  95. self.newUnlock = [aDecoder decodeBoolForKey:kMOGiftlistNewUnlock];
  96. self.newGet = [aDecoder decodeBoolForKey:kMOGiftlistNewGet];
  97. self.expireTime = [aDecoder decodeDoubleForKey:kMOGiftlistExpireTime];
  98. self.nameingAvatar = [aDecoder decodeObjectForKey:kMOGiftlistNameingAvatar];
  99. return self;
  100. }
  101. - (void)encodeWithCoder:(NSCoder *)aCoder
  102. {
  103. [aCoder encodeObject:_giftInfo forKey:kMOGiftlistGiftInfo];
  104. [aCoder encodeObject:_effect forKey:kMOGiftlistGiftInfo];
  105. [aCoder encodeBool:_lock forKey:kMOGiftlistLock];
  106. [aCoder encodeDouble:_basicExp forKey:kMOGiftlistBasicExp];
  107. [aCoder encodeDouble:_additionExp forKey:kMOGiftlistAdditionExp];
  108. [aCoder encodeDouble:_amount forKey:kMOGiftlistAmount];
  109. [aCoder encodeObject:_store forKey:kMOGiftlistStore];
  110. [aCoder encodeObject:_id forKey:kMOGiftlistId];
  111. [aCoder encodeBool:_newUnlock forKey:kMOGiftlistNewUnlock];
  112. [aCoder encodeBool:_newGet forKey:kMOGiftlistNewGet];
  113. [aCoder encodeDouble:_expireTime forKey:kMOGiftlistExpireTime];
  114. [aCoder encodeObject:_nameingAvatar forKey:kMOGiftlistNameingAvatar];
  115. }
  116. - (id)copyWithZone:(NSZone *)zone {
  117. MOGiftlist *copy = [[MOGiftlist alloc] init];
  118. if (copy) {
  119. copy.giftInfo = [self.giftInfo copyWithZone:zone];
  120. copy.effect = [self.effect copyWithZone:zone];
  121. copy.lock = self.lock;
  122. copy.basicExp = self.basicExp;
  123. copy.additionExp = self.additionExp;
  124. copy.amount = self.amount;
  125. copy.tempNum = self.tempNum;
  126. copy.isBag = self.isBag;
  127. copy.endGiftNum = self.endGiftNum;
  128. copy.tempNum = self.tempNum;
  129. copy.store = [self.store copyWithZone:zone];
  130. copy.id = [self.id copyWithZone:zone];
  131. copy.newUnlock = self.newUnlock;
  132. copy.newGet = self.newGet;
  133. copy.expireTime = self.expireTime;
  134. copy.nameingAvatar = [self.nameingAvatar copyWithZone:zone];
  135. }
  136. return copy;
  137. }
  138. - (BOOL)isEqual:(id)object {
  139. if (self == object) return YES;
  140. if (![object isKindOfClass:[self class]]) return NO;
  141. MOGiftlist *other = (MOGiftlist *)object;
  142. return self.id == other.id
  143. && self.lock == other.lock
  144. && [self.nameingAvatar isEqualToString:other.nameingAvatar]
  145. && self.newUnlock == other.newUnlock
  146. && self.newGet == other.newGet
  147. && self.expireTime == other.expireTime
  148. && self.isBag == other.isBag
  149. && self.amount == other.amount;
  150. }
  151. @end