;"Pick Pocket" Skill


SendMessageToUser(#USERID,"This skill has been temporarily disabled - Sorry for the in-convenient timing. Cheers mate! Apollyon.", #MSG_SERVER)
GoTo END

MaxPossibleSteal = 25000

PlusX = 0
PlusY = 0

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

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

If TargetID = 0
	SendMessageToUser(UserID,"You can't steal anything here.", #MSG_EMOTE)
	GoTo END
EndIf

If GetUserSilver(TargetID) < 1
	SendMessageToUser(UserID,GetUserName(TargetID)+" is flat broke.", #MSG_CRITICAL)
	GoTo END
EndIf

If GetUserGuild(UserID) = GetUserGuild(TargetID)
	SendMessageToUser(UserID,"You can't steal from this player.", #MSG_EMOTE)
	GoTo END
EndIf

If TargetID = #USERID
	SendMessageToUser(UserID,"You stole "+GetUserSilver(#USERID)+" silver from yourself! Some thief you are...", #MSG_TELL)
	GoTo END
EndIf

If TargetID <> 0
	Stats = 0
	Stats = Stats + GetUserStrength(TargetID)
	Stats = Stats + GetUserWisdom(TargetID)
	Stats = Stats + GetUserAgility(TargetID)
	Stats = Stats + GetUserEndurance(TargetID)

	If Stats < 25
		SendMessageToUser(UserID,"You can't pick this player's pocket.", #MSG_EMOTE)
		GoTo END
	EndIf
EndIf

If GetUserAccess(TargetID) > 5
	SendMessageToUser(UserID,"You can't steal anything from "+GetUserName(TargetID)+", he is a moderater!", #MSG_EMOTE)
	SendMessageToUser(TargetID,GetUserName(UserID)+" tried to pick your pockets, but was not allowed.", #MSG_TELL)
	GoTo END
EndIf

If GetMapType(#MAPID) = #MAPTYPE_FRIENDLY
	SendMessageToUser(UserID,"You can't steal anything here.", #MSG_EMOTE)
	GoTo END
ElseIf GetMapType(#MAPID) = #MAPTYPE_NEUTRAL 
	If GetUserGuild(UserID) = 0
		SendMessageToUser(UserID,"You can't steal anything here.", #MSG_EMOTE)
		GoTo END
	ElseIf GetUserGuild(TargetID) = 0
		SendMessageToUser(UserID,"You can't steal anything here.", #MSG_EMOTE)
		GoTo END
	EndIf
EndIf

FAILED_SHOUTOUT = -3
FAILED_FOUND = -2
FAILED_HIDDEN = -1
NONE = 0
SUCCEED_HIDDEN = 1
SUCCEED_FOUND = 2
SUCCEED_SHOUTOUT = 3

SuccessLevel = NONE

UserAgility = GetUserAgility(UserID)
TargetAgility = GetUserAgility(TargetID)
UserEndurance = GetUserEndurance(UserID)
TargetEndurance = GetUserEndurance(TargetID)

UserSilver = GetUserSilver(UserID)
TargetSilver = GetUserSilver(TargetID)

Random = Random(0, UserAgility)
Random = Floor(Random)

RandModifier = UserAgility / 5
Random = Random - RandModifier

TargetAwareness = TargetAgility / 2

Compilation = UserAgility
Compilation = Compilation - TargetAgility / 2

SuckLevel = 3
If Compilation > 15
	SuckLevel = 2
ElseIf Compilation > 35 
	SuckLevel = 1
EndIf

;Failure
If TargetAwareness > Random
	SuccessLevel = Random(0, SuckLevel) + 1
	SuccessLevel = 0 - SuccessLevel
;Success
Else
	SuccessLevel = Random(0, SuckLevel) + 1
EndIf

SilverStolen = 0

If SuccessLevel < NONE
	SendMessageToUser(UserID,"You failed to steal from "+GetUserName(TargetID)+".",#MSG_EMOTE)
ElseIf SuccessLevel > NONE
	
	StealLevel = 100
	StealLevel = StealLevel / TargetEndurance
	StealLevel = StealLevel + UserEndurance
     StealLevel = StealLevel - TargetEndurance
	
	MaxSteal = TargetSilver / StealLevel
	
	If MaxSteal > MaxPossibleSteal
		MaxSteal = MaxPossibleSteal
	EndIf
	
	SilverStolen = Random(1,MaxSteal)
	SilverStolen = Floor(SilverStolen)

	;New code added here!
	If SilverStolen > MaxPossibleSteal
		SilverStolen = MaxPossibleSteal
	EndIf
	;New code ends here!
	
	SetUserSilver(TargetID, TargetSilver - SilverStolen)
	SetUserSilver(UserID, UserSilver + SilverStolen)
	
	SendMessageToUser(UserID,"You stole "+SilverStolen+" silver from "+GetUserName(TargetID)+".",#MSG_TELL)
Else
	GoTo END
EndIf

If SuccessLevel = FAILED_SHOUTOUT
	SendMessageToMap(#MAPID,GetUserName(UserID)+" tried to pick "+GetUserName(TargetID)+"'s pockets!",#MSG_CRITICAL)
ElseIf SuccessLevel = FAILED_FOUND
	SendMessageToUser(TargetID,GetUserName(UserID)+" tried to pick your pockets!",#MSG_CRITICAL)
ElseIf SuccessLevel = FAILED_HIDDEN
	GoTo END
ElseIf SuccessLevel = SUCCEED_HIDDEN
	GoTo END
ElseIf SuccessLevel = SUCCEED_FOUND
	SendMessageToUser(TargetID,GetUserName(UserID)+" stole "+SilverStolen+" silver from you!",#MSG_CRITICAL)
ElseIf SuccessLevel = SUCCEED_SHOUTOUT
	SendMessageToMap(#MAPID,GetUserName(UserID)+" stole "+SilverStolen+" silver from "+GetUserName(TargetID)+"!",#MSG_CRITICAL)
Else 
	GoTo END
EndIf

Label END