예제 #1
0
            private static void RotateWithWheel(Player __instance)
            {
                var wheel = Input.GetAxis("Mouse ScrollWheel");

                var playerData = PlayersData[__instance];

                if (!wheel.Equals(0f) || ZInput.GetButton("JoyRotate"))
                {
                    if (Input.GetKey(Configuration.Current.FreePlacementRotation.rotateY))
                    {
                        playerData.PlaceRotation  += Vector3.up * Mathf.Sign(wheel);
                        __instance.m_placeRotation = (int)(playerData.PlaceRotation.y / 22.5f);
                    }
                    else if (Input.GetKey(Configuration.Current.FreePlacementRotation.rotateX))
                    {
                        playerData.PlaceRotation += Vector3.right * Mathf.Sign(wheel);
                    }
                    else if (Input.GetKey(Configuration.Current.FreePlacementRotation.rotateZ))
                    {
                        playerData.PlaceRotation += Vector3.forward * Mathf.Sign(wheel);
                    }
                    else
                    {
                        __instance.m_placeRotation = ClampPlaceRotation(__instance.m_placeRotation);
                        playerData.PlaceRotation   = new Vector3(0, __instance.m_placeRotation * 22.5f, 0);
                    }

                    playerData.PlaceRotation = ClampAngles(playerData.PlaceRotation);

                    Debug.Log("Angle " + playerData.PlaceRotation);
                }
            }
예제 #2
0
            static void Prefix(Player __instance, float ___m_lastToolUseTime, ref float ___m_placePressedTime)
            {
                __instance.m_placeDelay = placeDelay;

                if (!modEnabled.Value)
                {
                    return;
                }

                string rightItem = __instance.GetRightItem()?.m_shared.m_name;

                if (rightItem == "$item_hammer")
                {
                    if (!repeatBuildPlace.Value)
                    {
                        return;
                    }
                    __instance.m_placeDelay = repeatBuildPlaceDelay.Value;
                }
                else if (rightItem == "$item_hoe")
                {
                    if (!repeatTerrainMod.Value)
                    {
                        return;
                    }
                    __instance.m_placeDelay = repeatTerrainModDelay.Value;
                }
                else if (rightItem == "$item_cultivator")
                {
                    if (!repeatPlanting.Value)
                    {
                        return;
                    }
                    __instance.m_placeDelay = repeatPlantingDelay.Value;
                }

                if (!wasSelecting && (ZInput.GetButton("Attack") || ZInput.GetButton("JoyPlace")) && Time.time - ___m_lastToolUseTime > __instance.m_placeDelay)
                {
                    if (InventoryGui.IsVisible() || Minimap.IsOpen() || StoreGui.IsVisible() || Hud.IsPieceSelectionVisible())
                    {
                        wasSelecting = true;
                    }
                    else
                    {
                        ___m_placePressedTime = Time.time;
                    }
                }
                else if (wasSelecting && !ZInput.GetButton("Attack") && !ZInput.GetButton("JoyPlace"))
                {
                    wasSelecting = false;
                }
            }
예제 #3
0
 public static void Prefix(Character __instance, ref Vector3 ___m_moveDir)
 {
     if (__instance is Player player && (bool)typeof(Player).GetMethod("TakeInput", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(player, null))
     {
         if (ZInput.GetButton("Jump"))
         {
             ___m_moveDir += Vector3.up;
         }
         else if (ZInput.GetButton("Crouch") || ZInput.GetButton("JoyCrouch"))
         {
             ___m_moveDir -= Vector3.up;
         }
     }
 }
예제 #4
0
 static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemDrop.ItemData item, int ___m_dragAmount)
 {
     if (ZInput.GetButton("JoyLTrigger") || CheckModKey(modKey.Value))
     {
         if (item != null && item.m_stack > 1 && Player.m_localPlayer)
         {
             int amount = ___m_dragAmount > 0 ? (item.m_stack - ___m_dragAmount) / 2 + ___m_dragAmount : item.m_stack / 2;
             //Dbgl($"auto stacking: {amount}/{ item.m_stack } {item?.m_shared.m_name}");
             __instance.GetType().GetMethod("SetupDragItem", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { item, grid.GetInventory(), amount });
             autoSplitting = true;
         }
         return(false);
     }
     return(true);
 }
예제 #5
0
 // Token: 0x0600052B RID: 1323 RVA: 0x0002B598 File Offset: 0x00029798
 private void UpdateGamepad()
 {
     if (!this.m_uiGroup.IsActive())
     {
         return;
     }
     if (ZInput.GetButtonDown("JoyDPadLeft") || ZInput.GetButtonDown("JoyLStickLeft"))
     {
         this.m_selected.x = Mathf.Max(0, this.m_selected.x - 1);
     }
     if (ZInput.GetButtonDown("JoyDPadRight") || ZInput.GetButtonDown("JoyLStickRight"))
     {
         this.m_selected.x = Mathf.Min(this.m_width - 1, this.m_selected.x + 1);
     }
     if (ZInput.GetButtonDown("JoyDPadUp") || ZInput.GetButtonDown("JoyLStickUp"))
     {
         this.m_selected.y = Mathf.Max(0, this.m_selected.y - 1);
     }
     if (ZInput.GetButtonDown("JoyDPadDown") || ZInput.GetButtonDown("JoyLStickDown"))
     {
         this.m_selected.y = Mathf.Min(this.m_width - 1, this.m_selected.y + 1);
     }
     if (ZInput.GetButtonDown("JoyButtonA"))
     {
         InventoryGrid.Modifier arg = InventoryGrid.Modifier.Select;
         if (ZInput.GetButton("JoyLTrigger"))
         {
             arg = InventoryGrid.Modifier.Split;
         }
         if (ZInput.GetButton("JoyRTrigger"))
         {
             arg = InventoryGrid.Modifier.Move;
         }
         ItemDrop.ItemData gamepadSelectedItem = this.GetGamepadSelectedItem();
         this.m_onSelected(this, gamepadSelectedItem, this.m_selected, arg);
     }
     if (ZInput.GetButtonDown("JoyButtonX"))
     {
         ItemDrop.ItemData gamepadSelectedItem2 = this.GetGamepadSelectedItem();
         this.m_onRightClick(this, gamepadSelectedItem2, this.m_selected);
     }
 }
