Skip to content

Commit

Permalink
V2.4.0
Browse files Browse the repository at this point in the history
-Added 4 new events: Challenger, LooseGrasp, Melting and Pixelize
-The don't repeat event % setting now correctly keeps state after dying
-Friend event can now spawn EelLizard
-Speed and Thanksgiving event now work probably with JollyCoop
-LiftOff now has sound if MSC is enabled
-Rifle event now requires MSC
-Added shader source code
-Fixed an exception in Update when game was null
-CE now no longer keeps running when not in game mode
-Renamed event attributes to end with Attribute
-The MakeCreatureAttackCreature EventHelper method is more robust
-Cleaned up some comments + logging
  • Loading branch information
Gamer025 committed Sep 16, 2023
1 parent 2cb5928 commit 87c2cd0
Show file tree
Hide file tree
Showing 20 changed files with 761 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace RainWorldCE.Attributes
/// These events should never be randomly rolled
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
internal class InternalCEEvent : System.Attribute
internal class InternalCEEventAttribute : System.Attribute
{
}
}
2 changes: 1 addition & 1 deletion Attributes/MSCEvent.cs → Attributes/MSCEventAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace RainWorldCE.Attributes
/// These events only work with MSC enabled
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
internal class MSCEvent : System.Attribute
internal class MSCEventAttribute : System.Attribute
{
}
}
8 changes: 6 additions & 2 deletions Docs/CustomChaos.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ In the Remix options one of the lines shows up as ERROR:
You have entered an invalid command in that line (WAIT without time, Non existing event name etc.) This line will do nothing and you should fix it

