Add job for farming trees and object physics
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import re
|
||||
import time
|
||||
import importlib
|
||||
import random
|
||||
from math import hypot
|
||||
from itertools import count
|
||||
from bunch import Bunch
|
||||
from munch import Munch
|
||||
|
||||
from panda3d.core import LPoint3f
|
||||
|
||||
@@ -17,8 +18,7 @@ from protocol.packets import (
|
||||
ClickWindowPacket, CloseWindowPacket, ServerWindowConfirmationPacket,
|
||||
ClientWindowConfirmationPacket, EntityMetadataPacket,
|
||||
SpawnLivingEntityPacket, EntityPositionPacket,
|
||||
EntityPositionRotationPacket,
|
||||
|
||||
EntityPositionRotationPacket, DestroyEntitiesPacket, EntityVelocityPacket,
|
||||
)
|
||||
|
||||
from protocol.types import Slot
|
||||
@@ -93,7 +93,7 @@ class MCWorld:
|
||||
result = []
|
||||
|
||||
# TODO: make sure only non-solid and leaves between
|
||||
# make sure traversable too
|
||||
# make sure traversable too and non-avoid
|
||||
|
||||
for distance in range(5):
|
||||
for direction in path.CHECK_DIRECTIONS:
|
||||
@@ -203,6 +203,8 @@ class Game:
|
||||
register(self.handle_spawn_living, SpawnLivingEntityPacket)
|
||||
register(self.handle_entity_position, EntityPositionPacket)
|
||||
register(self.handle_entity_position_rotation, EntityPositionRotationPacket)
|
||||
register(self.handle_destroy_entities, DestroyEntitiesPacket)
|
||||
register(self.handle_entity_velocity, EntityVelocityPacket)
|
||||
|
||||
#register(self.handle_packet, Packet, early=True)
|
||||
|
||||
@@ -224,8 +226,8 @@ class Game:
|
||||
solution = path.Pathfinder(self.g.chunks).astar(utils.pint(self.g.pos), utils.pint(self.g.goal))
|
||||
if solution:
|
||||
solution = list(solution)
|
||||
#self.g.path = solution
|
||||
#self.g.job.state = self.g.job.stop
|
||||
self.g.path = solution
|
||||
self.g.job.state = self.g.job.stop
|
||||
print(len(solution))
|
||||
print(solution)
|
||||
print(round(time.time() - start, 3), 'seconds')
|
||||
@@ -320,6 +322,19 @@ class Game:
|
||||
else:
|
||||
reply += ', I need a bed'
|
||||
|
||||
if command == 'farm' and data:
|
||||
if data == 'wood':
|
||||
self.g.job.state = self.g.job.farm_wood
|
||||
reply = 'ok'
|
||||
|
||||
if reply:
|
||||
for i in self.g.inv.values():
|
||||
print(i.item_id)
|
||||
if i.item_id in items.BED_IDS:
|
||||
break
|
||||
else:
|
||||
reply += ', I need a bed'
|
||||
|
||||
if command == 'stop':
|
||||
self.g.job.state = self.g.job.stop
|
||||
reply = 'ok'
|
||||
@@ -386,6 +401,11 @@ class Game:
|
||||
self.g.job.find_gapple_states.count = int(data)
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'objects':
|
||||
for k, v in self.g.objects.items():
|
||||
if data and v.item_id != int(data): continue
|
||||
print(str(k) + ':', v)
|
||||
|
||||
if reply:
|
||||
print(reply)
|
||||
self.g.chat.send(reply)
|
||||
@@ -483,6 +503,23 @@ class Game:
|
||||
else: #for
|
||||
return False
|
||||
|
||||
def select_random_item(self, items):
|
||||
# select a random match from items of inv
|
||||
# this is random per item type
|
||||
# example: 5 stacks wood, 1 stack glass
|
||||
# -> still 50/50 chance between them
|
||||
|
||||
matches = set()
|
||||
for slot, item in self.g.inv.items():
|
||||
if item.item_id in items:
|
||||
matches.add(item.item_id)
|
||||
|
||||
if matches:
|
||||
return self.select_item([random.choice(list(matches))])
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def drop_stack(self):
|
||||
packet = PlayerDiggingPacket()
|
||||
packet.status = 3
|
||||
@@ -497,7 +534,7 @@ class Game:
|
||||
|
||||
def handle_window(self, packet):
|
||||
print(packet)
|
||||
self.g.window = Bunch(data=packet, contents=dict(), count=0)
|
||||
self.g.window = Munch(data=packet, contents=dict(), count=0)
|
||||
|
||||
def click_window(self, slot, button, mode, item):
|
||||
w = self.g.window
|
||||
@@ -529,41 +566,76 @@ class Game:
|
||||
self.g.connection.write_packet(packet2)
|
||||
|
||||
def handle_spawn_object(self, packet):
|
||||
return
|
||||
#return
|
||||
if packet.type_id != 37: return
|
||||
print(packet)
|
||||
self.g.objects[packet.entity_id] = Munch(
|
||||
x=packet.x,
|
||||
y=packet.y,
|
||||
z=packet.z,
|
||||
velocity_x=packet.velocity_x,
|
||||
velocity_y=packet.velocity_y,
|
||||
velocity_z=packet.velocity_z,
|
||||
)
|
||||
|
||||
def check_gapple(self, packet):
|
||||
if not self.g.job:
|
||||
return
|
||||
|
||||
current_gapple_chest = self.g.job.find_gapple_states.current_chest
|
||||
if current_gapple_chest:
|
||||
for entry in packet.metadata:
|
||||
if entry.type != 6:
|
||||
continue
|
||||
|
||||
if entry.value.item_id in items.GAPPLE_ID:
|
||||
self.g.chat.send('gapple found: ' + str(current_gapple_chest)[1:-1])
|
||||
print('gapple found:', str(current_gapple_chest)[1:-1])
|
||||
|
||||
def handle_entity_metadata(self, packet):
|
||||
if not packet.metadata:
|
||||
return
|
||||
|
||||
if not self.g.job:
|
||||
return
|
||||
|
||||
current_chest = self.g.job.find_gapple_states.current_chest
|
||||
if not current_chest:
|
||||
return
|
||||
|
||||
for entry in packet.metadata:
|
||||
if entry.type != 6:
|
||||
continue
|
||||
|
||||
if entry.value.item_id in items.GAPPLE_ID:
|
||||
self.g.chat.send('gapple found: ' + str(current_chest)[1:-1])
|
||||
print('gapple found:', str(current_chest)[1:-1])
|
||||
self.check_gapple(packet)
|
||||
|
||||
obj = self.g.objects.get(packet.entity_id, None)
|
||||
if obj:
|
||||
for entry in packet.metadata:
|
||||
if entry.type != 6:
|
||||
continue
|
||||
obj.item_id = entry.value.item_id
|
||||
obj.item_count = entry.value.item_count
|
||||
|
||||
def handle_spawn_living(self, packet):
|
||||
return
|
||||
print(packet)
|
||||
|
||||
def handle_entity_position(self, packet):
|
||||
return
|
||||
print(packet)
|
||||
obj = self.g.objects.get(packet.entity_id, None)
|
||||
if obj:
|
||||
pass
|
||||
#obj.x += packet.delta_x
|
||||
#obj.y += packet.delta_y
|
||||
#obj.z += packet.delta_z
|
||||
|
||||
def handle_entity_position_rotation(self, packet):
|
||||
return
|
||||
print(packet)
|
||||
obj = self.g.objects.get(packet.entity_id, None)
|
||||
if obj:
|
||||
print('object rotation found:', packet)
|
||||
raise
|
||||
|
||||
def handle_entity_velocity(self, packet):
|
||||
obj = self.g.objects.get(packet.entity_id, None)
|
||||
if obj:
|
||||
print(packet)
|
||||
#obj.velocity_x = packet.velocity_x
|
||||
#obj.velocity_y = packet.velocity_y
|
||||
#obj.velocity_z = packet.velocity_z
|
||||
|
||||
def handle_destroy_entities(self, packet):
|
||||
for eid in packet.entity_ids:
|
||||
if eid in self.g.objects:
|
||||
del self.g.objects[eid]
|
||||
|
||||
def tick(self):
|
||||
if self.g.breaking:
|
||||
|
||||
Reference in New Issue
Block a user