;Bank storage script

BANK_MAXIMUM_INCREMENT = 100000

BANK_MAXIMUM = GetUserFlag(#USERID, 46)

If BANK_MAXIMUM = 0 
	SetUserFlag(#USERID, 46, 1)
	BANK_MAXIMUM = 100000
EndIf

If BANK_MAXIMUM < 100000 
	BANK_MAXIMUM = BANK_MAXIMUM * 100000
EndIf

;Legacy support
If GetUserFlag(#USERID, 46) > 99999
	newMax = GetUserFlag(#USERID, 46) / BANK_MAXIMUM_INCREMENT
	SetUserFlag(#USERID, 46, newMax)
EndIf

NONE = 0
ACTION_DEPOSIT = 1
ACTION_DEPOSIT2 = 2
ACTION_DEPOSIT_ALL = 3
ACTION_WITHDRAW = 4
ACTION_WITHDRAW2 = 5
ACTION_WITHDRAW_ALL = 6
ACTION_BALANCE = 7
ACTION_INCREASE = 8

Action = NONE

UserBalance = GetUserFlag(#USERID, 47)
UserSilver = GetUserSilver(#USERID)


UserText=Lower(GetUserMessage(#USERID))

If UserText="withdraw"
	Action = ACTION_WITHDRAW
ElseIf UserText="withdrawmore"
	Action = ACTION_WITHDRAW2
ElseIf UserText="withdraw more"
	Action = ACTION_WITHDRAW2
ElseIf UserText="withdrawall"
	Action = ACTION_WITHDRAW_ALL
ElseIf UserText="withdraw all"
	Action = ACTION_WITHDRAW_ALL
ElseIf UserText="deposit"
	Action = ACTION_DEPOSIT 
ElseIf UserText="depositmore"
	Action = ACTION_DEPOSIT2
ElseIf UserText="deposit more"
	Action = ACTION_DEPOSIT2
ElseIf UserText="depositall"
	Action = ACTION_DEPOSIT_ALL
ElseIf UserText="deposit all"
	Action = ACTION_DEPOSIT_ALL
ElseIf UserText="balance"
	Action = ACTION_BALANCE 
ElseIf UserText="check"
	Action = ACTION_BALANCE 
ElseIf UserText="upgrade"
	Action = ACTION_INCREASE 
ElseIf UserText="increase"
	Action = ACTION_INCREASE
Else
	Action = NONE
EndIf

If Action = ACTION_WITHDRAW 
	If UserBalance < 10000
		SendMessageToUser(#USERID,"Account Balance: "+GetUserFlag(#USERID, 47),#MSG_CRITICAL)
	Else 
		UserBalance = UserBalance - 10000
		SetUserFlag(#USERID, 47, UserBalance)
		
		SetUserSilver(#USERID, UserSilver + 10000)
		SendMessageToUser(#USERID,"You have removed a sum of 10,000 silver from your account.",#MSG_TELL)
	EndIf
ElseIf Action = ACTION_WITHDRAW2 
	If UserBalance < 50000
		SendMessageToUser(#USERID,"Account Balance: "+GetUserFlag(#USERID, 47),#MSG_CRITICAL)
	Else 
		UserBalance = UserBalance - 50000
		SetUserFlag(#USERID, 47, UserBalance)
		
		SetUserSilver(#USERID, UserSilver + 50000)
		SendMessageToUser(#USERID,"You have removed a sum of 50,000 silver from your account.",#MSG_TELL)
	EndIf
ElseIf Action = ACTION_WITHDRAW_ALL 
	If UserBalance = 0
		SendMessageToUser(#USERID,"Account Balance: "+0,#MSG_CRITICAL)
	Else 
		SetUserSilver(#USERID, UserSilver + UserBalance)
		
		UserBalance = 0
		SetUserFlag(#USERID, 47, UserBalance)
		
		SendMessageToUser(#USERID,"You have withdrawn all your silver from your account.",#MSG_TELL)
	EndIf
ElseIf Action = ACTION_DEPOSIT 
	If BANK_MAXIMUM-1 < UserBalance
		SendMessageToUser(#USERID,"You have reached the maximum capacity of your account, upgrades to your account may be purchased by typing 'upgrade' and paying a sum of one hundred thousand silver.",#MSG_EMOTE)
	ElseIf UserSilver < 10000
		SendMessageToUser(#USERID,"You don't have 10000 silver to deposit.",#MSG_CRITICAL)
	Else 
		UserBalance = UserBalance + 10000
		SetUserFlag(#USERID, 47, UserBalance)
		
		SetUserSilver(#USERID, UserSilver - 10000)
		SendMessageToUser(#USERID,"You have deposited a sum of 10,000 silver into your account.",#MSG_TELL)
	EndIf
ElseIf Action = ACTION_DEPOSIT2
	If BANK_MAXIMUM-1 < UserBalance
		SendMessageToUser(#USERID,"You have reached the maximum capacity of your account, upgrades to your account may be purchased by typing 'upgrade' and paying a sum of one hundred thousand silver.",#MSG_EMOTE)
	ElseIf UserSilver < 50000
		SendMessageToUser(#USERID,"You don't have 50000 silver to deposit.",#MSG_CRITICAL)
	Else 
		UserBalance = UserBalance + 50000
		SetUserFlag(#USERID, 47, UserBalance)
		
		SetUserSilver(#USERID, UserSilver - 50000)
		SendMessageToUser(#USERID,"You have deposited a sum of 50,000 silver into your account.",#MSG_TELL)
	EndIf
ElseIf Action = ACTION_DEPOSIT_ALL 
	If BANK_MAXIMUM-1 < UserBalance
		SendMessageToUser(#USERID,"You have reached the maximum capacity of your account, upgrades to your account may be purchased by typing 'upgrade' and paying a sum of one hundred thousand silver.",#MSG_EMOTE)
	ElseIf UserSilver = 0
		SendMessageToUser(#USERID,"You don't have any silver to deposit.",#MSG_CRITICAL)
	Else 
		DepositAmount = GetUserSilver(#USERID)
		If Floor(UserBalance + DepositAmount) > BANK_MAXIMUM
			DepositAmount = BANK_MAXIMUM - UserBalance
		EndIf
		UserBalance = UserBalance + DepositAmount
		SetUserFlag(#USERID, 47, UserBalance)
		
		SetUserSilver(#USERID, UserSilver - DepositAmount)
		SendMessageToUser(#USERID,"You have deposited a sum of "+DepositAmount+" silver into your account.",#MSG_TELL)
	EndIf
ElseIf Action = ACTION_BALANCE 
	SendMessageToUser(#USERID,"Your account has a balance of "+GetUserFlag(#USERID, 47)+" silver.",#MSG_TELL)
ElseIf Action = ACTION_INCREASE
	If GetUserFlag(#USERID, 46) > 9
		If GetUserFlag(#USERID, 46) > 24
			If GetUserFlag(#USERID, 46) > 49
				If GetUserFlag(#USERID, 46) > 99
					SendMessageToUser(#USERID,"You can't upgrade your account any further.",#MSG_CRITICAL)
				ElseIf UserSilver < 1000000
					SendMessageToUser(#USERID,"You don't have the money to upgrade your account.",#MSG_CRITICAL)
				Else 
					UserSilver = UserSilver - 1000000
					SetUserSilver(#USERID,UserSilver)
					SetUserFlag(#USERID, 46, GetUserFlag(#USERID,46)+1)
					
					maxSilver = Floor(GetUserFlag(#USERID, 46)*BANK_MAXIMUM_INCREMENT)
					SendMessageToUser(#USERID,"Your account now has a maximum balance of "+maxSilver+" silver.",#MSG_TELL)
					;If GetUserFlag(#USERID, 46) = 100
					;	SendMessageToUser(#USERID,"Account increases will now cost 1,000,000 silver per 100,000 upgrade.",#MSG_CRITICAL)
					;EndIf
				EndIf
			ElseIf UserSilver < 500000
				SendMessageToUser(#USERID,"You don't have the money to upgrade your account.",#MSG_CRITICAL)
			Else 
				UserSilver = UserSilver - 500000
				SetUserSilver(#USERID,UserSilver)
				SetUserFlag(#USERID, 46, GetUserFlag(#USERID,46)+1)
				
				maxSilver = Floor(GetUserFlag(#USERID, 46)*BANK_MAXIMUM_INCREMENT)
				SendMessageToUser(#USERID,"Your account now has a maximum balance of "+maxSilver+" silver.",#MSG_TELL)
				If GetUserFlag(#USERID, 46) = 50
					SendMessageToUser(#USERID,"Account increases will now cost 1,000,000 silver per 100,000 upgrade.",#MSG_CRITICAL)
				EndIf
			EndIf
		ElseIf UserSilver < 250000
			SendMessageToUser(#USERID,"You don't have the money to upgrade your account.",#MSG_CRITICAL)
		Else 
			UserSilver = UserSilver - 250000
			SetUserSilver(#USERID,UserSilver)
			SetUserFlag(#USERID, 46, GetUserFlag(#USERID,46)+1)
			
			maxSilver = Floor(GetUserFlag(#USERID, 46)*BANK_MAXIMUM_INCREMENT)
			SendMessageToUser(#USERID,"Your account now has a maximum balance of "+maxSilver+" silver.",#MSG_TELL)
			If GetUserFlag(#USERID, 46) = 25
				SendMessageToUser(#USERID,"Account increases will now cost 50,0000 silver per 100,000 upgrade.",#MSG_CRITICAL)
			EndIf
		EndIf
	ElseIf UserSilver < 100000
		SendMessageToUser(#USERID,"You don't have the money to upgrade your account.",#MSG_CRITICAL)
	Else 
		UserSilver = UserSilver - 100000
		SetUserSilver(#USERID,UserSilver)
		SetUserFlag(#USERID, 46, GetUserFlag(#USERID,46)+1)
		
		maxSilver = Floor(GetUserFlag(#USERID, 46)*BANK_MAXIMUM_INCREMENT)
		SendMessageToUser(#USERID,"Your account now has a maximum balance of "+maxSilver+" silver.",#MSG_TELL)
		If GetUserFlag(#USERID, 46) = 10
			SendMessageToUser(#USERID,"Account increases will now cost 250,000 silver per 100,000 upgrade.",#MSG_CRITICAL)
		EndIf
	EndIf
Else
	SendMessageToUser(#USERID,"To deposit silver, simply type 'deposit', 'deposit more', or 'deposit all'.",#MSG_EMOTE)
	SendMessageToUser(#USERID,"To withdraw silver, type 'withdraw', 'withdraw more', or 'withdraw all'.",#MSG_EMOTE)
	SendMessageToUser(#USERID,"If you want to see the balance of your account, type 'balance'. Your current capacity is "+BANK_MAXIMUM+" silver.",#MSG_EMOTE)
EndIf

Label END

Continue = 1