Internal event names to be used in scripts:
Challenger - Challenger
CreatureMigration - Coming through
CreatureRandomizer - DNA Mutations
Darkness - Darkness / Shaded Region
Darkness - Darkness / Shaded Region
FlipCamera - Camera issues
FoodLevel - Digestive reordering
Friend - The Friend
Expand All @@ -30,13 +31,16 @@ InvertControls - Directional confusion
KarmaLevel - Karma shuffle
LiftOff - Lift off
LizardPack - The pack
LooseGrasp - Hot Potatoes
LowGravity - Low gravity
Melting - Extreme Heat
MovementTime - Super Slugcat
NoodleInvasion - Noodle invasion
PaletteRandomizer - Too many mushrooms
Pixelize - Retro
RainbowCat - Rainbow Cat
RainyDay - Rainy day
RandomLorePearl - A piece of history
RandomLorePearl - A piece of history
RandomSong - Jukebox Hero
Rifle - Free gun
RoomConnectionShuffle - Geographic issues
Expand Down
192 changes: 192 additions & 0 deletions Events/Challenger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
using BepInEx.Logging;
using IL.LizardCosmetics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RainWorldCE.Events
{
internal class Challenger : CEEvent
{
/// <summary>
/// Spawns a random enemy
/// </summary>
public Challenger()
{
_name = "Challenger";
_description = "A new foe has appeared";
}

public override void StartupTrigger()
{
CreatureTemplate.Type creatureType = RandomCreature(EventHelpers.CurrentRoom.AnySkyAccess);
WriteLog(LogLevel.Debug, $"Spawning: {creatureType}");
List<AbstractRoom> adjacendRooms = EventHelpers.GetConnectedRooms(EventHelpers.CurrentRoom);
AbstractRoom sourceRoom = adjacendRooms[rnd.Next(adjacendRooms.Count)];
int destRoomNodeId = EventHelpers.GetNodeIdOfRoomConnection(sourceRoom, EventHelpers.CurrentRoom);
if (creatureType == CreatureTemplate.Type.Vulture || creatureType == MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.MirosVulture)
{
sourceRoom = game.world.offScreenDen;
for (int i = 0; i < EventHelpers.CurrentRoom.realizedRoom.borderExits.Length; i++)
{
if (!(EventHelpers.CurrentRoom.realizedRoom.borderExits[i].type == AbstractRoomNode.Type.SkyExit))
{
continue;
}
destRoomNodeId = i + EventHelpers.CurrentRoom.realizedRoom.exitAndDenIndex.Length;
}
}
int amt = 1;
if (creatureType == CreatureTemplate.Type.Spider)
amt = 16;
for (int i = 0; i < amt; i++)
{
AbstractCreature creature = new AbstractCreature(game.world, StaticWorld.GetCreatureTemplate(creatureType), null, new WorldCoordinate(sourceRoom.index, -1, -1, 0), game.GetNewID());
if (creatureType == CreatureTemplate.Type.Centipede)
{
creature.spawnData = $"{{{UnityEngine.Random.Range(0.6f, 1.0f)}}}";
}
EventHelpers.MakeCreatureAttackCreature(creature, EventHelpers.MainPlayer);
creature.ChangeRooms(new WorldCoordinate(EventHelpers.CurrentRoom.index, -1, -1, destRoomNodeId));
WriteLog(LogLevel.Debug, $"Spawned: {creature}");
if (creatureType == MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.Inspector)
{
creature.abstractAI.RealAI.preyTracker.AddPrey(creature.abstractAI.RealAI.tracker.RepresentationForCreature(EventHelpers.MainPlayer, true));
(creature.realizedCreature as MoreSlugcats.Inspector).anger = 1.0f;
}
}
}

public static CreatureTemplate.Type RandomCreature(bool allowFlying = false)
{
int ran = rnd.Next(111);
if (rnd.Next(100) > 50)
{
if (ModManager.MSC)
{
switch (ran)
{
case < 10:
return CreatureTemplate.Type.GreenLizard;
case < 20:
return MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.EelLizard;
case < 30:
return CreatureTemplate.Type.PinkLizard;
case < 40:
return MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.SpitLizard;
case < 50:
return MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.ZoopLizard;
case < 60:
return CreatureTemplate.Type.BlueLizard;
case < 70:
return CreatureTemplate.Type.WhiteLizard;
case < 80:
return CreatureTemplate.Type.YellowLizard;
case < 90:
return CreatureTemplate.Type.Salamander;
case < 99:
return CreatureTemplate.Type.BlackLizard;
case < 105:
return CreatureTemplate.Type.CyanLizard;
case < 198:
return CreatureTemplate.Type.RedLizard;
case >= 109:
return MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.TrainLizard;

}
}
else
{
switch (ran)
{
case < 20:
return CreatureTemplate.Type.GreenLizard;
case < 40:
return CreatureTemplate.Type.PinkLizard;
case < 60:
return CreatureTemplate.Type.BlueLizard;
case < 70:
return CreatureTemplate.Type.WhiteLizard;
case < 80:
return CreatureTemplate.Type.YellowLizard;
case < 90:
return CreatureTemplate.Type.Salamander;
case < 99:
return CreatureTemplate.Type.BlackLizard;
case < 107:
return CreatureTemplate.Type.CyanLizard;
case >= 107:
return CreatureTemplate.Type.RedLizard;
}
}

}
else
{
ran = rnd.Next(120);
if (ModManager.MSC)
{
switch (ran)
{
case < 15:
return CreatureTemplate.Type.Centipede;
case < 30:
return CreatureTemplate.Type.BigSpider;
case < 40:
return MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.MotherSpider;
case < 50:
if (allowFlying) return CreatureTemplate.Type.Vulture;
else return RandomCreature();
case < 60:
return CreatureTemplate.Type.Spider;
case < 70:
return CreatureTemplate.Type.SpitterSpider;
case < 80:
return CreatureTemplate.Type.Centiwing;
case < 87:
return MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.ScavengerElite;
case < 95:
return MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.FireBug;
case < 101:
return MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.Inspector;
case < 108:
return CreatureTemplate.Type.MirosBird;
case < 114:
if (allowFlying) return MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.MirosVulture;
else return RandomCreature();
case >= 114:
return CreatureTemplate.Type.RedCentipede;

}
}
else
{
switch (ran)
{
case < 20:
return CreatureTemplate.Type.Centipede;
case < 40:
return CreatureTemplate.Type.BigSpider;
case < 55:
if (allowFlying) return CreatureTemplate.Type.Vulture;
else return RandomCreature();
case < 70:
return CreatureTemplate.Type.Spider;
case < 86:
return CreatureTemplate.Type.SpitterSpider;
case < 100:
return CreatureTemplate.Type.Centiwing;
case < 110:
return CreatureTemplate.Type.MirosBird;
case >= 110:
return CreatureTemplate.Type.RedCentipede;
}
}
}
}
}
}


