Example #1
0
        /// <summary>
        /// Broast all peers in team, beside self
        /// e.g BroadcastType is Chat
        /// e.g BroadcastType is Region,that will send same region action
        /// </summary>
        /// <param name="peer"></param>
        /// <param name="bundle"></param>
        public void BroadcastEvent(MarsPeer peer, Bundle bundle, BroadcastType broadcastType = BroadcastType.Notice)
        {
            Team            team     = null;
            List <MarsPeer> peerList = new List <MarsPeer>();

            if (Rooms.TryGetValue(peer.team.teamId, out team) == true)
            {
                foreach (MarsPeer for_p in team.peers)
                {
                    if (for_p != peer)
                    {
                        if (broadcastType == BroadcastType.Region)
                        {
                            if (peer.region != for_p.region || peer.region == Constants.SelectRole)
                            {
                                continue;
                            }
                        }
                        peerList.Add(for_p);
                    }
                }
            }
            if (peerList.Count > 0)
            {
                MarsPeer.BroadCastEvent(peerList, bundle);
            }
        }
Example #2
0
        void SetBroadMsg(Role role)
        {
            //get all online peers, in public region
            List <MarsPeer> peers = Actor.Instance.HandleAccountListOnlineBySamePos(this.marsPeer);

            if (peers.Count >= 0)
            {
                Bundle bundle = new Bundle();
                bundle.role = role;
                bundle.cmd  = Command.UpdatePlayer;
                MarsPeer.BroadCastEvent(peers, bundle);
            }
        }
Example #3
0
        public Game(MarsPeer peer)
        {
            this.marsPeer = peer;

            if (poolFiber == null)
            {
                poolFiber = new PoolFiber();
                poolFiber.Start();
            }

            /*this.poolFiber = new PoolFiber();
             * this.poolFiber.Start();*/
        }
Example #4
0
        /// <summary>
        /// add a peer by accountid
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="peer"></param>
        /// <returns></returns>
        public bool HandleAccountLogin(long accountId, MarsPeer peer)
        {
            MarsPeer getPeer = null;

            //if ( .TryGetValue(accountId, out getPeer) == false)
            if (Actors.TryGetValue(accountId, out getPeer) == false)
            {
                Actors.Add(peer);//NEW TODO:
                Debug.Log("Start..................................." + Size);
                return(true);
            }
            else
            {
                getPeer.Disconnect();
                getPeer.Dispose();
                getPeer = null;
                return(false);
            }
        }
Example #5
0
        /// <summary>
        /// LeaveTeamRole;Return a role
        /// </summary>
        /// <param name="peer"></param>
        public Role LeaveTeamRole(MarsPeer peer)
        {
            Role role = null;

            lock (this.SyncRoot)
            {
                Team team = null;
                if (Rooms.TryGetValue(peer.team.teamId, out team) == true)
                {
                    role = peer.Role;
                    team.peers.Remove(peer);
                    if (team.peers.Count == 0)
                    {
                        RemoveTeam(peer.team.teamId);
                    }
                }
            }
            return(role);
        }
