private void valueChanged(AirBubble value) { if (this.AirBubbleChanged != null) { this.AirBubbleChanged(value); } }
private void Start() { dispatcher = Service.Get <EventDispatcher>(); dataEntityCollection = Service.Get <CPDataEntityCollection>(); determineIfLocalPlayer(); if (isLocalPlayer) { DataEntityHandle localPlayerHandle = dataEntityCollection.LocalPlayerHandle; if (dataEntityCollection.TryGetComponent <AirBubbleData>(localPlayerHandle, out localPlayerAirBubbleData)) { AirSupply = localPlayerAirBubbleData.AirBubble.value; } else { localPlayerAirBubbleData = dataEntityCollection.AddComponent <AirBubbleData>(localPlayerHandle); AirBubble airBubble = new AirBubble(); airBubble.value = 10f; localPlayerAirBubbleData.AirBubble = airBubble; } if (isLocalPenguinSpawned()) { initializeDiving(); } else { dispatcher.AddListener <PlayerSpawnedEvents.LocalPlayerSpawned>(onLocalPlayerSpawned); } } else { initializeDiving(); } }
public static AirBubble FromSFSData(ISFSObject obj) { AirBubble airBubble = new AirBubble(); airBubble.time = obj.GetLong("t"); airBubble.value = obj.GetFloat("v"); airBubble.diveState = obj.GetInt("s"); return(airBubble); }
public void SetAirBubble(float value, int diveState) { AirBubble airBubble = new AirBubble(); airBubble.time = ServerTime; airBubble.value = value; airBubble.diveState = diveState; updateUserVars(new Dictionary <SocketUserVars, object> { { SocketUserVars.AIR_BUBBLE, airBubble.ToSFSObject() } }); }
private void OnRemotePlayerAirBubbleChanged(AirBubble airBubble) { if (airBubble.value > 10f) { airBubble.value = 10f; } if (airBubble.value < 0f) { airBubble.value = 0f; } AirSupply = airBubble.value; DivingState diveState = (DivingState)airBubble.diveState; if (diveState != 0) { State = diveState; } float num = AirSupply / 10f; if (bubble != null) { bubble.transform.localScale = new Vector3(num, num, num); } }
public AirBubbleChanged(long sessionId, AirBubble airBubble) { SessionId = sessionId; AirBubble = airBubble; }
private void broadcastUserVariables(User user, ArrayList changedVars = null) { bool flag = getSessionId(user) == mt.ClubPenguinClient.PlayerSessionId; if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.PROTOTYPE.GetKey())) && user.ContainsVariable(SocketUserVars.PROTOTYPE.GetKey())) { PrototypeState prototypeState = default(PrototypeState); prototypeState.id = getSessionId(user); prototypeState.data = JsonMapper.ToObject(user.GetVariable(SocketUserVars.PROTOTYPE.GetKey()).GetStringValue()); mt.triggerEvent(GameServerEvent.PROTOTYPE_STATE, prototypeState); } if (changedVars == null || changedVars.Contains(SocketUserVars.EQUIPPED_OBJECT.GetKey())) { UserVariable variable = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT.GetKey()); UserVariable variable2 = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT_PROPERTIES.GetKey()); if (variable == null) { if (changedVars != null && changedVars.Contains(SocketUserVars.EQUIPPED_OBJECT_PROPERTIES.GetKey()) && variable2 == null) { mt.triggerEvent(GameServerEvent.SERVER_ITEM_REMOVED, new CPMMOItemId(getSessionId(user), CPMMOItemId.CPMMOItemParent.PLAYER)); } else { mt.triggerEvent(GameServerEvent.HELD_OBJECT_DEQUIPPED, getSessionId(user)); } } else { EquippedObject equippedObject = EquippedObject.FromSFSData(variable.GetSFSObjectValue()); if (variable2 != null) { PlayerHeldItem playerHeldItem = new PlayerHeldItem(); playerHeldItem.Id = new CPMMOItemId(getSessionId(user), CPMMOItemId.CPMMOItemParent.PLAYER); playerHeldItem.CreatorId = playerHeldItem.Id.Id; playerHeldItem.Type = equippedObject.EquippedObjectId; playerHeldItem.Properties = variable2.GetStringValue(); mt.triggerEvent(GameServerEvent.SERVER_ITEM_ADDED, playerHeldItem); } else if (!flag || (flag && equippedObject.isPartyGame())) { HeldObjectEvent heldObjectEvent = default(HeldObjectEvent); heldObjectEvent.SessionId = getSessionId(user); heldObjectEvent.Type = equippedObject.EquippedObjectId; if (equippedObject.IsConsumable()) { mt.triggerEvent(GameServerEvent.CONSUMABLE_EQUIPPED, heldObjectEvent); } else if (equippedObject.IsDispensable()) { mt.triggerEvent(GameServerEvent.DISPENSABLE_EQUIPPED, heldObjectEvent); } else if (equippedObject.IsDurable()) { mt.triggerEvent(GameServerEvent.DURABLE_EQUIPPED, heldObjectEvent); } else if (equippedObject.isPartyGame()) { mt.triggerEvent(GameServerEvent.PARTYGAME_EQUIPPED, heldObjectEvent); } } } } else if (changedVars.Contains(SocketUserVars.EQUIPPED_OBJECT_PROPERTIES.GetKey())) { UserVariable variable3 = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT.GetKey()); if (variable3 != null && variable3.Type == VariableType.OBJECT) { PlayerHeldItem playerHeldItem = new PlayerHeldItem(); playerHeldItem.Id = new CPMMOItemId(getSessionId(user), CPMMOItemId.CPMMOItemParent.PLAYER); playerHeldItem.CreatorId = playerHeldItem.Id.Id; playerHeldItem.Type = EquippedObject.FromSFSData(variable3.GetSFSObjectValue()).EquippedObjectId; playerHeldItem.Properties = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT_PROPERTIES.GetKey()).GetStringValue(); mt.triggerEvent(GameServerEvent.SERVER_ITEM_CHANGED, playerHeldItem); } } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.LOCOMOTION_STATE.GetKey()))) { UserVariable variable4 = user.GetVariable(SocketUserVars.LOCOMOTION_STATE.GetKey()); PlayerLocomotionStateEvent playerLocomotionStateEvent = default(PlayerLocomotionStateEvent); playerLocomotionStateEvent.SessionId = getSessionId(user); if (variable4 == null || variable4.IsNull()) { playerLocomotionStateEvent.State = LocomotionState.Default; } else { playerLocomotionStateEvent.State = (LocomotionState)variable4.GetIntValue(); } mt.triggerEvent(GameServerEvent.USER_LOCO_STATE_CHANGED, playerLocomotionStateEvent); } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.OUTFIT.GetKey())) && user.ContainsVariable(SocketUserVars.OUTFIT.GetKey())) { PlayerOutfitDetails playerOutfitDetails = mt.JsonService.Deserialize <PlayerOutfitDetails>(user.GetVariable(SocketUserVars.OUTFIT.GetKey()).GetStringValue()); playerOutfitDetails.sessionId = getSessionId(user); mt.triggerEvent(GameServerEvent.USER_OUTFIT_CHANGED, playerOutfitDetails); } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.PROFILE.GetKey())) && user.ContainsVariable(SocketUserVars.PROFILE.GetKey())) { ProfileEvent profileEvent = default(ProfileEvent); profileEvent.SessionId = getSessionId(user); profileEvent.Profile = new Profile(); profileEvent.Profile.colour = user.GetVariable(SocketUserVars.PROFILE.GetKey()).GetIntValue(); mt.triggerEvent(GameServerEvent.USER_PROFILE_CHANGED, profileEvent); } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.AIR_BUBBLE.GetKey()))) { UserVariable variable5 = user.GetVariable(SocketUserVars.AIR_BUBBLE.GetKey()); PlayerAirBubbleEvent playerAirBubbleEvent = default(PlayerAirBubbleEvent); playerAirBubbleEvent.SessionId = getSessionId(user); if (variable5 == null || variable5.IsNull()) { playerAirBubbleEvent.AirBubble = new AirBubble(); } else { playerAirBubbleEvent.AirBubble = AirBubble.FromSFSData(variable5.GetSFSObjectValue()); } mt.triggerEvent(GameServerEvent.AIR_BUBBLE_UPDATE, playerAirBubbleEvent); } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.ON_QUEST.GetKey()))) { UserVariable variable4 = user.GetVariable(SocketUserVars.ON_QUEST.GetKey()); OnQuestState onQuestState = default(OnQuestState); onQuestState.SessionId = getSessionId(user); if (!(variable4?.IsNull() ?? true)) { onQuestState.MascotName = variable4.GetStringValue(); } mt.triggerEvent(GameServerEvent.ON_QUEST, onQuestState); } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.SELECTED_TUBE.GetKey())) && user.ContainsVariable(SocketUserVars.SELECTED_TUBE.GetKey())) { SelectedTubeEvent selectedTubeEvent = default(SelectedTubeEvent); selectedTubeEvent.SessionId = getSessionId(user); selectedTubeEvent.TubeId = user.GetVariable(SocketUserVars.SELECTED_TUBE.GetKey()).GetIntValue(); mt.triggerEvent(GameServerEvent.SELECTED_TUBE_CHANGED, selectedTubeEvent); } if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.TEMPORARY_HEAD_STATUS.GetKey())) && user.ContainsVariable(SocketUserVars.TEMPORARY_HEAD_STATUS.GetKey())) { TemporaryHeadStatusEvent temporaryHeadStatusEvent = default(TemporaryHeadStatusEvent); temporaryHeadStatusEvent.SessionId = getSessionId(user); temporaryHeadStatusEvent.Type = user.GetVariable(SocketUserVars.TEMPORARY_HEAD_STATUS.GetKey()).GetIntValue(); mt.triggerEvent(GameServerEvent.TEMPORARY_HEAD_STATUS_CHANGED, temporaryHeadStatusEvent); } if (flag || (changedVars != null && !changedVars.Contains(SocketUserVars.AWAY_FROM_KEYBOARD.GetKey()))) { return; } UserVariable variable6 = user.GetVariable(SocketUserVars.AWAY_FROM_KEYBOARD.GetKey()); if (variable6 == null || variable6.IsNull()) { EquippedObject equippedObject2 = null; UserVariable variable7 = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT.GetKey()); if (variable7 != null) { equippedObject2 = EquippedObject.FromSFSData(variable7.GetSFSObjectValue()); } mt.triggerEvent(GameServerEvent.AWAY_FROM_KEYBOARD_STATE_CHANGED, new AFKEvent(getSessionId(user), 0, equippedObject2)); } else { mt.triggerEvent(GameServerEvent.AWAY_FROM_KEYBOARD_STATE_CHANGED, new AFKEvent(getSessionId(user), variable6.GetIntValue(), null)); } }