示例#1
0
        public static bool LoadMapNPCRoles(int mapCode, GameMap gameMap)
        {
            string   fileName = string.Format("Map/{0}/npcs.xml", mapCode);
            XElement xml      = GeneralCachingXmlMgr.GetXElement(Global.ResPath(fileName));
            bool     result;

            if (null == xml)
            {
                result = false;
            }
            else
            {
                IEnumerable <XElement> items = xml.Elements("NPCs").Elements <XElement>();
                foreach (XElement item in items)
                {
                    NPC myNpc = new NPC();
                    myNpc.NpcID      = Convert.ToInt32((string)item.Attribute("Code"));
                    myNpc.MapCode    = mapCode;
                    myNpc.CurrentPos = new Point((double)Convert.ToInt32((string)item.Attribute("X")), (double)Convert.ToInt32((string)item.Attribute("Y")));
                    if (item.Attribute("Dir") != null)
                    {
                        myNpc.CurrentDir = (Dircetions)Global.GetSafeAttributeLong(item, "Dir");
                    }
                    else
                    {
                        myNpc.CurrentDir = Dircetions.DR_DOWN;
                    }
                    myNpc.RoleBufferData = NPCGeneralManager.GenerateNpcRoleBufferData(myNpc);
                    if (null != myNpc.RoleBufferData)
                    {
                        NPCGeneralManager.AddNpcToMap(myNpc);
                        int           safeGridNum = 2;
                        SystemXmlItem npcXmlItem;
                        if (GameManager.SystemNPCsMgr.SystemXmlItemDict.TryGetValue(myNpc.NpcID, out npcXmlItem))
                        {
                            safeGridNum = npcXmlItem.GetIntValue("IsSafe", -1);
                        }
                        if (safeGridNum > 0)
                        {
                            gameMap.SetPartialSafeRegion(myNpc.GridPoint, safeGridNum);
                        }
                    }
                }
                result = true;
            }
            return(result);
        }
示例#2
0
        public static NPC GetNPCFromConfig(int mapCode, int npcID, int toX, int toY, int dir)
        {
            SystemXmlItem systemNPCItem = null;
            NPC           result;

            if (!GameManager.SystemNPCsMgr.SystemXmlItemDict.TryGetValue(npcID, out systemNPCItem))
            {
                result = null;
            }
            else
            {
                GameMap gameMap = null;
                if (!GameManager.MapMgr.DictMaps.TryGetValue(mapCode, out gameMap))
                {
                    result = null;
                }
                else
                {
                    NPC myNpc = new NPC();
                    myNpc.NpcID          = npcID;
                    myNpc.MapCode        = mapCode;
                    myNpc.CurrentPos     = new Point((double)toX, (double)toY);
                    myNpc.CurrentDir     = (Dircetions)dir;
                    myNpc.RoleBufferData = NPCGeneralManager.GenerateNpcRoleBufferData(myNpc);
                    if (null == myNpc.RoleBufferData)
                    {
                        result = null;
                    }
                    else
                    {
                        result = myNpc;
                    }
                }
            }
            return(result);
        }