Exemple #1
0
        private static NgTriggerSubtypes ReadNgTriggerSubtypes(XmlNode parentNode, string postfix = null)
        {
            var result = new NgTriggerSubtypes();

            foreach (XmlNode timerNode in parentNode.ChildNodes)
            {
                var key            = ushort.Parse(timerNode.Attributes["K"].Value, CultureInfo.InvariantCulture);
                var value          = timerNode.Attributes["V"].Value + ((postfix != null) ? (" (" + postfix + key.ToString() + ")") : string.Empty);
                var triggerSubtype = new NgTriggerSubtype(key, value);

                foreach (XmlNode nodeList in timerNode.ChildNodes)
                {
                    switch (nodeList.Name)
                    {
                    case "Target":
                        triggerSubtype.Target = ReadNgParameterRange(nodeList.ChildNodes[0]);
                        break;

                    case "Extra":
                        triggerSubtype.Extra = ReadNgParameterRange(nodeList.ChildNodes[0]);
                        break;

                    case "Timer":
                        triggerSubtype.Timer = ReadNgParameterRange(nodeList.ChildNodes[0]);
                        break;
                    }
                }

                result.MainList.Add(triggerSubtype.Key, triggerSubtype);
            }
            return(result);
        }
Exemple #2
0
        public static NgParameterRange GetTimerRange(LevelSettings levelSettings, TriggerType triggerType, TriggerTargetType targetType, ITriggerParameter target)
        {
            switch (triggerType)
            {
            case TriggerType.ConditionNg:
                return(new NgParameterRange(NgCatalog.ConditionTrigger.MainList.DicSelect(e => (TriggerParameterUshort)e.Value)));

            default:
                switch (targetType)
                {
                case TriggerTargetType.FlipEffect:
                    if (!(target is TriggerParameterUshort))
                    {
                        return(new NgParameterRange(NgParameterKind.Empty));
                    }
                    NgTriggerSubtype flipEffectSubtriggerType = NgCatalog.FlipEffectTrigger.MainList.TryGetOrDefault(((TriggerParameterUshort)target).Key);
                    return(flipEffectSubtriggerType?.Timer ?? new NgParameterRange(NgParameterKind.Empty));

                case TriggerTargetType.ActionNg:
                    return(new NgParameterRange(NgCatalog.ActionTrigger.MainList.DicSelect(e => (TriggerParameterUshort)e.Value)));

                case TriggerTargetType.TimerfieldNg:
                    return(new NgParameterRange(NgParameterKind.Empty));

                default:
                    return(new NgParameterRange(NgParameterKind.AnyNumber));
                }
            }
        }
Exemple #3
0
        public static ushort EncodeNGRealTimer(TriggerTargetType targetType, TriggerType triggerType, ushort target, ushort upperBound, BoundedValueCallback timer, BoundedValueCallback extra)
        {
            ushort timerUpperBound = (ushort)(upperBound & 255);
            ushort extraUpperBound = (ushort)(upperBound >> 8);

            switch (triggerType)
            {
            case TriggerType.ConditionNg:
                // Bit 8 is one shot in trigger setup so we must shift by 9
                return((ushort)(timer(timerUpperBound) | (extra(extraUpperBound) << 9)));

            default:
                switch (targetType)
                {
                case TriggerTargetType.ActionNg:
                    return((ushort)(timer(timerUpperBound) | (extra(extraUpperBound) << 8)));

                case TriggerTargetType.TimerfieldNg:
                    return(timer(upperBound));

                case TriggerTargetType.FlipEffect:
                    NgTriggerSubtype flipEffectSubtriggerType = NgCatalog.FlipEffectTrigger.MainList.TryGetOrDefault(target);
                    if (flipEffectSubtriggerType != null && flipEffectSubtriggerType.Extra.IsEmpty)
                    {
                        return(timer(upperBound));
                    }
                    else
                    {
                        return((ushort)(timer(timerUpperBound) | (extra(extraUpperBound) << 8)));
                    }

                default:
                    return(timer(upperBound));
                }
            }
        }
