static bool Player_CheckCanRemovePiece_Prefix(Piece piece, ref bool __result) { PlanPiece PlanPiece = piece.GetComponent <PlanPiece>(); if (PlanPiece) { __result = true; return(false); } return(true); }
static bool WearNTear_Destroy_Prefix(WearNTear __instance) { PlanPiece planPiece = __instance.GetComponent <PlanPiece>(); if (planPiece && planPiece.m_nView.IsOwner()) { //Don't // create noise // create fragments // play destroyed effects planPiece.Refund(all: true); ZNetScene.instance.Destroy(__instance.gameObject); return(false); } return(true); }
/// <summary> /// Instantiate plan prefabs for all distinct pieces in this blueprint. /// </summary> /// <returns></returns> private bool PlanInstantiate() { var ret = true; try { // Get all distinct pieces and create plan versions var pieces = new List <PieceEntry>(m_pieceEntries); var prefabs = new Dictionary <string, GameObject>(); foreach (var piece in pieces.GroupBy(x => x.name).Select(x => x.FirstOrDefault())) { // Check if plan prefab already exists string planPrefabName = $"{piece.name}_planned"; if (PrefabManager.Instance.GetPrefab(planPrefabName)) { continue; } // Clone vanilla prefab GameObject oldPrefab = PrefabManager.Instance.GetPrefab(piece.name); Piece oldPiece = oldPrefab.GetComponent <Piece>(); GameObject newPrefab = PrefabManager.Instance.CreateClonedPrefab(planPrefabName, oldPrefab); // A plan doesn't need fancy scripts foreach (var component in newPrefab.GetComponentsInChildren <MonoBehaviour>()) { Object.Destroy(component); } // Except the basics ZNetView zNetView = newPrefab.AddComponent <ZNetView>(); zNetView.m_persistent = true; Piece newPiece = newPrefab.AddComponent <Piece>(); newPiece.m_name = $"Planned {oldPiece.m_name}"; newPiece.m_resources = new Piece.Requirement[0]; newPiece.m_craftingStation = null; newPiece.m_placeEffect.m_effectPrefabs = new EffectList.EffectData[0]; newPiece.m_comfort = 0; newPiece.m_canBeRemoved = true; WearNTear wearNTear = newPrefab.AddComponent <WearNTear>(); wearNTear.m_noSupportWear = true; wearNTear.m_noRoofWear = false; wearNTear.m_autoCreateFragments = false; wearNTear.m_supports = true; wearNTear.m_hitEffect = new EffectList(); // Also add our PlanPiece script PlanPiece planPieceScript = newPrefab.AddComponent <PlanPiece>(); planPieceScript.originalPiece = oldPiece; // Add to known prefabs PrefabManager.Instance.AddPrefab(newPrefab); } } catch (Exception ex) { Logger.LogError($"Error while instantiating: {ex}"); ret = false; } return(ret); }