2024-01-23 17:54:53 +00:00
|
|
|
|
using RPG.GameCore.Excel;
|
|
|
|
|
using RPG.GameCore.Level;
|
|
|
|
|
using RPG.GameCore.Level.Floor;
|
|
|
|
|
using RPG.GameCore.Level.Group;
|
|
|
|
|
using RPG.GameCore.Level.Objects;
|
|
|
|
|
using RPG.Network.Proto;
|
|
|
|
|
using RPG.Services.Gameserver.Game.Entity;
|
|
|
|
|
using RPG.Services.Gameserver.Game.Entity.Factory;
|
|
|
|
|
using RPG.Services.Gameserver.Game.Team;
|
2024-01-25 10:55:10 +00:00
|
|
|
|
using RPG.Services.Gameserver.Game.Util;
|
2024-01-23 17:54:53 +00:00
|
|
|
|
using MazeInfo = RPG.Network.Proto.Maze;
|
|
|
|
|
|
|
|
|
|
namespace RPG.Services.Gameserver.Game.Maze;
|
|
|
|
|
|
|
|
|
|
internal class MazeManager
|
|
|
|
|
{
|
|
|
|
|
private readonly EntityFactory _entityFactory;
|
|
|
|
|
|
|
|
|
|
private readonly ExcelTables _excelTables;
|
|
|
|
|
private readonly LevelTables _levelTables;
|
|
|
|
|
|
|
|
|
|
private MapEntryRow? _mapEntry;
|
|
|
|
|
private LevelFloorInfo? _floor;
|
|
|
|
|
|
|
|
|
|
private PlayerTeam? _playerTeam;
|
|
|
|
|
private uint _uid;
|
|
|
|
|
|
2024-01-25 10:55:10 +00:00
|
|
|
|
public EntityManager EntityManager { get; }
|
|
|
|
|
|
2024-01-23 17:54:53 +00:00
|
|
|
|
public MazeManager(EntityManager entityManager, EntityFactory entityFactory, ExcelTables excelTables, LevelTables levelTables)
|
|
|
|
|
{
|
2024-01-25 10:55:10 +00:00
|
|
|
|
EntityManager = entityManager;
|
2024-01-23 17:54:53 +00:00
|
|
|
|
_entityFactory = entityFactory;
|
|
|
|
|
_excelTables = excelTables;
|
|
|
|
|
_levelTables = levelTables;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetAvatarPosition()
|
|
|
|
|
{
|
|
|
|
|
foreach (TeamMember? member in _playerTeam!.Members)
|
|
|
|
|
{
|
|
|
|
|
if (member == null) continue;
|
|
|
|
|
|
2024-01-25 10:55:10 +00:00
|
|
|
|
AvatarEntity? entity = EntityManager.GetAvatar(_uid, member.AvatarId);
|
2024-01-23 17:54:53 +00:00
|
|
|
|
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
entity.SetMotion(CreateInitialAvatarMotion());
|
2024-01-25 12:14:47 +00:00
|
|
|
|
EntityManager.NotifyMove(entity);
|
2024-01-23 17:54:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveEntities(IEnumerable<uint> entities)
|
|
|
|
|
{
|
2024-01-25 10:55:10 +00:00
|
|
|
|
EntityManager.RemoveEntities(entities);
|
2024-01-23 17:54:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetPlayerUid(uint uid)
|
|
|
|
|
{
|
|
|
|
|
_uid = uid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EnterMaze(uint entryId, PlayerTeam team)
|
|
|
|
|
{
|
|
|
|
|
BeforeEnter();
|
|
|
|
|
|
|
|
|
|
_playerTeam = team;
|
|
|
|
|
_mapEntry = _excelTables.GetExcelRow<MapEntryRow>(ExcelType.MapEntry, entryId)
|
|
|
|
|
?? throw new ArgumentException("EnterMaze: specified entryId doesn't exist!", nameof(entryId));
|
|
|
|
|
|
|
|
|
|
_floor = _levelTables.GetFloorInfo(_mapEntry.FloorID);
|
|
|
|
|
|
|
|
|
|
AddTeamMemberEntities();
|
|
|
|
|
InitLevelGroups();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MazeInfo Maze
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_mapEntry == null) throw new InvalidOperationException("GetMaze: maze not loaded!");
|
|
|
|
|
|
|
|
|
|
return new()
|
|
|
|
|
{
|
|
|
|
|
MapEntryId = _mapEntry.ID,
|
|
|
|
|
Id = _mapEntry.PlaneID,
|
|
|
|
|
Floor = new()
|
|
|
|
|
{
|
|
|
|
|
FloorId = _mapEntry.FloorID,
|
|
|
|
|
Scene = SceneInfo
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SceneInfo SceneInfo
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_mapEntry == null || _playerTeam == null) throw new InvalidOperationException("GetSceneInfo: scene not loaded!");
|
|
|
|
|
|
2024-01-25 10:55:10 +00:00
|
|
|
|
AvatarEntity? leaderEntity = EntityManager.GetAvatar(_uid, _playerTeam.Leader.AvatarId);
|
2024-01-23 17:54:53 +00:00
|
|
|
|
|
|
|
|
|
SceneInfo info = new()
|
|
|
|
|
{
|
|
|
|
|
EntryId = _mapEntry.ID,
|
|
|
|
|
PlaneId = _mapEntry.PlaneID,
|
|
|
|
|
FloorId = _mapEntry.FloorID,
|
|
|
|
|
LeaderEntityId = leaderEntity?.Id ?? 0,
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-25 10:55:10 +00:00
|
|
|
|
info.EntityList.AddRange(EntityManager.EntityInfoList);
|
2024-01-23 17:54:53 +00:00
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitLevelGroups()
|
|
|
|
|
{
|
|
|
|
|
foreach (LevelGroupInstanceInfo groupInstanceInfo in _floor!.GroupList)
|
|
|
|
|
{
|
|
|
|
|
LevelGroupInfo? levelGroup = _levelTables.GetGroupInfo(groupInstanceInfo.GroupGUID);
|
|
|
|
|
if (levelGroup == null) continue;
|
|
|
|
|
|
2024-01-25 13:28:53 +00:00
|
|
|
|
if (levelGroup.MonsterList != null)
|
2024-01-23 17:54:53 +00:00
|
|
|
|
{
|
2024-01-25 13:28:53 +00:00
|
|
|
|
foreach (LevelMonsterInfo levelMonster in levelGroup.MonsterList)
|
|
|
|
|
{
|
|
|
|
|
if (!levelMonster.CreateOnInitial) continue;
|
2024-01-23 17:54:53 +00:00
|
|
|
|
|
2024-01-25 13:28:53 +00:00
|
|
|
|
NpcMonsterEntity monsterEntity = _entityFactory.CreateNpcMonsterEntity(levelMonster, groupInstanceInfo.ID);
|
|
|
|
|
monsterEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelMonster));
|
2024-01-25 10:55:10 +00:00
|
|
|
|
|
2024-01-25 13:28:53 +00:00
|
|
|
|
EntityManager.AddEntity(monsterEntity);
|
|
|
|
|
}
|
2024-01-25 10:55:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-25 13:28:53 +00:00
|
|
|
|
if (levelGroup.PropList != null)
|
2024-01-25 10:55:10 +00:00
|
|
|
|
{
|
2024-01-25 13:28:53 +00:00
|
|
|
|
foreach (LevelPropInfo levelProp in levelGroup.PropList)
|
|
|
|
|
{
|
|
|
|
|
if (!levelProp.CreateOnInitial) continue;
|
2024-01-23 17:54:53 +00:00
|
|
|
|
|
2024-01-25 13:28:53 +00:00
|
|
|
|
PropEntity propEntity = _entityFactory.CreatePropEntity(levelProp, groupInstanceInfo.ID);
|
|
|
|
|
propEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelProp));
|
2024-01-25 10:55:10 +00:00
|
|
|
|
|
2024-01-25 13:28:53 +00:00
|
|
|
|
EntityManager.AddEntity(propEntity);
|
|
|
|
|
}
|
2024-01-23 17:54:53 +00:00
|
|
|
|
}
|
2024-01-25 11:31:32 +00:00
|
|
|
|
|
2024-01-25 13:28:53 +00:00
|
|
|
|
if (levelGroup.NPCList != null)
|
2024-01-25 11:31:32 +00:00
|
|
|
|
{
|
2024-01-25 13:28:53 +00:00
|
|
|
|
foreach (LevelNPCInfo levelNPC in levelGroup.NPCList)
|
|
|
|
|
{
|
|
|
|
|
if (!levelNPC.CreateOnInitial) continue;
|
2024-01-25 11:31:32 +00:00
|
|
|
|
|
2024-01-25 13:28:53 +00:00
|
|
|
|
NpcEntity npcEntity = _entityFactory.CreateNpcEntity(levelNPC, groupInstanceInfo.ID);
|
|
|
|
|
npcEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelNPC));
|
2024-01-25 11:31:32 +00:00
|
|
|
|
|
2024-01-25 13:28:53 +00:00
|
|
|
|
EntityManager.AddEntity(npcEntity);
|
|
|
|
|
}
|
2024-01-25 11:31:32 +00:00
|
|
|
|
}
|
2024-01-23 17:54:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddTeamMemberEntities()
|
|
|
|
|
{
|
|
|
|
|
foreach (TeamMember? member in _playerTeam!.Members)
|
|
|
|
|
{
|
|
|
|
|
if (member == null) continue;
|
|
|
|
|
|
|
|
|
|
AvatarEntity entity = _entityFactory.CreateAvatarEntity(member.AvatarId, member.AvatarType, _uid);
|
|
|
|
|
entity.SetMotion(CreateInitialAvatarMotion());
|
|
|
|
|
|
2024-01-25 10:55:10 +00:00
|
|
|
|
EntityManager.AddEntity(entity);
|
2024-01-23 17:54:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MotionInfo CreateInitialAvatarMotion()
|
|
|
|
|
{
|
|
|
|
|
LevelGroupInfo startGroup = _levelTables.GetGroupInfo(_floor!.StartGroup.GroupGUID)!;
|
2024-01-25 13:28:53 +00:00
|
|
|
|
LevelAnchorInfo startAnchor = startGroup.AnchorList!.First(anchor => anchor.ID == _floor.StartAnchorID);
|
2024-01-23 17:54:53 +00:00
|
|
|
|
|
2024-01-25 10:55:10 +00:00
|
|
|
|
return MazeUtil.CreateDefaultMotion(startAnchor);
|
2024-01-23 17:54:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BeforeEnter()
|
|
|
|
|
{
|
|
|
|
|
_entityFactory.Reset();
|
2024-01-25 10:55:10 +00:00
|
|
|
|
EntityManager.Clear();
|
2024-01-23 17:54:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|