Ejemplo n.º 1
0
        public void CommonEffect(Player player)
        {
            //Spawn location structure
            var pos = originLocation;
            var rot = Quaternion.LookRotation(originForward) * Quaternion.Euler(0, 90, 0);
            var getLocationMethods = typeof(ZoneSystem).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
            var method             = (from MethodInfo m in getLocationMethods where m.Name == "GetLocation" && m.GetParameters().Any(param => param.ParameterType == typeof(string)) select m).FirstOrDefault();

            if (method == null)
            {
                throw new NullReferenceException("Could not find ZoneSystem.GetLocation method");
            }
            ZoneSystem.ZoneLocation location = (ZoneSystem.ZoneLocation)method.Invoke(ZoneSystem.instance, new object[] { houseLocationName });
            //m_didZoneTest = true;
            List <GameObject> spawnedGhostObjects = new List <GameObject>();

            typeof(ZoneSystem).GetMethod("SpawnLocation", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(ZoneSystem.instance, new object[] { location, spawnSeed, pos, rot, ZoneSystem.SpawnMode.Full, spawnedGhostObjects });

            //Set up for bed spawning
            var bedPos = originLocation + originForward * commonBedDisplacement;
            var bedRot = rot;

            //Get piece table
            var pieceTableName = "_HammerPieceTable";
            var pieceTable     = (from PieceTable table in Resources.FindObjectsOfTypeAll <PieceTable>() where table.gameObject.name == pieceTableName select table).FirstOrDefault();

            if (pieceTable == null || pieceTable.m_pieces.Count <= 0)
            {
                throw new NullReferenceException("Could not find hammer piece table");
            }
            pieceTable.UpdateAvailable(null, null, false, true); //noPlacementCost set to true - other fields don't matter

            //Select piece
            int        category   = -1;
            Vector2Int pieceIndex = pieceTable.GetPieceIndexVec(bedPieceName, ref category);

            pieceTable.SetCategory(category);
            pieceTable.SetSelected(pieceIndex);

            //Place piece
            var piece = pieceTable.GetSelectedPiece();

            piece.m_description = magicBedDesc;
            TerrainModifier.SetTriggerOnPlaced(trigger: true);
            GameObject gameObject = UnityEngine.Object.Instantiate(piece.gameObject, bedPos, bedRot);

            TerrainModifier.SetTriggerOnPlaced(trigger: false);
            WearNTear wear = gameObject.GetComponent <WearNTear>();

            if ((bool)wear)
            {
                wear.OnPlaced();
            }
            piece.m_description = "";
        }
Ejemplo n.º 2
0
        private void RPC_SpawnPieceAndDestroy(long sender, long creatorID)
        {
            if (!m_nView.IsOwner())
            {
                return;
            }
            GameObject actualPiece = Object.Instantiate(originalPiece.gameObject, gameObject.transform.position, gameObject.transform.rotation);

            // Register special effects
            if (creatorID == Player.m_localPlayer.GetPlayerID())
            {
                CraftingStation craftingStation = actualPiece.GetComponentInChildren <CraftingStation>();
                if (craftingStation)
                {
                    Player.m_localPlayer.AddKnownStation(craftingStation);
                }
                PrivateArea privateArea = actualPiece.GetComponent <PrivateArea>();
                if (privateArea)
                {
                    privateArea.Setup(Game.instance.GetPlayerProfile().GetName());
                }
                if (actualPiece.TryGetComponent(out Piece newPiece))
                {
                    newPiece.m_placeEffect.Create(actualPiece.transform.position, actualPiece.transform.rotation, actualPiece.transform, 1f);
                }

                // Count up player builds
                Game.instance.GetPlayerProfile().m_playerStats.m_builds++;
            }
            WearNTear wearntear = gameObject.GetComponent <WearNTear>();

            if (wearntear)
            {
                wearntear.OnPlaced();
            }
            TextReceiver textReceiver = gameObject.GetComponent <TextReceiver>();

            if (textReceiver != null)
            {
                textReceiver.SetText(m_nView.GetZDO().GetString(zdoAdditionalInfo));
            }

            actualPiece.GetComponent <Piece>().SetCreator(creatorID);

#if DEBUG
            Jotunn.Logger.LogDebug("Plan spawn actual piece: " + actualPiece + " -> Destroying self");
#endif
            BlueprintManager.Instance.PlanPieceRemovedFromBlueprint(this);
            ZNetScene.instance.Destroy(this.gameObject);
        }
Ejemplo n.º 3
0
        private void RPC_SpawnPieceAndDestroy(long sender)
        {
            if (!m_nView.IsOwner())
            {
                return;
            }
            GameObject actualPiece = Object.Instantiate(originalPiece.gameObject, gameObject.transform.position, gameObject.transform.rotation);
            WearNTear  wearNTear   = actualPiece.GetComponent <WearNTear>();

            if (wearNTear)
            {
                wearNTear.OnPlaced();
            }
            logger.LogDebug("Plan spawn actual piece: " + actualPiece + " -> Destroying self");
            ZNetScene.instance.Destroy(this.gameObject);
            Destroy(this.gameObject);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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));
        }