|
@@ -10,18 +10,40 @@ let BagMgr = {
|
10
|
10
|
// }
|
11
|
11
|
_items: [], // 背包基础信息
|
12
|
12
|
|
13
|
|
- init () {
|
|
13
|
+ init() {
|
14
|
14
|
if (CC_EDITOR) {
|
15
|
15
|
return;
|
16
|
16
|
}
|
17
|
17
|
|
18
|
18
|
this._items = [];
|
19
|
19
|
|
20
|
|
- // 推送消息
|
21
|
|
- cc.game.on('on_user_items', this._onUserItems, this);
|
|
20
|
+ this._initEventListener();
|
|
21
|
+ this._initPublishListener();
|
22
|
22
|
},
|
23
|
23
|
|
24
|
|
- _addItemData (data) {
|
|
24
|
+ _initEventListener() {
|
|
25
|
+ // 通用消息
|
|
26
|
+ G.PublicMgr.on(JMC.PUBLIC_MSG.SWITCH_ACCOUNT, JMC.PUBLIC_MSG_ORDER.BAG, this.handleDidSwitchAccount, this);
|
|
27
|
+ G.PublicMgr.on(JMC.PUBLIC_MSG.LOGIN_SUCCESS, JMC.PUBLIC_MSG_ORDER.BAG, this.handleDidLoginSuccess, this);
|
|
28
|
+ G.PublicMgr.on(JMC.PUBLIC_MSG.DISCONNECTED, JMC.PUBLIC_MSG_ORDER.BAG, this.handleDidDisconnected, this);
|
|
29
|
+ },
|
|
30
|
+
|
|
31
|
+ _initPublishListener() {
|
|
32
|
+ cc.game.on('on_user_items', this.handleUpdateItems, this);
|
|
33
|
+ },
|
|
34
|
+
|
|
35
|
+ handleDidLoginSuccess() {
|
|
36
|
+ this.requestInfo();
|
|
37
|
+ },
|
|
38
|
+
|
|
39
|
+ handleDidDisconnected() {
|
|
40
|
+ },
|
|
41
|
+
|
|
42
|
+ handleDidSwitchAccount() {
|
|
43
|
+ this._items = [];
|
|
44
|
+ },
|
|
45
|
+
|
|
46
|
+ _addItemData(data) {
|
25
|
47
|
let isUpdate = false;
|
26
|
48
|
for (let [idx, itemData] of Object.entries(this._items)) {
|
27
|
49
|
if (itemData.id == data.id) {
|
|
@@ -67,11 +89,11 @@ let BagMgr = {
|
67
|
89
|
|
68
|
90
|
//* ************* 客户端请求/响应 ************* *//
|
69
|
91
|
|
70
|
|
- requestInfo () {
|
|
92
|
+ requestInfo() {
|
71
|
93
|
G.NetworkMgr.sendSocketRequest('bag_get_info', {}, this._responseBagGetInfo.bind(this));
|
72
|
94
|
},
|
73
|
95
|
|
74
|
|
- _responseBagGetInfo (data) {
|
|
96
|
+ _responseBagGetInfo(data) {
|
75
|
97
|
let responseInfo = data.responseInfo;
|
76
|
98
|
if (responseInfo.code === 200) {
|
77
|
99
|
// 玩家基础信息
|
|
@@ -86,8 +108,7 @@ let BagMgr = {
|
86
|
108
|
|
87
|
109
|
_onUserItems(data) {
|
88
|
110
|
if (!data || !data.items || data.items.length == 0) return;
|
89
|
|
- for (const item of data.items)
|
90
|
|
- {
|
|
111
|
+ for (const item of data.items) {
|
91
|
112
|
this._addItemData(item);
|
92
|
113
|
}
|
93
|
114
|
}
|