private void GiveResourceOnDamage(GameObject target, bool isAlive, bool wasAlive) { TechType techType = CraftData.GetTechType(target); HarvestType harvestTypeFromTech = CraftData.GetHarvestTypeFromTech(techType); if (techType == TechType.Creepvine) { GoalManager.main.OnCustomGoalEvent("Cut_Creepvine"); } if ((harvestTypeFromTech == HarvestType.DamageAlive && wasAlive) || (harvestTypeFromTech == HarvestType.DamageDead && !isAlive)) { int num = 1; if (harvestTypeFromTech == HarvestType.DamageAlive && !isAlive) { num += CraftData.GetHarvestFinalCutBonus(techType); } TechType harvestOutputData = CraftData.GetHarvestOutputData(techType); if (harvestOutputData != TechType.None) { CraftData.AddToInventory(harvestOutputData, num, false, false); } } }
public static void junkFill() { System.Random random = new System.Random(); TechType[] listofstuff = { TechType.AcidMushroomSpore, TechType.Lead, TechType.Diamond, TechType.Magnetite, TechType.UraniniteCrystal, TechType.SeaTreaderPoop, TechType.BloodOil, TechType.SmallFanSeed, TechType.PosterAurora, TechType.DepletedReactorRod, TechType.Magnesium, TechType.MercuryOre }; for (int i = 0; i < 48; i++) { CraftData.AddToInventory(listofstuff[random.Next(listofstuff.Length)], 1, false, false); } }
private static bool Prefix(TechType techType, int num = 1, bool noMessage = false, bool spawnIfCantAdd = true) { if (techType == TechType.Titanium && num == 2 && noMessage == false && spawnIfCantAdd == true) { CraftData.AddToInventory(TechType.Titanium); CraftData.AddToInventory(TechType.Copper); return(false); } return(true); }
private static IEnumerator AddbrokenRestoPlayerInv(BreakableResource __instance, AssetReferenceGameObject gameObject) { CoroutineTask <GameObject> task = AddressablesUtility.InstantiateAsync(gameObject.RuntimeKey as string); yield return(task); GameObject prefab = task.GetResult(); var pickupable = prefab.GetComponent <Pickupable>(); pickupable.Initialize(); CraftData.AddToInventory(pickupable.GetTechType()); yield break; }
private static bool Prefix(TechType techType, int num, bool noMessage, bool spawnIfCantAdd) { if (QModManager.API.QModServices.Main.ModPresent("IngredientsFromScanning") || techType != TechType.Titanium || num != 2 || noMessage || !spawnIfCantAdd) { return(true); } CraftData.AddToInventory(TechType.Titanium); CraftData.AddToInventory(TechType.Copper); return(false); }
/// <summary> /// A method that takes the tank from holder and gives it to the player. /// </summary> private void TakeTank() { var size = CraftData.GetItemSize(TechType.FireExtinguisher); if (!Inventory.main.HasRoomFor(size.x, size.y)) { QuickLogger.Message(Language.main.Get("InventoryFull")); return; } CraftData.AddToInventory(TechType.FireExtinguisher, 1, false, false); _hasTank = false; _tankMesh.SetActive(false); gameObject.GetComponent <FireExtinguisher>().fuel = _fuel; }
//private void GiveResourceOnDamage(GameObject target, bool isAlive, bool wasAlive) public static void GiveResourceOnDamage_Postfix(GameObject target, bool isAlive, bool wasAlive) { TechType techType = CraftData.GetTechType(target); if ((int)techType == (int)purplePineConeTechType) // If it's our custom purple pinecone { #if DEBUG_KNIFE Logger.Log("DEBUG: Entering custom purple pinecone event. techType=[" + (int)techType + "][" + techType.AsString(false) + "] purplePineConeTechType=[" + (int)purplePineConeTechType + "][" + purplePineConeTechType.AsString(false) + "]"); #endif HarvestType harvestTypeFromTech = CraftData.GetHarvestTypeFromTech(techType); if ((harvestTypeFromTech == HarvestType.DamageAlive && wasAlive) || (harvestTypeFromTech == HarvestType.DamageDead && !isAlive)) { CraftData.AddToInventory(TechType.Salt, 1, false, false); // Add one salt in player's inventory } } }
//private void GiveResourceOnDamage(GameObject target, bool isAlive, bool wasAlive) public static void GiveResourceOnDamage_Postfix(GameObject target, bool isAlive, bool wasAlive) { TechType techType = CraftData.GetTechType(target); if ((int)techType == (int)purplePineConeTechType && purplePineConeTechType != TechType.None) // If it's our custom purple pinecone { #if DEBUG_KNIFE Logger.Log("DEBUG: Entering custom purple pinecone event. techType=[" + (int)techType + "][" + techType.AsString(false) + "] purplePineConeTechType=[" + (int)purplePineConeTechType + "][" + purplePineConeTechType.AsString(false) + "]"); #endif #if BELOWZERO HarvestType harvestTypeFromTech = TechData.GetHarvestType(techType); #else HarvestType harvestTypeFromTech = CraftData.GetHarvestTypeFromTech(techType); #endif if ((harvestTypeFromTech == HarvestType.DamageAlive && wasAlive) || (harvestTypeFromTech == HarvestType.DamageDead && !isAlive)) { CraftData.AddToInventory(ConfigSwitcher.PurplePineconeDroppedResource, ConfigSwitcher.PurplePineconeDroppedResourceAmount, false, false); // This will add PurplePineconeDroppedResourceAmount of PurplePineconeDroppedResource in player's inventory } } }
public static void randomBlueprintUnlock() { System.Random random = new System.Random(); TechType[] blueprintTech = { TechType.BaseBioReactor, TechType.RocketBase, TechType.Constructor, TechType.Exosuit, TechType.BaseMoonpool, TechType.BaseNuclearReactor, TechType.PropulsionCannon, TechType.Seamoth, TechType.StasisRifle, TechType.ThermalPlant, TechType.Transfuser, TechType.Workbench, TechType.Techlight, TechType.LEDLight, TechType.CyclopsHullBlueprint, TechType.CyclopsBridgeBlueprint, TechType.CyclopsEngineBlueprint, TechType.CyclopsDockingBayBlueprint, TechType.Seaglide, TechType.Beacon, TechType.BatteryCharger, TechType.BaseObservatory, TechType.FiltrationMachine, TechType.CoffeeVendingMachine, TechType.BaseMapRoom, TechType.BaseLadder }; int randomNum = random.Next(blueprintTech.Length); int counter = 0; while (CrafterLogic.IsCraftRecipeUnlocked(blueprintTech[randomNum]) && counter < 50) { randomNum = random.Next(blueprintTech.Length); counter++; } if (CraftData.IsAllowed(blueprintTech[randomNum]) && KnownTech.Add(blueprintTech[randomNum], true)) { ErrorMessage.AddDebug("Unlocked " + Language.main.Get(blueprintTech[randomNum].AsString(false))); } else { CraftData.AddToInventory(TechType.Titanium, 2); } }
public static void GetBaseResourceOnDamage(TechType harvestOutputData, int amount, bool noMessage, bool spawnIfCantAdd) { amount += Stats.KnifeData.BaseResourceOnDamage - 1; // subtracting 1 to account for the game adding 1 by default spawnIfCantAdd = Stats.KnifeData.SpawnResourceIfCantAdd; CraftData.AddToInventory(harvestOutputData, amount, noMessage, spawnIfCantAdd); }
private static void BreakIntoResources_Patch(BreakableResource __instance) { __instance.SendMessage("OnBreakResource", null, SendMessageOptions.DontRequireReceiver); if (__instance.gameObject.GetComponent <VFXBurstModel>()) { __instance.gameObject.BroadcastMessage("OnKill"); } else { UnityEngine.Object.Destroy(__instance.gameObject); } if (__instance.customGoalText != "") { GoalManager.main.OnCustomGoalEvent(__instance.customGoalText); } bool flag = false; for (int i = 0; i < __instance.numChances; i++) { GameObject gameObject = __instance.ChooseRandomResource(); if (gameObject) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "1 - Random Resouce is called"); if (Player.main.GetVehicle() is Exosuit exosuit) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "2 - Start AddToPrawn over randomress"); AddtoPrawn(__instance, exosuit, gameObject); } else { if ((Inventory.main.equipment.GetTechTypeInSlot("Gloves") == MetalHands.MetalHandsMK2TechType) | (MetalHands.Config.Config_fastcollect == true)) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "3 - Player has glove - randomress"); Vector2int size = CraftData.GetItemSize(CraftData.GetTechType(gameObject)); Inventory inventory = Inventory.Get(); if (inventory.HasRoomFor(size.x, size.y)) { CraftData.AddToInventory(CraftData.GetTechType(gameObject)); } else { __instance.SpawnResourceFromPrefab(gameObject); } } else { __instance.SpawnResourceFromPrefab(gameObject); } } flag = true; } } if (!flag) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "5 - default resouce is called"); if (Player.main.GetVehicle() is Exosuit exosuit) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "6 - Start AddToPrawn over defaultress"); AddtoPrawn(__instance, exosuit, __instance.defaultPrefab); } else if ((Inventory.main.equipment.GetTechTypeInSlot("Gloves") == MetalHands.MetalHandsMK2TechType) | (MetalHands.Config.Config_fastcollect == true)) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "7 - Player has glove - defaultress"); Vector2int size = CraftData.GetItemSize(CraftData.GetTechType(__instance.defaultPrefab)); Inventory inventory = Inventory.Get(); if (inventory.HasRoomFor(size.x, size.y)) { CraftData.AddToInventory(CraftData.GetTechType(__instance.defaultPrefab)); } else { __instance.SpawnResourceFromPrefab(__instance.defaultPrefab); } } else { __instance.SpawnResourceFromPrefab(__instance.defaultPrefab); } } FMODUWE.PlayOneShot(__instance.breakSound, __instance.transform.position, 1f); if (__instance.hitFX) { Utils.PlayOneShotPS(__instance.breakFX, __instance.transform.position, Quaternion.Euler(new Vector3(270f, 0f, 0f)), null); } QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "9 - Original Methode ending"); }
private static void AddInventory(TechType techType, int count = 1, bool bNoMessage = false, bool bSpawnIfCantAdd = true) { // Ripped<cough>based upon MrPurple6411's method Deconstruct_Patch from the BuilderModule mod Vehicle thisVehicle = Player.main.GetVehicle(); if (thisVehicle != null) { GameObject gameObject = CraftData.InstantiateFromPrefab(techType, false); Pickupable component = gameObject.GetComponent <Pickupable>(); if (thisVehicle is Exosuit exosuit) { StorageContainer storageContainer = exosuit.storageContainer; if (storageContainer.container.HasRoomFor(component)) { string name = Language.main.Get(component.GetTechName()); ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name)); uGUI_IconNotifier.main.Play(component.GetTechType(), uGUI_IconNotifier.AnimationType.From, null); #if SUBNAUTICA component = component.Initialize(); #elif BELOWZERO component.Initialize(); #endif var item = new InventoryItem(component); storageContainer.container.UnsafeAdd(item); component.PlayPickupSound(); return; } } else { var seamoth = (SeaMoth)thisVehicle; bool storageCheck = false; for (int i = 0; i < 12; i++) { try { ItemsContainer storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule); if (storage != null && storage.HasRoomFor(component)) { string name = Language.main.Get(component.GetTechName()); ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name)); uGUI_IconNotifier.main.Play(component.GetTechType(), uGUI_IconNotifier.AnimationType.From, null); #if SUBNAUTICA component = component.Initialize(); #elif BELOWZERO component.Initialize(); #endif var item = new InventoryItem(component); storage.UnsafeAdd(item); component.PlayPickupSound(); storageCheck = true; break; } } catch (Exception) { continue; } } if (storageCheck) { return; } } } CraftData.AddToInventory(techType, count, bNoMessage, bSpawnIfCantAdd); }
private static void AddInventory(TechType techType, int count = 1, bool bNoMessage = false, bool bSpawnIfCantAdd = true) { // Ripped<cough>based upon MrPurple6411's method Deconstruct_Patch from the BuilderModule if (Player.main.isPiloting) { #if SUBNAUTICA_STABLE //GameObject gameObject = CraftData.InstantiateFromPrefab(techType, false); GameObject prefabForTechType = CraftData.GetPrefabForTechType(techType, true); GameObject gameObject = (prefabForTechType != null) ? global::Utils.SpawnFromPrefab(prefabForTechType, null) : global::Utils.CreateGenericLoot(techType); #elif BELOWZERO GameObject gameObject = CraftData.InstantiateFromPrefab(null, techType, false); // Coming back to this months later, I didn't think this worked in BZ, because it's not async. But apparently it does... #endif Pickupable pickup = gameObject.GetComponent <Pickupable>(); if (pickup != null) { pickup.Initialize(); // This is kind of messy but it's an easy way to get the cross-game code running. In SN1 modules will always == null so the block won't run; but it'll still compile. #if SUBNAUTICA_STABLE Equipment modules = null; #elif BELOWZERO SeaTruckUpgrades upgrades = Player.main.GetComponentInParent <SeaTruckUpgrades>(); Equipment modules = upgrades?.modules; #endif if (modules != null && TechTypeHandler.TryGetModdedTechType("SeaTruckStorage", out TechType storageType)) { //HashSet<string> TruckSlotIDs = modules.equipment.Keys.ToSet<string>(); List <string> TruckSlotIDs = null; modules.GetSlots(EquipmentType.SeaTruckModule, TruckSlotIDs); foreach (string slot in TruckSlotIDs) { InventoryItem item = modules.GetItemInSlot(slot); if (item.item.GetTechType() == storageType) { //InventoryItem item = modules.GetItemInSlot(slot); if (item.item.TryGetComponent(out SeamothStorageContainer seamothStorageContainer)) { InventoryItem newItem = new InventoryItem(pickup); if (seamothStorageContainer.container.AddItem(newItem) != null) { string name = Language.main.Get(pickup.GetTechName()); ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name)); //uGUI_IconNotifier.main.Play(pickup.GetTechType(), uGUI_IconNotifier.AnimationType.From, null); uGUI_IconNotifier.main.Play(techType, uGUI_IconNotifier.AnimationType.From, null); pickup.PlayPickupSound(); #if !RELEASE Logger.Log(Logger.Level.Debug, $"Adding tech {techType} to Seatruck storage"); #endif return; } } } } } else { Vehicle thisVehicle = Player.main.GetVehicle(); if (thisVehicle != null) { if (thisVehicle is Exosuit exo) { StorageContainer storageContainer = exo.storageContainer; if (storageContainer != null) { int lastCount = storageContainer.container.GetCount(techType); storageContainer.container.AddItem(pickup); int techCount = storageContainer.container.GetCount(techType); #if !RELEASE Logger.Log(Logger.Level.Debug, $"Adding tech {techType.AsString().PadLeft(15)} to Exosuit storage; previous count {lastCount}, new count {techCount}"); #endif if (techCount - lastCount == 1) { string name = Language.main.Get(pickup.GetTechName()); ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name)); uGUI_IconNotifier.main.Play(pickup.GetTechType(), uGUI_IconNotifier.AnimationType.From, null); pickup.PlayPickupSound(); return; } } } else if (thisVehicle is SeaMoth seamoth) { //bool storageCheck = false; List <IItemsContainer> containers = new List <IItemsContainer>(); seamoth.GetAllStorages(containers); //for (int i = 0; i < 12; i++) InventoryItem newItem = new InventoryItem(pickup); foreach (IItemsContainer storage in containers) { try { //ItemsContainer storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule); if (storage is ItemsContainer iContainer) { int lastCount = iContainer.GetCount(techType); iContainer.AddItem(pickup); int techCount = iContainer.GetCount(techType); #if !RELEASE Logger.Log(Logger.Level.Debug, $"Adding tech {techType.AsString().PadLeft(15)} to Seamoth storage; previous count {lastCount}, new count {techCount}"); #endif if (techCount - lastCount == 1) { string name = Language.main.Get(pickup.GetTechName()); ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name)); uGUI_IconNotifier.main.Play(pickup.GetTechType(), uGUI_IconNotifier.AnimationType.From, null); pickup.PlayPickupSound(); //storageCheck = true; return; } } } catch (Exception e) { #if !RELEASE Logger.Log(Logger.Level.Debug, $"Exception adding tech {techType} to Seamoth storage: {e.ToString()}"); #endif continue; } } /*if (storageCheck) * { * return; * }*/ } } } } } #if !RELEASE Logger.Log(Logger.Level.Debug, $"Adding tech {techType} to player inventory"); #endif CraftData.AddToInventory(techType, count, bNoMessage, bSpawnIfCantAdd); }