Yardım Game Source Build

  • Konuyu açan Konuyu açan DarkNight
  • Açılış Tarihi Açılış Tarihi
  • Yanıt Yanıt 7
  • Gösterim Gösterim 78
Konu sahibi bu konuda soru soruyor. Sorusu ile ilgili bilgisi olanların yanıtlamasını bekliyor.

DarkNight

Üye
Üye
Mesaj
136
Çözümler
8
Beğeni
27
Puan
454
Ticaret Puanı
0
Sökmüş olduğum sistem g++10 da derlenen bir filesden söküldü ancak benim filesim gcc49 destekliyor. Build alırken almış olduğum hata görseli şu şekilde;
Derleme ve uyarlamada yardımcı olunursa temel düzenlemelerle sistemi değiştirip foruma kazandırmak istiyorum.
Sevgiler


hata.webp


BossDamageRanking.h:
Genişlet Daralt Kopyala
#pragma once

// #ifdef ENABLE_BOSS_DAMAGE_RANKING
using TBossInfo = struct SBossInfo
{
    DWORD   dwVnum;
    DWORD   dwMaxHP;
    DWORD   dwMapIDX;
    long    posX;
    long    posY;
    WORD    wReturnMin;
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
    bool    bIsSafeZone;
#endif
    bool    bIsSpawn;
    std::vector<std::pair<DWORD, DWORD>> gift_info; // -> gifts vnum & count
};
// #endif

class BossDamageInfo
{
    using TPlayerInfo = struct SPlayerInfo
    {
        DWORD   dwID;
        BYTE    bRace;
        const char* cName;
        BYTE    bLevel;
        BYTE    bEmpire;
        DWORD    dwDamage;

        bool operator < (const auto& a) const {
            return dwDamage > a.dwDamage;
    }

    };
    using DAMAGE_VEC = std::vector<TPlayerInfo>;

    public:
        BossDamageInfo(const TBossInfo& info);
        ~BossDamageInfo();

        // auto    Initialize() -> void;

        auto    AddPlayer(LPCHARACTER ch, DWORD dam) -> void;
        auto    PlayerAction(LPCHARACTER ch, DWORD dam) -> void;
        auto    SendRankings(bool isDead = false) -> void;
        auto    SpawnMob() -> void;
        auto    ErasePlayer(uint32_t pid) -> void;
        // auto    CreateTimer() -> void;
        // auto    CloseTimer() -> void;
        auto    Destroy() -> void;

/* Set - Get funcs */
        auto    SetVnum(const DWORD val) -> void { m_Info.dwVnum = val; }
        auto    GetVnum() const -> DWORD { return m_Info.dwVnum; }
        auto    SetHP(const DWORD val) -> void { m_Info.dwMaxHP = val; }
        auto    GetHP() const -> DWORD { return m_Info.dwMaxHP; }
        auto    SetMapIDX(const DWORD val) -> void { m_Info.dwMapIDX = val; }
        auto    GetMapIDX() const -> DWORD { return m_Info.dwMapIDX; }
        auto    SetPosX(const long val) -> void { m_Info.posX = val; }
        auto    GetPosX() const -> long { return m_Info.posX; }
        auto    SetPosY(const long val) -> void { m_Info.posY = val; }
        auto    GetPosY() const -> long { return m_Info.posY; }
        auto    SetReturnTime(const WORD val) { m_Info.wReturnMin = val; }
        auto    GetReturnTime() const -> WORD { return m_Info.wReturnMin; }
        auto    SetIsSpawn(const bool val) { m_Info.bIsSpawn = val; }
        auto    GetIsSpawn() const -> bool { return m_Info.bIsSpawn; }
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
        auto    SetIsSafeZone(const bool val) -> void;
        auto    GetIsSafeZone() const -> bool { return m_Info.bIsSafeZone; }
#endif
        // auto    PushGift(const std::pair<DWORD, DWORD> info) { m_Info.emplace_back(info); }
        auto    GetGiftWithIDX(const BYTE idx) -> std::pair<DWORD, DWORD>;
/* Set - Get funcs */
    private:
        DAMAGE_VEC      m_DmgVec;
        TBossInfo       m_Info;
};

class BossDamageInfo;

class CBossDamageRanking final : public singleton<CBossDamageRanking>
{
    public:
        CBossDamageRanking() = default;
        ~CBossDamageRanking() = default;

        BossDamageInfo* FindBossClass(DWORD dwID) const;

        auto    Initialize() -> bool;
        auto    CheckBoss(const int hour, const int min) const -> void;
        auto    CreateTimer() -> void;
        auto    CloseTimer() -> void;
        auto    Destroy() -> void;
        auto    IsRankingBoss(const DWORD dwVnum) const -> bool;
        auto    SendGUIData(LPCHARACTER ch) -> void;
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
        auto    CheckSafeZone(LPCHARACTER ch) -> void;
#endif
        auto    CheckPlayerID(uint32_t pid) -> void;
    private:
        std::map<DWORD, std::unique_ptr<BossDamageInfo>> boss_Map;
        LPEVENT         spawnEvent;
};
 
Merhaba,
Aşağı yukarı göz attığımda değişeçek birden fazla yer var. Ayrıca dinamik olarak manuel temizletme yapmamız gerekebilir. Ancak zaten değişecek kısımlar belli.
Mesela :
unique_ptr gibi akıllı işaretçiler mesela, auto yerine void gibi doğrudan dönüş tipi gibi.
Sonrasında nullptr yerine NULL kullanmak gibi.
Aşağıdaki kodları örnek yazıyorum. Muhtemelen hata gidecektir. Ancak sistemde ne gibi sorun yaratır. Deneyip görmek lazım.

Kod:
Genişlet Daralt Kopyala
#pragma once

// #ifdef ENABLE_BOSS_DAMAGE_RANKING
typedef struct SBossInfo
{
    DWORD   dwVnum;
    DWORD   dwMaxHP;
    DWORD   dwMapIDX;
    long    posX;
    long    posY;
    WORD    wReturnMin;
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
    bool    bIsSafeZone;
#endif
    bool    bIsSpawn;
    std::vector<std::pair<DWORD, DWORD>> gift_info; // -> gifts vnum & count
} TBossInfo;
// #endif

class BossDamageInfo
{
    typedef struct SPlayerInfo
    {
        DWORD   dwID;
        BYTE    bRace;
        const char* cName;
        BYTE    bLevel;
        BYTE    bEmpire;
        DWORD   dwDamage;

        bool operator < (const SPlayerInfo& a) const {
            return dwDamage > a.dwDamage;
        }

    } TPlayerInfo;

    typedef std::vector<TPlayerInfo> DAMAGE_VEC;

public:
    BossDamageInfo(const TBossInfo& info);
    ~BossDamageInfo();

    void AddPlayer(LPCHARACTER ch, DWORD dam);
    void PlayerAction(LPCHARACTER ch, DWORD dam);
    void SendRankings(bool isDead = false);
    void SpawnMob();
    void ErasePlayer(uint32_t pid);
    void Destroy();

/* Set - Get funcs */
    void SetVnum(const DWORD val) { m_Info.dwVnum = val; }
    DWORD GetVnum() const { return m_Info.dwVnum; }
    void SetHP(const DWORD val) { m_Info.dwMaxHP = val; }
    DWORD GetHP() const { return m_Info.dwMaxHP; }
    void SetMapIDX(const DWORD val) { m_Info.dwMapIDX = val; }
    DWORD GetMapIDX() const { return m_Info.dwMapIDX; }
    void SetPosX(const long val) { m_Info.posX = val; }
    long GetPosX() const { return m_Info.posX; }
    void SetPosY(const long val) { m_Info.posY = val; }
    long GetPosY() const { return m_Info.posY; }
    void SetReturnTime(const WORD val) { m_Info.wReturnMin = val; }
    WORD GetReturnTime() const { return m_Info.wReturnMin; }
    void SetIsSpawn(const bool val) { m_Info.bIsSpawn = val; }
    bool GetIsSpawn() const { return m_Info.bIsSpawn; }
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
    void SetIsSafeZone(const bool val);
    bool GetIsSafeZone() const { return m_Info.bIsSafeZone; }
#endif
    std::pair<DWORD, DWORD> GetGiftWithIDX(const BYTE idx);
/* Set - Get funcs */
private:
    DAMAGE_VEC      m_DmgVec;
    TBossInfo       m_Info;
};

class CBossDamageRanking final : public singleton<CBossDamageRanking>
{
public:
    CBossDamageRanking() = default;
    ~CBossDamageRanking() {
        ClearMap();
    }

    BossDamageInfo* FindBossClass(DWORD dwID) const;

    bool Initialize();
    void CheckBoss(const int hour, const int min) const;
    void CreateTimer();
    void CloseTimer();
    void Destroy();
    bool IsRankingBoss(const DWORD dwVnum) const;
    void SendGUIData(LPCHARACTER ch);
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
    void CheckSafeZone(LPCHARACTER ch);
#endif
    void CheckPlayerID(uint32_t pid);

private:
    void ClearMap() {
        for (auto& pair : boss_Map) {
            delete pair.second;
        }
        boss_Map.clear();
    }
    std::map<DWORD, BossDamageInfo*> boss_Map;
    LPEVENT spawnEvent = NULL;
};
 
Merhaba,
Aşağı yukarı göz attığımda değişeçek birden fazla yer var. Ayrıca dinamik olarak manuel temizletme yapmamız gerekebilir. Ancak zaten değişecek kısımlar belli.
Mesela :
unique_ptr gibi akıllı işaretçiler mesela, auto yerine void gibi doğrudan dönüş tipi gibi.
Sonrasında nullptr yerine NULL kullanmak gibi.
Aşağıdaki kodları örnek yazıyorum. Muhtemelen hata gidecektir. Ancak sistemde ne gibi sorun yaratır. Deneyip görmek lazım.

Kod:
Genişlet Daralt Kopyala
#pragma once

// #ifdef ENABLE_BOSS_DAMAGE_RANKING
typedef struct SBossInfo
{
    DWORD   dwVnum;
    DWORD   dwMaxHP;
    DWORD   dwMapIDX;
    long    posX;
    long    posY;
    WORD    wReturnMin;
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
    bool    bIsSafeZone;
#endif
    bool    bIsSpawn;
    std::vector<std::pair<DWORD, DWORD>> gift_info; // -> gifts vnum & count
} TBossInfo;
// #endif

class BossDamageInfo
{
    typedef struct SPlayerInfo
    {
        DWORD   dwID;
        BYTE    bRace;
        const char* cName;
        BYTE    bLevel;
        BYTE    bEmpire;
        DWORD   dwDamage;

        bool operator < (const SPlayerInfo& a) const {
            return dwDamage > a.dwDamage;
        }

    } TPlayerInfo;

    typedef std::vector<TPlayerInfo> DAMAGE_VEC;

public:
    BossDamageInfo(const TBossInfo& info);
    ~BossDamageInfo();

