public AffixItemItem() { rarity = ((PoMDataLoader.raritiesItem?.Length ?? 0) == 0) ? new ItemNone() : PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(ItemNone)]]; affixes = new List <Affix>(); prefixes = new List <Affix>(); suffixes = new List <Affix>(); }
/// <summary> /// Completely rerolls rarity and affixes. /// </summary> /// <param name="item"></param> public void RollItem(Item item) { ClearAffixes(item); rarity = PoMAffixController.RollRarity(item); RollAffixes(item); UpdateName(item); }
public override void Load(Item item, TagCompound tag) { string rarityModName = tag.GetString("rarityMod"); Mod mod = ModLoader.GetMod(rarityModName); if (mod == null) { PathOfModifiers.Instance.Logger.Warn($"Mod '{rarityModName}' not found"); return; } string rarityFullName = tag.GetString("rarityFullName"); Type type = mod.Code.GetType(rarityFullName); if (type == null) { PathOfModifiers.Instance.Logger.Warn($"Rarity '{type.FullName}' doesn't exist"); return; } if (type.IsDefined(typeof(DisableAffix), false)) { PathOfModifiers.Instance.Logger.Warn($"Rarity '{type.FullName}' is disabled"); return; } rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[type]]; int affixCount = tag.GetAsInt("affixCount"); TagCompound affixTag; Affix affix; for (int i = 0; i < affixCount; i++) { affixTag = tag.GetCompound(i.ToString()); string affixModName = affixTag.GetString("affixMod"); mod = ModLoader.GetMod(affixModName); if (mod == null) { PathOfModifiers.Instance.Logger.Warn($"Mod '{affixModName}' not found"); continue; } string affixFullName = affixTag.GetString("affixFullName"); type = mod.Code.GetType(affixFullName); if (type == null) { PathOfModifiers.Instance.Logger.Warn($"Affix '{affixFullName}' doesn't exist"); continue; } if (type.IsDefined(typeof(DisableAffix), false)) { PathOfModifiers.Instance.Logger.Warn($"Affix '{affixFullName}' is disabled"); continue; } affix = PoMDataLoader.affixesItem[PoMDataLoader.affixItemMap[type]].Clone(); affix.Load(affixTag, item); AddAffix(affix, item); } UpdateName(item); }
/// <summary> /// Returns a valid rarity for the item. /// </summary> public static RarityItem RollRarity(Item item) { Tuple <RarityItem, double>[] tuples = PoMDataLoader.raritiesItem .Where(r => r.Weight > 0 && r.CanBeRolled(item)) .Select(r => new Tuple <RarityItem, double>(r, r.Weight)) .ToArray(); WeightedRandom <RarityItem> weightedRandom = new WeightedRandom <RarityItem>(Main.rand, tuples); RarityItem rarity = weightedRandom; return(rarity); }
/// <summary> /// Roll item if it's rollable. /// </summary> public bool TryRollItem(Item item) { if (IsRollable(item)) { RollItem(item); return(true); } else { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(ItemNone)]]; return(false); } }
public void RemoveAll(Item item) { ClearAffixes(item); Type rarityType = rarity.GetType(); if (rarityType == typeof(WeaponUncommon) || rarityType == typeof(WeaponRare) || rarityType == typeof(WeaponEpic) || rarityType == typeof(WeaponLegendary)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(WeaponCommon)]]; } else if (rarityType == typeof(ArmorUncommon) || rarityType == typeof(ArmorRare) || rarityType == typeof(ArmorEpic) || rarityType == typeof(ArmorLegendary)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(ArmorCommon)]]; } else if (rarityType == typeof(AccessoryUncommon) || rarityType == typeof(AccessoryRare) || rarityType == typeof(AccessoryEpic) || rarityType == typeof(AccessoryLegendary)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(AccessoryCommon)]]; } UpdateName(item); }
public override void NetReceive(Item item, BinaryReader reader) { try { rarity = PoMDataLoader.raritiesItem[reader.ReadInt32()]; int affixCount = reader.ReadByte(); Affix affix; for (int i = 0; i < affixCount; i++) { affix = PoMDataLoader.affixesItem[reader.ReadInt32()].Clone(); affix.NetReceive(item, reader); AddAffix(affix, item); } UpdateName(item); } catch (Exception e) { mod.Logger.Error(e.ToString()); } }
public static void ReceiveDataMaps(BinaryReader reader) { try { #region Item Affixes int length = reader.ReadInt32(); PathOfModifiers.Instance.Logger.Debug($"Receiving Item Affix Map Length: {length} "); PathOfModifiers.Instance.Logger.Debug($"Loaded Item Affix Map Length: {affixItemMap.Count} "); Dictionary <Type, int> newAffixItemMap = new Dictionary <Type, int>(length); Affixes.Items.Affix[] newAffixesItem = new Affixes.Items.Affix[length]; Type type; Mod mod; for (int i = 0; i < length; i++) { string modString = reader.ReadString(); string typeString = reader.ReadString(); mod = ModLoader.GetMod(modString); type = mod.Code.GetType(typeString, true); PathOfModifiers.Instance.Logger.Debug($"ReceiveMaps: {i} / {type.FullName} from mod {mod}"); newAffixesItem[i] = affixesItem[affixItemMap[type]]; newAffixItemMap.Add(type, i); } affixItemMap = newAffixItemMap; affixesItem = newAffixesItem; #endregion #region Item Rarities length = reader.ReadInt32(); PathOfModifiers.Instance.Logger.Debug($"Receiving Item Rarity Map Length: {length} "); PathOfModifiers.Instance.Logger.Debug($"Loaded Item Rarity Map Length: {rarityItemMap.Count} "); Dictionary <Type, int> newRarityMapItem = new Dictionary <Type, int>(length); RarityItem[] newRaritiesItem = new RarityItem[length]; for (int i = 0; i < length; i++) { mod = ModLoader.GetMod(reader.ReadString()); type = mod.Code.GetType(reader.ReadString(), true); newRaritiesItem[i] = raritiesItem[rarityItemMap[type]]; newRarityMapItem.Add(type, i); } rarityItemMap = newRarityMapItem; raritiesItem = newRaritiesItem; #endregion #region NPC Affixes length = reader.ReadInt32(); PathOfModifiers.Instance.Logger.Debug($"Receiving NPC Affix Map Length: {length} "); PathOfModifiers.Instance.Logger.Debug($"Loaded NPC Affix Map Length: {affixNPCMap.Count} "); Dictionary <Type, int> newAffixNPCMap = new Dictionary <Type, int>(length); Affixes.NPCs.Affix[] newAffixesNPC = new Affixes.NPCs.Affix[length]; for (int i = 0; i < length; i++) { mod = ModLoader.GetMod(reader.ReadString()); type = mod.Code.GetType(reader.ReadString(), true); PathOfModifiers.Instance.Logger.Debug($"ReceiveMaps: {i} / {type.FullName} from mod {mod}"); newAffixesNPC[i] = affixesNPC[affixNPCMap[type]]; newAffixNPCMap.Add(type, i); } affixNPCMap = newAffixNPCMap; affixesNPC = newAffixesNPC; #endregion #region NPC Rarities length = reader.ReadInt32(); PathOfModifiers.Instance.Logger.Debug($"Receiving NPC Rarity Map Length: {length} "); PathOfModifiers.Instance.Logger.Debug($"Loaded NPC Rarity Map Length: {rarityNPCMap.Count} "); Dictionary <Type, int> newRarityNPCMap = new Dictionary <Type, int>(length); RarityNPC[] newRaritiesNPC = new RarityNPC[length]; for (int i = 0; i < length; i++) { mod = ModLoader.GetMod(reader.ReadString()); type = mod.Code.GetType(reader.ReadString(), true); newRaritiesNPC[i] = raritiesNPC[rarityNPCMap[type]]; newRarityNPCMap.Add(type, i); } rarityNPCMap = newRarityNPCMap; raritiesNPC = newRaritiesNPC; #endregion #region Map Generators length = reader.ReadInt32(); Dictionary <Type, int> newGenratorMap = new Dictionary <Type, int>(length); Generator[] newGenerators = new Generator[length]; for (int i = 0; i < length; i++) { mod = ModLoader.GetMod(reader.ReadString()); type = mod.Code.GetType(reader.ReadString(), true); newGenerators[i] = generators[generatorMap[type]]; newGenratorMap.Add(type, i); } #endregion #region Maps length = reader.ReadInt32(); Dictionary <Type, int> newMapMap = new Dictionary <Type, int>(length); Map[] newMaps = new Map[length]; for (int i = 0; i < length; i++) { mod = ModLoader.GetMod(reader.ReadString()); type = mod.Code.GetType(reader.ReadString(), true); newMaps[i] = maps[mapMap[type]]; newMapMap.Add(type, i); } mapMap = newMapMap; maps = newMaps; #endregion } catch (Exception e) { PathOfModifiers.Instance.Logger.Fatal(e.ToString()); } }
public bool RaiseRarity(Item item) { Type rarityType = rarity.GetType(); bool raised = false; if (rarityType == typeof(WeaponCommon)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(WeaponUncommon)]]; raised = true; } else if (rarityType == typeof(WeaponUncommon)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(WeaponRare)]]; raised = true; } else if (rarityType == typeof(WeaponRare)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(WeaponEpic)]]; raised = true; } else if (rarityType == typeof(WeaponEpic)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(WeaponLegendary)]]; raised = true; } else if (rarityType == typeof(ArmorCommon)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(ArmorUncommon)]]; raised = true; } else if (rarityType == typeof(ArmorUncommon)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(ArmorRare)]]; raised = true; } else if (rarityType == typeof(ArmorRare)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(ArmorEpic)]]; raised = true; } else if (rarityType == typeof(ArmorEpic)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(ArmorLegendary)]]; raised = true; } else if (rarityType == typeof(AccessoryCommon)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(AccessoryUncommon)]]; raised = true; } else if (rarityType == typeof(AccessoryUncommon)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(AccessoryRare)]]; raised = true; } else if (rarityType == typeof(AccessoryRare)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(AccessoryEpic)]]; raised = true; } else if (rarityType == typeof(AccessoryEpic)) { rarity = PoMDataLoader.raritiesItem[PoMDataLoader.rarityItemMap[typeof(AccessoryLegendary)]]; raised = true; } if (raised) { UpdateName(item); } return(raised); }