예제 #6
0
            private static void UpdateDebugFlyPrefix(Character __instance, Vector3 ___m_moveDir, ref Vector3 ___m_currentVel)
            {
                if (AllowDebugActions)
                {
                    // Add some extra velocity
                    Vector3 newVel = ___m_moveDir * 200f;

                    if (TakeInput(__instance))
                    {
                        if (ZInput.GetButton("Jump"))
                        {
                            newVel.y = 200;
                        }
                        else if (Input.GetKey(KeyCode.LeftControl))
                        {
                            newVel.y = -200;
                        }
                    }
                    ___m_currentVel = Vector3.Lerp(___m_currentVel, newVel, 0.5f);
                }
            }
예제 #7
0
    // Token: 0x0600024E RID: 590 RVA: 0x00012BF4 File Offset: 0x00010DF4
    private void LateUpdate()
    {
        if (!this.TakeInput() || this.InInventoryEtc())
        {
            this.m_character.SetMouseLook(Vector2.zero);
            return;
        }
        Vector2 zero = Vector2.zero;

        zero.x = Input.GetAxis("Mouse X") * PlayerController.m_mouseSens;
        zero.y = Input.GetAxis("Mouse Y") * PlayerController.m_mouseSens;
        if (!this.m_character.InPlaceMode() || !ZInput.GetButton("JoyRotate"))
        {
            zero.x += ZInput.GetJoyRightStickX() * 110f * Time.deltaTime;
            zero.y += -ZInput.GetJoyRightStickY() * 110f * Time.deltaTime;
        }
        if (PlayerController.m_invertMouse)
        {
            zero.y *= -1f;
        }
        this.m_character.SetMouseLook(zero);
    }
예제 #8
0
            public static void Update()
            {
                var Ply = CharTracker;

                if (DoorTracker != null)
                {
                    var xDist = Vector3.Distance(Ply.transform.position, DoorInst.transform.position);
                    if (xDist < refDist)
                    {
                        refDist = xDist;
                        return;
                    }
                    if (ZInput.GetButton("Use") || ZInput.GetButton("JoyUse"))
                    {
                        return;
                    }
                    if (xDist - refDist >= maxDist)
                    {
                        CloseTrackedDoor();
                    }
                }
            }
