1.0.9.9 Resets

Mon

Administrator
Developer
#2
Hello,

To do that you will need to edit the Character class:
https://github.com/lautaroangelico/WebEngine/blob/master/includes/classes/class.character.php

Here's the modified CharacterReset function:
PHP:
    function CharacterReset($username,$character_name,$userid) {
        global $dB,$common,$custom;
        if(check_value($username) && check_value($character_name)) {
            if(!Validator::Number($userid)) { $error = true; }
            if(!Validator::UsernameLength($username)) { $error = true; }
            if(!Validator::AlphaNumeric($username)) { $error = true; }
            if(!$error) {
                $character_name = Decode($character_name);
                if($this->CharacterExists($character_name) && $this->CharacterBelongsToAccount($character_name,$username)) {
                    if(!$common->accountOnline($username)) {
                    
                        $characterData = $this->CharacterData($character_name);
                        if($this->hasRequiredLevel($characterData[_CLMN_CHR_LVL_])) {
                            if(mconfig('resets_enable_zen_requirement')) {
                                $deductZen = $this->DeductZEN($character_name, mconfig('resets_price_zen'));
                                if($deductZen) {
                                    $zen_ok = true;
                                } else {
                                    $zen_ok = false;
                                }
                            } else {
                                $zen_ok = true;
                            }
                            
                            if($zen_ok) {
                                
                                $baseStats = $custom['character_class'][$characterData[_CLMN_CHR_CLASS_]]['base_stats'];
                                
                                $update = $dB->query("UPDATE "._TBL_CHR_." SET
                                "._CLMN_CHR_LVL_." = 1,
                                "._CLMN_CHR_STAT_STR_." = ?,
                                "._CLMN_CHR_STAT_AGI_." = ?,
                                "._CLMN_CHR_STAT_VIT_." = ?,
                                "._CLMN_CHR_STAT_ENE_." = ?,
                                "._CLMN_CHR_STAT_CMD_." = ?,
                                "._CLMN_CHR_RSTS_." = "._CLMN_CHR_RSTS_." + 1
                                WHERE "._CLMN_CHR_NAME_." = ?", array($baseStats['str'], $baseStats['agi'], $baseStats['vit'], $baseStats['ene'], $baseStats['cmd'], $character_name));
                                
                                if($update) {
                                    
                                    // SUCCESS
                                    message('success', lang('success_8',true));
                                    
                                    if(mconfig('resets_enable_credit_reward')) {
                                        try {
                                            $creditSystem = new CreditSystem($common, new Character(), $dB, $dB2);
                                            $creditSystem->setConfigId(mconfig('credit_config'));
                                            $configSettings = $creditSystem->showConfigs(true);
                                            switch($configSettings['config_user_col_id']) {
                                                case 'userid':
                                                    $creditSystem->setIdentifier($_SESSION['userid']);
                                                    break;
                                                case 'username':
                                                    $creditSystem->setIdentifier($_SESSION['username']);
                                                    break;
                                                case 'character':
                                                    $creditSystem->setIdentifier($character_name);
                                                    break;
                                                default:
                                                    throw new Exception("Invalid identifier (credit system).");
                                            }
                                            $creditSystem->addCredits(mconfig('resets_credits_reward'));
                                            
                                            message('success', langf('resetcharacter_txt_8', array(mconfig('resets_credits_reward'))));
                                        } catch (Exception $ex) {}
                                    }
                                    
                                } else {
                                    // unknown error (could not update database)
                                    message('error', lang('error_23',true));
                                }
                                
                            } else {
                                // not enough zen
                                message('error', lang('error_34',true));
                            }
                        } else {
                            // does not have the required level
                            message('error', lang('error_33',true));
                        }
                    } else {
                        // account is online
                        message('error', lang('error_14',true));
                    }
                } else {
                    // character doesnt exist or does not belong to account
                    message('error', lang('error_32',true));
                }
            } else {
                // unknown error (bad username)
                message('error', lang('error_23',true));
            }
        } else {
            // unknown error (incomplete data)
            message('error', lang('error_23',true));
        }
    }
This reset function will reset the character's stats to its base stats (depending on the class).
 

Mon

Administrator
Developer
#4
Here's the modified query so you can give level up points after a reset:

PHP:
$levelUpPoints = $characterData[_CLMN_CHR_CLASS_] * 50;

$update = $dB->query("UPDATE "._TBL_CHR_." SET
"._CLMN_CHR_LVL_." = 1,
"._CLMN_CHR_STAT_STR_." = ?,
"._CLMN_CHR_STAT_AGI_." = ?,
"._CLMN_CHR_STAT_VIT_." = ?,
"._CLMN_CHR_STAT_ENE_." = ?,
"._CLMN_CHR_STAT_CMD_." = ?,
"._CLMN_CHR_RSTS_." = "._CLMN_CHR_RSTS_." + 1,
"._CLMN_CHR_LVLUP_POINT_." = ?
WHERE "._CLMN_CHR_NAME_." = ?", array($baseStats['str'], $baseStats['agi'], $baseStats['vit'], $baseStats['ene'], $baseStats['cmd'], $levelUpPoints, $character_name));
 
Top