public void SetAdditionTriggers(XElement xml) { this.AdditionTriggers.Clear(); foreach (var trigger in xml.Elements("trigger")) { ItemTrigger t = new ItemTrigger(); t.Name = Tools.GetXmlAttribute(trigger, "name"); t.ArgvsString = Tools.GetXmlAttribute(trigger, "argvs"); this.AdditionTriggers.Add(t); } }
public ItemTrigger GenerateItemTrigger() { ItemTrigger rst = new ItemTrigger(); rst.Name = this.Name; for (int i = 0; i < this.Params.Count; ++i) //赋值 { ITParam param = this.Params[i]; if (param.Min != -1) { rst.Argvs.Add((Tools.GetRandomInt(param.Min, param.Max)).ToString()); } if (param.Pool != string.Empty) //多选一 { string poolSelect = param.PoolList[Tools.GetRandomInt(0, param.PoolList.Length - 1)]; rst.Argvs.Add(poolSelect); } } return(rst); }
public static ItemTrigger Parse(XElement node) { ItemTrigger rst = new ItemTrigger(); rst.Name = Tools.GetXmlAttribute(node, "name"); if (rst.Name != "AddBuff") { foreach (var s in Tools.GetXmlAttribute(node, "argvs").Split(new char[] { ',' })) { rst.Argvs.Add(s); } } else { rst.Argvs.Add(Tools.GetXmlAttribute(node, "argvs")); } if (node.Attribute("lv") != null) { rst.Level = Tools.GetXmlAttributeInt(node, "lv"); } return(rst); }
/// <summary> /// 给物品增加随机属性 /// </summary> public void AddRandomTrigger() { if (!(this.Type == (int)ItemType.Weapon || this.Type == (int)ItemType.Armor || this.Type == (int)ItemType.Accessories)) { return; //只有装备可以添加随机trigger } //决定物品字样的因素: // 物品等级、物品类型 //字样: // 数值范围、取值范围 List <ITTrigger> triggers = new List <ITTrigger>(); int totalWeight = 0; //寻找满足过滤条件的trigger foreach (var triggerDb in ItemManager.ItemTriggerDb) { if (this.level >= triggerDb.MinLevel && this.level <= triggerDb.MaxLevel || this.Name.Equals(triggerDb.Name)) { foreach (var t in triggerDb.Triggers) { totalWeight += t.Weight; triggers.Add(t); } } } while (true) { ItemTrigger t = null; ITTrigger selectTrigger = null; foreach (var trigger in triggers) //遍历所有的trigger池 { double p = (double)trigger.Weight / (double)totalWeight; //计算这个trigger加到物品上的概率 if (Tools.ProbabilityTest(p)) //如果满足概率 { t = trigger.GenerateItemTrigger(); //生成一个属性 selectTrigger = trigger; break; } } if (t == null) { continue; } bool finish = true; foreach (var myTrigger in this.AdditionTriggers) { if (t.Name == myTrigger.Name && !selectTrigger.HasPool) //主键重了 { finish = false; break; } else if (t.Name == myTrigger.Name && selectTrigger.HasPool && t.Argvs[0] == myTrigger.Argvs[0]) { finish = false; break; } } if (finish) { this.AdditionTriggers.Add(t); break; } } }
static public Item Parse(XElement node) { Item rst = new Item(); rst.myNode = node; rst.Name = Tools.GetXmlAttribute(node, "name"); rst.Info = Tools.GetXmlAttribute(node, "desc"); rst.PicInfo = Tools.GetXmlAttribute(node, "pic"); rst.Type = Tools.GetXmlAttributeInt(node, "type"); rst.level = Tools.GetXmlAttributeInt(node, "level"); if (node.Attribute("price") != null) { rst.price = Tools.GetXmlAttributeInt(node, "price"); } else { rst.price = 0; } /*if (node.Attribute("yuanbao") != null) * { * rst.yuanbao = Tools.GetXmlAttributeInt(node, "yuanbao"); * } * else * { * rst.yuanbao = 0; * }*/ if (node.Attribute("talent") != null) { foreach (var t in Tools.GetXmlAttribute(node, "talent").Split(new char[] { '#' })) { rst.Talent.Add(t); } } if (node.Attribute("cd") != null) { rst.Cooldown = Tools.GetXmlAttributeInt(node, "cd"); } if (Tools.GetXmlElements(node, "require") != null) { rst.Require = ItemRequire.Parse(Tools.GetXmlElements(node, "require")); } if (Tools.GetXmlElements(node, "trigger") != null) { foreach (var trigger in Tools.GetXmlElements(node, "trigger")) { rst.Triggers.Add(ItemTrigger.Parse(trigger)); } } if (node.Attribute("drop") != null) { rst.IsDrop = bool.Parse(Tools.GetXmlAttribute(node, "drop")); } //rst.Trigger = Tools.GetXmlAttribute(node, "trigger"); //rst.Args = Tools.GetXmlAttribute(node, "args"); return(rst); }