public bool Interact(Humanoid user, bool hold) { if (Player.m_localPlayer.InPlaceMode()) { return(false); } if (hold) { if (m_holdRepeatInterval <= 0f) { return(false); } if (Time.time - m_lastUseTime < m_holdRepeatInterval) { return(false); } m_lastUseTime = Time.time; return(AddAllSeeds(user)); } m_lastUseTime = Time.time; string restrict = GetRestrict(); string seedName = FindSeed(restrict, user.GetInventory()); if (seedName == null) { string missing; if (restrict == "") { missing = messageSeedGenericPlural; } else { missing = restrict; } user.Message(MessageHud.MessageType.Center, "$msg_donthaveany " + missing); return(false); } if (configMaxSeeds.Value > 0) { int currentSeeds = GetTotalSeedCount(); if (currentSeeds >= configMaxSeeds.Value) { user.Message(MessageHud.MessageType.Center, "$msg_itsfull"); return(false); } } user.GetInventory().RemoveItem(seedName, 1); m_nview.InvokeRPC("AddSeed", seedName, 1); user.Message(MessageHud.MessageType.Center, "$msg_added " + seedName); return(true); }
public bool Interact(Humanoid user, bool hold) { if (hold) { if (Time.time - m_lastUseTime < m_holdRepeatInterval) { return(false); } m_lastUseTime = Time.time; return(AddAllMaterials(user)); } foreach (Piece.Requirement req in originalPiece.m_resources) { string resourceName = GetResourceName(req); if (!PlayerHaveResource(user, resourceName)) { continue; } int currentCount = GetResourceCount(resourceName); if (currentCount < req.m_amount) { m_nView.InvokeRPC("AddResource", resourceName, 1); user.GetInventory().RemoveItem(resourceName, 1); UpdateHoverText(); return(true); } } if (!HasAllResources()) { user.Message(MessageHud.MessageType.Center, "$msg_missingrequirement"); return(false); } if (user.GetInventory().GetItem("$item_hammer") == null && user.GetInventory().GetItem(PlanHammerPrefabConfig.itemName) == null) { user.Message(MessageHud.MessageType.Center, "$message_plan_piece_need_hammer"); return(false); } if ((bool)originalPiece.m_craftingStation) { CraftingStation craftingStation = CraftingStation.HaveBuildStationInRange(originalPiece.m_craftingStation.m_name, user.transform.position); if (!craftingStation) { user.Message(MessageHud.MessageType.Center, "$msg_missingstation"); return(false); } } if (!hasSupport) { user.Message(MessageHud.MessageType.Center, "$message_plan_piece_not_enough_support"); return(false); } m_nView.InvokeRPC("Refund", false); m_nView.InvokeRPC("SpawnPieceAndDestroy"); return(false); }
public static void MineRock5_Damage_Patch(MineRock5 __instance, ZNetView ___m_nview, List <HitArea> ___m_hitAreas, HitData hit, Dictionary <int, Vector3> __state) { if (Player.m_localPlayer != null && hit.m_attacker == Player.m_localPlayer.GetZDOID()) { if (Input.GetKey(VeinMine.veinMineKey.Value) && !VeinMine.progressiveMode.Value) { for (int i = 0; i < (___m_hitAreas.Count <= 128 ? ___m_hitAreas.Count : 128); i++) { if (Player.m_localPlayer.GetCurrentWeapon().m_durability > 0 || !Player.m_localPlayer.GetCurrentWeapon().m_shared.m_useDurability) { hit.m_point = __instance.GetHitArea(i).m_bound.m_pos; hit.m_damage.m_pickaxe = __instance.m_health + 10; try { ___m_nview.InvokeRPC("Damage", new object[] { hit, i }); } catch { VeinMine.logger.LogInfo("Skipping section: " + i + "."); } } } } else if (Input.GetKey(VeinMine.veinMineKey.Value) && VeinMine.progressiveMode.Value) { foreach (var index in __state) { hit.m_point = index.Value; if (Player.m_localPlayer.GetCurrentWeapon().m_durability > 0 || !Player.m_localPlayer.GetCurrentWeapon().m_shared.m_useDurability) { try { ___m_nview.InvokeRPC("Damage", new object[] { hit, index.Key }); } catch { VeinMine.logger.LogInfo("Skipping section: " + index.Key + "."); } } } } } }
public static bool Prefix(Player __instance) { long playerID = __instance.GetPlayerID(); HardcoreData hardcoreProfile = Hardcore.GetHardcoreDataForProfileID(playerID); if (hardcoreProfile != null && hardcoreProfile.isHardcore) { hardcoreProfile.hasDied = true; Traverse tPlayer = Traverse.Create(__instance); tPlayer.Field <bool>("m_firstSpawn").Value = true; ZNetView nview = tPlayer.Field <ZNetView>("m_nview").Value; nview.GetZDO().Set("dead", true); nview.InvokeRPC(ZNetView.Everybody, "OnDeath", Array.Empty <object>()); tPlayer.Method("CreateDeathEffects").GetValue(new object[] { }); tPlayer.Field <GameObject>("m_visual").Value.SetActive(false); tPlayer.Field <List <Player.Food> >("m_foods").Value.Clear(); __instance.UnequipAllItems(); __instance.GetInventory().RemoveAll(); if (Hardcore.Settings.ClearCustomSpawn.Value) { Game.instance.GetPlayerProfile().ClearCustomSpawnPoint(); } Game.instance.RequestRespawn(10f); Gogan.LogEvent("Game", "Death", "biome: " + __instance.GetCurrentBiome().ToString(), 0L); return(false); } return(true); }
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); } } } } }
static void Postfix(ZNetView ___m_nview) { if (Time.time - m_callHomeKeyTimer < m_callHomeKeyDelay) { return; } if (Input.GetKey(m_callHomeKey)) { Common.Dbgl($"CallHome command"); m_callHomeKeyTimer = Time.time; ___m_nview.InvokeRPC(ZNetView.Everybody, Constants.Z_CallHomeCommand, Player.m_localPlayer.transform.position); var charsInRange = new List <Character>(); var m_nview = typeof(Character).GetField("m_nview", BindingFlags.Instance | BindingFlags.NonPublic); Character.GetCharactersInRange(Player.m_localPlayer.transform.position, 190, charsInRange); foreach (var character in charsInRange) { var nview = m_nview.GetValue(character) as ZNetView; var uniqueId = nview.GetZDO().GetString(Constants.Z_CharacterId); if (MobManager.IsAliveMob(uniqueId)) { MobManager.AliveMobs[uniqueId].Follow(Player.m_localPlayer); } } } }
static bool Prefix(ref CookingStation __instance, ref ZNetView ___m_nview, Humanoid user, bool hold) { if (hold) { return(false); } Traverse t_cookingStation = Traverse.Create(__instance); ZDO zdo = ___m_nview.GetZDO(); for (int slot = 0; slot < __instance.m_slots.Length; ++slot) { string itemName = zdo.GetString(nameof(slot) + slot); bool isItemDone = t_cookingStation.Method("IsItemDone", itemName).GetValue <bool>(); if (itemName != "" && itemName != __instance.m_overCookedItem.name && isItemDone) { JustAnotherCookingSkill.raiseCookingSkill(user, JustAnotherCookingSkill.cookingStaticExperienceGain.Value * 0.5f); string qualityPrefix = JustAnotherCookingSkill.getQualityBasedOnSkill(user); // check if such object exist string qualifyMealName = qualityPrefix + itemName; if (Prefab.Cache.GetPrefab <ItemDrop>(qualifyMealName) == null) { Log.LogError($"No object registered for qualify meal: {qualifyMealName}"); return(true); } // instead of processing normal food, we spawn qualified variant MethodInfo method = __instance.GetType().GetMethod("SpawnItem"); if (method == null) { Log.LogError("Method SpawnItem does not exist on type CookingStation"); return(true); } method.Invoke(__instance, new object[] { qualifyMealName }); zdo.Set("slot" + slot, ""); ___m_nview.InvokeRPC(ZNetView.Everybody, "SetSlotVisual", new object[] { slot, "" }); // Unfortunately we replace this hook totally and extra modifications will conflict on those. I gonna find better way return(false); } } return(true); }
internal static void ApplyFuel(Fireplace __instance, ref ZNetView ___m_nview) { if (Configuration.Current.Fireplace.onlyTorches) { if (__instance.m_piece.m_name.Equals(woodTorchName) || __instance.m_piece.m_name.Equals(sconceName) || __instance.m_piece.m_name.Equals(ironTorchName) || __instance.m_piece.m_name.Equals(brazierName) || __instance.m_piece.m_name.Equals(greenTorchName)) { //___m_nview.GetZDO().Set("fuel", __instance.m_maxFuel); // setting to max won't waste rss on fill attempts ___m_nview.InvokeRPC("AddFuel", new object[] { }); } } else { //___m_nview.GetZDO().Set("fuel", __instance.m_maxFuel); // setting to max won't waste rss on fill attempts ___m_nview.InvokeRPC("AddFuel", new object[] { }); } }
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); }
public bool Interact(Humanoid user, bool hold) { if (hold) { if (m_holdRepeatInterval <= 0f) { return(false); } if (Time.time - m_lastUseTime < m_holdRepeatInterval) { return(false); } m_lastUseTime = Time.time; m_nview.InvokeRPC("DropCores"); return(true); } m_lastUseTime = Time.time; return(false); }
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); } } } } }
private static void ChatMessage(Talker.Type type, string username, string message) { Player playerSender = Player.m_localPlayer; foreach (Player player in Player.GetAllPlayers()) { if (player.GetPlayerName().ToLower().Equals(username.ToLower())) { playerSender = player; break; } } if (playerSender) { if (type == Talker.Type.Shout) { if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "ChatMessage", new object[] { playerSender.GetHeadPoint(), 2, username, message }); } return; } ZNetView nview = playerSender.GetComponent <Talker>().GetComponent <ZNetView>(); if (nview) { nview.InvokeRPC(ZNetView.Everybody, "Say", new object[] { (int)type, username, message }); } } }
static bool Prefix(Smelter __instance, ref bool __result, ZNetView ___m_nview, Humanoid user, ItemDrop.ItemData item) { if (!AllowByKey() || user.GetInventory().HaveItem(__instance.m_fuelItem.m_itemData.m_shared.m_name) || item != null) { return(true); } if (((float)typeof(Smelter).GetMethod("GetFuel", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { })) > __instance.m_maxFuel - 1) { user.Message(MessageHud.MessageType.Center, "$msg_itsfull", 0, null); return(false); } Dbgl($"missing fuel in player inventory"); List <Container> nearbyContainers = GetNearbyContainers(__instance.transform.position); foreach (Container c in nearbyContainers) { ItemDrop.ItemData newItem = c.GetInventory().GetItem(__instance.m_fuelItem.m_itemData.m_shared.m_name); if (newItem != null) { if (fuelDisallowTypes.Value.Split(',').Contains(newItem.m_dropPrefab.name)) { Dbgl($"container at {c.transform.position} has {newItem.m_stack} {newItem.m_dropPrefab.name} but it's forbidden by config"); continue; } Dbgl($"container at {c.transform.position} has {newItem.m_stack} {newItem.m_dropPrefab.name}, taking one"); user.Message(MessageHud.MessageType.Center, "$msg_added " + __instance.m_fuelItem.m_itemData.m_shared.m_name, 0, null); ___m_nview.InvokeRPC("AddFuel", new object[] { }); 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[] { }); __result = true; return(false); } } return(true); }
private void Update() { if (configEnableAutoRepair.Value) { var cur_time = DateTime.Now.Ticks; if ((cur_time - l_saved_time) / TimeSpan.TicksPerSecond >= configRepairInterval.Value) { l_saved_time = cur_time; List <WearNTear> list = WearNTear.GetAllInstaces(); if (list.Count > 0) { foreach (WearNTear item in list) { ZNetView view = (ZNetView)GetInstanceField(item, "m_nview"); if (view != null) { if (PrivateArea.CheckInPrivateArea(item.transform.position)) { float health = view.GetZDO().GetFloat("health"); if (!(health > 0) || !(health < item.m_health)) { continue; } var res_health = health + item.m_health * configRepairAmountPercent.Value / 100; if (res_health > item.m_health) { res_health = item.m_health; } view.GetZDO().Set("health", res_health); view.InvokeRPC(ZNetView.Everybody, "WNTHealthChanged", new object[] { res_health }); } } } } } } }
public static async void RefuelSmelter(Smelter __instance, ZNetView ___m_nview, int delay) { await Task.Delay(delay); int maxOre = __instance.m_maxOre - Traverse.Create(__instance).Method("GetQueueSize").GetValue <int>(); int maxFuel = __instance.m_maxFuel - Mathf.CeilToInt(___m_nview.GetZDO().GetFloat("fuel", 0f)); List <Container> nearbyOreContainers = GetNearbyContainers(__instance.transform.position, smelterOreRange.Value); List <Container> nearbyFuelContainers = GetNearbyContainers(__instance.transform.position, smelterFuelRange.Value); Vector3 position = __instance.transform.position + Vector3.up; foreach (Collider collider in Physics.OverlapSphere(position, dropRange.Value, LayerMask.GetMask(new string[] { "item" }))) { if (collider?.attachedRigidbody) { ItemDrop item = collider.attachedRigidbody.GetComponent <ItemDrop>(); //Dbgl($"nearby item name: {item.m_itemData.m_dropPrefab.name}"); if (item?.GetComponent <ZNetView>()?.IsValid() != true) { continue; } string name = GetPrefabName(item.gameObject.name); foreach (Smelter.ItemConversion itemConversion in __instance.m_conversion) { if (item.m_itemData.m_shared.m_name == itemConversion.m_from.m_itemData.m_shared.m_name && maxOre > 0) { if (oreDisallowTypes.Value.Split(',').Contains(name)) { //Dbgl($"container at {c.transform.position} has {item.m_itemData.m_stack} {item.m_dropPrefab.name} but it's forbidden by config"); continue; } Dbgl($"auto adding ore {name} from ground"); int amount = Mathf.Min(item.m_itemData.m_stack, maxOre); maxOre -= amount; for (int i = 0; i < amount; i++) { if (item.m_itemData.m_stack <= 1) { if (___m_nview.GetZDO() == null) { Destroy(item.gameObject); } else { ZNetScene.instance.Destroy(item.gameObject); } ___m_nview.InvokeRPC("AddOre", new object[] { name }); break; } item.m_itemData.m_stack--; ___m_nview.InvokeRPC("AddOre", new object[] { name }); Traverse.Create(item).Method("Save").GetValue(); } } } if (__instance.m_fuelItem && item.m_itemData.m_shared.m_name == __instance.m_fuelItem.m_itemData.m_shared.m_name && maxFuel > 0) { if (fuelDisallowTypes.Value.Split(',').Contains(name)) { //Dbgl($"ground has {item.m_itemData.m_dropPrefab.name} but it's forbidden by config"); continue; } Dbgl($"auto adding fuel {name} from ground"); int amount = Mathf.Min(item.m_itemData.m_stack, maxFuel); maxFuel -= amount; for (int i = 0; i < amount; i++) { if (item.m_itemData.m_stack <= 1) { if (___m_nview.GetZDO() == null) { Destroy(item.gameObject); } else { ZNetScene.instance.Destroy(item.gameObject); } ___m_nview.InvokeRPC("AddFuel", new object[] { }); break; } item.m_itemData.m_stack--; ___m_nview.InvokeRPC("AddFuel", new object[] { }); Traverse.Create(item).Method("Save").GetValue(); } } } } foreach (Container c in nearbyOreContainers) { foreach (Smelter.ItemConversion itemConversion in __instance.m_conversion) { ItemDrop.ItemData oreItem = c.GetInventory().GetItem(itemConversion.m_from.m_itemData.m_shared.m_name); if (oreItem != null && maxOre > 0) { maxOre--; if (oreDisallowTypes.Value.Split(',').Contains(oreItem.m_dropPrefab.name)) { continue; } Dbgl($"container at {c.transform.position} has {oreItem.m_stack} {oreItem.m_dropPrefab.name}, taking one"); ___m_nview.InvokeRPC("AddOre", new object[] { oreItem.m_dropPrefab?.name }); c.GetInventory().RemoveItem(itemConversion.m_from.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[] { }); } } } foreach (Container c in nearbyFuelContainers) { if (__instance.m_fuelItem && maxFuel > 0) { ItemDrop.ItemData fuelItem = c.GetInventory().GetItem(__instance.m_fuelItem.m_itemData.m_shared.m_name); if (fuelItem != null) { maxFuel--; if (fuelDisallowTypes.Value.Split(',').Contains(fuelItem.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 {fuelItem.m_stack} {fuelItem.m_dropPrefab.name}, taking one"); ___m_nview.InvokeRPC("AddFuel", new object[] { }); 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[] { }); } } } }
static bool Prefix(Player __instance, Inventory ___m_inventory, ref float ___m_timeSinceDeath, float ___m_hardDeathCooldown, ZNetView ___m_nview, List <Player.Food> ___m_foods, Skills ___m_skills) { if (!modEnabled.Value) { return(true); } ___m_nview.GetZDO().Set("dead", true); ___m_nview.InvokeRPC(ZNetView.Everybody, "OnDeath", new object[] { }); Game.instance.GetPlayerProfile().m_playerStats.m_deaths++; Game.instance.GetPlayerProfile().SetDeathPoint(__instance.transform.position); if (createDeathEffects.Value) { Traverse.Create(__instance).Method("CreateDeathEffects").GetValue(); } List <ItemDrop.ItemData> dropItems = new List <ItemDrop.ItemData>(); if (!keepAllItems.Value) { List <Inventory> inventories = new List <Inventory>(); if (quickSlotsAssembly != null) { var extendedInventory = quickSlotsAssembly.GetType("EquipmentAndQuickSlots.InventoryExtensions").GetMethod("Extended", BindingFlags.Public | BindingFlags.Static).Invoke(null, new object[] { ___m_inventory }); inventories = (List <Inventory>)quickSlotsAssembly.GetType("EquipmentAndQuickSlots.ExtendedInventory").GetField("_inventories", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(extendedInventory); } else { inventories.Add(___m_inventory); } for (int i = 0; i < inventories.Count; i++) { Inventory inv = inventories[i]; if (quickSlotsAssembly != null && keepQuickSlotItems.Value && inv == (Inventory)quickSlotsAssembly.GetType("EquipmentAndQuickSlots.PlayerExtensions").GetMethod("GetQuickSlotInventory", BindingFlags.Public | BindingFlags.Static).Invoke(null, new object[] { __instance })) { Dbgl("Skipping quick slot inventory"); continue; } List <ItemDrop.ItemData> keepItems = Traverse.Create(inv).Field("m_inventory").GetValue <List <ItemDrop.ItemData> >(); if (destroyAllItems.Value) { keepItems.Clear(); } else { for (int j = keepItems.Count - 1; j >= 0; j--) { ItemDrop.ItemData item = keepItems[j]; if (keepEquippedItems.Value && item.m_equiped) { continue; } if (keepHotbarItems.Value && item.m_gridPos.y == 0) { continue; } if (item.m_shared.m_questItem) { continue; } if (destroyItemTypes.Value.Length > 0) { string[] destroyTypes = destroyItemTypes.Value.Split(','); if (destroyTypes.Contains(Enum.GetName(typeof(ItemDrop.ItemData.ItemType), item.m_shared.m_itemType))) { keepItems.RemoveAt(j); continue; } } if (keepItemTypes.Value.Length > 0) { string[] keepTypes = keepItemTypes.Value.Split(','); if (keepTypes.Contains(Enum.GetName(typeof(ItemDrop.ItemData.ItemType), item.m_shared.m_itemType))) { continue; } } else if (dropItemTypes.Value.Length > 0) { string[] dropTypes = dropItemTypes.Value.Split(','); if (dropTypes.Contains(Enum.GetName(typeof(ItemDrop.ItemData.ItemType), item.m_shared.m_itemType))) { dropItems.Add(item); keepItems.RemoveAt(j); } continue; } dropItems.Add(item); keepItems.RemoveAt(j); } } Traverse.Create(inv).Method("Changed").GetValue(); } } if (useTombStone.Value && dropItems.Any()) { GameObject gameObject = Instantiate(__instance.m_tombstone, __instance.GetCenterPoint(), __instance.transform.rotation); gameObject.GetComponent <Container>().GetInventory().RemoveAll(); int width = Traverse.Create(___m_inventory).Field("m_width").GetValue <int>(); int height = Traverse.Create(___m_inventory).Field("m_height").GetValue <int>(); Traverse.Create(gameObject.GetComponent <Container>().GetInventory()).Field("m_width").SetValue(width); Traverse.Create(gameObject.GetComponent <Container>().GetInventory()).Field("m_height").SetValue(height); Traverse.Create(gameObject.GetComponent <Container>().GetInventory()).Field("m_inventory").SetValue(dropItems); Traverse.Create(gameObject.GetComponent <Container>().GetInventory()).Method("Changed").GetValue(); TombStone component = gameObject.GetComponent <TombStone>(); PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); component.Setup(playerProfile.GetName(), playerProfile.GetPlayerID()); } else { foreach (ItemDrop.ItemData item in dropItems) { Vector3 position = __instance.transform.position + Vector3.up * 0.5f + UnityEngine.Random.insideUnitSphere * 0.3f; Quaternion rotation = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); ItemDrop.DropItem(item, 0, position, rotation); } } if (!keepFoodLevels.Value) { ___m_foods.Clear(); } bool hardDeath = noSkillProtection.Value || ___m_timeSinceDeath > ___m_hardDeathCooldown; if (hardDeath && reduceSkills.Value) { ___m_skills.OnDeath(); } Game.instance.RequestRespawn(10f); ___m_timeSinceDeath = 0; if (!hardDeath) { __instance.Message(MessageHud.MessageType.TopLeft, "$msg_softdeath", 0, null); } __instance.Message(MessageHud.MessageType.Center, "$msg_youdied", 0, null); __instance.ShowTutorial("death", false); string eventLabel = "biome:" + __instance.GetCurrentBiome().ToString(); Gogan.LogEvent("Game", "Death", eventLabel, 0L); return(false); }
public static async void RefuelTorch(Fireplace fireplace, ZNetView znview, int delay) { await Task.Delay(delay); int maxFuel = (int)(fireplace.m_maxFuel - Mathf.Ceil(znview.GetZDO().GetFloat("fuel", 0f))); List <Container> nearbyContainers = GetNearbyContainers(fireplace.transform.position, fireplaceRange.Value); Vector3 position = fireplace.transform.position + Vector3.up; foreach (Collider collider in Physics.OverlapSphere(position, dropRange.Value, LayerMask.GetMask(new string[] { "item" }))) { if (collider?.attachedRigidbody) { ItemDrop item = collider.attachedRigidbody.GetComponent <ItemDrop>(); //Dbgl($"nearby item name: {item.m_itemData.m_dropPrefab.name}"); if (item?.GetComponent <ZNetView>()?.IsValid() != true) { continue; } string name = GetPrefabName(item.gameObject.name); if (item.m_itemData.m_shared.m_name == fireplace.m_fuelItem.m_itemData.m_shared.m_name && maxFuel > 0) { if (fuelDisallowTypes.Value.Split(',').Contains(name)) { //Dbgl($"ground has {item.m_itemData.m_dropPrefab.name} but it's forbidden by config"); continue; } Dbgl($"auto adding fuel {name} from ground"); int amount = Mathf.Min(item.m_itemData.m_stack, maxFuel); maxFuel -= amount; for (int i = 0; i < amount; i++) { if (item.m_itemData.m_stack <= 1) { if (znview.GetZDO() == null) { Destroy(item.gameObject); } else { ZNetScene.instance.Destroy(item.gameObject); } znview.InvokeRPC("AddFuel", new object[] { }); break; } item.m_itemData.m_stack--; znview.InvokeRPC("AddFuel", new object[] { }); Traverse.Create(item).Method("Save").GetValue(); } } } } foreach (Container c in nearbyContainers) { if (fireplace.m_fuelItem && maxFuel > 0) { List <ItemDrop.ItemData> itemList = new List <ItemDrop.ItemData>(); c.GetInventory().GetAllItems(fireplace.m_fuelItem.m_itemData.m_shared.m_name, itemList); foreach (var fuelItem in itemList) { if (fuelItem != null && (!leaveLastItem.Value || fuelItem.m_stack > 1)) { if (fuelDisallowTypes.Value.Split(',').Contains(fuelItem.m_dropPrefab.name)) { //Dbgl($"container at {c.transform.position} has {item.m_stack} {item.m_dropPrefab.name} but it's forbidden by config"); continue; } maxFuel--; Dbgl($"container at {c.transform.position} has {fuelItem.m_stack} {fuelItem.m_dropPrefab.name}, taking one"); znview.InvokeRPC("AddFuel", new object[] { }); c.GetInventory().RemoveItem(fireplace.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[] { }); } } } } }
public static void BroadcastUpdateCharacterName(ref ZNetView nview, string text) { nview.InvokeRPC(ZNetView.Everybody, Constants.Z_UpdateCharacterHUD, nview.GetZDO().GetString(Constants.Z_CharacterId), text); }
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; } int maxFuel = (int)(__instance.m_maxFuel - Mathf.Ceil(___m_nview.GetZDO().GetFloat("fuel", 0f))); List <Container> nearbyContainers = GetNearbyContainers(__instance.transform.position); Vector3 position = __instance.transform.position + Vector3.up; foreach (Collider collider in Physics.OverlapSphere(position, dropRange.Value, LayerMask.GetMask(new string[] { "item" }))) { if (collider?.attachedRigidbody) { ItemDrop item = collider.attachedRigidbody.GetComponent <ItemDrop>(); //Dbgl($"nearby item name: {item.m_itemData.m_dropPrefab.name}"); if (item?.GetComponent <ZNetView>()?.IsValid() != true) { continue; } string name = GetPrefabName(item.gameObject.name); if (item.m_itemData.m_shared.m_name == __instance.m_fuelItem.m_itemData.m_shared.m_name && maxFuel > 0) { if (fuelDisallowTypes.Value.Split(',').Contains(name)) { //Dbgl($"ground has {item.m_itemData.m_dropPrefab.name} but it's forbidden by config"); continue; } Dbgl($"auto adding fuel {name} from ground"); int amount = Mathf.Min(item.m_itemData.m_stack, maxFuel); maxFuel -= amount; for (int i = 0; i < amount; i++) { if (item.m_itemData.m_stack <= 1) { if (___m_nview.GetZDO() == null) { Destroy(item.gameObject); } else { ZNetScene.instance.Destroy(item.gameObject); } ___m_nview.InvokeRPC("AddFuel", new object[] { }); break; } item.m_itemData.m_stack--; ___m_nview.InvokeRPC("AddFuel", new object[] { }); Traverse.Create(item).Method("Save").GetValue(); } } } } foreach (Container c in nearbyContainers) { if (__instance.m_fuelItem && maxFuel > 0) { ItemDrop.ItemData fuelItem = c.GetInventory().GetItem(__instance.m_fuelItem.m_itemData.m_shared.m_name); if (fuelItem != null) { maxFuel--; if (fuelDisallowTypes.Value.Split(',').Contains(fuelItem.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 {fuelItem.m_stack} {fuelItem.m_dropPrefab.name}, taking one"); ___m_nview.InvokeRPC("AddFuel", new object[] { }); 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[] { }); } } } }
public void RequestContainerLock(long playerId, bool shouldLock) { _zNetView.InvokeRPC("LockContainersRequest", playerId, shouldLock); }