mirror of
https://git.muiegratis.online/suikoakari/Campofinale
synced 2025-12-13 18:14:34 +01:00
some changes
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
using static Campofinale.Resource.ResourceManager;
|
using Campofinale.Packets.Sc;
|
||||||
|
using Campofinale.Protocol;
|
||||||
|
using static Campofinale.Resource.ResourceManager;
|
||||||
|
|
||||||
namespace Campofinale.Game.Dungeons
|
namespace Campofinale.Game.Dungeons
|
||||||
{
|
{
|
||||||
@@ -13,5 +15,34 @@ namespace Campofinale.Game.Dungeons
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Enter()
|
||||||
|
{
|
||||||
|
player.sceneManager.GetScene(GetSceneNumIdFromLevelData(table.sceneId)).activeScripts.Clear();
|
||||||
|
player.sceneManager.GetScene(GetSceneNumIdFromLevelData(table.sceneId)).scripts.ForEach(script =>
|
||||||
|
{
|
||||||
|
script.state = 1;
|
||||||
|
});
|
||||||
|
ScEnterDungeon enter = new()
|
||||||
|
{
|
||||||
|
DungeonId = table.dungeonId,
|
||||||
|
SceneId = table.sceneId,
|
||||||
|
};
|
||||||
|
player.Send(new PacketScSyncAllUnlock(player));
|
||||||
|
|
||||||
|
player.EnterScene(GetSceneNumIdFromLevelData(table.sceneId));
|
||||||
|
player.Send(ScMsgId.ScEnterDungeon, enter);
|
||||||
|
}
|
||||||
|
public void Leave()
|
||||||
|
{
|
||||||
|
ScLeaveDungeon rsp = new()
|
||||||
|
{
|
||||||
|
DungeonId = table.dungeonId,
|
||||||
|
};
|
||||||
|
player.Send(new PacketScSyncAllUnlock(player));
|
||||||
|
player.currentDungeon = null;
|
||||||
|
player.EnterScene(prevPlayerSceneNumId, prevPlayerPos, prevPlayerRot);
|
||||||
|
player.Send(ScMsgId.ScLeaveDungeon, rsp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ namespace Campofinale.Game.Entities
|
|||||||
public int sceneNumId;
|
public int sceneNumId;
|
||||||
public bool spawned = false;
|
public bool spawned = false;
|
||||||
public bool defaultHide = false;
|
public bool defaultHide = false;
|
||||||
public bool scriptSpawn = false;
|
|
||||||
public Entity()
|
public Entity()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -260,8 +260,6 @@ namespace Campofinale.Game
|
|||||||
public List<ulong> activeScripts = new();
|
public List<ulong> activeScripts = new();
|
||||||
|
|
||||||
public List<LevelScript> scripts = new();
|
public List<LevelScript> scripts = new();
|
||||||
[BsonIgnore, JsonIgnore]
|
|
||||||
private LevelFunctionRangeData currentAreaRange = new();
|
|
||||||
public int GetCollection(string id)
|
public int GetCollection(string id)
|
||||||
{
|
{
|
||||||
if (collections.ContainsKey(id))
|
if (collections.ContainsKey(id))
|
||||||
@@ -293,6 +291,7 @@ namespace Campofinale.Game
|
|||||||
foreach(Entity e in GetEntityExcludingChar().FindAll(e => e.spawned))
|
foreach(Entity e in GetEntityExcludingChar().FindAll(e => e.spawned))
|
||||||
{
|
{
|
||||||
guids.Add(e.guid);
|
guids.Add(e.guid);
|
||||||
|
e.spawned = false;
|
||||||
}
|
}
|
||||||
entities.Clear();
|
entities.Clear();
|
||||||
GetOwner().Send(new PacketScObjectLeaveView(GetOwner(), guids));
|
GetOwner().Send(new PacketScObjectLeaveView(GetOwner(), guids));
|
||||||
@@ -388,35 +387,28 @@ namespace Campofinale.Game
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateArea()
|
|
||||||
{
|
|
||||||
LevelScene lv_scene = ResourceManager.GetLevelData(sceneNumId);
|
|
||||||
lv_scene.levelData.functionArea.ranges.ForEach(range =>
|
|
||||||
{
|
|
||||||
if (range.IsObjectInside(GetOwner().position))
|
|
||||||
{
|
|
||||||
currentAreaRange=range;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//Bug on scene 101: spawning entities in this way make the game break if you try to load another scene from scene 101
|
//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()
|
public async void UpdateShowEntities()
|
||||||
{
|
{
|
||||||
UpdateArea();
|
|
||||||
List<Entity> toSpawn = new();
|
List<Entity> toSpawn = new();
|
||||||
List<Entity> toCheck = GetEntityExcludingChar().FindAll(e => e.spawned == false);
|
List<Entity> toCheck = GetEntityExcludingChar().FindAll(e => e.spawned == false);
|
||||||
toCheck.Sort((a, b) => a.Position.Distance(GetOwner().position).CompareTo(b.Position.Distance(GetOwner().position)));
|
toCheck.Sort((a, b) => a.Position.Distance(GetOwner().position).CompareTo(b.Position.Distance(GetOwner().position)));
|
||||||
foreach (Entity e in toCheck)
|
foreach (Entity e in toCheck)
|
||||||
{
|
{
|
||||||
|
if(e.Position.Distance(GetOwner().position) > 300 && sceneNumId != 87)
|
||||||
if(e.spawned==false && (GetActiveScript(e.belongLevelScriptId) || e.belongLevelScriptId==0))
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(e.spawned==false)
|
||||||
{
|
{
|
||||||
if(currentAreaRange.IsObjectInside(e.Position) || sceneNumId==87)
|
|
||||||
if (!e.defaultHide)
|
if (!e.defaultHide)
|
||||||
{
|
{
|
||||||
toSpawn.Add(e);
|
if (GetActiveScript(e.belongLevelScriptId))
|
||||||
e.spawned = true;
|
{
|
||||||
|
toSpawn.Add(e);
|
||||||
|
e.spawned = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -432,18 +424,6 @@ namespace Campofinale.Game
|
|||||||
GetOwner().Send(new PacketScObjectEnterView(GetOwner(), chunk));
|
GetOwner().Send(new PacketScObjectEnterView(GetOwner(), chunk));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<ulong> toDespawn=new();
|
|
||||||
foreach(Entity en in GetEntityExcludingChar().FindAll(e=> e.spawned==true))
|
|
||||||
{
|
|
||||||
if (!currentAreaRange.IsObjectInside(en.Position) && en.scriptSpawn==false && sceneNumId != 87)
|
|
||||||
{
|
|
||||||
toDespawn.Add(en.guid);
|
|
||||||
en.spawned = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if(toDespawn.Count > 0)
|
|
||||||
GetOwner().Send(new PacketScObjectLeaveView(GetOwner(), toDespawn));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player GetOwner()
|
public Player GetOwner()
|
||||||
@@ -469,7 +449,6 @@ namespace Campofinale.Game
|
|||||||
type = en.entityType,
|
type = en.entityType,
|
||||||
belongLevelScriptId = en.belongLevelScriptId,
|
belongLevelScriptId = en.belongLevelScriptId,
|
||||||
levelLogicId = en.levelLogicId,
|
levelLogicId = en.levelLogicId,
|
||||||
scriptSpawn = scriptSpawn
|
|
||||||
};
|
};
|
||||||
entities.Add(entity);
|
entities.Add(entity);
|
||||||
Logger.Print($"Enemy Id {v} found on scene {sceneNumId}:{lv_scene.mapIdStr}");
|
Logger.Print($"Enemy Id {v} found on scene {sceneNumId}:{lv_scene.mapIdStr}");
|
||||||
|
|||||||
@@ -16,51 +16,44 @@ namespace Campofinale.Packets.Cs
|
|||||||
public static void Handle(Player session, CsMsgId cmdId, Packet packet)
|
public static void Handle(Player session, CsMsgId cmdId, Packet packet)
|
||||||
{
|
{
|
||||||
CsSceneSetLevelScriptActive req = packet.DecodeBody<CsSceneSetLevelScriptActive>();
|
CsSceneSetLevelScriptActive req = packet.DecodeBody<CsSceneSetLevelScriptActive>();
|
||||||
if (req.IsActive)
|
LevelScriptData data = ResourceManager.GetLevelData(session.curSceneNumId).levelData.levelScripts.Find(s=>s.scriptId==req.ScriptId);
|
||||||
|
if (data != null)
|
||||||
|
if (data.refGameId != null && session.currentDungeon != null)
|
||||||
|
{
|
||||||
|
if (session.currentDungeon.table.dungeonId != data.refGameId)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
||||||
|
|
||||||
|
if (sceneScript != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
if (req.IsActive)
|
||||||
if (sceneScript != null)
|
|
||||||
{
|
{
|
||||||
sceneScript.state = 3;
|
sceneScript.state = 3;
|
||||||
ScSceneLevelScriptStateNotify rsp = new ScSceneLevelScriptStateNotify()
|
|
||||||
{
|
|
||||||
SceneNumId = req.SceneNumId,
|
|
||||||
ScriptId = req.ScriptId,
|
|
||||||
|
|
||||||
State = sceneScript.state
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!session.sceneManager.GetCurScene().activeScripts.Contains(req.ScriptId))
|
|
||||||
{
|
|
||||||
session.sceneManager.GetCurScene().activeScripts.Add(req.ScriptId);
|
|
||||||
session.sceneManager.GetCurScene().UpdateShowEntities();
|
|
||||||
}
|
|
||||||
session.Send(ScMsgId.ScSceneLevelScriptStateNotify, rsp);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
|
||||||
if (sceneScript != null)
|
|
||||||
{
|
{
|
||||||
sceneScript.state = 2;
|
sceneScript.state = 2;
|
||||||
ScSceneLevelScriptStateNotify rsp = new ScSceneLevelScriptStateNotify()
|
|
||||||
{
|
|
||||||
SceneNumId = req.SceneNumId,
|
|
||||||
ScriptId = req.ScriptId,
|
|
||||||
|
|
||||||
State = sceneScript.state
|
|
||||||
};
|
|
||||||
|
|
||||||
session.sceneManager.GetCurScene().UpdateShowEntities();
|
|
||||||
session.Send(ScMsgId.ScSceneLevelScriptStateNotify, rsp);
|
|
||||||
}
|
}
|
||||||
|
ScSceneLevelScriptStateNotify rsp = new ScSceneLevelScriptStateNotify()
|
||||||
|
{
|
||||||
|
SceneNumId = req.SceneNumId,
|
||||||
|
ScriptId = req.ScriptId,
|
||||||
|
|
||||||
|
State = sceneScript.state
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!session.sceneManager.GetCurScene().activeScripts.Contains(req.ScriptId))
|
||||||
|
{
|
||||||
|
session.sceneManager.GetCurScene().activeScripts.Add(req.ScriptId);
|
||||||
|
session.sceneManager.GetCurScene().UpdateShowEntities();
|
||||||
|
}
|
||||||
|
session.Send(ScMsgId.ScSceneLevelScriptStateNotify, rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,45 +61,40 @@ namespace Campofinale.Packets.Cs
|
|||||||
public static void HandleCsSceneSetLevelScriptStart(Player session, CsMsgId cmdId, Packet packet)
|
public static void HandleCsSceneSetLevelScriptStart(Player session, CsMsgId cmdId, Packet packet)
|
||||||
{
|
{
|
||||||
CsSceneSetLevelScriptStart req = packet.DecodeBody<CsSceneSetLevelScriptStart>();
|
CsSceneSetLevelScriptStart req = packet.DecodeBody<CsSceneSetLevelScriptStart>();
|
||||||
|
LevelScriptData data = ResourceManager.GetLevelData(session.curSceneNumId).levelData.levelScripts.Find(s => s.scriptId == req.ScriptId);
|
||||||
if (req.IsStart)
|
if(data!=null)
|
||||||
|
if (data.refGameId != null && session.currentDungeon != null)
|
||||||
{
|
{
|
||||||
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
if (session.currentDungeon.table.dungeonId != data.refGameId)
|
||||||
if (sceneScript != null)
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
||||||
|
if (sceneScript != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if (req.IsStart)
|
||||||
{
|
{
|
||||||
sceneScript.state = 4;
|
sceneScript.state = 4;
|
||||||
ScSceneLevelScriptStateNotify rsp = new ScSceneLevelScriptStateNotify()
|
|
||||||
{
|
|
||||||
SceneNumId = req.SceneNumId,
|
|
||||||
ScriptId = req.ScriptId,
|
|
||||||
|
|
||||||
State = sceneScript.state
|
|
||||||
};
|
|
||||||
|
|
||||||
session.Send(ScMsgId.ScSceneLevelScriptStateNotify, rsp);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
|
||||||
if (sceneScript != null)
|
|
||||||
{
|
{
|
||||||
sceneScript.state = 3;
|
sceneScript.state = 3;
|
||||||
ScSceneLevelScriptStateNotify rsp = new ScSceneLevelScriptStateNotify()
|
|
||||||
{
|
|
||||||
SceneNumId = req.SceneNumId,
|
|
||||||
ScriptId = req.ScriptId,
|
|
||||||
|
|
||||||
State = sceneScript.state
|
|
||||||
};
|
|
||||||
|
|
||||||
session.Send(ScMsgId.ScSceneLevelScriptStateNotify, rsp);
|
|
||||||
}
|
}
|
||||||
|
ScSceneLevelScriptStateNotify rsp = new ScSceneLevelScriptStateNotify()
|
||||||
|
{
|
||||||
|
SceneNumId = req.SceneNumId,
|
||||||
|
ScriptId = req.ScriptId,
|
||||||
|
|
||||||
|
State = sceneScript.state
|
||||||
|
};
|
||||||
|
session.Send(ScMsgId.ScSceneLevelScriptStateNotify, rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ExecuteEventAction(Player player, ScriptAction action, CsSceneLevelScriptEventTrigger req)
|
public static void ExecuteEventAction(Player player, ScriptAction action, CsSceneLevelScriptEventTrigger req)
|
||||||
|
|||||||
@@ -678,30 +678,13 @@ namespace Campofinale
|
|||||||
table = ResourceManager.dungeonTable[dungeonId],
|
table = ResourceManager.dungeonTable[dungeonId],
|
||||||
};
|
};
|
||||||
this.currentDungeon = dungeon;
|
this.currentDungeon = dungeon;
|
||||||
ScEnterDungeon enter = new()
|
dungeon.Enter();
|
||||||
{
|
|
||||||
DungeonId = dungeonId,
|
|
||||||
SceneId = dungeon.table.sceneId,
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Send(new PacketScSyncAllUnlock(this));
|
|
||||||
|
|
||||||
EnterScene(GetSceneNumIdFromLevelData(dungeon.table.sceneId));
|
|
||||||
Send(ScMsgId.ScEnterDungeon, enter);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LeaveDungeon(CsLeaveDungeon req)
|
public void LeaveDungeon(CsLeaveDungeon req)
|
||||||
{
|
{
|
||||||
ScLeaveDungeon rsp = new()
|
if(currentDungeon!=null)
|
||||||
{
|
currentDungeon.Leave();
|
||||||
DungeonId = req.DungeonId,
|
|
||||||
};
|
|
||||||
Send(ScMsgId.ScLeaveDungeon, rsp);
|
|
||||||
Dungeon dungeon = currentDungeon;
|
|
||||||
currentDungeon = null;
|
|
||||||
EnterScene(dungeon.prevPlayerSceneNumId, dungeon.prevPlayerPos, dungeon.prevPlayerRot);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCurrentChapter()
|
public string GetCurrentChapter()
|
||||||
|
|||||||
@@ -601,6 +601,7 @@ namespace Campofinale.Resource
|
|||||||
public class LevelScriptData
|
public class LevelScriptData
|
||||||
{
|
{
|
||||||
public ulong scriptId;
|
public ulong scriptId;
|
||||||
|
public string refGameId;
|
||||||
public List<ParamKeyValue> properties = new();
|
public List<ParamKeyValue> properties = new();
|
||||||
public Dictionary<int, string> propertyIdToKeyMap = new();
|
public Dictionary<int, string> propertyIdToKeyMap = new();
|
||||||
public ScriptActionMap actionMap = new();
|
public ScriptActionMap actionMap = new();
|
||||||
|
|||||||
Reference in New Issue
Block a user