Esempio n. 1
0
        public string FillString(string text, List <Profile> p)
        {
            if (p != null)
            {
                if (p.Count > 0)
                {
                    text = text.Replace("%NAME%", p[0].name);
                }
                if (p.Count > 1)
                {
                    text = text.Replace("%NAME2%", p[1].name);
                }
                if (p.Count > 2)
                {
                    text = text.Replace("%NAME3%", p[2].name);
                }
                if (p.Count > 3)
                {
                    text = text.Replace("%NAME4%", p[3].name);
                }
            }
            text = text.Replace("%PRICE%", Main.GetPriceString());
            if (this.valueCalculation != null)
            {
                object result = this.valueCalculation.result;
                switch (result)
                {
                case float _:
                case int _:
                    float single = Change.ToSingle(result);
                    text = text.Replace("%VALUE%", Change.ToString((object)single));
                    int int32 = Convert.ToInt32(result);
                    text = text.Replace("%INTVALUE%", Change.ToString((object)int32));
                    break;

                case string _:
                    text = text.Replace("%VALUE%", result as string);
                    break;
                }
            }
            if (this.valueCalculation2 != null)
            {
                object result = this.valueCalculation2.result;
                switch (result)
                {
                case float _:
                case int _:
                    float single = Change.ToSingle(result);
                    text = text.Replace("%VALUE2%", Change.ToString((object)single));
                    int int32 = Convert.ToInt32(result);
                    text = text.Replace("%INTVALUE2%", Change.ToString((object)int32));
                    break;

                case string _:
                    text = text.Replace("%VALUE2%", result as string);
                    break;
                }
            }
            return(text);
        }
