Skip to content

Commit

Permalink
feat: exiled 9
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeman2332 committed Dec 22, 2024
1 parent 95fe2f7 commit ee40f12
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
13 changes: 10 additions & 3 deletions MERRoomReplacement/Api/RoomReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ public static SchematicObject ReplaceRoom(RoomType roomType, RoomSchematic roomS
? null
: cachedRoomData.Schematic;
}

DestroyRoom(room);


var schematicSerializable = new SchematicSerializable(roomSchematic.SchematicName);
var rotation = Quaternion.Euler(schematicRotation + room.transform.localRotation.eulerAngles);
var schematic = ObjectSpawner.SpawnSchematic(schematicSerializable, schematicPosition + room.Position, rotation);
var schematic = ObjectSpawner.SpawnSchematic(schematicSerializable, schematicPosition, rotation);
schematic.Position += schematicPosition;

Log.Debug($"[{roomType}->{roomSchematic.SchematicName}] Schematic spawned at {schematic.Position}");

API.SpawnedObjects.Add(schematic);

Expand All @@ -75,8 +77,13 @@ public static SchematicObject ReplaceRoom(RoomType roomType, RoomSchematic roomS
/// <param name="delay">Delay in seconds until replacement</param>
public static void ReplaceRoom(RoomType roomType, RoomSchematic roomSchematic, float delay)
{
Log.Debug($"[{roomType}->{roomSchematic.SchematicName}] Starting replacement coroutine with {delay} seconds delay");

Timing.CallDelayed(delay, () =>
{

Log.Debug($"[{roomType}->{roomSchematic.SchematicName}] Coroutine: Replacing...");

_ = ReplaceRoom(roomType, roomSchematic);
});
}
Expand Down
1 change: 1 addition & 0 deletions MERRoomReplacement/Commands/ReplaceRoomCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using MapEditorReborn.API.Features;
using MERRoomReplacement.Api;
using MERRoomReplacement.Api.Structures;

// ReSharper disable HeuristicUnreachableCode
// ReSharper disable ConditionIsAlwaysTrueOrFalse

Expand Down
22 changes: 19 additions & 3 deletions MERRoomReplacement/Events/Handlers/ReplacementHandler.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Collections.Generic;
using Exiled.Events.Handlers;
using Exiled.API.Features;
using MERRoomReplacement.Api;
using MERRoomReplacement.Api.Structures;
using MERRoomReplacement.Events.Interfaces;
using UnityEngine;
using Server = Exiled.Events.Handlers.Server;

namespace MERRoomReplacement.Events.Handlers;

Expand All @@ -25,8 +26,23 @@ private void OnWaitingForPlayers()
{
foreach (var roomSchematic in _replacementOptions)
{
if (roomSchematic.SpawnChance >= 100 || Random.Range(0, 100) > roomSchematic.SpawnChance)
RoomReplacer.ReplaceRoom(roomSchematic.TargetRoomType, roomSchematic, roomSchematic.SpawnDelay);
Log.Debug($"Schematic name: {roomSchematic.SchematicName} | Room: {roomSchematic.TargetRoomType} | Chance: {roomSchematic.SpawnChance}%");

if (roomSchematic.SpawnChance >= 100)
{
Log.Debug("Spawn chance is more or equal to 100, starting replacing");
}
else if (Random.Range(0, 101) is var chance && roomSchematic.SpawnChance >= chance)
{
Log.Debug($"Schematic chance {roomSchematic.SpawnChance} >= generated {chance}, starting replacing");
}
else
{
Log.Debug($"Generated chance {chance} is less then {roomSchematic}, skipping..");
continue;
}

RoomReplacer.ReplaceRoom(roomSchematic.TargetRoomType, roomSchematic, roomSchematic.SpawnDelay);
}
}

Expand Down
7 changes: 4 additions & 3 deletions MERRoomReplacement/MERRoomReplacement.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EXILEDOFFICIAL" Version="8.11.0" />
<PackageReference Include="Lib.Harmony" Version="2.0.4"/>

<Reference Include="Assembly-CSharp-firstpass" HintPath="$(EXILED_References)\Assembly-CSharp-firstpass.dll" Private="false" />
<Reference Include="CommandSystem.Core" HintPath="$(EXILED_References)\CommandSystem.Core.dll" Private="false" />
<Reference Include="Mirror" HintPath="$(EXILED_References)\Mirror.dll" Private="false" />
Expand All @@ -19,4 +16,8 @@
<Reference Include="MapEditorReborn" HintPath="$(EXILED_Plugins)\MapEditorReborn.dll" Private="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ExMod.Exiled" Version="9.0.0-beta.1" />
</ItemGroup>

</Project>

0 comments on commit ee40f12

Please sign in to comment.