;'Lightning Bolt' skill

;SendMessageToUser(#USERID,"This skill goes through walls, I need to fix it - Comrade",#MSG_SERVER)
;GoTo END

UserID = #USERID
Blood = GetUserMana(UserID)
BloodCost = 10

BaseDamage = 1.7 * GetUserWisdom(UserID)
BaseDamage = Floor(BaseDamage)

Length = 5
Graphic = 7

YPlus = 0
XPlus = 0

If Blood < BloodCost
	SendMessageToUser(UserID,"You don't have enough blood to use this skill.",#MSG_CRITICAL)
	GoTo END
Else
	SendMessageToUser(UserID,"A bolt of lightning flies from your hands.",#MSG_EMOTE)
EndIf

Blood = Blood - BloodCost
SetUserMana(UserID, Blood)


If GetUserDirection(UserID) = #DIR_UP
	YPlus = -1
ElseIf GetUserDirection(UserID) = #DIR_RIGHT
	XPlus = 1
ElseIf GetUserDirection(UserID) = #DIR_DOWN
	YPlus = 1
ElseIf GetUserDirection(UserID) = #DIR_LEFT
	XPlus = -1
Else
	GoTo END
EndIf

CreateEffect(Graphic,600,200,GetUserDirection(UserID),#MAPID,#XPOS+XPlus,#YPOS+YPlus,0,UserID,1)

i = 1
While i < Length 
	TILE = GetTileType(#MAPID, #XPOS + XPlus * i, #YPOS + YPlus * i)
	If TILE = #TILE_DOOR 
		GoTo END
	ElseIf TILE = #TILE_WALL 
		GoTo END
	ElseIf TILE = #TILE_NPC 
		GoTo END
	ElseIf TILE = #TILE_GODONLY 
		GoTo END
	EndIf
	
	TargetID = GetUserAtXY(#MAPID, #XPOS + XPlus * i, #YPOS + YPlus * i)
	MonsterID = GetMonsterAtXY(#MAPID, #XPOS + XPlus * i, #YPOS + YPlus * i)
	
	If MonsterID <> -1
		UserDamageMonster(MonsterID, BaseDamage, #USERID)
	EndIf
	If TargetID > 0
		NODAMAGE = 0
		If GetUserAccess(TargetID) > 3
			NODAMAGE = 1
		EndIf
		If GetUserGuild(UserID) = GetUserGuild(TargetID)
			NODAMAGE = 1
		EndIf
		If GetMapType(#MAPID) = #MAPTYPE_FRIENDLY
			NODAMAGE = 1
		ElseIf GetMapType(#MAPID) = #MAPTYPE_NEUTRAL
			If GetUserGuild(UserID) = 0
				NODAMAGE = 1
			EndIf
			If GetUserGuild(TargetID) = 0
				NODAMAGE = 1
			EndIf
		EndIf
		
		If NODAMAGE = 0
			Damage = BaseDamage - GetUserWisdom(TargetID)
			If Damage < 10
				Damage = 10
			EndIf
			UserDamageUser(UserID,Damage,TargetID)
			SendCombatMessage(TargetID,"A bolt of lightning hits you for "+Damage+" points of damage! ")
		EndIf
	EndIf
	i = i + 1
Wend

Label END

Continue = 1