This commit is contained in:
AlessandroCH
2025-06-04 14:31:56 +02:00
parent 864f4307c8
commit 723b81d5e4
7 changed files with 58 additions and 34 deletions

View File

@@ -265,6 +265,7 @@ namespace Campofinale.Game
public bool alreadyLoaded = false; public bool alreadyLoaded = false;
[BsonIgnore, JsonIgnore] [BsonIgnore, JsonIgnore]
public List<ulong> activeScripts = new(); public List<ulong> activeScripts = new();
public List<LevelScript> scripts = new(); public List<LevelScript> scripts = new();
public int GetCollection(string id) public int GetCollection(string id)
{ {
@@ -294,7 +295,7 @@ namespace Campofinale.Game
public void Unload() public void Unload()
{ {
List<ulong> guids = new(); List<ulong> guids = new();
foreach(Entity e in entities) foreach(Entity e in GetEntityExcludingChar().FindAll(e => e.spawned))
{ {
guids.Add(e.guid); guids.Add(e.guid);
} }
@@ -307,8 +308,6 @@ namespace Campofinale.Game
} }
public void Load() public void Load()
{ {
if (info().isSeamless && alreadyLoaded) return;
//alreadyLoaded = true;
Unload(); Unload();
LevelScene lv_scene = ResourceManager.GetLevelData(sceneNumId); LevelScene lv_scene = ResourceManager.GetLevelData(sceneNumId);
@@ -362,7 +361,7 @@ namespace Campofinale.Game
lv_scene.levelData.npcs.ForEach(en => lv_scene.levelData.npcs.ForEach(en =>
{ {
if (en.npcGroupId.Contains("chr")) return; if (en.npcGroupId.Contains("chr") && sceneNumId == 98) return;
EntityNpc entity = new(en.entityDataIdKey,ownerId,en.position,en.rotation, sceneNumId, en.levelLogicId) EntityNpc entity = new(en.entityDataIdKey,ownerId,en.position,en.rotation, sceneNumId, en.levelLogicId)
{ {
belongLevelScriptId = en.belongLevelScriptId, belongLevelScriptId = en.belongLevelScriptId,
@@ -373,11 +372,11 @@ namespace Campofinale.Game
entity.defaultHide = en.defaultHide; entity.defaultHide = en.defaultHide;
entities.Add(entity); entities.Add(entity);
}); });
UpdateShowEntities();
UpdateShowEntities();
} }
public void SpawnEntity(Entity en,bool spawnedCheck=true) public void SpawnEntity(Entity en,bool spawnedCheck=true)
@@ -399,10 +398,12 @@ namespace Campofinale.Game
return true; return true;
} }
} }
public void UpdateShowEntities() //Bug on scene 101: spawning entities in this way make the game break if you try to load another scene from scene 101
public async void UpdateShowEntities()
{ {
List<Entity> toSpawn = new(); List<Entity> toSpawn = new();
foreach(Entity e in GetEntityExcludingChar()) foreach(Entity e in GetEntityExcludingChar().FindAll(e=>e.spawned==false))
{ {
if(e.spawned==false && (GetActiveScript(e.belongLevelScriptId) || e.belongLevelScriptId==0)) if(e.spawned==false && (GetActiveScript(e.belongLevelScriptId) || e.belongLevelScriptId==0))
{ {
@@ -415,9 +416,17 @@ namespace Campofinale.Game
} }
} }
if(toSpawn.Count > 0) if (toSpawn.Count > 0)
GetOwner().Send(new PacketScObjectEnterView(GetOwner(), toSpawn)); {
for (int i = 0; i < toSpawn.Count; i += 5)
{
int chunkSize = Math.Min(5, toSpawn.Count - i);
var chunk = toSpawn.GetRange(i, chunkSize);
GetOwner().Send(new PacketScObjectEnterView(GetOwner(), chunk));
}
}
/* foreach(Entity en in GetEntityExcludingChar()) /* foreach(Entity en in GetEntityExcludingChar())
{ {
float minDis = 100; float minDis = 100;

View File

@@ -47,17 +47,23 @@
s_notifyReqGroup = handlers.ToImmutable(); s_notifyReqGroup = handlers.ToImmutable();
} }
public static void Notify(Player session, CsMsgId cmdId, Network.Packet packet) public static async void Notify(Player session, CsMsgId cmdId, Network.Packet packet)
{ {
if (s_notifyReqGroup.TryGetValue(cmdId, out var handler)) await Task.Run(() =>
{ {
handler.Item2.Invoke(session, ((int)cmdId), packet);
} if (s_notifyReqGroup.TryGetValue(cmdId, out var handler))
else {
{
if (!Server.csMessageToHide.Contains(cmdId) && Server.config.logOptions.packets) handler.Item2.Invoke(session, ((int)cmdId), packet);
Logger.PrintWarn($"Can't find handler for {(Enum.GetName(typeof(CsMsgId), cmdId)).ToString().Pastel(Color.FromArgb(165, 229, 250))} ({(cmdId).ToString().Pastel(Color.FromArgb(165, 229, 250))})"); }
} else
{
if (!Server.csMessageToHide.Contains(cmdId) && Server.config.logOptions.packets)
Logger.PrintWarn($"Can't find handler for {(Enum.GetName(typeof(CsMsgId), cmdId)).ToString().Pastel(Color.FromArgb(165, 229, 250))} ({(cmdId).ToString().Pastel(Color.FromArgb(165, 229, 250))})");
}
});
} }
public static void AddReqGroupHandler(Type type) public static void AddReqGroupHandler(Type type)

View File

@@ -18,11 +18,7 @@ namespace Campofinale.Packets.Cs
session.sceneManager.LoadCurrentTeamEntities(); session.sceneManager.LoadCurrentTeamEntities();
session.sceneManager.LoadCurrent(); session.sceneManager.LoadCurrent();
session.LoadFinish = true; session.LoadFinish = true;
session.Send(ScMsgId.ScSceneClientIdInfo, new ScSceneClientIdInfo()
{
RoleIdx = (uint)session.roleId,
LastMaxIdx = session.random.usedGuids.Max()
});
if (session.curSceneNumId == 98) if (session.curSceneNumId == 98)
{ {
session.Send(new PacketScSyncGameMode(session, "spaceship")); session.Send(new PacketScSyncGameMode(session, "spaceship"));

View File

@@ -10,7 +10,6 @@ namespace Campofinale.Packets.Cs
public static void Handle(Player session, CsMsgId cmdId, Packet packet) public static void Handle(Player session, CsMsgId cmdId, Packet packet)
{ {
CsSceneMoveStateSet req = packet.DecodeBody<CsSceneMoveStateSet>(); CsSceneMoveStateSet req = packet.DecodeBody<CsSceneMoveStateSet>();
//req. //req.
} }

View File

@@ -14,6 +14,15 @@ namespace Campofinale.Packets.Cs
if (session.curSceneNumId != req.SceneNumId) if (session.curSceneNumId != req.SceneNumId)
{ {
session.EnterScene(req.SceneNumId, new Resource.ResourceManager.Vector3f(req.Position), new Resource.ResourceManager.Vector3f(req.Rotation)); session.EnterScene(req.SceneNumId, new Resource.ResourceManager.Vector3f(req.Position), new Resource.ResourceManager.Vector3f(req.Rotation));
/* ScSceneTeleport t = new()
{
TeleportReason = req.TeleportReason,
PassThroughData = req.PassThroughData,
Position = req.Position,
Rotation = req.Rotation,
SceneNumId = req.SceneNumId,
};
session.Send(ScMsgId.ScSceneTeleport, t);*/
} }
else else
{ {

View File

@@ -81,18 +81,23 @@ namespace Campofinale.Packets.Sc
}; };
l.properties.ForEach(p => l.properties.ForEach(p =>
{ {
if(!sceneScript.properties.ContainsKey(p.key))
sceneScript.properties.Add(p.key,p.ToScriptProperty()); sceneScript.properties.Add(p.key,p.ToScriptProperty());
}); });
session.sceneManager.GetCurScene().scripts.Add(sceneScript); session.sceneManager.GetCurScene().scripts.Add(sceneScript);
} }
script.State = sceneScript.state;
int i = 0; int i = 0;
foreach (var item in sceneScript.properties) foreach (var item in sceneScript.properties)
{ {
if(item.Value != null)
{
DynamicParameter p = item.Value.ToProto();
if (p != null)
script.Properties.Add(l.GetPropertyId(item.Key, script.Properties.Keys.ToList()), p);
}
DynamicParameter p=item.Value.ToProto();
if (p != null)
script.Properties.Add(l.GetPropertyId(item.Key,script.Properties.Keys.ToList()), p);
} }
sceneInfo.LevelScripts.Add(script); sceneInfo.LevelScripts.Add(script);
}); });

View File

@@ -436,7 +436,7 @@ namespace Campofinale
{ {
Send(Packet.EncodePacket((int)id, mes, seq, totalPackCount, currentPackIndex)); Send(Packet.EncodePacket((int)id, mes, seq, totalPackCount, currentPackIndex));
} }
public void Send(Packet packet) public async void Send(Packet packet)
{ {
byte[] datas = packet.set_body.ToByteArray(); byte[] datas = packet.set_body.ToByteArray();
int maxChunkSize = 65535; int maxChunkSize = 65535;
@@ -463,11 +463,11 @@ namespace Campofinale
Send(Packet.EncodePacket(packet.cmdId, data, seqNext, (uint)chunks.Count, (uint)i)); Send(Packet.EncodePacket(packet.cmdId, data, seqNext, (uint)chunks.Count, (uint)i));
} }
} }
public void Send(byte[] data) public async void Send(byte[] data)
{ {
try try
{ {
socket.Send(data); await socket.SendAsync(data);
} }
catch (Exception e) catch (Exception e)
{ {