Skip to content

Commit

Permalink
more redeems
Browse files Browse the repository at this point in the history
  • Loading branch information
Govorunb committed Jun 14, 2024
1 parent 82834a1 commit 5920266
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 35 deletions.
9 changes: 9 additions & 0 deletions SCHIZO/SwarmControl/Redeems/Enums/AggressiveCreature.cs
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,
}
14 changes: 14 additions & 0 deletions SCHIZO/SwarmControl/Redeems/Enums/CommonResources.cs
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
}
12 changes: 12 additions & 0 deletions SCHIZO/SwarmControl/Redeems/Enums/PassiveCreature.cs
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,
}
16 changes: 4 additions & 12 deletions SCHIZO/SwarmControl/Redeems/Helpful/GiveCommonResource.cs
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,
}
}
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>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
using SCHIZO.Commands.Output;
using SCHIZO.Creatures.Components;
using SCHIZO.Creatures.Ermfish;
using SCHIZO.Events.Ermcon;
using SCHIZO.Helpers;
using SCHIZO.Sounds.Players;
using UnityEngine;
using UWE;

namespace SCHIZO.SwarmControl.Redeems.Spawns;
namespace SCHIZO.SwarmControl.Redeems.Misc;

#nullable enable
[Redeem(Name = "redeem_bigerm",
Expand Down Expand Up @@ -87,6 +88,13 @@ private void GetBigAndWinWildPrizes(GameObject bigErm)
bigErm.GetComponent<Carryable>().enabled = false;
bigErm.GetComponent<CarryCreature>().enabled = false;
bigErm.GetComponent<ErmStack>().enabled = false;

ErmconAttendee ermconVisitor = bigErm.GetComponent<ErmconAttendee>();
if (ermconVisitor)
UnityEngine.Object.Destroy(ermconVisitor);
ErmconPanelist ermconHost = bigErm.EnsureComponent<ErmconPanelist>();
ermconHost.entertainmentFactor = 5f;

bigErm.GetComponentsInChildren<SoundPlayer>()
.ForEach(plr =>
{
Expand Down
77 changes: 77 additions & 0 deletions SCHIZO/SwarmControl/Redeems/Misc/MidasTouch.cs
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,

Check failure on line 32 in SCHIZO/SwarmControl/Redeems/Misc/MidasTouch.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'TechType' does not contain a definition for 'TwistyBridgesMushroomChunk'
TechType.GenericRibbon,

Check failure on line 33 in SCHIZO/SwarmControl/Redeems/Misc/MidasTouch.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'TechType' does not contain a definition for 'GenericRibbon'
TechType.JeweledDiskPiece, // table coral
TechType.GenericSpiralChunk,

Check failure on line 35 in SCHIZO/SwarmControl/Redeems/Misc/MidasTouch.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'TechType' does not contain a definition for 'GenericSpiralChunk'

TechType.Bladderfish,
TechType.ArcticPeeper,

Check failure on line 38 in SCHIZO/SwarmControl/Redeems/Misc/MidasTouch.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'TechType' does not contain a definition for 'ArcticPeeper'
TechType.SpinnerFish,

Check failure on line 39 in SCHIZO/SwarmControl/Redeems/Misc/MidasTouch.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'TechType' does not contain a definition for 'SpinnerFish'
TechType.Boomerang,
TechType.Brinewing,

Check failure on line 41 in SCHIZO/SwarmControl/Redeems/Misc/MidasTouch.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'TechType' does not contain a definition for 'Brinewing'
TechType.Hoopfish,
TechType.Spinefish,
TechType.PenguinBaby, // uh oh

Check failure on line 44 in SCHIZO/SwarmControl/Redeems/Misc/MidasTouch.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'TechType' does not contain a definition for 'PenguinBaby'
TechType.Rockgrub,
TechType.NootFish,

Check failure on line 46 in SCHIZO/SwarmControl/Redeems/Misc/MidasTouch.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'TechType' does not contain a definition for 'NootFish'
TechType.Symbiote,

Check failure on line 47 in SCHIZO/SwarmControl/Redeems/Misc/MidasTouch.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'TechType' does not contain a definition for 'Symbiote'
TechType.DiscusFish,

Check failure on line 48 in SCHIZO/SwarmControl/Redeems/Misc/MidasTouch.cs

View workflow job for this annotation

GitHub Actions / build (Subnautica)

'TechType' does not contain a definition for '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();
}
}
11 changes: 2 additions & 9 deletions SCHIZO/SwarmControl/Redeems/Spawns/SpawnAggressiveCreature.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SCHIZO.Commands.Attributes;
using SCHIZO.SwarmControl.Redeems.Enums;

namespace SCHIZO.SwarmControl.Redeems.Spawns;

Expand All @@ -8,15 +9,7 @@ namespace SCHIZO.SwarmControl.Redeems.Spawns;
DisplayName = "Spawn Aggressive Creature",
Description = "Spawn an aggressive creature near the player"
)]
internal class SpawnAggressiveCreature : SpawnFiltered<SpawnAggressiveCreature.AggressiveCreatures>
internal class SpawnAggressiveCreature : SpawnFiltered<AggressiveCreature>
{
public enum AggressiveCreatures
{
Ermshark,
LilyPaddler,
Cryptosuchus,
SquidShark,
}

protected override float SpawnDistance => 10;
}
15 changes: 2 additions & 13 deletions SCHIZO/SwarmControl/Redeems/Spawns/SpawnPassiveCreature.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SCHIZO.Commands.Attributes;
using SCHIZO.SwarmControl.Redeems.Enums;

namespace SCHIZO.SwarmControl.Redeems.Spawns;

Expand All @@ -9,16 +10,4 @@ namespace SCHIZO.SwarmControl.Redeems.Spawns;
DisplayName = "Spawn Passive Creature",
Description = "Spawn a passive creature near the player"
)]
internal class SpawnPassiveCreature : SpawnFiltered<SpawnPassiveCreature.PassiveCreature>
{
public enum PassiveCreature
{
Ermfish,
Anneel,
Tutel,
ArcticPeeper,
Bladderfish,
Boomerang,
SpinnerFish,
}
}
internal class SpawnPassiveCreature : SpawnFiltered<PassiveCreature>;

0 comments on commit 5920266

Please sign in to comment.