Beispiel #1
0
        private bool onLocalPlayerSpawned(PlayerSpawnedEvents.LocalPlayerSpawned evt)
        {
            if (LocalPlayerPropUser == null)
            {
                LocalPlayerPropUser = evt.LocalPlayerGameObject.GetComponent <PropUser>();
            }
            SessionIdData component = dataEntityCollection.GetComponent <SessionIdData>(evt.Handle);

            if (component != null)
            {
                userIdToPropUser[component.SessionId] = LocalPlayerPropUser;
                DHeldObject heldObject = dataEntityCollection.GetComponent <HeldObjectsData>(dataEntityCollection.LocalPlayerHandle).HeldObject;
                if (heldObject != null && heldObject.ObjectId != null)
                {
                    onPlayerPropRetrieved(heldObject.ObjectId, GetPropDefinition(heldObject.ObjectId).PropAssetContentKey, component.SessionId);
                }
                loadExistingPlayerHeldExperiences(component.SessionId);
                loadExistingWorldExperiences();
                if (dataEntityCollection.TryGetComponent <PropToBeRestoredData>(evt.Handle, out var component2))
                {
                    LocalPlayerRetrieveProp(component2.PropId);
                    dataEntityCollection.RemoveComponent <PropToBeRestoredData>(evt.Handle);
                }
            }
            return(false);
        }
        private void Start()
        {
            button               = GetComponentInParent <Button>();
            inputButton          = button.GetComponent <InputButton>();
            trayInputButton      = button.GetComponent <TrayInputButton>();
            interactButtonToggle = GetComponent <InteractButtonToggle>();
            tooltipButton        = button.gameObject.AddComponent <TooltipInputButton>();
            PropUser component = SceneRefs.ZoneLocalPlayerManager.LocalPlayerGameObject.GetComponent <PropUser>();
            Prop     prop      = component.Prop;

            if (prop != null)
            {
                propValidator = prop.GetComponent <PropValidateDeployLocation>();
                if (propValidator != null)
                {
                    validator = propValidator.GetValidator();
                    if (validator == null)
                    {
                        propValidator.OnValidatorSpawned += onValidatorSpawned;
                    }
                    else
                    {
                        onValidPositionChanged(validator.IsValidPosition);
                        validator.OnValidPositionChanged += onValidPositionChanged;
                    }
                }
            }
            Content.LoadAsync(onTooltipLoaded, TooltipPrefab);
        }
        private IEnumerator Start()
        {
            dispatcher = Service.Get <EventDispatcher>();
            propUser   = GetComponentInParent <PropUser>();
            GameObject localPlayer = SceneRefs.ZoneLocalPlayerManager.LocalPlayerGameObject;

            isLocalPlayer = localPlayer == propUser.gameObject;
            yield return(null);

            if (isLocalPlayer)
            {
                switch (Trigger)
                {
                case DisableTrigger.Start:
                    disableControls();
                    break;

                case DisableTrigger.Use:
                    addListenerToPropUse();
                    break;
                }
            }
            else
            {
                Object.Destroy(this);
            }
        }
Beispiel #4
0
 public UsePropCMD(PropUser propUser, Vector3 destination, bool destroyInstanceOnRemove, string experienceInstanceId, System.Action onCompleteHandler = null)
 {
     this.propUser                = propUser;
     this.destination             = destination;
     this.destroyInstanceOnRemove = destroyInstanceOnRemove;
     this.experienceInstanceId    = experienceInstanceId;
     this.onCompleteHandler       = onCompleteHandler;
 }
Beispiel #5
0
 public void Start()
 {
     if (!SceneRefs.ZoneLocalPlayerManager.LocalPlayerGameObject.IsDestroyed())
     {
         propUser = SceneRefs.ZoneLocalPlayerManager.LocalPlayerGameObject.GetComponent <PropUser>();
         propUser.EPropRemoved += onPropRemoved;
     }
 }
 public RetrievePropCMD(string propId, PrefabContentKey propContentKey, PropUser propUser, long ownerId, bool isOwnerLocalPlayer, Action <Prop> onPropInstantiatedHandler = null, System.Action onCompleteHandler = null)
 {
     this.propId                    = propId;
     this.propContentKey            = propContentKey;
     this.propUser                  = propUser;
     this.ownerId                   = ownerId;
     this.isOwnerLocalPlayer        = isOwnerLocalPlayer;
     this.onPropInstantiatedHandler = onPropInstantiatedHandler;
     this.onCompleteHandler         = onCompleteHandler;
     avatarView = propUser.GetComponent <AvatarView>();
 }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        private Vector3 getPropDestination(PropUser propUser)
        {
            Vector3 vector = propUser.transform.position + propUser.transform.forward * propUser.Prop.MaxDistanceFromUser;

            if (propUser.Prop.CheckCollisions)
            {
                Vector3 midPoint = propUser.transform.position + (vector - propUser.transform.position) * 0.5f;
                midPoint.y = propUser.transform.position.y + 1f;
                Vector3 groundFromArc = GroundFinder.GetGroundFromArc(propUser.transform.position, midPoint, vector);
                return(GroundFinder.GetGround(groundFromArc));
            }
            return(vector);
        }
