include("ajax_header.php");
switch($_GET['function']) {
case "robBank":
if(isset($_SESSION['bank_rob']) && $_SESSION['bank_rob']) {
global $WeaponInfo;
global $ArmourInfo;
global $CharacterInfo;
$level = $CharacterInfo["level"];
$User_HP = $CharacterInfo["now_hp"];
$ret = "";
if(mt_rand(1, 100) <= attackRoll($CharacterInfo['id'])){ // you've robbed my bank!
$cash = mt_rand(1, $level*1000);
updateCharacter("money", "(money + {$cash})", $CharacterInfo['id']);
$ret = "You managed to steal $cash KD";
if(mt_rand(1, 2) == 1) {
addExp($CharacterInfo['id'], mt_rand($level, $level * 10));
}
} else {
$ret = "You could not rob the bank.";
if(mt_rand(1, 4) == 1){
$HPTake = mt_rand(1, $User_HP) - defendRoll($CharacterInfo['id']);
TakeHP($CharacterInfo['id'], $HPTake);
if($HPTake < 0) $HPTake = 0;
$ret .= "
You were shot at and injured. -$HPTake HP";
}
$str = FineMoney(mt_rand(1,$level*1500), true);
$ret .= "
$str";
}
print $ret;
unset($_SESSION['bank_rob']);
}
break;
case "getSavings":
global $CharacterInfo;
$bankInfo = GetBankInfo($CharacterInfo['id']);
print format($bankInfo['money']);
break;
case "withdrawMoney":
global $CharacterInfo;
$withdraw = addslashes($_POST["withdraw"]);
if(is_numeric($withdraw)){
if($withdraw > 0){
$bankInfo = GetBankInfo($CharacterInfo['id']);
if($amount <= $bankInfo['money']){
updateBank("money", "(money - {$withdraw})", $CharacterInfo['id']);
$remMoney = $bankInfo['money'] - $withdraw;
updateCharacter("money", "(money + {$withdraw})", $CharacterInfo["id"]);
$result["status"] = true;
$result["message"] = "You have withdrawn $withdraw KD out of your account";
if(mt_rand(1, 200) == 1) {
addExp($CharacterInfo['id'], 1);
}
} else {
$result["status"] = false;
$result["message"] = "Error:\nYou cannot withdraw more than you own.";
}
} else {
$result["status"] = false;
$result["message"] = "Error:\nPlease use a positive number when trying to withdraw!";
}
} else {
$result["status"] = false;
$result["message"] = "Error:\nPlease only use numbers when attempting to withdraw.";
}
print json_encode($result);
break;
case "collectInterest":
global $CharacterInfo;
$sqlBank = mysql_query("SELECT money, (SELECT name FROM bank_account_types WHERE id = account_type) as account_name, (SELECT interest_rate FROM bank_account_types WHERE id = account_type) as interest_rate, last_collected FROM bank WHERE owner_id = '{$CharacterInfo['id']}'") or print(mysql_error() . " " . __FILE__ . " #" . __LINE__);
if(mysql_result($sqlBank, 0, "last_collected") != date("Y-m-d")){
$savings_year = ceil(PercentOfNumberIs(mysql_result($sqlBank, 0, "interest_rate"), mysql_result($sqlBank, 0, "money")));
$savings_day = ceil($savings_year / 365);
updateBank("money", "(money + {$savings_day})", $CharacterInfo['id']);
updateBank("last_collected", "CURRENT_DATE()", $CharacterInfo['id']);
addExp($CharacterInfo['id'], 1);
print "";
} else {
print "";
}
break;
case "depositMoney";
$deposit = addslashes($_POST["deposit"]);
if(is_numeric($deposit)) {
if($deposit > 0){
global $sess_user_id;
global $CharacterInfo;
if($deposit <= $CharacterInfo['money']){
updateBank("money", "(money + {$deposit})", $CharacterInfo['id']);
updateCharacter("money", "(money - {$deposit})", $CharacterInfo['id']);
$result["status"] = true;
$result["message"] = "You have deposited $deposit KD into your account!";
if(mt_rand(1, 200) == 1) {
addExp($CharacterInfo['id'], 1);
}
} else {
$result["status"] = false;
$result["message"] = "Error:\nYou cannot deposit more than you have!";
}
} else {
$result["status"] = false;
$result["message"] = "Error:\nYou must enter a number greater than 0 as a deposit.";
}
} else {
$result["status"] = false;
$result["message"] = "Error:\nPlease only use numbers when submitting a deposit.";
}
print json_encode($result);
break;
case "sendMoney":
$name = $post_safe['name'];
if(is_numeric($post['money']) && $post['money'] > 0){
$money = (int)$post['money'];
$CharacterBankInfo = GetBankInfo($CharacterInfo['id']);
if($CharacterBankInfo['money'] >= $money){
$NQ = mysql_query("SELECT id FROM characters WHERE name = '{$post_safe['name']}'") or print(mysql_error() . " " . __FILE__ . " #" . __LINE__);
if(mysql_num_rows($NQ) == 1){
$toID = mysql_result($NQ, 0);
updateBank("money", "(money + {$money})", $toID);
updateBank("money", "(money - {$money})", $CharacterInfo['id']);
$money = format($money);
alert($toID, "Money transfer {$money} KD from {$CharacterInfo['name']}", "{$post_safe['message']}", $CharacterInfo['id']);
print "Successfully transferred {$money} to {$post['name']}";
} else
print "No such user!";
} else
print "Put some more money in the bank!";
} else
print "Please put in a number!";
break;
case "upgradeAccount":
// Get account information
$sqlAccount = mysql_query("SELECT id, name, minimum_amount FROM bank_account_types WHERE id = '{$post_safe['bank_acc']}'");
if($sqlAccount && mysql_num_rows($sqlAccount) == 1) {
$userBank = GetBankInfo($CharacterInfo['id']);
if($userBank['money'] >= mysql_result($sqlAccount, 0, "minimum_amount")) {
// Do the upgrade.
updateBank("account_type", mysql_result($sqlAccount, 0, "id"), $CharacterInfo['id']);
print "Successfully updated your account to " . mysql_result($sqlAccount, 0, "name");
} else
print "You don't have enough deposited to upgrade your account to this!";
} else
print "That account does not exist!";
break;
}
?>