Ejemplo n.º 1
0
    // Token: 0x06000E64 RID: 3684 RVA: 0x00066E3C File Offset: 0x0006503C
    private void Awake()
    {
        if (this.m_areaMarker)
        {
            this.m_areaMarker.m_radius = this.m_radius;
        }
        this.m_nview = base.GetComponent <ZNetView>();
        if (!this.m_nview.IsValid())
        {
            return;
        }
        WearNTear component = base.GetComponent <WearNTear>();

        component.m_onDamaged = (Action)Delegate.Combine(component.m_onDamaged, new Action(this.OnDamaged));
        this.m_piece          = base.GetComponent <Piece>();
        if (this.m_areaMarker)
        {
            this.m_areaMarker.gameObject.SetActive(false);
        }
        if (this.m_inRangeEffect)
        {
            this.m_inRangeEffect.SetActive(false);
        }
        PrivateArea.m_allAreas.Add(this);
        base.InvokeRepeating("UpdateStatus", 0f, 1f);
        this.m_nview.Register <long>("ToggleEnabled", new Action <long, long>(this.RPC_ToggleEnabled));
        this.m_nview.Register <long, string>("TogglePermitted", new Action <long, long, string>(this.RPC_TogglePermitted));
        this.m_nview.Register("FlashShield", new Action <long>(this.RPC_FlashShield));
    }
Ejemplo n.º 2
0
    // Token: 0x06000F21 RID: 3873 RVA: 0x0006BFF4 File Offset: 0x0006A1F4
    private void Awake()
    {
        this.m_nview = base.GetComponent <ZNetView>();
        if (this.m_nview == null || this.m_nview.GetZDO() == null)
        {
            return;
        }
        Switch addOreSwitch = this.m_addOreSwitch;

        addOreSwitch.m_onUse = (Switch.Callback)Delegate.Combine(addOreSwitch.m_onUse, new Switch.Callback(this.OnAddOre));
        if (this.m_addWoodSwitch)
        {
            Switch addWoodSwitch = this.m_addWoodSwitch;
            addWoodSwitch.m_onUse = (Switch.Callback)Delegate.Combine(addWoodSwitch.m_onUse, new Switch.Callback(this.OnAddFuel));
        }
        if (this.m_emptyOreSwitch)
        {
            Switch emptyOreSwitch = this.m_emptyOreSwitch;
            emptyOreSwitch.m_onUse = (Switch.Callback)Delegate.Combine(emptyOreSwitch.m_onUse, new Switch.Callback(this.OnEmpty));
        }
        this.m_nview.Register <string>("AddOre", new Action <long, string>(this.RPC_AddOre));
        this.m_nview.Register("AddFuel", new Action <long>(this.RPC_AddFuel));
        this.m_nview.Register("EmptyProcessed", new Action <long>(this.RPC_EmptyProcessed));
        WearNTear component = base.GetComponent <WearNTear>();

        if (component)
        {
            WearNTear wearNTear = component;
            wearNTear.m_onDestroyed = (Action)Delegate.Combine(wearNTear.m_onDestroyed, new Action(this.OnDestroyed));
        }
        base.InvokeRepeating("UpdateSmelter", 1f, 1f);
    }
Ejemplo n.º 3
0
        private static float HowMuchIsTooMuch(ref WearNTear instance, float health, float damage)
        {
            float remainingHealth  = health - (damage / 100f * instance.m_health);
            float howMuchIsTooMuch = Mathf.Abs(minHealths[instance.GetInstanceID()] - remainingHealth);

            return(howMuchIsTooMuch / instance.m_health * 100f);
        }
