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 = adventurebook_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_safe_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_safe_redirect( get_permalink() ); exit; } // spend dev points if ( ab_get( 'spend_dev_points' ) > 0 ) { // check nonce if ( ! isset( $_GET['adventurebook_spend_dev_points_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['adventurebook_spend_dev_points_nonce'] ) ), 'adventurebook_spend_dev_points_nonce' ) ) { // nonce is invalid wp_die( esc_html( __( 'Security check failed. Please try again.', 'adventurebook' ) ) ); } $character_id = ab_get('character_id'); $stat_name = ab_get('stat_name'); $character = Character::get_character_by_id( $character_id ); if ( $character && $character->user_id == $user_id ) { $combat_system = adventurebook_get_combat_system_for_adventurebook( $character->adventurebook_id ); if ( $combat_system ) { // check if the character has a development point to spend if ( $character->get_development_points() > 0 ) { $valid_stats = ['Strength', 'Dexterity', 'Endurance']; if ( in_array( $stat_name, $valid_stats, true ) ) { // increase the stat by 1 $current_value = (int) $character->get_stat( $stat_name ); $character->set_stat( $stat_name, $current_value + 1 ); // decrease the development points by 1 $current_dev_points = $character->get_development_points(); $character->set_development_points( $current_dev_points - 1 ); } } } } // Refresh to avoid resubmission on page reload wp_safe_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 = adventurebook_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 ); } } } wp_safe_redirect( get_permalink() ); exit; } // 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_safe_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_safe_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 ) { /* @var $character 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_long( $character ); if ( ! empty( $combat_stats ) ) : ?>
array(), 'a' => array( 'href' => array(), 'title' => array(), 'class' => array(), 'onclick' => array() ), 'strong' => array(), 'em' => array(), 'i' => array(), 'span' => array( 'class' => array(), 'style' => array(), 'onclick' => array() ), ) ); ?>
$stat_value ) { // skip separate sections and internal stats if ( in_array( $stat_name, array( 'VARS', 'SKILLS', 'SLOTS', 'Health', 'CurHealth', 'EFFECTS', 'Strength', 'Dexterity', 'Endurance' ), true ) ) { continue; } if('XP' === $stat_name ) { $stat_value = number_format_i18n(intval($stat_value) ); } if ('XP_Spent' === $stat_name ) { $stat_name = __( 'XP Spent', 'adventurebook' ); $needed = $character->get_exp_needed_for_next_level() - $stat_value; /* translators: %s: needed XP for next level */ $stat_value = esc_html( number_format_i18n($stat_value) ). ' (' . esc_html( sprintf( __( 'Next Level in %s XP', 'adventurebook' ), number_format_i18n( $needed ) ) ) . ')'; } if ( 'RespawnZone' === $stat_name ) { $stat_name = __( 'Respawn Zone', 'adventurebook' ); $stat_value = $character->get_respawn_zone_title(); } if ( 'Wealth' === $stat_name && $combat_system ) { $stat_value = number_format_i18n(intval($stat_value)) .' ' . $combat_system->get_wealth_unit(); // if the bank_balance game_var is > 0, show it too $bank_balance = (int) $character->get_game_var( 'bank_balance' ); if ( $bank_balance > 0 ) { /* translators: 1: bank balance amount 2: wealth unit */ $stat_value .= ' (' . esc_html( sprintf( __( 'Bank: %1$s %2$s', 'adventurebook' ), number_format_i18n( $bank_balance ), $combat_system->get_wealth_unit() ) ) . ')'; } } if ( 'Development_Points' === $stat_name ) { $stat_name = __( 'Development Points', 'adventurebook' ); } if ( 'Piety' === $stat_name ) { $stat_name = __( 'Piety', 'adventurebook' ); } // Wealth-Wert wird oben (mit Währungseinheit) formatiert; hier NUR das // angezeigte Label übersetzen (vorher blieb der Roh-Schlüssel „Wealth"). if ( 'Wealth' === $stat_name ) { $stat_name = __( 'Wealth', 'adventurebook' ); } echo '
' . esc_html( $stat_name ) . '
' . esc_html( is_scalar( $stat_value ) ? $stat_value : wp_json_encode( $stat_value ) ) . '
'; } // special handling for Effects if ( ! empty( $stats['EFFECTS'] ) && is_array( $stats['EFFECTS'] ) ) { echo '
' . esc_html__( 'Effects', 'adventurebook' ) . '
'; $effect_names = []; foreach ( $stats['EFFECTS'] as $effect_info ) { $effect_names[] = $effect_info['name']. /* translators: number of turns left for an effect */ ( isset( $effect_info['duration'] ) && $effect_info['duration'] > 0 ? ' (' . esc_html( sprintf( __( '%d turns left', 'adventurebook' ), (int) $effect_info['duration'] ) ) . ')' : '' ); } echo implode( ', ', $effect_names ); echo '
'; } } ?>
$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_skill_value($skill_code) ); ?>
  • 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() ), 'br' => 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() ), ) ); ?>
    has_bonus_from_collectibles()): ?>
      get_bonus_from_collectibles(); foreach($bonuses as $type => $bonus) { $x = $character->get_number_of_cards_until_next_bonus($type); // use explicit singular/plural words via __() as requested if ( $x === 1 ) { $card_word = __( 'more card', 'adventurebook' ); } else { $card_word = __( 'more cards', 'adventurebook' ); } // build the "X more Card(s) for +1" text $cards_text = number_format_i18n( $x ) . ' ' . $card_word . ' ' . __( 'for', 'adventurebook' ). ' +'.$bonus+1; // full line with translations; use a translatable format and escape inserted values /* translators: 1: type of collectible, 2: bonus value, 3: cards text */ $line = sprintf( __( 'against %1$s: +%2$s to Attack and Defense (%3$s)', 'adventurebook' ), $type, $bonus, $cards_text ); echo '
    • ' . esc_html( $line ) . '
    • '; } ?>
    0 ) : ?>
    adventurebook_id ) ); ?>
    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' ) . ''; ?>