Critical damage renamed to marked for death and all share the same mechanic now Revelant now slows down to speed over a fixed short amount instead the nonworking jank before Moved item/enemy injection to DunGenPlus
144 lines
3.8 KiB
C#
144 lines
3.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using Unity.Netcode;
|
|
using GameNetcodeStuff;
|
|
using ScarletMansion.GamePatch.Managers;
|
|
|
|
namespace ScarletMansion.GamePatch.Items {
|
|
public class FlandreCrystal : GrabbableObject {
|
|
|
|
public static Color[] colorVariants = new Color[] {
|
|
new Color(0f, 0f, 1f),
|
|
new Color(0f, 1f, 1f),
|
|
new Color(0f, 1f, 0f),
|
|
new Color(1f, 0f, 1f),
|
|
new Color(1f, 0.647f, 0f),
|
|
new Color(0.502f, 0f, 0.502f),
|
|
new Color(1f, 0f, 0f),
|
|
new Color(1f, 1f, 0f)
|
|
};
|
|
|
|
[Header("Target Transformation")]
|
|
public Item targetTransformation;
|
|
|
|
[Header("Colors")]
|
|
public int colorIndex;
|
|
public Light light;
|
|
public bool hasUsedCrystal;
|
|
|
|
private PlayerControllerB previousPlayerHeldBy;
|
|
private Coroutine flashCoroutine;
|
|
private float intensity;
|
|
private float range;
|
|
|
|
public override void Start() {
|
|
base.Start();
|
|
StartCoroutine(WaitForScrapValue());
|
|
intensity = light.intensity;
|
|
range = light.range;
|
|
}
|
|
|
|
public IEnumerator WaitForScrapValue(){
|
|
while (scrapValue == 0) yield return null;
|
|
|
|
colorIndex = scrapValue % colorVariants.Length;
|
|
|
|
var color = colorVariants[colorIndex];
|
|
mainObjectRenderer.material.color = color;
|
|
light.color = color;
|
|
}
|
|
|
|
public override void EquipItem() {
|
|
base.EquipItem();
|
|
previousPlayerHeldBy = playerHeldBy;
|
|
light.enabled = true;
|
|
}
|
|
|
|
public override void ItemActivate(bool used, bool buttonDown = true) {
|
|
base.ItemActivate(used, buttonDown);
|
|
if (playerHeldBy == null) return;
|
|
if (hasUsedCrystal) return;
|
|
|
|
var flashLightResult = FindFlashlightInInventory();
|
|
if (flashLightResult.index != -1) {
|
|
var lastPlayer = playerHeldBy;
|
|
hasUsedCrystal = true;
|
|
lastPlayer.activatingItem = true;
|
|
|
|
// fail safe, but it feels kinda shit
|
|
var result = ScarletNetworkManagerUtility.CreateFlashlight(playerHeldBy, flashLightResult.item, this);
|
|
if (result == false){
|
|
hasUsedCrystal = false;
|
|
lastPlayer.activatingItem = false;
|
|
}
|
|
} else {
|
|
Flash();
|
|
FlashServerRpc();
|
|
}
|
|
}
|
|
|
|
public override void PocketItem() {
|
|
base.PocketItem();
|
|
playerHeldBy.activatingItem = false;
|
|
light.enabled = false;
|
|
}
|
|
|
|
public override void DiscardItem() {
|
|
base.DiscardItem();
|
|
light.enabled = true;
|
|
}
|
|
|
|
private (FlashlightItem item, int index) FindFlashlightInInventory(){
|
|
var items = playerHeldBy.ItemSlots;
|
|
for(var i = 0; i < items.Length; ++i){
|
|
var item = items[i] as FlashlightItem;
|
|
if (item != null && Assets.GetFlashlightCheckConfig(item.itemProperties) != null) {
|
|
Plugin.logger.LogDebug($"Flashlight slot {i}");
|
|
return (item, i);
|
|
}
|
|
}
|
|
return (null, -1);
|
|
}
|
|
|
|
[ServerRpc(RequireOwnership = false)]
|
|
public void FlashServerRpc(){
|
|
FlashClientRpc();
|
|
}
|
|
|
|
[ClientRpc]
|
|
public void FlashClientRpc(){
|
|
if (playerHeldBy && playerHeldBy.IsOwner) return;
|
|
Flash();
|
|
}
|
|
|
|
private void Flash(){
|
|
if (flashCoroutine != null) StopCoroutine(flashCoroutine);
|
|
flashCoroutine = StartCoroutine(FlashEnumerator());
|
|
}
|
|
|
|
public IEnumerator FlashEnumerator(){
|
|
light.intensity = intensity;
|
|
light.range = range;
|
|
|
|
var t = 0f;
|
|
while(t < 0.3f) {
|
|
yield return null;
|
|
t += Time.deltaTime;
|
|
|
|
var factor = t / 0.3f * (float)Math.PI;
|
|
factor = Mathf.Sin(factor) * 1f + 1f;
|
|
light.intensity = intensity * factor;
|
|
light.range = range * factor;
|
|
}
|
|
|
|
light.intensity = intensity;
|
|
light.range = range;
|
|
}
|
|
|
|
}
|
|
}
|