summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XAttributeMgr.cs
blob: 1d2f91e4748228b779c90b646f8028797ff00bc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
using System;
using System.Collections.Generic;
using System.IO;
using KKSG;
using ProtoBuf;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XAttributeMgr : XSingleton<XAttributeMgr>
	{
		public XPlayerAttributes XPlayerData
		{
			get
			{
				return this._playerAttributes;
			}
		}

		public XAttributeMgr.XPlayerCharacterInfo XPlayerCharacters
		{
			get
			{
				return this._playerCharacterInfo;
			}
		}

		public LoginExtraData LoginExData { get; private set; }

		private SmallBufferPool<double> m_AttrPool = new SmallBufferPool<double>();

		private BlockInfo[] blockInit = new BlockInfo[]
		{
			new BlockInfo(XAttributeCommon.AttrCount, 256)
		};

		private XPlayerAttributes _playerAttributes = null;

		private XAttributeMgr.XPlayerCharacterInfo _playerCharacterInfo = new XAttributeMgr.XPlayerCharacterInfo();

		public class XPlayerCharacterInfo
		{
			public List<RoleBriefInfo> PlayerBriefInfo = new List<RoleBriefInfo>();

			public int SelectedSlot = 0;
		}

		public override bool Init()
		{
			this.m_AttrPool.Init(this.blockInit, 8);
			return true;
		}

		public int BackFlowLevel()
		{
			int result = 0;
			bool flag = this.LoginExData != null && this.LoginExData.is_backflow_server;
			if (flag)
			{
				result = (int)this.LoginExData.backflow_level;
			}
			return result;
		}

		public void GetBuffer(ref SmallBuffer<double> sb, int size, int initSize = 0)
		{
			this.m_AttrPool.GetBlock(ref sb, size, initSize);
		}

		public void ReturnBuffer(ref SmallBuffer<double> sb)
		{
			this.m_AttrPool.ReturnBlock(ref sb);
		}

		public void ResetPlayerData()
		{
			bool flag = this._playerAttributes != null;
			if (flag)
			{
				this._playerAttributes.HPMPReset();
				this._playerAttributes.IsDead = false;
			}
			XStaticSecurityStatistics.Reset();
		}

		public XPlayerAttributes InitPlayerAttr(RoleBrief brief, KKSG.Attribute attr, List<SkillInfo> skills, List<uint> skillSlot, uint skillPageIndex, RoleSystem system, MilitaryRecord militaryRank)
		{
			bool flag = this._playerAttributes != null;
			if (flag)
			{
				this._playerAttributes.UninitilizeBuffer();
			}
			this._playerAttributes = (this.InitAttrFromServer(brief.roleID, brief.nickID, (uint)XFastEnumIntEqualityComparer<RoleType>.ToInt(brief.type), brief.name, attr, 1u, true, skills, skillSlot, new XOutLookAttr(brief.titleID, militaryRank), brief.level, brief.paymemberid) as XPlayerAttributes);
			this._playerAttributes.Outlook.SetProfType(this._playerAttributes.TypeID);
			this._playerAttributes.Outlook.uiAvatar = false;
			this._playerAttributes.Exp = brief.exp;
			this._playerAttributes.MaxExp = brief.maxexp;
			this._playerAttributes.SkillPageIndex = skillPageIndex;
			bool flag2 = system != null;
			if (flag2)
			{
				this._playerAttributes.openedSystem = system.system;
			}
			this._playerAttributes.Profession = brief.type;
			return this._playerAttributes;
		}

		public XAttributes InitAttrFromServer(ulong id, uint shortId, uint type_id, string name, KKSG.Attribute attr, uint fightgroup, bool isControlled, List<SkillInfo> skills, List<uint> bindskills, XOutLookAttr outlookAttr, uint level, uint payMemberID = 0u)
		{
			bool flag = XAttributes.GetCategory(id) == EntityCategory.Category_Role || XAttributes.GetCategory(id) == EntityCategory.Category_DummyRole;
			XAttributes xattributes;
			uint presentID;
			if (flag)
			{
				bool flag2 = XAttributes.IsPlayer(id);
				if (flag2)
				{
					xattributes = (XSingleton<XComponentMgr>.singleton.CreateComponent(null, XPlayerAttributes.uuID) as XPlayerAttributes);
				}
				else
				{
					xattributes = (XSingleton<XComponentMgr>.singleton.CreateComponent(null, XRoleAttributes.uuID) as XRoleAttributes);
				}
				presentID = XSingleton<XEntityMgr>.singleton.RoleInfo.GetByProfID(type_id % 10u).PresentID;
				XRoleAttributes xroleAttributes = xattributes as XRoleAttributes;
				xroleAttributes.Profession = (RoleType)type_id;
				xroleAttributes.GuildName = ((outlookAttr.guild == null) ? "" : outlookAttr.guild.name);
				xroleAttributes.GuildPortrait = ((outlookAttr.guild == null) ? 0u : outlookAttr.guild.icon);
				xroleAttributes.GuildID = ((outlookAttr.guild == null) ? 0UL : outlookAttr.guild.id);
				xroleAttributes.DesignationID = outlookAttr.designationID;
				xroleAttributes.SpecialDesignation = outlookAttr.specialDesignation;
				xroleAttributes.MilitaryRank = outlookAttr.militaryRank;
				xroleAttributes.PrerogativeScore = outlookAttr.prerogativeScore;
				xroleAttributes.PrerogativeSetID = outlookAttr.prerogativeSetID;
				bool flag3 = bindskills != null;
				if (flag3)
				{
					xroleAttributes.skillSlot = bindskills.ToArray();
				}
				xattributes.Type = EntitySpecies.Species_Role;
				xattributes.BeLocked = false;
			}
			else
			{
				XEntityStatistics.RowData byID = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID(type_id);
				presentID = byID.PresentID;
				xattributes = (XSingleton<XComponentMgr>.singleton.CreateComponent(null, XOthersAttributes.uuID) as XOthersAttributes);
				xattributes.Type = (EntitySpecies)byID.Type;
				xattributes.InitAttribute(byID);
			}
			xattributes.Prefab = XSingleton<XEntityMgr>.singleton.EntityInfo.GetByPresentID(presentID).Prefab;
			xattributes.Name = name;
			xattributes.ShortId = shortId;
			xattributes.EntityID = id;
			xattributes.TypeID = type_id;
			xattributes.PresentID = presentID;
			bool flag4 = attr != null;
			if (flag4)
			{
				xattributes.InitAttribute(attr);
			}
			xattributes.FightGroup = fightgroup;
			xattributes.TitleID = outlookAttr.titleID;
			xattributes.PayMemberID = payMemberID;
			bool flag5 = skills != null;
			if (flag5)
			{
				xattributes.SkillLevelInfo.Init(skills);
			}
			xattributes.Level = level;
			return xattributes;
		}

		public XOthersAttributes InitAttrFromClient(uint id, KKSG.Attribute attr, uint fightgroup)
		{
			XEntityStatistics.RowData byID = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID(id);
			bool flag = byID == null;
			XOthersAttributes result;
			if (flag)
			{
				result = null;
			}
			else
			{
				uint presentID = byID.PresentID;
				XEntityPresentation.RowData byPresentID = XSingleton<XEntityMgr>.singleton.EntityInfo.GetByPresentID(presentID);
				bool flag2 = byPresentID == null || string.IsNullOrEmpty(byPresentID.Prefab);
				if (flag2)
				{
					result = null;
				}
				else
				{
					XOthersAttributes xothersAttributes = XSingleton<XComponentMgr>.singleton.CreateComponent(null, XOthersAttributes.uuID) as XOthersAttributes;
					xothersAttributes.Prefab = byPresentID.Prefab;
					xothersAttributes.Name = byID.Name;
					xothersAttributes.EntityID = (ulong)(((long)XSingleton<XCommon>.singleton.New_id & 1152921504606846975L) | (long)XAttributes.GetTypePrefix((EntitySpecies)byID.Type));
					xothersAttributes.TypeID = id;
					xothersAttributes.PresentID = presentID;
					xothersAttributes.Type = (EntitySpecies)byID.Type;
					bool flag3 = fightgroup != uint.MaxValue && byID.Fightgroup == -1;
					if (flag3)
					{
						xothersAttributes.FightGroup = fightgroup;
					}
					else
					{
						xothersAttributes.FightGroup = (uint)byID.Fightgroup;
					}
					xothersAttributes.InitAttribute(byID);
					bool flag4 = attr != null;
					if (flag4)
					{
						xothersAttributes.InitAttribute(attr);
					}
					result = xothersAttributes;
				}
			}
			return result;
		}

		public bool HasNoRoleOnBackFlowServer()
		{
			bool flag = this.LoginExData != null && this.LoginExData.is_backflow_server;
			bool result;
			if (flag)
			{
				for (int i = 0; i < this._playerCharacterInfo.PlayerBriefInfo.Count; i++)
				{
					bool flag2 = this._playerCharacterInfo.PlayerBriefInfo[i] != null;
					if (flag2)
					{
						return false;
					}
				}
				result = true;
			}
			else
			{
				result = false;
			}
			return result;
		}

		public XNpcAttributes InitNpcAttr(uint id)
		{
			XNpcInfo.RowData byNPCID = XSingleton<XEntityMgr>.singleton.NpcInfo.GetByNPCID(id);
			bool flag = byNPCID == null;
			XNpcAttributes result;
			if (flag)
			{
				result = null;
			}
			else
			{
				uint presentID = byNPCID.PresentID;
				XNpcAttributes xnpcAttributes = XSingleton<XComponentMgr>.singleton.CreateComponent(null, XNpcAttributes.uuID) as XNpcAttributes;
				xnpcAttributes.Prefab = XSingleton<XEntityMgr>.singleton.EntityInfo.GetByPresentID(presentID).Prefab;
				xnpcAttributes.Name = byNPCID.Name;
				xnpcAttributes.EntityID = (XAttributes.GetTypePrefix(EntitySpecies.Species_Npc) | (ulong)XSingleton<XCommon>.singleton.XHash(byNPCID.Name) + (ulong)((long)XSingleton<XCommon>.singleton.New_id));
				xnpcAttributes.TypeID = id;
				xnpcAttributes.PresentID = presentID;
				xnpcAttributes.Type = EntitySpecies.Species_Npc;
				xnpcAttributes.FightGroup = (uint)XFastEnumIntEqualityComparer<FightGroupType>.ToInt(FightGroupType.FightNeutral);
				xnpcAttributes.InitAttribute(byNPCID);
				result = xnpcAttributes;
			}
			return result;
		}

		public bool ProcessAccountData(LoadAccountData roAccountData)
		{
			bool flag = roAccountData == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo.Clear();
				this.ParseRoleBriefInfo(XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role1);
				this.ParseRoleBriefInfo(XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role2);
				this.ParseRoleBriefInfo(XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role3);
				this.ParseRoleBriefInfo(XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role4);
				this.ParseRoleBriefInfo(XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role5);
				this.ParseRoleBriefInfo(XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role6);
				this.ParseRoleBriefInfo(XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role7);
				this.ParseRoleBriefInfo(XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role8);
				this.ParseRoleBriefInfo(XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role9);
				bool flag2 = roAccountData.selectSlot >= (uint)XGame.RoleCount;
				if (flag2)
				{
					XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.SelectedSlot = 0;
				}
				else
				{
					XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.SelectedSlot = (int)(roAccountData.selectSlot + 1u);
				}
				result = true;
			}
			return result;
		}

		public void ProcessLoginExtraData(LoginExtraData data)
		{
			this.LoginExData = data;
		}

		public void OnLeaveStage()
		{
			this._playerAttributes = null;
		}

		public void OnReconnect()
		{
			List<SkillInfo> skills = null;
			List<uint> skillSlot = null;
			uint skillPageIndex = 0u;
			bool flag = XSingleton<XReconnection>.singleton.PlayerInfo.skill != null;
			if (flag)
			{
				skills = ((XSingleton<XReconnection>.singleton.PlayerInfo.skill.index == 0u) ? XSingleton<XReconnection>.singleton.PlayerInfo.skill.Skills : XSingleton<XReconnection>.singleton.PlayerInfo.skill.SkillsTwo);
				skillSlot = ((XSingleton<XReconnection>.singleton.PlayerInfo.skill.index == 0u) ? XSingleton<XReconnection>.singleton.PlayerInfo.skill.SkillSlot : XSingleton<XReconnection>.singleton.PlayerInfo.skill.SkillSlotTwo);
				skillPageIndex = XSingleton<XReconnection>.singleton.PlayerInfo.skill.index;
			}
			this.InitPlayerAttrByReconncet(XSingleton<XReconnection>.singleton.PlayerInfo.Brief, XSingleton<XReconnection>.singleton.PlayerApperance.attributes, skills, skillSlot, skillPageIndex, XSingleton<XReconnection>.singleton.PlayerInfo.system, XSingleton<XReconnection>.singleton.PlayerInfo.military);
			bool flag2 = XSingleton<XEntityMgr>.singleton.Player != null;
			if (flag2)
			{
				XSecurityStatistics xsecurityStatistics = XSecurityStatistics.TryGetStatistics(XSingleton<XEntityMgr>.singleton.Player);
				XOutlookHelper.SetOutLook(this._playerAttributes, XSingleton<XReconnection>.singleton.PlayerApperance.outlook, true);
				this._playerAttributes.AutoPlayOn = XSingleton<XReconnection>.singleton.IsAutoFight;
				XSingleton<XEntityMgr>.singleton.Player.Attributes.OnFightGroupChange((XSingleton<XGame>.singleton.SyncModeValue != 0) ? XSingleton<XReconnection>.singleton.PlayerApperance.fightgroup : ((uint)XFastEnumIntEqualityComparer<FightGroupType>.ToInt(FightGroupType.FightRole)));
			}
		}

		private void InitPlayerAttrByReconncet(RoleBrief brief, KKSG.Attribute attr, List<SkillInfo> skills, List<uint> skillSlot, uint skillPageIndex, RoleSystem system, MilitaryRecord militaryRank)
		{
			this.InitAttrFromServerByReconncet(brief.roleID, brief.nickID, (uint)XFastEnumIntEqualityComparer<RoleType>.ToInt(brief.type), brief.name, attr, (XSingleton<XGame>.singleton.SyncModeValue != 0) ? XSingleton<XReconnection>.singleton.PlayerApperance.fightgroup : ((uint)XFastEnumIntEqualityComparer<FightGroupType>.ToInt(FightGroupType.FightRole)), true, skills, skillSlot, brief.level, new XOutLookAttr(brief.titleID, militaryRank), brief.paymemberid);
			this._playerAttributes.Outlook.SetProfType(this._playerAttributes.TypeID);
			this._playerAttributes.Outlook.uiAvatar = false;
			this._playerAttributes.Exp = brief.exp;
			this._playerAttributes.MaxExp = brief.maxexp;
			this._playerAttributes.SkillPageIndex = skillPageIndex;
			bool flag = system != null;
			if (flag)
			{
				this._playerAttributes.openedSystem = system.system;
			}
			this._playerAttributes.Profession = brief.type;
		}

		private void InitAttrFromServerByReconncet(ulong id, uint shortId, uint type_id, string name, KKSG.Attribute attr, uint fightgroup, bool isControlled, List<SkillInfo> skills, List<uint> bindskills, uint level, XOutLookAttr outlookAttr, uint payMemberID = 0u)
		{
			XAttributes playerAttributes = this._playerAttributes;
			uint presentID = XSingleton<XEntityMgr>.singleton.RoleInfo.GetByProfID(type_id % 10u).PresentID;
			XRoleAttributes xroleAttributes = playerAttributes as XRoleAttributes;
			xroleAttributes.Profession = (RoleType)type_id;
			xroleAttributes.MilitaryRank = outlookAttr.militaryRank;
			bool flag = bindskills != null;
			if (flag)
			{
				xroleAttributes.skillSlot = bindskills.ToArray();
			}
			playerAttributes.Type = EntitySpecies.Species_Role;
			playerAttributes.BeLocked = false;
			playerAttributes.Prefab = XSingleton<XEntityMgr>.singleton.EntityInfo.GetByPresentID(presentID).Prefab;
			playerAttributes.Name = name;
			playerAttributes.ShortId = shortId;
			playerAttributes.EntityID = id;
			playerAttributes.TypeID = type_id;
			playerAttributes.PresentID = presentID;
			bool flag2 = attr != null;
			if (flag2)
			{
				playerAttributes.InitAttribute(attr);
			}
			playerAttributes.FightGroup = fightgroup;
			playerAttributes.TitleID = outlookAttr.titleID;
			playerAttributes.PayMemberID = payMemberID;
			bool flag3 = skills != null;
			if (flag3)
			{
				playerAttributes.SkillLevelInfo.Init(skills);
			}
			playerAttributes.Level = level;
		}

		private void ParseRoleBriefInfo(List<RoleBriefInfo> list, byte[] data)
		{
			bool flag = list.Count >= XGame.RoleCount;
			if (!flag)
			{
				bool flag2 = data == null || data.Length == 0;
				if (flag2)
				{
					list.Add(null);
				}
				else
				{
					MemoryStream source = new MemoryStream(data);
					RoleBriefInfo item = Serializer.Deserialize<RoleBriefInfo>(source);
					list.Add(item);
				}
			}
		}
	}
}