summaryrefslogtreecommitdiff
path: root/npc/custom/eAAC_Scripts/kafraExpress/ke_bank.txt
blob: 65fed7d25fdace1b43934c0e34bc5713729255cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//===== eAthena Script ======================================= 
//= Kafra Express - Bank Module
//===== By: ================================================== 
//= Skotlex 
//===== Current Version: ===================================== 
//= 2.8
//===== Compatible With: ===================================== 
//= eAthena SVN R3524+
//===== Description: ========================================= 
//= Part of the Kafra Express Script Package.
//= Offers banking services with daily interests, and 
//= withdrawal/deposit fees.
//===== Additional Comments: ================================= 
//= See config.txt for configuration.
//============================================================ 

-	script	keInit_bank	-1,{
OnInit:	//Load Config
	donpcevent "keConfig::OnLoadBank";
	end;
}

function	script	F_keBank	{

	function	SF_calcInterest;
	SF_calcInterest();
	
	do {
		set @feeD,callfunc("F_keCost",$@kebk_depositCost,100);
		set @maxDep,Zeny;
		if (@maxDep > $@kebk_maxTransact)
			set @maxDep,$@kebk_maxTransact;
		if (#ke_bank + @maxDep > $@kebk_capacity)
			set @maxDep,$@kebk_capacity-#ke_bank;

		set @feeW,callfunc("F_keCost",$@kebk_withdrawCost,100);
		set @maxWith,#ke_bank-(#ke_bank*@feeW/100);
		if (@maxWith > $@kebk_maxTransact)
			set @maxWith,$@kebk_maxTransact;
		
		if (#ke_bank < $@kebk_capacity) {
			set @kmenu, select(
				"- Return (balance is "+#ke_bank+"z)",
				"- Deposit (up to "+@maxDep+"z - "+@feeD+"% fee)",
				"- Withdraw (up to "+@maxWith+"z + "+@feeW+"% fee)",
				"- Transfer from 1st B.o.P. ("+#bankstorage+"z)",
				"- Transfer from 2nd B.o.P. ("+#kafrabank+"z)"
			);
		} else {
			set @kmenu, select(
				"- Return (balance is "+#ke_bank+"z)",
				"- Withdraw (up to "+@maxWith+"z + "+@feeW+"% fee)",
				"- Transfer from 1st B.o.P. ("+#bankstorage+"z)",
				"- Transfer from 2nd B.o.P. ("+#kafrabank+"z)"
			);
			if (@kmenu > 1)
				set @kmenu, @kmenu+1;
		}
		switch (@kmenu) {
		case 2:	//Deposit
			input @amount;	
			if (@amount < $@kebk_minTransact) {
				callfunc "F_keIntro", -1, "Sorry, the minimum transaction value is "+$@kebk_minTransact+"z.";
				break;
			}
			if (@amount > @maxDep) {
				callfunc "F_keIntro", e_an, "You can't deposit that quantity!";
				break;
			}
			set #ke_bank,#ke_bank+@amount-(@amount*@feeD/100);
			if ($@kebk_useGlobalBank)
				set $ke_globalbank, $ke_globalbank +@amount*@feeD/100;
			set Zeny,Zeny-@amount;
			emotion e_cash;
			break;

		case 3:	//Withdraw
			input @amount;
			if (@amount < $@kebk_minTransact) {
				callfunc "F_keIntro", -1, "Sorry, the minimum transaction value is "+$@kebk_minTransact+"z.";
				break;
			}
			if (@amount > @maxWith) {
				callfunc "F_keIntro", e_X, "You can't withdraw that quantity!";
				break;
			}
			set #ke_bank,#ke_bank-@amount-(@amount*@feeW/100);
			if ($@kebk_useGlobalBank)
				set $ke_globalbank, $ke_globalbank +@amount*@feeW/100;
			set Zeny,Zeny+@amount;
			emotion e_oh;
			break;
			
		case 4:	//1st B.o.P.
			if (#bankstorage==0) {
				callfunc "F_keIntro", -1, "Sorry, there is nothing left to transfer.";
				break;
			}
			callfunc "F_keIntro", -1, #bankstorage+"z have been transferred from your account in the First Bank of Prontera.";
			set #ke_bank,#ke_bank+#bankstorage;
			set #bankstorage,0;
			break;

		case 5:	//2nd B.o.P.
			if (#kafrabank==0) {
				callfunc "F_keIntro", -1, "Sorry, there is nothing left to transfer.";
				break;
			}
			callfunc "F_keIntro", -1, #kafrabank+"z have been transferred from your account in the Second Bank of Prontera.";
			set #ke_bank,#ke_bank+#kafrabank;
			set #kafrabank,0;
			break;
		}
	} while (@kmenu > 1);
return;

//Subfunction: SF_calcInterest
//Calculates the interests gained on the account. Uses 30-day months
function	SF_calcInterest {
	set @day,gettime(5);
	if (@day>30)
		set @day,30; //Use 30 day-months
	set @month,gettime(6);
	if (#ke_banktick == 0) { //Init bank.
		set #ke_banktick,gettime(6)*30+@day;
		if ($@kebk_monMaintenance < 1) return;
		set #ke_bankmtick,@month;
		return;
	}
	set @banktick,gettime(6)*30+@day;
	if (@banktick == #ke_banktick) return;
	if (@banktick < #ke_banktick) { //Year change.
		do {
			set #ke_banktick,#ke_banktick-360;
			if ($@kebk_monMaintenance > 0) set #ke_bankmtick,#ke_bankmtick-12;
		} while (@banktick < #ke_banktick);
	}
	if ($@kebk_monMaintenance > 0 && #ke_bankmtick < @month){	//Month change
		set @qty,0;
		do {
			if (#ke_bank < $@kebk_monMaintenance) {
				if (@qty>0)
					mes "You've been charged "+@qty+"z for account maintenance, but it was not enough.";
				if ($@kebk_useGlobalBank)
					set $ke_globalbank, $ke_globalbank + @qty;
				mes "You owe the Bank "+($@kebk_monMaintenance*(#ke_bankmtick-@month))+"z for maintenance costs. Until paid you won't earn interests...";
				return;
			}
			set @qty, @qty+$@kebk_monMaintenance;
			set #ke_bankmtick,#ke_bankmtick+1;
			set #ke_bank, #ke_bank-$@kebk_monMaintenance;
		} while (#ke_bankmtick < @month);
		mes "You've been charged "+@qty+"z for account maintenance.";
		if ($@kebk_useGlobalBank)
			set $ke_globalbank, $ke_globalbank + @qty;
	}
	set @qty,0;
	if (#ke_bank > $@kebk_monMaintenance && #ke_bank < $@kebk_capacity)
	{
		if (#ke_bank > 1000000) //Overflow protection
			set @qty,(#ke_bank/10000)*$@kebk_dayInterest*(@banktick-#ke_banktick);
		else
			set @qty,#ke_bank*$@kebk_dayInterest*(@banktick-#ke_banktick)/10000;
	}
	set #ke_banktick,@banktick;
	if (@qty == 0) return;
	if (@qty < 0) {
		callfunc "F_keIntro", -1, "Sorry, your gained interests have been cancelled for being way too much.";
		return;
	}
	if (#ke_bank + @qty > $@kebk_capacity)
		set #ke_bank, $@kebk_capacity;
	else
		set #ke_bank,#ke_bank+@qty;

	callfunc "F_keIntro", -1, "Since your last visit, you've earned an interest of "+@qty+"z!";
}	//SF end

}