Add Alot of stuff, Computer, repairStation, Whole game, Many things!
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BaseCounter : MonoBehaviour, IObjectParentHolder, IInteractable {
|
||||
|
||||
//This could be private, but since this should be only inherticed I will leave it as protected
|
||||
//This could be private, but since this should be only inherited I will leave it as protected
|
||||
[SerializeField] protected Transform _counterObjectHandle;
|
||||
|
||||
|
||||
protected Object _currentObject;
|
||||
|
||||
public virtual void Interact() {
|
||||
public virtual void Interact(InteractionBehaviour interactionBehaviour) {
|
||||
Debug.LogError("Interact not implemented");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,58 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class ComputerBehaviour : MonoBehaviour, IInteractable {
|
||||
public void Interact() {
|
||||
HUDManager.Instance.ShowComputerHUD();
|
||||
[SerializeField] private List<ObjectSO> _objectsToSell = new List<ObjectSO>();
|
||||
|
||||
[SerializeField] private EmptyCounter _destinationCounter;
|
||||
|
||||
[Range(0, 100)]
|
||||
[SerializeField] private int _brokenChance = 10;
|
||||
|
||||
private ObjectSO _objectToSell;
|
||||
private bool _isBroken = false;
|
||||
|
||||
public event EventHandler OnBuyItem;
|
||||
|
||||
private void Start() {
|
||||
_objectToSell = GetRandomObject();
|
||||
_isBroken = GetRandomBroken();
|
||||
}
|
||||
|
||||
private ObjectSO GetRandomObject() {
|
||||
return _objectsToSell[Random.Range(0, _objectsToSell.Count)];
|
||||
}
|
||||
|
||||
private bool GetRandomBroken() {
|
||||
return Random.Range(0, 100) < _brokenChance;
|
||||
}
|
||||
|
||||
public void Interact(InteractionBehaviour interactionBehaviour) {
|
||||
if (_destinationCounter.HasObject() || HUDManager.Instance.IsUiOpen) {
|
||||
return;
|
||||
}
|
||||
HUDManager.Instance.BuyItem(this, _objectToSell, _isBroken);
|
||||
}
|
||||
|
||||
public void SkipItem() {
|
||||
_objectToSell = GetRandomObject();
|
||||
_isBroken = GetRandomBroken();
|
||||
HUDManager.Instance.UpdateItem(_objectToSell, _isBroken);
|
||||
}
|
||||
public void ConfirmBuy(ObjectSO objectSo, float price, bool isBroken) {
|
||||
_destinationCounter.SetItem(objectSo, price, isBroken);
|
||||
OnBuyItem?.Invoke(this, EventArgs.Empty);
|
||||
GameController.Instance.Money -= price;
|
||||
_objectToSell = GetRandomObject();
|
||||
_isBroken = GetRandomBroken();
|
||||
|
||||
}
|
||||
|
||||
public void SetItem(ObjectSO item, bool isBroken) {
|
||||
_objectToSell = item;
|
||||
_isBroken = isBroken;
|
||||
HUDManager.Instance.UpdateItem(_objectToSell, _isBroken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EmptyCounter : BaseCounter {
|
||||
@@ -8,16 +5,26 @@ public class EmptyCounter : BaseCounter {
|
||||
[SerializeField] private ObjectSO _objectSo;
|
||||
|
||||
[SerializeField] private bool _shouldSpawnOnInteract;
|
||||
|
||||
public void SetItem(ObjectSO objectSo, float price = 0, bool isBroken = false) {
|
||||
//Set the item on the counter
|
||||
if(_currentObject != null) {
|
||||
Destroy(_currentObject.gameObject);
|
||||
}
|
||||
Transform objectTransform = Instantiate(objectSo.prefab, _counterObjectHandle);
|
||||
|
||||
Object obj = objectTransform.GetComponent<Object>();
|
||||
obj.ObjectSo = objectSo;
|
||||
obj.PaidPrice = price;
|
||||
obj.IsBroken = isBroken;
|
||||
obj.setObjectParent(this);
|
||||
}
|
||||
|
||||
public override void Interact() {
|
||||
InteractionBehaviour interactionBehaviour = PlayerController.Instance.InteractionBehaviour;
|
||||
if (_shouldSpawnOnInteract) {
|
||||
public override void Interact(InteractionBehaviour interactionBehaviour) {
|
||||
if (_shouldSpawnOnInteract) { //Debug
|
||||
if (_currentObject == null) {
|
||||
Transform objectTransform = Instantiate(_objectSo.prefab, _counterObjectHandle);
|
||||
objectTransform.GetComponent<Object>().setObjectParent(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!HasObject()) {
|
||||
@@ -44,6 +51,5 @@ public class EmptyCounter : BaseCounter {
|
||||
GetObject().setObjectParent(interactionBehaviour);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,5 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public interface IInteractable {
|
||||
void Interact();
|
||||
void Interact(InteractionBehaviour interactionBehaviour);
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SellCounter : BaseCounter {
|
||||
|
||||
private bool _isSelling = false;
|
||||
|
||||
private Object _currentObject;
|
||||
|
||||
protected void Awake() {
|
||||
private float _sellingPrice;
|
||||
public event EventHandler<OnCounterStartSellingArgs> OnCounterStartSelling; //Event to notify that the counter is selling an item
|
||||
public class OnCounterStartSellingArgs : EventArgs {
|
||||
public SellCounter SellCounter;
|
||||
}
|
||||
|
||||
public override void Interact() {
|
||||
InteractionBehaviour interactionBehaviour = PlayerController.Instance.InteractionBehaviour;
|
||||
public override void Interact(InteractionBehaviour interactionBehaviour) {
|
||||
if (!_isSelling) {
|
||||
//This counter is not selling an item yet
|
||||
if (interactionBehaviour.HasObject()) {
|
||||
@@ -20,6 +19,7 @@ public class SellCounter : BaseCounter {
|
||||
Object obj = interactionBehaviour.GetObject();
|
||||
//Check if the object is sellable
|
||||
if (obj.TryGetComponent(out Object objectComponent)) {
|
||||
Debug.Log("Player has something and it is sellable");
|
||||
HUDManager.Instance.SellItem(this, objectComponent);
|
||||
}
|
||||
else {
|
||||
@@ -27,15 +27,42 @@ public class SellCounter : BaseCounter {
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
//Player wants to pick up the item
|
||||
if (interactionBehaviour.HasObject()) {
|
||||
//Player is holding something, cant pickup
|
||||
return;
|
||||
}
|
||||
else {
|
||||
//Player has nothing
|
||||
//Take the object
|
||||
GetObject().setObjectParent(interactionBehaviour);
|
||||
_isSelling = false;
|
||||
|
||||
CustomerManager.Instance.StoppedSelling(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Gets called if an item is being sold on this counter
|
||||
//This should prevent the counter thinking it's selling something if the user cancels the UI sell
|
||||
public void ConfirmSell(Object obj) {
|
||||
public void ConfirmSell(Object obj, float price) {
|
||||
_isSelling = true;
|
||||
obj.setObjectParent(this);
|
||||
_currentObject = obj;
|
||||
_sellingPrice = price;
|
||||
|
||||
OnCounterStartSelling?.Invoke(this, new OnCounterStartSellingArgs {SellCounter = this});
|
||||
|
||||
}
|
||||
|
||||
public void SellItem(CustomerController customerController) {
|
||||
this.GetObject().setObjectParent(customerController);
|
||||
_isSelling = false;
|
||||
GameController.Instance.Money += _sellingPrice;
|
||||
}
|
||||
|
||||
public float GetSellingPrice() {
|
||||
return _sellingPrice;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user