    void AddPlayer(LPCHARACTER ch, DWORD dam);
    void PlayerAction(LPCHARACTER ch, DWORD dam);
    void SendRankings(bool isDead = false);
    void SpawnMob();
    void ErasePlayer(uint32_t pid);
    void Destroy();

/* Set - Get funcs */
    void SetVnum(const DWORD val) { m_Info.dwVnum = val; }
    DWORD GetVnum() const { return m_Info.dwVnum; }
    void SetHP(const DWORD val) { m_Info.dwMaxHP = val; }
    DWORD GetHP() const { return m_Info.dwMaxHP; }
    void SetMapIDX(const DWORD val) { m_Info.dwMapIDX = val; }
    DWORD GetMapIDX() const { return m_Info.dwMapIDX; }
    void SetPosX(const long val) { m_Info.posX = val; }
    long GetPosX() const { return m_Info.posX; }
    void SetPosY(const long val) { m_Info.posY = val; }
    long GetPosY() const { return m_Info.posY; }
    void SetReturnTime(const WORD val) { m_Info.wReturnMin = val; }
    WORD GetReturnTime() const { return m_Info.wReturnMin; }
    void SetIsSpawn(const bool val) { m_Info.bIsSpawn = val; }
    bool GetIsSpawn() const { return m_Info.bIsSpawn; }
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
    void SetIsSafeZone(const bool val);
    bool GetIsSafeZone() const { return m_Info.bIsSafeZone; }
#endif
    std::pair<DWORD, DWORD> GetGiftWithIDX(const BYTE idx);
/* Set - Get funcs */
private:
    DAMAGE_VEC      m_DmgVec;
    TBossInfo       m_Info;
};

class CBossDamageRanking final : public singleton<CBossDamageRanking>
{
public:
    CBossDamageRanking() = default;
    ~CBossDamageRanking() {
        ClearMap();
    }

    BossDamageInfo* FindBossClass(DWORD dwID) const;

    bool Initialize();
    void CheckBoss(const int hour, const int min) const;
    void CreateTimer();
    void CloseTimer();
    void Destroy();
    bool IsRankingBoss(const DWORD dwVnum) const;
    void SendGUIData(LPCHARACTER ch);
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
    void CheckSafeZone(LPCHARACTER ch);
#endif
    void CheckPlayerID(uint32_t pid);

private:
    void ClearMap() {
        for (auto& pair : boss_Map) {
            delete pair.second;
        }
        boss_Map.clear();
    }
    std::map<DWORD, BossDamageInfo*> boss_Map;
    LPEVENT spawnEvent = NULL;
};
Sisteme ait söktüğüm kodların bütününü burada paylaşsam ilgili düzenlemeler sonrasında kullanmak isteyenlerinde faydasına olur diye düşünüyorum yardımcı olursanız sevinirim.
 
Sisteme ait söktüğüm kodların bütününü burada paylaşsam ilgili düzenlemeler sonrasında kullanmak isteyenlerinde faydasına olur diye düşünüyorum yardımcı olursanız sevinirim.
Eğer bu düzenlemeyle ilgili çalışırsa kendimede ekler kontrol ederim. build etmeyi bi deneyin.
 
19831 eklentisini görüntüle

düzenlemeleriniz sonrasında build alırken şöyle bir hata aldım.
Bunlardan kaynaklı hata vermiş.
C++:
Genişlet Daralt Kopyala
CBossDamageRanking::IsRankingBoss
CBossDamageRanking::CheckPlayerID
CBossDamageRanking::FindBossClass
CBossDamageRanking::SendGUIData
CBossDamageRanking::Initialize
CBossDamageRanking::Destroy
BossDamageInfo::SendRankings
BossDamageInfo::PlayerAction

BossDamageRanking.cpp içerisinde bunlar mevcut olmayabilir sanırım. Kontrol edermisin.
 
BossDamageRanking.cpp:
Genişlet Daralt Kopyala
#include "stdafx.h"
#ifdef ENABLE_BOSS_DAMAGE_RANKING
// #include "buffer_manager.h"
#include "config.h"
#include "char_manager.h"
#include "desc.h"
#include "char.h"
#include "BossDamageRanking.h"
#include "mob_manager.h"
#include "sectree_manager.h"

// #define USING_JSON_FOR_INFOS
#ifdef USING_JSON_FOR_INFOS
    #include "locale_service.h"
    #include <fstream>
    #include <nlohmann/json.hpp>
    using json = nlohmann::json;
#else
    #include "db.h"
#endif


// #define ENABLE_RANKING_NOTICE // -> when spawn boss sending notice

// #if (__cplusplus >= 202002L) // -> check c++ version
//     #include <ranges>
// #endif

#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
    // constexpr BYTE GUVENLI_ALAN_SURE = 1;
    constexpr BYTE CHECK_HOUR = 59;
#endif

// bossdamageclass

EVENTINFO(ranking_boss_regen_info)
{
    CBossDamageRanking     *pClass;

    ranking_boss_regen_info() : pClass(nullptr)
    {
    }
};

EVENTFUNC(ranking_regen_event)
{
    auto* info = dynamic_cast<ranking_boss_regen_info*>(event->info);

    if (info == NULL)
    {
        sys_err(">ranking_regen_event> <Factor> Null pointer");
        return 0;
    }

    auto* pClass = info->pClass;
    if (!pClass) { return 0;}

    time_t cur_Time = time(NULL);
    struct tm vKey = *localtime(&cur_Time);

    int hour = vKey.tm_hour;
    int minute = vKey.tm_min;
    pClass->CheckBoss(hour, minute);

    return PASSES_PER_SEC(60);
}

BossDamageInfo::BossDamageInfo(const TBossInfo & info) {
    SetVnum(info.dwVnum);
    SetHP(info.dwMaxHP);
    SetMapIDX(info.dwMapIDX);
    SetPosX(info.posX);
    SetPosY(info.posY);
    SetReturnTime(info.wReturnMin);
    m_Info.gift_info = info.gift_info;
    SpawnMob(); // -> when open game spawn boss
}

BossDamageInfo::~BossDamageInfo() {
    Destroy();
    sys_err("Bossdamageinfo has been destroyed!");
}

BossDamageInfo* CBossDamageRanking::FindBossClass(const DWORD dwVnum) const
{
    const auto& it = boss_Map.find(dwVnum);
    return it != boss_Map.cend() ? it->second.get() : nullptr;
}