Exemple #4
0
        public static NgParameterRange GetExtraRange(LevelSettings levelSettings, TriggerType triggerType, TriggerTargetType targetType, ITriggerParameter target, ITriggerParameter timer)
        {
            switch (triggerType)
            {
            case TriggerType.ConditionNg:
                if (!(timer is TriggerParameterUshort))
                {
                    return(new NgParameterRange(NgParameterKind.Empty));
                }
                NgTriggerSubtype conditionSubtriggerType = NgCatalog.ConditionTrigger.MainList.TryGetOrDefault(((TriggerParameterUshort)timer).Key);
                return(conditionSubtriggerType?.Extra ?? new NgParameterRange(NgParameterKind.Empty));

            default:
                switch (targetType)
                {
                case TriggerTargetType.FlipEffect:
                    if (!(target is TriggerParameterUshort))
                    {
                        return(new NgParameterRange(NgParameterKind.Empty));
                    }
                    NgTriggerSubtype flipEffectSubtriggerType = NgCatalog.FlipEffectTrigger.MainList.TryGetOrDefault(((TriggerParameterUshort)target).Key);
                    return(flipEffectSubtriggerType?.Extra ?? new NgParameterRange(NgParameterKind.Empty));

                case TriggerTargetType.ActionNg:
                    if (!(timer is TriggerParameterUshort))
                    {
                        return(new NgParameterRange(NgParameterKind.Empty));
                    }
                    NgTriggerSubtype actionSubtriggerType = NgCatalog.ActionTrigger.MainList.TryGetOrDefault(((TriggerParameterUshort)timer).Key);
                    return(actionSubtriggerType?.Extra ?? new NgParameterRange(NgParameterKind.Empty));

                default:
                    return(new NgParameterRange(NgParameterKind.Empty));
                }
            }
        }
Exemple #5
0
        public static string ExportToScriptTrigger(Level level, TriggerInstance trigger, bool withComment = false)
        {
            checked
            {
                string result = null;

                switch (trigger.TriggerType)
                {
                case TriggerType.ConditionNg:
                {
                    if (!TriggerIsValid(level.Settings, trigger))
                    {
                        throw new Exception("Trigger is invalid.");
                    }

                    ushort           conditionId      = GetValue(level, trigger.Timer);
                    NgTriggerSubtype conditionTrigger = NgCatalog.ConditionTrigger.MainList[conditionId];

                    ushort firstValue  = GetValue(level, trigger.Target);
                    ushort secondValue = conditionId;
                    if (!conditionTrigger.Extra.IsEmpty)
                    {
                        secondValue |= (ushort)(GetValue(level, trigger.Extra) << 8);
                    }

                    result  = trigger.Target is ObjectInstance ? "$9000," : "$8000,";
                    result += firstValue + ",$" + secondValue.ToString("X4");
                    break;
                }

                default:
                    switch (trigger.TargetType)
                    {
                    case TriggerTargetType.FlipEffect:
                    {
                        if (!TriggerIsValid(level.Settings, trigger))
                        {
                            throw new Exception("Trigger is invalid.");
                        }

                        ushort           flipeffectId      = GetValue(level, trigger.Target);
                        NgTriggerSubtype flipeffectTrigger = NgCatalog.FlipEffectTrigger.MainList[flipeffectId];

                        ushort firstValue  = flipeffectId;
                        ushort secondValue = GetValue(level, trigger.Timer);
                        if (!flipeffectTrigger.Extra.IsEmpty)
                        {
                            secondValue |= (ushort)(GetValue(level, trigger.Extra) << 8);
                        }

                        result = "$2000," + firstValue + ",$" + secondValue.ToString("X4");
                        break;
                    }

                    case TriggerTargetType.ActionNg:
                    {
                        if (!TriggerIsValid(level.Settings, trigger))
                        {
                            throw new Exception("Trigger is invalid.");
                        }

                        ushort           actionId      = GetValue(level, trigger.Timer);
                        NgTriggerSubtype actionTrigger = NgCatalog.ActionTrigger.MainList[actionId];

                        ushort firstValue  = GetValue(level, trigger.Target);
                        ushort secondValue = actionId;
                        if (!actionTrigger.Extra.IsEmpty)
                        {
                            secondValue |= (ushort)(GetValue(level, trigger.Extra) << 8);
                        }

                        result  = trigger.Target is StaticInstance ? "$4000," : "$5000,";
                        result += firstValue + ",$" + secondValue.ToString("X4");
                        break;
                    }
                    }
                    break;
                }

                if (!string.IsNullOrEmpty(result))
                {
                    return((withComment ?
                            "; " + trigger.TriggerType + " for " + trigger.TargetType +
                            "\n; <#> " + trigger.Target +
                            "\n; <&> " + trigger.Timer +
                            (trigger.Extra == null ? "" : "\n; <E> " + trigger.Extra) +
                            "\n; Copy following values to your script:" +
                            "\n; "
                        : "")
                           + result);
                }
            }
            throw new ExceptionScriptNotSupported();
        }
