Skip to content

Commit

Permalink
A few fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nrgill28 committed Nov 26, 2020
1 parent c137e73 commit c19a36d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 60 deletions.
5 changes: 5 additions & 0 deletions WurstMod/MappingComponents/Generic/CustomScene.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using FistVR;
using UnityEngine;
using Valve.VR.InteractionSystem;
using WurstMod.Runtime;
Expand All @@ -20,6 +21,8 @@ public class CustomScene : ComponentProxy
[Header("Scene Settings")]
public float MaxProjectileRange = 500f;

public int PlayerIFF = 0;

public override void OnExport(ExportErrors err)
{
Skybox = RenderSettings.skybox;
Expand Down Expand Up @@ -77,6 +80,8 @@ public override void InitializeComponent()
// Set the max range on the scene settings
// TODO: There are probably a lot of settings we should carry over here.
ObjectReferences.FVRSceneSettings.MaxProjectileRange = MaxProjectileRange;
ObjectReferences.FVRSceneSettings.DefaultPlayerIFF = PlayerIFF;
GM.CurrentPlayerBody.SetPlayerIFF(PlayerIFF);
}

[Serializable]
Expand Down
36 changes: 33 additions & 3 deletions WurstMod/MappingComponents/Generic/SosigSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,30 @@ public class SosigSpawner : ComponentProxy
[Tooltip("Whether or not this spawner is active by default")]
public bool Active = true;

[Tooltip("The options to spawn the Sosig with")]
public SosigSpawnerHelper.SpawnOptions SosigSpawnOptions;
[Header("Spawn Options")]
[Tooltip("Whether to spawn the Sosig activated or not")]
public bool SpawnActivated;

[Tooltip("Sets the Sosig's IFF (Team). Values 5 and above get randomized")]
public int IFF;

[Tooltip("Spawns the Sosig with full ammo")]
public bool SpawnWithFullAmmo;

[Tooltip("Not sure what this does. Recommended to just leave at 0")]
public int EquipmentMode;

[Tooltip("The state to spawn the Sosig in. 0 = Disabled, 1 = Guard, 2 = Wander, 3 = Assault")]
public int SpawnState;

[Tooltip("The position of the Sosig's attack / guard position")]
public Vector3 SosigTargetPosition;

public Vector3 SosigTargetRotation;

[Tooltip("Set this a transform to make the Sosigs spawn with it's position and rotation as it's target.")]
public Transform SosigTransformTarget;

