static void Prefix(Player __instance) { if (!modEnabled.Value || !Player.m_localPlayer || backpackInventory == null || __instance.GetPlayerID() != Player.m_localPlayer.GetPlayerID() || backpackInventory.NrOfItems() == 0) { return; } if (dropInventoryOnDeath.Value) { if (createTombStone.Value) { GameObject gameObject = Instantiate(__instance.m_tombstone, __instance.GetCenterPoint() + Vector3.forward, __instance.transform.rotation); gameObject.GetComponent <Container>().GetInventory().MoveInventoryToGrave(backpackInventory); TombStone component = gameObject.GetComponent <TombStone>(); PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); component.Setup(playerProfile.GetName(), playerProfile.GetPlayerID()); } else { List <ItemDrop.ItemData> allItems = backpackInventory.GetAllItems(); foreach (ItemDrop.ItemData item in allItems) { Vector3 position = __instance.transform.position + Vector3.up * 0.5f + UnityEngine.Random.insideUnitSphere * 0.3f; Quaternion rotation = Quaternion.Euler(0f, UnityEngine.Random.Range(0, 360), 0f); ItemDrop.DropItem(item, 0, position, rotation); backpackInventory.RemoveAll(); } } } }
static void Prefix(Player __instance) { if (!modEnabled.Value || !backpack || !Player.m_localPlayer || __instance.GetPlayerID() != Player.m_localPlayer.GetPlayerID() || backpack.GetComponent <Container>().GetInventory().NrOfItems() == 0) { return; } if (dropInventoryOnDeath.Value) { if (createTombStone.Value) { GameObject gameObject = Instantiate(__instance.m_tombstone, __instance.GetCenterPoint() + Vector3.forward, __instance.transform.rotation); gameObject.GetComponent <Container>().GetInventory().MoveInventoryToGrave(backpack.GetComponent <Container>().GetInventory()); TombStone component = gameObject.GetComponent <TombStone>(); PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); component.Setup(playerProfile.GetName(), playerProfile.GetPlayerID()); } else { Traverse.Create(backpack.GetComponent <Container>()).Method("DropAllItems", new object[] { }).GetValue(); } } Dbgl("Moving backpack to scene on death"); MoveBackpackToScene(); ResetBackpackSector(); }
private static Inventory CreateTempGrave(Player player) { GameObject graveGO = UnityEngine.Object.Instantiate <GameObject>(player.m_tombstone, player.GetCenterPoint(), player.transform.rotation); TombStone grave = graveGO.GetComponent <TombStone>(); PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); string name = playerProfile.GetName(); long playerId = playerProfile.GetPlayerID(); grave.Setup(name, playerId); return(graveGO.GetComponent <Container>().GetInventory()); }
private static void CreateTombStone() { Dbgl($"height {Player.m_localPlayer.m_tombstone.GetComponent<Container>().m_height}"); GameObject gameObject = Instantiate(Player.m_localPlayer.m_tombstone, Player.m_localPlayer.GetCenterPoint(), Player.m_localPlayer.transform.rotation); TombStone component = gameObject.GetComponent <TombStone>(); Dbgl($"height {gameObject.GetComponent<Container>().m_height}"); Dbgl($"inv height {gameObject.GetComponent<Container>().GetInventory().GetHeight()}"); Dbgl($"inv slots {gameObject.GetComponent<Container>().GetInventory().GetEmptySlots()}"); for (int i = 0; i < gameObject.GetComponent <Container>().GetInventory().GetEmptySlots(); i++) { gameObject.GetComponent <Container>().GetInventory().AddItem("SwordBronze", 1, 1, 0, 0, ""); } Dbgl($"no items: {gameObject.GetComponent<Container>().GetInventory().NrOfItems()}"); PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); component.Setup(playerProfile.GetName(), playerProfile.GetPlayerID()); }
private static void SpawnAGrave(Player player, Inventory inventory, int graveCount) { Vector3 offset = (graveCount > 0) ? (Quaternion.Euler(0, 30 * graveCount, 0) * (new Vector3(.5f, 1f, .5f))) : Vector3.zero; GameObject obj = Object.Instantiate(player.m_tombstone, player.GetCenterPoint() + offset, player.transform.rotation); Inventory graveInventory = obj.GetComponent <Container>().GetInventory(); graveInventory.m_name = "GKGrave"; graveInventory.m_height = Settings.Grave.GraveHeight; graveInventory.m_width = Settings.Grave.GraveWidth; graveInventory.MoveAll(inventory); TombStone component = obj.GetComponent <TombStone>(); PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); string graveName = playerProfile.GetName(); if (graveCount > 0) { graveName += $"({graveCount})"; } component.Setup(graveName, playerProfile.GetPlayerID()); }
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); }
private static void RPC_SendJSON(ZRpc rpc, string json) { if (!modEnabled.Value) { return; } JsonCommand command = JsonUtility.FromJson <JsonCommand>(json); Dbgl($"RPC_SendJSON received command {command.command} {json} from id {command.id}"); ZNetPeer peer = Traverse.Create(ZNet.instance).Method("GetPeer", new object[] { rpc }).GetValue <ZNetPeer>(); var steamID = (peer.m_socket as ZSteamSocket).GetPeerID(); if (ZNet.instance.IsServer()) { context.UpdatePlayers(true); if (command.command == "BuyPackage") { var packages = GetAllPackages(); PackageInfo package; try { package = packages.First(p => p.id == command.packageid); } catch { Dbgl($"Package {command.packageid} not found"); return; } PlayerInfo player = GetPlayerInfo(steamID.ToString()); if (!CanBuyPackage(ref player, package, true, true, out string result)) { WritePlayerData(player); return; } Dbgl(result); player.currency -= package.price; WritePlayerData(player); JsonCommand sendCommand = new JsonCommand() { command = "PurchaseResult", currency = player.currency, packageid = package.id, packagename = package.name, packagedescription = package.description, items = GetPackageItems(package, player) }; rpc.Invoke("SendServerRewardsJSON", new object[] { JsonUtility.ToJson(sendCommand) }); } else if (command.command == "RequestStoreInfo") { int currency = GetUserCurrency(steamID.ToString()); if (currency == -1) { Dbgl("Error getting store info"); return; } PlayerInfo player = GetPlayerInfo(steamID.ToString()); JsonCommand sendCommand = new JsonCommand() { command = "SendStoreInfo", storeTitle = storeTitleString.Value, storeInventory = GetStoreInventoryString(player), currencyString = currencyString.Value, currency = currency, }; rpc.Invoke("SendServerRewardsJSON", new object[] { JsonUtility.ToJson(sendCommand) }); } } else { if (command.command == "PurchaseResult") { Traverse.Create(GameCamera.instance).Field("m_mouseCapture").SetValue(true); Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; storeOpen = false; //PlayEffects(); var items = command.items.Split(';'); GameObject chest = null; PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); Traverse inventoryT = null; if (useTombstone.Value) { chest = Instantiate(Player.m_localPlayer.m_tombstone, Player.m_localPlayer.GetCenterPoint() + Player.m_localPlayer.transform.forward, Player.m_localPlayer.transform.rotation); chest.GetComponent <Container>().m_name = command.packagename; inventoryT = Traverse.Create(chest.GetComponent <Container>().GetInventory()); inventoryT.Field("m_name").SetValue(command.packagename); inventoryT.Field("m_width").SetValue(8); int rows = items.Count() / 8 + 2; if (items.Count() % 8 != 0) { rows++; } inventoryT.Field("m_height").SetValue(rows); TombStone tombstone = chest.GetComponent <TombStone>(); tombstone.Setup(command.packagename, playerProfile.GetPlayerID()); } myCurrency = command.currency; List <string> itemStrings = new List <string>(); foreach (string itemString in items) { Dbgl($"Receving {itemString}"); string[] nameAmount = itemString.Split(','); string name = nameAmount[0]; GameObject prefab = ZNetScene.instance.GetPrefab(name); if (!prefab) { Dbgl($"Item {name} not found!"); continue; } int amount = int.Parse(nameAmount[1]); if (useTombstone.Value) { ItemDrop.ItemData item = prefab.GetComponent <ItemDrop>().m_itemData; double slotsNeed = amount / item.m_shared.m_maxStackSize / 8; inventoryT.Field("m_height").SetValue((int)inventoryT.Field("m_height").GetValue() + (int)Math.Round(slotsNeed, 0)); while (amount >= item.m_shared.m_maxStackSize) { int stack = Mathf.Min(item.m_shared.m_maxStackSize, amount); //chest.GetComponent<Container>().GetInventory().AddItem(_newItem); chest.GetComponent <Container>().GetInventory().AddItem(name, stack, item.m_quality, item.m_variant, Player.m_localPlayer.GetPlayerID(), Player.m_localPlayer.GetPlayerName()); amount = amount - stack; } if (amount > 0) { //chest.GetComponent<Container>().GetInventory().AddItem(_newItem2); chest.GetComponent <Container>().GetInventory().AddItem(name, amount, item.m_quality, item.m_variant, Player.m_localPlayer.GetPlayerID(), Player.m_localPlayer.GetPlayerName()); } itemStrings.Add($"{Localization.instance.Localize(item.m_shared.m_name)} {nameAmount[0]}"); } else { if (amount == 1) { var go = Instantiate(prefab, Player.m_localPlayer.transform.position + Player.m_localPlayer.transform.forward * 2f + Vector3.up, Quaternion.identity); var item = go.GetComponent <ItemDrop>().m_itemData; item.m_durability = item.m_shared.m_maxDurability; Player.m_localPlayer.Message(MessageHud.MessageType.TopLeft, string.Format(rewardString.Value, Localization.instance.Localize(go.GetComponent <ItemDrop>().m_itemData.m_shared.m_name)), 0, null); } else { for (int j = 0; j < amount; j++) { Vector3 b = UnityEngine.Random.insideUnitSphere * 0.5f; var go = Instantiate(prefab, Player.m_localPlayer.transform.position + Player.m_localPlayer.transform.forward * 2f + Vector3.up + b, Quaternion.identity); var item = go.GetComponent <ItemDrop>().m_itemData; item.m_durability = item.m_shared.m_maxDurability; Player.m_localPlayer.Message(MessageHud.MessageType.TopLeft, Localization.instance.Localize(go.GetComponent <ItemDrop>().m_itemData.m_shared.m_name), 0, null); } } } } if (useTombstone.Value) { inventoryT.Method("Changed").GetValue(); chest.GetComponent <ZNetView>().GetZDO().Set("ServerReward", string.Format(packageInfoString.Value, command.packagename, playerProfile.GetName()) + "\r\n" + string.Join("\r\n", itemStrings)); } } else if (command.command == "SendStoreInfo") { if (command.currency == -1) { Dbgl("Error getting store info"); return; } myCurrency = command.currency; windowTitleText = command.storeTitle; currencyString.Value = command.currencyString; storePackages = GetStorePackagesFromString(command.storeInventory); Dbgl($"Got store inventory {storePackages.Count}, user currency: {myCurrency}"); storeOpen = true; } else if (command.command == "SendConsoleString") { Traverse.Create(Console.instance).Method("AddString", new object[] { command.data }).GetValue(); Dbgl(command.data); } } }