-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
266 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace SCHIZO.SwarmControl.Redeems.Enums; | ||
|
||
public enum AggressiveCreature | ||
{ | ||
Ermshark, | ||
LilyPaddler, | ||
Cryptosuchus, | ||
SquidShark, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace SCHIZO.SwarmControl.Redeems.Enums; | ||
|
||
public enum CommonResources | ||
{ | ||
Salt, | ||
Quartz, | ||
Titanium, | ||
Copper, | ||
Silver, | ||
Lead, | ||
|
||
FilteredWater, | ||
NutrientBlock | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace SCHIZO.SwarmControl.Redeems.Enums; | ||
|
||
public enum PassiveCreature | ||
{ | ||
Ermfish, | ||
Anneel, | ||
Tutel, | ||
ArcticPeeper, | ||
Bladderfish, | ||
Boomerang, | ||
SpinnerFish, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
using SCHIZO.Commands.Attributes; | ||
using SCHIZO.SwarmControl.Redeems.Enums; | ||
|
||
namespace SCHIZO.SwarmControl.Redeems.Helpful; | ||
|
||
[CommandCategory("Spawns")] | ||
[Redeem( | ||
Name = "give_common", | ||
DisplayName = "Give Common Resource" | ||
DisplayName = "Give Common Resource", | ||
Export = false /// deprecated in favor of <see cref="SeaMonkeyDeliverySystem"/> | ||
)] | ||
internal class GiveCommonResource : ItemFiltered<GiveCommonResource.CommonResources> | ||
internal class GiveCommonResource : ItemFiltered<CommonResources> | ||
{ | ||
protected override string SpawnThingName => "Item"; | ||
public enum CommonResources | ||
{ | ||
Salt, | ||
Quartz, | ||
Titanium, | ||
Copper, | ||
Silver, | ||
Lead, | ||
RibbonPlant, | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
SCHIZO/SwarmControl/Redeems/Helpful/SeaMonkeyDeliverySystem.BelowZero.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using SCHIZO.Commands.Base; | ||
using SCHIZO.Commands.Context; | ||
using SCHIZO.Commands.Output; | ||
using SCHIZO.Helpers; | ||
using SCHIZO.SwarmControl.Redeems.Enums; | ||
using UnityEngine; | ||
using UWE; | ||
using Random = UnityEngine.Random; | ||
|
||
namespace SCHIZO.SwarmControl.Redeems.Helpful; | ||
|
||
#nullable enable | ||
[Redeem( | ||
Name = "redeem_seamonkey_common", | ||
DisplayName = "Sea Monkey Delivery System", | ||
Description = "DISCLAIMER: Delivery not guaranteed." | ||
)] | ||
internal class SeaMonkeyDeliverySystem : Command, IParameters | ||
{ | ||
public IReadOnlyList<Parameter> Parameters => [ | ||
new Parameter(new("item", "Item", "Item you wish delivered."), typeof(CommonResources)) | ||
]; | ||
|
||
protected override object ExecuteCore(CommandExecutionContext ctx) | ||
{ | ||
if (!Player.main) return CommonResults.Error("Requires a loaded game"); | ||
|
||
TechType item; | ||
try | ||
{ | ||
if (!ctx.Input.GetNamedArguments().TryGetValue("item", out CommonResources itemFiltered)) | ||
return CommonResults.Error("Invalid item"); | ||
item = (TechType) Enum.Parse(typeof(TechType), itemFiltered.ToString()); | ||
} | ||
catch (ArgumentException) | ||
{ | ||
return CommonResults.Error("Invalid item"); | ||
} | ||
|
||
CoroutineHost.StartCoroutine(DeliverCoro(item)); | ||
|
||
return "Please note, the streamer may ignore the delivery, or the Sea Monkey may not care enough to deliver. SCHIZOCorp assumes no liability."; | ||
} | ||
|
||
private static readonly Dictionary<TechType, GameObject> _itemPrefabCache = []; | ||
|
||
private IEnumerator DeliverCoro(TechType item) | ||
{ | ||
SeaMonkey monke = FindMonke(); | ||
if (!monke) | ||
{ | ||
TaskResult<SeaMonkey> spawn = new(); | ||
yield return SpawnMonke(spawn); | ||
monke = spawn.Get(); | ||
} | ||
LOGGER.LogDebug("(SMDS) Got target"); | ||
|
||
if (!_itemPrefabCache.TryGetValue(item, out GameObject itemPrefab)) | ||
{ | ||
IPrefabRequest itemPrefabReq = PrefabDatabase.GetPrefabAsync(CraftData.GetClassIdForTechType(item)); | ||
yield return itemPrefabReq; | ||
if (!itemPrefabReq.TryGetPrefab(out itemPrefab)) | ||
{ | ||
LOGGER.LogError($"Could not get prefab for {item}"); // should not happen | ||
yield break; | ||
} | ||
LOGGER.LogDebug("(SMDS) Got prefab"); | ||
} | ||
|
||
SeaMonkeyBringGift gift = monke.GetComponent<SeaMonkeyBringGift>(); | ||
gift.evaluatePriority = 999f; | ||
GameObject itemInstance = GameObject.Instantiate(itemPrefab); | ||
gift.heldItem.Hold(itemInstance); | ||
|
||
gift.timeLastGiftAnimation = -9999f; | ||
SeaMonkeyBringGift.timeLastGlobalSeaMonkeyGift = -9999f; | ||
|
||
if (monke.prevBestAction) | ||
monke.prevBestAction.StopPerform(Time.time); | ||
if (gift.Evaluate(Time.time) == 0) | ||
{ | ||
LOGGER.LogWarning("Sea Monkey got distracted, unlucky"); | ||
} | ||
gift.swimVelocity *= 1.5f; // express delivery | ||
monke.TryStartAction(gift); | ||
|
||
LOGGER.LogInfo("(SMDS) Delivering"); | ||
} | ||
|
||
private static SeaMonkey FindMonke() | ||
{ | ||
return PhysicsHelpers.ObjectsInRange(Player.main.transform.position, 100) | ||
.OfTechType(TechType.SeaMonkey) | ||
.SelectComponentInParent<SeaMonkey>() // sphere cast hits the collider which is on the model | ||
.FirstOrDefault(m => | ||
{ | ||
SeaMonkeyHeldItem held = m.GetComponentInChildren<SeaMonkeyHeldItem>(); | ||
return held && !held.IsHoldingItem(); | ||
}); | ||
} | ||
|
||
private static GameObject? _monkePrefab; | ||
private IEnumerator SpawnMonke(IOut<SeaMonkey> result) | ||
{ | ||
if (!_monkePrefab) | ||
{ | ||
IPrefabRequest request = PrefabDatabase.GetPrefabAsync(CraftData.GetClassIdForTechType(TechType.SeaMonkey)); | ||
yield return request; | ||
request.TryGetPrefab(out _monkePrefab); | ||
} | ||
yield return new WaitUntil(() => SwarmControlManager.Instance.CanSpawn); | ||
|
||
Player player = Player.main; | ||
|
||
Vector3 deltaBehind = 10f * (Random.onUnitSphere - player.transform.forward); | ||
Vector3 spawnPos = player.transform.position + deltaBehind; | ||
|
||
// basic "spawning inside a wall" check | ||
int max = UWE.Utils.RaycastIntoSharedBuffer(player.transform.position, spawnPos); | ||
// closest blocking ray hit | ||
RaycastHit blockingHit = UWE.Utils.sharedHitBuffer.Take(max) | ||
.Where(hit => hit.collider.gameObject != player.gameObject) | ||
.OrderBy(hit => hit.point.DistanceSqrXZ(player.transform.position)) | ||
.FirstOrDefault(); | ||
if (blockingHit.point != default) | ||
spawnPos = blockingHit.point + blockingHit.normal * 0.1f; | ||
|
||
GameObject instance = GameObject.Instantiate(_monkePrefab!); | ||
instance.transform.position = spawnPos; | ||
UnityEngine.Object.Destroy(instance.GetComponent<LargeWorldEntity>()); | ||
result.Set(instance.GetComponentInChildren<SeaMonkey>()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using SCHIZO.Commands.Base; | ||
using SCHIZO.Commands.Context; | ||
using SCHIZO.Commands.Output; | ||
using SCHIZO.Helpers; | ||
using UWE; | ||
|
||
namespace SCHIZO.SwarmControl.Redeems.Misc; | ||
[Redeem( | ||
Name = "redeem_midas", | ||
DisplayName = "Midas' Touch", | ||
Description = "And all that glitters is gold" | ||
)] | ||
public sealed class MidasTouch : Command, IParameters | ||
{ | ||
private static readonly HashSet<TechType> _turnedItems = [ | ||
TechType.Salt, | ||
TechType.Quartz, | ||
TechType.ScrapMetal, | ||
TechType.Titanium, | ||
TechType.Copper, | ||
TechType.Lead, | ||
TechType.Silver, | ||
TechType.Gold, // funny | ||
TechType.Diamond, | ||
TechType.Lithium, | ||
TechType.Magnetite, | ||
TechType.Kyanite, | ||
TechType.Nickel, | ||
|
||
TechType.TwistyBridgesMushroomChunk, | ||
TechType.GenericRibbon, | ||
TechType.JeweledDiskPiece, // table coral | ||
TechType.GenericSpiralChunk, | ||
|
||
TechType.Bladderfish, | ||
TechType.ArcticPeeper, | ||
TechType.SpinnerFish, | ||
TechType.Boomerang, | ||
TechType.Brinewing, | ||
TechType.Hoopfish, | ||
TechType.Spinefish, | ||
TechType.PenguinBaby, // uh oh | ||
TechType.Rockgrub, | ||
TechType.NootFish, | ||
TechType.Symbiote, | ||
TechType.DiscusFish, | ||
TechType.FeatherFishRed, | ||
|
||
TechType.NutrientBlock, | ||
TechType.WaterPurificationTablet, | ||
TechType.BigFilteredWater, | ||
TechType.DisinfectedWater, | ||
TechType.FilteredWater, | ||
]; | ||
|
||
public IReadOnlyList<Parameter> Parameters => []; | ||
|
||
protected override object ExecuteCore(CommandExecutionContext ctx) | ||
{ | ||
if (!Inventory.main) return CommonResults.Error("Requires a loaded game"); | ||
InventoryItem[] items = Inventory.main.container.GetAllItems() | ||
.Where(i => _turnedItems.Contains(i.techType)) | ||
.ToArray(); | ||
if (items.Length == 0) | ||
{ | ||
return CommonResults.Error("No items to turn"); | ||
} | ||
foreach (InventoryItem item in items) | ||
{ | ||
Inventory.main.container.RemoveItem(item.item, true); | ||
} | ||
CoroutineHost.StartCoroutine(InventoryConsoleCommands.ItemCmdSpawnAsync(items.Length, TechType.Gold)); | ||
return CommonResults.OK(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters