Beispiel #1
0
        public int GetFieldIDByNPC(int NPCID)
        {
            ArrayList fieldList = FieldList.GetArrayList();

            foreach (SHField field in fieldList)
            {
                int fieldID = field.id;

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

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

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

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

                        if (spawnnpc.id == NPCID)
                        {
                            return(fieldID);
                        }
                    }
                }
            }
            return(0);
        }
Beispiel #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);
        }