AccountModel.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-09-12 12:41:49
  4. * @LastEditTime: 2021-09-12 17:22:06
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \zombiefood\assets\script\data\Account\AccountModel.ts
  8. */
  9. import { USER } from "../../constant/constant-user";
  10. import IDataModel from "../../framework/data/model/IDataModel";
  11. import setSearchResolutionsOrder = jsb.fileUtils.setSearchResolutionsOrder;
  12. import gameEventManager from "../../gameLogic/utrl/gameEventManager";
  13. import {EVENT_TYPE} from "../../gameLogic/utrl/gameEnum";
  14. const KEY_ACCOUNT = 'account';
  15. export default class AccountModel extends IDataModel {
  16. static singleInstance: AccountModel = null;
  17. static getInstance(): AccountModel {
  18. if (AccountModel.singleInstance == null) {
  19. AccountModel.singleInstance = new AccountModel();
  20. }
  21. return AccountModel.singleInstance;
  22. }
  23. constructor() {
  24. super('account');
  25. }
  26. initData() {
  27. //ToDo 第一次游戏
  28. this.saveValueByKey(USER.CUR_LEVEL, 1); //当前关卡
  29. this.saveValueByKey(USER.IS_NEW, 1);
  30. this.saveValueByKey(USER.PLAYER_DATA_LIST, []);
  31. this.saveValueByKey(USER.CUR_POWER, USER.init_powerNum);
  32. this.saveValueByKey(USER.CUR_DAY, USER.init_day);
  33. this.saveValueByKey(USER.CUR_BULLET, USER.init_bulletNum);
  34. this.saveValueByKey(USER.RELIVE, USER.reLiveNum);
  35. }
  36. set reliveNum(data) {
  37. this.saveValueByKey(USER.RELIVE, data);
  38. }
  39. get reliveNum() {
  40. let data = this.getValueByKey(USER.RELIVE);
  41. return data;
  42. }
  43. set curDay(data) {
  44. this.saveValueByKey(USER.CUR_DAY, data);
  45. }
  46. get curDay() {
  47. let data = this.getValueByKey(USER.CUR_DAY);
  48. return data;
  49. }
  50. set curBullet(data) {
  51. this.saveValueByKey(USER.CUR_BULLET, data);
  52. }
  53. get curBullet() {
  54. let data = this.getValueByKey(USER.CUR_BULLET);
  55. return data;
  56. }
  57. set curPower(data) {
  58. this.saveValueByKey(USER.CUR_POWER, data);
  59. }
  60. get curPower() {
  61. let data = this.getValueByKey(USER.CUR_POWER);
  62. return data;
  63. }
  64. set curKillZomNum(data) {
  65. this.saveValueByKey(USER.CUR_KILLZOM_NUM, data);
  66. }
  67. get curKillZomNum() {
  68. let data = this.getValueByKey(USER.CUR_KILLZOM_NUM);
  69. if (!data){
  70. return 0;
  71. }
  72. return data;
  73. }
  74. set playerDtList(data) {
  75. this.saveValueByKey(USER.PLAYER_DATA_LIST, data);
  76. }
  77. get playerDtList() {
  78. let data = this.getValueByKey(USER.PLAYER_DATA_LIST);
  79. return data;
  80. }
  81. get curLevel(): number {
  82. let level = this.getValueByKey(USER.CUR_LEVEL)
  83. return level;
  84. }
  85. set curLevel(level: number) {
  86. this.saveValueByKey(USER.CUR_LEVEL, level);
  87. }
  88. get is_new(): number {
  89. let is_new = this.getValueByKey(USER.IS_NEW)
  90. return is_new;
  91. }
  92. set is_new(num: number) {
  93. this.saveValueByKey(USER.IS_NEW, num);
  94. }
  95. get shop_time(): number {
  96. let shop_time = this.getValueByKey(USER.SHOP_TIME)
  97. return shop_time;
  98. }
  99. set shop_time(num: number) {
  100. this.saveValueByKey(USER.SHOP_TIME, num);
  101. }
  102. get airdrop_time(): number {
  103. let airdrop_time = this.getValueByKey(USER.AIRDROP_TIME)
  104. return airdrop_time;
  105. }
  106. set airdrop_time(num: number) {
  107. this.saveValueByKey(USER.AIRDROP_TIME, num);
  108. }
  109. get sign_timestamp(): number {
  110. let sign_timestamp = this.getValueByKey(USER.SIGN_TIMESTAMP)
  111. return sign_timestamp;
  112. }
  113. set sign_timestamp(num: number) {
  114. this.saveValueByKey(USER.SIGN_TIMESTAMP, num);
  115. }
  116. get sign_times(): number {
  117. let sign_times = this.getValueByKey(USER.SIGN_TIMES);
  118. if (!sign_times) {
  119. sign_times = 0;
  120. }
  121. return sign_times;
  122. }
  123. set sign_times(num: number) {
  124. this.saveValueByKey(USER.SIGN_TIMES, num);
  125. }
  126. get curWelfare(): string[] {
  127. let tag = this.getValueByKey(USER.WELFARE_TOPIC)
  128. if (!tag){
  129. tag = [];
  130. }
  131. return tag;
  132. }
  133. set curWelfare(tag: string[]) {
  134. gameEventManager.emit(EVENT_TYPE.OFF_WELFARE_TIP);
  135. this.saveValueByKey(USER.WELFARE_TOPIC, tag);
  136. }
  137. get airdrop_rewards(): string[] {
  138. let tag = this.getValueByKey(USER.AIRDROP_REWARDS)
  139. if (!tag){
  140. tag = [];
  141. }
  142. return tag;
  143. }
  144. set airdrop_rewards(tag: string[]) {
  145. this.saveValueByKey(USER.AIRDROP_REWARDS, tag);
  146. }
  147. get fixed_role_ids(): number[] {
  148. let tag = this.getValueByKey(USER.FIXED_ROLE_IDS)
  149. if (!tag){
  150. tag = [];
  151. }
  152. return tag;
  153. }
  154. set fixed_role_ids(tag: number[]) {
  155. this.saveValueByKey(USER.FIXED_ROLE_IDS, tag);
  156. }
  157. get fixed_wp_ids(): number[] {
  158. let tag = this.getValueByKey(USER.FIXED_WP_IDS)
  159. if (!tag){
  160. tag = [];
  161. }
  162. return tag;
  163. }
  164. set fixed_wp_ids(tag: number[]) {
  165. this.saveValueByKey(USER.FIXED_WP_IDS, tag);
  166. }
  167. get is_airdrop():boolean {
  168. let tag = this.getValueByKey(USER.IS_AIRDROP)
  169. if (!tag){
  170. tag = false;
  171. }
  172. return tag;
  173. }
  174. set is_airdrop(tag:boolean) {
  175. this.saveValueByKey(USER.IS_AIRDROP, tag);
  176. }
  177. get first_dec_power():boolean {
  178. let tag = this.getValueByKey(USER.FIRST_DEC_POWER)
  179. if (!tag){
  180. tag = false;
  181. }
  182. return tag;
  183. }
  184. set first_dec_power(tag:boolean) {
  185. this.saveValueByKey(USER.FIRST_DEC_POWER, tag);
  186. }
  187. get first_dec_bullet():boolean {
  188. let tag = this.getValueByKey(USER.FIRST_DEC_BULLET)
  189. if (!tag){
  190. tag = false;
  191. }
  192. return tag;
  193. }
  194. set first_dec_bullet(tag:boolean) {
  195. this.saveValueByKey(USER.FIRST_DEC_BULLET, tag);
  196. }
  197. get show_crazy_in_level():number {
  198. let tag = this.getValueByKey(USER.SHOW_CRAZY_IN_LEVEL)
  199. if (!tag){
  200. tag = 0;
  201. }
  202. return tag;
  203. }
  204. set show_crazy_in_level(tag:number) {
  205. this.saveValueByKey(USER.SHOW_CRAZY_IN_LEVEL, tag);
  206. }
  207. getValueByKey(key) {
  208. return this.Query(key, '');
  209. }
  210. saveValueByKey(key, value) {
  211. this.Set(key, value);
  212. this.Save();
  213. }
  214. /**需要重写 */
  215. getMessageListeners() {
  216. return {
  217. }
  218. }
  219. }