Exemplo n.º 1
0
        public virtual async Task <RoleEnterZoneResponse> RoleEnter(RoleEnterZoneRequest req)
        {
            if (roles.ContainsKey(req.roleUUID))
            {
                return(new RoleEnterZoneResponse()
                {
                    s2c_code = RoleEnterZoneResponse.CODE_ROLE_ALREADY_IN_ZONE
                });
            }
            var roleInfo = new RoleInfo(req.roleUUID, req);

            //先添加以防止二次进入//
            roles.Add(roleInfo.uuid, roleInfo);
            try
            {
                var zone = await this.LookingForExpectZone(req);

                if (zone == null || zone.close)
                {
                    roles.Remove(req.roleUUID);
                    return(new RoleEnterZoneResponse()
                    {
                        s2c_code = RoleEnterZoneResponse.CODE_ZONE_NOT_EXIST
                    });
                }
                //--------------------------------------------------------------------------------
                //分配线.
                req.expectLineIndex = zone.lineIndex;
                req.expectZoneUUID  = zone.uuid;
                zone.AddTeamID(req.teamID);
                //--------------------------------------------------------------------------------
                var rsp = await zone.area.service.CallAsync <RoleEnterZoneResponse>(req);

                if (Response.CheckSuccess(rsp))
                {
                    zone.currentRoleCount++;
                    zone.area.currentRoleCount++;
                    roleInfo.zone = zone;
                }
                else
                {
                    roles.Remove(req.roleUUID);
                    log.Error(rsp);
                }
                return(rsp);
            }
            catch (Exception err)
            {
                roles.Remove(req.roleUUID);
                return(new RoleEnterZoneResponse()
                {
                    s2c_code = RoleEnterZoneResponse.CODE_ERROR, s2c_msg = err.Message
                });
            }
        }
