public bool AreAllPlayersSleeping() { int quantitySleeping = 0; int quantityAwake = 0; foreach (IPlayer player in sapi.World.AllOnlinePlayers) { IServerPlayer splr = player as IServerPlayer; if (splr.ConnectionState != EnumClientState.Playing || splr.WorldData.CurrentGameMode == EnumGameMode.Spectator) { continue; } IMountable mount = player.Entity?.MountedOn; if (mount != null && mount is BlockEntityBed) { quantitySleeping++; } else { quantityAwake++; } } return(quantitySleeping > 0 && quantityAwake == 0); }
public void WakeAllPlayers() { GameSpeedBoost = 0; api.World.Calendar.SetTimeSpeedModifier("sleeping", (int)GameSpeedBoost); if (api.Side == EnumAppSide.Client) { capi.World.Player?.Entity.TryUnmount(); AllSleeping = false; return; } foreach (IPlayer player in sapi.World.AllOnlinePlayers) { IServerPlayer splr = player as IServerPlayer; if (splr.ConnectionState != EnumClientState.Playing || splr.WorldData.CurrentGameMode == EnumGameMode.Spectator) { continue; } IMountable mount = player.Entity?.MountedOn; if (mount != null && mount is BlockEntityBed) { player.Entity.TryUnmount(); } } AllSleeping = false; }
public static void Register(FrameworkElement element, IMountable mountable) { if (!(element?.DataContext is IMountable)) { throw new InvalidOperationException("The DataContext of the given element must inherit from IMountable"); } element.Loaded += (sender, args) => mountable.MountView(); element.Unloaded += (sender, args) => mountable.UnmountView(); }
/// <summary> /// Attempts to mount the player on a target. /// </summary> /// <param name="onmount">The mount to mount</param> /// <returns>Whether it was mounted or not.</returns> public bool TryMount(IMountable onmount) { this.MountedOn = onmount; controls.StopAllMovement(); if (MountedOn?.SuggestedAnimation != null) { string anim = MountedOn.SuggestedAnimation.ToLowerInvariant(); AnimManager?.StartAnimation(anim); } onmount.DidMount(this); return(true); }
/// <summary> /// Attempts to mount the player on a target. /// </summary> /// <param name="onmount">The mount to mount</param> /// <returns>Whether it was mounted or not.</returns> public bool TryMount(IMountable onmount) { if (MountedOn != onmount) { if (!TryUnmount()) { return(false); } } TreeAttribute mountableTree = new TreeAttribute(); onmount?.MountableToTreeAttributes(mountableTree); WatchedAttributes["mountedOn"] = mountableTree; WatchedAttributes.MarkPathDirty("mountedOn"); // -> this calls updateMountedState() return(true); }
/// <summary> /// Removes mountable from the list of objects attached to the current mount, and adds to the list of the new mount. /// </summary> /// <param name="newMount"></param> public static void ChangeMounting(IMountable mountable, Mount prevMount, Mount newMount) { //Debug.Log("Change Mounting " + (prevMount ? prevMount.photonView.OwnerActorNr.ToString() : "null") + " -> " + (newMount ? newMount.photonView.OwnerActorNr.ToString() : "null")); if (!ReferenceEquals(prevMount, null)) { prevMount.mountedObjs.Remove(mountable); } if (!ReferenceEquals(newMount, null)) { var mountedObjs = newMount.mountedObjs; if (!mountedObjs.Contains(mountable)) { mountedObjs.Add(mountable); } } }
/// <summary> /// Removes mountable from the list of objects attached to the current mount, and adds to the list of the new mount. /// </summary> /// <param name="newmount"></param> public static void ChangeMounting(IMountable mountable, Mount newmount) { var currentMount = mountable.CurrentMount; if (!ReferenceEquals(currentMount, null)) { currentMount.mountedObjs.Remove(mountable); } if (!ReferenceEquals(newmount, null)) { var mountedObjs = newmount.mountedObjs; if (!mountedObjs.Contains(mountable)) { mountedObjs.Add(mountable); } } }