コード例 #1
0
ファイル: NpcManager.cs プロジェクト: pzaps/Server
 public static Npc LoadNpc(int npcNum)
 {
     Npc npc = new Npc();
     string FileName = IO.Paths.NpcsFolder + "npc" + npcNum + ".dat";
     string s;
     string[] parse;
     using (System.IO.StreamReader read = new System.IO.StreamReader(FileName)) {
         while (!(read.EndOfStream)) {
             s = read.ReadLine();
             parse = s.Split('|');
             switch (parse[0].ToLower()) {
                 case "npcdata":
                     if (parse[1].ToLower() != "v1" && parse[1].ToLower() != "v2" && parse[1].ToLower() != "v3") {
                         read.Close();
                         return null;
                     }
                     break;
                 case "data": {
                         npc.Name = parse[1];
                         npc.AttackSay = parse[2];
                         npc.Sprite = parse[3].ToInt();
                         npc.SpawnSecs = parse[4].ToInt();
                         npc.Behavior = (Enums.NpcBehavior)parse[5].ToInt();
                         npc.Range = parse[6].ToInt();
                         npc.Str = parse[7].ToInt();
                         npc.Def = parse[8].ToInt();
                         npc.Speed = parse[9].ToInt();
                         npc.Magi = parse[10].ToInt();
                         npc.Big = parse[11].ToBool();
                         npc.MaxHp = parse[12].ToInt();
                         npc.Exp = parse[13].ToUlng();
                         npc.SpawnTime = parse[14].ToInt();
                         npc.Element = parse[15].ToInt();
                         if (parse.Length > 17) {
                             npc.Spell = parse[16].ToInt();
                         }
                         if (parse.Length > 18) {
                             npc.Frequency = parse[17].ToInt();
                         }
                         if (parse.Length > 19) {
                             npc.AIScript = parse[18];
                         }
                     }
                     break;
                 case "recruit":
                     npc.RecruitRate = parse[1].ToInt();
                     npc.RecruitLevel = parse[2].ToInt();
                     //Check if size is in the NPC file... if not add it...
                     if (parse.Length > 4) {
                         npc.Size = parse[3].ToInt();
                     } else {
                         npc.Size = 1;
                     }
                     if (parse.Length > 5) {
                         npc.RecruitClass = parse[4].ToInt();
                     } else {
                         npc.RecruitClass = 0;
                     }
                     break;
                 case "items": {
                         if (parse[1].ToInt() < npc.Drops.Length) {
                             npc.Drops[parse[1].ToInt()].ItemNum = parse[2].ToInt();
                             npc.Drops[parse[1].ToInt()].ItemValue = parse[3].ToInt();
                             npc.Drops[parse[1].ToInt()].Chance = parse[4].ToInt();
                         }
                     }
                     break;
             }
         }
     }
     return npc;
 }
コード例 #2
0
ファイル: NpcManager.cs プロジェクト: pzaps/Server
 public static void SaveNpc(Npc npc, int npcNum)
 {
     string FileName = IO.Paths.NpcsFolder + "npc" + npcNum.ToString() + ".dat";
     using (System.IO.StreamWriter Write = new System.IO.StreamWriter(FileName)) {
         Write.WriteLine("NpcData|V3");
         Write.WriteLine("Data" + "|" + npc.Name + "|" + npc.AttackSay + "|" + npc.Sprite + "|" + npc.SpawnSecs + "|" + (int)npc.Behavior + "|" + npc.Range + "|" + npc.Str + "|" + npc.Def + "|" + npc.Speed + "|" + npc.Magi + "|" + npc.Big + "|" + npc.MaxHp + "|" + npc.Exp + "|" + npc.SpawnTime + "|" + npc.Element + "|" + npc.Spell + "|" + npc.Frequency + "|" + npc.AIScript + "|");
         Write.WriteLine("recruit" + "|" + npc.RecruitRate + "|" + npc.RecruitLevel + "|" + npc.Size + "|" + npc.RecruitClass + "|");
         for (int z = 0; z < Constants.MAX_NPC_DROPS; z++) {
             Write.WriteLine("items" + "|" + z + "|" + npc.Drops[z].ItemNum + "|" + npc.Drops[z].ItemValue + "|" + npc.Drops[z].Chance + "|");
         }
     }
 }
コード例 #3
0
        public static Npc LoadNpc(int npcNum)
        {
            Npc    npc      = new Npc();
            string FileName = IO.Paths.NpcsFolder + "npc" + npcNum + ".dat";
            string s;

            string[] parse;
            using (System.IO.StreamReader read = new System.IO.StreamReader(FileName))
            {
                while (!(read.EndOfStream))
                {
                    s     = read.ReadLine();
                    parse = s.Split('|');
                    switch (parse[0].ToLower())
                    {
                    case "npcdata":
                        if (parse[1].ToLower() != "v1" && parse[1].ToLower() != "v2" && parse[1].ToLower() != "v3")
                        {
                            read.Close();
                            return(null);
                        }
                        break;

                    case "data":
                    {
                        npc.Name      = parse[1];
                        npc.AttackSay = parse[2];
                        npc.Sprite    = parse[3].ToInt();
                        npc.SpawnSecs = parse[4].ToInt();
                        npc.Behavior  = (Enums.NpcBehavior)parse[5].ToInt();
                        npc.Range     = parse[6].ToInt();
                        npc.Str       = parse[7].ToInt();
                        npc.Def       = parse[8].ToInt();
                        npc.Speed     = parse[9].ToInt();
                        npc.Magi      = parse[10].ToInt();
                        npc.Big       = parse[11].ToBool();
                        npc.MaxHp     = parse[12].ToInt();
                        npc.Exp       = parse[13].ToUlng();
                        npc.SpawnTime = parse[14].ToInt();
                        npc.Element   = parse[15].ToInt();
                        if (parse.Length > 17)
                        {
                            npc.Spell = parse[16].ToInt();
                        }
                        if (parse.Length > 18)
                        {
                            npc.Frequency = parse[17].ToInt();
                        }
                        if (parse.Length > 19)
                        {
                            npc.AIScript = parse[18];
                        }
                    }
                    break;

                    case "recruit":
                        npc.RecruitRate  = parse[1].ToInt();
                        npc.RecruitLevel = parse[2].ToInt();
                        //Check if size is in the NPC file... if not add it...
                        if (parse.Length > 4)
                        {
                            npc.Size = parse[3].ToInt();
                        }
                        else
                        {
                            npc.Size = 1;
                        }
                        if (parse.Length > 5)
                        {
                            npc.RecruitClass = parse[4].ToInt();
                        }
                        else
                        {
                            npc.RecruitClass = 0;
                        }
                        break;

                    case "items":
                    {
                        if (parse[1].ToInt() < npc.Drops.Length)
                        {
                            npc.Drops[parse[1].ToInt()].ItemNum   = parse[2].ToInt();
                            npc.Drops[parse[1].ToInt()].ItemValue = parse[3].ToInt();
                            npc.Drops[parse[1].ToInt()].Chance    = parse[4].ToInt();
                        }
                    }
                    break;
                    }
                }
            }
            return(npc);
        }