Ejemplo n.º 4
0
            static void Postfix(WearNTear __instance)
            {
                if (!modEnabled.Value || !customIntegrityColors.Value)
                {
                    return;
                }

                float support    = Traverse.Create(__instance).Method("GetSupport").GetValue <float>();
                float maxSupport = Traverse.Create(__instance).Method("GetMaxSupport").GetValue <float>();

                if (support < 0 || maxSupport < support)
                {
                    return;
                }
                Color color;

                if (support / maxSupport >= 0.5f)
                {
                    color = Color.Lerp(midIntegrityColor.Value, highIntegrityColor.Value, (support / maxSupport - 0.5f) * 2);
                }
                else
                {
                    color = Color.Lerp(lowIntegrityColor.Value, midIntegrityColor.Value, support / maxSupport * 2);
                }

                foreach (Renderer renderer in Traverse.Create(__instance).Method("GetHighlightRenderers").GetValue <List <Renderer> >())
                {
                    foreach (Material material in renderer.materials)
                    {
                        material.SetColor("_EmissionColor", color * 0.4f);
                        material.color = color;
                    }
                }
            }
Ejemplo n.º 5
0
        private static bool Prefix(ref WearNTear __instance, ref float damage)
        {
            // Gets the name of the method calling the ApplyDamage method
            StackTrace stackTrace    = new StackTrace();
            string     callingMethod = stackTrace.GetFrame(2).GetMethod().Name;

            if (!(Configuration.Current.StructuralIntegrity.IsEnabled && __instance.m_piece && __instance.m_piece.IsPlacedByPlayer() && callingMethod != "UpdateWear"))
            {
                return(true);
            }

            if (__instance.m_piece.m_name.StartsWith("$ship"))
            {
                if (Configuration.Current.StructuralIntegrity.disableDamageToPlayerBoats ||
                    (Configuration.Current.StructuralIntegrity.disableWaterDamageToPlayerBoats &&
                     stackTrace.GetFrame(15).GetMethod().Name == "UpdateWaterForce"))
                {
                    return(false);
                }

                return(true);
            }

            return(!Configuration.Current.StructuralIntegrity.disableDamageToPlayerStructures);
        }
Ejemplo n.º 6
0
        private static bool OverrideWearNTear(ref WearNTear instance)
        {
            if (DamageFilter.ALL.Equals(damageFilter.Value))
            {
                return(true);
            }
            foreach (string name in damageFilterValues.Value.Split(','))
            {
                if (instance.gameObject.name.Contains(name))
                {
                    switch (damageFilter.Value)
                    {
                    case DamageFilter.INCLUSIVE:
                        return(true);

                    case DamageFilter.EXCLUSIVE:
                        return(false);

                    default:
                        return(true);
                    }
                }
            }
            return(DamageFilter.EXCLUSIVE.Equals(damageFilter.Value));
        }
        private static void HighlightPiece(WearNTear wearNTear, float healthPercentage)
        {
            if (wearNTear.m_oldMaterials == null || wearNTear.m_oldMaterials.Count == 0)
            {
                StoreOldMaterials(wearNTear);
            }

            if (!HighlightedWears.Contains(wearNTear))
            {
                HighlightedWears.Add(wearNTear);
            }

            WearsDataCache[wearNTear].healthPercentage = healthPercentage;

            Color color = Color.Lerp(ZeroHealthColor.Value, FullHealthColor.Value, healthPercentage);

            foreach (WearNTear.OldMeshData oldMaterial in wearNTear.m_oldMaterials)
            {
                if ((bool)oldMaterial.m_renderer)
                {
                    Material[] materials = oldMaterial.m_renderer.materials;
                    foreach (Material obj in materials)
                    {
                        obj.SetColor(EmmissionID, color * 0.4f);
                        obj.color = color;
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public static void OnPortalDestroy(WearNTear instance)
        {
            if (ZNet.instance.IsServerInstance())
            {
                return;
            }

            if (instance.m_piece && instance.m_piece.m_name == "$piece_portal")
            {
                Logger.LogInfo("Portal destroyed");

                if (ZNet.instance.IsLocalInstance())
                {
                    Logger.LogInfo("Sending portal sync request to server");

                    ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), nameof(RPC_TeleporterSync), new ZPackage());
                }

                if (ZNet.instance.IsClientInstance())
                {
                    Logger.LogInfo("Sending deferred portal sync request to server");

                    Task.Factory.StartNew(() =>
                    {
                        // Wait for ZDO to be sent else server won't have accurate information to send back
                        Thread.Sleep(5000);

                        // Send trigger to server
                        ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), nameof(RPC_TeleporterSync), new ZPackage());
                    });
                }
            }
        }
