chenluhua1980
2025-12-11 77115b7f45e9fcc40c8831b857a77ee69751fcef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "stdafx.h"
#include "Model.h"
 
 
CModel::CModel()
{
    m_pEuqipment = nullptr;
}
 
 
CModel::~CModel()
{
}
 
BEQ::IEquipment* CModel::createEquipment(const char* pszName)
{
    if (m_pEuqipment != nullptr) {
        return nullptr;
    }
 
    m_strEquipmentName = pszName;
    BEQ_CreateEquipment(m_pEuqipment, pszName);
    if (m_pEuqipment != nullptr) {
        BEQ::EquipmentListener listener;
        listener.onConnected = [&](void* pEquipment, const char* pszAddr, int port) -> int {
            TRACE("%s:%dÁ¬½Ó½øÈë.", pszAddr, port);
            return 0;
        };
        listener.onDisconnected = [&](void* pEquipment, const char* pszAddr, int port) -> int {
            TRACE("%s:%dÁ¬½Ó¶Ï¿ª.\n", pszAddr, port);
            return 0;
        };
        listener.onRunRecipe = [&](void* pEquipment, void* pUnit, int id) -> int {
            BEQ::IUnit* p = (BEQ::IUnit*)pUnit;
            char szUnitName[256];
            p->getName(szUnitName, 256);
            m_mapRecipe[szUnitName] = id;
            TRACE("%sÕýÔÚÇл»ÖÁÅä·½%d.\n", szUnitName, id);
            // ×öÇл»Åä·½µÄ¶¯×÷
            Sleep(2000);
 
            return 0;
        };
        listener.onGetRecipeList = [&](void* pEquipment, void* pUnit) -> int {
            BEQ::IUnit* p = (BEQ::IUnit*)pUnit;
            char szUnitName[256];
            p->getName(szUnitName, 256);
            TRACE("ÖпØÇëÇó»ñÈ¡µ¥Ôª[%s]Åä·½Áбí.\n", szUnitName);
            // Ôڴ˸üÐÂÅä·½
            // p->addRecipe();
            Sleep(2000);
 
            // ×èÈû·½Ê½·µ»Ø0£¬
            // ¶àÏ̷߳½Ê½ÏÈ·µ»Ø1£¬ÔÚÏß³ÌÖлñÈ¡ÍêÅä·½ºó£¬µ÷ÓÃ
            // IEquipment::repRecipeListCompleteÒì²½·µ»ØÊý¾Ý
            return 0;
        };
        listener.onLoadReady = [&](void* pEquipment, void* pUnit, const char* pszMaterielId, const char* pszRecipeId) -> int {
            BEQ::IUnit* p = (BEQ::IUnit*)pUnit;
            char szUnitName[256];
            p->getName(szUnitName, 256);
            Sleep(2000);
 
            return 0;
        };
        m_pEuqipment->setEquipmentListener(listener);
    }
 
    return m_pEuqipment;
}
 
BEQ::IEquipment* CModel::getEquipment()
{
    return m_pEuqipment;
}
 
int CModel::getRecipeName(const char* pszUnitName)
{
    static std::string strEmpty = "";
    auto iter = m_mapRecipe.find(pszUnitName);
    if (iter == m_mapRecipe.end()) return 0;
 
    return iter->second;
}