auto BossDamageInfo::AddPlayer(LPCHARACTER ch, const DWORD dam) -> void {
    if (!ch || !ch->GetDesc()) { return; }
    const auto& it = std::find_if(std::begin(m_DmgVec), std::end(m_DmgVec),
         [&](const TPlayerInfo& a) { return ch->GetPlayerID() == a.dwID; }
    );
    if (it != std::end(m_DmgVec)) { return; }

    TPlayerInfo info = {};
    info.dwID = ch->GetPlayerID();
    info.bRace = ch->GetJob();
    info.cName = ch->GetName();
    info.bLevel = ch->GetLevel();
    info.bEmpire = ch->GetEmpire();
    info.dwDamage = dam;
    m_DmgVec.emplace_back(info);
    ch->ChatPacket(CHAT_TYPE_COMMAND, "ClearItems");
    for (const auto& it : m_Info.gift_info) {
        if (it.first == 0 || it.second == 0) { break; }
        ch->ChatPacket(CHAT_TYPE_COMMAND, "BossDamageRankingItem %u %u", it.first, it.second);
    }
    ch->ChatPacket(CHAT_TYPE_COMMAND, "OpenBossDamageRanking");
}

auto BossDamageInfo::PlayerAction(LPCHARACTER ch, const DWORD dam) -> void {
    if (!ch || !ch->GetDesc()) { return; }
    const auto& it = std::find_if(std::begin(m_DmgVec), std::end(m_DmgVec),
         [&](const TPlayerInfo& a) { return ch->GetPlayerID() == a.dwID; }
    );
    
    if (it != std::end(m_DmgVec)) {
        it->dwDamage += dam;
    }
    else {
        AddPlayer(ch, dam);
    }
    SendRankings();
}

auto BossDamageInfo::SendRankings(const bool isDead) -> void {
    if (m_DmgVec.empty()) { return; }

    std::sort(std::begin(m_DmgVec), std::end(m_DmgVec));
    const size_t size = m_DmgVec.size() > 5 ? 5 : m_DmgVec.size();
    std::vector<TPlayerInfo> vec = std::vector<TPlayerInfo>(std::begin(m_DmgVec), std::next(std::begin(m_DmgVec), size));

    if (vec.size() >= 5) {
        vec.resize(5);
        vec.shrink_to_fit();
    }

    for (auto&& it : m_DmgVec)
    {
        const LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(it.dwID);
        if (!ch || !ch->GetDesc()) { continue; }
        BYTE idx = 0;
        ch->ChatPacket(CHAT_TYPE_COMMAND, "ClearRanks");
        for (const auto& snd : vec)
        {
            BYTE percentDmg = std::clamp(static_cast<BYTE>((snd.dwDamage * 100) / (GetHP())), static_cast<BYTE>(0), static_cast<BYTE>(100));
            TBossDamageGCRankingData pack = {};
            pack.bHeader = HEADER_GC_BOSS_RANKING_INFO;
            pack.bRank = idx++;
            pack.bRaceNum = snd.bRace;
            std::strcpy(pack.cName, snd.cName);
            pack.bLevel = snd.bLevel;
            pack.bEmpire = snd.bEmpire;
            pack.bDamage = percentDmg;
            ch->GetDesc()->Packet(&pack, sizeof(pack));
        }
        if (isDead) {
            ch->ChatPacket(CHAT_TYPE_COMMAND, "CloseBossDamageRanking");
        }
        else {
        ch->ChatPacket(CHAT_TYPE_COMMAND, "LoadRanks");
        }
    }

    if (isDead) { // -> give gifts
        BYTE rank = 0;
        for (const auto& it :vec)
        {
            const LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(it.dwID);
            if (!ch || !ch->GetDesc()) { continue; }
#if (__cplusplus >= 201703L)
            std::pair<DWORD, DWORD> p = GetGiftWithIDX(rank++);
            if (p.first && p.second) {
                ch->AutoGiveItem(p.first, p.second);
            }
#else
            const auto& [vnum, count] = GetGiftWithIDX(rank++);
            if (vnum && count)
                ch->AutoGiveItem(vnum, count);
#endif
         }

        SetIsSpawn(false);
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
        SetIsSafeZone(false);
#endif
        Destroy();
        // CreateTimer();
    }

    vec.clear();
}

auto BossDamageInfo::SpawnMob() -> void {
    if (GetIsSpawn()) { return; }
    CHARACTER_MANAGER::instance().SpawnMob(GetVnum(), GetMapIDX(), GetPosX() * 100, GetPosY() * 100, 0, false, 360);
    SetIsSpawn(true);
#ifdef ENABLE_RANKING_NOTICE
    char szNotice[52] = {};
    snprintf(szNotice, sizeof(szNotice), "Spawn Notice");
    BroadcastNotice(szNotice);
#endif
}

auto BossDamageInfo::ErasePlayer(const uint32_t pid) -> void {
    m_DmgVec.erase(
    std::remove_if(m_DmgVec.begin(), m_DmgVec.end(), [&](TPlayerInfo const & elm) {
        return elm.dwID == pid;
    }),m_DmgVec.end());
    SendRankings();
}

#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
auto BossDamageInfo::SetIsSafeZone(const bool isSafe) -> void {
    auto pMap = SECTREE_MANAGER::instance().GetMap(GetMapIDX());
    if (pMap) {
        char szNotice[52] = {};
        const auto& ExitAllFunc = [&](LPENTITY ent) -> void {
            if (ent->IsType(ENTITY_CHARACTER))
            {
                auto ch = (LPCHARACTER)ent;
                if(!ch || !ch->IsPC()) { return; }
                snprintf(szNotice, sizeof(szNotice), "Bu bolgede korumali alan %s!", isSafe ? "aktif edildi" : "deaktif edildi");
                ch->ChatPacket(CHAT_TYPE_COMMAND, "BossDamageRankingSafeZone %d", isSafe);
                ch->ChatPacket(CHAT_TYPE_BIG_NOTICE, szNotice);
            }
        };
        pMap->for_each(ExitAllFunc);
    }
    m_Info.bIsSafeZone = isSafe;
}
#endif