예제 #9
0
            static void Prefix(PlayerController __instance, ref bool ___m_attackWasPressed, Player ___m_character)
            {
                if (!modEnabled.Value || !repeatAttacks.Value)
                {
                    return;
                }

                if (___m_attackWasPressed && (((Attack)___m_character.GetType().GetField("m_currentAttack", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(___m_character))?.CanStartChainAttack() == true || !___m_character.InAttack()) && (ZInput.GetButton("Attack") || ZInput.GetButton("JoyAttack")) && !(bool)__instance.GetType().GetMethod("InInventoryEtc", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { }))
                {
                    Dbgl("resetting attack");
                    ___m_attackWasPressed = false;
                }
            }
예제 #10
0
        public static void UpdatePlacementGhost(Player player)
        {
            if (player.m_placementGhost == null)
            {
                return;
            }

            if (ABM.isActive)
            {
                return;
            }

            bool altMode = ZInput.GetButton("AltPlace") || ZInput.GetButton("JoyAltPlace");

            var piece = player.m_placementGhost.GetComponent <Piece>();

            var newVal = piece.transform.position;

            newVal = Quaternion.Inverse(piece.transform.rotation) * newVal;

            Vector3 alignment;
            Vector3 offset;

            GetAlignment(piece, out alignment, out offset);
            newVal += offset;
            var copy = newVal;

            newVal = new Vector3(newVal.x / alignment.x, newVal.y / alignment.y, newVal.z / alignment.z);
            float alphaX, alphaY, alphaZ;

            newVal = new UnityEngine.Vector3(Align(newVal.x, out alphaX), Align(newVal.y, out alphaY), Align(newVal.z, out alphaZ));
            if (altMode)
            {
                float alphaMin = 0.2f;
                if (Mathf.Abs(alphaX) >= alphaMin && Mathf.Abs(alphaX) >= Mathf.Abs(alphaY) && Mathf.Abs(alphaX) >= Mathf.Abs(alphaZ))
                {
                    newVal.x += Mathf.Sign(alphaX);
                }
                else if (Mathf.Abs(alphaY) >= alphaMin && Mathf.Abs(alphaY) >= Mathf.Abs(alphaZ))
                {
                    newVal.y += Mathf.Sign(alphaY);
                }
                else if (Mathf.Abs(alphaZ) >= alphaMin)
                {
                    newVal.z += Mathf.Sign(alphaZ);
                }
            }
            newVal = new Vector3(newVal.x * alignment.x, newVal.y * alignment.y, newVal.z * alignment.z);
            if (alignment.x <= 0)
            {
                newVal.x = copy.x;
            }
            if (alignment.y <= 0)
            {
                newVal.y = copy.y;
            }
            if (alignment.z <= 0)
            {
                newVal.z = copy.z;
            }
            newVal -= offset;

            newVal = piece.transform.rotation * newVal;
            piece.transform.position = newVal;
        }
예제 #11
0
        private static bool PlaceBlueprint(Player player, Piece piece)
        {
            Blueprint bp        = Instance.m_blueprints[piece.m_name];
            var       transform = player.m_placementGhost.transform;
            var       position  = player.m_placementGhost.transform.position;
            var       rotation  = player.m_placementGhost.transform.rotation;

            bool placeDirect = ZInput.GetButton("Crouch");

            if (placeDirect && !allowDirectBuildConfig.Value)
            {
                MessageHud.instance.ShowMessage(MessageHud.MessageType.Center, "$msg_direct_build_disabled");
                return(false);
            }

            if (ZInput.GetButton("AltPlace"))
            {
                Vector2 extent = bp.GetExtent();
                FlattenTerrain.FlattenForBlueprint(transform, extent.x, extent.y, bp.m_pieceEntries);
            }

            uint cntEffects = 0u;
            uint maxEffects = 10u;

            GameObject blueprintPrefab = PrefabManager.Instance.GetPrefab(Blueprint.BlueprintPrefabName);
            GameObject blueprintObject = Object.Instantiate(blueprintPrefab, position, rotation);

            ZDO blueprintZDO = blueprintObject.GetComponent <ZNetView>().GetZDO();

            blueprintZDO.Set(ZDOBlueprintName, bp.m_name);
            ZDOIDSet createdPlans = new ZDOIDSet();

            for (int i = 0; i < bp.m_pieceEntries.Length; i++)
            {
                PieceEntry entry = bp.m_pieceEntries[i];
                // Final position
                Vector3 entryPosition = position + transform.forward * entry.posZ + transform.right * entry.posX + new Vector3(0, entry.posY, 0);

                // Final rotation
                Quaternion entryQuat = new Quaternion(entry.rotX, entry.rotY, entry.rotZ, entry.rotW);
                entryQuat.eulerAngles += rotation.eulerAngles;

                // Get the prefab of the piece or the plan piece
                string prefabName = entry.name;
                if (!placeDirect)
                {
                    prefabName += PlanPiecePrefab.PlannedSuffix;
                }

                GameObject prefab = PrefabManager.Instance.GetPrefab(prefabName);
                if (!prefab)
                {
                    Jotunn.Logger.LogWarning(entry.name + " not found, you are probably missing a dependency for blueprint " + bp.m_name + ", not placing @ " + entryPosition);
                    continue;
                }

                // Instantiate a new object with the new prefab
                GameObject gameObject = Object.Instantiate(prefab, entryPosition, entryQuat);

                ZNetView zNetView = gameObject.GetComponent <ZNetView>();
                if (!zNetView)
                {
                    Jotunn.Logger.LogWarning("No ZNetView for " + gameObject + "!!??");
                }
                else if (gameObject.TryGetComponent(out PlanPiece planPiece))
                {
                    planPiece.PartOfBlueprint(blueprintZDO.m_uid, entry);
                    createdPlans.Add(planPiece.GetPlanPieceID());
                }

                // Register special effects
                CraftingStation craftingStation = gameObject.GetComponentInChildren <CraftingStation>();
                if (craftingStation)
                {
                    player.AddKnownStation(craftingStation);
                }
                Piece newpiece = gameObject.GetComponent <Piece>();
                if (newpiece)
                {
                    newpiece.SetCreator(player.GetPlayerID());
                }
                PrivateArea privateArea = gameObject.GetComponent <PrivateArea>();
                if (privateArea)
                {
                    privateArea.Setup(Game.instance.GetPlayerProfile().GetName());
                }
                WearNTear wearntear = gameObject.GetComponent <WearNTear>();
                if (wearntear)
                {
                    wearntear.OnPlaced();
                }
                TextReceiver textReceiver = gameObject.GetComponent <TextReceiver>();
                if (textReceiver != null)
                {
                    textReceiver.SetText(entry.additionalInfo);
                }

                // Limited build effects
                if (cntEffects < maxEffects)
                {
                    newpiece.m_placeEffect.Create(gameObject.transform.position, rotation, gameObject.transform, 1f);
                    player.AddNoise(50f);
                    cntEffects++;
                }

                // Count up player builds
                Game.instance.GetPlayerProfile().m_playerStats.m_builds++;
            }

            blueprintZDO.Set(PlanPiece.zdoBlueprintPiece, createdPlans.ToZPackage().GetArray());

            // Dont set the blueprint piece and clutter the world with it
            return(false);
        }
예제 #12
0
            static bool Prefix(PlayerController __instance, ZNetView ___m_nview)
            {
                if ((bool)___m_nview && !___m_nview.IsOwner())
                {
                    return(true);
                }
                if (!(bool)Traverse.Create(__instance).Method("TakeInput").GetValue())
                {
                    return(true);
                }
                if ((bool)Traverse.Create(__instance).Method("InInventoryEtc").GetValue())
                {
                    return(true);
                }
                if (ZInput.GetButton("Forward"))
                {
                    DetectTap(true, (float)(DateTime.Now - m_forwardLastTapCheck).TotalMilliseconds, DodgeTapHoldMax.Value, ref m_forwardPressTimer);
                    m_forwardLastTapCheck = DateTime.Now;
                }
                else
                {
                    var isTap = DetectTap(false, (float)(DateTime.Now - m_forwardLastTapCheck).TotalMilliseconds, DodgeTapHoldMax.Value, ref m_forwardPressTimer);
                    m_forwardLastTapCheck = DateTime.Now;
                    CheckForDoubleTapDodge(isTap, ref m_forwardLastTapRegistered, DodgeDirection.Forward);
                }
                if (ZInput.GetButton("Backward"))
                {
                    DetectTap(true, (float)(DateTime.Now - m_backwardLastTapCheck).TotalMilliseconds, DodgeTapHoldMax.Value, ref m_backwardPressTimer);
                    m_backwardLastTapCheck = DateTime.Now;
                }
                else
                {
                    bool isTap = DetectTap(false, (float)(DateTime.Now - m_backwardLastTapCheck).TotalMilliseconds, DodgeTapHoldMax.Value, ref m_backwardPressTimer);
                    m_backwardLastTapCheck = DateTime.Now;
                    CheckForDoubleTapDodge(isTap, ref m_backwardLastTapRegistered, DodgeDirection.Backward);
                }
                if (ZInput.GetButton("Left"))
                {
                    DetectTap(true, (float)(DateTime.Now - m_leftLastTapCheck).TotalMilliseconds, DodgeTapHoldMax.Value, ref m_leftPressTimer);
                    m_leftLastTapCheck = DateTime.Now;
                }
                else
                {
                    bool isTap = DetectTap(false, (float)(DateTime.Now - m_leftLastTapCheck).TotalMilliseconds, DodgeTapHoldMax.Value, ref m_leftPressTimer);
                    m_leftLastTapCheck = DateTime.Now;
                    CheckForDoubleTapDodge(isTap, ref m_leftLastTapRegistered, DodgeDirection.Left);
                }
                if (ZInput.GetButton("Right"))
                {
                    DetectTap(true, (float)(DateTime.Now - m_rightLastTapCheck).TotalMilliseconds, DodgeTapHoldMax.Value, ref m_rightPressTimer);
                    m_rightLastTapCheck = DateTime.Now;
                }
                else
                {
                    bool isTap = DetectTap(false, (float)(DateTime.Now - m_rightLastTapCheck).TotalMilliseconds, DodgeTapHoldMax.Value, ref m_rightPressTimer);
                    m_rightLastTapCheck = DateTime.Now;
                    CheckForDoubleTapDodge(isTap, ref m_rightLastTapRegistered, DodgeDirection.Right);
                }

                // Gamepad
                var v = new Vector3(ZInput.GetJoyLeftStickX(), 0, ZInput.GetJoyLeftStickY());

                if (v.magnitude > 0.9f)
                {
                    DetectTap(true, (float)(DateTime.Now - m_GamepadLastTapCheck).TotalMilliseconds, DodgeTapHoldMax.Value, ref m_GamepadPressTimer);
                    m_GamepadLastTapCheck = DateTime.Now;
                    var milliesSinceLastTap = (DateTime.Now - m_GamepadLastTapRegistered)?.TotalMilliseconds ?? DodgeDoubleTapDelay.Value;
                    if (milliesSinceLastTap < DodgeDoubleTapDelay.Value)
                    {
                        m_GamepadSecondDir = v;
                    }
                    else
                    {
                        m_GamepadFirstDir = v;
                    }
                }
                else
                {
                    bool isTap = DetectTap(false, (float)(DateTime.Now - m_GamepadLastTapCheck).TotalMilliseconds, DodgeTapHoldMax.Value, ref m_GamepadPressTimer);
                    m_GamepadLastTapCheck = DateTime.Now;
                    CheckForDoubleTapDodge(isTap, ref m_GamepadLastTapRegistered);
                }
                return(true);
            }
예제 #13
0
            // almost copy of original UpdatePlacementGhost with modified calculation of Quaternion quaternion = Quaternion.Euler(rotation);
            // need to be re-calculated in Postfix for correct work of auto-attachment of placementGhost after change rotation
            private static void UpdatePlacementGhost(Player __instance, bool flashGuardStone)
            {
                if ((UnityEngine.Object)__instance.m_placementGhost == (UnityEngine.Object)null)
                {
                    if (!(bool)(UnityEngine.Object)__instance.m_placementMarkerInstance)
                    {
                        return;
                    }
                    __instance.m_placementMarkerInstance.SetActive(false);
                }
                else
                {
                    bool      flag       = ZInput.GetButton("AltPlace") || ZInput.GetButton("JoyAltPlace");
                    Piece     component1 = __instance.m_placementGhost.GetComponent <Piece>();
                    bool      water      = component1.m_waterPiece || component1.m_noInWater;
                    Vector3   point;
                    Vector3   normal;
                    Piece     piece;
                    Heightmap heightmap;
                    Collider  waterSurface;
                    if (__instance.PieceRayTest(out point, out normal, out piece, out heightmap, out waterSurface, water))
                    {
                        __instance.m_placementStatus = Player.PlacementStatus.Valid;
                        if ((UnityEngine.Object)__instance.m_placementMarkerInstance == (UnityEngine.Object)null)
                        {
                            __instance.m_placementMarkerInstance =
                                UnityEngine.Object.Instantiate <GameObject>(__instance.m_placeMarker, point,
                                                                            Quaternion.identity);
                        }
                        __instance.m_placementMarkerInstance.SetActive(true);
                        __instance.m_placementMarkerInstance.transform.position = point;
                        __instance.m_placementMarkerInstance.transform.rotation = Quaternion.LookRotation(normal);
                        if (component1.m_groundOnly || component1.m_groundPiece || component1.m_cultivatedGroundOnly)
                        {
                            __instance.m_placementMarkerInstance.SetActive(false);
                        }
                        WearNTear wearNtear = (UnityEngine.Object)piece != (UnityEngine.Object)null
                            ? piece.GetComponent <WearNTear>()
                            : (WearNTear)null;
                        StationExtension component2 = component1.GetComponent <StationExtension>();
                        if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
                        {
                            CraftingStation closestStationInRange = component2.FindClosestStationInRange(point);
                            if ((bool)(UnityEngine.Object)closestStationInRange)
                            {
                                component2.StartConnectionEffect(closestStationInRange);
                            }
                            else
                            {
                                component2.StopConnectionEffect();
                                __instance.m_placementStatus = Player.PlacementStatus.ExtensionMissingStation;
                            }

                            if (component2.OtherExtensionInRange(component1.m_spaceRequirement))
                            {
                                __instance.m_placementStatus = Player.PlacementStatus.MoreSpace;
                            }
                        }

                        if ((bool)(UnityEngine.Object)wearNtear && !wearNtear.m_supports)
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.Invalid;
                        }
                        if (component1.m_waterPiece && (UnityEngine.Object)waterSurface == (UnityEngine.Object)null &&
                            !flag)
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.Invalid;
                        }
                        if (component1.m_noInWater && (UnityEngine.Object)waterSurface != (UnityEngine.Object)null)
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.Invalid;
                        }
                        if (component1.m_groundPiece && (UnityEngine.Object)heightmap == (UnityEngine.Object)null)
                        {
                            __instance.m_placementGhost.SetActive(false);
                            __instance.m_placementStatus = Player.PlacementStatus.Invalid;
                            return;
                        }

                        if (component1.m_groundOnly && (UnityEngine.Object)heightmap == (UnityEngine.Object)null)
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.Invalid;
                        }
                        if (component1.m_cultivatedGroundOnly &&
                            ((UnityEngine.Object)heightmap == (UnityEngine.Object)null ||
                             !heightmap.IsCultivated(point)))
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.NeedCultivated;
                        }
                        if (component1.m_notOnWood && (bool)(UnityEngine.Object)piece &&
                            (bool)(UnityEngine.Object)wearNtear &&
                            (wearNtear.m_materialType == WearNTear.MaterialType.Wood ||
                             wearNtear.m_materialType == WearNTear.MaterialType.HardWood))
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.Invalid;
                        }
                        if (component1.m_notOnTiltingSurface && (double)normal.y < 0.800000011920929)
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.Invalid;
                        }
                        if (component1.m_inCeilingOnly && (double)normal.y > -0.5)
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.Invalid;
                        }
                        if (component1.m_notOnFloor && (double)normal.y > 0.100000001490116)
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.Invalid;
                        }
                        if (component1.m_onlyInTeleportArea &&
                            !(bool)(UnityEngine.Object)EffectArea.IsPointInsideArea(point, EffectArea.Type.Teleport,
                                                                                    0.0f))
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.NoTeleportArea;
                        }
                        if (!component1.m_allowedInDungeons && __instance.InInterior())
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.NotInDungeon;
                        }
                        if ((bool)(UnityEngine.Object)heightmap)
                        {
                            normal = Vector3.up;
                        }
                        __instance.m_placementGhost.SetActive(true);

                        var rotation = PlayersData.ContainsKey(__instance)
                            ? PlayersData[__instance].PlaceRotation
                            : __instance.m_placeRotation * 22.5f * Vector3.up;

                        Quaternion quaternion = Quaternion.Euler(rotation);

                        if ((component1.m_groundPiece || component1.m_clipGround) &&
                            (bool)(UnityEngine.Object)heightmap || component1.m_clipEverything)
                        {
                            if ((bool)(UnityEngine.Object)__instance.m_buildPieces.GetSelectedPrefab()
                                .GetComponent <TerrainModifier>() && component1.m_allowAltGroundPlacement &&
                                (component1.m_groundPiece && !ZInput.GetButton("AltPlace")) &&
                                !ZInput.GetButton("JoyAltPlace"))
                            {
                                float groundHeight = ZoneSystem.instance.GetGroundHeight(__instance.transform.position);
                                point.y = groundHeight;
                            }

                            __instance.m_placementGhost.transform.position = point;
                            __instance.m_placementGhost.transform.rotation = quaternion;
                        }
                        else
                        {
                            Collider[] componentsInChildren = __instance.m_placementGhost.GetComponentsInChildren <Collider>();
                            if (componentsInChildren.Length != 0)
                            {
                                __instance.m_placementGhost.transform.position = point + normal * 50f;
                                __instance.m_placementGhost.transform.rotation = quaternion;
                                Vector3 vector3_1 = Vector3.zero;
                                float   num1      = 999999f;
                                foreach (Collider collider in componentsInChildren)
                                {
                                    if (!collider.isTrigger && collider.enabled)
                                    {
                                        MeshCollider meshCollider = collider as MeshCollider;
                                        if (!((UnityEngine.Object)meshCollider != (UnityEngine.Object)null) ||
                                            meshCollider.convex)
                                        {
                                            Vector3 a    = collider.ClosestPoint(point);
                                            float   num2 = Vector3.Distance(a, point);
                                            if ((double)num2 < (double)num1)
                                            {
                                                vector3_1 = a;
                                                num1      = num2;
                                            }
                                        }
                                    }
                                }

                                Vector3 vector3_2 = __instance.m_placementGhost.transform.position - vector3_1;
                                if (component1.m_waterPiece)
                                {
                                    vector3_2.y = 3f;
                                }
                                __instance.m_placementGhost.transform.position = point + vector3_2;
                                __instance.m_placementGhost.transform.rotation = quaternion;
                            }
                        }

                        if (!flag)
                        {
                            __instance.m_tempPieces.Clear();
                            Transform a;
                            Transform b;
                            if (__instance.FindClosestSnapPoints(__instance.m_placementGhost.transform, 0.5f, out a, out b,
                                                                 __instance.m_tempPieces))
                            {
                                Vector3 position = b.parent.position;
                                Vector3 p        = b.position - (a.position - __instance.m_placementGhost.transform.position);
                                if (!__instance.IsOverlapingOtherPiece(p, __instance.m_placementGhost.transform.rotation, __instance.m_placementGhost.name, __instance.m_tempPieces, component1.m_allowRotatedOverlap))
                                {
                                    __instance.m_placementGhost.transform.position = p;
                                }
                            }
                        }

                        if (Location.IsInsideNoBuildLocation(__instance.m_placementGhost.transform.position))
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.NoBuildZone;
                        }
                        if (!PrivateArea.CheckAccess(__instance.m_placementGhost.transform.position,
                                                     (bool)(UnityEngine.Object)component1.GetComponent <PrivateArea>()
                                ? component1.GetComponent <PrivateArea>().m_radius
                                : 0.0f, flashGuardStone))
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.PrivateZone;
                        }
                        if (__instance.CheckPlacementGhostVSPlayers())
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.BlockedbyPlayer;
                        }
                        if (component1.m_onlyInBiome != Heightmap.Biome.None &&
                            (Heightmap.FindBiome(__instance.m_placementGhost.transform.position) &
                             component1.m_onlyInBiome) == Heightmap.Biome.None)
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.WrongBiome;
                        }
                        if (component1.m_noClipping && __instance.TestGhostClipping(__instance.m_placementGhost, 0.2f))
                        {
                            __instance.m_placementStatus = Player.PlacementStatus.Invalid;
                        }
                    }
                    else
                    {
                        if ((bool)(UnityEngine.Object)__instance.m_placementMarkerInstance)
                        {
                            __instance.m_placementMarkerInstance.SetActive(false);
                        }
                        __instance.m_placementGhost.SetActive(false);
                        __instance.m_placementStatus = Player.PlacementStatus.Invalid;
                    }

                    __instance.SetPlacementGhostValid(__instance.m_placementStatus == Player.PlacementStatus.Valid);
                }
            }
