Example #1
0
 /// <summary>
 /// 初始化角色层
 /// </summary>
 void InitializeRoleLayer(XElement root)
 {
     ClearAllRoles();
     //解析NPC配置(包含两部分配置,Info.xml和NPC.xml)
     IEnumerable<XElement> iNPC = root.Element("RoleLayer").Element("NPCs").Elements();
     for (int i = 0; i < iNPC.Count(); i++) {
         XElement xNPC = iNPC.ElementAt(i);
         XElement args = Infos["NPC"].DescendantsAndSelf("NPCs").Elements().Single(X => X.Attribute("ID").Value == xNPC.Attribute("ID").Value);
         NPC npc = new NPC(terrain) {
             ID = (int)args.Attribute("ID"),
             Code = (int)args.Attribute("Code"),
             ArmorCode = (int)args.Attribute("ArmorCode"),
             FullName = xNPC.Attribute("FullName").Value,
             Profession = Professions.NPC,
             DefaultDirection = (Directions)(int)xNPC.Attribute("Direction"),
             Direction = (Directions)(int)xNPC.Attribute("Direction"),
             State = States.Walking,
             Camp = Camps.None,
             LifeMax = 100,
             Life = 100,
             SpaceLayer = (SpaceLayers)(int)xNPC.Attribute("SpaceLayer"),
             Coordinate = new Point((double)xNPC.Attribute("X"), (double)xNPC.Attribute("Y")),
             TacticAI = TacticAIs.None,
             ActionAI = ActionAIs.Simple,
             FullNameColor = Colors.Magenta,
         };
         //加载说话内容
         IEnumerable<XElement> talks = args.DescendantsAndSelf("Talks").Elements();
         for (int j = 0; j < talks.Count(); j++) {
             npc.AddTalk(new Talk() { Content = talks.ElementAt(j).Attribute("Value").Value, Duration = (int)talks.ElementAt(j).Attribute("Duration") });
         }
         //加载剧情内容
         IEnumerable<XElement> dramas = args.DescendantsAndSelf("Dramas").Elements();
         for (int j = 0; j < dramas.Count(); j++) {
             npc.AddDrama((int)dramas.ElementAt(j).Attribute("Avatar"), string.Format("{0}:{1}", dramas.ElementAt(j).Attribute("Name").Value, dramas.ElementAt(j).Attribute("Content").Value));
         }
         SetSpriteVisible(npc, npc.InSight(leader));
         AddRole(npc, new RoleAddedEventArgs() {
             RegisterDisposedEvent = (bool)args.Attribute("RegisterDisposedEvent"),
             RegisterIntervalTriggerEvent = (bool)args.Attribute("RegisterIntervalTriggerEvent"),
             RegisterActionTriggerEvent = (bool)args.Attribute("RegisterActionTriggerEvent"),
             RegisterDoAttackEvent = (bool)args.Attribute("RegisterDoAttackEvent"),
             RegisterDoCastingEvent = (bool)args.Attribute("RegisterDoCastingEvent"),
             RegisterPositionChangedEvent = (bool)args.Attribute("RegisterPositionChangedEvent"),
             RegisterLifeChangedEvent = (bool)args.Attribute("RegisterLifeChangedEvent"),
         });
     }
 }