コード例 #1
0
        internal void PrepareCreepsList()
        {
            DHMpqFile    jScript = DHRC.GetFile(MpqPath.Script.Custom);
            MemoryStream ms      = jScript.GetStream();

            byte[] buffer = ms.GetBuffer();
            string script;

            unsafe
            {
                fixed(byte *ptr = buffer)
                {
                    script = new string((sbyte *)ptr);
                }
            }

            List <HabProperties> list = new List <HabProperties>();

            foreach (HabProperties hpsUnit in hpcData)
            {
                HabProperties hpsBalance = hpcBalance[hpsUnit.name];
                if (hpsBalance.GetStringValue("Primary").Length > 1)
                {
                    continue;
                }

                HabProperties hpsProfile = hpcProfile[hpsUnit.name];
                if (hpsProfile == null)
                {
                    continue;
                }

                if (hpsUnit.GetStringValue("targType") != "ground")
                {
                    continue;
                }

                HabProperties hpsWeapons = hpcWeapons[hpsUnit.name];
                if (hpsWeapons == null)
                {
                    continue;
                }

                if (hpsWeapons.GetStringValue("weapTp1") == "_")
                {
                    continue;
                }

                HabProperties hpsUI = hpcUI[hpsUnit.name];
                if (hpsUI == null)
                {
                    continue;
                }

                if (!hpsUI.GetStringValue("file").StartsWith("units", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                if (!hpsWeapons.ContainsKey("mindmg1"))
                {
                    continue;
                }

                if (!script.Contains("'" + hpsUnit.name + "'") && !script.Contains(DHJassInt.id2int(hpsUnit.name) + ""))
                {
                    continue;
                }

                list.Add(hpsProfile);
            }

            creepsCmbB.DataSource = list;
        }
コード例 #2
0
ファイル: DHJassExecutor.cs プロジェクト: sonygod/dotahit
        public static bool TryGetValue <T>(string code, out DHJassValue value) where T : DHJassValue, new()
        {
            if (String.IsNullOrEmpty(code))
            {
                value = null;
                return(false);
            }

            unsafe
            {
                fixed(char *pStr = code)
                {
                    char *ptr = DHJassSyntax.removeWsRbRecursive(pStr, pStr + code.Length);

                    code = new string(ptr);

                    if (code == "null")
                    {
                        value = new DHJassUnusedType();
                        return(true);
                    }

                    DHJassValue parser;

                    if (DbJassTypeValueKnowledge.TypeValuePairs.TryGetValue(typeof(T), out parser))
                    {
                        object parsedValue;
                        if (parser.TryParseDirect(code, out parsedValue))
                        {
                            value       = new T();
                            value.Value = parsedValue;
                            return(true);
                        }
                    }

                    string        name;
                    string        param;
                    List <string> operands;
                    List <string> operators;

                    if (DHJassSyntax.checkLogicalExpressionsSyntaxFast(ptr, out operands, out operators))
                    {
                        return(TryGetLogicalExpressionValueFast(operands, operators, out value));
                    }
                    else
                    if (DHJassSyntax.checkRelationalExpressionsSyntaxFast(ptr, out operands, out operators)) //, out match))
                    {
                        return(TryGetRelationalExpressionValueFast(operands, operators, out value));         //match, out value);
                    }
                    else
                    if (DHJassSyntax.checkArithmeticExpressionsSyntaxFast(ptr, out operands, out operators))  //, out match))
                    {
                        return(TryGetArithmeticExpressionValueFast <T>(operands, operators, out value));      //match, out value);
                    }
                    else
                    if (DHJassSyntax.checkTypeVariableUsageSyntaxFast(code, out name))
                    {
                        return(TryGetVariable(name, out value));
                    }
                    else
                    if (DHJassSyntax.checkArrayVariableUsageSyntaxFast(ptr, out name, out param))
                    {
                        DHJassValue array;
                        if (TryGetVariable(name, out array) && array is DHJassArray)
                        {
                            int index;
                            if (DHJassInt.TryParse(param, out index))
                            {
                                value = (array as DHJassArray)[index];
                                return(true);
                            }
                        }
                    }
                    else
                    if (DHJassSyntax.checkFunctionUsageSyntaxFast(ptr, out name, out operands))
                    {
                        return(TryCallFunctionFast(name, operands, out value));
                    }
                    else
                    if (DHJassSyntax.checkFunctionPointerUsageSyntaxFast(ptr, out name))
                    {
                        return(TryGetFunctionPointer(name, out value));
                    }
                }
            }

            value = null;
            return(false);
        }
コード例 #3
0
ファイル: ItemListForm.cs プロジェクト: sonygod/dotahit
        public void CollectItemCombiningData()
        {
            if (MorphingItems != null)
            {
                return;
            }

            sameLookingComplexItems = null;

            Current.player.AcceptMessages = false;

            Dictionary <string, widget> dcItems = new Dictionary <string, widget>();

            foreach (unit shop in DHLOOKUP.shops)
            {
                if (DHHELPER.IsNewVersionItemShop(shop))
                {
                    foreach (string unitID in shop.sellunits)
                    {
                        if (!dcItems.ContainsKey(unitID))
                        {
                            unit u = new unit(unitID);
                            u.DoSummon = true;
                            u.set_owningPlayer(Current.player);

                            dcItems.Add(unitID, u);
                        }
                    }
                }
                else
                {
                    foreach (string itemID in shop.sellitems)
                    {
                        if (!dcItems.ContainsKey(itemID))
                        {
                            dcItems.Add(itemID, new item(itemID));
                        }
                    }
                }
            }

            unit test_unit = new unit();

            test_unit.codeID = "test";
            test_unit.Inventory.init(0, 10);

            test_unit.set_owningPlayer(Current.player);

            DHJassExecutor.CaughtReferences.Clear();
            DHJassExecutor.CatchArrayReference = true;

            DBINVENTORY inventory = test_unit.Inventory;

            List <widget> itemList = new List <widget>(dcItems.Values);

            MorphingItems = new Dictionary <string, string>(itemList.Count);

            SplashScreen splashScreen = new SplashScreen();

            splashScreen.Show();
            splashScreen.ShowText("Collecting item combining data...");

            for (int i = 0; i < itemList.Count; i++)
            {
                widget item = itemList[i];

                if (DHHELPER.IsNewVersionItem(item.codeID))
                {
                    test_unit.OnSell(item as unit);
                    Thread.Sleep(2); // to pass control to item handling script thread
                }
                else
                {
                    test_unit.OnSellItem(item as item, test_unit);
                    inventory.put_item(item as item);
                }

                item result = inventory[0].Item;
                if (result != null)
                {
                    if (result.codeID != item.codeID)
                    {
                        MorphingItems.Add(result.codeID, item.codeID);
                    }
                    inventory[0].drop_item();
                }

                splashScreen.ShowProgress((double)i, (double)itemList.Count);
            }

            Current.player.remove_unit(test_unit);
            test_unit.destroy();

            List <string> arrays = DHJassExecutor.CaughtReferences;

            if (arrays.Count == 6)
            {
                Dictionary <int, DHJassValue> dcA = (DHJassExecutor.Globals[arrays[0]] as DHJassArray).Array;
                Dictionary <int, DHJassValue> dcB = (DHJassExecutor.Globals[arrays[1]] as DHJassArray).Array;
                Dictionary <int, DHJassValue> dcC = (DHJassExecutor.Globals[arrays[2]] as DHJassArray).Array;
                Dictionary <int, DHJassValue> dcD = (DHJassExecutor.Globals[arrays[3]] as DHJassArray).Array;

                Dictionary <int, DHJassValue> dcCombined = (DHJassExecutor.Globals[arrays[4]] as DHJassArray).Array;

                ComplexItems = new Dictionary <string, List <List <string> > >(dcA.Count);

                int value;
                foreach (int key in dcA.Keys)
                {
                    List <string> components = new List <string>(4);

                    value = dcA[key].IntValue;
                    if (value != 0)
                    {
                        components.Add(DHJassInt.int2id(value));
                    }

                    value = dcB[key].IntValue;
                    if (value != 0)
                    {
                        components.Add(DHJassInt.int2id(value));
                    }

                    value = dcC[key].IntValue;
                    if (value != 0)
                    {
                        components.Add(DHJassInt.int2id(value));
                    }

                    value = dcD[key].IntValue;
                    if (value != 0)
                    {
                        components.Add(DHJassInt.int2id(value));
                    }

                    value = dcCombined[key].IntValue;
                    if (value != 0)
                    {
                        string strValue = DHJassInt.int2id(value);

                        List <List <string> > componentsList;
                        if (!ComplexItems.TryGetValue(strValue, out componentsList))
                        {
                            componentsList = new List <List <string> >(1);
                            ComplexItems.Add(strValue, componentsList);
                        }

                        componentsList.Add(components);
                    }
                }
            }

            splashScreen.Close();

            Current.player.AcceptMessages = true;
        }