Ejemplo n.º 9
0
        public void Awake()
        {
            if (m_forceDisableInit)
            {
                Object.Destroy(this);
                return;
            }

            if (!originalPiece)
            {
                InvalidPlanPiece();
                return;
            }

            //logger.LogInfo("Prefab loaded for " + name + " -> " + originalPrefab.name);
            DisablePiece(gameObject);

            //logger.LogInfo("PlanPiece awake: " + gameObject.GetInstanceID());
            m_wearNTear = GetComponent <WearNTear>();
            m_nView     = GetComponent <ZNetView>();
            if (m_nView.IsOwner())
            {
                m_nView.GetZDO().Set("support", 0f);
            }
            m_nView.Register <bool>("Refund", RPC_Refund);
            m_nView.Register <string, int>("AddResource", RPC_AddResource);
            m_nView.Register("SpawnPieceAndDestroy", RPC_SpawnPieceAndDestroy);
            UpdateHoverText();
        }
            public static bool Prefix(WearNTear __instance)
            {
                if (__instance.m_oldMaterials == null)
                {
                    __instance.m_oldMaterials = new List <WearNTear.OldMeshData>();
                    foreach (Renderer highlightRenderer in __instance.GetHighlightRenderers())
                    {
                        WearNTear.OldMeshData item = default(WearNTear.OldMeshData);
                        item.m_materials     = highlightRenderer.sharedMaterials;
                        item.m_color         = new Color[item.m_materials.Length];
                        item.m_emissiveColor = new Color[item.m_materials.Length];
                        for (int i = 0; i < item.m_materials.Length; i++)
                        {
                            if (item.m_materials[i].HasProperty("_Color"))
                            {
                                item.m_color[i] = item.m_materials[i].GetColor("_Color");
                            }
                            if (item.m_materials[i].HasProperty("_EmissionColor"))
                            {
                                item.m_emissiveColor[i] = item.m_materials[i].GetColor("_EmissionColor");
                            }
                        }
                        item.m_renderer = highlightRenderer;
                        __instance.m_oldMaterials.Add(item);
                    }
                }
                Color color = new Color(0.6f, 0.8f, 1f);

                float supportColorValue;

                if (!_modEnabled)
                {
                    supportColorValue = __instance.GetSupportColorValue();
                    if (supportColorValue >= 0f)
                    {
                        color = Color.Lerp(new Color(1f, 0f, 0f), new Color(0f, 1f, 0f), supportColorValue);
                        Color.RGBToHSV(color, out var H, out var S, out var V);
                        S     = Mathf.Lerp(1f, 0.5f, supportColorValue);
                        V     = Mathf.Lerp(1.2f, 0.9f, supportColorValue);
                        color = Color.HSVToRGB(H, S, V);
                    }
                }

                foreach (WearNTear.OldMeshData oldMaterial in __instance.m_oldMaterials)
                {
                    if ((bool)oldMaterial.m_renderer)
                    {
                        Material[] materials = oldMaterial.m_renderer.materials;
                        foreach (Material obj in materials)
                        {
                            obj.SetColor("_EmissionColor", color * 0.4f);
                            obj.color = color;
                        }
                    }
                }
                __instance.CancelInvoke("ResetHighlight");
                __instance.Invoke("ResetHighlight", 0.2f);
                return(false);
            }
