Fixed knight ghost to sprint when you ain't looking Fixed Gohei to detect enemies
305 lines
9.7 KiB
C#
305 lines
9.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using System.Reflection;
|
|
using System.IO;
|
|
using DunGen.Graph;
|
|
using LethalLib.Modules;
|
|
using LethalLevelLoader;
|
|
using DunGenPlus;
|
|
using ScarletMansion.ModPatch;
|
|
using ScarletMansion.Configs;
|
|
|
|
namespace ScarletMansion {
|
|
public static class Assets {
|
|
|
|
static BepInEx.Logging.ManualLogSource logger => Plugin.logger;
|
|
|
|
public static ActionList onAssetsLoadEvent = new ActionList("onAssetsLoad");
|
|
public static ActionList<CoronerParameters> onPlayerDeath = new ActionList<CoronerParameters>("onPlayerDeath");
|
|
|
|
const string mainAssetBundleName = "scarletmansion";
|
|
|
|
// main assets
|
|
public static AssetBundle MainAssetBundle = null;
|
|
public static ExtendedMod extendedMod;
|
|
public static NetworkObjectListScriptableObject networkObjectList;
|
|
public static AudioClip entranceAudioClip;
|
|
|
|
// enemy values
|
|
|
|
public class Enemy {
|
|
public GameObject enemy;
|
|
public EnemyType enemyType;
|
|
public Func<int> rarityFunc;
|
|
|
|
public TerminalNode terminalNode;
|
|
public TerminalKeyword terminalKeyword;
|
|
|
|
public Enemy(GameObject enemy, TerminalNode node, TerminalKeyword keyword) {
|
|
this.enemy = enemy;
|
|
this.terminalNode = node;
|
|
this.terminalKeyword = keyword;
|
|
}
|
|
|
|
public SpawnableEnemyWithRarity GetItemEntry(int rarity){
|
|
var entry = new SpawnableEnemyWithRarity();
|
|
entry.enemyType = enemyType;
|
|
entry.rarity = rarity;
|
|
return entry;
|
|
}
|
|
}
|
|
|
|
public static Enemy knight;
|
|
public static Enemy maid;
|
|
|
|
// item values
|
|
public class GlobalItem {
|
|
public Item item;
|
|
private int _itemId;
|
|
|
|
public Func<ConfigItem> configItemEntryFunc;
|
|
|
|
public GlobalItem(Item item, Func<ConfigItem> configItemEntryFunc) {
|
|
this.item = item;
|
|
_itemId = -1;
|
|
this.configItemEntryFunc = configItemEntryFunc;
|
|
}
|
|
|
|
public int itemId {
|
|
get {
|
|
// cache time
|
|
if (_itemId == -1 && StartOfRound.Instance) {
|
|
var itemString = item ? item.itemName : "NULL";
|
|
_itemId = Utility.GetGlobalItemId(item);
|
|
|
|
if (_itemId != -1) {
|
|
Plugin.logger.LogWarning($"Cached {_itemId} itemId for item {itemString}");
|
|
return _itemId;
|
|
}
|
|
Plugin.logger.LogWarning($"Tried to get itemId for item {itemString} but failed");
|
|
}
|
|
|
|
return _itemId;
|
|
} set {
|
|
_itemId = value;
|
|
}
|
|
}
|
|
|
|
public ConfigItem GetConfigItemEntry(){
|
|
return configItemEntryFunc();
|
|
}
|
|
}
|
|
|
|
public class ScrapItem : GlobalItem {
|
|
public bool SpawnsOnMap => configScrapItemEntryFunc != null;
|
|
|
|
public Func<ConfigScrapItem> configScrapItemEntryFunc;
|
|
|
|
public ScrapItem(Item item, Func<ConfigScrapItem> configScrapItemEntryFunc) : base (item, configScrapItemEntryFunc){
|
|
this.configScrapItemEntryFunc = configScrapItemEntryFunc;
|
|
}
|
|
|
|
public void UpdateItemValue(){
|
|
if (SpawnsOnMap) {
|
|
var config = GetConfigScrapItemEntry();
|
|
item.minValue = config.valueRange.min;
|
|
item.maxValue = config.valueRange.max;
|
|
}
|
|
}
|
|
|
|
public SpawnableItemWithRarity GetItemRarity(){
|
|
var configEntry = GetConfigScrapItemEntry();
|
|
var item = new SpawnableItemWithRarity();
|
|
item.spawnableItem = this.item;
|
|
item.rarity = configEntry != null ? configEntry.spawnWeight : 0;
|
|
return item;
|
|
}
|
|
|
|
public ConfigScrapItem GetConfigScrapItemEntry(){
|
|
return configScrapItemEntryFunc();
|
|
}
|
|
|
|
}
|
|
|
|
public class Flashlight : GlobalItem {
|
|
public string assetName;
|
|
public string displayName;
|
|
|
|
public Item lethalVanillaItem;
|
|
public int lethalHelmetIndex = -1;
|
|
public int scarletHelmetIndex = -1;
|
|
|
|
public Flashlight(string baseName, int lethalHelmetIndex, Func<ConfigItem> configEntryFunc) : base(null, configEntryFunc) {
|
|
assetName = $"Scarlet{baseName}";
|
|
displayName = $"D. {baseName}";
|
|
this.lethalHelmetIndex = lethalHelmetIndex;
|
|
}
|
|
|
|
public bool ContainsItemCheckConfig(Item compareItem){
|
|
if (!GetConfigItemEntry().enabled) return false;
|
|
return ContainsItem(compareItem);
|
|
}
|
|
|
|
public bool ContainsItem(Item compareItem) {
|
|
return compareItem == item || compareItem == lethalVanillaItem;
|
|
}
|
|
}
|
|
|
|
public static List<GlobalItem> globalItems;
|
|
public static List<ScrapItem> scrapItems;
|
|
|
|
public static Dictionary<string, Func<ConfigScrapItem>> itemConfigTable = new Dictionary<string, Func<ConfigScrapItem>>(){
|
|
{ "Deco. crystal", () => ConfigMain.Instance.crystalValue },
|
|
{ "Shattered deco. crystal", () => ConfigMain.Instance.crystalBrokenValue },
|
|
{ "Doll Snow Globe", () => ConfigMain.Instance.snowGlobeValue },
|
|
{ "Gohei", () => ConfigMain.Instance.goheiValue }
|
|
};
|
|
|
|
|
|
public static GlobalItem key;
|
|
public static Flashlight flashlight;
|
|
public static Flashlight flashlightBB;
|
|
|
|
public static GlobalItem GetGlobalItem(Item item){
|
|
return globalItems.FirstOrDefault(x => x.item == item);
|
|
}
|
|
|
|
public static Flashlight GetFlashlight(Item item){
|
|
if (flashlight.ContainsItem(item)) return flashlight;
|
|
if (flashlightBB.ContainsItem(item)) return flashlightBB;
|
|
return null;
|
|
}
|
|
|
|
public static Flashlight GetFlashlightCheckConfig(Item item){
|
|
if (flashlight.ContainsItemCheckConfig(item)) return flashlight;
|
|
if (flashlightBB.ContainsItemCheckConfig(item)) return flashlightBB;
|
|
return null;
|
|
}
|
|
|
|
// game references
|
|
|
|
public static ItemGroup genericItemGroup;
|
|
public static ItemGroup tabletopItemGroup;
|
|
public static ItemGroup smallItemGroup;
|
|
|
|
public static bool dungeonMapHazardFound;
|
|
public static GameObject dungeonTurretMapHazard;
|
|
public static GameObject dungeonMinesMapHazard;
|
|
public static GameObject dungeonSpikeTrapMapHazard;
|
|
|
|
public static Sprite hoverIcon;
|
|
|
|
public static void LoadAssetBundle() {
|
|
if (MainAssetBundle == null) {
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
var resourceNames = assembly.GetManifestResourceNames();
|
|
if (resourceNames.Length >= 1) {
|
|
var name = resourceNames[0];
|
|
using (var assetStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name)) {
|
|
Plugin.logger.LogDebug($"Loading resource {name}");
|
|
MainAssetBundle = AssetBundle.LoadFromStream(assetStream);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
Plugin.ConfigFoyer.dungeon = Load<DungeonFlow>("sdmFoyer");
|
|
Plugin.ConfigFoyer.dunGenExtender = Load<DunGenExtender>("foyerExtender");
|
|
|
|
Plugin.ConfigBasement.dungeon = Load<DungeonFlow>("sdmBasement");
|
|
Plugin.ConfigBasement.dunGenExtender = Load<DunGenExtender>("basementExtender");
|
|
|
|
networkObjectList = Load<NetworkObjectListScriptableObject>("SDMList");
|
|
entranceAudioClip = Load<AudioClip>("entrance_ogg");
|
|
|
|
knight = new Enemy(
|
|
Load<GameObject>("NET_KnightEnemy"),
|
|
Load<TerminalNode>("KnightNode"),
|
|
Load<TerminalKeyword>("KnightKeyword")
|
|
);
|
|
|
|
maid = new Enemy(
|
|
Load<GameObject>("NET_MaidEnemy"),
|
|
Load<TerminalNode>("MaidNode"),
|
|
Load<TerminalKeyword>("MaidKeyword")
|
|
);
|
|
|
|
RegisterNetworkPrefab(networkObjectList.networkDungeon);
|
|
RegisterNetworkPrefab(networkObjectList.networkDoors);
|
|
RegisterNetworkPrefab(networkObjectList.networkItems);
|
|
RegisterNetworkPrefab(networkObjectList.networkFrames);
|
|
RegisterNetworkPrefab(networkObjectList.networkOther);
|
|
|
|
globalItems = new List<GlobalItem>();
|
|
scrapItems = new List<ScrapItem>();
|
|
|
|
foreach(var i in networkObjectList.scrapItems) {
|
|
var function = GetItemConfigFunction(i);
|
|
var entry = new ScrapItem(i, function);
|
|
scrapItems.Add(entry);
|
|
globalItems.Add(entry);
|
|
|
|
Items.RegisterScrap(i, 0, Levels.LevelTypes.None);
|
|
NetworkPrefabs.RegisterNetworkPrefab(i.spawnPrefab);
|
|
Plugin.logger.LogDebug($"Scrap Item {i.itemName} registered");
|
|
}
|
|
|
|
key = new GlobalItem(networkObjectList.items[0], () => ConfigMain.Instance.scarletKeyValue);
|
|
globalItems.Add(key);
|
|
Items.RegisterItem(key.item);
|
|
|
|
flashlight = new Flashlight("Pro Flashlight", 0, () => ConfigMain.Instance.decoProFlashlightValue);
|
|
flashlightBB = new Flashlight("Flashlight", 1, () => ConfigMain.Instance.decoFlashlightValue);
|
|
globalItems.Add(flashlight);
|
|
globalItems.Add(flashlightBB);
|
|
|
|
foreach(var e in networkObjectList.enemies) {
|
|
Enemies.RegisterEnemy(e, 0, Levels.LevelTypes.None, null, null);
|
|
NetworkPrefabs.RegisterNetworkPrefab(e.enemyPrefab);
|
|
}
|
|
|
|
onAssetsLoadEvent.Call();
|
|
}
|
|
|
|
public static Func<ConfigScrapItem> GetItemConfigFunction(Item item){
|
|
var name = item.itemName;
|
|
if (itemConfigTable.TryGetValue(name, out var result)){
|
|
return result;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
private static void RegisterNetworkPrefab(List<GameObject> list){
|
|
foreach(var p in list){
|
|
NetworkPrefabs.RegisterNetworkPrefab(p);
|
|
}
|
|
}
|
|
|
|
public static T Load<T>(string name, bool onlyReportErrors = true) where T: UnityEngine.Object {
|
|
if (MainAssetBundle == null){
|
|
logger.LogError($"Trying to load in asset but asset bundle is missing");
|
|
return null;
|
|
}
|
|
|
|
var asset = MainAssetBundle.LoadAsset<T>(name);
|
|
var missingasset = asset == null;
|
|
|
|
if (missingasset || onlyReportErrors == true) {
|
|
logger.LogDebug($"Loading asset {name}");
|
|
}
|
|
|
|
if (missingasset) {
|
|
logger.LogError($"...but it was not found");
|
|
}
|
|
|
|
return asset;
|
|
|
|
}
|
|
}
|
|
}
|