<commit_before>/*
 * SEGS - Super Entity Game Server
 * http://www.segs.io/
 * Copyright (c) 2006 - 2018 SEGS Team (see AUTHORS.md)
 * This software is licensed under the terms of the 3-clause BSD License. See LICENSE.md for details.
 */

/*!
 * @addtogroup NetStructures Projects/CoX/Common/NetStructures
 * @{
 */

#include "Character.h"

#include "BitStream.h"
#include "Entity.h"
#include "Costume.h"
#include "Friend.h"
#include "Powers.h"
#include "GameData/serialization_common.h"
#include "Servers/GameDatabase/GameDBSyncEvents.h"
#include "GameData/chardata_serializers.h"
#include "GameData/entitydata_serializers.h"
#include "GameData/playerdata_definitions.h"
#include "GameData/playerdata_serializers.h"
#include "Servers/MapServer/DataHelpers.h"
#include "Logging.h"
#include <QtCore/QString>
#include <QtCore/QDebug>

// Anonymous namespace
namespace {

}
// End Anonymous namespace

Character::Character()
{
    m_multiple_costumes                         = false;
    m_current_costume_idx                       = 0;
    m_current_costume_set                       = false;
    m_char_data.m_supergroup_costume            = false;
    m_sg_costume                                = nullptr;
    m_char_data.m_using_sg_costume              = false;
    m_char_data.m_current_attribs.m_HitPoints   = 25;
    m_max_attribs.m_HitPoints                   = 50;
    m_char_data.m_current_attribs.m_Endurance   = 33;
    m_max_attribs.m_Endurance                   = 43;
    m_char_data.m_has_titles = m_char_data.m_has_the_prefix
            || !m_char_data.m_titles[0].isEmpty()
            || !m_char_data.m_titles[1].isEmpty()
            || !m_char_data.m_titles[2].isEmpty();
    m_char_data.m_sidekick.m_has_sidekick = false;
    m_char_data.m_current_attribs.initAttribArrays();
}

void Character::reset()
{
    m_char_data.m_level=0;
    m_name="EMPTY";
    m_char_data.m_class_name="EMPTY";
    m_char_data.m_origin_name="EMPTY";
    m_villain=false;
    m_multiple_costumes=false;
    m_current_costume_idx=0;
    m_current_costume_set=false;
    m_char_data.m_supergroup_costume=false;
    m_sg_costume=nullptr;
    m_char_data.m_using_sg_costume=false;
    m_char_data.m_has_titles = false;
    m_char_data.m_sidekick.m_has_sidekick = false;
}


bool Character::isEmpty()
{
    return ( 0==m_name.compare("EMPTY",Qt::CaseInsensitive)&&
            (0==m_char_data.m_class_name.compare("EMPTY",Qt::CaseInsensitive)));
}

void Character::setName(const QString &val )
{
    if(val.length()>0)
        m_name = val;
    else
        m_name = "EMPTY";
}

void Character::sendTray(BitStream &bs) const
{
    m_char_data.m_trays.serializeto(bs);
}

void Character::GetCharBuildInfo(BitStream &src)
{
    m_char_data.m_level = 0;
    src.GetString(m_char_data.m_class_name);
    src.GetString(m_char_data.m_origin_name);
    CharacterPowerSet primaryset, secondaryset;
    CharacterPower primary, secondary;
    primary.power_id.serializefrom(src);
    secondary.power_id.serializefrom(src);

    primaryset.m_powers.push_back(primary); // primary_powerset power
    secondaryset.m_powers.push_back(secondary); // secondary_powerset power
    m_char_data.m_trays.serializefrom(src);
}

