12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System;
- namespace ET.Server
- {
- /// <summary>
- /// 向场景增加玩家
- /// </summary>
- [MessageHandler(SceneType.Game)]
- public class C2G_AddUnitsToMapHandler: AMRpcHandler<C2G_AddUnitsToMap, G2C_AddUnitsToMap>
- {
- protected override async ETTask Run(Session session, C2G_AddUnitsToMap request, G2C_AddUnitsToMap response, Action reply)
- {
- if (session.DomainScene().SceneType != SceneType.Game)
- {
- Log.Debug($"Game 请求的Scene错误...SceneType={session.DomainScene().SceneType}");
- session.Dispose();
- return;
- }
- // 移除session自动超时组件
- session.RemoveComponent<SessionAcceptTimeoutComponent>();
- WNPlayer player = session.GetComponent<SessionPlayerComponent>().GetMyPlayer();
- if (player == null)
- {
- Log.Debug($"操作错误, player is null");
- response.Error = ErrorCode.ERR_OperationError;
- reply();
- return;
- }
- // 参数判断
- if (request.UnitId <= 0 || request.Force < 0 || request.Force > (int)AreaForce.FORCEB )
- {
- Log.Debug($"参数错误...unitId={request.UnitId}, force={request.Force}");
- response.Error = ErrorCode.ERR_ParameterError;
- reply();
- return;
- }
- // Struct.MonsterUnit unit = new Struct.MonsterUnit();
- // unit.id = request.UnitId;
- // unit.force = request.Force;
- // if (!string.IsNullOrEmpty(request.Flag))
- // {
- // unit.flag = request.Flag;
- // }
- // else
- // {
- // unit.x = request.X;
- // unit.y = request.Y;
- // }
- // unit.autoGuard = true;
- //
- // await player.Map.AddUnits(unit, false);
- // 预先创建数据
- Scene scene = session.DomainScene();
- long _id = IdGenerater.Instance.GenerateUnitId(scene.DomainZone());
- PlayerInfo playerInfo = new PlayerInfo();
- playerInfo.Id = _id;
- playerInfo.UserId = session.GetComponent<SessionPlayerComponent>().UserId;
- playerInfo.PlayerType = 1;
- playerInfo.Name = "玩家-" + _id;
- playerInfo.Sex = 0;
- playerInfo.Pro = (int)PlayerProType.CANG_LANG;
- playerInfo.Level = 1;
- playerInfo.Exp = 0;
- WNPlayer unitPlayer = await PlayerFactory.CreatPlayer(session, playerInfo);
- if (unitPlayer == null)
- {
- Log.Debug($"创建单位玩家有误...unitPlayerId={_id}, force={request.Force}");
- response.Error = ErrorCode.ERR_CreateUnitPlayerError;
- reply();
- return;
- }
- // 进入主播场景
- player.Map.PlayerEnterRequest(unitPlayer);
- reply();
- }
- }
- }
|