post_content, 'adventurebook_character_overview' ) ) { return; } // get the page id from the settings $character_page_id = get_option( 'adventurebook_character_page_id', '' ); // only run this code on the character overview page, i.e. if the current page id matches the character_page_id if ( ! is_page( $character_page_id ) ) { return; } global $wpdb; $user_id = get_current_user_id(); // Create a new character if ( isset( $_POST['create_character'] ) ) { // check nonce if ( ! isset( $_POST['adventurebook_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['adventurebook_nonce'] ) ), 'adventurebook_character_overview' ) ) { // nonce is invalid wp_die( esc_html( __( 'Security check failed. Please try again.', 'adventurebook' ) ) ); } $character_name = isset( $_POST['character_name'] ) ? sanitize_text_field( wp_unslash( $_POST['character_name'] ) ) : ''; $adventurebook_id = isset( $_POST['char_adventurebook'] ) ? intval( $_POST['char_adventurebook'] ) : 0; // check if a combat system is set in the adventurebook $combat_system = get_combat_system_for_adventurebook( $adventurebook_id ); if ( ! $combat_system ) { echo '

' . esc_html( __( 'The selected adventurebook does not have a combat system set. Please contact the administrator.', 'adventurebook' ) ) . '

'; return ob_get_clean(); } if ( $adventurebook_id == 0 ) { echo '

' . esc_html( __( 'Please select an adventurebook!', 'adventurebook' ) ) . '

'; return ob_get_clean(); } if ( $character_name ) { // check if a character with this name already exists $existing_character = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "adventurebook_characters WHERE name = %s AND user_id = %d", $character_name, $user_id ) );// phpcs:ignore WordPress.DB.DirectDatabaseQuery if ( $existing_character ) { echo '

' . esc_html( __( 'A character with this name already exists!', 'adventurebook' ) ) . '

'; return ob_get_clean(); } // now create a character $character = new Character( 0, $user_id, $adventurebook_id, $character_name ); $new_character_id = $character->save_to_db(); // move to the starting zone of the adventurebook $starting_zone_id = get_post_meta( $adventurebook_id, '_adventurebook_start_page', true ); // set the starting zone as the respawn zone, too $character->set_stat( 'RespawnZone', $starting_zone_id ); $character->move_to_zone( $starting_zone_id ); //echo '

' . esc_html( __( 'Character created!', 'adventurebook' ) ) . '

