From 366542d249cc4138a57ba542f0b64660a5bcf737 Mon Sep 17 00:00:00 2001 From: Znote Date: Sun, 4 Dec 2016 01:44:44 +0100 Subject: [PATCH] Better character creation. Configurable vocation skills and will calculate HP/MP/CAP for each vocation at their configured starting level. --- admin_skills.php | 15 ++--- config.php | 129 +++++++++++++++++++++++++++++--------- engine/function/users.php | 105 ++++++++++++++++++------------- 3 files changed, 169 insertions(+), 80 deletions(-) diff --git a/admin_skills.php b/admin_skills.php index 0a3db5a..6f551d2 100644 --- a/admin_skills.php +++ b/admin_skills.php @@ -1,7 +1,6 @@ 0) { $pid = (int)$_POST['pid']; if ($config['TFSVersion'] != 'TFS_10') $status = user_is_online($pid); else $status = user_is_online_10($pid); + if (!$status) { // New player level $level = (int)$_POST['level']; // Fetch stat gain for vocation $statgain = $config['vocations_gain'][(int)$_POST['vocation']]; + $playercnf = $config['player']; + /* if ((int)$_POST['vocation'] !== 0) { // Fetch base level and stats: $baselevel = $config['level']; @@ -36,13 +38,12 @@ if (isset($_POST['pid']) && (int)$_POST['pid'] > 0) { $basemana = $config['nvMana']; $basecap = $config['nvCap']; } + */ - $levelC = $level - $baselevel; - if ($levelC >= 1) { - $newhp = $basehealth + ($statgain['hp'] * $levelC); - $newmp = $basemana + ($statgain['mp'] * $levelC); - $newcap = $basecap + ($statgain['cap'] * $levelC); - } else die("Failed to calibrate skills. Level below $baselevel."); + $LevelsFromBase = $level - $playercnf['base']['level']; + $newhp = $playercnf['base']['health'] + ($statgain['hp'] * $LevelsFromBase); + $newmp = $playercnf['base']['mana'] + ($statgain['mp'] * $LevelsFromBase); + $newcap = $playercnf['base']['cap'] + ($statgain['cap'] * $LevelsFromBase); // Calibrate hp/mana/cap if ($config['TFSVersion'] != 'TFS_10') { diff --git a/config.php b/config.php index 860797e..e743959 100644 --- a/config.php +++ b/config.php @@ -394,31 +394,98 @@ // Available character vocation users can create. $config['available_vocations'] = array(1, 2, 3, 4); - // Available towns (specify town ids, etc: (0, 1, 2); to display 3 town options (town id 0, 1 and 2). - $config['available_towns'] = array(1,2,4,5); + // Available towns (specify town ids, etc: (1, 2, 3); to display 3 town options (town id 1, 2 and 3). + $config['available_towns'] = array(1, 2, 4, 5); - $config['level'] = 8; - $config['health'] = 185; - $config['mana'] = 40; - $config['cap'] = 470; - $config['soul'] = 100; - - $config['maleOutfitId'] = 128; - $config['femaleOutfitId'] = 136; - $config['lookHead'] = 78; - $config['lookBody'] = 68; - $config['lookLegs'] = 58; - $config['lookFeet'] = 76; - - // No vocation info (if user select vocation id 0, we force thees configurations on him - $config['nvlevel'] = 1; - $config['nvHealth'] = 150; - $config['nvMana'] = 5; - $config['nvCap'] = 400; - $config['nvSoul'] = 100; - - $config['nvForceTown'] = 0; // Force a town to no vocation even though he selected something else? 0 = no, 1 = yes. - $config['nvTown'] = 0; // Town id to force no vocations to get to, if nvForceTown is 1. + $config['player'] = array( + 'base' => array( + 'level' => 8, + 'health' => 185, + 'mana' => 40, + 'cap' => 470, + 'soul' => 100 + ), + // health, mana cap etc are calculated with $config['vocations_gain'] and 'base' values of $config['player'] + 'create' => array( + 'level' => 8, + 'novocation' => array( // vocation id 0 (No vocation) special settings + 'level' => 1, // Level + 'forceTown' => true, + 'townId' => 30 + ), + 'skills' => array( // See $config['vocations'] for proper vocation names of these IDs + // No vocation + 0 => array( + 'magic' => 0, + 'fist' => 10, + 'club' => 10, + 'axe' => 10, + 'sword' => 10, + 'dist' => 10, + 'shield' => 10, + 'fishing' => 10, + ), + // Sorcerer + 1 => array( + 'magic' => 0, + 'fist' => 10, + 'club' => 10, + 'axe' => 10, + 'sword' => 10, + 'dist' => 10, + 'shield' => 10, + 'fishing' => 10, + ), + // Druid + 2 => array( + 'magic' => 0, + 'fist' => 10, + 'club' => 10, + 'axe' => 10, + 'sword' => 10, + 'dist' => 10, + 'shield' => 10, + 'fishing' => 10, + ), + // Paladin + 3 => array( + 'magic' => 0, + 'fist' => 10, + 'club' => 10, + 'axe' => 10, + 'sword' => 10, + 'dist' => 10, + 'shield' => 10, + 'fishing' => 10, + ), + // Knight + 4 => array( + 'magic' => 0, + 'fist' => 10, + 'club' => 10, + 'axe' => 10, + 'sword' => 10, + 'dist' => 10, + 'shield' => 10, + 'fishing' => 10, + ), + ), + 'male_outfit' => array( + 'id' => 128, + 'head' => 78, + 'body' => 68, + 'legs' => 58, + 'feet' => 76 + ), + 'female_outfit' => array( + 'id' => 136, + 'head' => 78, + 'body' => 68, + 'legs' => 58, + 'feet' => 76 + ) + ) + ); // Minimum allowed character name letters. Etc 4 letters: "Kåre". $config['minL'] = 4; @@ -451,12 +518,6 @@ 'price_sqm' => '50', // price per house sqm ); - $config['status'] = array( - 'status_check' => false, //enable or disable status checker - 'status_ip' => '127.0.0.1', - 'status_port' => "7171", - ); - $config['delete_character_interval'] = '3 DAY'; // Delay after user character delete request is executed eg. 1 DAY, 2 HOUR, 3 MONTH etc. $config['validate_IP'] = true; @@ -491,7 +552,7 @@ // What client version and server port are you using on this OT? // Used for the Downloads page. - $config['client'] = 1098; // 954 = tibia 9.54 + $config['client'] = 1098; // 954 = client 9.54 // Download link to client. $config['client_download'] = 'http://clients.halfaway.net/windows.php?tibia='. $config['client'] .''; @@ -499,6 +560,12 @@ $config['port'] = 7171; // Port number to connect to your OT. + $config['status'] = array( + 'status_check' => false, //enable or disable status checker + 'status_ip' => '127.0.0.1', + 'status_port' => "7171", + ); + // Gameserver info is used for client 11+ loginWebService $config['gameserver'] = array( 'ip' => $_SERVER["SERVER_ADDR"], // Can be an ip string like '123.123.123.123' diff --git a/engine/function/users.php b/engine/function/users.php index 91007c6..acda161 100644 --- a/engine/function/users.php +++ b/engine/function/users.php @@ -1135,43 +1135,53 @@ function user_create_account($register_data, $maildata) { function user_create_character($character_data) { array_walk($character_data, 'array_sanitize'); $cnf = fullConfig(); + + $vocation = (int)$character_data['vocation']; + $playercnf = $cnf['player']; + $base = $playercnf['base']; + $create = $playercnf['create']; + $skills = $create['skills'][$vocation]; + + $outfit = ($character_data['sex'] == 1) ? $create['male_outfit'] : $create['female_outfit']; - if ($character_data['sex'] == 1) { - $outfit_type = $cnf['maleOutfitId']; - } else { - $outfit_type = $cnf['femaleOutfitId']; - } + $leveldiff = $create['level'] - $base['level']; + + $gains = $cnf['vocations_gain'][$vocation]; + + $health = $base['health'] + ( $gains['hp'] * $leveldiff ); + $mana = $base['mana'] + ( $gains['mp'] * $leveldiff ); + $cap = $base['cap'] + ( $gains['cap'] * $leveldiff ); // This is TFS 0.2 compatible import data with Znote AAC mysql schema $import_data = array( 'name' => $character_data['name'], 'group_id' => 1, 'account_id' => $character_data['account_id'], - 'level' => $cnf['level'], - 'vocation' => $character_data['vocation'], - 'health' => $cnf['health'], - 'healthmax' => $cnf['health'], - 'experience' => 0, /* Will automatically be configured according to level after creating this array*/ - 'lookbody' => $cnf['lookBody'], /* STARTER OUTFITS */ - 'lookfeet' => $cnf['lookFeet'], - 'lookhead' => $cnf['lookHead'], - 'looklegs' => $cnf['lookLegs'], - 'looktype' => $outfit_type, + 'level' => $create['level'], + 'vocation' => $vocation, + 'health' => $health, + 'healthmax' => $health, + 'experience' => level_to_experience($create['level']), + 'lookbody' => $outfit['body'], /* STARTER OUTFITS */ + 'lookfeet' => $outfit['feet'], + 'lookhead' => $outfit['head'], + 'looklegs' => $outfit['legs'], + 'looktype' => $outfit['id'], 'lookaddons' => 0, - 'maglevel' => 0, - 'mana' => $cnf['mana'], - 'manamax' => $cnf['mana'], + 'maglevel' => $skills['magic'], + 'mana' => $mana, + 'manamax' => $mana, 'manaspent' => 0, - 'soul' => $cnf['soul'], - 'town_id' => $character_data['town_id'], + 'soul' => $base['soul'], + 'town_id' => $character_data['town_id'], 'posx' => $cnf['default_pos']['x'], 'posy' => $cnf['default_pos']['y'], 'posz' => $cnf['default_pos']['z'], 'conditions' => '', - 'cap' => $cnf['cap'], + 'cap' => $cap, 'sex' => $character_data['sex'], 'lastlogin' => 0, - 'lastip' => $character_data['lastip'], + 'lastip' => $character_data['lastip'], 'save' => 1, 'skull' => 0, 'skulltime' => 0, @@ -1188,8 +1198,8 @@ function user_create_character($character_data) { 'balance' => 0 ); - // TFS 1.0 rules - if (Config('TFSVersion') === 'TFS_10') { + // TFS 1.0 variations + if ($cnf['TFSVersion'] === 'TFS_10') { unset($import_data['rank_id']); unset($import_data['guildnick']); unset($import_data['direction']); @@ -1199,39 +1209,50 @@ function user_create_character($character_data) { unset($import_data['loss_mana']); unset($import_data['premend']); unset($import_data['online']); - } - // Set correct experience for level - $import_data['experience'] = level_to_experience($import_data['level']); + // Skills can be added into the same query on TFS 1.0+ + $import_data['skill_fist'] = $skills['fist']; + $import_data['skill_club'] = $skills['club']; + $import_data['skill_sword'] = $skills['sword']; + $import_data['skill_axe'] = $skills['axe']; + $import_data['skill_dist'] = $skills['dist']; + $import_data['skill_shielding'] = $skills['shield']; + $import_data['skill_fishing'] = $skills['fishing']; + } // If you are no vocation (id 0), use these details instead: - if ($character_data['vocation'] === '0') { - $import_data['level'] = $cnf['nvlevel']; - $import_data['experience'] = level_to_experience($cnf['nvlevel']); - $import_data['health'] = $cnf['nvHealth']; - $import_data['healthmax'] = $cnf['nvHealth']; - $import_data['cap'] = $cnf['nvCap']; - $import_data['mana'] = $cnf['nvMana']; - $import_data['manamax'] = $cnf['nvMana']; - $import_data['soul'] = $cnf['nvSoul']; + if ($vocation === 0) { + $import_data['level'] = $create['novocation']['level']; + $import_data['experience'] = level_to_experience($create['novocation']['level']); - if ($cnf['nvForceTown'] == 1) { - $import_data['town_id'] = $cnf['nvTown']; + if ($create['novocation']['forceTown'] === true) { + $import_data['town_id'] = $create['novocation']['townId']; } } - + $fields = array_keys($import_data); // Fetch select fields $data = array_values($import_data); // Fetch insert data $fields_sql = implode("`, `", $fields); // Convert array into SQL compatible string $data_sql = implode("', '", $data); // Convert array into SQL compatible string - echo 1; + mysql_insert("INSERT INTO `players`(`$fields_sql`) VALUES ('$data_sql');"); $created = time(); $charid = user_character_id($import_data['name']); - echo 2; mysql_insert("INSERT INTO `znote_players`(`player_id`, `created`, `hide_char`, `comment`) VALUES ('$charid', '$created', '0', '');"); + + // Player skills TFS 0.2, 0.3/4. (TFS 1.0 is done above character creation) + if ($cnf['TFSVersion'] != 'TFS_10') { + // Not quite sure if players table have player_skills creation triggers, this may need to be inserts instead of update queries. + mysql_update("UPDATE `player_skills` SET `value`='". $skills['fist'] ."' WHERE `player_id`='{$charid}' AND `skillid`='0' LIMIT 1;"); + mysql_update("UPDATE `player_skills` SET `value`='". $skills['club'] ."' WHERE `player_id`='{$charid}' AND `skillid`='1' LIMIT 1;"); + mysql_update("UPDATE `player_skills` SET `value`='". $skills['sword'] ."' WHERE `player_id`='{$charid}' AND `skillid`='2' LIMIT 1;"); + mysql_update("UPDATE `player_skills` SET `value`='". $skills['axe'] ."' WHERE `player_id`='{$charid}' AND `skillid`='3' LIMIT 1;"); + mysql_update("UPDATE `player_skills` SET `value`='". $skills['dist'] ."' WHERE `player_id`='{$charid}' AND `skillid`='4' LIMIT 1;"); + mysql_update("UPDATE `player_skills` SET `value`='". $skills['shield'] ."' WHERE `player_id`='{$charid}' AND `skillid`='5' LIMIT 1;"); + mysql_update("UPDATE `player_skills` SET `value`='". $skills['fish'] ."' WHERE `player_id`='{$charid}' AND `skillid`='6' LIMIT 1;"); + } } // Returns counted value of all players online @@ -1542,4 +1563,4 @@ function cancel_war_invitation($cid, $gid) { mysql_update("UPDATE `guild_wars` SET `status` = 3, `ended` = '$time' WHERE `guild2` = '$cid' AND `guild1` = '$gid';"); } -?> +?> \ No newline at end of file