;"Restore Group" skill

;The cost of blood the skill takes
BloodCost = Floor(GetUserWisdom(#USERID) / 2)

;The amount of HP the skill will heal
HealthGain = GetUserWisdom(#USERID)

;The effect graphic to use
Graphic = 1

GuildOnly = GetUserTempFlag(#USERID,5)

UserMsg=Lower(GetUserMessage(#USERID))
If UserMsg="guild"
	If GuildOnly = 0
		SetUserTempFlag(#USERID,5,1)
		GuildOnly = 1
		SendMessageToUser(#USERID,"Restore Group is now set to restore guild members only.",#MSG_SERVER)
	Else
		SendMessageToUser(#USERID,"Restore Group is already set to only restore guild members.",#MSG_SERVER)
	EndIf
	SetUserMessage(#USERID,"blah")
	GoTo END
ElseIf UserMsg="guildonly"
	If GetUserGuild(#USERID) = 0
		SendMessageToUser(#USERID,"You are not in a guild.",#MSG_SERVER)
		SetUserMessage(#USERID,"blah")
		GoTo END
	EndIf
	If GuildOnly = 0
		SetUserTempFlag(#USERID,5,1)
		GuildOnly = 1
		SendMessageToUser(#USERID,"Restore Group is now set to restore guild members only.",#MSG_SERVER)
	Else
		SendMessageToUser(#USERID,"Restore Group is already set to only restore guild members.",#MSG_SERVER)
	EndIf
	SetUserMessage(#USERID,"blah")
	GoTo END
ElseIf UserMsg="normal"
	If GuildOnly = 1
		SetUserTempFlag(#USERID,5,0)
		GuildOnly = 0
		SendMessageToUser(#USERID,"Restore Group is now set to restore any player nearby.",#MSG_SERVER)
	Else
		SendMessageToUser(#USERID,"Restore Group is already set to restore any player, guildmate or not.",#MSG_SERVER)
	EndIf
	SetUserMessage(#USERID,"blah")
	GoTo END
ElseIf UserMsg="help"
	SendMessageToUser(#USERID,"Type 'guild' or 'guildonly' to make this skill only heal guildmates, or type 'normal' to set it back to normal.",#MSG_SERVER)
	SetUserMessage(#USERID,"blah")
	GoTo END
EndIf

LargerArea = 0
If GetUserWisdom(#USERID) > 49
	LargerArea = 1
	Graphic = 21
EndIf

If GetUserWisdom(#USERID) > 39
   BloodCost = 40
   HealthGain = 75
ElseIf GetUserWisdom(#USERID) > 29
   BloodCost = 30
   HealthGain = 55
ElseIf GetUserWisdom(#USERID) > 19
   BloodCost = 24
   HealthGain = 40
ElseIf GetUserWisdom(#USERID) > 9
   BloodCost = 16
   HealthGain = 25
EndIf

If GetUserMana(#USERID) < BloodCost
   SendMessageToUser(#USERID, "You do not have the required blood to use this skill!", #MSG_CRITICAL)
   GoTo END
EndIf

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

;Heal all players in the surrounding area
EndPos = 2
If LargerArea = 1
	EndPos = 3
EndIf

EndX = #XPOS + EndPos
EndY = #YPOS + EndPos

StartPos = -1
If LargerArea = 1
	StartPos = -2
EndIf

Y = #YPOS + StartPos
While Y < EndY
	X = #XPOS + StartPos
	While X < EndX
		If X = #XPOS-2
			If Y = #YPOS-2
				GoTo SKIP
			ElseIf Y = #YPOS+2
				GoTo SKIP
			EndIf
		ElseIf X = #XPOS+2
			If Y = #YPOS-2
				GoTo SKIP
			ElseIf Y = #YPOS+2
				GoTo SKIP
			EndIf
		EndIf
		
		UserID = GetUserAtXY(#MAPID, X, Y)
		If UserID > 0
			If GuildOnly = 1
				If GetUserGuild(UserID)<>GetUserGuild(#USERID)
					GoTo SKIP
				EndIf
			EndIf
			
			CreateEffect(Graphic,350,0,#DIR_UP,#MAPID,X,Y,0,UserID,0)
			
			Health = GetUserHP(UserID)
			If Health < GetUserMaxHP(UserID)
				Health = Health + HealthGain
				If Health > GetUserMaxHP(UserID)
					Health = GetUserMaxHP(UserID)
				EndIf
				SetUserHP(UserID, Health)
			Else
				If UserID <> #USERID
					SendCombatMessage(#USERID,GetUserName(UserID)+" already has full health. ")
				EndIf
			EndIf
			
			SendMessageToUser(UserID, "Your flesh regenerates.", #MSG_EMOTE)
		EndIf
		
		Label SKIP
		
		X = X + 1
	Wend
	Y = Y + 1
Wend

;All users have been healed

SendMessageToUser(#USERID, "The people around you have been regenerated.", #MSG_EMOTE)

Label END

Continue = 1
