Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def keep_it(self, me):
result = Oplist()
if (self.where in me.things) == 0: return
if (self.what in me.things) == 0: return
thing_all = me.find_thing(self.what)
where = me.find_thing(self.where)[0]
to_location = Location(where, Point3D(0, 0, 0))
minx = where.location.bbox.low_corner.x
minz = where.location.bbox.low_corner.z
maxx = where.location.bbox.high_corner.x
maxz = where.location.bbox.high_corner.z
for thing in thing_all:
if thing.location.parent.id != where.id and thing.location.parent.id != me.entity.id:
thingloc = Location(where, Point3D(uniform(minx, maxx), 0, uniform(minz, maxz)))
result.append(Operation("move", Entity(thing.id, location=thingloc)))
return result
def tick_operation(self, op):
""" Op handler for regular tick op """
res = Oplist()
if self.target() is None:
# print "Target is no more"
self.irrelevant()
return
if not self.target().location.parent:
self.irrelevant()
return
target_location = Location(self.target().location.parent,
self.target().location.pos)
target_location.velocity = Vector3D(0, -0.5, 0)
new_loc = self.character.location.pos
origin = self.points[0]
# Get the diffrence in the location of user at current time to the time when he started the task
diff = origin.x - new_loc.x
target_entity_moving = Entity(self.target().id, location=target_location)
# Replicate the diffrence in position to the corresponding change in height.
target_location = Location(self.target().location.parent,
Point3D(self.target().location.pos.x,
self.target().location.pos.y + diff,
self.target().location.pos.z))
target_location.velocity = Vector3D(0, 0, 0)
target_entity = Entity(self.target().id, location=target_location)
res = Oplist()
arg = op[0]
if not arg:
return server.OPERATION_IGNORED
if not arg.pos:
print('No pos supplied')
return server.OPERATION_IGNORED
terrain_prop = self.props.terrain
if not terrain_prop:
print('No terrain prop on excavatable terrain entity')
return server.OPERATION_IGNORED
chunk_loc = Location(self, arg.pos)
surface = terrain_prop.get_surface_name(arg.pos[0], arg.pos[2])
if surface not in ExcavatableTerrain.materials:
print("Not rock")
return
material = ExcavatableTerrain.materials[surface]
mods = terrain_prop.find_mods(arg.pos[0], arg.pos[2])
if len(mods) == 0:
# There is no terrain mod where we are digging,
# create a quarry
modmap = {
'heightoffset': -1,
'shape': {
'points': [[-1.0, -1.0],
self.rate = 0.5 / 0.75
self.progress += 1
if not target:
print("Target is no more")
self.irrelevant()
return
if self.progress < 1:
# print "Not done yet"
return self.next_tick(0.75)
self.progress = 0
chunk_loc = Location(self.character.location.parent)
chunk_loc.pos = self.pos
chunk_loc.orientation = self.character.location.orientation
res = Oplist()
acount = 0 # A frame count
lcount = 0 # lumber count
wcount = 0 # wood count
ccount = 0 # campfire count
bcount = 0 # boulder count
self.fname = "" # furnishing name
lumberwidth = 0
# makes sure we have the right amount of material
for item in self.character.contains:
if item.type[0] == "lumber":
lcount = lcount + 1
lumberwidth = item.location.bbox.high_corner[2] - item.location.bbox.low_corner[2]
self.progress += 0.1
if old_rate < 0.01:
self.progress = 0
# print "%s" % self.pos
if self.progress < 1:
# print "Not done yet"
return self.next_tick(1.75)
self.progress = 0
res = Oplist()
self_loc = Location(self.character)
self_loc.velocity = Vector3D()
if hasattr(world, 'moisture'):
moisture = 10 * world.moisture
else:
moisture = 1
self_loc.pos = self.pos
quality = int(self.get_quality(self_loc.pos, self.target(), moisture))
print(quality)
for i in range(int(quality / 2), quality):
res = res + Operation("create", Entity(name="scrawny earthworm", parent="annelid", location=self_loc), to=self.character)
for i in range(int((10 - quality) / 2), quality):
res = res + Operation("create", Entity(name="juicy earthworm", parent="annelid", location=self_loc), to=self.character)
self.irrelevant()
return res
def hit_operation(self, op):
res = Oplist()
arg = op[0]
if arg:
# Place the explosion at the point of collision.
new_location = rules.Location(self.location.parent, arg.pos)
entity = Entity(parent="explosion", location=new_location, mode="fixed")
mode_data = self.props.mode_data
actor_id = self.id
# Check if there's an entity ref contained in the mode_data prop,
# and if so attach that to the "entity_ref" prop of the explosion.
# This way the explosion can properly attribute any Hit op it sends to the actor which fired the item.
if mode_data:
entity_ref = mode_data['$eid']
if entity_ref is not None:
actor_id = entity_ref
entity["entity_ref"] = {"$eid": actor_id}
damage_explosion = self.props.damage_explosion
if damage_explosion is not None:
entity["damage"] = damage_explosion
id = me.get_knowledge('focus', 'hook')
if id != None:
thing = me.map.get(id)
if thing == None:
me.remove_knowledge('focus', what)
else:
if thing.location.parent.id != me.entity.location.parent.id:
me.remove_knowledge('focus', what)
else:
if thing.location.parent.id == me.entity.id:
return
# ensures that the entity will check only other entities really close to it,
# thereby reducing the possibility of infinite loops
if distance < 0.4 and ent.location.velocity:
print("changing only velocity")
new_loc = Location(me.entity.location.parent)
new_loc.velocity = ent.location.velocity
if distance > 0.4 and ent.location.velocity:
print("changing both location and velocity")
myvel = me.entity.location.velocity.unit_vector()
evel = ent.location.velocity.unit_vector()
edir = (ent.location.pos - me.entity.location.pos).unit_vector()
if myvel and (evel.dot(myvel) > 0.9 or edir.dot(myvel) > 0.9):
return
if edir.dot(evel) < 0:
new_loc = Location(me.entity.location.parent)
# replace by rotatez?
new_loc.velocity = -ent.location.velocity
else:
new_loc = Location(me.entity.location.parent)
new_loc.velocity = ent.location.velocity
else:
def respawn(self):
limbo_entity = server.get_limbo_location()
# If we're in limbo we should respawn
if limbo_entity and self.location.parent == limbo_entity:
respawn_loc = self.props["__respawn"]
if respawn_loc:
set_op = Operation("set", Entity(self.id, __respawn=None), to=self.id)
if hasattr(respawn_loc, "pos") and hasattr(respawn_loc, "loc"):
return Operation("move", Entity(self.id, pos=respawn_loc.pos, loc=respawn_loc.loc),
to=self.id), set_op
elif hasattr(respawn_loc, "spawn"):
# Respawn in a spawn area
location = Location()
server.move_to_spawn(respawn_loc.spawn, location)
return Operation("move", Entity(self.id, location=location), to=self.id), set_op
self.rate = 1.0 / 1.75
self.progress = 0.01
if old_rate < 0.1:
# print "Wasn't moving right speed"
return self.next_tick(1.75)
surface = self.target().props.terrain.get_surface(self.character.location.pos)
if surface is not 2:
# print "Not grass"
return self.next_tick(1.75)
res = Oplist()
chunk_loc = Location(self.character.location.parent)
chunk_loc.velocity = Vector3D()
chunk_loc.pos = self.character.location.pos
create = Operation("create",
Entity(name="grass",
type="grass",
location=chunk_loc), to=self.target())
res.append(create)
res.append(self.next_tick(1.75))
return res
print('No pos supplied')
return server.OPERATION_IGNORED
terrain_prop = self.props.terrain
if not terrain_prop:
print('No terrain prop on diggable terrain entity')
return server.OPERATION_IGNORED
surface = self.props.terrain.get_surface_name(arg.pos[0], arg.pos[2])
if surface not in DiggableTerrain.materials:
print("The surface couldn't be digged here. Material {}.".format(surface))
return server.OPERATION_IGNORED
material = DiggableTerrain.materials[surface]
chunk_loc = Location(self, arg.pos)
print("Creating pile of {} at {}".format(material, chunk_loc))
new_entity = Entity(name="Pile of {}".format(material),
parent="pile",
material=material,
location=chunk_loc)
if material == 'earth':
new_entity._worms = random.randint(0, 3)
create_op = Operation("create", new_entity, to=self.id)
return server.OPERATION_BLOCKED, create_op