auto BossDamageInfo::GetGiftWithIDX(const BYTE idx) -> std::pair<DWORD, DWORD> {
    if (idx > m_Info.gift_info.size()) {
        return std::make_pair(0,0);
    }
    return std::make_pair(m_Info.gift_info[idx].first, m_Info.gift_info[idx].second);
}

auto BossDamageInfo::Destroy() -> void {
    m_DmgVec.clear();
}

// bossdamageclass end
 

auto CBossDamageRanking::CheckBoss(const int hour, const int min) const -> void {
    for (const auto& elm : boss_Map)
    {
        const auto it = FindBossClass(elm.first);
        if (!it) { continue; }
        const bool isHour = it->GetReturnTime() % 60 == 1;
        if(isHour)
        {
            // if (min % )
            const bool mintoHour = it->GetReturnTime() / 60 == 0;
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
            if (mintoHour && min % it->GetReturnTime() == 1) {
                it->SetIsSafeZone(true);
            }
#endif
            if (mintoHour && min == 0){
                it->SpawnMob();
            }
        }
        else {
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
            if (min % it->GetReturnTime() == 1) {
                it->SetIsSafeZone(true);
            }
#endif
            if (min % it->GetReturnTime() == 0) {
                it->SpawnMob();
            }
        }
    }
}

auto CBossDamageRanking::CreateTimer() -> void {
    CloseTimer();

    auto* info = AllocEventInfo<ranking_boss_regen_info>();
    info->pClass = this;
    spawnEvent = event_create(ranking_regen_event, info, PASSES_PER_SEC(30));
}

auto CBossDamageRanking::CloseTimer() -> void {
    if (spawnEvent) {
        event_cancel(&spawnEvent);
        spawnEvent = nullptr;
    }
}

auto CBossDamageRanking::Initialize() -> bool {
#ifdef USING_JSON_FOR_INFOS
    char file_name[256+1];
    snprintf(file_name, sizeof(file_name), "%s/bossdamage_info.json", LocaleService_GetBasePath().c_str());
    std::ifstream ifs(file_name);
    if (!ifs.is_open()) { return false; }

    try {
        json jf = json::parse(ifs);

        json& arr = jf["boss_info"];
        for (const auto& i : arr) {
            TBossInfo info = {};
            i.at("boss_vnum").get_to(info.dwVnum);
            //mobtable control
            const auto* pMob = CMobManager::instance().Get(info.dwVnum);
            if (!pMob) {
                sys_err("Bossdamage_info.json have wrong boss! vnum : %u pls check it!", info.dwVnum);
                continue;
            }

            i.at("map_index").get_to(info.dwMapIDX);
            i.at("spawn_x").get_to(info.posX);
            i.at("spawn_y").get_to(info.posY);
            i.at("return_time").get_to(info.wReturnMin);
            info.dwMaxHP = pMob->m_table.dwMaxHP;

            for(const auto& [vnum, count] : i["gift_items"].items()) {
                const DWORD vnm = std::stoi(vnum);
                const DWORD cnt = count.get<DWORD>();
                info.gift_info.emplace_back(vnm, cnt);
            }

            boss_Map.emplace(info.dwVnum, std::make_unique<BossDamageInfo>(info));
        }
        ifs.close();
    }
    catch (const std::exception& e) {
        sys_err("ReadBossDamageError error : %s - file : %s", e.what(), file_name);
        return false;
    }
#else
        const std::unique_ptr<SQLMsg> pkMsg(DBManager::instance().DirectQuery("SELECT * FROM boss_damage_ranking%s", get_table_postfix()));

        if (pkMsg->Get()->uiNumRows == 0) {
            sys_err("boss_damage_ranking table is empty");
            return false;
        }
        boss_Map.clear();
        MYSQL_ROW row;
        while ((row = mysql_fetch_row(pkMsg->Get()->pSQLResult)) != nullptr)
        {
            DWORD col = 1;

            TBossInfo info = {};
            str_to_number(info.dwVnum, row[col++]);

            const auto* pMob = CMobManager::instance().Get(info.dwVnum);
            if (!pMob) {
                sys_err("Bossdamage_info.json have wrong boss! vnum : %u pls check it!", info.dwVnum);
                continue;
            }
            info.dwMaxHP = pMob->m_table.dwMaxHP;
            str_to_number(info.dwMapIDX, row[col++]);
            str_to_number(info.posX, row[col++]);
            str_to_number(info.posY, row[col++]);
            str_to_number(info.wReturnMin, row[col++]);

            for (uint8_t i(0); i < 5; ++i) {
                DWORD vnum, count = 0;
                str_to_number(vnum, row[col++]);
                str_to_number(count, row[col++]);
                info.gift_info.emplace_back(vnum, count);
            }


            auto data = std::unique_ptr<BossDamageInfo>(new BossDamageInfo(info));
            boss_Map.emplace(info.dwVnum, std::move(data));
        }
#endif
    CreateTimer();
    return true;
}

auto CBossDamageRanking::SendGUIData(LPCHARACTER ch) -> void {
    if (!ch || !ch->GetDesc()) { return; }

    for (const auto& elm : boss_Map) {
        const auto it = FindBossClass(elm.first);
        if (!it) { continue; }
        ch->ChatPacket(CHAT_TYPE_COMMAND, "BossRankingUI %u %u %u %u %u", elm.first, it->GetMapIDX(), it->GetPosX(), it->GetPosY(), it->GetReturnTime());
    }
}

