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;
[BsonIgnore, JsonIgnore]
public List<ulong> activeScripts = new();
public List<LevelScript> scripts = new();
public int GetCollection(string id)
{
@@ -294,7 +295,7 @@ namespace Campofinale.Game
public void Unload()
{
List<ulong> guids = new();
foreach(Entity e in entities)
foreach(Entity e in GetEntityExcludingChar().FindAll(e => e.spawned))
{
guids.Add(e.guid);
}
@@ -307,8 +308,6 @@ namespace Campofinale.Game
}
public void Load()
{
if (info().isSeamless && alreadyLoaded) return;
//alreadyLoaded = true;
Unload();
LevelScene lv_scene = ResourceManager.GetLevelData(sceneNumId);
@@ -362,7 +361,7 @@ namespace Campofinale.Game
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)
{
belongLevelScriptId = en.belongLevelScriptId,
@@ -375,9 +374,9 @@ namespace Campofinale.Game
});
UpdateShowEntities();
}
public void SpawnEntity(Entity en,bool spawnedCheck=true)
@@ -399,10 +398,12 @@ namespace Campofinale.Game
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();
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))
{
@@ -416,7 +417,15 @@ namespace Campofinale.Game
}
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())
{

View File

@@ -47,10 +47,14 @@
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)
{
await Task.Run(() =>
{
if (s_notifyReqGroup.TryGetValue(cmdId, out var handler))
{
handler.Item2.Invoke(session, ((int)cmdId), packet);
}
else
@@ -58,6 +62,8 @@
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)

View File

@@ -18,11 +18,7 @@ namespace Campofinale.Packets.Cs
session.sceneManager.LoadCurrentTeamEntities();
session.sceneManager.LoadCurrent();
session.LoadFinish = true;
session.Send(ScMsgId.ScSceneClientIdInfo, new ScSceneClientIdInfo()
{
RoleIdx = (uint)session.roleId,
LastMaxIdx = session.random.usedGuids.Max()
});
if (session.curSceneNumId == 98)
{
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)
{
CsSceneMoveStateSet req = packet.DecodeBody<CsSceneMoveStateSet>();
//req.
}

View File

@@ -14,6 +14,15 @@ namespace Campofinale.Packets.Cs
if (session.curSceneNumId != req.SceneNumId)
{
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
{

View File

@@ -81,19 +81,24 @@ namespace Campofinale.Packets.Sc
};
l.properties.ForEach(p =>
{
if(!sceneScript.properties.ContainsKey(p.key))
sceneScript.properties.Add(p.key,p.ToScriptProperty());
});
session.sceneManager.GetCurScene().scripts.Add(sceneScript);
}
script.State = sceneScript.state;
int i = 0;
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);
}
}
sceneInfo.LevelScripts.Add(script);
});
SetData(ScMsgId.ScSelfSceneInfo, sceneInfo);

View File

@@ -436,7 +436,7 @@ namespace Campofinale
{
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();
int maxChunkSize = 65535;
@@ -463,11 +463,11 @@ namespace Campofinale
Send(Packet.EncodePacket(packet.cmdId, data, seqNext, (uint)chunks.Count, (uint)i));
}
}
public void Send(byte[] data)
public async void Send(byte[] data)
{
try
{
socket.Send(data);
await socket.SendAsync(data);
}
catch (Exception e)
{