示例#1
0
 private void RPC_Refund(long sender, bool all)
 {
     if (m_nView.IsOwner())
     {
         Refund(all);
     }
 }
示例#2
0
 private void OnDestroyed()
 {
     BlueprintManager.Instance.PlanPieceRemovedFromBlueprint(this);
     if (m_nView.IsOwner())
     {
         Refund(true);
     }
 }
示例#3
0
        internal void DisperseSeeds()
        {
            if (!m_nview ||
                !m_nview.IsOwner() ||
                !m_nview.IsValid() ||
                Player.m_localPlayer == null)
            {
                return;
            }

            bool dispersed   = false;
            int  totalPlaced = 0;
            int  maxRetries  = configMaxRetries.Value;

            while (GetQueueSize() > 0)
            {
                string currentSeed  = GetQueuedSeed();
                int    currentCount = GetQueuedSeedCount();
                if (!seedPrefabMap.ContainsKey(currentSeed))
                {
                    logger.LogWarning("Key '" + currentSeed + "' not found in seedPrefabMap");
                    DumpQueueDetails();
                    logger.LogWarning("Shifting queue to remove invalid entry");
                    ShiftQueueDown();
                    return;
                }

                ItemConversion  conversion = seedPrefabMap[currentSeed];
                PlacementStatus status     = TryPlacePlant(conversion, maxRetries);
                SetStatus(status);
                if (status == PlacementStatus.Planting)
                {
                    totalPlaced += 1;
                    dispersed    = true;
                }
                else if (status == PlacementStatus.WrongBiome)
                {
                    logger.LogDebug("Wrong biome deteced, moving " + currentSeed + " to end of queue");

                    MoveToEndOfQueue(currentSeed, currentCount, status);
                    break;
                }
                else if (status == PlacementStatus.NoRoom)
                {
                    break;
                }
                if (totalPlaced >= configDispersionCount.Value)
                {
                    break;
                }
            }
            ;

            if (dispersed)
            {
                m_disperseEffects.Create(transform.position, Quaternion.Euler(0f, Random.Range(0, 360), 0f), transform, configRadius.Value / 5f);
            }
        }
        private void RPC_DropCores(long sender)
        {
            if (m_nview.IsOwner())
            {
                Debug.Log("Drop all cores");

                foreach (string coreName in dropTable.Keys)
                {
                    DropCores(dropTable[coreName], GetCoreCount(coreName));
                    SetCoreCount(coreName, 0);
                }
                UpdateSmelterValues();
            }
        }
 private void RPC_LockContainersRequest(long uid, long playerId, bool shouldLock)
 {
     Plugin.Log.LogDebug("Player " + uid + " wants to craft with " + _container.gameObject.name + "   im: " +
                         ZDOMan.instance.GetMyID());
     if (!_zNetView.IsOwner())
     {
         Plugin.Log.LogDebug("  but im not the owner");
     }
     else if (shouldLock && (_container.IsInUse() || (bool)_container.m_wagon && _container.m_wagon.InUse()) &&
              uid != ZNet.instance.GetUID())
     {
         Plugin.Log.LogDebug("  in use");
         _zNetView.InvokeRPC(uid, "LockContainersResponse", playerId, shouldLock, false);
     }
     else if (!_container.CheckAccess(playerId))
     {
         Plugin.Log.LogDebug("  not yours");
         _zNetView.InvokeRPC(uid, "LockContainersResponse", playerId, shouldLock, false);
     }
     else
     {
         _container.SetInUse(shouldLock);
         ZDOMan.instance.ForceSendZDO(uid, _zNetView.GetZDO().m_uid);
         _zNetView.GetZDO().SetOwner(uid);
         _zNetView.InvokeRPC(uid, "LockContainersResponse", playerId, shouldLock, true);
     }
 }