void Character::SendCharBuildInfo(BitStream &bs) const
{
    Character c = *this;
    PowerPool_Info null_power = {0,0,0};
    bs.StoreString(getClass(c));   // class name
    bs.StoreString(getOrigin(c));  // origin name
    bs.StorePackedBits(5, getCombatLevel(c)); // related to combat level?
    PUTDEBUG("SendCharBuildInfo after plevel");

    {
        // TODO: this is character powers related, refactor it out of here.
        bs.StorePackedBits(4, m_char_data.m_powersets.size()); // count
        for(const CharacterPowerSet &pset : m_char_data.m_powersets)
        {
            bs.StorePackedBits(5, pset.m_level_bought);
            bs.StorePackedBits(4, pset.m_powers.size());
            for(const CharacterPower &power : pset.m_powers)
            {
                //sendPower(bs,0,0,0);
                power.power_id.serializeto(bs);
                bs.StorePackedBits(5, power.bought_at_level);
                bs.StoreFloat(power.range);<commit_msg>Added powersets to array. Whooops<commit_after>/*
 * SEGS - Super Entity Game Server
 * http://www.segs.io/
 * Copyright (c) 2006 - 2018 SEGS Team (see AUTHORS.md)
 * This software is licensed under the terms of the 3-clause BSD License. See LICENSE.md for details.
 */

/*!
 * @addtogroup NetStructures Projects/CoX/Common/NetStructures
 * @{
 */

#include "Character.h"

#include "BitStream.h"
#include "Entity.h"
#include "Costume.h"
#include "Friend.h"
#include "Powers.h"
#include "GameData/serialization_common.h"
#include "Servers/GameDatabase/GameDBSyncEvents.h"
#include "GameData/chardata_serializers.h"
#include "GameData/entitydata_serializers.h"
#include "GameData/playerdata_definitions.h"
#include "GameData/playerdata_serializers.h"
#include "Servers/MapServer/DataHelpers.h"
#include "Logging.h"
#include <QtCore/QString>
#include <QtCore/QDebug>

// Anonymous namespace
namespace {

}
// End Anonymous namespace

Character::Character()
{
    m_multiple_costumes                         = false;
    m_current_costume_idx                       = 0;
    m_current_costume_set                       = false;
    m_char_data.m_supergroup_costume            = false;
    m_sg_costume                                = nullptr;
    m_char_data.m_using_sg_costume              = false;
    m_char_data.m_current_attribs.m_HitPoints   = 25;
    m_max_attribs.m_HitPoints                   = 50;
    m_char_data.m_current_attribs.m_Endurance   = 33;
    m_max_attribs.m_Endurance                   = 43;
    m_char_data.m_has_titles = m_char_data.m_has_the_prefix
            || !m_char_data.m_titles[0].isEmpty()
            || !m_char_data.m_titles[1].isEmpty()
            || !m_char_data.m_titles[2].isEmpty();
    m_char_data.m_sidekick.m_has_sidekick = false;
    m_char_data.m_current_attribs.initAttribArrays();
}

void Character::reset()
{
    m_char_data.m_level=0;
    m_name="EMPTY";
    m_char_data.m_class_name="EMPTY";
    m_char_data.m_origin_name="EMPTY";
    m_villain=false;
    m_multiple_costumes=false;
    m_current_costume_idx=0;
    m_current_costume_set=false;
    m_char_data.m_supergroup_costume=false;
    m_sg_costume=nullptr;
    m_char_data.m_using_sg_costume=false;
    m_char_data.m_has_titles = false;
    m_char_data.m_sidekick.m_has_sidekick = false;
}


bool Character::isEmpty()
{
    return ( 0==m_name.compare("EMPTY",Qt::CaseInsensitive)&&
            (0==m_char_data.m_class_name.compare("EMPTY",Qt::CaseInsensitive)));
}

void Character::setName(const QString &val )
{
    if(val.length()>0)
        m_name = val;
    else
        m_name = "EMPTY";
}

void Character::sendTray(BitStream &bs) const
{
    m_char_data.m_trays.serializeto(bs);
}

void Character::GetCharBuildInfo(BitStream &src)
{
    m_char_data.m_level = 0;
    src.GetString(m_char_data.m_class_name);
    src.GetString(m_char_data.m_origin_name);

    CharacterPowerSet primaryset, secondaryset;
    CharacterPower primary, secondary;
    primary.power_id.serializefrom(src);
    secondary.power_id.serializefrom(src);
    primaryset.m_powers.push_back(primary); // primary_powerset power
    secondaryset.m_powers.push_back(secondary); // secondary_powerset power
    m_char_data.m_powersets.push_back(primaryset);
    m_char_data.m_powersets.push_back(secondaryset);

    m_char_data.m_trays.serializefrom(src);
}

void Character::SendCharBuildInfo(BitStream &bs) const
{
    Character c = *this;
    PowerPool_Info null_power = {0,0,0};
    bs.StoreString(getClass(c));   // class name
    bs.StoreString(getOrigin(c));  // origin name
    bs.StorePackedBits(5, getCombatLevel(c)); // related to combat level?
    PUTDEBUG("SendCharBuildInfo after plevel");

    {
        // TODO: this is character powers related, refactor it out of here.
        bs.StorePackedBits(4, m_char_data.m_powersets.size()); // count
        for(const CharacterPowerSet &pset : m_char_data.m_powersets)
        {
            bs.StorePackedBits(5, pset.m_level_bought);
            bs.StorePackedBits(4, pset.m_powers.size());
            for(const CharacterPower &power : pset.m_powers)
            {
                //sendPower(bs,0,0,0);
                power.power_id.serializeto(bs);
                bs.StorePackedBits(5, power.bought_at_level);
                bs.StoreFloat(power.range);
{'fraction_non_alphanumeric': 0.112817483756645, 'fraction_numerical': 0.00897814530419374, 'mean_word_length': 3.197322756569162, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6952340', 'n_tokens_mistral': 3052, 'n_tokens_neox': 2972, 'n_words': 437}