public static ITTriggerDb Parse(XElement xml) { ITTriggerDb rst = new ITTriggerDb(); if (xml.Attribute("name") != null) { rst.Name = Tools.GetXmlAttribute(xml, "name"); } if (xml.Attribute("minlevel") != null) { rst.MinLevel = Tools.GetXmlAttributeInt(xml, "minlevel"); } if (xml.Attribute("maxlevel") != null) { rst.MaxLevel = Tools.GetXmlAttributeInt(xml, "maxlevel"); } if (xml.Elements("trigger") != null) { foreach (var node in xml.Elements("trigger")) { rst.Triggers.Add(ITTrigger.Parse(node)); } } return(rst); }
public static ITTrigger Parse(XElement xml) { ITTrigger rst = new ITTrigger(); rst.Name = Tools.GetXmlAttribute(xml, "name"); if (xml.Elements("param") != null) { foreach (var node in xml.Elements("param")) { rst.Params.Add(ITParam.Parse(node)); } } if (xml.Attribute("w") != null) { rst.Weight = Tools.GetXmlAttributeInt(xml, "w"); } 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; } } }