Beispiel #1
0
 public void UpdateStateTime(int gameId, KuaFuRoleStates state, long stateEndTicks)
 {
     lock (this)
     {
         Age++;
         GameId        = gameId;
         State         = state;
         StateEndTicks = stateEndTicks;
     }
 }
Beispiel #2
0
        public int ChangeRoleState(int roleId, KuaFuRoleStates state, bool noWait = false)
        {
            int result = StdErrorCode.Error_Operation_Faild;

            ITianTiService kuaFuService  = null;
            KuaFuRoleData  kuaFuRoleData = null;
            int            serverId      = ClientInfo.ServerId;

            lock (Mutex)
            {
                if (RoleId2RoleDataDict.TryGetValue(roleId, out kuaFuRoleData))
                {
                    serverId = kuaFuRoleData.ServerId;
                }
            }

            kuaFuService = GetKuaFuService(noWait);
            if (null != kuaFuService)
            {
                try
                {
                    result = kuaFuService.RoleChangeState(serverId, roleId, (int)state);
                    if (result >= 0)
                    {
                        lock (Mutex)
                        {
                            if (RoleId2RoleDataDict.TryGetValue(roleId, out kuaFuRoleData))
                            {
                                kuaFuRoleData.State = (KuaFuRoleStates)result;
                            }
                        }

                        if (null != kuaFuRoleData)
                        {
                            UpdateRoleData(kuaFuRoleData);
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    result = StdErrorCode.Error_Server_Internal_Error;
                }
            }

            return(result);
        }
Beispiel #3
0
        public int ChangeRoleState(int roleId, KuaFuRoleStates state, bool noWait = false)
        {
            int           result        = -11;
            KuaFuRoleData kuaFuRoleData = null;
            int           serverId      = this.ClientInfo.ServerId;

            lock (this.Mutex)
            {
                if (this.RoleId2RoleDataDict.TryGetValue(roleId, out kuaFuRoleData))
                {
                    serverId = kuaFuRoleData.ServerId;
                }
            }
            IKuaFuService kuaFuService = this.GetKuaFuService(noWait);

            if (null != kuaFuService)
            {
                try
                {
                    result = kuaFuService.RoleChangeState(serverId, roleId, (int)state);
                    if (result >= 0)
                    {
                        lock (this.Mutex)
                        {
                            if (this.RoleId2RoleDataDict.TryGetValue(roleId, out kuaFuRoleData))
                            {
                                kuaFuRoleData.State = (KuaFuRoleStates)result;
                            }
                        }
                        if (null != kuaFuRoleData)
                        {
                            this.UpdateRoleData(kuaFuRoleData, 0);
                        }
                    }
                }
                catch (Exception ex)
                {
                    result = -11003;
                }
            }
            return(result);
        }
Beispiel #4
0
        private int ChangeRoleState(KuaFuRoleData kuaFuRoleData, KuaFuRoleStates state)
        {
            int result = -1;

            try
            {
                IKuaFuClient  kuaFuClient = null;
                KuaFuRoleData roleData    = null;
                int           oldGameId   = 0;
                lock (kuaFuRoleData)
                {
                    kuaFuRoleData.Age++;
                    kuaFuRoleData.State = state;
                    if (state == KuaFuRoleStates.None && kuaFuRoleData.GameId > 0)
                    {
                        oldGameId = kuaFuRoleData.GameId;
                    }

                    roleData = (KuaFuRoleData)kuaFuRoleData;
                }

                if (oldGameId > 0)
                {
                    RemoveRoleFromFuBen(oldGameId, kuaFuRoleData.RoleId);
                }

                if (null != roleData)
                {
                    AsyncDataItem evItem = new AsyncDataItem(KuaFuEventTypes.RoleStateChange, kuaFuRoleData);
                    ClientAgentManager.Instance().PostAsyncEvent(kuaFuRoleData.ServerId, GameType, evItem);
                }
            }
            catch (System.Exception ex)
            {
                return(-1);
            }

            return(result);
        }
Beispiel #5
0
        private int ChangeRoleState(HuanYingSiYuanAgent huanYingSiYuanAgent, KuaFuRoleData kuaFuRoleData, KuaFuRoleStates state)
        {
            int result = -1;

            try
            {
                IKuaFuClient  kuaFuClient = null;
                KuaFuRoleData roleData    = null;
                int           oldGameId   = 0;
                lock (kuaFuRoleData)
                {
                    kuaFuRoleData.Age++;
                    kuaFuRoleData.State = state;
                    if (state == KuaFuRoleStates.None && kuaFuRoleData.GameId > 0)
                    {
                        oldGameId = kuaFuRoleData.GameId;
                    }

                    kuaFuClient = huanYingSiYuanAgent.KuaFuClient;
                    roleData    = (KuaFuRoleData)kuaFuRoleData;
                }

                if (oldGameId > 0)
                {
                    RemoveRoleFromFuBen(oldGameId, kuaFuRoleData.RoleId);
                }

                if (null != kuaFuClient && null != roleData)
                {
                    result = huanYingSiYuanAgent.NotifyChangeState(kuaFuRoleData);
                }
            }
            catch (System.Exception ex)
            {
                return(-1);
            }

            return(result);
        }