public static uint GetExplicitDiscoverySpell(uint spellId, Player player) { // explicit discovery spell chances (always success if case exist) // in this case we have both skill and spell var tab = SkillDiscoveryStorage.LookupByKey((int)spellId); if (tab.Empty()) { return(0); } var bounds = Global.SpellMgr.GetSkillLineAbilityMapBounds(spellId); uint skillvalue = !bounds.Empty() ? (uint)player.GetSkillValue((SkillType)bounds.FirstOrDefault().SkillLine) : 0; float full_chance = 0; foreach (var item_iter in tab) { if (item_iter.reqSkillValue <= skillvalue) { if (!player.HasSpell(item_iter.spellId)) { full_chance += item_iter.chance; } } } float rate = full_chance / 100.0f; float roll = (float)RandomHelper.randChance() * rate; // roll now in range 0..full_chance foreach (var item_iter in tab) { if (item_iter.reqSkillValue > skillvalue) { continue; } if (player.HasSpell(item_iter.spellId)) { continue; } if (item_iter.chance > roll) { return(item_iter.spellId); } roll -= item_iter.chance; } return(0); }
public static uint GetSkillDiscoverySpell(uint skillId, uint spellId, Player player) { uint skillvalue = skillId != 0 ? (uint)player.GetSkillValue((SkillType)skillId) : 0; // check spell case var tab = SkillDiscoveryStorage.LookupByKey((int)spellId); if (!tab.Empty()) { foreach (var item_iter in tab) { if (RandomHelper.randChance(item_iter.chance * WorldConfig.GetFloatValue(WorldCfg.RateSkillDiscovery)) && item_iter.reqSkillValue <= skillvalue && !player.HasSpell(item_iter.spellId)) { return(item_iter.spellId); } } return(0); } if (skillId == 0) { return(0); } // check skill line case tab = SkillDiscoveryStorage.LookupByKey(-(int)skillId); if (!tab.Empty()) { foreach (var item_iter in tab) { if (RandomHelper.randChance(item_iter.chance * WorldConfig.GetFloatValue(WorldCfg.RateSkillDiscovery)) && item_iter.reqSkillValue <= skillvalue && !player.HasSpell(item_iter.spellId)) { return(item_iter.spellId); } } return(0); } return(0); }
public static bool HasDiscoveredAllSpells(uint spellId, Player player) { var tab = SkillDiscoveryStorage.LookupByKey((int)spellId); if (tab.Empty()) { return(true); } foreach (var item_iter in tab) { if (!player.HasSpell(item_iter.spellId)) { return(false); } } return(true); }