Example #1
0
        public void SaveRecipeByNPC()
        {
            SHRecipeNPCXml RecipeNPCXml = new SHRecipeNPCXml();

            foreach (SHRecipe recipe in Recipe.dataList)
            {
                SHRecipeNPC sNPC = new SHRecipeNPC();
                sNPC.recipe = recipe.id;

                int Index = 0;
                foreach (SHCraft craft in Craft.dataList)
                {
                    foreach (int recipeid in craft.RecipeIDList)
                    {
                        if (recipe.id == recipeid)
                        {
                            foreach (SHNPC npc in NPCs.dataList)
                            {
                                SHNPCIType[] _iType = npc.GetIType();
                                string[]     _iAct  = npc.GetIAct();
                                for (int i = 0; i < 10; i++)
                                {
                                    if (_iType[i] == SHNPCIType.craft)
                                    {
                                        if (Craft.IsValid(_iAct[i]) == false)
                                        {
                                            continue;
                                        }

                                        SHCraft craftinfo = Craft[_iAct[i]];
                                        if (craftinfo.hidden == true)
                                        {
                                            continue;
                                        }

                                        int cID = Convert.ToInt32(_iAct[i]);
                                        if (craft.id == cID)
                                        {
                                            //
                                            if (Index >= 10)
                                            {
                                                break;
                                            }

                                            int FieldID = GetFieldIDByNPC(npc.id);
                                            if (FieldID == 0)
                                            {
                                                continue;
                                            }

                                            sNPC.Add(Index, npc.id.ToString(), FieldID.ToString());
                                            Index++;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                RecipeNPCXml.Add(sNPC);
            }

            string strFileName = "\\recipeNPC.xml";

            SHGlobal.Serialize <SHRecipeNPCXml>(SHGlobal.GetClientSystemFolder() + strFileName, RecipeNPCXml, Encoding.UTF8);
        }
Example #2
0
        public void NPCInfoSave(int fieldID)
        {
            string strFieldFileName = String.Format("\\{0}.field.xml", fieldID);

            if (File.Exists(SHGlobal.GetClientFieldFolder() + strFieldFileName) == false)
            {
                return;
            }

            SHFieldXml field = SHGlobal.Deserialize <SHFieldXml>(SHGlobal.GetClientFieldFolder() + strFieldFileName, Encoding.UTF8);

            field.Compile();

            SHFieldNPCXml fieldNPCXml = new SHFieldNPCXml();

            foreach (SHSpawn spawn in field.fieldInfo.spawnList)
            {
                if (false == spawn.enabled)
                {
                    continue;
                }

                foreach (SHSpawnNPC spawnnpc in spawn.dataList)
                {
                    if (NPCs.IsValid(spawnnpc.id) == false)
                    {
                        continue;
                    }

                    SHNPC npc = NPCs[spawnnpc.id];
                    if (npc.InteractCount == 0)
                    {
                        continue;
                    }

                    string[] _Type = new string[2];
                    string[] _ICon = new string[2];
                    int      Index = 0;

                    SHNPCIType[] _iType = npc.GetIType();
                    string[]     _iAct  = npc.GetIAct();
                    for (int i = 0; i < 10; i++)
                    {
                        if (_iType[i] == SHNPCIType.craft)
                        {
                            if (Craft.IsValid(_iAct[i]) == false)
                            {
                                continue;
                            }

                            SHCraft craftinfo = Craft[_iAct[i]];
                            if (craftinfo.hidden == true)
                            {
                                continue;
                            }

                            _Type[Index] = "craft";
                            _ICon[Index] = craftinfo.type;
                            Index++;

                            break;
                        }
                    }
                    for (int i = 0; i < 10; i++)
                    {
                        if (_iType[i] == SHNPCIType.trade)
                        {
                            if (NPCShop.IsValid(_iAct[i]) == false)
                            {
                                continue;
                            }

                            _ICon[Index] = "common";
                            SHNPCShop npcshop = NPCShop[_iAct[i]];
                            if (npcshop.repairable == true)
                            {
                                _ICon[Index] = "repair";
                            }

                            if (npcshop.IsLicensable(Items, Talents) == true)
                            {
                                _ICon[Index] = "license";
                            }

                            _Type[Index] = "shop";
                            Index++;

                            break;
                        }
                    }

                    if (Index == 0)
                    {
                        continue;
                    }

                    SHFieldNPC sNPC = new SHFieldNPC();
                    sNPC.id    = spawnnpc.id;
                    sNPC.name  = npc.Name;
                    sNPC.x     = spawn.x;
                    sNPC.y     = spawn.y;
                    sNPC.z     = spawn.z;
                    sNPC.type1 = _Type[0];
                    sNPC.icon1 = _ICon[0];
                    sNPC.type2 = _Type[1];
                    sNPC.icon2 = _ICon[1];
                    fieldNPCXml.Add(sNPC);
                }
            }

            if (fieldNPCXml.dataList.Count == 0)
            {
                return;
            }

            string strFileName = String.Format("\\{0}.field.npc.xml", fieldID);

            SHGlobal.Serialize <SHFieldNPCXml>(SHGlobal.GetClientFieldFolder() + "\\map" + strFileName, fieldNPCXml, Encoding.UTF8);
        }