示例#1
0
        internal static Script Parse(BinaryReader reader, MapParseContext context)
        {
            return(ParseAsset(reader, context, version =>
            {
                if (version != 1 && version != 2)
                {
                    throw new InvalidDataException();
                }

                var name = reader.ReadUInt16PrefixedAsciiString();

                var comment = reader.ReadUInt16PrefixedAsciiString();
                var conditionsComment = reader.ReadUInt16PrefixedAsciiString();
                var actionsComment = reader.ReadUInt16PrefixedAsciiString();

                var isActive = reader.ReadBooleanChecked();
                var deactivateUponSuccess = reader.ReadBooleanChecked();

                var activeInEasy = reader.ReadBooleanChecked();
                var activeInMedium = reader.ReadBooleanChecked();
                var activeInHard = reader.ReadBooleanChecked();

                var isSubroutine = reader.ReadBooleanChecked();

                var evaluationInterval = 0u;
                if (version > 1)
                {
                    evaluationInterval = reader.ReadUInt32();
                }

                var orConditions = new List <ScriptOrCondition>();
                var actionsIfTrue = new List <ScriptAction>();
                var actionsIfFalse = new List <ScriptAction>();

                ParseAssets(reader, context, assetName =>
                {
                    switch (assetName)
                    {
                    case ScriptOrCondition.AssetName:
                        orConditions.Add(ScriptOrCondition.Parse(reader, context));
                        break;

                    case ScriptAction.AssetNameTrue:
                        actionsIfTrue.Add(ScriptAction.Parse(reader, context));
                        break;

                    case ScriptAction.AssetNameFalse:
                        actionsIfFalse.Add(ScriptAction.Parse(reader, context));
                        break;

                    default:
                        throw new InvalidDataException($"Unexpected asset: {assetName}");
                    }
                });

                return new Script
                {
                    Name = name,
                    Comment = comment,
                    ConditionsComment = conditionsComment,
                    ActionsComment = actionsComment,
                    IsActive = isActive,
                    DeactivateUponSuccess = deactivateUponSuccess,
                    ActiveInEasy = activeInEasy,
                    ActiveInMedium = activeInMedium,
                    ActiveInHard = activeInHard,
                    IsSubroutine = isSubroutine,
                    EvaluationInterval = evaluationInterval,

                    OrConditions = orConditions.ToArray(),
                    ActionsIfTrue = actionsIfTrue.ToArray(),
                    ActionsIfFalse = actionsIfFalse.ToArray()
                };
            }));
        }
示例#2
0
文件: Script.cs 项目: ybwsfl/OpenSAGE
        internal static Script Parse(BinaryReader reader, MapParseContext context)
        {
            return(ParseAsset(reader, context, version =>
            {
                var result = new Script
                {
                    Name = reader.ReadUInt16PrefixedAsciiString(),

                    Comment = reader.ReadUInt16PrefixedAsciiString(),
                    ConditionsComment = reader.ReadUInt16PrefixedAsciiString(),
                    ActionsComment = reader.ReadUInt16PrefixedAsciiString(),

                    IsActive = reader.ReadBooleanChecked(),
                    DeactivateUponSuccess = reader.ReadBooleanChecked(),

                    ActiveInEasy = reader.ReadBooleanChecked(),
                    ActiveInMedium = reader.ReadBooleanChecked(),
                    ActiveInHard = reader.ReadBooleanChecked(),

                    IsSubroutine = reader.ReadBooleanChecked()
                };

                if (version >= 2)
                {
                    result.EvaluationInterval = reader.ReadUInt32();

                    if (version == 5)
                    {
                        result.UsesEvaluationIntervalType = reader.ReadBooleanChecked();

                        result.EvaluationIntervalType = reader.ReadUInt32AsEnum <EvaluationIntervalType>();
                    }
                    else
                    {
                        result.EvaluationIntervalType = EvaluationIntervalType.FrameOrSeconds;
                    }
                }

                if (version >= 4)
                {
                    result.ActionsFireSequentially = reader.ReadBooleanChecked();

                    result.LoopActions = reader.ReadBooleanChecked();

                    result.LoopCount = reader.ReadInt32();

                    result.SequentialTargetType = reader.ReadByteAsEnum <SequentialScriptTarget>();

                    result.SequentialTargetName = reader.ReadUInt16PrefixedAsciiString();

                    result.Unknown = reader.ReadUInt16PrefixedAsciiString();
                    if (result.Unknown != "ALL" && result.Unknown != "Planning" && result.Unknown != "X")
                    {
                        throw new InvalidDataException();
                    }
                }

                if (version >= 6)
                {
                    result.Unknown2 = reader.ReadInt32();

                    result.Unknown3 = reader.ReadUInt16();
                    if (result.Unknown3 != 0)
                    {
                        throw new InvalidDataException();
                    }
                }

                var orConditions = new List <ScriptOrCondition>();
                var actionsIfTrue = new List <ScriptAction>();
                var actionsIfFalse = new List <ScriptAction>();

                ParseAssets(reader, context, assetName =>
                {
                    switch (assetName)
                    {
                    case ScriptOrCondition.AssetName:
                        orConditions.Add(ScriptOrCondition.Parse(reader, context));
                        break;

                    case ScriptAction.AssetNameTrue:
                        actionsIfTrue.Add(ScriptAction.Parse(reader, context));
                        break;

                    case ScriptAction.AssetNameFalse:
                        actionsIfFalse.Add(ScriptAction.Parse(reader, context));
                        break;

                    default:
                        throw new InvalidDataException($"Unexpected asset: {assetName}");
                    }
                });

                result.OrConditions = orConditions.ToArray();
                result.ActionsIfTrue = actionsIfTrue.ToArray();
                result.ActionsIfFalse = actionsIfFalse.ToArray();

                return result;
            }));
        }