auto CBossDamageRanking::IsRankingBoss(const DWORD dwVnum) const -> bool {
#if (__cplusplus >= 202002L)
        return boss_Map.contains(dwVnum); // -> c++20 is have contains func
#endif
    const auto& it = boss_Map.find(dwVnum);
    return it != boss_Map.cend() ? true : false;
}

#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
auto CBossDamageRanking::CheckSafeZone(LPCHARACTER ch) -> void {
    if (!ch) { return; }
    DWORD dwVnum = 0;
    for (const auto& it : boss_Map){
        if (it.second->GetMapIDX() == ch->GetMapIndex()) {
            dwVnum = it.first;
            break;
        }
    }
    const auto it = FindBossClass(dwVnum);
    if (!it) { return; }
    if(it->GetIsSafeZone()) {
        ch->ChatPacket(CHAT_TYPE_COMMAND, "BossDamageRankingSafeZone %d", 1);
    }

}
#endif

auto CBossDamageRanking::CheckPlayerID(const uint32_t pid) -> void {
    for (const auto& it : boss_Map) {
        it.second->ErasePlayer(pid);
    }
}

auto CBossDamageRanking::Destroy() -> void {
    CloseTimer();
    boss_Map.clear();
}
#endif
 
BossDamageRanking.cpp:
Genişlet Daralt Kopyala
#include "stdafx.h"
#ifdef ENABLE_BOSS_DAMAGE_RANKING
// #include "buffer_manager.h"
#include "config.h"
#include "char_manager.h"
#include "desc.h"
#include "char.h"
#include "BossDamageRanking.h"
#include "mob_manager.h"
#include "sectree_manager.h"

// #define USING_JSON_FOR_INFOS
#ifdef USING_JSON_FOR_INFOS
    #include "locale_service.h"
    #include <fstream>
    #include <nlohmann/json.hpp>
    using json = nlohmann::json;
#else
    #include "db.h"
#endif


// #define ENABLE_RANKING_NOTICE // -> when spawn boss sending notice

// #if (__cplusplus >= 202002L) // -> check c++ version
//     #include <ranges>
// #endif

#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
    // constexpr BYTE GUVENLI_ALAN_SURE = 1;
    constexpr BYTE CHECK_HOUR = 59;
#endif

// bossdamageclass

EVENTINFO(ranking_boss_regen_info)
{
    CBossDamageRanking     *pClass;

    ranking_boss_regen_info() : pClass(nullptr)
    {
    }
};

EVENTFUNC(ranking_regen_event)
{
    auto* info = dynamic_cast<ranking_boss_regen_info*>(event->info);

    if (info == NULL)
    {
        sys_err(">ranking_regen_event> <Factor> Null pointer");
        return 0;
    }

    auto* pClass = info->pClass;
    if (!pClass) { return 0;}

    time_t cur_Time = time(NULL);
    struct tm vKey = *localtime(&cur_Time);

    int hour = vKey.tm_hour;
    int minute = vKey.tm_min;
    pClass->CheckBoss(hour, minute);

    return PASSES_PER_SEC(60);
}

BossDamageInfo::BossDamageInfo(const TBossInfo & info) {
    SetVnum(info.dwVnum);
    SetHP(info.dwMaxHP);
    SetMapIDX(info.dwMapIDX);
    SetPosX(info.posX);
    SetPosY(info.posY);
    SetReturnTime(info.wReturnMin);
    m_Info.gift_info = info.gift_info;
    SpawnMob(); // -> when open game spawn boss
}

BossDamageInfo::~BossDamageInfo() {
    Destroy();
    sys_err("Bossdamageinfo has been destroyed!");
}

BossDamageInfo* CBossDamageRanking::FindBossClass(const DWORD dwVnum) const
{
    const auto& it = boss_Map.find(dwVnum);
    return it != boss_Map.cend() ? it->second.get() : nullptr;
}

auto BossDamageInfo::AddPlayer(LPCHARACTER ch, const DWORD dam) -> void {
    if (!ch || !ch->GetDesc()) { return; }
    const auto& it = std::find_if(std::begin(m_DmgVec), std::end(m_DmgVec),
         [&](const TPlayerInfo& a) { return ch->GetPlayerID() == a.dwID; }
    );
    if (it != std::end(m_DmgVec)) { return; }

    TPlayerInfo info = {};
    info.dwID = ch->GetPlayerID();
    info.bRace = ch->GetJob();
    info.cName = ch->GetName();
    info.bLevel = ch->GetLevel();
    info.bEmpire = ch->GetEmpire();
    info.dwDamage = dam;
    m_DmgVec.emplace_back(info);
    ch->ChatPacket(CHAT_TYPE_COMMAND, "ClearItems");
    for (const auto& it : m_Info.gift_info) {
        if (it.first == 0 || it.second == 0) { break; }
        ch->ChatPacket(CHAT_TYPE_COMMAND, "BossDamageRankingItem %u %u", it.first, it.second);
    }
    ch->ChatPacket(CHAT_TYPE_COMMAND, "OpenBossDamageRanking");
}

auto BossDamageInfo::PlayerAction(LPCHARACTER ch, const DWORD dam) -> void {
    if (!ch || !ch->GetDesc()) { return; }
    const auto& it = std::find_if(std::begin(m_DmgVec), std::end(m_DmgVec),
         [&](const TPlayerInfo& a) { return ch->GetPlayerID() == a.dwID; }
    );
   
    if (it != std::end(m_DmgVec)) {
        it->dwDamage += dam;
    }
    else {
        AddPlayer(ch, dam);
    }
    SendRankings();
}