'; // make it the standard character update_user_meta( $user_id, 'adventurebook_current_character_id_' . $adventurebook_id, $new_character_id ); } wp_redirect( get_permalink() ); exit; } // Charakter delete if ( isset( $_GET['delete_character'] ) ) { // check nonce if ( ! isset( $_GET['adventurebook_delete_character_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['adventurebook_delete_character_nonce'] ) ), 'adventurebook_delete_character_nonce' ) ) { // nonce is invalid wp_die( esc_html( __( 'Security check failed. Please try again.', 'adventurebook' ) ) ); } $character_id = intval( $_GET['delete_character'] ); $character = Character::get_character_by_id( $character_id ); if ( $character && $character->user_id == $user_id ) { $character->delete_from_db(); } // Refresh to avoid resubmission on page reload wp_redirect( get_permalink() ); exit; } // train skill if ( ab_get( 'train_skill' ) > 0 ) { // check nonce if ( ! isset( $_GET['adventurebook_train_skill_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['adventurebook_train_skill_nonce'] ) ), 'adventurebook_train_skill_nonce' ) ) { // nonce is invalid wp_die( esc_html( __( 'Security check failed. Please try again.', 'adventurebook' ) ) ); } $character_id = ab_get('character_id'); $skill_name = ab_get('skill_name'); $character = Character::get_character_by_id( $character_id ); if ( $character && $character->user_id == $user_id ) { $combat_system = get_combat_system_for_adventurebook( $character->adventurebook_id ); if ( $combat_system ) { // check if the skill can be raised if($character->can_raise_skill($skill_name)) { $combat_system->combatant_raise_skill( $character, $skill_name ); } } } } // Rename character if ( isset( $_GET['rename_character'] ) && isset( $_GET['new_name'] ) ) { // check nonce if ( ! isset( $_GET['adventurebook_rename_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['adventurebook_rename_nonce'] ) ), 'adventurebook_rename_nonce' ) ) { // nonce is invalid wp_die( esc_html( __( 'Security check failed. Please try again.', 'adventurebook' ) ) ); } $character_id = intval( sanitize_text_field( wp_unslash( $_GET['rename_character'] ) ) ); $new_name = sanitize_text_field( wp_unslash( $_GET['new_name'] ) ); $character = Character::get_character_by_id( $character_id ); if ( $character && $character->user_id == $user_id ) { // check if a character with this name already exists $existing_character = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "adventurebook_characters WHERE name = %s AND user_id = %d", $new_name, $user_id ) );// phpcs:ignore WordPress.DB.DirectDatabaseQuery if ( ! $existing_character ) { $character->set_name( $new_name ); } } // Refresh to avoid resubmission on page reload wp_redirect( get_permalink() ); exit; } // set a character as the current character if ( isset( $_GET['set_current_character'] ) ) { // check nonce if ( ! isset( $_GET['adventurebook_set_character_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['adventurebook_set_character_nonce'] ) ), 'adventurebook_set_character_nonce' ) ) { // nonce is invalid wp_die( esc_html( __( 'Security check failed. Please try again.', 'adventurebook' ) ) ); } $character_id = intval( $_GET['set_current_character'] ); // check if the character belongs to the user $character = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "adventurebook_characters WHERE id = %d AND user_id = %d", $character_id, $user_id ) );// phpcs:ignore WordPress.DB.DirectDatabaseQuery if ( $character ) { update_user_meta( $user_id, 'adventurebook_current_character_id_' . $character->adventurebook_id, $character_id ); // Refresh to avoid resubmission on page reload wp_redirect( get_permalink() ); exit; } } } ); /** * Add a shortcode to display the character overview * This shortcode will display a list of the user's characters * and allow them to create new characters, set a character as the current character, * and delete characters. */ function display_character_overview() { // check if the user is logged in if ( ! is_user_logged_in() ) { $requested_uri = ''; if ( isset( $_SERVER['REQUEST_URI'] ) ) { $login_url = wp_login_url( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); } /* translators: %s: login url */ return '

' . sprintf( __( 'You need to log in to access this page.', 'adventurebook' ), esc_url( $login_url ) ) . '

'; } global $wpdb; $user_id = get_current_user_id(); // get all characters of the user $characters = Character::get_characters_by_user_id( $user_id ); ob_start(); // --- Charaktere nach Adventurebook gruppieren --- $grouped = []; foreach ( $characters as $character ) { $adv_id = $character->adventurebook_id; if ( ! isset( $grouped[ $adv_id ] ) ) { $grouped[ $adv_id ] = []; } $grouped[ $adv_id ][] = $character; } ?>

$chars ) : ?>

post_title ); ?>

