public bool ReadJs(Dictionary <string, object> dic) { if (dic != null) { _Type = Convert.ToInt32(dic["type"]); _Live = Convert.ToUInt16(dic["live"]); _Product = Convert.ToUInt16(dic["product"]); _Name = dic["name"].ToString(); ReadListI32(dic["options"], ref _Options); ReadListU16(dic["survivor"], ref _Survivor); ReadListU16(dic["food"], ref _Food); ReadListU16(dic["equip"], ref _Equip); if (dic.ContainsKey("equiplst")) { _GenEquip = new EquipGenList(); _GenEquip.ReadJs((Dictionary <string, object>)dic["equiplst"]); } else { _GenEquip = null; } return(true); } return(false); }
/// <summary> /// 根据装备生成列表,计算生成权重,随机出生成的装备id /// </summary> /// <param name="lst">装备生成列表,在建筑配置中</param> /// <returns></returns> private int CalcEquipWeight(ref EquipGenList lst) { if (lst != null) { int w = 0; foreach (var t in _EquipTemplates) { if (lst.ContainsEquip(Convert.ToUInt16(t.Key))) { w += lst.Ratio * t.Value.Weight; } else { w += t.Value.Weight; } } int r = Random.Range(1, w); foreach (var t in _EquipTemplates) { if (lst.ContainsEquip(Convert.ToUInt16(t.Key))) { w += lst.Ratio * t.Value.Weight; } else { w += t.Value.Weight; } if (w >= r) { return(t.Key); } } return(lst.EquipList[Random.Range(0, lst.EquipList.Length)]); } return(0); }