public ScavengerHuntData(int sessionId, long localPlayerSessionId, long otherPlayerSessionId, int totalMarbleCount, RewardDefinition winRewardDefinition, RewardDefinition loseRewardDefinition)
    {
        GameSessionId        = sessionId;
        LocalPlayerSessionId = localPlayerSessionId;
        OtherPlayerSessionId = otherPlayerSessionId;
        TotalMarbleCount     = totalMarbleCount;
        WinRewardDefinition  = winRewardDefinition;
        LoseRewardDefinition = loseRewardDefinition;
        CPDataEntityCollection cPDataEntityCollection = Service.Get <CPDataEntityCollection>();
        DataEntityHandle       handle  = cPDataEntityCollection.FindEntity <SessionIdData, long>(otherPlayerSessionId);
        DataEntityHandle       handle2 = cPDataEntityCollection.FindEntity <SessionIdData, long>(localPlayerSessionId);

        if (cPDataEntityCollection.TryGetComponent(handle2, out DisplayNameData component))
        {
            LocalPlayerName = component.DisplayName;
        }
        if (cPDataEntityCollection.TryGetComponent(handle, out DisplayNameData component2))
        {
            OtherPlayerName = component2.DisplayName;
        }
        if (cPDataEntityCollection.TryGetComponent(handle2, out PresenceData component3))
        {
            string zoneToken = Service.Get <ZoneTransitionService>().GetZone(component3.Room).ZoneToken;
            RoomName = Service.Get <Localizer>().GetTokenTranslation(zoneToken);
        }
        GameObject localPlayerGameObject = ClubPenguin.SceneRefs.ZoneLocalPlayerManager.LocalPlayerGameObject;

        localPlayerAnimator = localPlayerGameObject.GetComponent <Animator>();
        if (cPDataEntityCollection.TryGetComponent(handle, out GameObjectReferenceData component4))
        {
            otherPlayerAnimator = component4.GameObject.GetComponent <Animator>();
        }
    }
Example #2
0
        private bool onConsumableUsed(ConsumableServiceEvents.ConsumableUsed evt)
        {
            DataEntityHandle dataEntityHandle = dataEntityCollection.FindEntity <SessionIdData, long>(evt.SessionId);

            if (!dataEntityHandle.IsNull && userIdToPropUser.TryGetValue(evt.SessionId, out var value) && value != null && !value.gameObject.IsDestroyed() && value.Prop != null)
            {
                onPropUsed(evt.SessionId, value.Prop.PropId, evt.Type, getPropDestination(value));
            }
            return(false);
        }
