hxp
2025-05-28 a6fe9b060edf315f6abde7443e48db5dea439f47
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
85
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package DB.StructData.DBEventTrig
#
# @todo:ʼþ´¥·¢Öµ¹ÜÀíÆ÷
# @author hxp
# @date 2025-05-15
# @version 1.0
#
# ÏêϸÃèÊö: Ê¼þ´¥·¢Öµ¹ÜÀíÆ÷
#
#-------------------------------------------------------------------------------
#"""Version = 2025-05-15 10:35"""
#-------------------------------------------------------------------------------
 
import DBStruct
import GameWorld
import CommFunc
    
class EventTrigMgr():
    
    def __init__(self):
        self.__eventDict = {} # Ê¼þ×Öµä {key:value, ...}
        return
    
    def GetDict(self): return self.__eventDict
    
    def GetValue(self, key, defaultValue=0):
        if key in self.__eventDict:
            return self.__eventDict[key]
        return defaultValue
    
    def SetValue(self, key, value):
        self.__eventDict[key] = value
        return value
    
    def DelAllKey(self, excludeList=[]):
        ## É¾³ýËùÓмǼ
        # @param excludeList: ²»°üº¬µÄkeyÁбí
        self.__eventDict = {k:self.GetValue(k) for k in excludeList}           
        return
    
    def DelKey(self, key):
        return self.__eventDict.pop(key, None)
    
    def SetValueIncrement(self, key):
        ## É趨·þÎñÆ÷ʼþ(¸Ãʼþ¼Ç¼ΪÊýÖµ´Ó1Ò»Ö±×ÔÔöÀÛ¼Ó)
        # @return: ×ÔÔöºóµÄÖµ
        value = self.GetValue(key, 0)
        return self.SetValue(key, value + 1)
 
    # ±£´æÊý¾Ý ´æÊý¾Ý¿âºÍrealtimebackup
    def GetSaveData(self):
        savaData = ""
        cntData = ""
        cnt = 0
        
        dbData = DBStruct.tagDBEventTrig()
        for key, value in self.__eventDict.items():
            if not value:
                continue
            dbData.clear()
            dbData.EventID = key
            dbData.EventLen = len(dbData.EventID)
            dbData.EventValue = value
            cnt += 1
            savaData += dbData.getBuffer()
            
        GameWorld.Log("Save DBEventTrig count :%s len=%s" % (cnt, len(savaData)))
        return CommFunc.WriteDWORD(cntData, cnt) + savaData
    
    # ´ÓÊý¾Ý¿âÔØÈëÊý¾Ý
    def LoadPyGameData(self, datas, pos, dataslen):
        
        cnt, pos = CommFunc.ReadDWORD(datas, pos)
        GameWorld.Log("Load DBEventTrig count :%s" % cnt)
        
        dbData = DBStruct.tagDBEventTrig()
        for _ in xrange(cnt):
            pos += dbData.readData(datas, pos, dataslen)
            self.__eventDict[dbData.EventID] = dbData.EventValue
            
        return pos