auto BossDamageInfo::SendRankings(const bool isDead) -> void {
    if (m_DmgVec.empty()) { return; }

    std::sort(std::begin(m_DmgVec), std::end(m_DmgVec));
    const size_t size = m_DmgVec.size() > 5 ? 5 : m_DmgVec.size();
    std::vector<TPlayerInfo> vec = std::vector<TPlayerInfo>(std::begin(m_DmgVec), std::next(std::begin(m_DmgVec), size));

    if (vec.size() >= 5) {
        vec.resize(5);
        vec.shrink_to_fit();
    }

    for (auto&& it : m_DmgVec)
    {
        const LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(it.dwID);
        if (!ch || !ch->GetDesc()) { continue; }
        BYTE idx = 0;
        ch->ChatPacket(CHAT_TYPE_COMMAND, "ClearRanks");
        for (const auto& snd : vec)
        {
            BYTE percentDmg = std::clamp(static_cast<BYTE>((snd.dwDamage * 100) / (GetHP())), static_cast<BYTE>(0), static_cast<BYTE>(100));
            TBossDamageGCRankingData pack = {};
            pack.bHeader = HEADER_GC_BOSS_RANKING_INFO;
            pack.bRank = idx++;
            pack.bRaceNum = snd.bRace;
            std::strcpy(pack.cName, snd.cName);
            pack.bLevel = snd.bLevel;
            pack.bEmpire = snd.bEmpire;
            pack.bDamage = percentDmg;
            ch->GetDesc()->Packet(&pack, sizeof(pack));
        }
        if (isDead) {
            ch->ChatPacket(CHAT_TYPE_COMMAND, "CloseBossDamageRanking");
        }
        else {
        ch->ChatPacket(CHAT_TYPE_COMMAND, "LoadRanks");
        }
    }

    if (isDead) { // -> give gifts
        BYTE rank = 0;
        for (const auto& it :vec)
        {
            const LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(it.dwID);
            if (!ch || !ch->GetDesc()) { continue; }
#if (__cplusplus >= 201703L)
            std::pair<DWORD, DWORD> p = GetGiftWithIDX(rank++);
            if (p.first && p.second) {
                ch->AutoGiveItem(p.first, p.second);
            }
#else
            const auto& [vnum, count] = GetGiftWithIDX(rank++);
            if (vnum && count)
                ch->AutoGiveItem(vnum, count);
#endif
         }

        SetIsSpawn(false);
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
        SetIsSafeZone(false);
#endif
        Destroy();
        // CreateTimer();
    }

    vec.clear();
}

auto BossDamageInfo::SpawnMob() -> void {
    if (GetIsSpawn()) { return; }
    CHARACTER_MANAGER::instance().SpawnMob(GetVnum(), GetMapIDX(), GetPosX() * 100, GetPosY() * 100, 0, false, 360);
    SetIsSpawn(true);
#ifdef ENABLE_RANKING_NOTICE
    char szNotice[52] = {};
    snprintf(szNotice, sizeof(szNotice), "Spawn Notice");
    BroadcastNotice(szNotice);
#endif
}

auto BossDamageInfo::ErasePlayer(const uint32_t pid) -> void {
    m_DmgVec.erase(
    std::remove_if(m_DmgVec.begin(), m_DmgVec.end(), [&](TPlayerInfo const & elm) {
        return elm.dwID == pid;
    }),m_DmgVec.end());
    SendRankings();
}

#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
auto BossDamageInfo::SetIsSafeZone(const bool isSafe) -> void {
    auto pMap = SECTREE_MANAGER::instance().GetMap(GetMapIDX());
    if (pMap) {
        char szNotice[52] = {};
        const auto& ExitAllFunc = [&](LPENTITY ent) -> void {
            if (ent->IsType(ENTITY_CHARACTER))
            {
                auto ch = (LPCHARACTER)ent;
                if(!ch || !ch->IsPC()) { return; }
                snprintf(szNotice, sizeof(szNotice), "Bu bolgede korumali alan %s!", isSafe ? "aktif edildi" : "deaktif edildi");
                ch->ChatPacket(CHAT_TYPE_COMMAND, "BossDamageRankingSafeZone %d", isSafe);
                ch->ChatPacket(CHAT_TYPE_BIG_NOTICE, szNotice);
            }
        };
        pMap->for_each(ExitAllFunc);
    }
    m_Info.bIsSafeZone = isSafe;
}
#endif

auto BossDamageInfo::GetGiftWithIDX(const BYTE idx) -> std::pair<DWORD, DWORD> {
    if (idx > m_Info.gift_info.size()) {
        return std::make_pair(0,0);
    }
    return std::make_pair(m_Info.gift_info[idx].first, m_Info.gift_info[idx].second);
}

auto BossDamageInfo::Destroy() -> void {
    m_DmgVec.clear();
}

// bossdamageclass end
 

auto CBossDamageRanking::CheckBoss(const int hour, const int min) const -> void {
    for (const auto& elm : boss_Map)
    {
        const auto it = FindBossClass(elm.first);
        if (!it) { continue; }
        const bool isHour = it->GetReturnTime() % 60 == 1;
        if(isHour)
        {
            // if (min % )
            const bool mintoHour = it->GetReturnTime() / 60 == 0;
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
            if (mintoHour && min % it->GetReturnTime() == 1) {
                it->SetIsSafeZone(true);
            }
#endif
            if (mintoHour && min == 0){
                it->SpawnMob();
            }
        }
        else {
#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
            if (min % it->GetReturnTime() == 1) {
                it->SetIsSafeZone(true);
            }
#endif
            if (min % it->GetReturnTime() == 0) {
                it->SpawnMob();
            }
        }
    }
}

auto CBossDamageRanking::CreateTimer() -> void {
    CloseTimer();

    auto* info = AllocEventInfo<ranking_boss_regen_info>();
    info->pClass = this;
    spawnEvent = event_create(ranking_regen_event, info, PASSES_PER_SEC(30));
}

