Exemplo n.º 1
0
        protected MegaloScriptModel(Variants.GameEngineVariant variantManager, Variants.GameEngineMegaloVariant variant)
        {
            Database      = variantManager.MegaloProtoSystem.GetMegaloDatabaseAsync(variantManager.GameBuild).Result;
            MegaloVariant = variant;

            var db = Database;

            UnionGroups           = new Collections.ActiveList <MegaloScriptUnionGroup>(db.Limits.UnionGroupsDesc);
            Values                = new Collections.ActiveList <MegaloScriptValueBase>(db.Limits.ScriptValuesDesc);
            VirtualTriggers       = new Collections.ActiveList <MegaloScriptVirtualTrigger>(db.Limits.VirtualTriggersDesc);
            TriggerExecutionOrder = new ObservableCollection <int>();

            Conditions     = new Collections.ActiveList <MegaloScriptCondition>(db.Limits.ConditionsDesc);
            Actions        = new Collections.ActiveList <MegaloScriptAction>(db.Limits.ActionsDesc);
            Triggers       = new Collections.ActiveList <MegaloScriptTrigger>(db.Limits.TriggersDesc);
            GameStatistics = new ObservableCollection <MegaloScriptGameStatistic>();
            #region Variable Sets
            GlobalVariables = new MegaloScriptModelVariableSet(Database, MegaloScriptVariableSet.Globals);
            PlayerVariables = new MegaloScriptModelVariableSet(Database, MegaloScriptVariableSet.Player);
            ObjectVariables = new MegaloScriptModelVariableSet(Database, MegaloScriptVariableSet.Object);
            TeamVariables   = new MegaloScriptModelVariableSet(Database, MegaloScriptVariableSet.Team);
            #endregion
            HudWidgets = new ObservableCollection <MegaloScriptHudWidget>();
            #region Trigger entry points
            InitializationTriggerIndex           = LocalInitializationTriggerIndex =
                HostMigrationTriggerIndex        = DoubleHostMigrationTriggerIndex =
                    ObjectDeathEventTriggerIndex =
                        LocalTriggerIndex        = PregameTriggerIndex =
                            IncidentTriggerIndex =
                                TypeExtensions.kNone;
            #endregion
            ObjectTypeReferences = new Collections.BitSet(db.Limits.MultiplayerObjectTypes.MaxCount);
            ObjectFilters        = new ObservableCollection <MegaloScriptObjectFilter>();
            CandySpawnerFilters  = new ObservableCollection <MegaloScriptGameObjectFilter>();
        }
        void DecompileVariableNames(MegaloScriptModelVariableSet set)
        {
            string prefix = set.SetType != MegaloScriptVariableSet.Globals ? set.SetType.ToString() : "Global";
            var    custom_var_proto_type = Database.VariableRefTypes[MegaloScriptVariableReferenceType.Custom];
            var    sb = new System.Text.StringBuilder();

            for (int x = 0; x < set.Numerics.Count; x++, sb.Clear())
            {
                var variable = set.Numerics[x];
                var custom_var_proto_member = custom_var_proto_type.Members[variable.Var.Type];
                var value_type = custom_var_proto_member.ValueType;

                sb.Append(prefix);
                sb.Append("Numeric");

                if (value_type.BaseType == Proto.MegaloScriptValueBaseType.Index &&
                    value_type.IndexTarget == Proto.MegaloScriptValueIndexTarget.Option)
                {
                    var option = Variant.UserDefinedOptions[variable.Var.Data];
                    sb.Append(option.CodeName.Replace(" ", ""));
                }
                else
                {
                    sb.Append(x);
                }

                variable.CodeName = sb.ToString();
            }
            for (int x = 0; x < set.Timers.Count; x++, sb.Clear())
            {
                var variable = set.Timers[x];
                var custom_var_proto_member = custom_var_proto_type.Members[variable.Var.Type];
                var value_type = custom_var_proto_member.ValueType;

                sb.Append(prefix);
                sb.Append("Timer");

                if (value_type.BaseType == Proto.MegaloScriptValueBaseType.Index &&
                    value_type.IndexTarget == Proto.MegaloScriptValueIndexTarget.Option)
                {
                    var option = Variant.UserDefinedOptions[variable.Var.Data];
                    sb.Append(option.CodeName.Replace(" ", ""));
                }
                else
                {
                    sb.Append(x);
                }

                variable.CodeName = sb.ToString();
            }
            for (int x = 0; x < set.Teams.Count; x++, sb.Clear())
            {
                var variable = set.Teams[x];
                variable.CodeName = string.Format("{0}{1}{2}", prefix, "Team", x.ToString());
            }
            for (int x = 0; x < set.Players.Count; x++, sb.Clear())
            {
                var variable = set.Players[x];
                variable.CodeName = string.Format("{0}{1}{2}", prefix, "Player", x.ToString());
            }
            for (int x = 0; x < set.Objects.Count; x++, sb.Clear())
            {
                var variable = set.Objects[x];
                variable.CodeName = string.Format("{0}{1}{2}", prefix, "Object", x.ToString());
            }
        }