adventurebook_id, true ); if ( $current_character_id ) { $row = $wpdb->get_row(// phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}adventurebook_characters WHERE id = %d AND user_id = %d", $current_character_id, $user_id ) ); if ( ! $row ) { delete_user_meta( $user_id, 'adventurebook_current_character_id_' . $character->adventurebook_id ); $current_character_id = 0; } } // Health (ohne round) $health_cur = (int) $character->get_stat( 'CurHealth' ); $health_max = (int) $character->get_stat( 'Health' ); $health_pct = 0; if ( $health_max > 0 ) { $pct = (int) ( ( $health_cur * 100 ) / $health_max ); if ( $pct < 0 ) { $pct = 0; } if ( $pct > 100 ) { $pct = 100; } $health_pct = $pct; } // Location $zone_title = ''; if ( $character->location_id ) { $zone = get_post( $character->location_id ); if ( $zone ) { $zone_title = $zone->post_title; } } $stats = $character->get_stats(); ?>
CLOSE

get_name() ); ?>
get_name() ); ?>
id === (int) $current_character_id ) : ?>
: get_game_var( 'turns_played' ) ); ?>
: created_at ) ) ); ?>
:
0 ) : ?>
get_combat_stats_output( $character ); if ( ! empty( $combat_stats ) ) : ?>
$stat_value ) { // interner Kram/Separat-Sections überspringen if ( in_array( $stat_name, array( 'VARS', 'SKILLS', 'SLOTS', 'Health', 'CurHealth' ), true ) ) { continue; } if ('XP_spent' === $stat_name ) { $stat_name = __( 'XP Spent', 'adventurebook' ); } if ( 'RespawnZone' === $stat_name ) { $stat_name = __( 'Respawn Zone', 'adventurebook' ); $stat_value = $character->get_respawn_zone_title(); } if ( 'Wealth' === $stat_name && $combat_system ) { $stat_value .= ' ' . $combat_system->get_wealth_unit(); } if ( 'Piety' === $stat_name ) { $stat_name = __( 'Piety', 'adventurebook' ); } echo '
' . esc_html( $stat_name ) . '
' . esc_html( is_scalar( $stat_value ) ? $stat_value : wp_json_encode( $stat_value ) ) . '
'; } } ?>
$skill_info) : ?>
  • get_skill_by_code( $skill_code ); ?> combatant_can_raise_skill( $character, $skill_code ); if ( $can_raise ) { $raise_cost = $combat_system->combatant_get_skill_cost_for_next_skill_level( $character, $skill_code ); } } if ( $can_raise ) { $train_skill_nonce = wp_create_nonce( 'adventurebook_train_skill_nonce' ); ?> get_wealth_unit() ) ); ?> combatant_get_skill_cost_for_next_skill_level( $character, $skill_code ); $cost_money = ceil( $cost / 2 ); if ( $cost > 0 ) { /* translators: 1: raise cost in XP 2: raise cost in money 3: Wealth Unit */ echo '(' . esc_html( sprintf( __( '%1$s XP, %2$s %3$s', 'adventurebook' ), number_format_i18n( $cost ), number_format_i18n( $cost_money ), $combat_system->get_wealth_unit() ) ) . ')'; } } ?> Lv
  • get_slotted_item_list_html(), array( 'a' => array( 'href' => array(), 'title' => array(), 'class' => array() ), 'ul' => array( 'class' => array() ), 'li' => array( 'class' => array() ), 'b' => array(), 'strong' => array(), 'em' => array(), 'i' => array(), 'span' => array( 'class' => array(), 'style' => array(), 'onclick' => array() ), 'div' => array( 'class' => array(), 'id' => array(), 'style' => array(), 'onclick' => array() ), 'img' => array( 'src' => array(), 'width' => array(), 'height' => array(), 'style' => array(), 'alt' => array() ), ) ); ?>
    get_item_list_html(), array( 'a' => array( 'href' => array(), 'title' => array(), 'class' => array() ), 'ul' => array( 'class' => array() ), 'li' => array( 'class' => array() ), 'b' => array(), 'strong' => array(), 'em' => array(), 'i' => array(), 'span' => array( 'class' => array(), 'style' => array(), 'onclick' => array() ), 'div' => array( 'class' => array(), 'id' => array(), 'style' => array(), 'onclick' => array() ), 'img' => array( 'src' => array(), 'width' => array(), 'height' => array(), 'style' => array(), 'alt' => array() ), ) ); ?>
    get_combat_strength_output($character)): ?>
  • get_combat_strength_output($character)); ?>
  • id === (int) $current_character_id ) { $adv_page = adventurebook_get_first_page_using_shortcode( $adventurebook_id ); if ( $adv_page ) { echo ' ' . esc_html__( 'Play', 'adventurebook' ) . ''; } } else { $nonce_set = wp_create_nonce( 'adventurebook_set_character_nonce' ); echo ' ' . esc_html__( 'Set active', 'adventurebook' ) . ''; } $rename_nonce = wp_create_nonce( 'adventurebook_rename_nonce' ); echo ' ' . esc_html__( 'Rename', 'adventurebook' ) . ''; $delete_nonce = wp_create_nonce( 'adventurebook_delete_character_nonce' ); echo ' ' . esc_html__( 'Delete', 'adventurebook' ) . ''; ?>