mirror of
https://git.muiegratis.online/suikoakari/Campofinale
synced 2025-12-12 09:34:34 +01:00
levelscript saving
This commit is contained in:
@@ -30,6 +30,7 @@ namespace Campofinale.Game.MissionSys
|
||||
sync.TrackMissionId = curMission;
|
||||
missions.ForEach(m =>
|
||||
{
|
||||
if(!sync.Missions.ContainsKey(m.missionId))
|
||||
sync.Missions.Add(m.missionId, new Mission()
|
||||
{
|
||||
MissionId = m.missionId,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Campofinale.Game.Entities;
|
||||
using Campofinale.Game.Inventory;
|
||||
using Campofinale.Game.Spawners;
|
||||
using Campofinale.Packets.Sc;
|
||||
using Campofinale.Resource;
|
||||
using Campofinale.Resource.Dynamic;
|
||||
@@ -10,6 +9,7 @@ using System.Text.Json.Serialization;
|
||||
using static Campofinale.Resource.Dynamic.SpawnerConfig;
|
||||
using static Campofinale.Resource.ResourceManager;
|
||||
using static Campofinale.Resource.ResourceManager.LevelScene.LevelData;
|
||||
using static Campofinale.Resource.ResourceManager.LevelScene.LevelData.ParamKeyValue;
|
||||
using static System.Formats.Asn1.AsnWriter;
|
||||
|
||||
namespace Campofinale.Game
|
||||
@@ -247,7 +247,12 @@ namespace Campofinale.Game
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class LevelScript
|
||||
{
|
||||
public ulong scriptId;
|
||||
public int state;
|
||||
public Dictionary<string, ScriptProperty> properties = new();
|
||||
}
|
||||
public class Scene
|
||||
{
|
||||
public ulong ownerId;
|
||||
@@ -260,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)
|
||||
{
|
||||
if (collections.ContainsKey(id))
|
||||
@@ -381,12 +387,24 @@ namespace Campofinale.Game
|
||||
|
||||
GetOwner().Send(new PacketScObjectEnterView(GetOwner(), new List<Entity>() { en }));
|
||||
}
|
||||
public bool GetActiveScript(ulong id)
|
||||
{
|
||||
LevelScript script = scripts.Find(s => s.scriptId == id);
|
||||
if (script != null)
|
||||
{
|
||||
return script.state > 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public void UpdateShowEntities()
|
||||
{
|
||||
List<Entity> toSpawn = new();
|
||||
foreach(Entity e in GetEntityExcludingChar())
|
||||
{
|
||||
if(e.spawned==false && (activeScripts.Contains(e.belongLevelScriptId) || e.belongLevelScriptId==0))
|
||||
if(e.spawned==false && (GetActiveScript(e.belongLevelScriptId) || e.belongLevelScriptId==0))
|
||||
{
|
||||
if (!e.defaultHide)
|
||||
{
|
||||
|
||||
@@ -19,12 +19,16 @@ namespace Campofinale.Packets.Cs
|
||||
if (req.IsActive)
|
||||
{
|
||||
|
||||
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
||||
if (sceneScript != null)
|
||||
{
|
||||
sceneScript.state = 3;
|
||||
ScSceneLevelScriptStateNotify rsp = new ScSceneLevelScriptStateNotify()
|
||||
{
|
||||
SceneNumId = req.SceneNumId,
|
||||
ScriptId = req.ScriptId,
|
||||
|
||||
State = 3
|
||||
State = sceneScript.state
|
||||
};
|
||||
|
||||
if (!session.sceneManager.GetCurScene().activeScripts.Contains(req.ScriptId))
|
||||
@@ -33,6 +37,8 @@ namespace Campofinale.Packets.Cs
|
||||
session.sceneManager.GetCurScene().UpdateShowEntities();
|
||||
}
|
||||
session.Send(ScMsgId.ScSceneLevelScriptStateNotify, rsp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -64,17 +70,23 @@ namespace Campofinale.Packets.Cs
|
||||
|
||||
if (req.IsStart)
|
||||
{
|
||||
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
||||
if (sceneScript != null)
|
||||
{
|
||||
sceneScript.state = 4;
|
||||
ScSceneLevelScriptStateNotify rsp = new ScSceneLevelScriptStateNotify()
|
||||
{
|
||||
SceneNumId = req.SceneNumId,
|
||||
ScriptId = req.ScriptId,
|
||||
|
||||
State = 4
|
||||
State = sceneScript.state
|
||||
};
|
||||
|
||||
session.Send(ScMsgId.ScSceneLevelScriptStateNotify, rsp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -239,10 +251,14 @@ namespace Campofinale.Packets.Cs
|
||||
|
||||
};
|
||||
LevelScriptData levelscript= ResourceManager.GetLevelData(session.curSceneNumId).levelData.levelScripts.Find(l=>l.scriptId == req.ScriptId);
|
||||
if (levelscript != null) {
|
||||
var sceneScript = session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == req.ScriptId);
|
||||
|
||||
if (levelscript != null && sceneScript != null) {
|
||||
foreach (var item in req.Properties)
|
||||
{
|
||||
int key = levelscript.GetPropertyId(item.Key, new List<int>());
|
||||
|
||||
sceneScript.properties[item.Key] = new ScriptProperty(item.Value);
|
||||
update1.Properties.Add(key, item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,13 +70,29 @@ namespace Campofinale.Packets.Sc
|
||||
State = 2,
|
||||
|
||||
};
|
||||
var sceneScript=session.sceneManager.GetCurScene().scripts.Find(s => s.scriptId == l.scriptId);
|
||||
if (sceneScript == null)
|
||||
{
|
||||
sceneScript = new()
|
||||
{
|
||||
scriptId = l.scriptId,
|
||||
|
||||
state = 2
|
||||
};
|
||||
l.properties.ForEach(p =>
|
||||
{
|
||||
sceneScript.properties.Add(p.key,p.ToScriptProperty());
|
||||
});
|
||||
|
||||
session.sceneManager.GetCurScene().scripts.Add(sceneScript);
|
||||
}
|
||||
int i = 0;
|
||||
foreach (var item in l.properties)
|
||||
foreach (var item in sceneScript.properties)
|
||||
{
|
||||
|
||||
DynamicParameter p=item.ToProto();
|
||||
DynamicParameter p=item.Value.ToProto();
|
||||
if (p != null)
|
||||
script.Properties.Add(l.GetPropertyId(item.key,script.Properties.Keys.ToList()), p);
|
||||
script.Properties.Add(l.GetPropertyId(item.Key,script.Properties.Keys.ToList()), p);
|
||||
}
|
||||
sceneInfo.LevelScripts.Add(script);
|
||||
});
|
||||
|
||||
@@ -663,6 +663,42 @@ namespace Campofinale.Resource
|
||||
public List<ParamKeyValue> properties;
|
||||
public Dictionary<InteractiveComponentType, List<ParamKeyValue>> componentProperties = new();
|
||||
}
|
||||
public class ScriptProperty
|
||||
{
|
||||
public int RealType;
|
||||
public int ValueType;
|
||||
public List<string> ValueStringList = new();
|
||||
public List<float> ValueFloatList = new();
|
||||
public List<long> ValueIntList = new();
|
||||
public List<bool> ValueBoolList = new();
|
||||
|
||||
public ScriptProperty()
|
||||
{
|
||||
|
||||
}
|
||||
public ScriptProperty(DynamicParameter p)
|
||||
{
|
||||
this.RealType = p.RealType;
|
||||
this.ValueType = p.ValueType;
|
||||
this.ValueBoolList.AddRange(p.ValueBoolList.ToList());
|
||||
this.ValueFloatList.AddRange(p.ValueFloatList.ToList());
|
||||
this.ValueIntList.AddRange(p.ValueIntList.ToList());
|
||||
this.ValueStringList.AddRange(p.ValueStringList.ToList());
|
||||
}
|
||||
public DynamicParameter ToProto()
|
||||
{
|
||||
return new DynamicParameter()
|
||||
{
|
||||
RealType = RealType,
|
||||
ValueType = ValueType,
|
||||
ValueStringList = { ValueStringList },
|
||||
ValueBoolList = { ValueBoolList },
|
||||
ValueFloatList = { ValueFloatList },
|
||||
ValueIntList = { ValueIntList },
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
public class ParamKeyValue
|
||||
{
|
||||
public string key;
|
||||
@@ -753,6 +789,98 @@ namespace Campofinale.Resource
|
||||
return param;
|
||||
}
|
||||
|
||||
public ScriptProperty ToScriptProperty()
|
||||
{
|
||||
ScriptProperty param = new()
|
||||
{
|
||||
RealType = (int)value.type,
|
||||
ValueType = (int)value.type,
|
||||
|
||||
};
|
||||
foreach (var val in value.valueArray)
|
||||
{
|
||||
switch (value.type)
|
||||
{
|
||||
case ParamRealType.LangKey:
|
||||
param.ValueStringList.Add(val.valueString);
|
||||
param.ValueType = (int)ParamValueType.String;
|
||||
break;
|
||||
case ParamRealType.LangKeyList:
|
||||
param.ValueStringList.Add(val.valueString);
|
||||
param.ValueType = (int)ParamValueType.StringList;
|
||||
break;
|
||||
case ParamRealType.String:
|
||||
param.ValueStringList.Add(val.valueString);
|
||||
param.ValueType = (int)ParamValueType.String;
|
||||
break;
|
||||
case ParamRealType.StringList:
|
||||
param.ValueStringList.Add(val.valueString);
|
||||
param.ValueType = (int)ParamValueType.StringList;
|
||||
break;
|
||||
case ParamRealType.Vector3:
|
||||
param.ValueFloatList.Add(val.ToFloat());
|
||||
param.ValueType = (int)ParamValueType.FloatList;
|
||||
break;
|
||||
case ParamRealType.Float:
|
||||
param.ValueFloatList.Add(val.ToFloat());
|
||||
param.ValueType = (int)ParamValueType.Float;
|
||||
break;
|
||||
case ParamRealType.FloatList:
|
||||
param.ValueFloatList.Add(val.ToFloat());
|
||||
param.ValueType = (int)ParamValueType.FloatList;
|
||||
break;
|
||||
case ParamRealType.Int:
|
||||
param.ValueIntList.Add(val.valueBit64);
|
||||
param.ValueType = (int)ParamValueType.Int;
|
||||
break;
|
||||
case ParamRealType.IntList:
|
||||
param.ValueIntList.Add(val.valueBit64);
|
||||
param.ValueType = (int)ParamValueType.IntList;
|
||||
break;
|
||||
case ParamRealType.Bool:
|
||||
param.ValueBoolList.Add(val.valueBit64 == 1);
|
||||
param.ValueType = (int)ParamValueType.Bool;
|
||||
break;
|
||||
case ParamRealType.Vector3List:
|
||||
param.ValueFloatList.Add(val.ToFloat());
|
||||
param.ValueType = (int)ParamValueType.FloatList;
|
||||
break;
|
||||
case ParamRealType.BoolList:
|
||||
param.ValueBoolList.Add(val.valueBit64 == 1);
|
||||
param.ValueType = (int)ParamValueType.BoolList;
|
||||
break;
|
||||
case ParamRealType.EntityPtr:
|
||||
param.ValueIntList.Add(val.valueBit64);
|
||||
param.ValueType = (int)ParamValueType.Int;
|
||||
break;
|
||||
case ParamRealType.EntityPtrList:
|
||||
param.ValueIntList.Add(val.valueBit64);
|
||||
param.ValueType = (int)ParamValueType.Int;
|
||||
break;
|
||||
case ParamRealType.UInt64:
|
||||
param.ValueIntList.Add(val.valueBit64);
|
||||
param.ValueType = (int)ParamValueType.Int;
|
||||
break;
|
||||
case ParamRealType.WaterVolumePtr:
|
||||
param.ValueIntList.Add(val.valueBit64);
|
||||
param.ValueType = (int)ParamValueType.Int;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return param;
|
||||
}
|
||||
public void Update(DynamicParameter value)
|
||||
{
|
||||
foreach (var item in value.ValueBoolList)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class ParamValue
|
||||
{
|
||||
public ParamRealType type;
|
||||
|
||||
Reference in New Issue
Block a user