Exemple #1
0
            public static bool Interact(Bed __instance, ref bool __result, ref Humanoid human, ref bool repeat)
            {
                if (!modEnabled.Value)
                {
                    return(true);
                }

                // No special logic, so defer to normal execution
                if (!enableMultipleBedfellows.Value && !sleepWithoutSpawnpoint.Value && !sleepAnyTime.Value && !sleepWithoutClaiming.Value)
                {
                    return(true);
                }

                if (repeat)
                {
                    return(false);
                }

                long   playerID  = Game.instance.GetPlayerProfile().GetPlayerID();
                bool   owner     = __instance.GetOwner() != 0L;
                bool   altFunc   = Input.GetKey(ALT_FUNC_KEY);
                Player thePlayer = human as Player;

                // If there is no owner at all
                if (!owner)
                {
                    if (!__instance.CheckExposure(thePlayer))
                    {
                        __result = false;
                        return(false);
                    }

                    if (!altFunc)
                    {
                        __instance.SetOwner(playerID, Game.instance.GetPlayerProfile().GetName());
                        __result = false;
                        return(false);
                    }

                    if (!sleepWithoutSpawnpoint.Value)
                    {
                        Game.instance.GetPlayerProfile().SetCustomSpawnPoint(__instance.GetSpawnPoint());
                        human.Message(MessageHud.MessageType.Center, "$msg_spawnpointset", 0, null);
                    }

                    if (!altFunc && sleepWithoutClaiming.Value && sleepWithoutSpawnpoint.Value)
                    {
                        __result = false;
                        return(false);
                    }
                }

                // If the bed belongs to the current player
                if (__instance.IsMine() || enableMultipleBedfellows.Value)
                {
                    if (__instance.IsCurrent() || sleepWithoutSpawnpoint.Value)
                    {
                        if (!sleepAnyTime.Value && !EnvMan.instance.IsAfternoon() && !EnvMan.instance.IsNight())
                        {
                            human.Message(MessageHud.MessageType.Center, "$msg_cantsleep", 0, null);
                            __result = false;
                            return(false);
                        }
                        if (!__instance.CheckEnemies(thePlayer))
                        {
                            __result = false;
                            return(false);
                        }
                        if (!__instance.CheckExposure(thePlayer))
                        {
                            __result = false;
                            return(false);
                        }
                        if (!__instance.CheckFire(thePlayer))
                        {
                            __result = false;
                            return(false);
                        }
                        if (!__instance.CheckWet(thePlayer))
                        {
                            __result = false;
                            return(false);
                        }

                        human.AttachStart(__instance.m_spawnPoint, human.gameObject, true, true, false, "attach_bed", new Vector3(0f, 0.5f, 0f));
                        __result = false;

                        return(false);
                    }
                    else
                    {
                        if (!__instance.CheckExposure(thePlayer))
                        {
                            __result = false;
                            return(false);
                        }

                        if (!sleepWithoutSpawnpoint.Value)
                        {
                            Game.instance.GetPlayerProfile().SetCustomSpawnPoint(__instance.GetSpawnPoint());
                            human.Message(MessageHud.MessageType.Center, "$msg_spawnpointset", 0, null);
                        }
                    }
                }

                __result = false;
                return(false);
            }