/*
		public static int GetSpecialNumber(Style style)
		{
			if (style.SpecialType == Style.eSpecialType.Effect)
			{
				Spell spell = SkillBase.GetSpellById(style.SpecialValue);
				if (spell != null)
					return spell.ClientEffect;
			}
			return 0;
		}

		public static int GetSpecialValue(Style style)
		{
			switch(style.SpecialType)
			{
				case Style.eSpecialType.ExtendedRange:
					return 128; // Extended Range für Reaver style
				case Style.eSpecialType.Taunt:
					return style.SpecialValue;
			}
			return 0;
		}*/

		
		/*public static int GetOpeningResult(Style style,GameClient clt)
		{
			switch(StyleProcessor.ResolveAttackResult(style,clt.Player.PlayerCharacter.Class))
			{
				case GameLiving.eAttackResult.Any:
					return (int)Style.eAttackResult.Any;
				case GameLiving.eAttackResult.Missed:
					return (int) Style.eAttackResult.Miss;
				case GameLiving.eAttackResult.Parried:
					return (int)Style.eAttackResult.Parry;
				case GameLiving.eAttackResult.Evaded:
					return (int)Style.eAttackResult.Evade;
				case GameLiving.eAttackResult.Blocked:
					return (int)Style.eAttackResult.Block;
				case GameLiving.eAttackResult.Fumbled:
					return (int)Style.eAttackResult.Fumble;
				case GameLiving.eAttackResult.HitStyle:
					return (int)Style.eAttackResult.Style;
				case GameLiving.eAttackResult.HitUnstyled:
					return (int)Style.eAttackResult.Hit;
			}
			return 0;
		}*/
		/*
		public static string GetOpeningStyle(Style style)
		{
			if (style.OpeningRequirementValue > 0)
			{
				Style style2 = SkillBase.GetStyleByID(style.OpeningRequirementValue);
				if (style2!=null)
					return style2.Name;
				return "";
			}
			return "";
		}*/

		#endregion

		/// <summary>
		/// Delve the realm abilities for v1.110+ clients
		/// </summary>
		/// <param name="clt"></param>
		/// <param name="id"></param>
		/// <returns></returns>
        static string DelveRealmAbility(GameClient clt, int id) {
            var dw = new DelveWriter().Begin("RealmAbility").Value("Index", id);
            var ra = clt.Player.GetNonTrainableSkillList().Cast<Skill>().Where(sk => sk.ID == id).FirstOrDefault() as RealmAbility;
            if (ra != null)
            {
                ra.AddDelve(dw);
            }
            else dw.Value("Name", "(not found)");
            return dw.ToString();
        }
		static string DelveStyle(GameClient clt, int id)
        {
            var style = SkillBase.GetStyleByID(id, clt.Player.CharacterClass.ID);

            var dw = new DelveWriter()
                .Begin("Style").Value("Index", id);
            
            if (style != null) {
                // Not implemented:
                // (Style (FollowupStyle "Sapphire Slash")(LevelBonus "2")(OpeningDamage "16")(Skill "1")(Expires "1343375647"))
                // (Style (Fingerprint "1746652963")(FollowupStyle "Thigh Cut")(Hidden "1")OpeningDamage "55")(Skill "118")(SpecialNumber "1511")(SpecialType "1")(Expires "1342381240"))

            	dw
            		.Value("Name", style.Name)
            		.Value("Icon", style.Icon)
            		.Value("Level", style.Level)
            		.Value("Fatigue", style.EnduranceCost)
            		//.Value("SpecialType", (int)style.SpecialType, style.SpecialType != 0)
					//.Value("SpecialNumber", GetSpecialNumber(style), GetSpecialNumber(style)!=0)
            		.Value("DefensiveMod", style.BonusToDefense, style.BonusToDefense != 0)
            		.Value("AttackMod", style.BonusToHit, style.BonusToHit != 0)
            		.Value("OpeningType", (int)style.OpeningRequirementType)
					.Value("OpeningNumber", style.OpeningRequirementValue, style.OpeningRequirementType == Style.eOpening.Positional)
					//.Value("OpeningResult",GetOpeningResult(style,clt),GetOpeningResult(style,clt)>0)
					//.Value("OpeningStyle",GetOpeningStyle(style),(Style.eAttackResult)GetOpeningResult(style,clt) == Style.eAttackResult.Style)
            		.Value("Weapon", style.GetRequiredWeaponName(), style.WeaponTypeRequirement > 0)
            		.Value("Hidden", "1",style.StealthRequirement)
            		//.Value("TwoHandedIcon", 10, style.TwoHandAnimation > 0)
					//.Value("Skill",43)
					.Value("OpeningDamage",style.GrowthRate*100,style.GrowthRate>0)
					//.Value("SpecialValue", GetSpecialValue(style),GetSpecialValue(style)!=0)
					//.Value("FollowupStyle",style.DelveFollowUpStyles,!string.IsNullOrEmpty(style.DelveFollowUpStyles))
            		;
            }
            else {
                dw.Value("Name", "(not found)");
            }
            return dw.End().ToString();
        }
		/// <summary>
		/// Delve Info for Songs (V1.110+)
		/// </summary>
		/// <param name="clt">Client</param>
		/// <param name="id">SpellID</param>
		/// <returns></returns>
		public static string DelveSong(GameClient clt, int id)
		{
			var dw = new DelveWriter();

			Spell spell = SkillBase.GetSpellByID(id);
		
	
			if (spell != null)
			{
	
					dw.Begin("Song")
						.Value("Index", id)
						.Value("Name", spell.Name)
						.Value("effect", spell.ClientEffect)
						.Value("description_string", spell.Description, !string.IsNullOrEmpty(spell.Description))
						;
					//log.Info(dw.ToString());
					return dw.ToString();
			}

			// not found
			return dw.Begin("Song").Value("Name", "(not found)").Value("Index", id).ToString();
		}
		/// <summary>
		/// Delve Info for Spells (V1.110+)
		/// </summary>
		/// <param name="clt">Client</param>
		/// <param name="id">SpellID</param>
		/// <returns></returns>
        public static string DelveSpell(GameClient clt, int id) {
            var dw = new DelveWriter();
			
			var spell = SkillBase.GetSpellByID(id);

			//if (spell != null && spellLine != null)
			{
				/*
				var spellLine = clt.Player.GetSpellLines()[lineId] as SpellLine;
				if (spellLine != null) {
					Spell spell = null;
					foreach (Spell spl in SkillBase.GetSpellList(spellLine.KeyName)) {
						if (spl.Level == level) {
							spell = spl;
							break;
						}
					}*/
				//if (spell != null) {
				// NOT GOOD SOLUTION SPELLLINE IS BETTER INCLUDED IN SPELL
				ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(clt.Player, spell,SkillBase.GetSpellLine(GlobalSpellsLines.Mob_Spells));
				if (spellHandler != null)
				{
				dw.Begin("Spell")
						.Value("Index", id)
						.Value("Name", spell.Name)
						//.Value("Function", spellHandler.FunctionName ?? "0")
						.Value("cast_timer", spell.CastTime - 2000, spell.CastTime > 2000) //minus 2 seconds (why mythic?)
						.Value("instant","1",spell.CastTime==0)
						//.Value("damage", spellHandler.GetDelveValueDamage, spellHandler.GetDelveValueDamage != 0)
						.Value("damage_type", (int) spell.DamageType + 1, (int) spell.DamageType > 0) // Damagetype not the same as dol
						//.Value("type1", spellHandler.GetDelveValueType1, spellHandler.GetDelveValueType1 > 0)
						.Value("level", spell.Level, spell.Level > 0)
						.Value("power_cost", spell.Power, spell.Power != 0)
						//.Value("round_cost",spellHandler.GetDelveValueRoundCost,spellHandler.GetDelveValueRoundCost!=0)
						//.Value("power_level", spellHandler.GetDelveValuePowerLevel,spellHandler.GetDelveValuePowerLevel!=0)
						.Value("range", spell.Range, spell.Range > 0)
						.Value("duration", spell.Duration/1000, spell.Duration > 0) //seconds
						.Value("dur_type", GetDurrationType(spell), GetDurrationType(spell) > 0)
						//.Value("parm",spellHandler.GetDelveValueParm,spellHandler.GetDelveValueParm>0) 
						.Value("timer_value", spell.RecastDelay/1000, spell.RecastDelay > 1000)
						//.Value("bonus", spellHandler.GetDelveValueBonus, spellHandler.GetDelveValueBonus > 0)
						//.Value("no_combat"," ",Util.Chance(50))//TODO
						//.Value("link",14000)
						//.Value("ability",4) // ??
						//.Value("use_timer",4)
						.Value("target", GetSpellTargetType(spell.Target), GetSpellTargetType(spell.Target) > 0)
						//.Value("frequency", spellHandler.GetDelveValueFrequency, spellHandler.GetDelveValueFrequency != 0)
						.Value("description_string", spell.Description, !string.IsNullOrEmpty(spell.Description))
						.Value("radius", spell.Radius, spell.Radius > 0)
						.Value("concentration_points", spell.Concentration, spell.Concentration > 0)
						//.Value("num_targets", spellHandler.GetDelveValueNumTargets, spellHandler.GetDelveValueNumTargets>0)
						//.Value("no_interrupt", spell.Interruptable ? (char)0 : (char)1) //Buggy?
						;
					//log.Info(dw.ToString());
					return dw.ToString();
					// }
				}
			}

        	// not found
            return dw.Begin("Spell").Value("Name", "(not found)").Value("Index", id).ToString();
        }
        /** General info @ v1.110:
         *  - Examples can be found at http://dl.dropbox.com/u/48908369/delve.txt
         *  - 'Expires' can be left out
         *  - No idea what 'Fingerprint' does
         **/

        static string DelveAbility(GameClient clt, int id) { /* or skill */
            Skill s = clt.Player.GetNonTrainableSkillList().Cast<Skill>().Where(sk => sk.ID == id).FirstOrDefault();
            var dw = new DelveWriter().Begin(s is Ability ? "Ability" : "Skill").Value("Index", id);
            if (s != null) {
                dw.Value("Name", s.Name);
            }
            else dw.Value("Name", "(not found)");
            return dw.ToString();
        }