Exemplo n.º 1
0
        static public void Init()
        {
            triggerList.Clear();
            foreach (string triggerFile in GameProject.GetFiles("timetrigger"))
            {
                XElement xmlRoot = Tools.LoadXml("Scripts/" + triggerFile);
                foreach (XElement times in xmlRoot.Elements("time"))
                {
                    int         day         = Tools.GetXmlAttributeInt(times, "day");
                    string      storyDialog = Tools.GetXmlAttribute(times, "story");
                    TimeTrigger tt          = new TimeTrigger();
                    tt.time  = day;
                    tt.story = storyDialog;

                    if (times.Element("condition") != null)
                    {
                        foreach (var c in times.Elements("condition"))
                        {
                            EventCondition cd = EventCondition.Parse(c);
                            tt.conditions.Add(cd);
                        }
                    }
                    triggerList.Add(tt);
                }
            }
        }
Exemplo n.º 2
0
        static public Event Parse(XElement node)
        {
            Event aEvent = new Event();

            //推荐进入等级
            if (node.Attribute("lv") != null)
            {
                aEvent.lv = Tools.GetXmlAttributeInt(node, "lv");
            }
            if (node.Attribute("image") != null)
            {
                aEvent.image = Tools.GetXmlAttribute(node, "image");
            }
            else
            {
                aEvent.image = "";
            }
            if (node.Attribute("description") != null)
            {
                aEvent.description = Tools.GetXmlAttribute(node, "description");
            }

            aEvent.Value = Tools.GetXmlAttribute(node, "value");
            aEvent.Type  = Tools.GetXmlAttribute(node, "type");
            if (node.Attribute("probability") == null)
            {
                aEvent.probability = 100;
            }
            else
            {
                aEvent.probability = Tools.GetXmlAttributeInt(node, "probability");
            }

            if (node.Attribute("repeat") != null && node.Attribute("repeat").Value == "once")
            {
                aEvent.RepeatType = EventRepeatType.Once;
            }
            else
            {
                aEvent.RepeatType = EventRepeatType.Unlimited;
            }
            aEvent.conditions = new List <EventCondition>();
            foreach (XElement eventCondition in node.Elements("condition"))
            {
                EventCondition eventCont = new EventCondition();
                eventCont.type  = Tools.GetXmlAttribute(eventCondition, "type");
                eventCont.value = Tools.GetXmlAttribute(eventCondition, "value");
                if (eventCondition.Attribute("number") != null)
                {
                    eventCont.number = Tools.GetXmlAttributeInt(eventCondition, "number");
                }
                aEvent.conditions.Add(eventCont);
            }
            return(aEvent);
        }
