mirror of
https://port.numenaute.org/aleajactaest/clientbot.git
synced 2024-11-09 08:49:05 +00:00
101 lines
3.9 KiB
Python
101 lines
3.9 KiB
Python
#!/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
|
|
|
|
LOGGER='CPropertyDecoder'
|
|
|
|
class CEntityEntry():
|
|
def __init__(self):
|
|
self.Sheet = 0
|
|
self.AssociationBits = 0
|
|
self.EntryUsed = False
|
|
self.PosIsRelative = False
|
|
self.PosIsInterior = False
|
|
|
|
class CPropertyDecoder():
|
|
def __init__(self):
|
|
# khanat-opennel-code/code/ryzom/client/src/network_connection.cpp:2937 _PropertyDecoder.init (256);
|
|
self.Entities = [CEntityEntry() for _ in range(0, 256)]
|
|
#for i in range(0, 256):
|
|
# self.Entities[i] = CEntityEntry()
|
|
self._RefPosX = 0
|
|
self._RefPosY = 0
|
|
self._RefBitsX = 0
|
|
self._RefBitsY = 0
|
|
self._RefBitsZ = 0
|
|
|
|
def GetAssociationBits(self, slot):
|
|
return self.Entities[slot].AssociationBits
|
|
|
|
def clear(self):
|
|
for i in range(0, 256):
|
|
self.Entities[i] = CEntityEntry()
|
|
|
|
def associationBitsHaveChanged(self, slot, _associationBits):
|
|
res = _associationBits != self.GetAssociationBits(slot)
|
|
self.Entities[slot].AssociationBits = _associationBits
|
|
return res
|
|
|
|
def addEntity(self, entity, sheet):
|
|
self.Entities[entity].EntryUsed = True
|
|
self.Entities[entity].Sheet = sheet
|
|
|
|
def removeEntity(self, entity):
|
|
if self.Entities[entity].EntryUsed:
|
|
self.Entities[entity].EntryUsed = False
|
|
self.Entities[entity].Sheet = 0xffff
|
|
|
|
def isUsed(self, slot):
|
|
return self.Entities[slot].EntryUsed
|
|
|
|
def getSheet(self, slot):
|
|
return self.Entities[slot].Sheet
|
|
|
|
def decodeAbsPos2D(self, x16, y16):
|
|
x = self._RefPosX + (x16 - self._RefBitsX) << 4
|
|
y = self._RefPosY + (y16 - self._RefBitsY) << 4
|
|
|
|
return (x, y)
|
|
|
|
def receive(self, actionPosition):
|
|
# if (action->Code == ACTION_POSITION_CODE) # normally is always this type
|
|
if actionPosition.IsRelative:
|
|
# Relative position (entity in a ferry...)
|
|
actionPosition.Position[0] = actionPosition.Position16[0]
|
|
actionPosition.Position[1] = actionPosition.Position16[1]
|
|
actionPosition.Position[2] = actionPosition.Position16[2]
|
|
self.Entities[actionPosition.Slot].PosIsRelative = True
|
|
self.Entities[actionPosition.Slot].PosIsInterior = False
|
|
else:
|
|
# Absolute position
|
|
# actionPosition.Position[0] , actionPosition.Position[1] = self.decodeAbsPos2D(actionPosition.Position16[0], actionPosition.Position16[1])
|
|
actionPosition.Position[0] = self._RefPosX + (actionPosition.Position16[0] - self._RefBitsX) << 4
|
|
actionPosition.Position[1] = self._RefPosY + (actionPosition.Position16[1] - self._RefBitsY) << 4
|
|
actionPosition.Position[2] = actionPosition.Position16[2] << 4
|
|
if actionPosition.Interior:
|
|
actionPosition.Position[2] += 2
|
|
self.Entities[actionPosition.Slot].PosIsRelative = False
|
|
self.Entities[actionPosition.Slot].PosIsInterior = actionPosition.Interior
|