Example #3
0
        private bool onOnlinePlayerSwidListReceived(PlayerStateServiceEvents.OnlinePlayerSwidListReceived evt)
        {
            onlineStatusReceived = true;
            ProfileData component;

            for (int i = 0; i < allPlayersList.Count; i++)
            {
                if (!dataEntityCollection.TryGetComponent <ProfileData>(allPlayersList[i], out component))
                {
                    component = dataEntityCollection.AddComponent <ProfileData>(allPlayersList[i]);
                }
                component.IsOnline = false;
            }
            for (int i = 0; i < evt.Swids.Count; i++)
            {
                DataEntityHandle dataEntityHandle = dataEntityCollection.FindEntity <SwidData, string>(evt.Swids[i]);
                if (!dataEntityHandle.IsNull)
                {
                    if (!dataEntityCollection.TryGetComponent <ProfileData>(dataEntityHandle, out component))
                    {
                        component = dataEntityCollection.AddComponent <ProfileData>(dataEntityHandle);
                    }
                    component.IsOnline = true;
                }
            }
            sortPlayers(visiblePlayersList);
            if (playerItemPrefab != null)
            {
                initializePool();
            }
            return(false);
        }
 private void onExperienceStarted(string instanceId, long ownerId, bool isOwnerLocalPlayer, PropDefinition propDef)
 {
     try
     {
         invitationExperienceInstanceId = instanceId;
         invitingPlayerId        = ownerId;
         isInvitationLocalPlayer = isOwnerLocalPlayer;
         invitingPlayerObject    = getInvitingPlayerObject();
         if (invitingPlayerObject != null)
         {
             invitingPlayerAvatarView = invitingPlayerObject.GetComponent <AvatarView>();
         }
         CPMMOItemId identifier = new CPMMOItemId(long.Parse(invitationExperienceInstanceId), CPMMOItemId.CPMMOItemParent.PLAYER);
         serverObjectHandle = dataEntityCollection.FindEntity <ServerObjectItemData, CPMMOItemId>(identifier);
         if (serverObjectHandle.IsNull)
         {
             onItemRemoved();
             return;
         }
         serverObjectData      = dataEntityCollection.GetComponent <ServerObjectItemData>(serverObjectHandle);
         AvailableItemQuantity = propDef.TotalItemQuantity;
         totalItemQuantity     = propDef.TotalItemQuantity;
         setupNetworkServiceListeners();
         if (isOwnerLocalPlayer)
         {
             GameObject target = dataEntityCollection.GetComponent <GameObjectReferenceData>(dataEntityCollection.LocalPlayerHandle).GameObject;
             InputButtonGroupContentKey inputButtonGroupContentKey = (LocomotionHelper.IsCurrentControllerOfType <SwimController>(target) ? ((!(LocomotionHelper.GetCurrentController(target) as SwimController).IsInShallowWater) ? DivingControlLayout : SwimControlLayout) : ((!LocomotionHelper.IsCurrentControllerOfType <SitController>(target)) ? ControlLayout : ((!(LocomotionHelper.GetCurrentController(target) as SitController).IsUnderwater) ? SitControlLayout : SitSwimControlLayout)));
             if (inputButtonGroupContentKey != null && !string.IsNullOrEmpty(inputButtonGroupContentKey.Key))
             {
                 Service.Get <EventDispatcher>().DispatchEvent(new ControlsScreenEvents.SetRightOption(inputButtonGroupContentKey));
             }
             else
             {
                 Log.LogError(this, "Did not find a valid controls content key for this state");
             }
             ParticipationData component = dataEntityCollection.GetComponent <ParticipationData>(dataEntityCollection.LocalPlayerHandle);
             if (component != null)
             {
                 component.CurrentParticipationState = ParticipationState.Participating;
                 component.IsInteractButtonAvailable = false;
             }
         }
         Service.Get <EventDispatcher>().AddListener <PenguinInteraction.InteractionStartedEvent>(onInteractionStarted);
         if (invitingPlayerAvatarView != null)
         {
             if (invitingPlayerAvatarView.IsReady)
             {
                 onAvatarReady();
             }
             invitingPlayerAvatarView.OnReady += onAvatarViewReady;
         }
         switchToCamera();
     }
     catch (FormatException ex)
     {
         Log.LogException(this, ex);
     }
 }
 private DataEntityHandle findPlayerHandle(long sessionId)
 {
     if (!handles.TryGetValue(sessionId, out var value))
     {
         value = dataEntityCollection.FindEntity <SessionIdData, long>(sessionId);
         handles.Add(sessionId, value);
     }
     return(value);
 }
        private void onItemRemoved()
        {
            CPDataEntityCollection cPDataEntityCollection = Service.Get <CPDataEntityCollection>();
            DHeldObject            dHeldObject            = null;

            if (isInvitationLocalPlayer)
            {
                dHeldObject = cPDataEntityCollection.GetComponent <HeldObjectsData>(cPDataEntityCollection.LocalPlayerHandle).HeldObject;
            }
            else
            {
                DataEntityHandle dataEntityHandle = cPDataEntityCollection.FindEntity <SessionIdData, long>(invitingPlayerId);
                if (!dataEntityHandle.IsNull)
                {
                    dHeldObject = Service.Get <CPDataEntityCollection>().GetComponent <HeldObjectsData>(dataEntityHandle).HeldObject;
                }
            }
            if (dHeldObject != null)
            {
                string         text           = "";
                PlayerHeldItem playerHeldItem = ((serverObjectData == null) ? null : (serverObjectData.Item as PlayerHeldItem));
                if (playerHeldItem != null)
                {
                    text = playerHeldItem.Type;
                }
                if (text == dHeldObject.ObjectId)
                {
                    if (isInvitationLocalPlayer)
                    {
                        cPDataEntityCollection.GetComponent <HeldObjectsData>(cPDataEntityCollection.LocalPlayerHandle).HeldObject = null;
                    }
                    else
                    {
                        DataEntityHandle dataEntityHandle = cPDataEntityCollection.FindEntity <SessionIdData, long>(invitingPlayerId);
                        Service.Get <CPDataEntityCollection>().GetComponent <HeldObjectsData>(dataEntityHandle).HeldObject = null;
                    }
                }
            }
            destroySelf();
        }
    protected Transform getTransform(long sessionId)
    {
        DataEntityHandle dataEntityHandle = dataEntityCollection.FindEntity <SessionIdData, long>(sessionId);

        if (!dataEntityHandle.IsNull)
        {
            GameObjectReferenceData component = dataEntityCollection.GetComponent <GameObjectReferenceData>(dataEntityHandle);
            if (component != null && component.GameObject != null)
            {
                return(component.GameObject.transform);
            }
        }
        return(null);
    }
