private bool isPropRestorable(PropDefinition def) { bool result = true; if (def.PropType == PropDefinition.PropTypes.PartyGame) { result = false; } return(result); }
public void LocalPlayerRetrieveProp(string propId) { if (LocalPlayerPropUser == null) { Log.LogError(this, "The local player was asked to retrieve a prop before the spawn event was raised"); } else if (LocalPlayerPropUser.gameObject == null || LocalPlayerPropUser.gameObject.Equals(null)) { Log.LogError(this, "The local player game object is not set"); } else { if (dataEntityCollection.LocalPlayerSessionId == 0) { return; } if (!Props.ContainsKey(propId)) { throw new InvalidOperationException("There is no prop definition for " + propId); } PropDefinition propDefinition = Props[propId]; InvitationalItemExperience componentInChildren = LocalPlayerPropUser.GetComponentInChildren <InvitationalItemExperience>(); if (componentInChildren != null) { PropExperience componentInChildren2 = LocalPlayerPropUser.GetComponentInChildren <PropExperience>(); if (componentInChildren2 != null && componentInChildren2.PropDef != null && componentInChildren2.PropDef.Id.ToString() != propId) { Service.Get <EventDispatcher>().DispatchEvent(new InputEvents.ActionEvent(InputEvents.Actions.Cancel)); } } DHeldObject dHeldObject = new DHeldObject(); dHeldObject.ObjectId = propId; switch (propDefinition.PropType) { case PropDefinition.PropTypes.Consumable: dHeldObject.ObjectType = HeldObjectType.CONSUMABLE; Service.Get <INetworkServicesManager>().ConsumableService.EquipItem(propId); break; case PropDefinition.PropTypes.InteractiveObject: dHeldObject.ObjectType = HeldObjectType.DISPENSABLE; if (LocalPlayerPropUser.GetComponent <LocomotionBroadcaster>() != null) { Service.Get <INetworkServicesManager>().PlayerStateService.EquipDispensable(propDefinition.Id); } break; case PropDefinition.PropTypes.Durable: dHeldObject.ObjectType = HeldObjectType.DURABLE; Service.Get <INetworkServicesManager>().PlayerStateService.EquipDurable(propDefinition.Id); break; } dataEntityCollection.GetComponent <HeldObjectsData>(dataEntityCollection.LocalPlayerHandle).HeldObject = dHeldObject; } }
private bool usePropOnActionEvent(InputEvents.ActionEvent evt) { if (evt.Action != InputEvents.Actions.Interact || !IsLocalUserUsingProp() || CanActionsBeUsedWithProp()) { return(false); } if (!userIdToPropUser.TryGetValue(dataEntityCollection.LocalPlayerSessionId, out var value)) { return(false); } string propId = value.Prop.PropId; if (!Props.ContainsKey(propId)) { return(false); } PropDefinition propDefinition = Props[propId]; PropUser propUser = userIdToPropUser[dataEntityCollection.LocalPlayerSessionId]; Vector3 propDestination = getPropDestination(propUser); if (propDefinition.ServerAddedItem) { onPropUsed(dataEntityCollection.LocalPlayerSessionId, propId, dataEntityCollection.LocalPlayerSessionId.ToString(), propDestination); GameObject playerObject = getPlayerObject(dataEntityCollection.LocalPlayerSessionId); LocomotionEventBroadcaster component = playerObject.GetComponent <LocomotionEventBroadcaster>(); if (component != null) { component.BroadcastOnInteractionStarted(playerObject); } } else if (propDefinition.ExperienceType == PropDefinition.ConsumableExperience.OneShot) { onPropUsed(dataEntityCollection.LocalPlayerSessionId, propId, dataEntityCollection.LocalPlayerSessionId.ToString(), propDestination); } if (propDefinition.PropType == PropDefinition.PropTypes.Consumable && !propDefinition.ServerAddedItem) { if (propDefinition.QuestOnly && !Service.Get <QuestService>().OnPrototypeQuest) { Service.Get <INetworkServicesManager>().ConsumableService.ReuseConsumable(value.Prop.PropId, propDestination); } else if (value.Prop != null && !value.Prop.IsUseCompleted) { dataEntityCollection.GetComponent <ConsumableInventoryData>(dataEntityCollection.LocalPlayerHandle).UseConsumable(value.Prop.PropId); Service.Get <INetworkServicesManager>().ConsumableService.UseConsumable(value.Prop.PropId, propDestination); value.Prop.IsUseCompleted = true; } } if (propDefinition.PropType != 0 || propDefinition.ExperienceType == PropDefinition.ConsumableExperience.OneShot) { dataEntityCollection.GetComponent <HeldObjectsData>(dataEntityCollection.LocalPlayerHandle).HeldObject = null; } return(false); }
private bool onJumpToPlayer(PlayerCardEvents.JoinPlayer evt) { if (IsLocalUserUsingProp()) { PropDefinition propDefinition = GetPropDefinition(LocalPlayerPropUser.Prop.PropId); PropDefinition.PropTypes propType = propDefinition.PropType; if (propType == PropDefinition.PropTypes.InteractiveObject) { LocalPlayerStoreProp(); } } return(false); }
private void onPlayerPropRetrieved(string propId, PrefabContentKey propContentKey, long playerId) { if (!userIdToPropUser.TryGetValue(playerId, out var value)) { return; } if (value.Prop != null && !value.Prop.IsUseCompleted) { PropDefinition propDefinition = GetPropDefinition(value.Prop.PropId); if (propDefinition != null && propDefinition.PropAssetContentKey.Key == propContentKey.Key) { return; } new StorePropCMD(value, destroyInstance: true).Execute(); } new RetrievePropCMD(propId, propContentKey, value, playerId, dataEntityCollection.IsLocalPlayer(playerId)).Execute(); }
public PropService(EventDispatcher eventDispatcher, Manifest manifest) { ScriptableObject[] assets = manifest.Assets; foreach (ScriptableObject scriptableObject in assets) { PropDefinition propDefinition = (PropDefinition)scriptableObject; Props.Add(propDefinition.GetNameOnServer(), propDefinition); PropsById.Add(propDefinition.Id, propDefinition); } eventDispatcher.AddListener <PlayerSpawnedEvents.LocalPlayerSpawned>(onLocalPlayerSpawned); eventDispatcher.AddListener <PlayerSpawnedEvents.RemotePlayerSpawned>(onRemotePlayerSpawned); eventDispatcher.AddListener <ConsumableServiceEvents.ConsumableUsed>(onConsumableUsed); eventDispatcher.AddListener <ConsumableServiceEvents.ConsumableMMODeployed>(onConsumableMMODeployed); eventDispatcher.AddListener <ZoneTransitionEvents.ZoneTransition>(onZoneTransition); eventDispatcher.AddListener <InputEvents.ActionEvent>(filterUsePropOnActionEvent); eventDispatcher.AddListener <PlayerCardEvents.JoinPlayer>(onJumpToPlayer); eventDispatcher.AddListener <SessionEvents.SessionPausedEvent>(onSessionPaused, EventDispatcher.Priority.HIGH); dataEntityCollection = Service.Get <CPDataEntityCollection>(); dataEntityCollection.EventDispatcher.AddListener <DataEntityEvents.ComponentAddedEvent <ServerObjectItemData> >(onServerObjectItemAdded); dataEntityCollection.EventDispatcher.AddListener <DataEntityEvents.ComponentRemovedEvent>(onItemRemoved); }
public PropDefinition GetPropDefinition(string idOrName) { PropDefinition propDefinition = null; if (Props.ContainsKey(idOrName)) { propDefinition = Props[idOrName]; } else { int result = 0; if (int.TryParse(idOrName, out result) && PropsById.ContainsKey(result)) { propDefinition = PropsById[result]; } } if (propDefinition == null) { throw new InvalidOperationException("There is no prop definition for " + idOrName); } return(propDefinition); }