mirror of
https://git.muiegratis.online/suikoakari/Campofinale
synced 2025-12-12 17:44:37 +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
|
||||
{
|
||||
@@ -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 bool spawned = false;
|
||||
public bool defaultHide = false;
|
||||
public bool scriptSpawn = false;
|
||||
public Entity()
|
||||
{
|
||||
|
||||
|
||||
@@ -260,8 +260,6 @@ namespace Campofinale.Game
|
||||
public List<ulong> activeScripts = new();
|
||||
|
||||
public List<LevelScript> scripts = new();
|
||||
[BsonIgnore, JsonIgnore]
|
||||
private LevelFunctionRangeData currentAreaRange = new();
|
||||
public int GetCollection(string id)
|
||||
{
|
||||
if (collections.ContainsKey(id))
|
||||
@@ -293,6 +291,7 @@ namespace Campofinale.Game
|
||||
foreach(Entity e in GetEntityExcludingChar().FindAll(e => e.spawned))
|
||||
{
|
||||
guids.Add(e.guid);
|
||||
e.spawned = false;
|
||||
}
|
||||
entities.Clear();
|
||||
GetOwner().Send(new PacketScObjectLeaveView(GetOwner(), guids));
|
||||
@@ -388,35 +387,28 @@ namespace Campofinale.Game
|
||||
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
|
||||
public async void UpdateShowEntities()
|
||||
{
|
||||
UpdateArea();
|
||||
List<Entity> toSpawn = new();
|
||||
List<Entity> toCheck = GetEntityExcludingChar().FindAll(e => e.spawned == false);
|
||||
toCheck.Sort((a, b) => a.Position.Distance(GetOwner().position).CompareTo(b.Position.Distance(GetOwner().position)));
|
||||
foreach (Entity e in toCheck)
|
||||
{
|
||||
|
||||
if(e.spawned==false && (GetActiveScript(e.belongLevelScriptId) || e.belongLevelScriptId==0))
|
||||
if(e.Position.Distance(GetOwner().position) > 300 && sceneNumId != 87)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(e.spawned==false)
|
||||
{
|
||||
if(currentAreaRange.IsObjectInside(e.Position) || sceneNumId==87)
|
||||
if (!e.defaultHide)
|
||||
{
|
||||
toSpawn.Add(e);
|
||||
e.spawned = true;
|
||||
if (GetActiveScript(e.belongLevelScriptId))
|
||||
{
|
||||
toSpawn.Add(e);
|
||||
e.spawned = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -432,18 +424,6 @@ namespace Campofinale.Game
|
||||
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()
|
||||
@@ -469,7 +449,6 @@ namespace Campofinale.Game
|
||||
type = en.entityType,
|
||||
belongLevelScriptId = en.belongLevelScriptId,
|
||||
levelLogicId = en.levelLogicId,
|
||||
scriptSpawn = scriptSpawn
|
||||
};
|
||||
entities.Add(entity);
|
||||
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)
|
||||
{
|
||||
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 (sceneScript != null)
|
||||
if (req.IsActive)
|
||||
{
|
||||
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
|
||||
{
|
||||
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
||||
if (sceneScript != null)
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
CsSceneSetLevelScriptStart req = packet.DecodeBody<CsSceneSetLevelScriptStart>();
|
||||
|
||||
if (req.IsStart)
|
||||
LevelScriptData data = ResourceManager.GetLevelData(session.curSceneNumId).levelData.levelScripts.Find(s => s.scriptId == req.ScriptId);
|
||||
if(data!=null)
|
||||
if (data.refGameId != null && session.currentDungeon != null)
|
||||
{
|
||||
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
||||
if (sceneScript != null)
|
||||
if (session.currentDungeon.table.dungeonId != data.refGameId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
||||
if (sceneScript != null)
|
||||
{
|
||||
|
||||
|
||||
if (req.IsStart)
|
||||
{
|
||||
sceneScript.state = 4;
|
||||
ScSceneLevelScriptStateNotify rsp = new ScSceneLevelScriptStateNotify()
|
||||
{
|
||||
SceneNumId = req.SceneNumId,
|
||||
ScriptId = req.ScriptId,
|
||||
|
||||
State = sceneScript.state
|
||||
};
|
||||
|
||||
session.Send(ScMsgId.ScSceneLevelScriptStateNotify, rsp);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
||||
if (sceneScript != null)
|
||||
else
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -678,30 +678,13 @@ namespace Campofinale
|
||||
table = ResourceManager.dungeonTable[dungeonId],
|
||||
};
|
||||
this.currentDungeon = dungeon;
|
||||
ScEnterDungeon enter = new()
|
||||
{
|
||||
DungeonId = dungeonId,
|
||||
SceneId = dungeon.table.sceneId,
|
||||
|
||||
};
|
||||
|
||||
Send(new PacketScSyncAllUnlock(this));
|
||||
|
||||
EnterScene(GetSceneNumIdFromLevelData(dungeon.table.sceneId));
|
||||
Send(ScMsgId.ScEnterDungeon, enter);
|
||||
|
||||
dungeon.Enter();
|
||||
}
|
||||
|
||||
public void LeaveDungeon(CsLeaveDungeon req)
|
||||
{
|
||||
ScLeaveDungeon rsp = new()
|
||||
{
|
||||
DungeonId = req.DungeonId,
|
||||
};
|
||||
Send(ScMsgId.ScLeaveDungeon, rsp);
|
||||
Dungeon dungeon = currentDungeon;
|
||||
currentDungeon = null;
|
||||
EnterScene(dungeon.prevPlayerSceneNumId, dungeon.prevPlayerPos, dungeon.prevPlayerRot);
|
||||
if(currentDungeon!=null)
|
||||
currentDungeon.Leave();
|
||||
}
|
||||
|
||||
public string GetCurrentChapter()
|
||||
|
||||
@@ -601,6 +601,7 @@ namespace Campofinale.Resource
|
||||
public class LevelScriptData
|
||||
{
|
||||
public ulong scriptId;
|
||||
public string refGameId;
|
||||
public List<ParamKeyValue> properties = new();
|
||||
public Dictionary<int, string> propertyIdToKeyMap = new();
|
||||
public ScriptActionMap actionMap = new();
|
||||
|
||||
Reference in New Issue
Block a user