Maplerde Pvp Engelleme

Bende yeni oyuna ekleyecektim. Bi bakıyım diyordum buna genel anlamda, senin paylaşman iyi oldu. Ellerine sağlık :)
Rica ederim deneyip sonucunu yazabilirsen sevinirim
 
Ben olsam const ve static bir container (vector uygundur) içerisinde tutup onunla kontrol ederdim.
 
Son düzenleme:
Ben olsam const ve static bir container (unordered_map uygundur) içerisinde tutup onunla kontrol ederdim.
Yapıp paylaşsan daha iyi olur hocam bence böyle şeyleri. Bahsettiğinle paylaştığım arasında fark yok neredeyse performans olarak. Tek fark kod okunurluğu olurdu.
 
Yapıp paylaşsan daha iyi olur hocam bence böyle şeyleri. Bahsettiğinle paylaştığım arasında fark yok neredeyse performans olarak. Tek fark kod okunurluğu olurdu.
C++:
Genişlet Daralt Kopyala
static const std::vector<int> PvpBlockedMaps = {1, 3, 21, 23, 41, 43};

int iMapIdx = ch->GetMapIndex();
if (ch->IsPC() && victim->IsPC())
{
    bool bIsBlockedMap = std::find(PvpBlockedMaps.begin(), PvpBlockedMaps.end(), iMapIdx) != PvpBlockedMaps.end();   
    if (bIsBlockedMap)
        return false;
}

Performans olarak ben de önemli bir fark olduğunu düşünmüyorum.
Fakat bloklanan haritalar arasına yenisi eklenmesi gerektiğinde tüm if bloklarını tek tek bulup araya eklemek uğraştırıcı olur.
 
C++:
Genişlet Daralt Kopyala
static const std::vector<int> PvpBlockedMaps = {1, 3, 21, 23, 41, 43};

int iMapIdx = ch->GetMapIndex();
if (ch->IsPC() && victim->IsPC())
{
    bool bIsBlockedMap = std::find(PvpBlockedMaps.begin(), PvpBlockedMaps.end(), iMapIdx) != PvpBlockedMaps.end(); 
    if (bIsBlockedMap)
        return false;
}

Performans olarak ben de önemli bir fark olduğunu düşünmüyorum.
Fakat bloklanan haritalar arasına yenisi eklenmesi gerektiğinde tüm if bloklarını tek tek bulup araya eklemek uğraştırıcı olur.
Performans olarak fark olacağı tek şey 50-100 tane map eklenecekse o zaman ki o da mümkün değil. Zaten benim paylaştığımda pvp açık olan mapler 1. ve 2. köyler geri kalan tüm maplerde pvp kapalı genel olarak insanların kullanacağı yerler.

Evet dediğiniz gibi yenisi ekleneceği zaman bir tek uğraştırır onun dışında farkı olmaz.
 
C++:
Genişlet Daralt Kopyala
static const std::vector<int> PvpBlockedMaps = {1, 3, 21, 23, 41, 43};

int iMapIdx = ch->GetMapIndex();
if (ch->IsPC() && victim->IsPC())
{
    bool bIsBlockedMap = std::find(PvpBlockedMaps.begin(), PvpBlockedMaps.end(), iMapIdx) != PvpBlockedMaps.end();  
    if (bIsBlockedMap)
        return false;
}

Performans olarak ben de önemli bir fark olduğunu düşünmüyorum.
Fakat bloklanan haritalar arasına yenisi eklenmesi gerektiğinde tüm if bloklarını tek tek bulup araya eklemek uğraştırıcı olur.

Konu performans ise bu şekilde daha iyi olur sadece var yok kontrolü yapıyoruz, zaman tabanlı baştan sona aratmaya gerek yok.

C++:
Genişlet Daralt Kopyala
static const std::unordered_set<int> PvpBlockedMaps = {1, 3, 21, 23, 41, 43};

int iMapIdx = ch->GetMapIndex();
if (ch->IsPC() && victim->IsPC())
{
    if (PvpBlockedMaps.find(iMapIdx) == PvpBlockedMaps.end())
        return false;
}
 
