private static void ApplyCombatSpell(Item item, ItemEnchantmentEffect effect) { var spell = SpellHandler.Get(effect.Misc); if (spell == null) { ContentMgr.OnInvalidClientData("Enchantment Effect {0} had invalid SpellId: {1}", effect, (SpellId)effect.Misc); } else { item.OwningCharacter.AddProcHandler(new ItemHitProcHandler(item, spell)); } }
public override void Convert(byte[] rawData) { #region Parsing int currentIndex = 0; var spell = new Spell { Id = GetUInt32(rawData, currentIndex++), SpellId = (SpellId)GetInt32(rawData, 0) }; try { spell.Category = GetUInt32(rawData, currentIndex++); // 1+ spell.DispelType = (DispelType)GetUInt32(rawData, currentIndex++); // 2+ spell.Mechanic = (SpellMechanic)GetUInt32(rawData, currentIndex++); // 3+ spell.Attributes = (SpellAttributes)GetUInt32(rawData, currentIndex++); // 4+ spell.AttributesEx = (SpellAttributesEx)GetUInt32(rawData, currentIndex++); // 5+ spell.AttributesExB = (SpellAttributesExB)GetUInt32(rawData, currentIndex++); // 6+ spell.AttributesExC = (SpellAttributesExC)GetUInt32(rawData, currentIndex++); // 7+ spell.AttributesExD = (SpellAttributesExD)GetUInt32(rawData, currentIndex++); // 8+ spell.AttributesExE = (SpellAttributesExE)GetUInt32(rawData, currentIndex++); // 9 spell.AttributesExF = (SpellAttributesExF)GetUInt32(rawData, currentIndex++); // 10 spell.RequiredShapeshiftMask = (ShapeshiftMask)GetUInt32(rawData, currentIndex++); // 11- spell.Unk_322_1 = GetUInt32(rawData, currentIndex++); // 12 spell.ExcludeShapeshiftMask = (ShapeshiftMask)GetUInt32(rawData, currentIndex++); // 13- spell.Unk_322_2 = GetUInt32(rawData, currentIndex++); // 14 spell.TargetFlags = (SpellTargetFlags)GetUInt32(rawData, currentIndex++); // 15+ spell.Unk_322_3 = GetUInt32(rawData, currentIndex++); // 16 spell.CreatureMask = (CreatureMask)GetUInt32(rawData, currentIndex++); // 17- spell.RequiredSpellFocus = (SpellFocus)GetUInt32(rawData, currentIndex++); // 18- 0 spell.FacingFlags = (SpellFacingFlags)GetUInt32(rawData, currentIndex++); // 19- spell.RequiredCasterAuraState = (AuraState)GetUInt32(rawData, currentIndex++); // 20+- spell.RequiredTargetAuraState = (AuraState)GetUInt32(rawData, currentIndex++); // 21+- spell.ExcludeCasterAuraState = (AuraState)GetUInt32(rawData, currentIndex++); // 22+- spell.ExcludeTargetAuraState = (AuraState)GetUInt32(rawData, currentIndex++); // 23+- spell.RequiredCasterAuraId = (SpellId)GetUInt32(rawData, currentIndex++); // 24+- spell.RequiredTargetAuraId = (SpellId)GetUInt32(rawData, currentIndex++); // 25+- spell.ExcludeCasterAuraId = (SpellId)GetUInt32(rawData, currentIndex++); // 26+- spell.ExcludeTargetAuraId = (SpellId)GetUInt32(rawData, currentIndex++); // 27+- int castTimeIndex = GetInt32(rawData, currentIndex++); // 28+ if (castTimeIndex > 0) { if (!mappeddbcCastTimeReader.Entries.TryGetValue(castTimeIndex, out spell.CastDelay)) { ContentMgr.OnInvalidClientData("DBC Spell \"{0}\" referred to invalid CastTime-Entry: {1}", spell.Name, castTimeIndex); } } spell.CooldownTime = Math.Max(0, GetInt32(rawData, currentIndex++) - (int)spell.CastDelay); // 29+ spell.categoryCooldownTime = GetInt32(rawData, currentIndex++); // 30+- spell.InterruptFlags = (InterruptFlags)GetUInt32(rawData, currentIndex++); // 31+- spell.AuraInterruptFlags = (AuraInterruptFlags)GetUInt32(rawData, currentIndex++); // 32+- spell.ChannelInterruptFlags = (ChannelInterruptFlags)GetUInt32(rawData, currentIndex++); // 33+- spell.ProcTriggerFlagsProp = (ProcTriggerFlags)GetUInt32(rawData, currentIndex++); // 34++- spell.ProcChance = GetUInt32(rawData, currentIndex++); // 35++- spell.ProcCharges = GetInt32(rawData, currentIndex++); // 36++- spell.MaxLevel = GetInt32(rawData, currentIndex++); // 37+ spell.BaseLevel = GetInt32(rawData, currentIndex++); // 38+ spell.Level = GetInt32(rawData, currentIndex++); // 30+ var durationIndex = GetInt32(rawData, currentIndex++); // 40+ if (durationIndex > 0) { if (!mappeddbcDurationReader.Entries.TryGetValue(durationIndex, out spell.Durations)) { ContentMgr.OnInvalidClientData("DBC Spell \"{0}\" referred to invalid Duration-Entry: {1}", spell.Name, durationIndex); } } spell.PowerType = (PowerType)GetUInt32(rawData, currentIndex++); // 41+ always mana spell.PowerCost = GetInt32(rawData, currentIndex++); // 42+ spell.PowerCostPerlevel = GetInt32(rawData, currentIndex++); // 43+ spell.PowerPerSecond = GetInt32(rawData, currentIndex++); // 44+ spell.PowerPerSecondPerLevel = GetInt32(rawData, currentIndex++); // 45- var rangeIndex = GetInt32(rawData, currentIndex++); // 46+ if (rangeIndex > 0) { if (!mappeddbcRangeReader.Entries.TryGetValue(rangeIndex, out spell.Range)) { ContentMgr.OnInvalidClientData("DBC Spell \"{0}\" referred to invalid Range-Entry: {1}", spell.Name, rangeIndex); } } spell.ProjectileSpeed = GetFloat(rawData, currentIndex++); // 47+ spell.ModalNextSpell = (SpellId)GetUInt32(rawData, currentIndex++); // 48- spell.MaxStackCount = GetInt32(rawData, currentIndex++); // 49+ 1 spell.RequiredToolIds = new uint[2]; // 50-51+- for (var i = 0; i < spell.RequiredToolIds.Length; i++) { spell.RequiredToolIds[i] = GetUInt32(rawData, currentIndex++); } List <ItemStackDescription> reagents = null; int reagentStart = currentIndex; for (int i = 0; i < 8; i++) //52-59 - spell.Reagents = ItemStackDescription.EmptyArray; { ReadReagent(rawData, reagentStart, i, out currentIndex, ref reagents); } if (reagents != null) { spell.Reagents = reagents.ToArray(); } else { spell.Reagents = ItemStackDescription.EmptyArray; } spell.RequiredItemClass = (ItemClass)GetUInt32(rawData, currentIndex++); //68+ spell.RequiredItemClass = ItemClass.None; if (spell.RequiredItemClass < 0) { spell.RequiredItemClass = ItemClass.None; } spell.RequiredItemSubClassMask = (ItemSubClassMask)GetUInt32(rawData, currentIndex++); // 69+ spell.RequiredItemSubClassMask = ItemSubClassMask.None; if (spell.RequiredItemSubClassMask < 0) { spell.RequiredItemSubClassMask = ItemSubClassMask.None; } spell.RequiredItemInventorySlotMask = (InventorySlotTypeMask)GetUInt32(rawData, currentIndex++); // 70 + spell.RequiredItemInventorySlotMask = InventorySlotTypeMask.None; if (spell.RequiredItemInventorySlotMask < 0) { spell.RequiredItemInventorySlotMask = InventorySlotTypeMask.None; } var effects = new List <SpellEffect>(3); // 71 - 127+ int effectStart = currentIndex; for (int i = 0; i < 3; i++) { var effect = ReadEffect(spell, rawData, effectStart, i, out currentIndex); if (effect != null && (effect.EffectType != SpellEffectType.None || effect.BasePoints > 0 || effect.AuraType != 0 || effect.TriggerSpellId != 0)) { effects.Add(effect); } } spell.Effects = effects.ToArray(); spell.Visual = GetUInt32(rawData, currentIndex++); // 128- spell.Visual2 = GetUInt32(rawData, currentIndex++); // 129- spell.SpellbookIconId = GetUInt32(rawData, currentIndex++); // 130- spell.BuffIconId = GetUInt32(rawData, currentIndex++); // 131- spell.Priority = GetUInt32(rawData, currentIndex++); // 132- spell.Name = GetString(rawData, ref currentIndex); // 133+ spell.RankDesc = GetString(rawData, ref currentIndex); // 124- spell.Description = GetString(rawData, ref currentIndex); // 125+ spell.BuffDescription = GetString(rawData, ref currentIndex); // 126- spell.PowerCostPercentage = GetInt32(rawData, currentIndex++); // 127+- spell.StartRecoveryTime = GetInt32(rawData, currentIndex++); // 128- spell.StartRecoveryCategory = GetInt32(rawData, currentIndex++); // 129- spell.MaxTargetLevel = GetUInt32(rawData, currentIndex++); // 130- spell.SpellClassSet = (SpellClassSet)GetUInt32(rawData, currentIndex++); // 131+ spell.SpellClassMask[0] = GetUInt32(rawData, currentIndex++); // 132- spell.SpellClassMask[1] = GetUInt32(rawData, currentIndex++); // 133- spell.SpellClassMask[2] = GetUInt32(rawData, currentIndex++); // 134- spell.MaxTargets = GetUInt32(rawData, currentIndex++); // 135+ spell.DamageType = (DamageType)GetUInt32(rawData, currentIndex++); // 136+ spell.PreventionType = (SpellPreventionType)GetUInt32(rawData, currentIndex++); // 137+ spell.StanceBarOrder = GetInt32(rawData, currentIndex++); // 138- for (int i = 0; i < spell.DamageMultipliers.Length; i++) // 139-141+ { spell.DamageMultipliers[i] = GetFloat(rawData, currentIndex++); } spell.MinFactionId = GetUInt32(rawData, currentIndex++); // 142- spell.MinReputation = GetUInt32(rawData, currentIndex++); // 143- spell.RequiredAuraVision = GetUInt32(rawData, currentIndex++); // 144- spell.RequiredToolCategories = new ToolCategory[2]; // 145-146+ for (int i = 0; i < spell.RequiredToolCategories.Length; i++) { spell.RequiredToolCategories[i] = (ToolCategory)GetUInt32(rawData, currentIndex++); } spell.AreaGroupId = GetUInt32(rawData, currentIndex++); //- spell.SchoolMask = (DamageSchoolMask)GetUInt32(rawData, currentIndex++); //+ var runeCostId = GetInt32(rawData, currentIndex++); //- if (runeCostId != 0) { mappeddbcRuneCostReader.Entries.TryGetValue(runeCostId, out spell.RuneCostEntry); } spell.MissileId = GetUInt32(rawData, currentIndex++); //- // New 3.1.0. Id from PowerDisplay.dbc spell.PowerDisplayId = GetInt32(rawData, currentIndex++); //- // 3.2.2 unk float (array?) spell.Unk_322_4_1 = GetUInt32(rawData, currentIndex++); //- spell.Unk_322_4_2 = GetUInt32(rawData, currentIndex++); //- spell.Unk_322_4_3 = GetUInt32(rawData, currentIndex++); //- // 3.2.2 spell.spellDescriptionVariablesID = GetUInt32(rawData, currentIndex++); //- } catch (Exception e) { throw new Exception(string.Format("Unable to parse Spell from DBC file. Index: " + currentIndex), e); } #endregion SpellHandler.AddSpell(spell); }