Files
panda3d/samples/networking/03-distributed-node/AIDGameObjectAI.py
Fireclaw 3d8f824081 Add Distributed Network samples
1: Simple client-server connection
2: Client-server connection with timeManager
3: Create distributed objects, sending and receiving messages
4: Distributed model file
5: Simple text chat
6: Simple smooth moving actor
2021-10-28 09:54:17 +02:00

26 lines
1.0 KiB
Python

from direct.distributed.DistributedObjectAI import DistributedObjectAI
class AIDGameObjectAI(DistributedObjectAI):
def __init__(self, aiRepository):
DistributedObjectAI.__init__(self, aiRepository)
def messageRoundtripToAI(self, data):
""" The client sent us some data to process. So work with it and send
changed data back to the requesting client """
requesterId = self.air.getAvatarIdFromSender()
print("Got client data:", data, "from client with ID", requesterId)
# do something with the data
aiChangedData = (
data[0] + " from the AI",
data[1] + 1,
data[2])
print("Sending modified game data back:", aiChangedData)
self.d_messageRoundtripToClient(aiChangedData, requesterId)
def d_messageRoundtripToClient(self, data, requesterId):
""" Send the given data to the requesting client """
print("Send message to back to:", requesterId)
self.sendUpdateToAvatarId(requesterId, 'messageRoundtripToClient', [data])