本文整理汇总了Python中services.current_zone函数的典型用法代码示例。如果您正苦于以下问题:Python current_zone函数的具体用法?Python current_zone怎么用?Python current_zone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了current_zone函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_object
def create_object(definition_or_id, obj_id=0, init=None, post_add=None, loc_type=None, **kwargs):
from objects.components.inventory_item import ItemLocation
from objects.base_object import BaseObject
added_to_object_manager = False
obj = None
if loc_type is None:
loc_type = ItemLocation.ON_LOT
try:
obj = create_script_object(definition_or_id, **kwargs)
if obj is None:
return
if not isinstance(obj, BaseObject):
logger.error('Type {0} is not a valid managed object. It is not a subclass of BaseObject.', type(obj))
return
if init is not None:
init(obj)
if loc_type == ItemLocation.FROM_WORLD_FILE:
obj.persistence_group = PersistenceGroups.IN_OPEN_STREET
obj.item_location = ItemLocation(loc_type) if loc_type is not None else ItemLocation.INVALID_LOCATION
obj.id = obj_id
if loc_type == ItemLocation.ON_LOT or loc_type == ItemLocation.FROM_WORLD_FILE or loc_type == ItemLocation.FROM_OPEN_STREET:
obj.object_manager_for_create.add(obj)
elif loc_type == ItemLocation.SIM_INVENTORY or loc_type == ItemLocation.OBJECT_INVENTORY:
services.current_zone().inventory_manager.add(obj)
else:
logger.error('Unsupported loc_type passed to create_script_object. We likely need to update this code path.', owner='mduke')
added_to_object_manager = True
if post_add is not None:
post_add(obj)
return obj
finally:
if not added_to_object_manager and obj is not None:
import _weakrefutils
_weakrefutils.clear_weak_refs(obj)
示例2: get_save_lot_coords_and_level
def get_save_lot_coords_and_level(self):
lot_coord_msg = LotCoord()
parent = self.parent
if parent is not None and parent.is_sim:
parent.force_update_routing_location()
starting_position = parent.position + parent.forward
search_flags = CarryingObject.SNAP_TO_GOOD_LOCATION_SEARCH_FLAGS
(trans, orient) = placement.find_good_location(placement.FindGoodLocationContext(starting_position=starting_position, starting_orientation=parent.orientation, starting_routing_surface=self.location.world_routing_surface, object_footprints=(self.footprint,), object_id=self.id, search_flags=search_flags))
if trans is None:
logger.warn('Unable to find good location to save object{}, which is parented to sim {} and cannot go into an inventory. Defaulting to location of sim.', self, parent)
transform = parent.transform
else:
transform = sims4.math.Transform(trans, orient)
transform = services.current_zone().lot.convert_to_lot_coordinates(transform)
elif self.persistence_group == PersistenceGroups.OBJECT:
transform = services.current_zone().lot.convert_to_lot_coordinates(self.transform)
else:
transform = self.transform
lot_coord_msg.x = transform.translation.x
lot_coord_msg.y = transform.translation.y
lot_coord_msg.z = transform.translation.z
lot_coord_msg.rot_x = transform.orientation.x
lot_coord_msg.rot_y = transform.orientation.y
lot_coord_msg.rot_z = transform.orientation.z
lot_coord_msg.rot_w = transform.orientation.w
if self.location.world_routing_surface is not None:
level = self.location.level
else:
level = 0
return (lot_coord_msg, level)
示例3: _on_leaving_situation
def _on_leaving_situation(self, end_work_reason):
service_npc_type = self._service_npc_type
household = self._hiring_household
try:
now = services.time_service().sim_now
time_worked = now - self._service_start_time
time_worked_in_hours = time_worked.in_hours()
if self._had_preroll_work:
cost = service_npc_type.get_cost(time_worked_in_hours)
else:
cost = 0
if cost > 0:
(paid_amount, billed_amount) = service_npc_type.try_charge_for_service(household, cost)
end_work_reason = ServiceNpcEndWorkReason.NOT_PAID
else:
paid_amount = 0
billed_amount = 0
self._send_end_work_notification(end_work_reason, paid_amount, billed_amount)
service_record = household.get_service_npc_record(service_npc_type.guid64)
service_record.time_last_finished_service = now
if end_work_reason == ServiceNpcEndWorkReason.FIRED:
service_sim = self.service_sim()
if service_record is not None:
service_record.add_fired_sim(service_sim.id)
service_record.remove_preferred_sim(service_sim.id)
while end_work_reason in ServiceNpcSituation.CANCEL_SERVICE_LEAVING_REASONS:
services.current_zone().service_npc_service.cancel_service(household, service_npc_type)
except Exception as e:
logger.exception('Exception while executing _on_leaving_situation for situation {}', self, exc=e)
finally:
if not self._is_recurring:
services.current_zone().service_npc_service.cancel_service(household, service_npc_type)
return end_work_reason
示例4: on_add
def on_add(self):
if self._relationship_based_state_change_tuning is None:
return
self._state_changes = self._relationship_based_state_change_tuning.state_changes
self._default_state = self._relationship_based_state_change_tuning.default_state
services.current_zone().register_callback(zone_types.ZoneState.CLIENT_CONNECTED, self._register_active_sim_change)
services.current_zone().register_callback(zone_types.ZoneState.HOUSEHOLDS_AND_SIM_INFOS_LOADED, self._publish_relationship_data)
示例5: on_update
def on_update(self):
super().on_update()
if self._countdown <= 0:
services.current_zone().on_hit_their_marks()
return _ZoneSpinUpStateResult.DONE
services.game_clock_service().advance_for_hitting_their_marks()
return _ZoneSpinUpStateResult.WAITING
示例6: broadcasters_add
def broadcasters_add(broadcaster_type, broadcasting_object:OptionalTargetParam=None, _connection=None):
broadcasting_object = get_optional_target(broadcasting_object, _connection)
if broadcasting_object is None:
return False
broadcaster = broadcaster_type(broadcasting_object=broadcasting_object)
services.current_zone().broadcaster_service.add_broadcaster(broadcaster)
return True
示例7: set_venue
def set_venue(venue_type, _connection=None):
venue_tuning = services.venue_manager().get(venue_type)
if venue_tuning is None:
sims4.commands.output('Requesting an unknown venue type: {0}'.format(venue_type), _connection)
return False
services.current_zone().venue_service.set_venue_and_schedule_events(venue_tuning)
return True
示例8: on_enter
def on_enter(self):
super().on_enter()
services.current_zone().lot.publish_shared_inventory_items()
active_household_id = services.active_household_id()
for script_object in services.object_manager().get_all():
script_object.finalize(active_household_id=active_household_id)
return _ZoneSpinUpStateResult.DONE
示例9: add
def add(self, obj, *args, **kwargs):
super().add(obj, *args, **kwargs)
if obj.objectage_component is None:
services.current_zone().increment_object_count(obj)
household_manager = services.household_manager()
if household_manager is not None:
household_manager.increment_household_object_count(obj.get_household_owner_id())
示例10: _run_interaction_gen
def _run_interaction_gen(self, timeline):
sim = self.sim
end_time = services.time_service().sim_now + create_time_span(hours=8)
fake_alarm_data = AlarmData(None, end_time, None, False)
default_user_specified_data_id = self._service_tuning.get_default_user_specified_data_id()
creation_data = ServiceNpcSituationCreationParams(sim.household, self._service_tuning, user_specified_data_id=default_user_specified_data_id, is_recurring=False)
services.current_zone().service_npc_service._send_service_npc(None, fake_alarm_data, creation_data)
return True
示例11: get_jog_waypoint_constraints
def get_jog_waypoint_constraints(cls, context):
sim = context.sim
if context.pick is not None:
pick_position = context.pick.location
pick_vector = pick_position - sim.position
pick_vector /= pick_vector.magnitude()
else:
pick_vector = sim.forward
zone = services.current_zone()
active_lot = zone.lot
lot_corners = active_lot.corners
sim_poly = sims4.geometry.CompoundPolygon(sims4.geometry.Polygon([sim.position]))
lot_poly = sims4.geometry.CompoundPolygon(sims4.geometry.Polygon([corner for corner in lot_corners]))
intersection = lot_poly.intersect(sim_poly)
sim_on_lot = len(intersection) >= 1
if sim_on_lot:
spawn_point = zone.get_spawn_point(lot_id=active_lot.lot_id, sim_spawner_tags=SimInfoSpawnerTags.SIM_SPAWNER_TAGS)
origin_position = spawn_point.center
routing_surface = routing.SurfaceIdentifier(zone.id, 0, routing.SURFACETYPE_WORLD)
except_lot_id = active_lot.lot_id
else:
origin_position = sim.position
routing_surface = sim.routing_surface
except_lot_id = None
interaction_constraint = Circle(origin_position, cls.CONSTRAINT_RADIUS, routing_surface=routing_surface, los_reference_point=None)
jog_waypoint_constraints = []
zone = services.current_zone()
active_lot = zone.lot
constraint_set = zone.get_spawn_points_constraint(except_lot_id=except_lot_id)
constraints_weighted = []
min_score = sims4.math.MAX_FLOAT
for constraint in constraint_set:
spawn_point_vector = constraint.average_position - sim.position
score = sims4.math.vector_dot_2d(pick_vector, spawn_point_vector)
if score < min_score:
min_score = score
constraints_weighted.append((score, constraint))
constraints_weighted = [(score - min_score, constraint) for (score, constraint) in constraints_weighted]
constraints_weighted = sorted(constraints_weighted, key=lambda i: i[0])
first_constraint = constraints_weighted[-1][1]
del constraints_weighted[-1]
first_constraint_circle = Circle(first_constraint.average_position, cls.CONSTRAINT_RADIUS, routing_surface=first_constraint.routing_surface)
jog_waypoint_constraints.append(first_constraint_circle)
last_waypoint_position = first_constraint.average_position
for _ in range(cls.NUM_JOG_POINTS - 1):
constraints_weighted_next = []
for (_, constraint) in constraints_weighted:
average_position = constraint.average_position
distance_last = (average_position - last_waypoint_position).magnitude_2d()
distance_home = (average_position - origin_position).magnitude_2d()
constraints_weighted_next.append((distance_last + distance_home, constraint))
next_constraint = pop_weighted(constraints_weighted_next)
next_constraint_circle = Circle(next_constraint.average_position, cls.CONSTRAINT_RADIUS, routing_surface=next_constraint.routing_surface)
jog_waypoint_constraints.append(next_constraint_circle)
constraints_weighted = constraints_weighted_next
last_waypoint_position = next_constraint.average_position
jog_waypoint_constraints.append(interaction_constraint)
return (interaction_constraint, jog_waypoint_constraints)
示例12: cancel_service
def cancel_service(service_npc_type, max_duration:int=240, _connection=None):
service_npc_tuning = services.service_npc_manager().get(service_npc_type)
if service_npc_tuning is not None:
tgt_client = services.client_manager().get(_connection)
if tgt_client is None:
return False
household = tgt_client.household
services.current_zone().service_npc_service.cancel_service(household, service_npc_tuning)
return True
return False
示例13: stop
def stop(self):
if self._alarm_handle is not None:
cancel_alarm(self._alarm_handle)
self._alarm_handle = None
if self._processing_task is not None:
self._processing_task.stop()
self._processing_task = None
object_manager = services.object_manager()
object_manager.unregister_callback(CallbackTypes.ON_OBJECT_LOCATION_CHANGED, self._update_object_cache)
object_manager.unregister_callback(CallbackTypes.ON_OBJECT_ADD, self._update_object_cache)
services.current_zone().wall_contour_update_callbacks.remove(self._update_object_cache)
示例14: create_situation_for_venue_type
def create_situation_for_venue_type(situation_type, venue_type, opt_sim:OptionalTargetParam=None, _connection=None):
sim = get_optional_target(opt_sim, _connection)
if not services.current_zone().venue_service.has_zone_for_venue_type((venue_type,)):
sims4.commands.output('There are no zones that support the venue type provided, {}.'.format(venue_type), _connection)
return False
situation_manager = services.get_zone_situation_manager()
(zone_id, _) = services.current_zone().venue_service.get_zone_and_venue_type_for_venue_types((venue_type,))
guest_list = SituationGuestList(False, sim.id)
situation_id = situation_manager.create_situation(situation_type, guest_list=guest_list, user_facing=True, zone_id=zone_id)
if situation_id is None:
sims4.commands.output('Insufficient funds to create situation', _connection)
else:
sims4.commands.output('Successfully created situation: {}.'.format(situation_id), _connection)
示例15: c_api_buildbuy_session_begin
def c_api_buildbuy_session_begin(zone_id, account_id):
with sims4.zone_utils.global_zone_lock(zone_id):
posture_graph_service = services.current_zone().posture_graph_service
posture_graph_service.on_enter_buildbuy()
services.current_zone().on_build_buy_enter()
indexed_manager.IndexedManager.add_gc_collect_disable_reason(
BUILD_BUY_OBJECT_LEAK_DISABLED)
resource_keys = []
current_zone = services.current_zone()
household = current_zone.get_active_lot_owner_household()
if household is not None:
for unlock in household.build_buy_unlocks:
resource_keys.append(unlock)
update_gameplay_unlocked_products(resource_keys, zone_id, account_id)
return True