12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- 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)
- {
- 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 || request.X < 0 || request.Y < 0)
- {
- Log.Debug($"参数错误...unitId={request.UnitId}, force={request.Force}");
- response.Error = ErrorCode.ERR_ParameterError;
- reply();
- return;
- }
- // 配置是否能找到
- Monster prop = MonsterCategory.Instance.Get(request.UnitId);
- if (prop == null)
- {
- Log.Debug($"添加单位出错, 未找到配置...unitId={request.UnitId}, playerId={player.GetId()}");
- response.Error = ErrorCode.ERR_ConfigError;
- reply();
- return;
- }
- Struct.MonsterUnit unit = new Struct.MonsterUnit();
- unit.id = prop.Id;
- 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);
- reply();
- }
- }
- }
|