auto CBossDamageRanking::CloseTimer() -> void {
    if (spawnEvent) {
        event_cancel(&spawnEvent);
        spawnEvent = nullptr;
    }
}

auto CBossDamageRanking::Initialize() -> bool {
#ifdef USING_JSON_FOR_INFOS
    char file_name[256+1];
    snprintf(file_name, sizeof(file_name), "%s/bossdamage_info.json", LocaleService_GetBasePath().c_str());
    std::ifstream ifs(file_name);
    if (!ifs.is_open()) { return false; }

    try {
        json jf = json::parse(ifs);

        json& arr = jf["boss_info"];
        for (const auto& i : arr) {
            TBossInfo info = {};
            i.at("boss_vnum").get_to(info.dwVnum);
            //mobtable control
            const auto* pMob = CMobManager::instance().Get(info.dwVnum);
            if (!pMob) {
                sys_err("Bossdamage_info.json have wrong boss! vnum : %u pls check it!", info.dwVnum);
                continue;
            }

            i.at("map_index").get_to(info.dwMapIDX);
            i.at("spawn_x").get_to(info.posX);
            i.at("spawn_y").get_to(info.posY);
            i.at("return_time").get_to(info.wReturnMin);
            info.dwMaxHP = pMob->m_table.dwMaxHP;

            for(const auto& [vnum, count] : i["gift_items"].items()) {
                const DWORD vnm = std::stoi(vnum);
                const DWORD cnt = count.get<DWORD>();
                info.gift_info.emplace_back(vnm, cnt);
            }

            boss_Map.emplace(info.dwVnum, std::make_unique<BossDamageInfo>(info));
        }
        ifs.close();
    }
    catch (const std::exception& e) {
        sys_err("ReadBossDamageError error : %s - file : %s", e.what(), file_name);
        return false;
    }
#else
        const std::unique_ptr<SQLMsg> pkMsg(DBManager::instance().DirectQuery("SELECT * FROM boss_damage_ranking%s", get_table_postfix()));

        if (pkMsg->Get()->uiNumRows == 0) {
            sys_err("boss_damage_ranking table is empty");
            return false;
        }
        boss_Map.clear();
        MYSQL_ROW row;
        while ((row = mysql_fetch_row(pkMsg->Get()->pSQLResult)) != nullptr)
        {
            DWORD col = 1;

            TBossInfo info = {};
            str_to_number(info.dwVnum, row[col++]);

            const auto* pMob = CMobManager::instance().Get(info.dwVnum);
            if (!pMob) {
                sys_err("Bossdamage_info.json have wrong boss! vnum : %u pls check it!", info.dwVnum);
                continue;
            }
            info.dwMaxHP = pMob->m_table.dwMaxHP;
            str_to_number(info.dwMapIDX, row[col++]);
            str_to_number(info.posX, row[col++]);
            str_to_number(info.posY, row[col++]);
            str_to_number(info.wReturnMin, row[col++]);

            for (uint8_t i(0); i < 5; ++i) {
                DWORD vnum, count = 0;
                str_to_number(vnum, row[col++]);
                str_to_number(count, row[col++]);
                info.gift_info.emplace_back(vnum, count);
            }


            auto data = std::unique_ptr<BossDamageInfo>(new BossDamageInfo(info));
            boss_Map.emplace(info.dwVnum, std::move(data));
        }
#endif
    CreateTimer();
    return true;
}

auto CBossDamageRanking::SendGUIData(LPCHARACTER ch) -> void {
    if (!ch || !ch->GetDesc()) { return; }

    for (const auto& elm : boss_Map) {
        const auto it = FindBossClass(elm.first);
        if (!it) { continue; }
        ch->ChatPacket(CHAT_TYPE_COMMAND, "BossRankingUI %u %u %u %u %u", elm.first, it->GetMapIDX(), it->GetPosX(), it->GetPosY(), it->GetReturnTime());
    }
}

auto CBossDamageRanking::IsRankingBoss(const DWORD dwVnum) const -> bool {
#if (__cplusplus >= 202002L)
        return boss_Map.contains(dwVnum); // -> c++20 is have contains func
#endif
    const auto& it = boss_Map.find(dwVnum);
    return it != boss_Map.cend() ? true : false;
}

#ifdef ENABLE_DAMAGE_RANKING_SAFE_ZONE
auto CBossDamageRanking::CheckSafeZone(LPCHARACTER ch) -> void {
    if (!ch) { return; }
    DWORD dwVnum = 0;
    for (const auto& it : boss_Map){
        if (it.second->GetMapIDX() == ch->GetMapIndex()) {
            dwVnum = it.first;
            break;
        }
    }
    const auto it = FindBossClass(dwVnum);
    if (!it) { return; }
    if(it->GetIsSafeZone()) {
        ch->ChatPacket(CHAT_TYPE_COMMAND, "BossDamageRankingSafeZone %d", 1);
    }

}
#endif

auto CBossDamageRanking::CheckPlayerID(const uint32_t pid) -> void {
    for (const auto& it : boss_Map) {
        it.second->ErasePlayer(pid);
    }
}

auto CBossDamageRanking::Destroy() -> void {
    CloseTimer();
    boss_Map.clear();
}
#endif
hataların sebebi zaten varlarda autoları voidle değiştirdiğimiz için kaynaklı aşağıdaki gibi değiştir. Daha sonra dosyayı makefileye eklediğinden emin ol ve derle.

C++:
Genişlet Daralt Kopyala
bool CBossDamageRanking::IsRankingBoss....
void CBossDamageRanking::CheckPlayerID....
void CBossDamageRanking::SendGUIData...
bool CBossDamageRanking::Initialize...
void BossDamageInfo::Destroy...
void CBossDamageRanking::Destroy...
void BossDamageInfo::SendRankings(bool isDead)....
 
Geri
Üst