Fixed treasure room event for bedroom Fixed painting's interaction with MattyFixes Fixed critical damage bug introduced by v62 Increased lights spawn for all presets by a lot Added Coroner compatibility Added Scarlet Devil Mansion (moon) to the interior's spawn list Lights now have a chance of flickering and dying
104 lines
3.8 KiB
C#
104 lines
3.8 KiB
C#
using DunGen;
|
|
using ScarletMansion.GamePatch.Managers;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using TMPro;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
|
|
namespace ScarletMansion.GamePatch.Components.TreasureRoom {
|
|
public class TreasureRoomTimeEvent : TreasureRoom {
|
|
|
|
[Header("References")]
|
|
public GameObject timeClockPrefab;
|
|
public Transform[] timeClockSpawnTransforms;
|
|
private int timeClockSpawnTransformIndex;
|
|
|
|
[Header("Values")]
|
|
public Vector2Int hourRange;
|
|
private int hourSelected;
|
|
private int mintuesSelected;
|
|
|
|
public override bool CanOpen() {
|
|
var time = Utility.GetTime();
|
|
var ready = time.hours > hourSelected || (time.hours >= hourSelected && time.minutes >= mintuesSelected);
|
|
if (ready) {
|
|
Plugin.logger.LogDebug($"Opening cause {time.hours}:{time.minutes} > {hourSelected}:{mintuesSelected}");
|
|
return ready;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected override void LockTreasureDoor(List<Doorway> doorways) {
|
|
base.LockTreasureDoor(doorways);
|
|
|
|
hourSelected = systemRandom.Next(hourRange.x, hourRange.y);
|
|
mintuesSelected = systemRandom.Next(0, 3) * 15;
|
|
Plugin.logger.LogDebug($"Opening at {hourSelected}:{mintuesSelected:D2}");
|
|
|
|
timeClockSpawnTransformIndex = systemRandom.Next(timeClockSpawnTransforms.Length);
|
|
var parent = timeClockSpawnTransforms[timeClockSpawnTransformIndex];
|
|
var copy = Instantiate(timeClockPrefab, parent);
|
|
|
|
var textMesh = copy.GetComponentInChildren<TextMeshPro>();
|
|
textMesh.text = $"{hourSelected}:{mintuesSelected:D2}";
|
|
RandomizeCharacters(textMesh);
|
|
}
|
|
|
|
private void RandomizeCharacters(TextMeshPro textMesh){
|
|
textMesh.renderMode = TextRenderFlags.DontRender;
|
|
textMesh.ForceMeshUpdate();
|
|
|
|
var textInfo = textMesh.textInfo;
|
|
var vertices = textInfo.meshInfo[0].vertices;
|
|
var characterCount = textInfo.characterCount;
|
|
|
|
for(var i = 0; i < characterCount; i++){
|
|
var charInfo = textMesh.textInfo.characterInfo[i];
|
|
if (!charInfo.isVisible) continue;
|
|
|
|
var vertexIndex = charInfo.vertexIndex;
|
|
var charMidPoint = (vertices[vertexIndex + 0] + vertices[vertexIndex + 2]) * 0.5f;
|
|
|
|
// offset to mid point just in case
|
|
var offset = charMidPoint;
|
|
vertices[vertexIndex + 0] += -offset;
|
|
vertices[vertexIndex + 1] += -offset;
|
|
vertices[vertexIndex + 2] += -offset;
|
|
vertices[vertexIndex + 3] += -offset;
|
|
|
|
// get offset values and setup matrix
|
|
var angle = UnityEngine.Random.Range(-5f, 5f);
|
|
var position = new Vector3(UnityEngine.Random.Range(-0.1f, 0.1f), UnityEngine.Random.Range(-0.1f, 0.1f), 0f);
|
|
var scale = Vector3.one * UnityEngine.Random.Range(0.95f, 1.05f);
|
|
var matrix = Matrix4x4.TRS(position, Quaternion.Euler(0f, 0f, angle), scale);
|
|
|
|
// move
|
|
vertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]);
|
|
vertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
|
|
vertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
|
|
vertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);
|
|
|
|
// fix offset
|
|
vertices[vertexIndex + 0] += offset;
|
|
vertices[vertexIndex + 1] += offset;
|
|
vertices[vertexIndex + 2] += offset;
|
|
vertices[vertexIndex + 3] += offset;
|
|
|
|
}
|
|
|
|
textMesh.mesh.vertices = vertices;
|
|
textMesh.mesh.uv = textMesh.textInfo.meshInfo[0].uvs0;
|
|
textMesh.mesh.uv2= textMesh.textInfo.meshInfo[0].uvs2;
|
|
textMesh.mesh.colors32 = textMesh.textInfo.meshInfo[0].colors32;
|
|
textMesh.mesh.RecalculateBounds();
|
|
}
|
|
|
|
|
|
}
|
|
}
|