clientbot/tools/TVPNodeBase.py

263 lines
13 KiB
Python
Raw Permalink Normal View History

2020-07-27 20:17:48 +00:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# module BitStream
#
# Copyright (C) 2019 AleaJactaEst
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
#from ctypes import *
#import sys
#import inspect
#import copy
#import struct
#from tools import TPropIndex
from tools import Enum
#from tools import BitStream
from tools import CActionFactory
LOGGER='TVPNodeBase'
class TVPNodeBase():
def __init__(self, name=""):
# khanat-opennel-code/code/ryzom/client/src/network_connection.cpp:414
self.VPParent = None # TVPNodeBase
self.VPA = None # TVPNodeBase
self.VPB = None # TVPNodeBase
self.PropIndex = Enum.TPropIndex.NB_VISUAL_PROPERTIES
self.BranchHasPayload = False
self.Name = name
self.NameProperty = ""
def setNodePropIndex(self, property , name_property = ""):
self.PropIndex = property
self.NameProperty = name_property
def makeChildren(self):
self.VPA = TVPNodeBase(self.Name + '.VPA')
self.VPA.VPParent = self
self.VPB = TVPNodeBase(self.Name + '.VPB')
self.VPB.VPParent = self
def makeDescendants(self, nbLevels ):
self.makeChildren()
if nbLevels > 1:
self.VPA.makeDescendants( nbLevels-1 );
self.VPB.makeDescendants( nbLevels-1 );
def build_tree(self):
# khanat-opennel-code/code/ryzom/common/src/game_share/entity_types.h:458 uint buildTree()
self.makeChildren()
self.VPA.setNodePropIndex(Enum.TPropIndex.PROPERTY_POSITION, 'PROPERTY_POSITION')
self.VPB.makeChildren()
self.VPB.VPA.setNodePropIndex(Enum.TPropIndex.PROPERTY_ORIENTATION, 'PROPERTY_ORIENTATION')
self.VPB.VPB.makeDescendants( 3 ) # 8 leaves + those created by additional makeChildren()
self.VPB.VPB.VPA.VPA.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_SHEET, 'PROPERTY_SHEET');
self.VPB.VPB.VPA.VPA.VPB.makeChildren();
self.VPB.VPB.VPA.VPA.VPB.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_BEHAVIOUR, 'PROPERTY_BEHAVIOUR');
self.VPB.VPB.VPA.VPA.VPB.VPB.setNodePropIndex( Enum.TPropIndex.PROPERTY_OWNER_PEOPLE, 'PROPERTY_OWNER_PEOPLE');
self.VPB.VPB.VPA.VPB.VPA.makeChildren();
self.VPB.VPB.VPA.VPB.VPA.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_NAME_STRING_ID, 'PROPERTY_NAME_STRING_ID');
self.VPB.VPB.VPA.VPB.VPA.VPB.setNodePropIndex( Enum.TPropIndex.PROPERTY_CONTEXTUAL, 'PROPERTY_CONTEXTUAL');
self.VPB.VPB.VPA.VPB.VPB.makeChildren();
self.VPB.VPB.VPA.VPB.VPB.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_TARGET_LIST, 'PROPERTY_TARGET_LIST');
self.VPB.VPB.VPA.VPB.VPB.VPB.setNodePropIndex( Enum.TPropIndex.PROPERTY_TARGET_ID, 'PROPERTY_TARGET_ID');
self.VPB.VPB.VPB.VPA.VPA.makeChildren();
self.VPB.VPB.VPB.VPA.VPA.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_MODE, 'PROPERTY_MODE');
self.VPB.VPB.VPB.VPA.VPA.VPB.setNodePropIndex( Enum.TPropIndex.PROPERTY_VPA, 'PROPERTY_VPA');
self.VPB.VPB.VPB.VPA.VPB.makeChildren();
self.VPB.VPB.VPB.VPA.VPB.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_BARS, 'PROPERTY_BARS');
self.VPB.VPB.VPB.VPA.VPB.VPB.setNodePropIndex( Enum.TPropIndex.PROPERTY_VISUAL_FX, 'PROPERTY_VISUAL_FX');
self.VPB.VPB.VPB.VPB.VPA.makeChildren();
self.VPB.VPB.VPB.VPB.VPA.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_VPB, 'PROPERTY_VPB');
self.VPB.VPB.VPB.VPB.VPA.VPB.makeChildren();
self.VPB.VPB.VPB.VPB.VPA.VPB.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_VPC, 'PROPERTY_VPC');
self.VPB.VPB.VPB.VPB.VPA.VPB.VPB.makeChildren();
self.VPB.VPB.VPB.VPB.VPA.VPB.VPB.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_EVENT_FACTION_ID, 'PROPERTY_EVENT_FACTION_ID');
self.VPB.VPB.VPB.VPB.VPA.VPB.VPB.VPB.makeChildren();
self.VPB.VPB.VPB.VPB.VPA.VPB.VPB.VPB.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_PVP_MODE, 'PROPERTY_PVP_MODE');
self.VPB.VPB.VPB.VPB.VPA.VPB.VPB.VPB.VPB.setNodePropIndex( Enum.TPropIndex.PROPERTY_PVP_CLAN, 'PROPERTY_PVP_CLAN');
self.VPB.VPB.VPB.VPB.VPB.makeChildren();
self.VPB.VPB.VPB.VPB.VPB.VPA.makeChildren();
self.VPB.VPB.VPB.VPB.VPB.VPA.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_ENTITY_MOUNTED_ID, 'PROPERTY_ENTITY_MOUNTED_ID');
self.VPB.VPB.VPB.VPB.VPB.VPA.VPB.setNodePropIndex( Enum.TPropIndex.PROPERTY_RIDER_ENTITY_ID, 'PROPERTY_RIDER_ENTITY_ID');
self.VPB.VPB.VPB.VPB.VPB.VPB.makeChildren();
self.VPB.VPB.VPB.VPB.VPB.VPB.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_OUTPOST_INFOS, 'PROPERTY_OUTPOST_INFOS');
self.VPB.VPB.VPB.VPB.VPB.VPB.VPB.makeChildren();
self.VPB.VPB.VPB.VPB.VPB.VPB.VPB.VPA.setNodePropIndex( Enum.TPropIndex.PROPERTY_GUILD_SYMBOL, 'PROPERTY_GUILD_SYMBOL');
self.VPB.VPB.VPB.VPB.VPB.VPB.VPB.VPB.setNodePropIndex( Enum.TPropIndex.PROPERTY_GUILD_NAME_ID, 'PROPERTY_GUILD_NAME_ID');
# TVPNodeBase *getPOSITIONnode() { return VPA; }
# TVPNodeBase *getORIENTATIONnode() { return VPB->VPA; }
#
# // From the discrete root (mainroot->VPB->VPB)
# TVPNodeBase *getSHEETnode() { return VPA->VPA->VPA; }
# TVPNodeBase *getBEHAVIOURnode() { return VPA->VPA->VPB->VPA; }
# TVPNodeBase *getOWNER_PEOPLEnode() { return VPA->VPA->VPB->VPB; }
# TVPNodeBase *getNAME_STRING_IDnode() { return VPA->VPB->VPA->VPA; }
# TVPNodeBase *getCONTEXTUALnode() { return VPA->VPB->VPA->VPB; }
# TVPNodeBase *getTARGET_LISTnode() { return VPA->VPB->VPB->VPA; }
# TVPNodeBase *getTARGET_IDnode() { return VPA->VPB->VPB->VPB; }
# TVPNodeBase *getMODEnode() { return VPB->VPA->VPA->VPA; }
# TVPNodeBase *getVPAnode() { return VPB->VPA->VPA->VPB; }
# TVPNodeBase *getBARSnode() { return VPB->VPA->VPB->VPA; }
# TVPNodeBase *getVISUAL_FXnode() { return VPB->VPA->VPB->VPB; }
# TVPNodeBase *getVPBnode() { return VPB->VPB->VPA->VPA; }
# TVPNodeBase *getVPCnode() { return VPB->VPB->VPA->VPB->VPA; }
# TVPNodeBase *getEVENT_FACTION_IDnode() { return VPB->VPB->VPA->VPB->VPB->VPA; }
# TVPNodeBase *getPVP_MODEnode() { return VPB->VPB->VPA->VPB->VPB->VPB->VPA; }
# TVPNodeBase *getPVP_CLANnode() { return VPB->VPB->VPA->VPB->VPB->VPB->VPB; }
# TVPNodeBase *getENTITY_MOUNTED_IDnode() { return VPB->VPB->VPB->VPA->VPA; }
# TVPNodeBase *getRIDER_ENTITY_IDnode() { return VPB->VPB->VPB->VPA->VPB; }
# TVPNodeBase *getOUTPOST_INFOSnode() { return VPB->VPB->VPB->VPB->VPA; }
# TVPNodeBase *getGUILD_SYMBOLnode() { return VPB->VPB->VPB->VPB->VPB->VPA; }
# TVPNodeBase *getGUILD_NAME_IDnode() { return VPB->VPB->VPB->VPB->VPB->VPB; }
#uint buildTree()
# {
# makeChildren();
# setNodePropIndex( POSITION );
# VPB->makeChildren();
# setNodePropIndex( ORIENTATION );
#
# TVPNodeBase *discreetRoot = VPB->VPB;
# discreetRoot->makeDescendants( 3 ); // 8 leaves + those created by additional makeChildren()
# discreetRoot->setNodePropIndex( SHEET );
# discreetRoot->VPA->VPA->VPB->makeChildren();
# discreetRoot->setNodePropIndex( BEHAVIOUR );
# discreetRoot->setNodePropIndex( OWNER_PEOPLE );
# discreetRoot->VPA->VPB->VPA->makeChildren();
# discreetRoot->setNodePropIndex( NAME_STRING_ID );
# discreetRoot->setNodePropIndex( CONTEXTUAL );
# discreetRoot->VPA->VPB->VPB->makeChildren();
# discreetRoot->setNodePropIndex( TARGET_LIST );
# discreetRoot->setNodePropIndex( TARGET_ID );
# discreetRoot->VPB->VPA->VPA->makeChildren();
# discreetRoot->setNodePropIndex( MODE );
# discreetRoot->setNodePropIndex( VPA );
# discreetRoot->VPB->VPA->VPB->makeChildren();
# discreetRoot->setNodePropIndex( BARS );
# discreetRoot->setNodePropIndex( VISUAL_FX );
# discreetRoot->VPB->VPB->VPA->makeChildren();
# discreetRoot->setNodePropIndex( VPB );
# discreetRoot->VPB->VPB->VPA->VPB->makeChildren();
# discreetRoot->setNodePropIndex( VPC );
# discreetRoot->VPB->VPB->VPA->VPB->VPB->makeChildren();
# discreetRoot->setNodePropIndex( EVENT_FACTION_ID );
# discreetRoot->VPB->VPB->VPA->VPB->VPB->VPB->makeChildren();
# discreetRoot->setNodePropIndex( PVP_MODE );
# discreetRoot->setNodePropIndex( PVP_CLAN );
# discreetRoot->VPB->VPB->VPB->makeChildren();
# discreetRoot->VPB->VPB->VPB->VPA->makeChildren();
# discreetRoot->setNodePropIndex( ENTITY_MOUNTED_ID );
# discreetRoot->setNodePropIndex( RIDER_ENTITY_ID );
# discreetRoot->VPB->VPB->VPB->VPB->makeChildren();
# discreetRoot->setNodePropIndex( OUTPOST_INFOS );
# discreetRoot->VPB->VPB->VPB->VPB->VPB->makeChildren();
# discreetRoot->setNodePropIndex( GUILD_SYMBOL );
# discreetRoot->setNodePropIndex( GUILD_NAME_ID );
#
# return NB_VISUAL_PROPERTIES;
def isRoot(self):
# khanat-opennel-code/code/ryzom/common/src/game_share/entity_types.h:407 bool isRoot()
return self.VPParent == None
def isLeaf(self):
# khanat-opennel-code/code/ryzom/common/src/game_share/entity_types.h:410 bool isLeaf()
return self.PropIndex != Enum.TPropIndex.NB_VISUAL_PROPERTIES
def getLevel(self):
level = 0
node = self
while node != None:
level += 1
node = node.VPParent
return level
def decodeDiscreetProperty(self, msgin, propIndex, slot, world):
# khanat-opennel-code/code/ryzom/client/src/network_connection.cpp:1746 void CNetworkConnection::decodeDiscreetProperty
logging.getLogger(LOGGER).debug("decodeDiscreetProperty")
notices = {}
2020-07-27 20:17:48 +00:00
action = None
if propIndex == Enum.TPropIndex.PROPERTY_TARGET_LIST:
logging.getLogger(LOGGER).debug("PROPERTY_TARGET_LIST")
listSize = msgin.readUint8("listSize")
logging.getLogger(LOGGER).debug("listSize:{0}".format(listSize))
# TargetSlotsList.resize(listSize);
if listSize > 0:
for i in range(0, listSize):
d1 = msgin.readUint8( "TargetSlots_{0}".format(i));
logging.getLogger(LOGGER).debug("data:{0}".format(d1))
# Update property
return [], notices
2020-07-27 20:17:48 +00:00
logging.getLogger(LOGGER).debug("CActionFactory : {0}".format(slot))
action = CActionFactory.CActionFactory(world).createByPropIndex(slot, self.PropIndex, self.NameProperty)
action.set_header_notice("-")
2020-07-27 20:17:48 +00:00
logging.getLogger(LOGGER).debug("unpack: {0}".format(slot))
action.unpack(msgin)
if self.PropIndex == Enum.TPropIndex.PROPERTY_SHEET:
aliasBit = msgin.readBool("aliasBit")
logging.getLogger(LOGGER).debug("aliasBit:{0}".format(aliasBit))
if aliasBit:
alias = msgin.readUint32("alias");
logging.getLogger(LOGGER).debug("alias:{0}".format(alias))
elif self.PropIndex == Enum.TPropIndex.PROPERTY_MODE:
pass
else:
pass
logging.getLogger(LOGGER).debug("[decodeDiscreetProperty] (%s)" % (msgin.showAllData()))
for key in action.notice:
notices.setdefault(key[2:], action.notice[key])
return action, notices
2020-07-27 20:17:48 +00:00
def decodeDiscreetProperties(self, clientid, msgin, slot, world):
# khanat-opennel-code/code/ryzom/client/src/network_connection.h:148 void decodeDiscreetProperties
logging.getLogger(LOGGER).debug("decodeDiscreetProperties " + self.Name)
self.BranchHasPayload = msgin.readBool("BranchHasPayload [{0}, NameProperty:{1}]".format(self.Name, self.NameProperty))
actions = []
notices = {}
2020-07-27 20:17:48 +00:00
if self.BranchHasPayload:
if self.isLeaf():
# SlotContext.NetworkConnection->decodeDiscreetProperty( msgin, PropIndex );
logging.getLogger(LOGGER).debug("isLeaf")
action, addnotices = self.decodeDiscreetProperty(msgin, self.PropIndex, slot, world)
for key in addnotices:
notices.setdefault(key, addnotices[key])
2020-07-27 20:17:48 +00:00
if action:
actions.append(action)
else:
if self.VPA:
tmp, addnotices = self.VPA.decodeDiscreetProperties(clientid, msgin, slot, world)
for key in addnotices:
notices.setdefault(key, addnotices[key])
2020-07-27 20:17:48 +00:00
for action in tmp:
actions.append(action)
if self.VPB:
tmp, addnotices = self.VPB.decodeDiscreetProperties(clientid, msgin, slot, world)
for key in addnotices:
notices.setdefault(key, addnotices[key])
2020-07-27 20:17:48 +00:00
for action in tmp:
actions.append(action)
return actions, notices
2020-07-27 20:17:48 +00:00
def decodeDiscreetPropertiesVpbVpb(self, clientid, msgin, slot, world):
return self.VPB.VPB.decodeDiscreetProperties(clientid, msgin, slot, world)