예제 #14
0
    // Token: 0x0600024A RID: 586 RVA: 0x00012870 File Offset: 0x00010A70
    private void FixedUpdate()
    {
        if (this.m_nview && !this.m_nview.IsOwner())
        {
            return;
        }
        if (!this.TakeInput())
        {
            this.m_character.SetControls(Vector3.zero, false, false, false, false, false, false, false, false, false);
            return;
        }
        bool    flag = this.InInventoryEtc();
        Vector3 zero = Vector3.zero;

        if (ZInput.GetButton("Forward"))
        {
            zero.z += 1f;
        }
        if (ZInput.GetButton("Backward"))
        {
            zero.z -= 1f;
        }
        if (ZInput.GetButton("Left"))
        {
            zero.x -= 1f;
        }
        if (ZInput.GetButton("Right"))
        {
            zero.x += 1f;
        }
        zero.x += ZInput.GetJoyLeftStickX();
        zero.z += -ZInput.GetJoyLeftStickY();
        if (zero.magnitude > 1f)
        {
            zero.Normalize();
        }
        bool flag2      = (ZInput.GetButton("Attack") || ZInput.GetButton("JoyAttack")) && !flag;
        bool attackHold = flag2;
        bool attack     = flag2 && !this.m_attackWasPressed;

        this.m_attackWasPressed = flag2;
        bool flag3           = (ZInput.GetButton("SecondAttack") || ZInput.GetButton("JoySecondAttack")) && !flag;
        bool secondaryAttack = flag3 && !this.m_secondAttackWasPressed;

        this.m_secondAttackWasPressed = flag3;
        bool flag4     = (ZInput.GetButton("Block") || ZInput.GetButton("JoyBlock")) && !flag;
        bool blockHold = flag4;
        bool block     = flag4 && !this.m_blockWasPressed;

        this.m_blockWasPressed = flag4;
        bool button = ZInput.GetButton("Jump");
        bool jump   = (button && !this.m_lastJump) || ZInput.GetButtonDown("JoyJump");

        this.m_lastJump = button;
        bool flag5  = InventoryGui.IsVisible();
        bool flag6  = (ZInput.GetButton("Crouch") || ZInput.GetButton("JoyCrouch")) && !flag5;
        bool crouch = flag6 && !this.m_lastCrouch;

        this.m_lastCrouch = flag6;
        bool run     = ZInput.GetButton("Run") || ZInput.GetButton("JoyRun");
        bool button2 = ZInput.GetButton("AutoRun");

        this.m_character.SetControls(zero, attack, attackHold, secondaryAttack, block, blockHold, jump, crouch, run, button2);
    }
