Exemplo n.º 1
0
        public void SetMapData(string mapData)
        {
            if (m_nview == null)
            {
                return;
            }

            m_nview.ClaimOwnership();
            m_nview.GetZDO().Set(nameof(mapData), mapData);
            _mapData = mapData;
            Utils.Log("Writing Shared Map Data");
        }
Exemplo n.º 2
0
        public static void DeleteTMod(TerrainModifier modifier)
        {
            ZNetView znview = modifier.gameObject.GetComponent <ZNetView>();

            if (!znview || znview.GetZDO() == null)
            {
                return;
            }
            bool has_copy = false;

            foreach (ZDO item in zdos_to_save)
            {
                if (item.m_uid == znview.GetZDO().m_uid)
                {
                    has_copy = true;
                    break;
                }
            }
            if (!has_copy)
            {
                zdos_to_save.Add(znview.GetZDO().Clone());
            }
            modifier.enabled = false;
            znview.ClaimOwnership();
            if (!new string[3] {
                "mud_road(Clone)", "digg(Clone)", "path(Clone)"
            }.Contains(modifier.name))
            {
                Debug.LogWarning("Deleting " + modifier.name);
            }
            Debug.Log("Deleting " + modifier.name);
            ZNetScene.instance.Destroy(modifier.gameObject);
        }