Example #6
0
        private void GetEnterGameData(Role role)
        {
            Role newRole = new Role();//this.Role;//RoleMySQL.instance.getRoleByRoleId(roleId);

            if (newRole != null)
            {
                newRole.accountId  = marsPeer.Role.accountId;
                newRole.roleId     = marsPeer.Role.roleId;
                newRole.roleName   = marsPeer.Role.roleName;
                newRole.sex        = marsPeer.Role.sex;
                newRole.exp        = marsPeer.Role.exp;
                newRole.profession = marsPeer.Role.profession;
                newRole.level      = marsPeer.Role.level;
                newRole.expMax     = ExpMySQL.instance.GetNextExp(marsPeer.Role.level + 1);

                PropertyValue pv = Property.instance.GetValueByK(newRole.profession);
                newRole.strength = pv.strength;
                newRole.stamina  = pv.stamina;
                newRole.wit      = pv.wit;
                newRole.agility  = pv.agility;
                newRole.critical = pv.critical;

                bundle.onlineRoles = Actor.Instance.HandleRoleListOnlineBySamePos(this.marsPeer);
                bundle.role        = newRole;
            }
            //get all online peers, in public region
            List <MarsPeer> peers = Actor.Instance.HandleAccountListOnlineBySamePos(this.marsPeer);

            //new Role
            if (peers.Count >= 0)
            {
                Role mRole = new Role();
                mRole.roleId     = newRole.roleId;
                mRole.roleName   = newRole.roleName;
                mRole.profession = newRole.profession;
                Bundle mBundle = new Bundle();
                mBundle.cmd  = Command.AddNewPlayer;
                mBundle.role = mRole;
                MarsPeer.BroadCastEvent(peers, mBundle);
            }
        }
Example #7
0
        /// <summary>
        /// !!!!!!!!!
        /// id is team's id
        /// name is team's. if not null, creat, else get a specified team
        /// MarsPeer is one peer;
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="peer"></param>
        /// <returns></returns>
        public virtual Team GetTeamById(string id, string name, MarsPeer peer) //creat new......
        {
            Team team = null;                                                  //

            lock (this.SyncRoot)
            {
                if (id == null || Rooms.TryGetValue(id, out team) == false)
                {
                    if (name != null)
                    {
                        team          = new Team();
                        team.teamId   = (MinTeamID++).ToString();//Guid.NewGuid().ToString();
                        team.teamName = name;
                        team.peers    = new List <MarsPeer>();
                        Rooms.Add(team.teamId, team);
                    }
                }
                if (team.peers.Contains(peer) == false)
                {
                    team.peers.Add(peer);
                }
            }
            return(team);
        }
Example #8
0
        public override void ExecuteOperation(Command cmd, params object[] objs)
        {
            base.ExecuteOperation(cmd, objs);

            Message message = (Message)objs[0];

            bundle.message = message;
            List <MarsPeer> peers = null;// new List<MarsPeer>();

            switch (message.chatType)
            {
            case ChatType.World:
                peers = HandleWorldChat();
                break;

            case ChatType.Team:
                HandleTeamChat();
                return;
            }
            if (peers != null && peers.Count > 0)
            {
                MarsPeer.BroadCastEvent(peers, bundle);
            }
        }
Example #9
0
 /// <summary>
 /// get same region's roles
 /// </summary>
 /// <param name="peer"></param>
 /// <returns></returns>
 public List <Role> HandleRoleListOnlineBySamePos(MarsPeer peer)
 {
     return(Actors.GetRolesBySamePos(peer));
 }
Example #10
0
 /// <summary>
 /// Get the same region all peers beside self
 /// </summary>
 /// <param name="peer"></param>
 /// <returns></returns>
 public List <MarsPeer> HandleAccountListOnlineBySamePos(MarsPeer peer)
 {
     return(Actors.GetPeersBySamePos(peer));
 }
Example #11
0
 /// <summary>
 /// Remove a peer by accountid
 /// </summary>
 /// <param name="accountId"></param>
 public void HandleDisconnect(MarsPeer peer)
 {
     Actors.Remove(peer);//NEW TODO:
 }
Example #12
0
 public MessageOperator(MarsPeer peer)
     : base(peer)
 {
 }
Example #13
0
 public ServerOperator(MarsPeer peer) : base(peer)
 {
 }
Example #14
0
 public TeamOperator(MarsPeer peer)
     : base(peer)
 {
 }
Example #15
0
 public MonsterOperator(MarsPeer peer)
     : base(peer)
 {
 }
Example #16
0
 public FightOperator(MarsPeer peer)
     : base(peer)
 {
 }
Example #17
0
 public RoleOperator(MarsPeer peer)
     : base(peer)
 {
 }