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;
|
|
|
|
|
|
|
|
|
|
foreach (LevelMonsterInfo levelMonster in levelGroup.MonsterList)
|
|
|
|
|
{
|
|
|
|
|
if (!levelMonster.CreateOnInitial) continue;
|
|
|
|
|
|
|
|
|
|
NpcMonsterEntity monsterEntity = _entityFactory.CreateNpcMonsterEntity(levelMonster, groupInstanceInfo.ID);
|
2024-01-25 10:55:10 +00:00
|
|
|
|
monsterEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelMonster));
|
|
|
|
|
|
|
|
|
|
EntityManager.AddEntity(monsterEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (LevelPropInfo levelProp in levelGroup.PropList)
|
|
|
|
|
{
|
|
|
|
|
if (!levelProp.CreateOnInitial) continue;
|
2024-01-23 17:54:53 +00:00
|
|
|
|
|
2024-01-25 10:55:10 +00:00
|
|
|
|
PropEntity propEntity = _entityFactory.CreatePropEntity(levelProp, groupInstanceInfo.ID);
|
|
|
|
|
propEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelProp));
|
|
|
|
|
|
|
|
|
|
EntityManager.AddEntity(propEntity);
|
2024-01-23 17:54:53 +00:00
|
|
|
|
}
|
2024-01-25 11:31:32 +00:00
|
|
|
|
|
|
|
|
|
foreach (LevelNPCInfo levelNPC in levelGroup.NPCList)
|
|
|
|
|
{
|
|
|
|
|
if (!levelNPC.CreateOnInitial) continue;
|
|
|
|
|
|
|
|
|
|
NpcEntity npcEntity = _entityFactory.CreateNpcEntity(levelNPC, groupInstanceInfo.ID);
|
|
|
|
|
npcEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelNPC));
|
|
|
|
|
|
|
|
|
|
EntityManager.AddEntity(npcEntity);
|
|
|
|
|
}
|
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)!;
|
|
|
|
|
LevelAnchorInfo startAnchor = startGroup.AnchorList.First(anchor => anchor.ID == _floor.StartAnchorID);
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|