From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/XAttributeMgr.cs | 409 +++++++++++++++++++++ 1 file changed, 409 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XAttributeMgr.cs (limited to 'Client/Assets/Scripts/XMainClient/XAttributeMgr.cs') diff --git a/Client/Assets/Scripts/XMainClient/XAttributeMgr.cs b/Client/Assets/Scripts/XMainClient/XAttributeMgr.cs new file mode 100644 index 00000000..1d2f91e4 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XAttributeMgr.cs @@ -0,0 +1,409 @@ +using System; +using System.Collections.Generic; +using System.IO; +using KKSG; +using ProtoBuf; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XAttributeMgr : XSingleton + { + public XPlayerAttributes XPlayerData + { + get + { + return this._playerAttributes; + } + } + + public XAttributeMgr.XPlayerCharacterInfo XPlayerCharacters + { + get + { + return this._playerCharacterInfo; + } + } + + public LoginExtraData LoginExData { get; private set; } + + private SmallBufferPool m_AttrPool = new SmallBufferPool(); + + 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 PlayerBriefInfo = new List(); + + 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 sb, int size, int initSize = 0) + { + this.m_AttrPool.GetBlock(ref sb, size, initSize); + } + + public void ReturnBuffer(ref SmallBuffer 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 skills, List 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.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 skills, List 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.singleton.CreateComponent(null, XPlayerAttributes.uuID) as XPlayerAttributes); + } + else + { + xattributes = (XSingleton.singleton.CreateComponent(null, XRoleAttributes.uuID) as XRoleAttributes); + } + presentID = XSingleton.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.singleton.EntityStatistics.GetByID(type_id); + presentID = byID.PresentID; + xattributes = (XSingleton.singleton.CreateComponent(null, XOthersAttributes.uuID) as XOthersAttributes); + xattributes.Type = (EntitySpecies)byID.Type; + xattributes.InitAttribute(byID); + } + xattributes.Prefab = XSingleton.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.singleton.EntityStatistics.GetByID(id); + bool flag = byID == null; + XOthersAttributes result; + if (flag) + { + result = null; + } + else + { + uint presentID = byID.PresentID; + XEntityPresentation.RowData byPresentID = XSingleton.singleton.EntityInfo.GetByPresentID(presentID); + bool flag2 = byPresentID == null || string.IsNullOrEmpty(byPresentID.Prefab); + if (flag2) + { + result = null; + } + else + { + XOthersAttributes xothersAttributes = XSingleton.singleton.CreateComponent(null, XOthersAttributes.uuID) as XOthersAttributes; + xothersAttributes.Prefab = byPresentID.Prefab; + xothersAttributes.Name = byID.Name; + xothersAttributes.EntityID = (ulong)(((long)XSingleton.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.singleton.NpcInfo.GetByNPCID(id); + bool flag = byNPCID == null; + XNpcAttributes result; + if (flag) + { + result = null; + } + else + { + uint presentID = byNPCID.PresentID; + XNpcAttributes xnpcAttributes = XSingleton.singleton.CreateComponent(null, XNpcAttributes.uuID) as XNpcAttributes; + xnpcAttributes.Prefab = XSingleton.singleton.EntityInfo.GetByPresentID(presentID).Prefab; + xnpcAttributes.Name = byNPCID.Name; + xnpcAttributes.EntityID = (XAttributes.GetTypePrefix(EntitySpecies.Species_Npc) | (ulong)XSingleton.singleton.XHash(byNPCID.Name) + (ulong)((long)XSingleton.singleton.New_id)); + xnpcAttributes.TypeID = id; + xnpcAttributes.PresentID = presentID; + xnpcAttributes.Type = EntitySpecies.Species_Npc; + xnpcAttributes.FightGroup = (uint)XFastEnumIntEqualityComparer.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.singleton.XPlayerCharacters.PlayerBriefInfo.Clear(); + this.ParseRoleBriefInfo(XSingleton.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role1); + this.ParseRoleBriefInfo(XSingleton.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role2); + this.ParseRoleBriefInfo(XSingleton.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role3); + this.ParseRoleBriefInfo(XSingleton.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role4); + this.ParseRoleBriefInfo(XSingleton.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role5); + this.ParseRoleBriefInfo(XSingleton.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role6); + this.ParseRoleBriefInfo(XSingleton.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role7); + this.ParseRoleBriefInfo(XSingleton.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role8); + this.ParseRoleBriefInfo(XSingleton.singleton.XPlayerCharacters.PlayerBriefInfo, roAccountData.role9); + bool flag2 = roAccountData.selectSlot >= (uint)XGame.RoleCount; + if (flag2) + { + XSingleton.singleton.XPlayerCharacters.SelectedSlot = 0; + } + else + { + XSingleton.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 skills = null; + List skillSlot = null; + uint skillPageIndex = 0u; + bool flag = XSingleton.singleton.PlayerInfo.skill != null; + if (flag) + { + skills = ((XSingleton.singleton.PlayerInfo.skill.index == 0u) ? XSingleton.singleton.PlayerInfo.skill.Skills : XSingleton.singleton.PlayerInfo.skill.SkillsTwo); + skillSlot = ((XSingleton.singleton.PlayerInfo.skill.index == 0u) ? XSingleton.singleton.PlayerInfo.skill.SkillSlot : XSingleton.singleton.PlayerInfo.skill.SkillSlotTwo); + skillPageIndex = XSingleton.singleton.PlayerInfo.skill.index; + } + this.InitPlayerAttrByReconncet(XSingleton.singleton.PlayerInfo.Brief, XSingleton.singleton.PlayerApperance.attributes, skills, skillSlot, skillPageIndex, XSingleton.singleton.PlayerInfo.system, XSingleton.singleton.PlayerInfo.military); + bool flag2 = XSingleton.singleton.Player != null; + if (flag2) + { + XSecurityStatistics xsecurityStatistics = XSecurityStatistics.TryGetStatistics(XSingleton.singleton.Player); + XOutlookHelper.SetOutLook(this._playerAttributes, XSingleton.singleton.PlayerApperance.outlook, true); + this._playerAttributes.AutoPlayOn = XSingleton.singleton.IsAutoFight; + XSingleton.singleton.Player.Attributes.OnFightGroupChange((XSingleton.singleton.SyncModeValue != 0) ? XSingleton.singleton.PlayerApperance.fightgroup : ((uint)XFastEnumIntEqualityComparer.ToInt(FightGroupType.FightRole))); + } + } + + private void InitPlayerAttrByReconncet(RoleBrief brief, KKSG.Attribute attr, List skills, List skillSlot, uint skillPageIndex, RoleSystem system, MilitaryRecord militaryRank) + { + this.InitAttrFromServerByReconncet(brief.roleID, brief.nickID, (uint)XFastEnumIntEqualityComparer.ToInt(brief.type), brief.name, attr, (XSingleton.singleton.SyncModeValue != 0) ? XSingleton.singleton.PlayerApperance.fightgroup : ((uint)XFastEnumIntEqualityComparer.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 skills, List bindskills, uint level, XOutLookAttr outlookAttr, uint payMemberID = 0u) + { + XAttributes playerAttributes = this._playerAttributes; + uint presentID = XSingleton.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.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 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(source); + list.Add(item); + } + } + } + } +} -- cgit v1.1-26-g67d0