Exemplo n.º 3
0
        public static EventCondition Parse(XElement node)
        {
            EventCondition rst = new EventCondition();

            rst.type  = Tools.GetXmlAttribute(node, "type");
            rst.value = Tools.GetXmlAttribute(node, "value");
            if (node.Attribute("number") != null)
            {
                rst.number = Tools.GetXmlAttributeInt(node, "number");
            }
            return(rst);
        }
        public static bool judge(EventCondition condition)
        {
            //XXX必须在队中的判定,按照roleName判断,非roleKey
            if (condition.type == "in_team")
            {
                if (!RuntimeData.Instance.NameInTeam(condition.value))
                {
                    return(false);
                }
            }

            //XXX必须不在队中的判定,按照roleName判断,非roleKey
            if (condition.type == "not_in_team")
            {
                if (RuntimeData.Instance.NameInTeam(condition.value))
                {
                    return(false);
                }
            }

            //XXX必须在队中的判定,按照roleKey
            if (condition.type == "key_in_team")
            {
                if (!RuntimeData.Instance.InTeam(condition.value))
                {
                    return(false);
                }
            }

            //XXX必须不在队中的判定,按照roleKey
            if (condition.type == "key_not_in_team")
            {
                if (RuntimeData.Instance.InTeam(condition.value))
                {
                    return(false);
                }
            }

            //XXX剧情必须已经完成的判定,有key
            if (condition.type == "should_finish")
            {
                if (!RuntimeData.Instance.KeyValues.ContainsKey(condition.value))
                {
                    return(false);
                }
            }

            //必须没有完成,没key
            if (condition.type == "should_not_finish")
            {
                if (RuntimeData.Instance.KeyValues.ContainsKey(condition.value))
                {
                    return(false);
                }
            }

            if (condition.type == "has_time_key")
            {
                if (!RuntimeData.Instance.KeyValues.ContainsKey(RuntimeData.TIMEKEY_PREF + condition.value))
                {
                    return(false);
                }
            }

            if (condition.type == "not_has_time_key")
            {
                if (RuntimeData.Instance.KeyValues.ContainsKey(RuntimeData.TIMEKEY_PREF + condition.value))
                {
                    return(false);
                }
            }

            if (condition.type == "not_in_time")
            {
                string[] times = condition.value.Split(new char[] { '#' });
                foreach (var t in times)
                {
                    if (CommonSettings.IsChineseTime(RuntimeData.Instance.Date, t[0]))
                    {
                        return(false);
                    }
                }
            }

            if (condition.type == "in_time")
            {
                string[] times = condition.value.Split(new char[] { '#' });
                foreach (var t in times)
                {
                    if (CommonSettings.IsChineseTime(RuntimeData.Instance.Date, t[0]))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            //必须有XXX银子
            if (condition.type == "have_money")
            {
                if (RuntimeData.Instance.Money < int.Parse(condition.value))
                {
                    return(false);
                }
            }

            //必须有XXX物品,XXX个(默认1个。)
            if (condition.type == "have_item")
            {
                int number = 0;
                foreach (var s in RuntimeData.Instance.Items)
                {
                    if (s.Name == condition.value)
                    {
                        number++;
                    }
                }

                if (number < condition.number || number == 0)
                {
                    return(false);
                }
            }

            //游戏模式
            if (condition.type == "game_mode")
            {
                if (RuntimeData.Instance.GameMode != condition.value)
                {
                    return(false);
                }
            }

            //游戏已经进行了XXX天以上
            if (condition.type == "exceed_day")
            {
                if ((RuntimeData.Instance.Date - DateTime.ParseExact("0001-01-01 00:00:00", "yyyy-MM-dd HH:mm:ss", CultureInfo.CurrentCulture)).Days <= int.Parse(condition.value))
                {
                    return(false);
                }
            }

            //游戏还没进行XXX天
            if (condition.type == "not_exceed_day")
            {
                if ((RuntimeData.Instance.Date - DateTime.ParseExact("0001-01-01 00:00:00", "yyyy-MM-dd HH:mm:ss", CultureInfo.CurrentCulture)).Days > int.Parse(condition.value))
                {
                    return(false);
                }
            }

            //属于/不属于某个门派
            if (condition.type == "in_menpai")
            {
                if (RuntimeData.Instance.Menpai != condition.value)
                {
                    return(false);
                }
            }
            if (condition.type == "not_in_menpai")
            {
                if (RuntimeData.Instance.Menpai == condition.value)
                {
                    return(false);
                }
            }
            if (condition.type == "has_menpai")
            {
                return(RuntimeData.Instance.Menpai != "");
            }

            //是不是在某个周目内
            if (condition.type == "in_round")
            {
                if (RuntimeData.Instance.Round != int.Parse(condition.value))
                {
                    return(false);
                }
            }
            if (condition.type == "not_in_round")
            {
                if (RuntimeData.Instance.Round == int.Parse(condition.value))
                {
                    return(false);
                }
            }

            //一定概率触发
            if (condition.type == "probability")
            {
                if (!Tools.ProbabilityTest((double)int.Parse(condition.value) / 100.0f))
                {
                    return(false);
                }
            }

            //道德
            if (condition.type == "daode_more_than")
            {
                return(RuntimeData.Instance.Daode >= int.Parse(condition.value));
            }
            if (condition.type == "daode_less_than")
            {
                return(RuntimeData.Instance.Daode < int.Parse(condition.value));
            }

            //好感
            if (condition.type == "haogan_more_than")
            {
                return(RuntimeData.Instance.Haogan >= int.Parse(condition.value));
            }
            if (condition.type == "haogan_less_than")
            {
                return(RuntimeData.Instance.Haogan < int.Parse(condition.value));
            }

            //XX武功在多少级(含)以上
            if (condition.type == "skill_more_than")
            {
                string[] paras     = condition.value.Split(new char[] { '#' });
                string   roleKey   = paras[0];
                string   skillName = paras[1];
                int      level     = int.Parse(paras[2]);
                foreach (var r in RuntimeData.Instance.Team)
                {
                    if (r.Key == roleKey)
                    {
                        foreach (var s in r.Skills)
                        {
                            if (s.Skill.Name == skillName && s.Level >= level)
                            {
                                return(true);
                            }
                        }
                        foreach (var s in r.InternalSkills)
                        {
                            if (s.Skill.Name == skillName && s.Level >= level)
                            {
                                return(true);
                            }
                        }
                    }
                }
                return(false);
            }
            //XX武功在多少级以下
            if (condition.type == "skill_less_than")
            {
                string[] paras     = condition.value.Split(new char[] { '#' });
                string   roleKey   = paras[0];
                string   skillName = paras[1];
                int      level     = int.Parse(paras[2]);
                foreach (var r in RuntimeData.Instance.Team)
                {
                    if (r.Key == roleKey)
                    {
                        bool find = false;
                        foreach (var s in r.Skills)
                        {
                            if (s.Skill.Name == skillName)
                            {
                                find = true;
                            }
                            if (s.Skill.Name == skillName && s.Level < level)
                            {
                                return(true);
                            }
                        }
                        foreach (var s in r.InternalSkills)
                        {
                            if (s.Skill.Name == skillName)
                            {
                                find = true;
                            }
                            if (s.Skill.Name == skillName && s.Level < level)
                            {
                                return(true);
                            }
                        }
                        if (!find)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }

            //XX在多少级(含)以上
            if (condition.type == "level_greater_than")
            {
                string[] paras   = condition.value.Split(new char[] { '#' });
                string   roleKey = paras[0];
                int      level   = int.Parse(paras[1]);
                foreach (var r in RuntimeData.Instance.Team)
                {
                    if (r.Key == roleKey && r.Level >= level)
                    {
                        return(true);
                    }
                }
                return(false);
            }

            //XX定力在XX以上
            if (condition.type == "dingli_greater_than")
            {
                string[] paras   = condition.value.Split(new char[] { '#' });
                string   roleKey = paras[0];
                int      level   = int.Parse(paras[1]);
                foreach (var r in RuntimeData.Instance.Team)
                {
                    if (r.Key == roleKey && r.Attributes["dingli"] >= level)
                    {
                        return(true);
                    }
                }
                return(false);
            }

            //XX悟性在XX以上
            if (condition.type == "wuxing_greater_than")
            {
                string[] paras   = condition.value.Split(new char[] { '#' });
                string   roleKey = paras[0];
                int      level   = int.Parse(paras[1]);
                foreach (var r in RuntimeData.Instance.Team)
                {
                    if (r.Key == roleKey && r.Attributes["wuxing"] >= level)
                    {
                        return(true);
                    }
                }
                return(false);
            }

            //XX定力在XX以下
            if (condition.type == "dingli_less_than")
            {
                string[] paras   = condition.value.Split(new char[] { '#' });
                string   roleKey = paras[0];
                int      level   = int.Parse(paras[1]);
                foreach (var r in RuntimeData.Instance.Team)
                {
                    if (r.Key == roleKey && r.Attributes["dingli"] < level)
                    {
                        return(true);
                    }
                }
                return(false);
            }

            //XX悟性在XX以上
            if (condition.type == "wuxing_less_than")
            {
                string[] paras   = condition.value.Split(new char[] { '#' });
                string   roleKey = paras[0];
                int      level   = int.Parse(paras[1]);
                foreach (var r in RuntimeData.Instance.Team)
                {
                    if (r.Key == roleKey && r.Attributes["wuxing"] < level)
                    {
                        return(true);
                    }
                }
                return(false);
            }

            //XX身法在XX以上
            if (condition.type == "shenfa_greater_than")
            {
                string[] paras   = condition.value.Split(new char[] { '#' });
                string   roleKey = paras[0];
                int      level   = int.Parse(paras[1]);
                foreach (var r in RuntimeData.Instance.Team)
                {
                    if (r.Key == roleKey && r.Attributes["shenfa"] >= level)
                    {
                        return(true);
                    }
                }
                return(false);
            }

            //队伍中队友达到了X人
            if (condition.type == "friendCount")
            {
                if (RuntimeData.Instance.Team.Count >= int.Parse(condition.value))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            //江湖排名(武道大会)
            if (condition.type == "rank")
            {
                if (RuntimeData.Instance.Rank == -1)
                {
                    return(false);
                }
                else
                {
                    return(RuntimeData.Instance.Rank <= int.Parse(condition.value));
                }
            }
            return(true);
        }
Exemplo n.º 5
0
        static public void Init()
        {
            Towers.Clear();
            Conditions.Clear();
            BonusItems.Clear();
            TowerDesc.Clear();
            foreach (var mapXmlFile in GameProject.GetFiles("tower"))
            {
                XElement xmlRoot = Tools.LoadXml("Scripts/" + mapXmlFile);
                foreach (XElement node in xmlRoot.Elements("tower"))
                {
                    string key    = Tools.GetXmlAttribute(node, "key");
                    int    number = Tools.GetXmlAttributeInt(node, "number");
                    if (node.Attribute("desc") != null)
                    {
                        TowerDesc[key] = Tools.GetXmlAttribute(node, "desc");
                    }
                    List <Battle> battles = new List <Battle>();
                    battles.Clear();
                    battles.Capacity = number;
                    foreach (XElement map in node.Element("maps").Elements("map"))
                    {
                        String battleKey = Tools.GetXmlAttribute(map, "key");
                        int    index     = Tools.GetXmlAttributeInt(map, "index");
                        battles.Add(BattleManager.GetBattle(battleKey));

                        //处理奖励物品
                        List <BonusItem> items = new List <BonusItem>();
                        items.Clear();
                        foreach (XElement item in map.Elements("item"))
                        {
                            string itemKey    = Tools.GetXmlAttribute(item, "key");
                            int    itemNumber = 0;
                            double itemProb   = 1.0;
                            if (item.Attribute("number") != null)
                            {
                                itemNumber = Tools.GetXmlAttributeInt(item, "number");
                            }
                            if (item.Attribute("probability") != null)
                            {
                                itemProb = (double)Tools.GetXmlAttributeFloat(item, "probability");
                            }

                            items.Add(new BonusItem(itemKey, itemNumber, itemProb));
                        }
                        BonusItems.Add(battleKey, items);
                    }
                    Towers.Add(key, battles);

                    //开启天关的条件
                    List <EventCondition> conditions = new List <EventCondition>();
                    conditions.Clear();
                    foreach (XElement condition in node.Element("conditions").Elements("condition"))
                    {
                        EventCondition cond = new EventCondition();
                        cond.type  = Tools.GetXmlAttribute(condition, "type");
                        cond.value = Tools.GetXmlAttribute(condition, "value");
                        if (condition.Attribute("number") != null)
                        {
                            cond.number = Tools.GetXmlAttributeInt(condition, "number");
                        }
                        conditions.Add(cond);
                    }
                    Conditions.Add(key, conditions);
                }
            }
        }