예제 #15
0
        /// <summary>
        ///     Incept placing of the meta pieces.
        ///     Cancels the real placement of the placeholder pieces.
        /// </summary>
        private bool BeforePlaceBlueprintPiece(On.Player.orig_PlacePiece orig, Player self, Piece piece)
        {
            // Client only
            if (!ZNet.instance.IsServerInstance())
            {
                // Capture a new blueprint
                if (piece.name == "make_blueprint")
                {
                    var circleProjector = self.m_placementGhost.GetComponent <CircleProjector>();
                    if (circleProjector != null)
                    {
                        Destroy(circleProjector);
                    }

                    var bpname = $"blueprint{Instance.m_blueprints.Count() + 1:000}";
                    Jotunn.Logger.LogInfo($"Capturing blueprint {bpname}");

                    if (Player.m_localPlayer.m_hoveringPiece != null)
                    {
                        var bp = new Blueprint(bpname);
                        if (bp.Capture(Player.m_localPlayer.m_hoveringPiece.transform.position, Instance.selectionRadius, 1.0f))
                        {
                            TextInput.instance.m_queuedSign = new Blueprint.BlueprintSaveGUI(bp);
                            TextInput.instance.Show($"Save Blueprint ({bp.GetPieceCount()} pieces captured)", bpname, 50);
                        }
                        else
                        {
                            Jotunn.Logger.LogWarning($"Could not capture blueprint {bpname}");
                        }
                    }
                    else
                    {
                        Jotunn.Logger.LogInfo("Not hovering any piece");
                    }

                    // Reset Camera offset
                    Instance.cameraOffsetMake = 0f;

                    // Don't place the piece and clutter the world with it
                    return(false);
                }

                // Place a known blueprint
                if (Player.m_localPlayer.m_placementStatus == Player.PlacementStatus.Valid && piece.name.StartsWith("piece_blueprint"))
                {
                    Blueprint bp        = Instance.m_blueprints[piece.m_name];
                    var       transform = self.m_placementGhost.transform;
                    var       position  = self.m_placementGhost.transform.position;
                    var       rotation  = self.m_placementGhost.transform.rotation;

                    if (ZInput.GetButton("Crouch") && !ConfigUtil.Get <bool>("Blueprints", "allowPlacementWithoutMaterial"))
                    {
                        MessageHud.instance.ShowMessage(MessageHud.MessageType.Center, "$plan_direct_build_disable");
                        return(false);
                    }

                    if (ZInput.GetButton("AltPlace"))
                    {
                        Vector2 extent = bp.GetExtent();
                        FlattenTerrain.FlattenForBlueprint(transform, extent.x, extent.y, bp.m_pieceEntries);
                    }

                    uint cntEffects = 0u;
                    uint maxEffects = 10u;

                    foreach (var entry in bp.m_pieceEntries)
                    {
                        // Final position
                        Vector3 entryPosition = position + transform.forward * entry.posZ + transform.right * entry.posX + new Vector3(0, entry.posY, 0);

                        // Final rotation
                        Quaternion entryQuat = new Quaternion(entry.rotX, entry.rotY, entry.rotZ, entry.rotW);
                        entryQuat.eulerAngles += rotation.eulerAngles;

                        // Get the prefab of the piece or the plan piece
                        string prefabName = entry.name;
                        if (!ConfigUtil.Get <bool>("Blueprints", "allowPlacementWithoutMaterial") || !ZInput.GetButton("Crouch"))
                        {
                            prefabName += "_planned";
                        }
                        GameObject prefab = PrefabManager.Instance.GetPrefab(prefabName);
                        if (!prefab)
                        {
                            Jotunn.Logger.LogError(entry.name + " not found?");
                            continue;
                        }

                        // Instantiate a new object with the new prefab
                        GameObject gameObject = Instantiate(prefab, entryPosition, entryQuat);

                        // Register special effects
                        CraftingStation craftingStation = gameObject.GetComponentInChildren <CraftingStation>();
                        if (craftingStation)
                        {
                            self.AddKnownStation(craftingStation);
                        }
                        Piece newpiece = gameObject.GetComponent <Piece>();
                        if (newpiece != null)
                        {
                            newpiece.SetCreator(self.GetPlayerID());
                        }
                        PrivateArea privateArea = gameObject.GetComponent <PrivateArea>();
                        if (privateArea != null)
                        {
                            privateArea.Setup(Game.instance.GetPlayerProfile().GetName());
                        }
                        WearNTear wearntear = gameObject.GetComponent <WearNTear>();
                        if (wearntear != null)
                        {
                            wearntear.OnPlaced();
                        }
                        TextReceiver textReceiver = gameObject.GetComponent <TextReceiver>();
                        if (textReceiver != null)
                        {
                            textReceiver.SetText(entry.additionalInfo);
                        }

                        // Limited build effects
                        if (cntEffects < maxEffects)
                        {
                            newpiece.m_placeEffect.Create(gameObject.transform.position, rotation, gameObject.transform, 1f);
                            self.AddNoise(50f);
                            cntEffects++;
                        }

                        // Count up player builds
                        Game.instance.GetPlayerProfile().m_playerStats.m_builds++;
                    }

                    // Reset Camera offset
                    Instance.cameraOffsetPlace = 5f;

                    // Dont set the blueprint piece and clutter the world with it
                    return(false);
                }
            }

            return(orig(self, piece));
        }