Ejemplo n.º 11
0
 static bool WearNTear_Damage_Prefix(WearNTear __instance)
 {
     if (__instance.GetComponent <PlanPiece>())
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 12
0
 static void Prefix(WearNTear __instance, ref HitData hit)
 {
     if (__instance.gameObject.GetComponent <Ship>() == null)
     {
         return;
     }
     MultiplyDamage(ref hit, damageMult.Value);
 }
Ejemplo n.º 13
0
 static bool Prefix(WearNTear __instance, long sender)
 {
     if (!modEnabled.Value || !restrictToCreator.Value || sender == Game.instance.GetPlayerProfile().GetPlayerID())
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 14
0
        public PlanPiecePrefab(Piece piece) : base(piece.gameObject.name + PlannedSuffix, piece.gameObject.name, PlanHammerPieceTableName)
        {
            this.originalPiece                  = piece;
            Piece.m_name                        = Localization.instance.Localize("$item_plan_piece_name", originalPiece.m_name);
            Piece.m_description                 = Localization.instance.Localize("$item_plan_piece_description", originalPiece.m_name);
            Piece.m_resources                   = new Piece.Requirement[0];
            Piece.m_craftingStation             = null;
            Piece.m_placeEffect.m_effectPrefabs = new EffectList.EffectData[0];
            Piece.m_comfort                     = 0;
            Piece.m_canBeRemoved                = true;

            Piece.m_category                = originalPiece.m_category;
            Piece.m_groundOnly              = originalPiece.m_groundOnly;
            Piece.m_groundPiece             = originalPiece.m_groundPiece;
            Piece.m_icon                    = originalPiece.m_icon;
            Piece.m_inCeilingOnly           = originalPiece.m_inCeilingOnly;
            Piece.m_isUpgrade               = originalPiece.m_isUpgrade;
            Piece.m_haveCenter              = originalPiece.m_haveCenter;
            Piece.m_dlc                     = originalPiece.m_dlc;
            Piece.m_allowAltGroundPlacement = originalPiece.m_allowAltGroundPlacement;
            Piece.m_allowedInDungeons       = originalPiece.m_allowedInDungeons;

            this.PieceTable = PlanHammerPieceTableName;

            WearNTear wearNTear = PiecePrefab.GetComponent <WearNTear>();

            if (wearNTear == null)
            {
                wearNTear = PiecePrefab.AddComponent <WearNTear>();
            }

            wearNTear.m_noSupportWear       = true;
            wearNTear.m_noRoofWear          = false;
            wearNTear.m_autoCreateFragments = false;
            wearNTear.m_supports            = true;
            wearNTear.m_hitEffect           = new EffectList();
            wearNTear.m_destroyedEffect     = new EffectList();
            wearNTear.m_destroyNoise        = 0f;
            wearNTear.m_hitNoise            = 0f;

            PlanPiece planPieceScript = PiecePrefab.AddComponent <PlanPiece>();

            planPieceScript.originalPiece = originalPiece;
            planToOriginalMap.Add(Piece, originalPiece);
            if (logComponents)
            {
                StringBuilder sb = new StringBuilder("Components in prefab: " + PiecePrefab.name + "\n");
                sb.Append("Components in prefab: " + PiecePrefab.name + "\n");
                sb.Append($" Prefab: {PiecePrefab.name} -> {PiecePrefab.gameObject}\n");
                foreach (Component component in PiecePrefab.GetComponents <Component>())
                {
                    sb.Append($" {component.GetType()} -> {component.name}\n");
                }
                Jotunn.Logger.LogWarning(sb.ToString());
            }

            DisablePiece(PiecePrefab);
        }
Ejemplo n.º 15
0
 static bool WearNTear_GetSupport_Prefix(WearNTear __instance, ref float __result)
 {
     if (__instance.GetComponent <PlanPiece>())
     {
         __result = 0f;
         return(false);
     }
     return(true);
 }
Ejemplo n.º 16
0
        static void HighlightPiece(Piece p)
        {
            WearNTear component = p.GetComponent <WearNTear>();

            if (component)
            {
                component.Highlight();
            }
        }
Ejemplo n.º 17
0
 static bool WearNTear_HaveSupport_Prefix(WearNTear __instance, ref bool __result)
 {
     if (__instance.GetComponent <PlanPiece>())
     {
         __result = true;
         return(false);
     }
     return(true);
 }
Ejemplo n.º 18
0
 private static void OnHighlight(On.WearNTear.orig_Highlight orig, WearNTear self)
 {
     if (self.TryGetComponent(out PlanPiece planPiece))
     {
         planPiece.Highlight();
         return;
     }
     orig(self);
 }
Ejemplo n.º 19
0
        private static bool Prefix(ref WearNTear __instance, ref float damage)
        {
            if (Configuration.Current.StructuralIntegrity.IsEnabled && Configuration.Current.StructuralIntegrity.disableDamageToPlayerStructures && __instance.m_piece && __instance.m_piece.IsPlacedByPlayer())
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 20
0
        private static void SettleIntegrityForMaterial(GameObject location, WearNTear.MaterialType material)
        {
            Dictionary <WearNTear, float> remainingObjects = InitSettlingObjects(location, material);

            int numTotalObjectsDeleted     = 0;
            var objectsToRemoveInIteration = new HashSet <WearNTear>();
            var objectsToDelete            = new HashSet <WearNTear>();

            while (remainingObjects.Count > 0)
            {
                objectsToRemoveInIteration.Clear();
                foreach (var wearAndOldSupport in remainingObjects)
                {
                    UpdateSupport(wearAndOldSupport.Key);
                }
                foreach (var wearAndOldSupport in remainingObjects)
                {
                    WearNTear wear       = wearAndOldSupport.Key;
                    float     oldSupport = wearAndOldSupport.Value;

                    UpdateSupport(wear);

                    float newSupport = wear.m_support;
                    if (newSupport == oldSupport)
                    {
                        objectsToRemoveInIteration.Add(wear);
                    }
                    else
                    {
                        remainingObjects[wear] = newSupport;
                    }

                    if (!wear.HaveSupport())
                    {
                        objectsToDelete.Add(wear);
                    }
                }

                foreach (var removeMe in objectsToRemoveInIteration)
                {
                    remainingObjects.Remove(removeMe);
                }

                foreach (var deleteMe in objectsToDelete)
                {
                    remainingObjects.Remove(deleteMe);
                    UnityEngine.Object.DestroyImmediate(deleteMe.gameObject);
                }
                numTotalObjectsDeleted += objectsToDelete.Count;
            }

            if (numTotalObjectsDeleted > 0)
            {
                Jotunn.Logger.LogInfo($"Settling {location.name} - Deleted {numTotalObjectsDeleted} objects in {material} material pass");
            }
        }
 private void ClearVars()
 {
     HighlightedWears.Clear();
     WearsDataCache.Clear();
     lastAddedToCache  = null;
     firstElementCache = null;
     _modEnabled       = false;
     _needsFirstUpdate = false;
     isUpdatingAsync   = false;
 }
Ejemplo n.º 22
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.º 23
0
 public static void CraftingStation_Start(ref CraftingStation __instance)
 {
     if (disableWeatherDamageForCraftingStation.Value)
     {
         WearNTear wearNTear = __instance.GetComponent <WearNTear>();
         if (wearNTear)
         {
             wearNTear.m_noRoofWear = false;
         }
     }
 }
Ejemplo n.º 24
0
 static bool Prefix(WearNTear __instance, ref HitData hit, ZNetView ___m_nview)
 {
     if (___m_nview != null)
     {
         if (PrivateArea.CheckInPrivateArea(__instance.transform.position))
         {
             ApplyDamageReduction(ref hit, configConstructionDamageReduction.Value);
         }
     }
     return(true);
 }
Ejemplo n.º 25
0
        private static void UpdateSupport(WearNTear wear)
        {
            if (wear.m_colliders == null)
            {
                wear.SetupColliders();
            }

            var     materialProperties = materialLookup[wear.m_materialType];
            Vector3 cOM        = wear.GetCOM();
            float   maxSupport = 0f;

            foreach (WearNTear.BoundData bound in wear.m_bounds)
            {
                int numColliders = Physics.OverlapBoxNonAlloc(bound.m_pos, bound.m_size, tempColliders, bound.m_rot, WearNTear.m_rayMask);
                for (int i = 0; i < numColliders; i++)
                {
                    Collider collider = tempColliders[i];
                    if (wear.m_colliders.Contains(collider) || collider.attachedRigidbody != null || collider.isTrigger)
                    {
                        continue;
                    }

                    WearNTear touchingWear = collider.GetComponentInParent <WearNTear>();
                    if (touchingWear == null)
                    {
                        wear.m_support = materialProperties.maxSupport;
                        return;
                    }

                    if (!touchingWear.m_supports)
                    {
                        continue;
                    }

                    float distanceToTouching = Vector3.Distance(cOM, touchingWear.transform.position) + 0.1f;
                    float support            = touchingWear.m_support;

                    maxSupport = Mathf.Max(maxSupport, support - materialProperties.horizontalLoss * distanceToTouching * support);
                    Vector3 vector = wear.FindSupportPoint(cOM, touchingWear, collider);
                    if (vector.y < cOM.y + 0.05f)
                    {
                        Vector3 normalized = (vector - cOM).normalized;
                        if (normalized.y < 0f)
                        {
                            float angle         = Mathf.Acos(1f - Mathf.Abs(normalized.y)) / ((float)Math.PI / 2f);
                            float loss          = Mathf.Lerp(materialProperties.horizontalLoss, materialProperties.verticalLoss, angle);
                            float angledSupport = support - loss * distanceToTouching * support;
                            maxSupport = Mathf.Max(maxSupport, angledSupport);
                        }
                    }
                }
            }
            wear.m_support = Mathf.Min(maxSupport, materialProperties.maxSupport);
        }
Ejemplo n.º 26
0
 static void Prefix(WearNTear __instance, ref HitData hit)
 {
     if (__instance.gameObject.GetComponent <Ship>() == null)
     {
         return;
     }
     if (IsPlayerControlling(__instance.gameObject.GetComponent <Ship>()))
     {
         MultiplyDamage(ref hit, GetSkillFactorMultiplier(sailingConfig.MaxDamageReduction));  // up to 50% dmg reduction
     }
 }
Ejemplo n.º 27
0
 private static void Postfix(WearNTear __instance)
 {
     try
     {
         PostfixEvent?.Invoke(__instance);
     }
     catch (Exception ex)
     {
         Logger.LogError(ex.Message + Environment.NewLine + ex.StackTrace);
     }
 }
Ejemplo n.º 28
0
 public static bool Damage(WearNTear __instance, ref HitData hit)
 {
     if (AccessTools.FieldRefAccess <WearNTear, ZNetView>(__instance, "m_nview").IsValid())
     {
         var Ply = Player.m_localPlayer;
         if (Ply != null && PrivateArea.CheckInPrivateArea(hit.m_point, true))
         {
             return(SmartBepInMods.Tools.Patching.Constants.CONST.SKIP);
         }
     }
     return(SmartBepInMods.Tools.Patching.Constants.CONST.NOSKIP);
 }
Ejemplo n.º 29
0
        private void UpdatePrefabs()
        {
            try
            {
                var           stoneGolemTrophyPrefab = PrefabManager.Instance.GetPrefab("TrophySGolem");
                var           surtlingCorePrefab     = PrefabManager.Instance.GetPrefab("SurtlingCore");
                var           raftPrefab             = PrefabManager.Instance.GetPrefab("Raft");
                Ship          raftShip          = raftPrefab.GetComponent <Ship>();
                ShipControlls raftShipControlls = raftPrefab.GetComponentInChildren <ShipControlls>();
                GameObject    onBoardTrigger    = Object.Instantiate(new GameObject(), airshipPiece.PiecePrefab.transform);
                onBoardTrigger.name = "OnBoardTrigger";
                BoxCollider onBoardCollider = onBoardTrigger.AddComponent <BoxCollider>();
                onBoardCollider.isTrigger = true;
                onBoardTrigger.layer      = characterTriggerLayer;
                onBoardTrigger.transform.localPosition = new Vector3(0, 1, 0);
                onBoardTrigger.transform.localScale    = Vector3.one * 2;

                GameObject attachPoint = Object.Instantiate(new GameObject(), airshipPiece.PiecePrefab.transform);
                attachPoint.name = "attachpoint";
                attachPoint.transform.localRotation = Quaternion.Euler(0f, 90f, 0f);
                GameObject shipObject = Object.Instantiate(new GameObject(), airshipPiece.PiecePrefab.transform);
                shipObject.name = "ship";
                GameObject collidersObject = Object.Instantiate(new GameObject(), shipObject.transform);
                collidersObject.name  = "colliders";
                collidersObject.layer = vehicleLayer;
                var colliderObject = airshipPiece.PiecePrefab.transform.Find("collider").gameObject;
                colliderObject.transform.SetParent(collidersObject.transform);
                colliderObject.name  = "Cube";
                colliderObject.layer = vehicleLayer;
                BoxCollider boxCollider = colliderObject.GetComponent <BoxCollider>();
                boxCollider.material = raftPrefab.transform.Find("ship/colliders/Cube").GetComponent <BoxCollider>().material;

                WearNTear wearNTear = airshipPiece.Piece.GetComponent <WearNTear>();
                wearNTear.m_noSupportWear = false;
                wearNTear.m_supports      = true;

                airshipPiece.Piece.m_icon = stoneGolemTrophyPrefab.GetComponent <ItemDrop>().m_itemData.m_shared.m_icons[0];

                airshipPiece.PiecePrefab.AddComponent <AirshipBase>();
                Airship airship = airshipPiece.PiecePrefab.AddComponent <Airship>();
                airship.m_controlGuiPos = raftShip.m_controlGuiPos;
                AddVisualPiece(stoneGolemTrophyPrefab, "crystal1", new Vector3(1f, 0f, -1f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
                var surtlingCore = AddVisualPiece(surtlingCorePrefab, "surtlingCore", new Vector3(1f, 1f, 0f), Quaternion.Euler(0f, 0f, 0f), Vector3.one);
                AirshipControlls airshipControlls = surtlingCore.AddComponent <AirshipControlls>();
                airshipControlls.m_attachAnimation = raftShipControlls.m_attachAnimation;
                airshipControlls.m_maxUseRange     = raftShipControlls.m_maxUseRange;

                AddVisualPiece(stoneGolemTrophyPrefab, "crystal2", new Vector3(1f, 0f, 1f), Quaternion.Euler(0f, 180f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
            } finally
            {
                PieceManager.OnPiecesRegistered -= UpdatePrefabs;
            }
        }
            private static bool Prefix(WearNTear __instance, HitData hit)
            {
                if (WorldofValheimZones.ServerMode)
                {
                    return(true);
                }

                bool isInArea = false;

                // Is the area we are searching in a Warded area.
                if (Client.Ward.Damage && PrivateArea.CheckInPrivateArea(__instance.transform.position, false))
                {
                    ZDOID attacker = hit.m_attacker;
                    bool  isplayer = false;
                    foreach (var character in Character.GetAllCharacters())
                    {
                        if (character.GetZDOID() == attacker)
                        {
                            if (character.GetComponent <Player>())
                            {
                                isplayer = true;
                            }
                        }
                    }
                    // It's a player so lets see if it has access.
                    if (isplayer)
                    {
                        if (!PrivateArea.CheckAccess(Player.m_localPlayer.transform.position, 0f, true, false))
                        {
                            Util.DoAreaEffectW(__instance.transform.position);
                            MessageHud.instance.ShowMessage(MessageHud.MessageType.TopLeft, "This is a Warded Area", 0, null);
                            isInArea = true;
                            return(!isInArea);
                        }
                    }
                    else
                    {
                        // It's not a player so lets send out a Ward notification and block the damage.
                        PrivateArea.CheckInPrivateArea(__instance.transform.position, true);
                        isInArea = true;
                        return(!isInArea);
                    }
                }
                // Is the user restricted by NoBuildDamage?
                if (Util.RestrictionCheck("nobuilddamage"))
                {
                    isInArea = true;
                    Util.DoAreaEffect(__instance.transform.position + Vector3.up * 0.5f);
                    MessageHud.instance.ShowMessage(MessageHud.MessageType.TopLeft, "This is a Private Area", 0, null);
                }
                return(!isInArea);
            }