12 changes: 9 additions & 3 deletions Events/EventHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,18 @@ internal static int GetNodeIdOfRoomConnection(AbstractRoom source, AbstractRoom

internal static void MakeCreatureAttackCreature(AbstractCreature attacker, AbstractCreature target)
{
attacker.state.socialMemory.GetOrInitiateRelationship(target.ID).like = -1f;
attacker.state.socialMemory.GetOrInitiateRelationship(target.ID).tempLike = -1f;
if (attacker.state?.socialMemory is not null)
{
attacker.state.socialMemory.GetOrInitiateRelationship(target.ID).like = -1f;
attacker.state.socialMemory.GetOrInitiateRelationship(target.ID).tempLike = -1f;
}
attacker.personality.aggression = 1f;
attacker.personality.dominance = 1f;
attacker.personality.bravery = 1f;
attacker.abstractAI.followCreature = target;
if (attacker.abstractAI is not null)
{
attacker.abstractAI.followCreature = target;
}
}

internal static void MakeCreatureLikeAndFollowCreature(AbstractCreature friend, AbstractCreature target)
Expand Down
2 changes: 1 addition & 1 deletion Events/FlipCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace RainWorldCE.Events
{
/// <summary>
/// Flips the camera either by y
/// Flips the camera vertically
/// </summary>
internal class FlipCamera : CEEvent
{
Expand Down
2 changes: 1 addition & 1 deletion Events/Friend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static CreatureTemplate.Type PickLizardType
case < 10:
return CreatureTemplate.Type.GreenLizard;
case < 20:
return MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.SpitLizard;
return MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.EelLizard;
case < 30:
return CreatureTemplate.Type.PinkLizard;
case < 40:
Expand Down
11 changes: 11 additions & 0 deletions Events/LiftOff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using static SlugcatStats;
using UnityEngine;
using BepInEx.Logging;
using System.Drawing;

namespace RainWorldCE.Events
{
Expand All @@ -23,6 +24,16 @@ public LiftOff()

public override void RecurringTrigger()
{
if (ModManager.MSC)
{
VirtualMicrophone virtMic = game.cameras[0].virtualMicrophone;
SoundLoader.SoundData soundData = virtMic.GetSoundData(MoreSlugcats.MoreSlugcatsEnums.MSCSoundID.Inv_Hit, 2);
if (virtMic.SoundClipReady(soundData))
{
virtMic.soundObjects.Add(new VirtualMicrophone.DisembodiedSound(virtMic, soundData, 0f, 1f, 1f, startAtRandomTime: false, 0));
}
}

foreach (AbstractCreature player in EventHelpers.AllPlayers)
{
player.realizedCreature.mainBodyChunk.vel.y += 100f;
Expand Down
53 changes: 53 additions & 0 deletions Events/LooseGrasp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RainWorldCE.Events
{
/// <summary>
/// Makes the player loose grasp of an item after about 7 seconds if they don't switch hands/replace/drop it
/// </summary>
internal class LooseGrasp : CEEvent
{
public LooseGrasp()
{
_name = "Hot Potatoes";
_description = "Why is everything suddenly hot to the touch?\n Holding stuff for too long might burn you";
_repeatEverySec = 1;
_activeTime = (int)(60 * RainWorldCE.eventDurationMult);
}

Tuple<Creature.Grasp[], Creature.Grasp[], int[]>[] graspCounter = new Tuple<Creature.Grasp[], Creature.Grasp[], int[]>[16]; //4 players should be max but just in case?
public override void RecurringTrigger()
{
for (int playerIndex = 0; playerIndex < EventHelpers.AllPlayers.Count; playerIndex++)
{
AbstractCreature playerA = EventHelpers.AllPlayers[playerIndex];
Creature player = playerA.realizedCreature;
if (graspCounter[playerIndex] is null)
{
graspCounter[playerIndex] = new (player.grasps, (Creature.Grasp[])player.grasps.Clone(), new int[player.grasps.Length]);
}
for (int graspIndex = 0; graspIndex < graspCounter[playerIndex].Item1.Length; graspIndex++)
{
if (ReferenceEquals(graspCounter[playerIndex].Item1[graspIndex], graspCounter[playerIndex].Item2[graspIndex]))
{
graspCounter[playerIndex].Item3[graspIndex] += 1;
}
else
{
graspCounter[playerIndex].Item3[graspIndex] = 0;
graspCounter[playerIndex].Item2[graspIndex] = graspCounter[playerIndex].Item1[graspIndex];
}

if (graspCounter[playerIndex].Item3[graspIndex] > 6)
{
(player as Player).ReleaseGrasp(graspIndex);
}
}
}
}
}
}
Loading

0 comments on commit 87c2cd0

Please sign in to comment.