예제 #16
0
    // Token: 0x06000AE9 RID: 2793 RVA: 0x0004E798 File Offset: 0x0004C998
    private void UpdateFreeFly(float dt)
    {
        if (global::Console.IsVisible())
        {
            return;
        }
        Vector2 zero = Vector2.zero;

        zero.x               = Input.GetAxis("Mouse X");
        zero.y               = Input.GetAxis("Mouse Y");
        zero.x              += ZInput.GetJoyRightStickX() * 110f * dt;
        zero.y              += -ZInput.GetJoyRightStickY() * 110f * dt;
        this.m_freeFlyYaw   += zero.x;
        this.m_freeFlyPitch -= zero.y;
        if (Input.GetAxis("Mouse ScrollWheel") < 0f)
        {
            this.m_freeFlySpeed *= 0.8f;
        }
        if (Input.GetAxis("Mouse ScrollWheel") > 0f)
        {
            this.m_freeFlySpeed *= 1.2f;
        }
        if (Input.GetAxis("Mouse ScrollWheel") > 0f)
        {
            this.m_freeFlySpeed *= 1.2f;
        }
        if (ZInput.GetButton("JoyTabLeft"))
        {
            this.m_camera.fieldOfView = Mathf.Max(this.m_freeFlyMinFov, this.m_camera.fieldOfView - dt * 20f);
        }
        if (ZInput.GetButton("JoyTabRight"))
        {
            this.m_camera.fieldOfView = Mathf.Min(this.m_freeFlyMaxFov, this.m_camera.fieldOfView + dt * 20f);
        }
        this.m_skyCamera.fieldOfView = this.m_camera.fieldOfView;
        if (ZInput.GetButton("JoyButtonY"))
        {
            this.m_freeFlySpeed += this.m_freeFlySpeed * 0.1f * dt * 10f;
        }
        if (ZInput.GetButton("JoyButtonX"))
        {
            this.m_freeFlySpeed -= this.m_freeFlySpeed * 0.1f * dt * 10f;
        }
        this.m_freeFlySpeed = Mathf.Clamp(this.m_freeFlySpeed, 1f, 1000f);
        if (ZInput.GetButtonDown("JoyLStick") || ZInput.GetButtonDown("SecondAttack"))
        {
            if (this.m_freeFlyLockon)
            {
                this.m_freeFlyLockon = null;
            }
            else
            {
                int mask = LayerMask.GetMask(new string[]
                {
                    "Default",
                    "static_solid",
                    "terrain",
                    "vehicle",
                    "character",
                    "piece",
                    "character_net",
                    "viewblock"
                });
                RaycastHit raycastHit;
                if (Physics.Raycast(base.transform.position, base.transform.forward, out raycastHit, 10000f, mask))
                {
                    this.m_freeFlyLockon       = raycastHit.collider.transform;
                    this.m_freeFlyLockonOffset = this.m_freeFlyLockon.InverseTransformPoint(base.transform.position);
                }
            }
        }
        Vector3 vector = Vector3.zero;

        if (ZInput.GetButton("Left"))
        {
            vector -= Vector3.right;
        }
        if (ZInput.GetButton("Right"))
        {
            vector += Vector3.right;
        }
        if (ZInput.GetButton("Forward"))
        {
            vector += Vector3.forward;
        }
        if (ZInput.GetButton("Backward"))
        {
            vector -= Vector3.forward;
        }
        if (ZInput.GetButton("Jump"))
        {
            vector += Vector3.up;
        }
        if (ZInput.GetButton("Crouch"))
        {
            vector -= Vector3.up;
        }
        vector += Vector3.up * ZInput.GetJoyRTrigger();
        vector -= Vector3.up * ZInput.GetJoyLTrigger();
        vector += Vector3.right * ZInput.GetJoyLeftStickX();
        vector += -Vector3.forward * ZInput.GetJoyLeftStickY();
        if (ZInput.GetButtonDown("JoyButtonB") || ZInput.GetButtonDown("Block"))
        {
            this.m_freeFlySavedVel = vector;
        }
        float magnitude = this.m_freeFlySavedVel.magnitude;

        if (magnitude > 0.001f)
        {
            vector += this.m_freeFlySavedVel;
            if (vector.magnitude > magnitude)
            {
                vector = vector.normalized * magnitude;
            }
        }
        if (vector.magnitude > 1f)
        {
            vector.Normalize();
        }
        vector  = base.transform.TransformVector(vector);
        vector *= this.m_freeFlySpeed;
        if (this.m_freeFlySmooth <= 0f)
        {
            this.m_freeFlyVel = vector;
        }
        else
        {
            this.m_freeFlyVel = Vector3.SmoothDamp(this.m_freeFlyVel, vector, ref this.m_freeFlyAcc, this.m_freeFlySmooth, 99f, dt);
        }
        if (this.m_freeFlyLockon)
        {
            this.m_freeFlyLockonOffset += this.m_freeFlyLockon.InverseTransformVector(this.m_freeFlyVel * dt);
            base.transform.position     = this.m_freeFlyLockon.TransformPoint(this.m_freeFlyLockonOffset);
        }
        else
        {
            base.transform.position = base.transform.position + this.m_freeFlyVel * dt;
        }
        Quaternion quaternion = Quaternion.Euler(0f, this.m_freeFlyYaw, 0f) * Quaternion.Euler(this.m_freeFlyPitch, 0f, 0f);

        if (this.m_freeFlyLockon)
        {
            quaternion = this.m_freeFlyLockon.rotation * quaternion;
        }
        if (ZInput.GetButtonDown("JoyRStick") || ZInput.GetButtonDown("Attack"))
        {
            if (this.m_freeFlyTarget)
            {
                this.m_freeFlyTarget = null;
            }
            else
            {
                int mask2 = LayerMask.GetMask(new string[]
                {
                    "Default",
                    "static_solid",
                    "terrain",
                    "vehicle",
                    "character",
                    "piece",
                    "character_net",
                    "viewblock"
                });
                RaycastHit raycastHit2;
                if (Physics.Raycast(base.transform.position, base.transform.forward, out raycastHit2, 10000f, mask2))
                {
                    this.m_freeFlyTarget       = raycastHit2.collider.transform;
                    this.m_freeFlyTargetOffset = this.m_freeFlyTarget.InverseTransformPoint(raycastHit2.point);
                }
            }
        }
        if (this.m_freeFlyTarget)
        {
            quaternion = Quaternion.LookRotation((this.m_freeFlyTarget.TransformPoint(this.m_freeFlyTargetOffset) - base.transform.position).normalized, Vector3.up);
        }
        if (this.m_freeFlySmooth <= 0f)
        {
            base.transform.rotation = quaternion;
            return;
        }
        Quaternion rotation = Utils.SmoothDamp(base.transform.rotation, quaternion, ref this.m_freeFlyRef, this.m_freeFlySmooth, 9999f, dt);

        base.transform.rotation = rotation;
    }