Siga-nos em...
Follow us on Twitter Follow us on Facebook Watch us on YouTube
Registro

Alpha Servers
Resultados 1 a 3 de 3
  1. #1

    Avatar de konvict
    Data de Ingresso
    Sep 2009
    Localização
    SP, interiorzão
    Posts
    338
    Agradecido
    283
    Agradeceu
    91
    Peso da Avaliação
    18

    Padrão Sistema Mata-Mata Automático by Konvict

    Eis o meu simples sistema de mata-mata automático. Estava fazendo no meu projeto Exchange, porém não vou mais colocar ele (pretendo fazer um melhor)... Não está totalmente terminado, e pode não estar "usável"... Testei apenas com 3 contas,sendo assim, não darei suporte quanto a implantação do código.

    matamata.cpp
    #include "StdAfx.h"

    cMataMata cMata;

    void cMataMata::ResetMEvent()
    {
    InitTime = 0;
    InitSeconds = 0;
    TimeStage = 0;
    SecondsStage = 0;
    pCount = 0;
    mtRunning = false;
    Activated = false;
    NextStage = false;
    Finalize = false;
    CurStage = 0;
    TotalStages = 0;

    for (int m = 0; m < MAXMTSTAGE; m++)
    {
    sMata[m].InCurse = false;
    sMata[m].playerCount = 0;
    sMata[m].InRound[0] = -1;
    sMata[m].InRound[1] = -1;

    for (int x = 4800; x < 5800; x++)
    {
    psPlayer[x].inMataEvent = 0;
    psPlayer[x].WinnerLoser = 0;
    psPlayer[x].MoveTime = 0;
    psPlayer[x].pFighting = false;
    psPlayer[x].pWaiting = false;
    psPlayer[x].pScore = 0;
    psPlayer[x].Index = -1;
    psPlayer[x].pStage = 0;
    sMata[m].sPlayer[x].Index = 0;
    }
    }
    }

    void cMataMata::Load()
    {
    ResetMEvent();
    }

    void cMataMata::GmCmdInit(LPOBJ lpObj, char* msg)
    {
    int aIndex = lpObj->m_Index;
    int TempTime = atoi(msg);


    if (TempTime < 1)
    {
    MsgOutput(aIndex, "Erro na configuração do evento!");
    return;
    }

    InitTime = TempTime * 60;

    if (pObj[aIndex].mAutority < 1)
    {
    MsgOutput(aIndex, "Você não tem autoridade para isso.");
    return;
    }

    else if (Activated == true)
    {
    MsgOutput(aIndex, "Mata-Mata já está ativado.");
    return;
    }
    else if(mtRunning == true)
    {
    MsgOutput(aIndex, "Mata-Mata já está rolando.");
    return;
    }
    else if (psPlayer[aIndex].inMataEvent != 0)
    {
    MsgOutput(aIndex, "Você já éstá ocupado");
    return;
    }
    else
    {
    psPlayer[aIndex].inMataEvent = 2;
    Activated = true;
    CurStage = 1;
    AllServerAnnounce("%s iniciou o Mata-Mata", lpObj->Name);
    MsgOutputAll("digite [/ir] para participar");
    }
    }

    void cMataMata::PlayerCmdIWant(LPOBJ lpObj)
    {
    int aIndex = lpObj->m_Index;

    if (mtRunning == true)
    {
    MsgOutput(aIndex, "Mata-Mata já está rolando.");
    return;
    }
    else if (Activated == false)
    {
    MsgOutput(aIndex, "Mata-Mata não está ativado.");
    return;
    }
    else if (psPlayer[aIndex].inMataEvent!= 0)
    {
    MsgOutput(aIndex, "Você já está %s", (sMata->sPlayer[aIndex].inMataEvent == 1) ? "no evento" : "ocupado");
    return;
    }
    else if (psPlayer[aIndex].pWaiting == true)
    {
    MsgOutput(aIndex, "Você já está aguardando.");
    return;
    }
    else
    {

    psPlayer[aIndex].pWaiting = true;
    psPlayer[aIndex].pStage = CurStage;
    psPlayer[aIndex].inMataEvent = 1;
    int id = GetPlayerCount();
    sMata[CurStage].aIndex[id] = aIndex;

    MsgOutput(aIndex, "Você entrou no Mata-Mata %d", id);
    MsgOutput(aIndex, "Fique atento que vai começar!");
    gObjTeleport(aIndex, 6, 72, 160);
    sMata[CurStage].playerCount++;
    }
    }

    void cMataMata::MataMataStart()
    {

    if (Activated == true && InitTime > 0)
    InitSeconds++;

    int TempRest;
    TempRest = InitSeconds == (InitTime - 59) ? 1 : InitSeconds == (InitTime - 119) ? 2 : InitSeconds == (InitTime - 179) ? 3 : 4;
    if (InitSeconds == (InitTime - 59) || InitSeconds == (InitTime - 119) || InitSeconds == (InitTime - 179) || InitSeconds == (InitTime - 239))
    AllServerAnnounce("Mata-Mata começará em %d minuto(s)", TempRest);

    if (InitSeconds == InitTime && mtRunning == false && Activated == true)
    {
    Activated = false;
    InitSeconds = 0;
    InitTime = 0;
    TimeStage = 0;
    SecondsStage = 0;
    mtRunning = true;

    sMata[CurStage].InCurse = true;
    TotalStages = TotalStage();
    AllServerAnnounce("MataMata Começou! %d", GetPlayerCount());
    }

    if (mtRunning == true)
    {

    if (NextStage == true)
    {
    if (TimeStage > 0)
    SecondsStage++;

    if (SecondsStage == TimeStage)
    {
    if (CurStage < TotalStages)
    {
    if (sMata[CurStage].InCurse == false)
    {
    CurStage++;
    sMata[CurStage].InCurse = true;
    TotalStages = TotalStage();

    AllServerAnnounce("%s", (TotalStages - CurStage) == 0 ? "[Mata-mata]Última Rodada" : (TotalStages - CurStage) == 1 ? "[Mata-mata]Penultima Rodada" : "[Mata-mata]Próxima Rodada");
    }
    }
    else
    {
    if (Finalize == true)
    {
    AllServerAnnounce("Mata-mata acabou!");
    ResetMEvent();
    }
    }

    NextStage = false;
    TimeStage = 0;
    SecondsStage = 0;
    }
    }
    }
    }

    void cMataMata::SetPlayerToFight(LPOBJ lpObj)
    {
    int aIndex = lpObj->m_Index;

    if (mtRunning == true && Activated == false && sMata[CurStage].InCurse == true)
    {
    if (lpObj->Connected == 3)
    {
    int TempContage = CountStagePlayer(CurStage);
    int pRander;

    if (TempContage > 1)
    {
    if (sMata[CurStage].InRound[0] == -1)
    {
    srand((unsigned)time(NULL));
    pRander = 1 + (rand() % CountStagePlayer(CurStage));

    if (psPlayer[aIndex].pWaiting == true && psPlayer[aIndex].pStage == CurStage)
    {
    if (sMata[CurStage].aIndex[pRander] == aIndex && psPlayer[aIndex].pFighting == false)
    {
    psPlayer[aIndex].pWaiting = false;
    psPlayer[aIndex].pFighting = true;
    gObjTeleport(aIndex, 6, 121, 115);
    lpObj->PkLevel = 6;
    GCPkLevelSend(aIndex, 6);
    sMata[CurStage].InRound[0] = aIndex;

    }
    }
    }
    if (sMata[CurStage].InRound[1] == -1)
    {
    srand((unsigned)time(NULL));
    pRander = 1 + (rand() % CountStagePlayer(CurStage));
    if (psPlayer[aIndex].pWaiting == true && psPlayer[aIndex].pStage == CurStage)
    {
    if (sMata[CurStage].aIndex[pRander] == aIndex && psPlayer[aIndex].pFighting == false)
    {
    psPlayer[aIndex].pWaiting = false;
    psPlayer[aIndex].pFighting = true;
    gObjTeleport(aIndex, 6, 121, 116);
    lpObj->PkLevel = 6;
    GCPkLevelSend(aIndex, 6);
    sMata[CurStage].InRound[1] = aIndex;
    MsgOutputAll("%s X %s", gObj[sMata[CurStage].InRound[0]].Name, gObj[sMata[CurStage].InRound[1]].Name);
    }
    }
    }
    }
    else if (TempContage == 1) // quando sobrar 1, joga ele pra próxima fase
    {
    srand((unsigned)time(NULL));
    int TempCont = 1 + (rand() % CountStagePlayer(CurStage));

    if (psPlayer[aIndex].pWaiting == true && psPlayer[aIndex].pStage == CurStage && psPlayer[aIndex].pFighting == false)
    {

    psPlayer[aIndex].pStage++;
    sMata[psPlayer[aIndex].pStage].aIndex[CountStagePlayer(psPlayer[aIndex].pStage)] = aIndex;
    MsgOutputAll("%s foi para próxima fase por W.O", lpObj->Name);
    }
    }
    else
    {

    }
    }
    }
    }

    void cMataMata::SetPlayerEstage(LPOBJ lpObj, LPOBJ lpTarget)
    {
    int aIndex = lpObj->m_Index;
    int tIndex = lpTarget->m_Index;
    int Contp,TempCont;

    if (mtRunning == true)
    {
    if (sMata[CurStage].InCurse == true)
    {
    if (psPlayer[aIndex].inMataEvent > 0 && psPlayer[tIndex].inMataEvent > 0 && psPlayer[aIndex].pFighting && psPlayer[tIndex].pFighting)
    {
    sMata[CurStage].sPlayer[aIndex].pScore++;
    AllServerAnnounce("%s %d X %d %s", lpObj->Name, sMata[CurStage].sPlayer[aIndex].pScore, sMata[CurStage].sPlayer[tIndex].pScore, lpTarget->Name);

    if (sMata[CurStage].sPlayer[aIndex].pScore == 3)
    {

    psPlayer[aIndex].pStage++;
    TempCont = CountStagePlayer(psPlayer[aIndex].pStage);
    psPlayer[aIndex].WinnerLoser = 1;
    psPlayer[tIndex].WinnerLoser = 2;
    psPlayer[aIndex].pFighting = false;
    psPlayer[aIndex].pWaiting = false;
    sMata[CurStage].sPlayer[aIndex].pScore = 0;
    sMata[psPlayer[aIndex].pStage].aIndex[TempCont] = aIndex;


    sMata[CurStage].sPlayer[tIndex].pScore = 0;
    psPlayer[tIndex].inMataEvent = 0;
    psPlayer[tIndex].pFighting = false;
    psPlayer[tIndex].pWaiting = false;
    psPlayer[tIndex].pStage = 0;

    AllServerAnnounce("%s Venceu %s no Mata-mata", lpObj->Name,lpTarget->Name);

    if (CountStagePlayer(CurStage) == 0)
    {
    if (CurStage == TotalStages)
    {
    AllServerAnnounce("%s Ganhou o Mata-mata", lpObj->Name);
    TimeStage = 12;
    Finalize = true;
    NextStage = true;
    }
    else
    {
    TimeStage = 12;
    if (GetPlayerCount() > 1)
    {
    NextStage = true;
    sMata[CurStage].InCurse = false;
    }
    sMata[CurStage].InRound[0] = -1;
    sMata[CurStage].InRound[1] = -1;
    }
    }
    }
    }
    }
    }
    }

    void cMataMata::MoveOfFightArea(LPOBJ lpObj)
    {
    int aIndex = lpObj->m_Index;
    if (this->Activated == true || this->mtRunning)
    {
    if (psPlayer[aIndex].WinnerLoser != 0)
    {
    psPlayer[aIndex].MoveTime++;
    if (psPlayer[aIndex].MoveTime >= 6)
    {
    if (psPlayer[aIndex].WinnerLoser == 1)
    {

    gObjTeleport(aIndex, 6, 72, 160);
    psPlayer[aIndex].WinnerLoser = 0;
    psPlayer[aIndex].MoveTime = 0;
    psPlayer[aIndex].pWaiting = true;
    }
    else
    {
    lpObj->PkLevel = 3;
    GCPkLevelSend(aIndex, 3);
    gObjTeleport(aIndex, 6, 69, 93);
    psPlayer[aIndex].WinnerLoser = 0;
    psPlayer[aIndex].MoveTime = 0;
    }

    }
    }
    }
    }

    int cMataMata::CountStagePlayer(BYTE Stage)
    {
    int cont = 0;
    if (this->Activated == true || this->mtRunning)
    {
    for (int i = 4800; i < 5800; i++)
    {
    if (gObj[i].Connected == 3)
    {
    if (psPlayer[i].inMataEvent == 1 && psPlayer[i].pStage == Stage)
    {
    cont++;
    }
    }
    }
    }
    return cont;
    }

    int cMataMata::GetPlayerCount()
    {
    int cont = 0;
    if (this->Activated == true || this->mtRunning)
    {
    for (int i = 4800; i < 5800; i++)
    {
    if (gObj[i].Connected == 3)
    {
    if (psPlayer[i].inMataEvent == 1)
    {
    cont++;
    }
    }
    }
    }
    return cont;
    }

    int cMataMata::GetPlayerWaiting()
    {
    int cont = 0;
    if (this->Activated == true || this->mtRunning)
    {
    for (int i = 4800; i < 5800; i++)
    {
    if (gObj[i].Connected == 3)
    {
    if (psPlayer[i].inMataEvent == 1 && psPlayer[i].pWaiting == true)
    {
    cont++;
    }
    }
    }
    }
    return cont;
    }

    BYTE cMataMata::TotalStage()
    {
    int stage = 0;
    int totalplayer = GetPlayerWaiting();


    if (totalplayer >= 2)
    {
    if (totalplayer % 2 != 0)
    stage = (totalplayer + 1) / 2;
    else
    stage = totalplayer / 2;
    }
    else
    {
    stage = 1;
    }

    return stage;
    }


    matamata.h
    #pragma once

    #define MAXMTSTAGE 20
    #define MAXMTPLAYER 20

    struct sMTPlayer
    {
    BYTE inMataEvent; // 0 = no, 1 = player, 2 = gm
    BYTE WinnerLoser; // 0 neutro, 1 = win, 2 = lose
    bool pWaiting; // user
    bool pFighting; // user
    short pScore; // user
    BYTE pStage; // user
    int Index;

    BYTE MoveTime;
    };

    struct sMataMata
    {
    sMTPlayer sPlayer[5800];
    bool InCurse;
    int aIndex[MAXMTPLAYER];
    int InRound[2];
    short playerCount;
    };



    class cMataMata
    {
    public:
    void Load();
    void GmCmdInit(LPOBJ lpObj, char* msg);
    void PlayerCmdIWant(LPOBJ lpObj);
    void MataMataStart();
    void SetPlayerEstage(LPOBJ lpObj, LPOBJ lpTarget);
    void SetPlayerToFight(LPOBJ lpObj);
    void MoveOfFightArea(LPOBJ lpObj);

    private:

    void ResetMEvent();

    int GetPlayerCount();
    int CountStagePlayer(BYTE Stage);
    BYTE TotalStage();
    int GetPlayerWaiting();

    short InitTime;
    short InitSeconds;

    short TimeStage, SecondsStage;

    int pCount;
    BYTE CurStage;
    BYTE TotalStages;
    bool mtRunning;
    bool Activated;
    bool NextStage;
    bool Finalize;
    sMataMata sMata[MAXMTSTAGE];
    sMTPlayer psPlayer[5800];

    };

    extern cMataMata cMata;


    Crédito: Konvict
    Última edição por konvict; 02-07-2015 às 06:26 PM.
    Sê Sóbrio...

  2. Os Seguintes 8 Usuários Agradeceram você konvict Por este Post Útil:


  3. #2


    Avatar de Agathos
    Data de Ingresso
    Oct 2014
    Localização
    BRA
    Idade
    40
    Posts
    341
    Agradecido
    150
    Agradeceu
    91
    Peso da Avaliação
    13

    Padrão

    Citação Postado originalmente por konvict Ver Post
    ...porém não vou mais colocar ele (pretendo fazer um melhor)... Não está totalmente terminado, e pode não estar "usável"...

    Não é a primeira vez que me deparo em fóruns de MuOnline com falas desse tipo e realmente não consigo entender o porque de posts assim.
    Não é uma crítica ao seu post em particular @konvict. Provavelmente deve haver alguma razão que eu desconheça.
    Você pode descobrir mais a respeito de uma pessoa numa hora de jogo do que num ano de conversação.
    ( Platão )

  4. #3

    Avatar de konvict
    Data de Ingresso
    Sep 2009
    Localização
    SP, interiorzão
    Posts
    338
    Agradecido
    283
    Agradeceu
    91
    Peso da Avaliação
    18

    Padrão

    @Agathos
    Eu te explico:
    Liberei o meu código que fiz para meu projeto, porém não vou mais colocar esse sistema, e para não dizer que fiz o código em vão, decidi compartilhar com o fórum e depois removê-lo da minha source.

    No caso de "fazer um melhor", não quer dizer que o código seja ruim, pode ser que eu não gostei de como ficou o sistema em si, e queira desenvolver um diferente (considerado melhor por mim).

    Aqui... "Não está totalmente terminado, e pode não estar usável"
    O problema é que todo mundo quer o código prontinho, pra dar um ctrl+c e ctrl+v e já sair usando...
    Quando na verdade a intenção de quem compartilha o código (no meu caso), é mostrar um meio de se fazer tal sistema, pra alguém que esteja aprendendo mexer ou que esteja quebrando cabeça com isso, e não pra "copiões".
    Sê Sóbrio...

  5. Os Seguintes 10 Usuários Agradeceram você konvict Por este Post Útil:


 

 

Informações de Tópico

Usuários Navegando neste Tópico

Há 1 usuários navegando neste tópico. (0 registrados e 1 visitantes)

Tópicos Similares

  1. |Download| Entrada para mata/mata Evento
    Por crazy_digital no fórum Entradas
    Respostas: 2
    Último Post: 26-07-2013, 06:59 PM
  2. Respostas: 0
    Último Post: 27-06-2010, 08:22 PM
  3. OITAVAS DE FINAIS (Mata-Mata) - Estados Unidos 1 x 2 Gana (Classificado: Gana)
    Por _LenaD_ no fórum Jogos Finalizados - Resultados
    Respostas: 0
    Último Post: 27-06-2010, 08:12 PM
  4. Respostas: 0
    Último Post: 27-06-2010, 08:03 PM

Marcadores

Permissões de Postagem

  • Você não pode iniciar novos tópicos
  • Você não pode enviar respostas
  • Você não pode enviar anexos
  • Você não pode editar suas mensagens
  •