Konu performans ise bu şekilde daha iyi olur sadece var yok kontrolü yapıyoruz, zaman tabanlı baştan sona aratmaya gerek yok.

C++:
Genişlet Daralt Kopyala
static const std::unordered_set<int> PvpBlockedMaps = {1, 3, 21, 23, 41, 43};

int iMapIdx = ch->GetMapIndex();
if (ch->IsPC() && victim->IsPC())
{
    if (PvpBlockedMaps.find(iMapIdx) == PvpBlockedMaps.end())
        return false;
}
Var yok kontrolü hash set ile yapılıyor iyi hoşta hocam az öncede yazdığım gibi uzun bir map listesi olmayacaksa yine bir önemi yok :D ama tabi var yok kontrolü yapılacaksa hash set ile yapılması daha doğrudur.
 
It would be better if it was the other way around. This means that the PVP system would be enabled on all maps, except for maps that are currently being added, where PVP is disabled. However, this code would be difficult to handle because I would need to add 65 maps with combat and only 5 maps with no combat. Will the code be able to handle adding 65 maps?

I tried to reverse the code to prevent fighting on the maps you specify and not as in the original topic. Can someone take a look and tell me if it's good or not?


C++:
Genişlet Daralt Kopyala
bool battle_is_attackable(LPCHARACTER ch, LPCHARACTER victim)
{
    if (victim->IsDead())
        return false;

    if (victim->IsObserverMode())
        return false;

    if (victim->GetShopOwner())
        return false;

    {
        SECTREE* sectree = NULL;

        sectree = ch->GetSectree();
        if (sectree && sectree->IsAttr(ch->GetX(), ch->GetY(), ATTR_BANPK))
            return false;

        sectree = victim->GetSectree();
        if (sectree && sectree->IsAttr(victim->GetX(), victim->GetY(), ATTR_BANPK))
            return false;
    }

    // >>>>>>>>>>>>>>>> PVP ENGEL () <<<<<<<<<<<<<<
    if (ch->IsPC() && victim->IsPC())
    {
        int m = ch->GetMapIndex();
        if (m == 1 || m == 3 || m == 21 || m == 23 || m == 41 || m == 43)
            return false;
    }
    // >>>>>>>>>>>>>>>> PVP ENGEL () <<<<<<<<<<<<<<

#ifdef NEW_ICEDAMAGE_SYSTEM
    if (!battle_is_icedamage(ch, victim))
        return false;
#endif

    if (ch->IsStun() || ch->IsDead())
        return false;

    if (ch->IsPC() && victim->IsPC())
    {
        CGuild* g1 = ch->GetGuild();
        CGuild* g2 = victim->GetGuild();

        if (g1 && g2)
        {
            if (g1->UnderWar(g2->GetID()))
                return true;
        }
    }

    if (IS_CASTLE_MAP(ch->GetMapIndex()) && false == castle_can_attack(ch, victim))
        return false;

    if (CArenaManager::instance().CanAttack(ch, victim) == true)
        return true;

    return CPVPManager::instance().CanAttack(ch, victim);
}

@M29
The logic is correct, because our intention is the opposite of what you described.
We are not trying to enable PVP on all maps and disable it only on a few — the goal is PVP should be allowed only on specific maps, and disabled on all other maps. This is intentional, especially because this system is used on 55–120 gameplay structures or farm-oriented servers, not classic 1–99 leveling servers. In such servers, most maps are used for pure farming and players should not be disturbed there. PVP is only available in a few selected areas. That is exactly why the logic is written in whitelist form — only allowed maps have PVP, the rest are blocked. Performance is also not an issue. Even if the allowed/blocked map list contains 50+ entries, lookups are extremely cheap and won’t affect the server.
 
En son bir moderatör tarafından düzenlenmiş:
Yada bu şöyle yapılabilir, tek tek belli koşullar eklenir. Onu farklı bir cpp'ye çekersin sonrasında zaten sadece o farklı cpp'den yapacağın için tek tek uğraşmaya gerek kalmaz.
 
Geri
Üst