|
@@ -17,15 +17,16 @@ namespace ET.Server
|
|
protected override void Awake(Map self, JObject opts, WNPlayer player)
|
|
protected override void Awake(Map self, JObject opts, WNPlayer player)
|
|
{
|
|
{
|
|
Log.Debug($"创建场景实体...create area opts:{opts.ToString()}");
|
|
Log.Debug($"创建场景实体...create area opts:{opts.ToString()}");
|
|
- self.createTime = TimeHelper.ServerNow();
|
|
|
|
|
|
+ self.CreateTime = TimeHelper.ServerNow();
|
|
self.LogicServerId = opts.SelectToken("logicServerId") != null? Convert.ToInt32(opts.SelectToken("logicServerId")) : 0;
|
|
self.LogicServerId = opts.SelectToken("logicServerId") != null? Convert.ToInt32(opts.SelectToken("logicServerId")) : 0;
|
|
self.MapId = Convert.ToInt32(opts.SelectToken("areaId"));
|
|
self.MapId = Convert.ToInt32(opts.SelectToken("areaId"));
|
|
self.Prop = MapConfigCategory.Instance.Get(self.MapId);
|
|
self.Prop = MapConfigCategory.Instance.Get(self.MapId);
|
|
self.Type = self.Prop.Type;
|
|
self.Type = self.Prop.Type;
|
|
- self.Player = player;
|
|
|
|
- self.UnitPlayers = new Dictionary<string, Struct.UnitPlayerData>();
|
|
|
|
|
|
+ self.HasPlayerEntered = false;
|
|
|
|
+ self.Actors = new Dictionary<long, Struct.Actor>();
|
|
self.DeadUnits = new List<int>();
|
|
self.DeadUnits = new List<int>();
|
|
self.DeadUnitPlayer = new List<int>();
|
|
self.DeadUnitPlayer = new List<int>();
|
|
|
|
+ self.IsLeaveKeepObject = false;
|
|
|
|
|
|
// 战斗服事件组件
|
|
// 战斗服事件组件
|
|
self.AddComponent<MapEventComponent>();
|
|
self.AddComponent<MapEventComponent>();
|
|
@@ -40,19 +41,6 @@ namespace ET.Server
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// 初始化场景数据
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="self"></param>
|
|
|
|
- public static void Reset(this Map self)
|
|
|
|
- {
|
|
|
|
- self.UnitPlayers.Clear();
|
|
|
|
- self.TotalLikeNum = 0;
|
|
|
|
- self.ConfigNum = 0;
|
|
|
|
- self.DeadUnits.Clear();
|
|
|
|
- self.DeadUnitPlayer.Clear();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public static ZoneManagerPrx GetZoneManager(this Map self)
|
|
public static ZoneManagerPrx GetZoneManager(this Map self)
|
|
{
|
|
{
|
|
return self.DomainScene().GetComponent<BattleIceAgentComponent>().IceZoneManager;
|
|
return self.DomainScene().GetComponent<BattleIceAgentComponent>().IceZoneManager;
|
|
@@ -92,17 +80,6 @@ namespace ET.Server
|
|
player.GetComponent<PlayerTempDataComponent>().SyncHistoryData(self.Prop, self.InstanceId, result);
|
|
player.GetComponent<PlayerTempDataComponent>().SyncHistoryData(self.Prop, self.InstanceId, result);
|
|
}
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// 获取场景角色
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="self"></param>
|
|
|
|
- /// <param name="playerId"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- public static WNPlayer GetPlayer(this Map self, long playerId)
|
|
|
|
- {
|
|
|
|
- return self.Player;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 分配阵营
|
|
/// 分配阵营
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -113,51 +90,6 @@ namespace ET.Server
|
|
player.Force = (int)AreaForce.FORCEA;
|
|
player.Force = (int)AreaForce.FORCEA;
|
|
}
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// 移除角色,通用框架接口 切换场景/掉线会自动调用,尽量 不要手动调用
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="self"></param>
|
|
|
|
- /// <param name="player"></param>
|
|
|
|
- /// <param name="keepObject"></param>
|
|
|
|
- public static void RemovePlayer(this Map self, WNPlayer player, bool keepObject)
|
|
|
|
- {
|
|
|
|
- Log.Info($"removePlayer: playerId={player.GetId()}, mapId={self.MapId}, ip={player.Session.RemoteAddress}");
|
|
|
|
- WNPlayer actorPlayer = self.GetPlayer(player.GetId());
|
|
|
|
- if (actorPlayer != null)
|
|
|
|
- {
|
|
|
|
- // self.Players.Remove(player.GetId());
|
|
|
|
- }
|
|
|
|
- // 重置进入场景标识
|
|
|
|
- player.GetComponent<PlayerTempDataComponent>().MapData.ready = false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 玩家进入场景请求
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="self"></param>
|
|
|
|
- /// <param name="player"></param>
|
|
|
|
- public static void PlayerEnterRequest(this Map self, WNPlayer player)
|
|
|
|
- {
|
|
|
|
- bool ready = player.GetComponent<PlayerTempDataComponent>().MapData.ready;
|
|
|
|
- if (ready)
|
|
|
|
- {
|
|
|
|
- Log.Info($"PlayerEnterRequest: playerId={player.GetId()}, ready={ready}");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- string enterData = player.ToJSON4EnterScene(self);
|
|
|
|
- Log.Debug($"{player.GetName()}, enterSceneData:{enterData}");
|
|
|
|
- self.GetZoneManager().playerEnterRequest(player.GetId().ToString().Trim(), self.Id.ToString().Trim(), enterData);
|
|
|
|
- }
|
|
|
|
- catch (Exception e)
|
|
|
|
- {
|
|
|
|
- Log.Warning(
|
|
|
|
- $"playerEnterRequest: playerName={player.GetName()}, instanceId={self.Id}, mapName={self.Prop.Name}, serverID={self.BattleServerId}, e={e}");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 场景添加角色
|
|
/// 场景添加角色
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -165,10 +97,15 @@ namespace ET.Server
|
|
/// <param name="player"></param>
|
|
/// <param name="player"></param>
|
|
public static void AddPlayer(this Map self, WNPlayer player)
|
|
public static void AddPlayer(this Map self, WNPlayer player)
|
|
{
|
|
{
|
|
- Log.Info($"addPlayer: playerId={player.GetId()}, mapId={self.MapId}, ip={player.Session.RemoteAddress}");
|
|
|
|
- player.Map = self;
|
|
|
|
|
|
+ Log.Info($"AddPlayer: playerId={player.GetId()}, mapId={self.MapId}, ip={player.Session.RemoteAddress}");
|
|
self.SetForce(player);
|
|
self.SetForce(player);
|
|
- self.Player = player;
|
|
|
|
|
|
+ player.Map = self;
|
|
|
|
+
|
|
|
|
+ if (!self.Actors.ContainsKey(player.GetId()))
|
|
|
|
+ {
|
|
|
|
+ self.HasPlayerEntered = true;
|
|
|
|
+ self.Actors.Add(player.GetId(), new Struct.Actor());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -186,8 +123,9 @@ namespace ET.Server
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="self"></param>
|
|
/// <param name="player"></param>
|
|
/// <param name="player"></param>
|
|
- public static void PlayerEntered(this Map self, WNPlayer player)
|
|
|
|
|
|
+ public static void OnPlayerEntered(this Map self, WNPlayer player)
|
|
{
|
|
{
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -195,28 +133,43 @@ namespace ET.Server
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="self"></param>
|
|
/// <param name="player"></param>
|
|
/// <param name="player"></param>
|
|
- public static void PlayerLogin(this Map self, WNPlayer player)
|
|
|
|
|
|
+ public static void OnPlayerLogin(this Map self, WNPlayer player)
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 玩家离开场景请求
|
|
|
|
|
|
+ /// 移除角色,通用框架接口 切换场景/掉线会自动调用,尽量 不要手动调用
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="self"></param>
|
|
/// <param name="player"></param>
|
|
/// <param name="player"></param>
|
|
/// <param name="keepObject"></param>
|
|
/// <param name="keepObject"></param>
|
|
- public static void PlayerLeaveRequest(this Map self, WNPlayer player, bool keepObject)
|
|
|
|
|
|
+ public static void RemovePlayer(this Map self, WNPlayer player, bool keepObject)
|
|
{
|
|
{
|
|
- try
|
|
|
|
|
|
+ Log.Info($"RemovePlayer: playerId={player.GetId()}, mapId={self.MapId}, ip={player.Session.RemoteAddress}");
|
|
|
|
+ // 重置进入场景标识
|
|
|
|
+ // player.GetComponent<PlayerTempDataComponent>().MapData.ready = false;
|
|
|
|
+
|
|
|
|
+ if (self.Actors.ContainsKey(player.GetId()))
|
|
{
|
|
{
|
|
- self.GetZoneManager().playerLeaveRequest(player.GetId().ToString().Trim(), self.InstanceId.ToString().Trim(), keepObject);
|
|
|
|
|
|
+ self.PlayerLeaveRequest(player, keepObject);
|
|
|
|
+ self.Actors.Remove(player.GetId());
|
|
}
|
|
}
|
|
- catch (Exception e)
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 玩家离线时触发
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="self"></param>
|
|
|
|
+ /// <param name="player"></param>
|
|
|
|
+ public static void OnPlayerLogout(this Map self, WNPlayer player)
|
|
|
|
+ {
|
|
|
|
+ if (self.Actors.ContainsKey(player.GetId()))
|
|
{
|
|
{
|
|
- Log.Warning($"playerLeaveRequest: catch - {e}");
|
|
|
|
|
|
+ // 本场景移除玩家
|
|
|
|
+ self.RemovePlayer(player, self.IsLeaveKeepObject);
|
|
}
|
|
}
|
|
-
|
|
|
|
- Log.Debug($"playerLeaveRequest--------------------{player.GetName()} - {self.InstanceId} - {self.Prop.Name}");
|
|
|
|
|
|
+ // 移除本地玩家数据
|
|
|
|
+ self.DomainScene().GetComponent<GamePlayerComponent>().Remove(player.GetId());
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -278,107 +231,58 @@ namespace ET.Server
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 战斗服结束场景
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="self"></param>
|
|
|
|
- public static void DestroyZoneRequest(this Map self)
|
|
|
|
- {
|
|
|
|
- self.GetZoneManager().destroyZoneRequest(self.Id.ToString());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 增加单位玩家本地数据
|
|
|
|
|
|
+ /// 玩家进入场景请求
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="self"></param>
|
|
- /// <param name="openId"></param>
|
|
|
|
- /// <param name="templateId"></param>
|
|
|
|
- /// <param name="force"></param>
|
|
|
|
- /// <param name="flag"></param>
|
|
|
|
- /// <param name="x"></param>
|
|
|
|
- /// <param name="y"></param>
|
|
|
|
- /// <param name="name"></param>
|
|
|
|
- /// <param name="url"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- public static async ETTask<Struct.UnitPlayerData> AddUnitPlayer(this Map self, string openId, int templateId, int force, string flag, float x, float y, string name, string url)
|
|
|
|
|
|
+ /// <param name="player"></param>
|
|
|
|
+ public static void PlayerEnterRequest(this Map self, WNPlayer player)
|
|
{
|
|
{
|
|
- if (templateId <= 0)
|
|
|
|
- {
|
|
|
|
- Log.Debug("illegal templateId @AddUnitPlayer");
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- if (self.UnitPlayers.ContainsKey(openId))
|
|
|
|
|
|
+ self.Actors.TryGetValue(player.GetId(), out Struct.Actor actor);
|
|
|
|
+ if (actor.Ready)
|
|
{
|
|
{
|
|
- Log.Debug("already contain unit @AddUnitPlayer");
|
|
|
|
- return null;
|
|
|
|
|
|
+ Log.Info($"PlayerEnterRequest: playerId={player.GetId()}, ready={actor.Ready}");
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
- // 战斗服数据
|
|
|
|
- Struct.MonsterUnit unit = new Struct.MonsterUnit();
|
|
|
|
- unit.id = templateId;
|
|
|
|
- unit.force = force;
|
|
|
|
- if (!string.IsNullOrEmpty(flag))
|
|
|
|
- {
|
|
|
|
- unit.flag = flag;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- unit.x = x;
|
|
|
|
- unit.y = y;
|
|
|
|
|
|
+ string enterData = player.ToJSON4EnterScene(self);
|
|
|
|
+ Log.Debug($"{player.GetName()}, EnterSceneData:{enterData}");
|
|
|
|
+ self.GetZoneManager().playerEnterRequest(player.GetId().ToString().Trim(), self.Id.ToString().Trim(), enterData);
|
|
}
|
|
}
|
|
- unit.autoGuard = true;
|
|
|
|
- unit.uuid = name;
|
|
|
|
- unit.alias = url;
|
|
|
|
-
|
|
|
|
- int objId = await self.AddUnits(unit, true);
|
|
|
|
- var unitPlayerData = new Struct.UnitPlayerData
|
|
|
|
- {
|
|
|
|
- OpenId = openId,
|
|
|
|
- TemplateId = templateId,
|
|
|
|
- ObjId = objId,
|
|
|
|
- Name = name,
|
|
|
|
- Url = url,
|
|
|
|
- Level = 1,
|
|
|
|
- Likes = 0,
|
|
|
|
- ReliveTime = 0,
|
|
|
|
- x = 0,
|
|
|
|
- y = 0,
|
|
|
|
- Map = self
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- if(!self.UnitPlayers.TryAdd(openId, unitPlayerData))
|
|
|
|
|
|
+ catch (Exception e)
|
|
{
|
|
{
|
|
- Log.Debug("openid already exist");
|
|
|
|
- await self.RemovePointUnit(objId);
|
|
|
|
- return null;
|
|
|
|
|
|
+ Log.Error($"PlayerEnterRequest: playerName={player.GetName()}, instanceId={self.Id}, mapName={self.Prop.Name}, serverID={self.BattleServerId}, e={e}");
|
|
}
|
|
}
|
|
- return unitPlayerData;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 获取单位玩家
|
|
|
|
|
|
+ /// 玩家离开场景请求
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="self"></param>
|
|
- /// <param name="openId"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- public static Struct.UnitPlayerData GetUnitPlayerByOpenId(this Map self, string openId)
|
|
|
|
|
|
+ /// <param name="player"></param>
|
|
|
|
+ /// <param name="keepObject"></param>
|
|
|
|
+ public static void PlayerLeaveRequest(this Map self, WNPlayer player, bool keepObject)
|
|
{
|
|
{
|
|
- if (self.UnitPlayers.TryGetValue(openId, out Struct.UnitPlayerData unitPlayer))
|
|
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- return unitPlayer;
|
|
|
|
|
|
+ self.GetZoneManager().playerLeaveRequest(player.GetId().ToString().Trim(), self.InstanceId.ToString(), keepObject);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ Log.Error($"PlayerLeaveRequest: 出错 - {e}");
|
|
}
|
|
}
|
|
|
|
|
|
- return null;
|
|
|
|
|
|
+ Log.Debug($"PlayerLeaveRequest--------------------{player.GetName()} - {self.InstanceId} - {self.Prop.Name}");
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 获取单位玩家
|
|
|
|
|
|
+ /// 战斗服结束场景
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="self"></param>
|
|
- /// <param name="objId"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- public static Struct.UnitPlayerData GetUnitPlayerByObjId(this Map self, int objId)
|
|
|
|
|
|
+ public static void DestroyZoneRequest(this Map self)
|
|
{
|
|
{
|
|
- return self.UnitPlayers.Values.FirstOrDefault(unitPlayer => unitPlayer != null && unitPlayer.ObjId == objId);
|
|
|
|
|
|
+ self.GetZoneManager().destroyZoneRequest(self.Id.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|