Example #8
0
        public void SetData(PartyGameSessionMessages.TubeRacePlayerResult data, PartyGameDefinition partyGameDefinition)
        {
            skinForDefinition(partyGameDefinition);
            ScoreText.text = data.OverallScore.ToString();
            CPDataEntityCollection cPDataEntityCollection = Service.Get <CPDataEntityCollection>();
            DataEntityHandle       dataEntityHandle       = cPDataEntityCollection.FindEntity <SessionIdData, long>(data.PlayerId);

            if (!dataEntityHandle.IsNull && cPDataEntityCollection.TryGetComponent <DisplayNameData>(dataEntityHandle, out var component))
            {
                NameText.text = component.DisplayName;
            }
            if (data.PlayerId == cPDataEntityCollection.LocalPlayerSessionId)
            {
                setLocalPlayerData(data);
            }
        }
 public void PlayCelebrationAnimation(List <long> playersToReward)
 {
     foreach (long item in playersToReward)
     {
         DataEntityHandle dataEntityHandle = dataEntityCollection.FindEntity <SessionIdData, long>(item);
         if (dataEntityHandle.IsNull || !dataEntityCollection.TryGetComponent <GameObjectReferenceData>(dataEntityHandle, out var component) || (component?.GameObject.IsDestroyed() ?? true))
         {
             continue;
         }
         PropUser component2 = component.GameObject.GetComponent <PropUser>();
         if (!(component2 != null) || component2.IsAllowedToCelebrate())
         {
             Animator component3 = component.GameObject.GetComponent <Animator>();
             if (component3 != null)
             {
                 component3.Play(AnimationHashes.States.TorsoCelebration, AnimationHashes.Layers.Torso);
             }
         }
     }
 }
        private GameObject getPlayerGameObj(long sessionId = 0L)
        {
            GameObject result = null;

            if (sessionId != 0)
            {
                DataEntityHandle dataEntityHandle = dataEntityCollection.FindEntity <SessionIdData, long>(sessionId);
                if (dataEntityHandle != null)
                {
                    dataEntityCollection.TryGetComponent <GameObjectReferenceData>(dataEntityHandle, out var component);
                    if (component != null)
                    {
                        result = component.GameObject;
                    }
                }
            }
            else
            {
                result = SceneRefs.ZoneLocalPlayerManager.LocalPlayerGameObject;
            }
            return(result);
        }
 private bool onRewardsEarned(RewardServiceEvents.RewardsEarned evt)
 {
     if (evt.RewardedUsers != null && evt.RewardedUsers.source == RewardSource.MINI_GAME && evt.RewardedUsers.sourceId == "Targets")
     {
         List <long> list = new List <long>();
         foreach (KeyValuePair <long, Reward> reward in evt.RewardedUsers.rewards)
         {
             long key = reward.Key;
             list.Add(reward.Key);
             if (!string.IsNullOrEmpty(ParticipationPlayerPrefName) && !isQuestActive())
             {
                 DataEntityHandle dataEntityHandle = dataEntityCollection.FindEntity <SessionIdData, long>(key);
                 if (!dataEntityHandle.IsNull && key == Service.Get <CPDataEntityCollection>().LocalPlayerSessionId)
                 {
                     RewardedForLocalParticipation();
                 }
             }
         }
         SceneRefs.CelebrationRunner.PlayCelebrationAnimation(list);
         UnityEngine.Object.Instantiate(RewardEffectsPrefab, RewardEffectsPosition.position, Quaternion.identity);
     }
     return(false);
 }
        private bool OnTemporaryHeadStatusChanged(PlayerStateServiceEvents.TemporaryHeadStatusChanged evt)
        {
            if (isLocalPlayer(evt.SessionId))
            {
                return(false);
            }
            DataEntityHandle dataEntityHandle = dataEntityCollection.FindEntity <SessionIdData, long>(evt.SessionId);

            if (!dataEntityHandle.IsNull)
            {
                PresenceData component = dataEntityCollection.GetComponent <PresenceData>(dataEntityHandle);
                if (component != null)
                {
                    component.TemporaryHeadStatusType = (TemporaryHeadStatusType)evt.Type;
                }
            }
            return(false);
        }
 private DataEntityHandle findPlayerHandle(long sessionId, CPDataEntityCollection dataEntityCollection)
 {
     return(dataEntityCollection.FindEntity <SessionIdData, long>(sessionId));
 }