Exemple #6
0
        public static NgParameterRange GetTargetRange(LevelSettings levelSettings, TriggerType triggerType, TriggerTargetType targetType, ITriggerParameter timer)
        {
            switch (triggerType)
            {
            case TriggerType.ConditionNg:
                if (!(timer is TriggerParameterUshort))
                {
                    return(new NgParameterRange(NgParameterKind.Empty));
                }
                NgTriggerSubtype conditionSubtriggerType = NgCatalog.ConditionTrigger.MainList.TryGetOrDefault(((TriggerParameterUshort)timer).Key);
                return(conditionSubtriggerType?.Target ?? new NgParameterRange(NgParameterKind.Empty));

            default:
                switch (targetType)
                {
                case TriggerTargetType.Object:
                    return(new NgParameterRange(NgParameterKind.MoveablesInLevel));

                case TriggerTargetType.Camera:
                    return(new NgParameterRange(NgParameterKind.CamerasInLevel));

                case TriggerTargetType.Sink:
                    return(new NgParameterRange(NgParameterKind.SinksInLevel));

                case TriggerTargetType.Target:
                    // Actually it is possible to not only target Target objects, but all movables.
                    // This is also useful: It makes sense to target egg a trap or an enemy.
                    return(new NgParameterRange(NgParameterKind.MoveablesInLevel));

                case TriggerTargetType.FlyByCamera:
                    return(new NgParameterRange(NgParameterKind.FlybyCamerasInLevel));

                case TriggerTargetType.FlipEffect:
                    if (levelSettings.GameVersion == TRVersion.Game.TRNG)
                    {
                        return(new NgParameterRange(NgCatalog.FlipEffectTrigger.MainList.DicSelect(e => (TriggerParameterUshort)e.Value)));
                    }
                    else if (levelSettings.GameVersion == TRVersion.Game.TR4)
                    {
                        return(new NgParameterRange(NgCatalog.FlipEffectTrigger.MainList
                                                    .DicWhere(entry => entry.Value.Name.Contains("OldFlip"))
                                                    .DicSelect(e => (TriggerParameterUshort)e.Value)));
                    }
                    else
                    {
                        return(new NgParameterRange(NgParameterKind.AnyNumber));
                    }

                case TriggerTargetType.ActionNg:
                    if (!(timer is TriggerParameterUshort))
                    {
                        return(new NgParameterRange(NgParameterKind.Empty));
                    }
                    NgTriggerSubtype actionSubtriggerType = NgCatalog.ActionTrigger.MainList.TryGetOrDefault(((TriggerParameterUshort)timer).Key);
                    return(actionSubtriggerType?.Target ?? new NgParameterRange(NgParameterKind.Empty));

                case TriggerTargetType.TimerfieldNg:
                    return(NgCatalog.TimerFieldTrigger);

                default:
                    return(new NgParameterRange(NgParameterKind.AnyNumber));
                }
            }
        }