// This needs to be a ScriptableObject because otherwise Unity throws a fit
private ScriptableObject[] _enemyTemplates;
private IEnumerator _coroutine;
Expand Down Expand Up @@ -74,7 +95,16 @@ public void Spawn()
{
// Pick a random template and spawn the Sosig
var template = _enemyTemplates[Random.Range(0, _enemyTemplates.Length)] as SosigEnemyTemplate;
SosigSpawnerHelper.SpawnSosigWithTemplate(template, SosigSpawnOptions, transform.position, transform.forward);
SosigSpawnerHelper.SpawnSosigWithTemplate(template, new SosigSpawnerHelper.SpawnOptions
{
SpawnActivated = SpawnActivated,
IFF = IFF,
SpawnWithFullAmmo = SpawnWithFullAmmo,
EquipmentMode = EquipmentMode,
SpawnState = SpawnState,
SosigTargetPosition = SosigTransformTarget ? SosigTransformTarget.position : SosigTargetPosition,
SosigTargetRotation = SosigTransformTarget ? SosigTransformTarget.rotation.eulerAngles : SosigTargetRotation
}, transform.position, transform.forward);
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion WurstMod/Runtime/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using WurstMod.MappingComponents;
using WurstMod.MappingComponents.Generic;
using WurstMod.Shared;
using Logger = BepInEx.Logging.Logger;
using Object = UnityEngine.Object;

namespace WurstMod.Runtime
Expand Down
14 changes: 11 additions & 3 deletions WurstMod/Runtime/ObjectReferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void FindReferences(Scene scene)
// If the field's value is already set, break.
// NOTE: Objects are "deleted" on scene load, but reflection will not necessarily return null immediately.
// This method is only run on scene load anyway, so the duplicate checking isn't super necessary.
//if (field.GetValue(null) != null) break;
if (field.GetValue(null) as Object) break;

// If the field type is GameObject, just find the GameObject normally
Object found;
Expand All @@ -86,8 +86,16 @@ public static void FindReferences(Scene scene)
field.SetValue(null, found);

if (!reference.DontDestroyOnLoad) continue;
if (found is GameObject go) go.transform.parent = null;
else ((Component) found).transform.parent = null;
if (found is GameObject go)
{
go.transform.parent = null;
go.transform.position = Vector3.down * 1000;
}
else
{
((Component) found).transform.parent = null;
((Component) found).transform.position = Vector3.down * 1000;
}
Object.DontDestroyOnLoad(found);
}
}
Expand Down
3 changes: 0 additions & 3 deletions WurstMod/Runtime/ScenePatchers/TNH_LevelSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public static class TNH_LevelSelector
{
// Settings.
private static readonly string levelDir = "CustomLevels/TakeAndHold";
private static readonly string dataFile = "/leveldata";
private static readonly string imageFile = "/thumb.png";
private static readonly string infoFile = "/info.txt";

// Referenced objects.
public static Canvas levelSelectorCanvas;
Expand Down
80 changes: 30 additions & 50 deletions WurstMod/Runtime/SosigSpawnerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ public static void SpawnSosigWithTemplate(SosigEnemyTemplate template, SpawnOpt
{
var sosigPrefab = template.SosigPrefabs[Random.Range(0, template.SosigPrefabs.Count)];
var configTemplate = template.ConfigTemplates[Random.Range(0, template.ConfigTemplates.Count)];
var w1 = template.OutfitConfig[Random.Range(0, template.OutfitConfig.Count)];
var key = SpawnSosigAndConfigureSosig(sosigPrefab.GetGameObject(), position,
Quaternion.LookRotation(forward, Vector3.up), configTemplate, w1);
key.InitHands();
key.Inventory.Init();
var outfitConfig = template.OutfitConfig[Random.Range(0, template.OutfitConfig.Count)];
var sosig = SpawnSosigAndConfigureSosig(sosigPrefab.GetGameObject(), position,
Quaternion.LookRotation(forward, Vector3.up), configTemplate, outfitConfig);
sosig.InitHands();
sosig.Inventory.Init();
if (template.WeaponOptions.Count > 0)
{
var w2 = SpawnWeapon(template.WeaponOptions);
w2.SetAutoDestroy(true);
key.ForceEquip(w2);
if (w2.Type == SosigWeapon.SosigWeaponType.Gun && spawnOptions.SpawnWithFullAmmo)
key.Inventory.FillAmmoWithType(w2.AmmoType);
var weapon = SpawnWeapon(template.WeaponOptions);
weapon.SetAutoDestroy(true);
sosig.ForceEquip(weapon);
if (weapon.Type == SosigWeapon.SosigWeaponType.Gun && spawnOptions.SpawnWithFullAmmo)
sosig.Inventory.FillAmmoWithType(weapon.AmmoType);
}

var spawnWithSecondaryWeapon = spawnOptions.EquipmentMode == 0 || spawnOptions.EquipmentMode == 2 ||
spawnOptions.EquipmentMode == 3 &&
Random.Range(0.0f, 1f) >= template.SecondaryChance;
if (template.WeaponOptions_Secondary.Count > 0 && spawnWithSecondaryWeapon)
{
var w2 = SpawnWeapon(template.WeaponOptions_Secondary);
w2.SetAutoDestroy(true);
key.ForceEquip(w2);
if (w2.Type == SosigWeapon.SosigWeaponType.Gun && spawnOptions.SpawnWithFullAmmo)
key.Inventory.FillAmmoWithType(w2.AmmoType);
var weapon = SpawnWeapon(template.WeaponOptions_Secondary);
weapon.SetAutoDestroy(true);
sosig.ForceEquip(weapon);
if (weapon.Type == SosigWeapon.SosigWeaponType.Gun && spawnOptions.SpawnWithFullAmmo)
sosig.Inventory.FillAmmoWithType(weapon.AmmoType);
}

var spawnWithTertiaryWeapon = spawnOptions.EquipmentMode == 0 ||
Expand All @@ -47,44 +47,40 @@ public static void SpawnSosigWithTemplate(SosigEnemyTemplate template, SpawnOpt
{
var w2 = SpawnWeapon(template.WeaponOptions_Tertiary);
w2.SetAutoDestroy(true);
key.ForceEquip(w2);
sosig.ForceEquip(w2);
if (w2.Type == SosigWeapon.SosigWeaponType.Gun && spawnOptions.SpawnWithFullAmmo)
key.Inventory.FillAmmoWithType(w2.AmmoType);
sosig.Inventory.FillAmmoWithType(w2.AmmoType);
}

var sosigIFF = spawnOptions.IFF;
if (sosigIFF >= 5)
sosigIFF = Random.Range(6, 10000);
key.E.IFFCode = sosigIFF;
key.CurrentOrder = Sosig.SosigOrder.Disabled;
sosig.E.IFFCode = sosigIFF;
sosig.CurrentOrder = Sosig.SosigOrder.Disabled;
switch (spawnOptions.SpawnState)
{
case 0:
key.FallbackOrder = Sosig.SosigOrder.Disabled;
sosig.FallbackOrder = Sosig.SosigOrder.Disabled;
break;
case 1:
key.FallbackOrder = Sosig.SosigOrder.GuardPoint;
sosig.FallbackOrder = Sosig.SosigOrder.GuardPoint;
break;
case 2:
key.FallbackOrder = Sosig.SosigOrder.Wander;
sosig.FallbackOrder = Sosig.SosigOrder.Wander;
break;
case 3:
key.FallbackOrder = Sosig.SosigOrder.Assault;
sosig.FallbackOrder = Sosig.SosigOrder.Assault;
break;
}

var targetPos = spawnOptions.SosigTransformTarget
? spawnOptions.SosigTransformTarget.position
: spawnOptions.SosigTargetPosition;
var targetRot = spawnOptions.SosigTransformTarget
? spawnOptions.SosigTransformTarget.eulerAngles
: spawnOptions.SosigTargetRotation;
key.UpdateGuardPoint(targetPos);
key.SetDominantGuardDirection(targetRot);
key.UpdateAssaultPoint(targetPos);
var targetPos = spawnOptions.SosigTargetPosition;
var targetRot = spawnOptions.SosigTargetRotation;
sosig.UpdateGuardPoint(targetPos);
sosig.SetDominantGuardDirection(targetRot);
sosig.UpdateAssaultPoint(targetPos);
if (!spawnOptions.SpawnActivated)
return;
key.SetCurrentOrder(key.FallbackOrder);
sosig.SetCurrentOrder(sosig.FallbackOrder);
}

private static SosigWeapon SpawnWeapon(List<FVRObject> o) => Object
Expand Down Expand Up @@ -130,32 +126,16 @@ private static void SpawnAccessoryToLink(List<FVRObject> gs, SosigLink l)
accessory.transform.SetParent(l.transform);
accessory.GetComponent<SosigWearable>().RegisterWearable(l);
}

[Serializable]

public struct SpawnOptions
{
[Tooltip("Whether to spawn the Sosig activated or not")]
public bool SpawnActivated;

[Tooltip("Sets the Sosig's IFF (Team). Values 5 and above get randomized")]
public int IFF;

[Tooltip("Spawns the Sosig with full ammo")]
public bool SpawnWithFullAmmo;

[Tooltip("Not sure what this does. Recommended to just leave at 0")]
public int EquipmentMode;

[Tooltip("The state to spawn the Sosig in. 0 = Disabled, 1 = Guard, 2 = Wander, 3 = Assault")]
public int SpawnState;

[Tooltip("The position of the Sosig's attack / guard position")]
public Vector3 SosigTargetPosition;

public Vector3 SosigTargetRotation;

[Tooltip("Set this a transform to make the Sosigs spawn with it's position and rotation as it's target.")]
public Transform SosigTransformTarget;
}
}
}

0 comments on commit c19a36d

Please sign in to comment.