示例#6
0
            private static MobAIBase GetOrCreateMob(string uniqueId, MonsterAI instance, ZNetView nview)
            {
                MobAIBase mob;

                if (MobManager.IsAliveMob(uniqueId))
                {
                    mob = MobManager.AliveMobs[uniqueId];
                    if (!mob.HasInstance())
                    {
                        mob = MobManager.CreateMob(uniqueId, instance);
                        MobManager.AliveMobs[uniqueId] = mob;
                        Common.Dbgl($"Replacing old instance of mob '{mob.Character.m_name}', IsOwner:{nview.IsOwner()}");
                    }
                    return(mob);
                }
                else
                {
                    mob = MobManager.CreateMob(uniqueId, instance);
                }

                if (mob == null)
                {
                    Common.Dbgl($"Failed to create mob {uniqueId}', IsOwner:{nview.IsOwner()}");
                    return(null);
                }

                Common.Dbgl($"Adding new instance of mob '{mob.Character.GetHoverName()}', IsOwner:{nview.IsOwner()}");
                MobManager.AliveMobs.Add(uniqueId, mob);
                return(mob);
            }
示例#7
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();
        }
示例#8
0
        private static IEnumerator DropNow(Ragdoll ragdoll, ZNetView nview, EffectList removeEffect)
        {
            if (dropDelay.Value < 0)
            {
                context.StartCoroutine(DestroyNow(ragdoll, nview, removeEffect));
                yield break;
            }

            Dbgl($"delaying dropping loot");
            yield return(new WaitForSeconds(dropDelay.Value));

            if (!modEnabled.Value)
            {
                yield break;
            }

            if (!nview.IsValid() || !nview.IsOwner())
            {
                context.StartCoroutine(DropNow(ragdoll, nview, removeEffect));
                yield break;
            }
            Dbgl($"dropping loot");
            Vector3 averageBodyPosition = ragdoll.GetAverageBodyPosition();

            Traverse.Create(ragdoll).Method("SpawnLoot", new object[] { averageBodyPosition }).GetValue();
            context.StartCoroutine(DestroyNow(ragdoll, nview, removeEffect));
        }
示例#9
0
            static void Postfix(CookingStation __instance, ZNetView ___m_nview)
            {
                if (!modEnabled.Value || !___m_nview.IsValid() || !___m_nview.IsOwner() || !EffectArea.IsPointInsideArea(__instance.transform.position, EffectArea.Type.Burning, 0.25f))
                {
                    return;
                }
                for (int i = 0; i < __instance.m_slots.Length; i++)
                {
                    string itemName = ___m_nview.GetZDO().GetString("slot" + i, "");

                    float num = ___m_nview.GetZDO().GetFloat("slot" + i, 0f);
                    if (itemName != "" && itemName != __instance.m_overCookedItem.name && itemName != null)
                    {
                        CookingStation.ItemConversion itemConversion = Traverse.Create(__instance).Method("GetItemConversion", new object[] { itemName }).GetValue <CookingStation.ItemConversion>();
                        if (num > itemConversion.m_cookTime && itemName == itemConversion.m_to.name)
                        {
                            if (autoPop.Value)
                            {
                                Traverse.Create(__instance).Method("SpawnItem", new object[] { itemName }).GetValue();
                                ___m_nview.GetZDO().Set("slot" + i, "");
                                ___m_nview.GetZDO().Set("slot" + i, 0f);
                                ___m_nview.InvokeRPC(ZNetView.Everybody, "SetSlotVisual", new object[] { i, "" });
                            }
                            else if (preventBurning.Value)
                            {
                                ___m_nview.GetZDO().Set("slot" + i, itemConversion.m_cookTime);
                            }
                        }
                    }
                }
            }
 public static void Postfix(bool picked, ZNetView ___m_nview, bool ___m_picked, ref PickState __state)
 {
     if (__state != null && __state.picked == ___m_picked && ___m_nview.IsOwner())
     {
         ___m_nview.GetZDO().Set("picked_time", __state.picked_time);
     }
 }
