2020-07-19 21:36:57 -04:00
|
|
|
|
using System;
|
2020-08-29 02:15:38 -04:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class InteractionController : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private PlayerController playerController;
|
2020-08-29 02:15:38 -04:00
|
|
|
|
private BlockDictionary blockDictionary;
|
|
|
|
|
private MachineInteraction machineInteraction;
|
|
|
|
|
private StorageInteraction storageInteraction;
|
|
|
|
|
private BlockInteraction blockInteraction;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
|
2020-09-03 03:09:26 -04:00
|
|
|
|
// Called by unity engine on start up to initialize variables
|
|
|
|
|
public void Start()
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
|
|
|
|
playerController = GetComponent<PlayerController>();
|
2020-08-29 02:15:38 -04:00
|
|
|
|
blockDictionary = GetComponent<BlockDictionary>();
|
|
|
|
|
machineInteraction = gameObject.AddComponent<MachineInteraction>();
|
|
|
|
|
storageInteraction = gameObject.AddComponent<StorageInteraction>();
|
2020-08-29 22:49:12 -04:00
|
|
|
|
blockInteraction = gameObject.AddComponent<BlockInteraction>();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 03:09:26 -04:00
|
|
|
|
// Called once per frame by unity engine
|
|
|
|
|
public void Update()
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
|
|
|
|
//RAYCAST AND ASSOCIATED DATA FOR INTERACTING WITH MACHINES AND OTHER OBJECTS
|
2020-08-29 02:15:38 -04:00
|
|
|
|
if (Physics.Raycast(Camera.main.gameObject.transform.position, Camera.main.gameObject.transform.forward, out playerController.playerLookHit, 40))
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
if (playerController.inventoryOpen == false && playerController.escapeMenuOpen == false && playerController.tabletOpen == false)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
playerController.objectInSight = playerController.playerLookHit.collider.gameObject;
|
|
|
|
|
if (!IsResource(playerController.objectInSight))
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
if (IsStorageContainer(playerController.objectInSight))
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
storageInteraction.InteractWithStorageContainer();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<StorageComputer>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
storageInteraction.InteractWithStorageComputer();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<PowerSource>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithPowerSource();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<NuclearReactor>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithNuclearReactor();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<PowerConduit>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithPowerConduit();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<Turret>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithTurret();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<UniversalExtractor>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithUniversalExtractor();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<Auger>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithAuger();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<DarkMatterCollector>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithDarkMatterCollector();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<UniversalConduit>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithUniversalConduit();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<DarkMatterConduit>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithDarkMatterConduit();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<Smelter>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithSmelter();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<AlloySmelter>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithAlloySmelter();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<Extruder>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithExtruder();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<RailCartHub>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithRailCartHub();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<Retriever>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithRetriever();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<AutoCrafter>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithAutoCrafter();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<HeatExchanger>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithHeatExchanger();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<GearCutter>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithGearCutter();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<Press>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithPress();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<ElectricLight>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithElectricLight();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<AirLock>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
machineInteraction.InteractWithAirLock();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<IronBlock>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
blockInteraction.InteractWithIronBlock();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<Steel>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
blockInteraction.InteractWithSteelBlock();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<Glass>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
blockInteraction.InteractWithGlass();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.GetComponent<Brick>() != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
blockInteraction.InteractWithBricks();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else if (playerController.objectInSight.tag.Equals("CombinedMesh"))
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
blockInteraction.InteractWithCombinedMesh();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
EndInteraction();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EndInteraction();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-19 21:36:57 -04:00
|
|
|
|
|
2020-09-03 03:09:26 -04:00
|
|
|
|
// Returns true if the object in question is a resource node
|
2020-08-29 02:15:38 -04:00
|
|
|
|
private Boolean IsResource(GameObject obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj.GetComponent<DarkMatter>() != null || obj.GetComponent<UniversalResource>() != null)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-07-19 21:36:57 -04:00
|
|
|
|
|
2020-09-03 03:09:26 -04:00
|
|
|
|
// Returns true if the object in question is a storage container
|
2020-08-29 02:15:38 -04:00
|
|
|
|
private Boolean IsStorageContainer(GameObject obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj.GetComponent<InventoryManager>() != null && obj.GetComponent<Retriever>() == null && obj.GetComponent<AutoCrafter>() == null)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-07-19 21:36:57 -04:00
|
|
|
|
|
2020-09-03 03:09:26 -04:00
|
|
|
|
// Destroys an object in the world and adds it's associated inventory item to the player's inventory
|
2020-08-29 02:15:38 -04:00
|
|
|
|
public void CollectObject(string type)
|
|
|
|
|
{
|
|
|
|
|
bool spaceAvailable = false;
|
|
|
|
|
foreach (InventorySlot slot in playerController.playerInventory.inventory)
|
|
|
|
|
{
|
|
|
|
|
if (slot.typeInSlot.Equals("nothing") || slot.typeInSlot.Equals(type) && slot.amountInSlot < 1000)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
spaceAvailable = true;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
}
|
|
|
|
|
if (spaceAvailable == true)
|
|
|
|
|
{
|
|
|
|
|
playerController.playerInventory.AddItem(type, 1);
|
|
|
|
|
Destroy(playerController.objectInSight);
|
2020-09-03 18:26:56 -04:00
|
|
|
|
playerController.PlayCraftingSound();
|
2020-08-29 02:15:38 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
playerController.cannotCollect = true;
|
2020-09-03 18:26:56 -04:00
|
|
|
|
playerController.PlayMissingItemsSound();
|
2020-08-29 02:15:38 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 03:09:26 -04:00
|
|
|
|
// Opens the machine GUI
|
2020-08-29 02:15:38 -04:00
|
|
|
|
public void OpenMachineGUI()
|
|
|
|
|
{
|
|
|
|
|
if (playerController.machineGUIopen == false)
|
|
|
|
|
{
|
|
|
|
|
if (playerController.building == true)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
if (GameObject.Find("GameManager").GetComponent<GameManager>().working == false)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
playerController.stoppingBuildCoRoutine = true;
|
|
|
|
|
GameObject.Find("GameManager").GetComponent<GameManager>().CombineBlocks();
|
|
|
|
|
playerController.separatedBlocks = false;
|
|
|
|
|
playerController.destroyTimer = 0;
|
|
|
|
|
playerController.buildTimer = 0;
|
|
|
|
|
playerController.building = false;
|
|
|
|
|
playerController.destroying = false;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
else
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
playerController.requestedBuildingStop = true;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
Cursor.visible = true;
|
|
|
|
|
Cursor.lockState = CursorLockMode.None;
|
|
|
|
|
playerController.storageGUIopen = false;
|
|
|
|
|
playerController.craftingGUIopen = false;
|
|
|
|
|
playerController.inventoryOpen = false;
|
|
|
|
|
playerController.machineGUIopen = true;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-29 02:15:38 -04:00
|
|
|
|
Cursor.visible = false;
|
|
|
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
|
|
|
playerController.inventoryOpen = false;
|
|
|
|
|
playerController.craftingGUIopen = false;
|
|
|
|
|
playerController.storageGUIopen = false;
|
|
|
|
|
playerController.machineGUIopen = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 03:09:26 -04:00
|
|
|
|
// Called when the player is no longer looking at any interactive objects
|
2020-08-29 02:15:38 -04:00
|
|
|
|
private void EndInteraction()
|
|
|
|
|
{
|
|
|
|
|
if (playerController.machineGUIopen == true)
|
|
|
|
|
{
|
|
|
|
|
playerController.machineGUIopen = false;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
2020-08-29 02:15:38 -04:00
|
|
|
|
playerController.lookingAtCombinedMesh = false;
|
|
|
|
|
playerController.objectInSight = null;
|
|
|
|
|
playerController.machineInSight = null;
|
|
|
|
|
playerController.machineInputID = "none";
|
|
|
|
|
playerController.machineOutputID = "none";
|
|
|
|
|
playerController.machineType = "none";
|
|
|
|
|
playerController.machineAmount = 0;
|
|
|
|
|
playerController.machineInputAmount = 0;
|
|
|
|
|
playerController.machineOutputAmount = 0;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|