Esempio n. 1
0
 private static NPC registerNPC(NPC npc)
 {
     if (npc == null) return null;
     lock (NPCLock) {
         if (_npcIdMap.ContainsKey(npc.id)) {
             npc.image.Dispose();
             return _npcIdMap[npc.id];
         }
         _npcIdMap.Add(npc.id, npc);
         string name = npc.name.ToLower();
         if (!_npcNameMap.ContainsKey(name)) {
             _npcNameMap.Add(npc.name.ToLower(), npc);
         }
     }
     return npc;
 }
Esempio n. 2
0
        private static NPC createNPC(SQLiteDataReader reader)
        {
            SQLiteCommand command;

            if (!reader.Read()) {
                return null;
            }

            NPC npc = new NPC();
            npc.permanent = true;
            npc.id = reader.GetInt32(0);
            npc.name = reader["name"].ToString();
            npc.city = reader["city"].ToString();
            if (!reader.IsDBNull(3) && !reader.IsDBNull(4) && !reader.IsDBNull(5)) {
                npc.pos.x = reader.GetInt32(3);
                npc.pos.y = reader.GetInt32(4);
                npc.pos.z = reader.GetInt32(5);
            }
            npc.image = Image.FromStream(reader.GetStream(6));
            npc.job = reader.IsDBNull(7) ? "" : reader.GetString(7);
            if (npc.image.RawFormat.Guid == ImageFormat.Gif.Guid) {
                int frames = npc.image.GetFrameCount(FrameDimension.Time);
                if (frames == 1) {
                    Bitmap new_bitmap = new Bitmap(npc.image);
                    new_bitmap.MakeTransparent();
                    npc.image.Dispose();
                    npc.image = new_bitmap;
                }
            }

            // special case for rashid: change location based on day of the week
            if (npc != null && npc.name == "Rashid") {
                command = new SQLiteCommand(String.Format("SELECT city, x, y, z FROM RashidPositions WHERE day='{0}'", DateTime.Now.DayOfWeek.ToString()), mainForm.conn);
                reader = command.ExecuteReader();
                if (reader.Read()) {
                    npc.city = reader["city"].ToString();
                    npc.pos.x = reader.GetInt32(1);
                    npc.pos.y = reader.GetInt32(2);
                    npc.pos.z = reader.GetInt32(3);
                }
            }
            command = new SQLiteCommand(String.Format("SELECT itemid, value FROM SellItems WHERE vendorid={0}", npc.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                ItemSold sellItem = new ItemSold();
                sellItem.itemid = reader.GetInt32(0);
                sellItem.npcid = npc.id;
                sellItem.price = reader.GetInt32(1);
                npc.sellItems.Add(sellItem);
            }
            command = new SQLiteCommand(String.Format("SELECT itemid, value FROM BuyItems WHERE vendorid={0}", npc.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                ItemSold buyItem = new ItemSold();
                buyItem.itemid = reader.GetInt32(0);
                buyItem.npcid = npc.id;
                buyItem.price = reader.GetInt32(1);
                npc.buyItems.Add(buyItem);
            }
            command = new SQLiteCommand(String.Format("SELECT spellid,knight,druid,paladin,sorcerer FROM SpellNPCs WHERE npcid={0}", npc.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                SpellTaught t = new SpellTaught();
                t.npcid = npc.id;
                t.spellid = reader.GetInt32(0);
                t.knight = reader.GetBoolean(1);
                t.druid = reader.GetBoolean(2);
                t.paladin = reader.GetBoolean(3);
                t.sorcerer = reader.GetBoolean(4);
                npc.spellsTaught.Add(t);
            }

            command = new SQLiteCommand(String.Format("SELECT DISTINCT questid FROM QuestNPCs WHERE npcid={0}", npc.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                Quest q = getQuest(reader.GetInt32(0));
                npc.involvedQuests.Add(q);
            }

            command = new SQLiteCommand(String.Format("SELECT destination,cost,notes FROM NPCDestinations WHERE npcid={0}", npc.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                Transport t = new Transport();
                t.destination = reader.GetString(0);
                t.cost = reader.GetInt32(1);
                t.notes = reader.GetString(2);
                npc.transportOffered.Add(t);
            }
            return npc;
        }
Esempio n. 3
0
        public static void ShowNPCForm(NPC c, string command)
        {
            if (c == null) return;
            string[] split = command.Split(Constants.CommandSymbol);
            int page = 0;
            int currentDisplay = -1;
            if (split.Length > 2 && int.TryParse(split[2], out page)) { }
            if (split.Length > 3 && int.TryParse(split[3], out currentDisplay)) { }
            NPCForm f = new NPCForm(page, currentDisplay);
            f.npc = c;

            ShowNotification(f, command);
        }