Python:Toontown的服务器模拟器



好吧,我正在为迪士尼现已关闭的游戏《卡通城在线》制作一个服务器,但我在添加此代码后遇到了一个问题。游戏需要这一部分,它对游戏至关重要,没有它,游戏将无法发送客户端"AvatarChooser.enter",玩家将无法创建自己的角色!如果需要,我会发布更多的代码,但现在是这样。

class DistributedDistrict(DistributedObject):
__module__ = __name__
notify = directNotify.newCategory('DistributedDistrict')
neverDisable = 1
def __init__(self, cr):
    print 'DistributedDistrict: BlankTest Canvas is now Online..'
    DistributedObject.__init__(self, cr)
    self.name = 'BlankTest Canvas'
    self.available = 0
    self.avatarCount = 0
    self.newAvatarCount = 0
def announceGenerate(self):
    DistributedObject.announceGenerate(self)
    self.cr.activeDistrictMap[self.doId] = self
    messenger.send('shardInfoUpdated')
def delete(self):
    if base.cr.distributedDistrict is self:
        base.cr.distributedDistrict = None
    if self.cr.activeDistrictMap.has_key(self.doId):
        del self.cr.activeDistrictMap[self.doId]
    DistributedObject.delete(self)
    messenger.send('shardInfoUpdated')
    return
def setAvailable(self, available):
    self.available = available
    messenger.send('shardInfoUpdated')
def setName(self, name):
    self.name = name
    messenger.send('shardInfoUpdated')
simbase = DistributedDistrict()
#run() # Initialize the Panda3D API.

我得到这个错误:

类型错误:__init__()正好取2个参数(给定1个)

任何帮助都将不胜感激!!

错误发生在:

simbase = DistributedDistrict()
#run() # Initialize the Panda3D API.

"当我把它设置为5时,它起作用了"

您不应该将其设置为5cr参数需要ClientRepository参数。

注意此行中的参数数量:

simbase = DistributedDistrict()

现在,看看DistributedDistrict:的构造函数

def __init__(self, cr):

self隐含在构造函数中,但您忘记了cr参数。

要解决此问题,您需要:

simbase = DistributedDistrict(some_value) # wasn't sure what the value of cr would be

当谈到分布式对象(在本例中为DistributedDistrict)时,您需要检查DistributedClass文件以查看它实际占用的字段,在这个文件中,您会发现它看起来是这样的(如果您想自己在toontown目录中的otp.dc中查看)

dclass DistributedDistrict : DistributedObject {
    setName(string) required broadcast ram;
    setAvailable(uint8) required broadcast ram;

在这里,你可以看到你在代码中显示的2个字段,现在,虽然你可以向这个代码提供ClientRepository,但你还需要看看这个DistributedObject是否有AI或UD(UberDOG)表示。你可以通过(再次)查看otp.dc 来弄清楚这一点

from otp.distributed import DistributedDistrict/AI/UD

在这里,您可以看到DistributedDistrict实际上是由AI服务器生成的DistributedObject。这意味着服务器是该对象的所有者,除了服务器之外,任何人都不能设置值setName和setAvailable。为了使其正确运行,您需要编写一些内容来接收由普通DistributedDistrict.py文件发送的更新,这个新的AI文件必须称为DistributedDistrictAI.py,并且必须在AIRepository中创建为新的DistributedObject。事实上,它也是一个UberDOG,这也意味着您需要编写DistributedObject的DistributedDistrictUD.py表示,然后应该在您的UDRepository上创建该表示。

希望这能为你指明正确的方向,祝你的项目好运。

最新更新