Esempio n. 2
0
 public static void Initialize()
 {
     foreach (string file in Content.GetFiles("Content/titles"))
     {
         IEnumerable <XElement> source = XDocument.Load(TitleContainer.OpenStream(file)).Elements((XName)"Title");
         if (source != null)
         {
             XAttribute xattribute1 = source.Attributes((XName)"name").FirstOrDefault <XAttribute>();
             if (xattribute1 != null)
             {
                 DuckTitle duckTitle = new DuckTitle();
                 duckTitle._name = xattribute1.Value;
                 bool flag = false;
                 foreach (XElement element in source.Elements <XElement>())
                 {
                     if (element.Name == (XName)"StatRequirement")
                     {
                         XAttribute statNameAttrib = element.Attributes((XName)"name").FirstOrDefault <XAttribute>();
                         XAttribute xattribute2    = element.Attributes((XName)"value").FirstOrDefault <XAttribute>();
                         if (statNameAttrib != null && xattribute2 != null)
                         {
                             PropertyInfo key = ((IEnumerable <PropertyInfo>) typeof(ProfileStats).GetProperties()).FirstOrDefault <PropertyInfo>((Func <PropertyInfo, bool>)(x => x.Name == statNameAttrib.Value));
                             if (key != (PropertyInfo)null)
                             {
                                 if (key.GetType() == typeof(float))
                                 {
                                     duckTitle._requirementsFloat.Add(key, Change.ToSingle((object)xattribute2.Value));
                                 }
                                 else if (key.GetType() == typeof(int))
                                 {
                                     duckTitle._requirementsFloat.Add(key, (float)Convert.ToInt32(xattribute2.Value));
                                 }
                                 else
                                 {
                                     duckTitle._requirementsString.Add(key, xattribute2.Value);
                                 }
                             }
                             else
                             {
                                 flag = true;
                                 break;
                             }
                         }
                         else
                         {
                             flag = true;
                             break;
                         }
                     }
                 }
                 if (!flag)
                 {
                     DuckTitle._titles.Add(duckTitle);
                 }
             }
         }
     }
 }
        private bool LegacyDoDeserialize(XElement node)
        {
            System.Type type  = Editor.GetType(node.Element((XName)"blockType").Value);
            bool        flag1 = typeof(AutoBlock).IsAssignableFrom(type);

            this._things = new List <Thing>();
            string[] strArray1 = node.Element((XName)"data").Value.Split(',');
            bool     flag2     = strArray1[0] == "n";

            if (!flag2)
            {
                flag1 = false;
            }
            List <AutoBlock> autoBlockList = new List <AutoBlock>();

            for (int index = flag2 ? 1 : 0; index < ((IEnumerable <string>)strArray1).Count <string>(); index += 3)
            {
                float num    = Change.ToSingle((object)strArray1[index]);
                float single = Change.ToSingle((object)strArray1[index + 1]);
                int   int32  = Convert.ToInt32(strArray1[index + 2]);
                bool  flag3  = Level.flipH;
                if (Level.loadingOppositeSymmetry)
                {
                    flag3 = !flag3;
                }
                if (flag3)
                {
                    num = (float)(192.0 - (double)num - 16.0);
                }
                Thing thing = Editor.CreateThing(type);
                if (flag3 && thing is AutoBlock)
                {
                    (thing as AutoBlock).needsRefresh = true;
                    (thing as AutoBlock).isFlipped    = true;
                }
                if (flag3 && thing is AutoPlatform)
                {
                    (thing as AutoPlatform).needsRefresh = true;
                }
                thing.x      = num;
                thing.y      = single;
                thing.placed = true;
                if (thing.isStatic)
                {
                    this._isStatic = true;
                }
                if (flag1)
                {
                    AutoBlock autoBlock = thing as AutoBlock;
                    autoBlock.northIndex = Convert.ToInt32(strArray1[index + 3]);
                    autoBlock.southIndex = Convert.ToInt32(strArray1[index + 4]);
                    if (flag3)
                    {
                        autoBlock.westIndex = Convert.ToInt32(strArray1[index + 5]);
                        autoBlock.eastIndex = Convert.ToInt32(strArray1[index + 6]);
                    }
                    else
                    {
                        autoBlock.eastIndex = Convert.ToInt32(strArray1[index + 5]);
                        autoBlock.westIndex = Convert.ToInt32(strArray1[index + 6]);
                    }
                    autoBlockList.Add(autoBlock);
                    index += 4;
                }
                bool flag4 = true;
                if (Level.symmetry)
                {
                    if (Level.leftSymmetry && (double)num > 80.0)
                    {
                        flag4 = false;
                    }
                    if (!Level.leftSymmetry && (double)num < 96.0)
                    {
                        flag4 = false;
                    }
                }
                if (flag4)
                {
                    thing.frame = int32;
                    this._things.Add(thing);
                }
            }
            if (flag1 && !(Level.current is Editor))
            {
                foreach (AutoBlock autoBlock in autoBlockList)
                {
                    if (autoBlock.northIndex != -1)
                    {
                        autoBlock.upBlock = (Block)autoBlockList[autoBlock.northIndex];
                    }
                    if (autoBlock.southIndex != -1)
                    {
                        autoBlock.downBlock = (Block)autoBlockList[autoBlock.southIndex];
                    }
                    if (autoBlock.eastIndex != -1)
                    {
                        autoBlock.rightBlock = (Block)autoBlockList[autoBlock.eastIndex];
                    }
                    if (autoBlock.westIndex != -1)
                    {
                        autoBlock.leftBlock = (Block)autoBlockList[autoBlock.westIndex];
                    }
                    autoBlock.neighborsInitialized = true;
                }
                XElement xelement = node.Element((XName)"groupData");
                if (xelement != null)
                {
                    string[] strArray2 = xelement.Value.Split(',');
                    int      num1;
                    for (int index1 = 0; index1 < ((IEnumerable <string>)strArray2).Count <string>(); index1 = num1 + 7)
                    {
                        BlockGroup blockGroup = new BlockGroup();
                        blockGroup.position = new Vec2(Change.ToSingle((object)strArray2[index1]), Change.ToSingle((object)strArray2[index1 + 1]));
                        bool flag3 = Level.flipH;
                        if (Level.loadingOppositeSymmetry)
                        {
                            flag3 = !flag3;
                        }
                        if (flag3)
                        {
                            blockGroup.position.x = (float)(192.0 - (double)blockGroup.position.x - 16.0);
                        }
                        blockGroup.collisionOffset = new Vec2(Change.ToSingle((object)strArray2[index1 + 2]), Change.ToSingle((object)strArray2[index1 + 3]));
                        blockGroup.collisionSize   = new Vec2(Change.ToSingle((object)strArray2[index1 + 4]), Change.ToSingle((object)strArray2[index1 + 5]));
                        float num2 = 88f;
                        if (Level.symmetry)
                        {
                            if (Level.leftSymmetry)
                            {
                                if ((double)blockGroup.left < (double)num2 && (double)blockGroup.right > (double)num2)
                                {
                                    float num3 = blockGroup.right - num2;
                                    float x    = blockGroup.collisionSize.x - num3;
                                    blockGroup.position.x     -= num3;
                                    blockGroup.position.x     += x / 2f;
                                    blockGroup.collisionSize   = new Vec2(x, blockGroup.collisionSize.y);
                                    blockGroup.collisionOffset = new Vec2((float)-((double)x / 2.0), blockGroup.collisionOffset.y);
                                    blockGroup.right           = num2;
                                }
                            }
                            else
                            {
                                num2 = 88f;
                                if ((double)blockGroup.right > (double)num2 && (double)blockGroup.left < (double)num2)
                                {
                                    float num3 = num2 - blockGroup.left;
                                    float x    = blockGroup.collisionSize.x - num3;
                                    blockGroup.position.x     += num3;
                                    blockGroup.position.x     -= x / 2f;
                                    blockGroup.collisionSize   = new Vec2(x, blockGroup.collisionSize.y);
                                    blockGroup.collisionOffset = new Vec2((float)-((double)x / 2.0), blockGroup.collisionOffset.y);
                                    blockGroup.left            = num2;
                                }
                            }
                        }
                        int int32_1 = Convert.ToInt32(strArray2[index1 + 6]);
                        for (int index2 = 0; index2 < int32_1; ++index2)
                        {
                            int       int32_2   = Convert.ToInt32(strArray2[index1 + 7 + index2]);
                            AutoBlock autoBlock = autoBlockList[int32_2];
                            bool      flag4     = true;
                            if (Level.symmetry)
                            {
                                if (Level.leftSymmetry && (double)autoBlock.x > 80.0)
                                {
                                    flag4 = false;
                                }
                                if (!Level.leftSymmetry && (double)autoBlock.x < 96.0)
                                {
                                    flag4 = false;
                                }
                            }
                            if (flag4)
                            {
                                autoBlock.groupedWithNeighbors = true;
                                blockGroup.Add((Block)autoBlock);
                                blockGroup.physicsMaterial = autoBlock.physicsMaterial;
                                blockGroup.thickness       = autoBlock.thickness;
                            }
                            this._things.Remove((Thing)autoBlock);
                        }
                        num1 = index1 + int32_1;
                        if (flag3)
                        {
                            blockGroup.needsRefresh = true;
                        }
                        if (Level.symmetry)
                        {
                            if (Level.leftSymmetry && (double)blockGroup.left < (double)num2)
                            {
                                this._things.Add((Thing)blockGroup);
                            }
                            else if (!Level.leftSymmetry && (double)blockGroup.right > (double)num2)
                            {
                                this._things.Add((Thing)blockGroup);
                            }
                        }
                        else
                        {
                            this._things.Add((Thing)blockGroup);
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 4
0
        public List <DuckStory> CalculateStory()
        {
            List <DuckStory> duckStoryList = new List <DuckStory>();
            List <Profile>   p             = new List <Profile>();

            if (this._cycle == CycleMode.Once)
            {
                p.Add(Profiles.DefaultPlayer1);
                duckStoryList.AddRange((IEnumerable <DuckStory>) this.CalculateStory(p));
            }
            else if (this._cycle == CycleMode.PerProfile)
            {
                foreach (Profile profile in Profiles.active)
                {
                    p.Add(profile);
                    duckStoryList.AddRange((IEnumerable <DuckStory>) this.CalculateStory(p));
                    p.Clear();
                }
            }
            else if (this._cycle == CycleMode.PerPosition && this._valueCalculation != null)
            {
                List <List <Profile> > source = new List <List <Profile> >();
                List <Profile>         active = Profiles.active;
                foreach (Profile profile in Profiles.active)
                {
                    float num = -999999f;
                    Script.activeProfile = profile;
                    object result = this.valueCalculation.result;
                    if (result != null && result is float || (result is int || result is double))
                    {
                        num = Change.ToSingle(result);
                    }
                    profile.storeValue = num;
                    bool flag = false;
                    for (int index = 0; index < source.Count; ++index)
                    {
                        if ((double)source[index][0].storeValue < (double)num)
                        {
                            source.Insert(index, new List <Profile>());
                            source[index].Add(profile);
                            flag = true;
                            break;
                        }
                        if ((double)source[index][0].storeValue == (double)num)
                        {
                            source[index].Add(profile);
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        source.Add(new List <Profile>());
                        source.Last <List <Profile> >().Add(profile);
                    }
                }
                source.Reverse();
                Script.positions = source;
                int num1 = source.Count - 1;
                foreach (List <Profile> profileList in source)
                {
                    Script.currentPosition = num1;
                    p.AddRange((IEnumerable <Profile>)profileList);
                    duckStoryList.AddRange((IEnumerable <DuckStory>) this.CalculateStory(p));
                    p.Clear();
                    --num1;
                }
            }
            return(duckStoryList);
        }
Esempio n. 5
0
        public static ScriptStatement Parse(
            string statement,
            object left           = null,
            object right          = null,
            ScriptOperator operat = ScriptOperator.None,
            string func           = null,
            bool isChild          = false)
        {
            ScriptStatement scriptStatement1 = new ScriptStatement();

            scriptStatement1.leftObject   = left;
            scriptStatement1.rightObject  = right;
            scriptStatement1.op           = operat;
            scriptStatement1.functionName = func;
            int num = 1;

            if (!isChild)
            {
                ++num;
            }
            string         str     = "";
            ScriptOperator operat1 = ScriptOperator.None;
            bool           flag1   = false;
            bool           flag2   = false;
            bool           flag3   = false;
            bool           flag4   = false;
            bool           flag5   = false;

            while (statement.Length > 0)
            {
                char c = statement[0];
                statement = statement.Remove(0, 1);
                if (!flag3 && char.IsNumber(c))
                {
                    if (str.Length > 0 && !flag1)
                    {
                        if (flag4 && str == "-")
                        {
                            flag4 = false;
                        }
                        else
                        {
                            scriptStatement1.error = "Found unexpected number.";
                            break;
                        }
                    }
                    flag1 = true;
                }
                else if (c == '.' && !flag3)
                {
                    if (str.Length > 0 && !flag1)
                    {
                        scriptStatement1.error = "Found unexpected Period.";
                        break;
                    }
                    flag2 = true;
                }
                else if (c == ' ' || c == '(' || c == ')')
                {
                    flag5 = true;
                    if (flag3 && (str == "and" || str == "or"))
                    {
                        flag3 = false;
                        flag4 = true;
                    }
                    if (scriptStatement1.data == null)
                    {
                        if (flag3)
                        {
                            scriptStatement1.data = (object)str;
                        }
                        else if (flag2)
                        {
                            scriptStatement1.data = (object)Change.ToSingle((object)str);
                        }
                        else if (flag1)
                        {
                            scriptStatement1.data = (object)Convert.ToInt32(str);
                        }
                    }
                    if (flag4)
                    {
                        if (str == "+")
                        {
                            operat1 = ScriptOperator.Plus;
                        }
                        else if (str == "-")
                        {
                            operat1 = ScriptOperator.Minus;
                        }
                        else if (str == "*")
                        {
                            operat1 = ScriptOperator.Multiply;
                        }
                        else if (str == "/")
                        {
                            operat1 = ScriptOperator.Divide;
                        }
                        else if (str == "==")
                        {
                            operat1 = ScriptOperator.IsEqual;
                        }
                        else if (str == "!=")
                        {
                            operat1 = ScriptOperator.IsNotEqual;
                        }
                        else if (str == ">")
                        {
                            operat1 = ScriptOperator.GreaterThan;
                        }
                        else if (str == "<")
                        {
                            operat1 = ScriptOperator.LessThan;
                        }
                        else if (str == "&&")
                        {
                            operat1 = ScriptOperator.And;
                        }
                        else if (str == "and")
                        {
                            operat1 = ScriptOperator.And;
                        }
                        else if (str == "or")
                        {
                            operat1 = ScriptOperator.Or;
                        }
                        if (scriptStatement1.op == ScriptOperator.None)
                        {
                            scriptStatement1.op = operat1;
                        }
                    }
                    switch (c)
                    {
                    case '(':
                        ScriptStatement scriptStatement2 = ScriptStatement.Parse(statement, func: (flag3 ? str : (string)null), isChild: true);
                        statement = scriptStatement2.remainingStatementString;
                        if (scriptStatement2.error != null)
                        {
                            scriptStatement1.error = scriptStatement2.error;
                            goto label_76;
                        }
                        else
                        {
                            scriptStatement1.data = (object)scriptStatement2;
                            break;
                        }

                    case ')':
                        --num;
                        break;
                    }
                    if (scriptStatement1.data != null)
                    {
                        object obj = scriptStatement1.data;
                        scriptStatement1.data = (object)null;
                        if (operat1 > ScriptOperator.COMPARATORS)
                        {
                            ScriptStatement scriptStatement3 = ScriptStatement.Parse(statement, obj, isChild: true);
                            obj       = (object)scriptStatement3;
                            statement = scriptStatement3.remainingStatementString;
                        }
                        if (scriptStatement1.leftObject == null)
                        {
                            scriptStatement1.leftObject = obj;
                        }
                        else
                        {
                            if (scriptStatement1.rightObject != null)
                            {
                                return(ScriptStatement.Parse(statement, (object)scriptStatement1, obj, operat1, isChild: true));
                            }
                            scriptStatement1.rightObject = obj;
                        }
                    }
                    str   = "";
                    flag3 = false;
                    flag2 = false;
                    flag1 = false;
                    flag4 = false;
                    if (num <= 0)
                    {
                        break;
                    }
                }
                else if (!flag3 && c == '+' || (c == '-' || c == '*') || (c == '/' || c == '=' || (c == '<' || c == '!')) || (c == '>' || c == '&'))
                {
                    if (str.Length > 0 && !flag4)
                    {
                        scriptStatement1.error = "Found unexpected operator.";
                        break;
                    }
                    flag4 = true;
                }
                else if (c == '"')
                {
                    flag5 = true;
                    flag3 = true;
                }
                else
                {
                    if (str.Length > 0 && !flag3)
                    {
                        scriptStatement1.error = "Found unexpected letter.";
                        break;
                    }
                    flag3 = true;
                }
                if (!flag5)
                {
                    str += (string)(object)c;
                }
                flag5 = false;
            }
label_76:
            scriptStatement1.remainingStatementString = statement;
            return(scriptStatement1);
        }