Exemplo n.º 3
0
        private void ApplyTexture(string url, Texture2D obj)
        {
            m_nview.ClaimOwnership();
            m_nview.GetZDO().Set("SailUrl", url);

            sailRenderer.material.SetTexture("_MainTex", obj);
        }
 public static bool Prefix(Player __instance, ZSyncAnimation ___m_zanim, ref bool __result)
 {
     if (__instance.GetRightItem().m_shared.m_name == "$item_cultivator")
     {
         if (Physics.Raycast(GameCamera.instance.transform.position, GameCamera.instance.transform.forward, out var hitInfo, 50f, LayerMask.GetMask("item", "piece_nonsolid", "terrain")) && Vector3.Distance(hitInfo.point, __instance.m_eye.position) < __instance.m_maxPlaceDistance)
         {
             Pickable pickable = hitInfo.collider.GetComponentInParent <Pickable>();
             if (pickable == null)
             {
                 float    num      = 999999f;
                 ZNetView zNetView = null;
                 foreach (KeyValuePair <ZDO, ZNetView> item in typeof(ZNetScene).GetField("m_instances", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(ZNetScene.instance) as Dictionary <ZDO, ZNetView> )
                 {
                     if ((bool)item.Value.gameObject.GetComponent <Pickable>())
                     {
                         float num2 = Mathf.Sqrt((item.Key.GetPosition().x - hitInfo.point.x) * (item.Key.GetPosition().x - hitInfo.point.x) + (item.Key.GetPosition().z - hitInfo.point.z) * (item.Key.GetPosition().z - hitInfo.point.z));
                         if ((double)num2 <= 0.5 && num2 <= num)
                         {
                             num      = num2;
                             zNetView = item.Value;
                         }
                     }
                 }
                 if ((bool)zNetView)
                 {
                     pickable = zNetView.gameObject.GetComponent <Pickable>();
                 }
             }
             if (pickable != null)
             {
                 ZNetView component = pickable.GetComponent <ZNetView>();
                 if (component == null)
                 {
                     __result = false;
                     return(false);
                 }
                 component.ClaimOwnership();
                 __instance.m_removeEffects.Create(pickable.transform.position, Quaternion.identity);
                 ZNetScene.instance.Destroy(pickable.gameObject);
                 ItemDrop.ItemData rightItem = __instance.GetRightItem();
                 if (rightItem != null)
                 {
                     __instance.FaceLookDirection();
                     ___m_zanim.SetTrigger(rightItem.m_shared.m_attack.m_attackAnimation);
                 }
                 __result = true;
                 return(false);
             }
         }
         __result = false;
         return(false);
     }
     return(true);
 }
Exemplo n.º 5
0
            static bool Prefix(Fireplace __instance, Humanoid user, bool hold, ref bool __result, ZNetView ___m_nview)
            {
                __result = false;
                if (!AllowByKey())
                {
                    return(true);
                }
                if (hold)
                {
                    return(false);
                }
                if (!___m_nview.HasOwner())
                {
                    ___m_nview.ClaimOwnership();
                }
                Inventory inventory = user.GetInventory();

                if (inventory == null)
                {
                    __result = true;
                    return(false);
                }
                if (!inventory.HaveItem(__instance.m_fuelItem.m_itemData.m_shared.m_name) && (float)Mathf.CeilToInt(___m_nview.GetZDO().GetFloat("fuel", 0f)) < __instance.m_maxFuel)
                {
                    List <Container> nearbyContainers = GetNearbyContainers(__instance.transform.position);

                    foreach (Container c in nearbyContainers)
                    {
                        ItemDrop.ItemData item = c.GetInventory().GetItem(__instance.m_fuelItem.m_itemData.m_shared.m_name);
                        if (item != null)
                        {
                            if (fuelDisallowTypes.Value.Split(',').Contains(item.m_dropPrefab.name))
                            {
                                Dbgl($"container at {c.transform.position} has {item.m_stack} {item.m_dropPrefab.name} but it's forbidden by config");
                                continue;
                            }
                            Dbgl($"container at {c.transform.position} has {item.m_stack} {item.m_dropPrefab.name}, taking one");
                            c.GetInventory().RemoveItem(__instance.m_fuelItem.m_itemData.m_shared.m_name, 1);
                            typeof(Container).GetMethod("Save", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(c, new object[] { });
                            typeof(Inventory).GetMethod("Changed", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(c.GetInventory(), new object[] { });
                            user.Message(MessageHud.MessageType.Center, Localization.instance.Localize("$msg_fireadding", new string[]
                            {
                                __instance.m_fuelItem.m_itemData.m_shared.m_name
                            }), 0, null);
                            inventory.RemoveItem(__instance.m_fuelItem.m_itemData.m_shared.m_name, 1);
                            ___m_nview.InvokeRPC("AddFuel", new object[] { });
                            __result = true;
                            return(false);
                        }
                    }
                }
                return(true);
            }
Exemplo n.º 6
0
 // Token: 0x060003E3 RID: 995 RVA: 0x00020838 File Offset: 0x0001EA38
 private void RemoveStartEffects()
 {
     if (this.m_startEffectInstances != null && ZNetScene.instance != null)
     {
         foreach (GameObject gameObject in this.m_startEffectInstances)
         {
             if (gameObject)
             {
                 ZNetView component = gameObject.GetComponent <ZNetView>();
                 if (component.IsValid())
                 {
                     component.ClaimOwnership();
                     component.Destroy();
                 }
             }
         }
         this.m_startEffectInstances = null;
     }
 }
Exemplo n.º 7
0
            static void Postfix(Player __instance, bool __result, Piece piece, int ___m_placeRayMask, GameObject ___m_placementGhost)
            {
                if (!modEnabled.Value || !__result)
                {
                    return;
                }

                Vector3 position = ___m_placementGhost.transform.position;

                Collider[] componentsInChildren = piece.GetComponentsInChildren <Collider>();
                Collider[] array = Physics.OverlapSphere(position, 10f, ___m_placeRayMask);
                foreach (Collider collider in componentsInChildren)
                {
                    foreach (Collider collider2 in array)
                    {
                        if (collider2.GetComponent <Piece>() && position == collider2.gameObject.transform.position && piece.m_name != collider2.gameObject.GetComponent <Piece>().m_name)
                        {
                            WearNTear component2 = collider2.GetComponent <WearNTear>();
                            if (component2)
                            {
                                Dbgl("removeing wnt piece");

                                component2.Remove();
                            }
                            else
                            {
                                ZNetView component = collider2.GetComponent <ZNetView>();
                                if (component == null)
                                {
                                    continue;
                                }
                                ZLog.Log("Removing non WNT object with hammer " + collider2.name);
                                component.ClaimOwnership();
                                collider2.GetComponent <Piece>().DropResources();
                                collider2.GetComponent <Piece>().m_placeEffect.Create(collider2.transform.position, collider2.transform.rotation, collider2.gameObject.transform, 1f);
                                __instance.m_removeEffects.Create(collider2.transform.position, Quaternion.identity, null, 1f);
                                ZNetScene.instance.Destroy(collider2.gameObject);
                            }
                        }
                    }
                }
            }
Exemplo n.º 8
0
 public static void Reset(Vector3 centerLocation, float radius)
 {
     radius = Mathf.Clamp(radius, 2f, 50f);
     try
     {
         foreach (TerrainModifier terrainModifier in TerrainModifier.GetAllInstances())
         {
             if (terrainModifier != null && Utils.DistanceXZ(Player.m_localPlayer.transform.position, terrainModifier.transform.position) < radius)
             {
                 ZNetView component = terrainModifier.GetComponent <ZNetView>();
                 if (component != null && component.IsValid())
                 {
                     component.ClaimOwnership();
                     component.Destroy();
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 9
0
 private void Update()
 {
     if (!AedenthornUtils.IgnoreKeyPresses(true) && AedenthornUtils.CheckKeyDown(hotKey.Value))
     {
         Player player = Player.m_localPlayer;
         Dbgl($"Ka-boom");
         Collider[] array = Physics.OverlapSphere(player.transform.position, destroyRadius.Value, destroyMask);
         for (int i = 0; i < array.Length; i++)
         {
             Piece piece = array[i].GetComponentInParent <Piece>();
             if (piece)
             {
                 if (!piece.IsCreator())
                 {
                     continue;
                 }
                 if (!piece.m_canBeRemoved)
                 {
                     continue;
                 }
                 if (Location.IsInsideNoBuildLocation(piece.transform.position))
                 {
                     continue;
                 }
                 if (!PrivateArea.CheckAccess(piece.transform.position, 0f, true))
                 {
                     continue;
                 }
                 if (!Traverse.Create(player).Method("CheckCanRemovePiece", new object[] { piece }).GetValue <bool>())
                 {
                     continue;
                 }
                 ZNetView component = piece.GetComponent <ZNetView>();
                 if (component == null)
                 {
                     continue;
                 }
                 if (!piece.CanBeRemoved())
                 {
                     continue;
                 }
                 WearNTear component2 = piece.GetComponent <WearNTear>();
                 if (component2)
                 {
                     component2.Remove();
                 }
                 else
                 {
                     component.ClaimOwnership();
                     piece.DropResources();
                     piece.m_placeEffect.Create(piece.transform.position, piece.transform.rotation, piece.gameObject.transform, 1f);
                     player.m_removeEffects.Create(piece.transform.position, Quaternion.identity, null, 1f);
                     ZNetScene.instance.Destroy(piece.gameObject);
                 }
                 ItemDrop.ItemData rightItem = player.GetRightItem();
                 if (rightItem != null)
                 {
                     player.FaceLookDirection();
                     Traverse.Create(player).Field("m_zanim").GetValue <ZSyncAnimation>().SetTrigger(rightItem.m_shared.m_attack.m_attackAnimation);
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
        private static void listenToHotKeysAndDoWork()
        {
            float rX = 0;
            float rZ = 0;
            float rY = 0;


            if (Input.GetKeyDown(Settings.getHotkey("resetAdvancedEditingMode")))
            {
                resetObjectTransform();
            }

            if (Input.GetKeyDown(Settings.getHotkey("confirmPlacementOfAdvancedEditingMode")))
            {
                if (isContainer())
                {
                    dropContainerContents();
                }

                // PLACE NEW
                GameObject gameObject2 = UnityEngine.Object.Instantiate <GameObject>(HitPiece.gameObject, HitPiece.transform.position, HitPiece.transform.rotation);
                HitPiece.m_placeEffect.Create(HitPiece.transform.position, HitPiece.transform.rotation, gameObject2.transform, 1f);

                // REMOVE OLD
                ZNetView component1 = HitPiece.GetComponent <ZNetView>();
                if ((UnityEngine.Object)component1 == (UnityEngine.Object)null)
                {
                    Debug.Log("AEM: Error, network object empty.");

                    resetObjectTransform();
                    exitMode();
                    return;
                }

                component1.ClaimOwnership();
                ZNetScene.instance.Destroy(HitPiece.gameObject);
                Debug.Log("AEM: Executed.");


                exitMode();
                return;
            }



            // CONTROL PRESSED
            if (Input.GetKeyDown(KeyCode.LeftControl))
            {
                controlFlag = true;
            }
            if (Input.GetKeyUp(KeyCode.LeftControl))
            {
                controlFlag = false;
            }

            // SHIFT PRESSED
            float distance       = gDistance;
            float scrollDistance = gScrollDistance;

            if (Input.GetKeyDown(KeyCode.LeftShift))
            {
                shiftFlag = true;
            }
            if (Input.GetKeyUp(KeyCode.LeftShift))
            {
                shiftFlag = false;
            }
            changeModificationSpeeds(shiftFlag);
            if (shiftFlag)
            {
                distance = gDistance * 3; scrollDistance = gScrollDistance * 3;
            }
            else
            {
                distance = gDistance; scrollDistance = gScrollDistance;
            }

            // LEFT ALT PRESSED
            if (Input.GetKeyDown(KeyCode.LeftAlt))
            {
                altFlag = true;
            }
            if (Input.GetKeyUp(KeyCode.LeftAlt))
            {
                altFlag = false;
            }


            // Maximum distance between player and placed piece
            if (Vector3.Distance(PlayerInstance.transform.position, HitPiece.transform.position) > PlayerInstance.m_maxPlaceDistance)
            {
                resetObjectTransform();
                exitMode();
            }

            // SCROLL CONTROLS
            if (Input.GetAxis("Mouse ScrollWheel") > 0f)
            {
                Quaternion rotation;
                if (controlFlag)
                {
                    rX++;
                    rotation = Quaternion.Euler(HitPiece.transform.eulerAngles.x + (scrollDistance * (float)rX), HitPiece.transform.eulerAngles.y, HitPiece.transform.eulerAngles.z); // forward to backwards
                }
                else
                {
                    if (altFlag)
                    {
                        rZ++;
                        rotation = Quaternion.Euler(HitPiece.transform.eulerAngles.x, HitPiece.transform.eulerAngles.y, HitPiece.transform.eulerAngles.z + (scrollDistance * (float)rZ)); // diagonal
                    }
                    else
                    {
                        rY++;
                        rotation = Quaternion.Euler(HitPiece.transform.eulerAngles.x, HitPiece.transform.eulerAngles.y + (scrollDistance * (float)rY), HitPiece.transform.eulerAngles.z); // left<->right
                    }
                }
                HitPiece.transform.rotation = rotation;
            }
            if (Input.GetAxis("Mouse ScrollWheel") < 0f)
            {
                Quaternion rotation;
                if (controlFlag)
                {
                    rX--;
                    rotation = Quaternion.Euler(HitPiece.transform.eulerAngles.x + (scrollDistance * (float)rX), HitPiece.transform.eulerAngles.y, HitPiece.transform.eulerAngles.z); // forward to backwards
                }
                else
                {
                    if (altFlag)
                    {
                        rZ--;
                        rotation = Quaternion.Euler(HitPiece.transform.eulerAngles.x, HitPiece.transform.eulerAngles.y, HitPiece.transform.eulerAngles.z + (scrollDistance * (float)rZ)); // diagonal
                    }
                    else
                    {
                        rY--;
                        rotation = Quaternion.Euler(HitPiece.transform.eulerAngles.x, HitPiece.transform.eulerAngles.y + (scrollDistance * (float)rY), HitPiece.transform.eulerAngles.z); // left<->right
                    }
                }

                HitPiece.transform.rotation = rotation;
            }

            // NUMPAD CONTROL
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                if (controlFlag)
                {
                    HitPiece.transform.Translate(Vector3.up * distance * Time.deltaTime);
                }
                else
                {
                    HitPiece.transform.Translate(Vector3.forward * distance * Time.deltaTime);
                }
            }
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                if (controlFlag)
                {
                    HitPiece.transform.Translate(Vector3.down * distance * Time.deltaTime);
                }
                else
                {
                    HitPiece.transform.Translate(Vector3.back * distance * Time.deltaTime);
                }
            }
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                HitPiece.transform.Translate(Vector3.left * distance * Time.deltaTime);
            }
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                HitPiece.transform.Translate(Vector3.right * distance * Time.deltaTime);
            }
        }
Exemplo n.º 11
0
        private static int DemolishPieces(float radius)
        {
            Player player = Player.m_localPlayer;

            if (!player)
            {
                return(0);
            }
            int count = 0;

            Collider[] array = Physics.OverlapSphere(player.transform.position, radius, destroyMask);
            for (int i = 0; i < array.Length; i++)
            {
                Piece piece = array[i].GetComponentInParent <Piece>();
                if (piece)
                {
                    if (!piece.IsCreator() && (piece.GetCreator() != 0 || !allowDestroyUncreated.Value))
                    {
                        continue;
                    }
                    if (!piece.m_canBeRemoved)
                    {
                        continue;
                    }
                    if (Location.IsInsideNoBuildLocation(piece.transform.position))
                    {
                        continue;
                    }
                    if (!PrivateArea.CheckAccess(piece.transform.position, 0f, true, false))
                    {
                        continue;
                    }
                    if (requireCraftingStation.Value && !Traverse.Create(player).Method("CheckCanRemovePiece", new object[] { piece }).GetValue <bool>())
                    {
                        continue;
                    }
                    ZNetView component = piece.GetComponent <ZNetView>();
                    if (component == null)
                    {
                        continue;
                    }
                    if (!piece.CanBeRemoved())
                    {
                        continue;
                    }
                    count++;
                    WearNTear component2 = piece.GetComponent <WearNTear>();
                    if (component2)
                    {
                        component2.Remove();
                    }
                    else
                    {
                        component.ClaimOwnership();
                        piece.DropResources();
                        piece.m_placeEffect.Create(piece.transform.position, piece.transform.rotation, piece.gameObject.transform, 1f);
                        player.m_removeEffects.Create(piece.transform.position, Quaternion.identity, null, 1f);
                        ZNetScene.instance.Destroy(piece.gameObject);
                    }
                }
            }
            return(count);
        }
Exemplo n.º 12
0
 public void SetText(string text)
 {
     m_nview.ClaimOwnership();
     m_nview.GetZDO().Set(Constants.Z_GivenName, text);
     Character_Awake_Patch.BroadcastUpdateCharacterName(ref m_nview, text);
 }
Exemplo n.º 13
0
        private static void listenToHotKeysAndDoWork()
        {
            float rX = 0;
            float rZ = 0;
            float rY = 0;

            if (Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.resetAdvancedEditingMode))
            {
                resetObjectTransform();
            }

            if (Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.confirmPlacementOfAdvancedEditingMode))
            {
                if (isContainer())
                {
                    dropContainerContents();
                }

                // PLACE NEW
                GameObject gameObject2 = UnityEngine.Object.Instantiate <GameObject>(HitPiece.gameObject, HitPiece.transform.position, HitPiece.transform.rotation);
                HitPiece.m_placeEffect.Create(HitPiece.transform.position, HitPiece.transform.rotation, gameObject2.transform, 1f);

                // REMOVE OLD
                ZNetView component1 = HitPiece.GetComponent <ZNetView>();
                if ((UnityEngine.Object)component1 == (UnityEngine.Object)null)
                {
                    Debug.Log("AEM: Error, network object empty.");

                    resetObjectTransform();
                    exitMode();
                    return;
                }

                component1.ClaimOwnership();
                ZNetScene.instance.Destroy(HitPiece.gameObject);
                Debug.Log("AEM: Executed.");

                exitMode();
                return;
            }

            // CONTROL PRESSED
            if (Input.GetKeyDown(KeyCode.LeftControl))
            {
                controlFlag = true;
            }
            if (Input.GetKeyUp(KeyCode.LeftControl))
            {
                controlFlag = false;
            }
            // SHIFT PRESSED
            if (Input.GetKeyDown(KeyCode.LeftShift))
            {
                shiftFlag = true;
            }
            if (Input.GetKeyUp(KeyCode.LeftShift))
            {
                shiftFlag = false;
            }
            // LEFT ALT PRESSED
            if (Input.GetKeyDown(KeyCode.LeftAlt))
            {
                altFlag = true;
            }
            if (Input.GetKeyUp(KeyCode.LeftAlt))
            {
                altFlag = false;
            }

            changeModificationSpeed();

            if (Input.GetKeyUp(Configuration.Current.AdvancedEditingMode.copyObjectRotation))
            {
                savedRotation = HitPiece.transform.rotation;
            }
            if (Input.GetKeyUp(Configuration.Current.AdvancedEditingMode.pasteObjectRotation))
            {
                HitPiece.transform.rotation = savedRotation;
            }

            // Maximum distance between player and placed piece
            if (Vector3.Distance(PlayerInstance.transform.position, HitPiece.transform.position) > PlayerInstance.m_maxPlaceDistance)
            {
                resetObjectTransform();
                exitMode();
            }

            var currentRotationAngleDegrees = BASE_ROTATION_ANGLE_DEGREES * currentModificationSpeed;

            if (Input.GetAxis("Mouse ScrollWheel") > 0f)
            {
                Quaternion rotation;
                if (controlFlag)
                {
                    rX++;
                    rotation = Quaternion.Euler(HitPiece.transform.eulerAngles.x + (currentRotationAngleDegrees * rX), HitPiece.transform.eulerAngles.y, HitPiece.transform.eulerAngles.z); // forward to backwards
                }
                else if (altFlag)
                {
                    rZ++;
                    rotation = Quaternion.Euler(HitPiece.transform.eulerAngles.x, HitPiece.transform.eulerAngles.y, HitPiece.transform.eulerAngles.z + (currentRotationAngleDegrees * rZ)); // diagonal
                }
                else
                {
                    rY++;
                    rotation = Quaternion.Euler(HitPiece.transform.eulerAngles.x, HitPiece.transform.eulerAngles.y + (currentRotationAngleDegrees * rY), HitPiece.transform.eulerAngles.z); // left<->right
                }
                HitPiece.transform.rotation = rotation;
            }
            if (Input.GetAxis("Mouse ScrollWheel") < 0f)
            {
                Quaternion rotation;
                if (controlFlag)
                {
                    rX--;
                    rotation = Quaternion.Euler(HitPiece.transform.eulerAngles.x + (currentRotationAngleDegrees * rX), HitPiece.transform.eulerAngles.y, HitPiece.transform.eulerAngles.z); // forward to backwards
                }
                else if (altFlag)
                {
                    rZ--;
                    rotation = Quaternion.Euler(HitPiece.transform.eulerAngles.x, HitPiece.transform.eulerAngles.y, HitPiece.transform.eulerAngles.z + (currentRotationAngleDegrees * rZ)); // diagonal
                }
                else
                {
                    rY--;
                    rotation = Quaternion.Euler(HitPiece.transform.eulerAngles.x, HitPiece.transform.eulerAngles.y + (currentRotationAngleDegrees * rY), HitPiece.transform.eulerAngles.z); // left<->right
                }

                HitPiece.transform.rotation = rotation;
            }

            var currentTranslationDistance = BASE_TRANSLATION_DISTANCE * currentModificationSpeed;

            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                if (controlFlag)
                {
                    HitPiece.transform.Translate(Vector3.up * currentTranslationDistance);
                }
                else
                {
                    HitPiece.transform.Translate(Vector3.forward * currentTranslationDistance);
                }
            }
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                if (controlFlag)
                {
                    HitPiece.transform.Translate(Vector3.down * currentTranslationDistance);
                }
                else
                {
                    HitPiece.transform.Translate(Vector3.back * currentTranslationDistance);
                }
            }
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                HitPiece.transform.Translate(Vector3.left * currentTranslationDistance);
            }
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                HitPiece.transform.Translate(Vector3.right * currentTranslationDistance);
            }
        }