Beispiel #9
0
        private bool onServerObjectItemAdded(DataEntityEvents.ComponentAddedEvent <ServerObjectItemData> evt)
        {
            Vector3 zero = Vector3.zero;

            if (evt.Component.Item.Id.Parent == CPMMOItemId.CPMMOItemParent.WORLD)
            {
                if (evt.Component.Item is ConsumableItem)
                {
                    new ServerObjectTracker(this, evt.Handle, evt.Component);
                }
                if (userIdToPropUser.ContainsKey(evt.Component.Item.CreatorId))
                {
                    PropUser propUser = userIdToPropUser[evt.Component.Item.CreatorId];
                    if (propUser.PendingExperienceId == evt.Component.Item.Id.Id)
                    {
                        propUser.PendingExperienceId = -1L;
                    }
                }
            }
            PlayerHeldItem playerHeldItem = evt.Component.Item as PlayerHeldItem;

            if (playerHeldItem != null)
            {
                string type = playerHeldItem.Type;
                if (!Props.ContainsKey(type))
                {
                    throw new InvalidOperationException("There is no prop definition for " + type);
                }
                if (Props[type].ServerAddedItem)
                {
                    DHeldObject dHeldObject = new DHeldObject();
                    dHeldObject.ObjectId = type;
                    DataEntityHandle dataEntityHandle = ((!dataEntityCollection.IsLocalPlayer(evt.Component.Item.CreatorId)) ? dataEntityCollection.FindEntity <SessionIdData, long>(evt.Component.Item.CreatorId) : dataEntityCollection.LocalPlayerHandle);
                    if (!dataEntityHandle.IsNull)
                    {
                        dataEntityCollection.GetComponent <HeldObjectsData>(dataEntityHandle).HeldObject = dHeldObject;
                        evt.Component.ItemChanged += onCPMMOItemChanged;
                    }
                }
                else
                {
                    onPropUsed(evt.Component.Item.CreatorId, playerHeldItem.Type, evt.Component.Item.Id.Id.ToString(), zero);
                }
            }
            return(false);
        }
Beispiel #10
0
 private bool onRemotePlayerSpawned(PlayerSpawnedEvents.RemotePlayerSpawned evt)
 {
     if (!evt.Handle.IsNull)
     {
         PropUser value = evt.RemotePlayerGameObject.AddComponent <PropUser>();
         userIdToPropUser[dataEntityCollection.GetComponent <SessionIdData>(evt.Handle).SessionId] = value;
         RemotePlayerData component = dataEntityCollection.GetComponent <RemotePlayerData>(evt.Handle);
         if (component != null)
         {
             loadExistingPlayerHeldExperiences(dataEntityCollection.GetComponent <SessionIdData>(evt.Handle).SessionId);
             component.PlayerRemoved += onPlayerRemoved;
         }
         else
         {
             Log.LogError(this, "Failed to get the remote player data once it was spawned");
         }
     }
     return(false);
 }
Beispiel #11
0
        public IEnumerator Start()
        {
            GameObject localPlayer = SceneRefs.ZoneLocalPlayerManager.LocalPlayerGameObject;
            PropUser   propUser    = GetComponentInParent <PropUser>();

            if (propUser.gameObject != localPlayer)
            {
                UnityEngine.Object.Destroy(this);
                yield break;
            }
            AssetRequest <GameObject> request = Content.LoadAsync(ValidatorContentKey);

            yield return(request);

            validator = UnityEngine.Object.Instantiate(request.Asset).GetComponent <PropSpawnLocationValidator>();
            if (this.OnValidatorSpawned != null)
            {
                this.OnValidatorSpawned(validator);
            }
        }
Beispiel #12
0
 public StorePropCMD(PropUser propUser, bool destroyInstance, Action <bool> onCompleteHandler = null)
 {
     this.propUser          = propUser;
     this.destroyInstance   = destroyInstance;
     this.onCompleteHandler = onCompleteHandler;
 }