示例#11
0
        private void UndoSpawn()
        {
            Debug.Log("Easyspawner: Undo spawn action");

            if (spawnActions.Count <= 0)
            {
                return;
            }

            List <GameObject> spawnedGameObjects = spawnActions.Pop();

            Debug.Log("Easyspawner: Destroying " + spawnedGameObjects.Count + " objects");
            string objectName = "objects";

            foreach (GameObject GO in spawnedGameObjects)
            {
                if (GO != null)
                {
                    objectName = GO.name.Remove(GO.name.Length - 7);
                    ZNetView zNetV = GO.GetComponent <ZNetView>();
                    if (zNetV && zNetV.IsValid() && zNetV.IsOwner())
                    {
                        zNetV.Destroy();
                    }
                }
            }

            Player.m_localPlayer.Message(MessageHud.MessageType.Center, "Undo spawn of " + spawnedGameObjects.Count + " " + objectName);
            Debug.Log("Easyspawner: Spawn undone");
        }
示例#12
0
 public static void Postfix(ZNetView ___m_nview, bool ___m_picked, ref PickState __state)
 {
     //if we're not changing the state, don't change the pick time.
     //Don't do anything if we're the client. Trust the server in that case.
     if (__state != null && __state.picked == ___m_picked && ___m_nview.IsOwner())
     {
         ___m_nview.GetZDO().Set("picked_time", __state.picked_time);
     }
 }
示例#13
0
        public static void Postfix(ZNetView ___m_nview, bool ___m_picked, ref Patch_Pickable_SetPicked.PickState __state)
        {
            bool flag = __state != null && __state.picked == ___m_picked && ___m_nview.IsOwner();

            if (flag)
            {
                ___m_nview.GetZDO().Set("picked_time", __state.picked_time);
            }
        }
示例#14
0
    // Token: 0x06000FAC RID: 4012 RVA: 0x0006E93C File Offset: 0x0006CB3C
    private void Awake()
    {
        ZNetView component = base.GetComponent <ZNetView>();

        if (component && component.IsOwner())
        {
            this.m_active = true;
            ZNet.instance.SetReferencePosition(base.transform.position);
        }
    }
示例#15
0
 static bool Prefix(MineRock5 __instance, HitData hit, ZNetView ___m_nview)
 {
     if (!modEnabled.Value)
     {
         return(true);
     }
     if (!___m_nview.IsValid() || !___m_nview.IsOwner())
     {
         return(false);
     }
     return(CheckCanDamage(__instance.gameObject, hit));
 }
示例#16
0
            static void Postfix(MonsterAI __instance, ZNetView ___m_nview, Character ___m_character, Tameable ___m_tamable, List <ItemDrop> ___m_consumeItems, float dt, bool __result)
            {
                if (!modEnabled.Value || !isOn.Value || __result || !___m_nview.IsOwner() || ___m_tamable == null || !___m_tamable.IsHungry() || ___m_consumeItems == null || ___m_consumeItems.Count == 0)
                {
                    return;
                }

                string name = GetPrefabName(__instance.gameObject.name);

                if (animalDisallowTypes.Value.Split(',').Contains(name))
                {
                    return;
                }

                var nearbyContainers = GetNearbyContainers(___m_character.gameObject.transform.position, containerRange.Value, __instance);

                using (List <ItemDrop> .Enumerator enumerator = __instance.m_consumeItems.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        foreach (Container c in nearbyContainers)
                        {
                            if (Utils.DistanceXZ(c.transform.position, __instance.transform.position) < moveProximity.Value && Mathf.Abs(c.transform.position.y - __instance.transform.position.y) > moveProximity.Value)
                            {
                                continue;
                            }

                            ItemDrop.ItemData item = c.GetInventory().GetItem(enumerator.Current.m_itemData.m_shared.m_name);
                            if (item != null)
                            {
                                if (feedDisallowTypes.Value.Split(',').Contains(item.m_dropPrefab.name))
                                {
                                    continue;
                                }

                                if (Time.time - lastFeed < 0.1)
                                {
                                    feedCount++;
                                    FeedAnimal(__instance, ___m_tamable, ___m_character, c, item, feedCount * 33);
                                }
                                else
                                {
                                    feedCount = 0;
                                    lastFeed  = Time.time;
                                    FeedAnimal(__instance, ___m_tamable, ___m_character, c, item, 0);
                                }
                                return;
                            }
                        }
                    }
                }
            }
