Esempio n. 1
0
        private bool ChangeOccupation(GameClient client, int nID, byte[] bytes, string[] cmdParams)
        {
            int result           = 0;
            int targetOccupation = Global.SafeConvertToInt32(cmdParams[1]);
            int occupation       = client.ClientData.Occupation;

            GameManager.ClientMgr.StopClientStoryboard(client, -1);
            if (!this.IsGongNengOpened(client))
            {
                result = -12;
            }
            else if (!client.InSafeRegion)
            {
                result = -33;
            }
            else if (occupation == targetOccupation)
            {
                result = -18;
            }
            else
            {
                lock (this.RuntimeData.Mutex)
                {
                    if (!this.RuntimeData.CanChangeOccupationMapCodes.Contains(client.ClientData.MapCode))
                    {
                        result = -34;
                        goto IL_221;
                    }
                    if (!client.ClientData.OccupationList.Contains(targetOccupation))
                    {
                        result = -20;
                        goto IL_221;
                    }
                }
                RoleCustomData customData = Global.sendToDB <RoleCustomData, int>(10230, client.ClientData.RoleID, client.ServerId);
                if (null == customData)
                {
                    customData = new RoleCustomData
                    {
                        roleId = client.ClientData.RoleID
                    };
                }
                this.SaveRoleCustomData(client, customData);
                if (!this.StoreRoleOccGoodsList(client))
                {
                    result = -15;
                }
                if (result >= 0)
                {
                    string[] args = Global.SendToDB <string>(10126, string.Format("{0}:{1}", client.ClientData.RoleID, targetOccupation), client.ServerId);
                    if (args[1] != targetOccupation.ToString())
                    {
                        result = -15;
                    }
                    else
                    {
                        EventLogManager.AddChangeOccupationEvent(client, targetOccupation);
                        client.ClientData.Occupation       = targetOccupation;
                        client.ClientData.IsMainOccupation = (client.ClientData.OccupationList[0] == client.ClientData.Occupation);
                        this.RestoreRoleCustomData(client, customData);
                        this.RestoreRoleOccGoodsList(client);
                        RebornManager.getInstance().InitPlayerRebornPorperty(client);
                        client.sendCmd <int>(13999, client.ClientData.RoleID, false);
                    }
                }
            }
IL_221:
            if (result < 0)
            {
                client.sendCmd <int>(nID, result, false);
            }
            return(true);
        }