;'Slash' - skill script (Skill #32)

Effect = 17

SendMessageToUser(#USERID,"Undergoing re-construction - Comrade",#MSG_SERVER)
GoTo END

BloodCost = Floor(GetUserMaxMana(#USERID)/5)

SlashCount = Floor(GetUserAgilityTotal(#USERID)/15)

If SlashCount < 0
	SlashCount = 0
EndIf

Damage = 0
If GetUserEquippedWeapon(#USERID) > -1
	Damage = GetItemFlag1(GetUserInvItem(#USERID,GetUserEquippedWeapon(#USERID)))
EndIf
Damage = Damage + Floor(GetUserStrengthTotal(#USERID)*0.65)

PlusX = 0
PlusY = 0

If GetUserDirection(#USERID) = #DIR_UP
	PlusY = -1
ElseIf GetUserDirection(#USERID) = #DIR_DOWN
	PlusY = 1
ElseIf GetUserDirection(#USERID) = #DIR_LEFT
	PlusX = -1
ElseIf GetUserDirection(#USERID) = #DIR_RIGHT
	PlusX = 1
EndIf

TargetID = GetUserAtXY(#MAPID,#XPOS+PlusX,#YPOS+PlusY)

If TargetID < 1
	If GetUserEnduranceTotal(#USERID) > 25
		TargetID = GetUserAtXY(#MAPID,#XPOS+PlusX+PlusX,#YPOS+PlusY+PlusY)
		If TargetID < 1
			If GetUserEnduranceTotal(#USERID) > 50
				TargetID = GetUserAtXY(#MAPID,#XPOS+PlusX+PlusX+PlusX,#YPOS+PlusY+PlusY+PlusY)
			EndIf
		EndIf
	EndIf
EndIf

If GetUserAccess(#USERID) < 6
	If GetMapType(#MAPID) = #MAPTYPE_NEUTRAL
		If GetUserGuild(#USERID) > 0
			If GetUserGuild(#USERID) = GetUserGuild(TargetID)
				TargetID = 0
			EndIf
			If GetUserGuild(TargetID) = 0
				TargetID = 0
			EndIf
		Else 
			TargetID = 0
		EndIf
	ElseIf GetMapType(#MAPID) = #MAPTYPE_FRIENDLY 
		TargetID = 0 
	EndIf
EndIf

MonsterID = GetMonsterAtXY(#MAPID,#XPOS+PlusX,#YPOS+PlusY)
MonsterStep = 1

If MonsterID < 0
	If GetUserEnduranceTotal(#USERID) > 25
		MonsterID = GetMonsterAtXY(#MAPID,#XPOS+PlusX+PlusX,#YPOS+PlusY+PlusY)
		MonsterStep = 2
		If MonsterID < 0
			If GetUserEnduranceTotal(#USERID) > 50
				MonsterID = GetMonsterAtXY(#MAPID,#XPOS+PlusX+PlusX+PlusX,#YPOS+PlusY+PlusY+PlusY)
				MonsterStep = 3
			EndIf
		EndIf
	EndIf
EndIf

If TargetID < 1
	If MonsterID < 0
		SendCombatMessage(#USERID,"There is no one in range of you ")
		GoTo END
	EndIf
EndIf

If GetUserMana(#USERID) < BloodCost
	SendCombatMessage(#USERID,"Not enough blood to use this skill ")
	GoTo END
EndIf

SetUserMana(#USERID,GetUserMana(#USERID) - BloodCost)

TargetDefense = 0
If TargetID > 0
	Rand = Random(0,9)
	If Rand > 8
		If GetUserEquippedBoots(TargetID) > -1
			TargetDefense = GetItemFlag1(GetUserInvItem(TargetID,GetUserEquippedBoots(TargetID)))
		EndIf
	ElseIf Rand > 6
		If GetUserEquippedHelmet(TargetID) > -1
			TargetDefense = GetItemFlag1(GetUserInvItem(TargetID,GetUserEquippedHelmet(TargetID)))
		EndIf
	ElseIf Rand > 3
		If GetUserEquippedAccessory(TargetID) > -1
			TargetDefense = GetItemFlag1(GetUserInvItem(TargetID,GetUserEquippedAccessory(TargetID)))
		EndIf
	Else
		If GetUserEquippedArmor(TargetID) > -1
			TargetDefense = GetItemFlag1(GetUserInvItem(TargetID,GetUserEquippedArmor(TargetID)))
		EndIf
	EndIf
EndIf

TargetDamage = Damage - TargetDefense
If Damage < 10
	Damage = 10
EndIf

Variance = Floor(Damage / 10) + 3
MonsterDamage = Damage - Random(Variance,Variance*3)

If TargetID > 0
	CreateEffect(Effect,500,0,#DIR_RIGHT,GetUserMap(TargetID),GetUserX(TargetID),GetUserY(TargetID),0,TargetID,0)
	UserDamageUser(#USERID,Damage,TargetID)
	SendCombatMessage(TargetID,"You were slashed by "+GetUserName(#USERID)+" ")	
	
	If SlashCount > 1
		i = 1
		While i < SlashCount 
			Damage = Floor(Damage * 0.5)
			If Damage < 1
				Damage = 1
			EndIf
			
			Timer(383,i*100,#USERID,Damage,TargetID)
			i=i+1
		Wend
	EndIf
EndIf

If MonsterID > -1
	CreateEffect(Effect,500,0,#DIR_RIGHT,GetUserMap(#USERID),GetUserX(#USERID)+Floor(PlusX*MonsterStep),GetUserY(#USERID)+Floor(PlusY*MonsterStep),0,#USERID,0)
	UserDamageMonster(MonsterID,Damage,#USERID)
	
	If SlashCount > 1
		i = 1
		While i < SlashCount
			Damage = Floor(Damage * 0.5)
			If Damage < 1
				Damage = 1
			EndIf
			 
			UserDamageMonster(MonsterID,Damage,#USERID)
			Timer(384,i*100,#MAPID,#XPOS+Floor(PlusX*MonsterStep),#YPOS+Floor(PlusY*MonsterStep))
			i=i+1
		Wend
	EndIf
EndIf




Label END

Continue = 1