Exemplo n.º 2
0
        protected virtual async Task <ZoneInfo> LookingForPublicZone(string publicmapUUID, int publicmapID, ZonePosition pos, RoleEnterZoneRequest req)
        {
            //没有统一返回上一次的公共场景.
            req.roleScenePos = pos;
            ZoneInfo zone = GetZone(publicmapUUID);

            if (zone != null && !zone.close)
            {
                if (zone.currentRoleCount < zone.map_data.max_players)
                {
                    return(zone);
                }
            }
            //找当前存在的公共场景.
            var temp = RPGServerTemplateManager.Instance.GetMapTemplate(publicmapID);

            if (temp == null)
            {
                temp = RPGServerTemplateManager.Instance.GetDefaultMapData(req);
                req.lastPublicPos = new ZonePosition();
            }
            zone = LookingForExpectServerGroupZone(req.servergroupID, z =>
            {
                return(z.currentRoleCount < temp.full_players && z.map_data.zone_template_id == temp.id);
            }, (a, b) =>
            {
                if (req.roleSessionNode == a.nodeName)
                {
                    return(-1);
                }
                if (req.roleSessionNode == b.nodeName)
                {
                    return(1);
                }
                return(0);
            });
            if (zone != null && !zone.close)
            {
                return(zone);
            }
            //创建一个公共场景.
            var rsp = await this.CreateZone(new CreateZoneNodeRequest()
            {
                serverGroupID  = req.servergroupID,
                serverID       = req.serverID,
                mapTemplateID  = temp.id,
                reason         = "LookingForAreaRequest dispatch",
                expandData     = RPGServerTemplateManager.Instance.GetCreateZoneExpandData(req),
                roomKey        = req.roomKey,
                expectAreaNode = req.roleSessionNode,
            });

            if (Response.CheckSuccess(rsp))
            {
                return(GetZone(rsp.zoneUUID));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public virtual async Task <ZoneInfo> LookingForExpectZone(RoleEnterZoneRequest req)
        {
            ZoneInfo zone = null;

            #region 返回上一个场景.

            //返回上一次的场景,如果没有统一返回上一次的公共场景.
            if (!string.IsNullOrEmpty(req.expectZoneUUID))
            {
                //根据提供的UUID寻找场景//
                zone = GetZone(req.expectZoneUUID);
                if (zone != null && !zone.close)
                {
                    if (zone.currentRoleCount < zone.map_data.max_players)
                    {
                        return(zone);
                    }
                }

                return(await LookingForPublicZone(req.lastPublicMapUUID, req.lastPublicMapID, req.lastPublicPos, req));
            }
            #endregion
            else
            {
                var temp = RPGServerTemplateManager.Instance.GetMapTemplate(req.expectMapTemplateID);
                if (temp == null)//场景不存在,往公共场景扔.
                {
                    return(await LookingForPublicZone(req.lastPublicMapUUID, req.lastPublicMapID, new ZonePosition(), req));
                }
                //优先判断公会场景//
                if (!string.IsNullOrEmpty(req.guildUUID))
                {
                    ZoneInfo guildZone = GetGuildZone(req.guildUUID);
                    if (guildZone != null && !guildZone.close)
                    {
                        if (guildZone.currentRoleCount < guildZone.map_data.max_players)
                        {
                            return(guildZone);
                        }
                        else//公会场景人数大于人数时候,不再能进入场景.
                        {
                            return(await LookingForPublicZone(req.lastPublicMapUUID, req.lastPublicMapID, req.lastPublicPos, req));
                        }
                    }
                    else //创建公会场景.
                    {
                        //新创建一个场景//
                        var rsp = await this.CreateZone(new CreateZoneNodeRequest()
                        {
                            serverID       = req.serverID,
                            serverGroupID  = req.servergroupID,
                            mapTemplateID  = req.expectMapTemplateID,
                            createRoleID   = req.roleUUID,
                            teamID         = req.teamID,
                            guildUUID      = req.guildUUID,
                            reason         = "LookingForAreaRequest dispatch",
                            expandData     = RPGServerTemplateManager.Instance.GetCreateZoneExpandData(req),
                            expectAreaNode = req.roleSessionNode,
                        });

                        if (Response.CheckSuccess(rsp))
                        {
                            return(GetZone(rsp.zoneUUID));
                        }
                        else
                        {
                            return(await LookingForPublicZone(req.lastPublicMapUUID, req.lastPublicMapID, req.lastPublicPos, req));
                        }
                    }
                }

                //ROOMKEY.
                if (!string.IsNullOrEmpty(req.roomKey))
                {
                    zone = GetRoomZone(req.roomKey);
                    if (zone != null && !zone.close)
                    {
                        return(zone);
                    }
                }

                //分配至队伍场景/
                if (req.teamID != null)
                {
                    zone = LookingForExpectServerGroupZone(req.servergroupID, z =>
                    {
                        return(z.currentRoleCount < temp.max_players &&
                               z.map_data.zone_template_id == req.expectMapTemplateID &&
                               z.ContainTeamID(req.teamID));
                    });
                    if (zone != null && !zone.close)
                    {
                        return(zone);
                    }
                }

                //根据EXPECT MAP来.
                if (RPGServerTemplateManager.Instance.IsPublicMap(temp))
                {
                    return(await LookingForPublicZone(null, req.expectMapTemplateID, req.roleScenePos, req));
                }
                else
                {
                    //新创建一个场景//
                    var rsp = await this.CreateZone(new CreateZoneNodeRequest()
                    {
                        serverID       = req.serverID,
                        serverGroupID  = req.servergroupID,
                        mapTemplateID  = temp.id,
                        createRoleID   = req.roleUUID,
                        teamID         = req.teamID,
                        reason         = "LookingForAreaRequest dispatch",
                        expandData     = RPGServerTemplateManager.Instance.GetCreateZoneExpandData(req),
                        roomKey        = req.roomKey,
                        expectAreaNode = req.roleSessionNode,
                    });

                    if (Response.CheckSuccess(rsp))
                    {
                        return(GetZone(rsp.zoneUUID));
                    }
                    else
                    {
                        return(await LookingForPublicZone(req.lastPublicMapUUID, req.lastPublicMapID, req.lastPublicPos, req));
                    }
                }
            }
        }
Exemplo n.º 4
0
 public virtual Task <RoleEnterZoneResponse> logic_rpc_Handle(RoleEnterZoneRequest req)
 {
     //log.Info(req);
     return(RoleEnter(req));
 }
Exemplo n.º 5
0
 public RoleInfo(string uuid, RoleEnterZoneRequest req)
 {
     this.uuid  = uuid;
     this.enter = req;
 }