public static void Patch(HarmonyInstance harmony) { Type creatureType = typeof(Creature); Type thisType = typeof(CustomFishPatcher); harmony.Patch(creatureType.GetMethod("Start", BindingFlags.Public | BindingFlags.Instance), null, new HarmonyMethod(thisType.GetMethod("CreatureStart_Postfix", BindingFlags.NonPublic | BindingFlags.Static)), null); Logger.Log("CustomFishPatcher is done.", LogLevel.Debug); }
private static void CreatureStart_Postfix(Creature __instance) { if (usedCreatures.Contains(__instance) || CustomFishHandler.fishTechTypes.Count == 0) { return; } TechTag tag = __instance.GetComponent <TechTag>(); if (tag) { if (CustomFishHandler.fishTechTypes.Contains(tag.type)) { return; } } if (Random.value < 0.1f) { Logger.Log($"[FishFramework] Selecting fish out of {CustomFishHandler.fishTechTypes.Count} total types", LogLevel.Debug); int randomIndex = Random.Range(0, CustomFishHandler.fishTechTypes.Count); TechType randomFish = CustomFishHandler.fishTechTypes[randomIndex]; GameObject fish = CraftData.InstantiateFromPrefab(randomFish); // Deletes the fish if it is a ground creature spawned in water if (fish.GetComponent <WalkOnGround>() && !__instance.GetComponent <WalkOnGround>()) { GameObject.Destroy(fish); return; } // Deletes the fish if it is a water creature spawned on ground if (!fish.GetComponent <WalkOnGround>() && __instance.GetComponent <WalkOnGround>()) { GameObject.Destroy(fish); return; } fish.transform.position = __instance.transform.position; usedCreatures.Add(__instance); } }
public override GameObject GetGameObject() { Logger.Log($"[FishFramework] Initializing fish: {ClassID}", LogLevel.Debug); GameObject mainObj = modelPrefab; Logger.Log("[FishFramework] Setting correct shaders on renderers", LogLevel.Debug); Renderer[] renderers = mainObj.GetComponentsInChildren <Renderer>(); foreach (Renderer rend in renderers) { rend.material.shader = Shader.Find("MarmosetUBER"); } Logger.Log("[FishFramework] Adding essential components to object", LogLevel.Debug); Rigidbody rb = mainObj.GetOrAddComponent <Rigidbody>(); rb.useGravity = false; rb.angularDrag = 1f; WorldForces forces = mainObj.GetOrAddComponent <WorldForces>(); forces.useRigidbody = rb; forces.aboveWaterDrag = 0f; forces.aboveWaterGravity = 9.81f; forces.handleDrag = true; forces.handleGravity = true; forces.underwaterDrag = 1f; forces.underwaterGravity = 0; forces.waterDepth = Ocean.main.GetOceanLevel(); forces.enabled = false; forces.enabled = true; mainObj.GetOrAddComponent <EntityTag>().slotType = EntitySlot.Type.Creature; mainObj.GetOrAddComponent <PrefabIdentifier>().ClassId = ClassID; mainObj.GetOrAddComponent <TechTag>().type = TechType; mainObj.GetOrAddComponent <SkyApplier>().renderers = renderers; mainObj.GetOrAddComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Near; mainObj.GetOrAddComponent <LiveMixin>().health = 10f; Creature creature = mainObj.GetOrAddComponent <Creature>(); creature.initialCuriosity = AnimationCurve.Linear(0f, 0.5f, 1f, 0.5f); creature.initialFriendliness = AnimationCurve.Linear(0f, 0.5f, 1f, 0.5f); creature.initialHunger = AnimationCurve.Linear(0f, 0.5f, 1f, 0.5f); SwimBehaviour behaviour = null; if (isWaterCreature) { behaviour = mainObj.GetOrAddComponent <SwimBehaviour>(); SwimRandom swim = mainObj.GetOrAddComponent <SwimRandom>(); swim.swimVelocity = swimSpeed; swim.swimRadius = swimRadius; swim.swimInterval = swimInterval; } else { behaviour = mainObj.GetOrAddComponent <WalkBehaviour>(); WalkOnGround walk = mainObj.GetOrAddComponent <WalkOnGround>(); OnSurfaceMovement move = mainObj.GetOrAddComponent <OnSurfaceMovement>(); move.onSurfaceTracker = mainObj.GetOrAddComponent <OnSurfaceTracker>(); } Locomotion loco = mainObj.GetOrAddComponent <Locomotion>(); loco.useRigidbody = rb; mainObj.GetOrAddComponent <EcoTarget>().type = EcoTargetType.Peeper; mainObj.GetOrAddComponent <CreatureUtils>(); mainObj.GetOrAddComponent <VFXSchoolFishRepulsor>(); SplineFollowing spline = mainObj.GetOrAddComponent <SplineFollowing>(); spline.locomotion = loco; spline.levelOfDetail = mainObj.GetOrAddComponent <BehaviourLOD>(); spline.GoTo(mainObj.transform.position + mainObj.transform.forward, mainObj.transform.forward, 5f); behaviour.splineFollowing = spline; if (pickupable) { Logger.Log("[FishFramework] Adding pickupable component", LogLevel.Debug); mainObj.GetOrAddComponent <Pickupable>(); } creature.ScanCreatureActions(); return(mainObj); }