示例#17
0
            static bool Prefix(Destructible __instance, HitData hit, ZNetView ___m_nview, bool ___m_destroyed)
            {
                if (!modEnabled.Value)
                {
                    return(true);
                }

                if (!___m_nview.IsValid() || !___m_nview.IsOwner() || ___m_destroyed)
                {
                    return(false);
                }
                return(CheckCanDamage(__instance.gameObject, hit));
            }
示例#18
0
 // Token: 0x06000403 RID: 1027 RVA: 0x00020E30 File Offset: 0x0001F030
 private void Trigger()
 {
     if (GameCamera.instance)
     {
         if (this.m_localOnly)
         {
             ZNetView component = base.GetComponent <ZNetView>();
             if (component && !component.IsOwner())
             {
                 return;
             }
         }
         GameCamera.instance.AddShake(base.transform.position, this.m_range, this.m_strength, this.m_continous);
     }
 }
示例#19
0
            public override void OnHit(GameObject gameObject)
            {
                var plant = gameObject.GetComponent <Plant>();

                if (plant != null)
                {
                    ZNetView plantView = (ZNetView)typeof(Plant).GetField("m_nview", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(plant);
                    if (plantView.GetZDO() != null && plantView.IsOwner())
                    {
                        var currentPlantTime = new DateTime(plantView.GetZDO().GetLong("plantTime", ZNet.instance.GetTime().Ticks));
                        var newPlantTime     = currentPlantTime.AddSeconds(-m_hitInterval * m_accelerationFactor);
                        plantView.GetZDO().Set("plantTime", newPlantTime.Ticks);
                        //Debug.Log($"Accelerated plant growth from {currentPlantTime} to {newPlantTime}");
                    }
                }
            }
示例#20
0
            static bool Prefix(ItemDrop.ItemData item, ref ItemDrop.ItemData ___m_rightItem, ref ZNetView ___m_nview, ref VisEquipment ___m_visEquipment)
            {
                if (!___m_nview.IsValid() || !___m_nview.IsOwner())
                {
                    return(true);
                }
                if (!MobManager.IsAliveMob(___m_nview.GetZDO().GetString(Constants.Z_CharacterId)))
                {
                    return(true);
                }

                ___m_rightItem           = item;
                ___m_rightItem.m_equiped = item != null;
                ___m_visEquipment.SetRightItem(item?.m_dropPrefab?.name);
                ___m_visEquipment.GetType().GetMethod("UpdateEquipmentVisuals", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(___m_visEquipment, new object[] { });
                return(false);
            }
示例#21
0
            static void Postfix(CookingStation __instance, ZNetView ___m_nview)
            {
                Traverse traverse = Traverse.Create(__instance);

                if (!modEnabled.Value || !___m_nview.IsValid() || !___m_nview.IsOwner() || (__instance.m_requireFire && !traverse.Method("IsFireLit").GetValue <bool>()) || (__instance.m_useFuel && traverse.Method("GetFuel").GetValue <float>() <= 0f))
                {
                    return;
                }

                //Dbgl($"Updating {__instance.name}");
                for (int i = 0; i < __instance.m_slots.Length; i++)
                {
                    string itemName   = ___m_nview.GetZDO().GetString("slot" + i, "");
                    float  cookedTime = ___m_nview.GetZDO().GetFloat("slot" + i, 0f);
                    int    status     = ___m_nview.GetZDO().GetInt("slotstatus" + i, 0);

                    if (itemName == "")
                    {
                        continue;
                    }

                    CookingStation.ItemConversion itemConversion = traverse.Method("GetItemConversion", new object[] { itemName }).GetValue <CookingStation.ItemConversion>();
                    //Dbgl($"Updating slot {i} {cookedTime}/{itemConversion.m_cookTime} {status}");

                    if (itemName != "" && status != 2)
                    {
                        //Dbgl($"Updating slot {i} {itemName} {cookedTime}");
                        if (itemConversion != null && cookedTime > itemConversion.m_cookTime && itemName == itemConversion.m_to.name)
                        {
                            if (autoPop.Value)
                            {
                                Dbgl($"Popping {__instance.name} slot {i} {itemName}");
                                Traverse.Create(__instance).Method("SpawnItem", new object[] { itemName, i, __instance.m_slots[i].position }).GetValue();
                                ___m_nview.GetZDO().Set("slot" + i, "");
                                ___m_nview.GetZDO().Set("slot" + i, 0f);
                                ___m_nview.InvokeRPC(ZNetView.Everybody, "SetSlotVisual", new object[] { i, "" });
                            }
                            else if (preventBurning.Value)
                            {
                                ___m_nview.GetZDO().Set("slot" + i, itemConversion.m_cookTime);
                            }
                        }
                    }
                }
            }
示例#22
0
    // Token: 0x06000F46 RID: 3910 RVA: 0x0006D028 File Offset: 0x0006B228
    private void Snap()
    {
        if (ZoneSystem.instance == null)
        {
            return;
        }
        float   groundHeight = ZoneSystem.instance.GetGroundHeight(base.transform.position);
        Vector3 position     = base.transform.position;

        position.y = groundHeight + this.m_offset;
        base.transform.position = position;
        ZNetView component = base.GetComponent <ZNetView>();

        if (component != null && component.IsOwner())
        {
            component.GetZDO().SetPosition(position);
        }
    }
示例#23
0
            static void Prefix(Vagon __instance, ZNetView ___m_nview, ref float mass)
            {
                if (!modEnabled.Value || !___m_nview.IsOwner())
                {
                    return;
                }

                float before = mass;

                List <Player> players = new List <Player>();

                Player.GetPlayersInRange(__instance.gameObject.transform.position, playerRange.Value, players);
                if (players.Count > (includePuller.Value ? 0 : 1))
                {
                    mass = Mathf.Max(0, mass - mass * playerMassReduction.Value * Mathf.Min(maxPlayers.Value, players.Count - (includePuller.Value ? 0 : 1)));
                }

                //Dbgl($"mass players {players.Count} distance {Vector3.Distance(__instance.gameObject.transform.position, Player.m_localPlayer.transform.position)} before {before} after {mass} is owner {___m_nview.IsOwner()}");
            }
示例#24
0
 // Token: 0x06000D9A RID: 3482 RVA: 0x00061264 File Offset: 0x0005F464
 private void FindObjectsToMove(Vector3 worldPos, float area, List <Rigidbody> objects)
 {
     if (this.m_collider == null)
     {
         return;
     }
     foreach (Collider collider in Physics.OverlapBox(worldPos, new Vector3(area / 2f, 500f, area / 2f)))
     {
         if (!(collider == this.m_collider) && collider.attachedRigidbody)
         {
             Rigidbody attachedRigidbody = collider.attachedRigidbody;
             ZNetView  component         = attachedRigidbody.GetComponent <ZNetView>();
             if (!component || component.IsOwner())
             {
                 objects.Add(attachedRigidbody);
             }
         }
     }
 }
示例#25
0
            static void Postfix(Smelter __instance, ZNetView ___m_nview)
            {
                if (!Player.m_localPlayer || !isOn.Value || ___m_nview == null || !___m_nview.IsOwner())
                {
                    return;
                }

                if (Time.time - lastFuel < 0.1)
                {
                    fuelCount++;
                    RefuelSmelter(__instance, ___m_nview, fuelCount * 33);
                }
                else
                {
                    fuelCount = 0;
                    lastFuel  = Time.time;
                    RefuelSmelter(__instance, ___m_nview, 0);
                }
            }
示例#26
0
            static void Postfix(Fireplace __instance, ZNetView ___m_nview)
            {
                if (!Player.m_localPlayer || !isOn.Value || !___m_nview.IsOwner() || (__instance.name.Contains("groundtorch") && !refuelStandingTorches.Value) || (__instance.name.Contains("walltorch") && !refuelWallTorches.Value) || (__instance.name.Contains("fire_pit") && !refuelFirePits.Value))
                {
                    return;
                }

                if (Time.time - lastFuel < 0.1)
                {
                    fuelCount++;
                    RefuelTorch(__instance, ___m_nview, fuelCount * 33);
                }
                else
                {
                    fuelCount = 0;
                    lastFuel  = Time.time;
                    RefuelTorch(__instance, ___m_nview, 0);
                }
            }
示例#27
0
        private static IEnumerator DestroyNow(Ragdoll ragdoll, ZNetView nview, EffectList m_removeEffect)
        {
            Dbgl($"delaying destroying ragdoll");
            yield return(new WaitForSeconds(Mathf.Max(destroyDelay.Value - dropDelay.Value, 0)));

            if (!modEnabled.Value)
            {
                yield break;
            }

            if (!nview.IsValid() || !nview.IsOwner())
            {
                yield break;
            }
            Dbgl($"destroying ragdoll");
            Vector3 averageBodyPosition = ragdoll.GetAverageBodyPosition();

            m_removeEffect.Create(averageBodyPosition, Quaternion.identity, null, 1f, -1);
            ZNetScene.instance.Destroy(ragdoll.gameObject);
        }
示例#28
0
        public void Awake()
        {
            if (!originalPiece)
            {
                InvalidPlanPiece();
                return;
            }

            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();
            UpdateTextures();
        }
示例#29
0
            static bool Prefix(WearNTear __instance, HitData hit, ZNetView ___m_nview, Piece ___m_piece)
            {
                if (!modEnabled.Value)
                {
                    return(true);
                }

                Dbgl($"attacker: {hit.m_attacker.userID}, creator { ___m_nview.IsOwner()}");
                if (!hit.m_attacker.IsNone() &&
                    (hit.m_attacker.userID != ___m_piece.GetCreator() && preventNonCreatorDamage.Value)
                    ||
                    (hit.m_attacker.userID == ___m_piece.GetCreator() && preventCreatorDamage.Value)
                    ||
                    (___m_piece.GetCreator() == 0 && preventUncreatedDamage.Value)
                    )
                {
                    Dbgl("Preventing damage");
                    return(false);
                }
                return(true);
            }
示例#30
0
            static bool Prefix(MonsterAI __instance, float dt, ref ZNetView ___m_nview, ref Character ___m_character, ref float ___m_timeSinceHurt,
                               ref float ___m_jumpInterval, ref float ___m_jumpTimer, ref float ___m_randomMoveUpdateTimer, ref bool ___m_alerted)
            {
                if (!___m_nview.IsValid())
                {
                    return(true);
                }
                var uniqueId = ___m_nview.GetZDO().GetString(Constants.Z_CharacterId);

                if (string.IsNullOrEmpty(uniqueId))
                {
                    return(true);
                }
                if (!MobManager.IsRegisteredMob(uniqueId))
                {
                    return(true);
                }

                var mobAI = GetOrCreateMob(uniqueId, __instance, ___m_nview);

                if (null == mobAI)
                {
                    return(true);
                }
                if (!___m_nview.IsOwner())
                {
                    return(false);
                }
                if (__instance.IsSleeping())
                {
                    Invoke(__instance, "UpdateSleep", new object[] { dt });
                    Common.Dbgl($"{___m_character.GetHoverName()}: Sleep updated");
                    return(false);
                }

                BaseAI_UpdateAI_ReversePatch.UpdateAI(__instance, dt, ___m_nview, ref ___m_jumpInterval, ref ___m_jumpTimer, ref ___m_randomMoveUpdateTimer, ref ___m_timeSinceHurt, ref ___m_alerted);
                mobAI.UpdateAI(dt);

                return(false);
            }