230 lines
6.0 KiB
C#
230 lines
6.0 KiB
C#
using System;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class Feeder : MonoBehaviour
|
|
{
|
|
public enum FeederType
|
|
{
|
|
METHOD = 0,
|
|
CAGE = 1,
|
|
SPRING = 2,
|
|
WEIGHT = 3
|
|
}
|
|
|
|
public FeederType feederType;
|
|
|
|
public MeshRenderer baitRenderer;
|
|
|
|
public Vector3 idleRotation = Vector3.zero;
|
|
|
|
public Vector3 onLineRotation = Vector3.zero;
|
|
|
|
public ParticleSystem baitParticles;
|
|
|
|
public float duration = 5f;
|
|
|
|
public float multiplier = 1f;
|
|
|
|
public float timer = 1f;
|
|
|
|
[HideInInspector]
|
|
public FishingPlayer fishingPlayer;
|
|
|
|
[HideInInspector]
|
|
public FishingHands fishingHands;
|
|
|
|
[HideInInspector]
|
|
public Vector3 startBaitScale = Vector3.one;
|
|
|
|
[HideInInspector]
|
|
public Boilie boilie;
|
|
|
|
[HideInInspector]
|
|
public EquipmentObject feederBaitEquipmentObject;
|
|
|
|
[ReadOnly]
|
|
public Boilie feederBait;
|
|
|
|
[ReadOnly]
|
|
public Vector3 startScale = Vector3.one;
|
|
|
|
public void Initialize()
|
|
{
|
|
fishingPlayer = GameController.Instance.fishingPlayer;
|
|
if (feederType != FeederType.WEIGHT)
|
|
{
|
|
boilie = GetComponent<Boilie>();
|
|
startBaitScale = baitRenderer.transform.localScale;
|
|
if (feederBaitEquipmentObject != null && (bool)feederBaitEquipmentObject.prefab)
|
|
{
|
|
feederBait = feederBaitEquipmentObject.prefab.GetComponent<Boilie>();
|
|
}
|
|
if ((bool)feederBait)
|
|
{
|
|
baitRenderer.material = feederBait.ballModel.GetComponent<MeshRenderer>().sharedMaterial;
|
|
boilie.fishLikesParams.fishInterests.Clear();
|
|
boilie.fishLikesParams.fishInterests.AddRange(feederBait.fishLikesParams.fishInterests);
|
|
}
|
|
else
|
|
{
|
|
baitRenderer.enabled = false;
|
|
}
|
|
baitParticles.startColor = baitRenderer.material.color;
|
|
baitParticles.Stop(true);
|
|
}
|
|
startScale = base.transform.localScale;
|
|
timer = duration;
|
|
Utilities.SetLayerRecursively(base.gameObject, "Weapon");
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (feederType == FeederType.WEIGHT || feederBait == null)
|
|
{
|
|
return;
|
|
}
|
|
if (!fishingPlayer || !fishingHands || !fishingHands.bait.isOnWater)
|
|
{
|
|
boilie.attractCollider.gameObject.SetActive(false);
|
|
baitParticles.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
if (Time.timeScale == 0f || timer <= 0f)
|
|
{
|
|
return;
|
|
}
|
|
baitParticles.gameObject.SetActive(fishingPlayer.underwaterCamera.isTurnedOn);
|
|
if (boilie.attractCollider.gameObject.activeSelf)
|
|
{
|
|
timer -= Time.deltaTime * (1f + 0.2f * (float)boilie.fishCounter);
|
|
}
|
|
if ((bool)fishingPlayer.fish && fishingPlayer.fish.isJerked)
|
|
{
|
|
timer -= Time.deltaTime * 50f;
|
|
}
|
|
if (timer <= 0f)
|
|
{
|
|
timer = 0f;
|
|
TurnOn(false);
|
|
if (!fishingPlayer.fish)
|
|
{
|
|
HUDManager.Instance.ShowMessage(Utilities.GetTranslation("HUD_MESSAGE/FEEDER_EMPTY"));
|
|
}
|
|
}
|
|
baitRenderer.transform.localScale = startBaitScale * (timer / duration);
|
|
}
|
|
}
|
|
|
|
public void UpdateFeederPosition(bool underwater)
|
|
{
|
|
if (fishingHands == null)
|
|
{
|
|
return;
|
|
}
|
|
base.transform.localScale = startScale;
|
|
if (underwater)
|
|
{
|
|
base.transform.parent = fishingPlayer.underwaterCamera.lineUnderwater.transform.parent;
|
|
base.transform.localPosition = new Vector3(0f, 0f, 0.2f);
|
|
base.transform.localEulerAngles = onLineRotation;
|
|
if (feederType == FeederType.CAGE)
|
|
{
|
|
base.transform.localEulerAngles += new Vector3(0f, UnityEngine.Random.Range(20f, 70f) * ((!(UnityEngine.Random.Range(0f, 1f) > 0.5f)) ? (-1f) : 1f), 0f);
|
|
}
|
|
}
|
|
else if (fishingHands.baitWasThrown)
|
|
{
|
|
if (base.transform.parent != GameController.Instance.transform)
|
|
{
|
|
base.transform.parent = GameController.Instance.transform;
|
|
}
|
|
base.transform.position = fishingHands.bait.transform.position + (fishingHands.fishingRod.rodEndPosition.position - fishingHands.bait.transform.position).normalized * 0.2f;
|
|
base.transform.rotation = fishingHands.bait.transform.rotation;
|
|
}
|
|
else
|
|
{
|
|
if (base.transform.parent != fishingHands.fakeStraightLine.transform.parent)
|
|
{
|
|
base.transform.parent = fishingHands.fakeStraightLine.transform.parent;
|
|
}
|
|
base.transform.localPosition = Vector3.forward * (Vector3.Distance(fishingHands.fishingRod.rodEndPosition.position, fishingHands.bait.transform.position) - 0.2f);
|
|
base.transform.localEulerAngles = idleRotation;
|
|
base.transform.eulerAngles = new Vector3(base.transform.eulerAngles.x, base.transform.eulerAngles.y, 0f);
|
|
}
|
|
}
|
|
|
|
public void TurnOn(bool turnOn)
|
|
{
|
|
if (feederType != FeederType.WEIGHT && !(feederBait == null))
|
|
{
|
|
if (base.transform.parent == null)
|
|
{
|
|
base.gameObject.SetActive(false);
|
|
}
|
|
if (turnOn && !baitParticles.isPlaying)
|
|
{
|
|
baitParticles.Play(true);
|
|
}
|
|
if (!turnOn && (bool)baitParticles && baitParticles.isPlaying)
|
|
{
|
|
baitParticles.Stop(true);
|
|
}
|
|
if ((bool)boilie)
|
|
{
|
|
boilie.attractCollider.gameObject.SetActive(turnOn);
|
|
}
|
|
Utilities.SetLayerRecursively(boilie.attractCollider.gameObject, LayerMask.NameToLayer("Boilie"));
|
|
}
|
|
}
|
|
|
|
public void ResetFeederBait(bool useUp)
|
|
{
|
|
if (useUp)
|
|
{
|
|
timer = 0f;
|
|
baitRenderer.transform.localScale = Vector3.zero;
|
|
}
|
|
else
|
|
{
|
|
timer = duration;
|
|
baitRenderer.transform.localScale = startBaitScale;
|
|
}
|
|
}
|
|
|
|
public void PulledFromWater()
|
|
{
|
|
if (feederBaitEquipmentObject == null || !(timer / duration < 0.8f))
|
|
{
|
|
return;
|
|
}
|
|
if (feederBaitEquipmentObject.amount <= 0)
|
|
{
|
|
feederBaitEquipmentObject.amount = 0;
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
GlobalSettings.Instance.equipmentManager.UnequipObject(EquipmentObject.EquipmentType.FEEDER_BAIT);
|
|
}
|
|
LeanTween.delayedCall((!HUDManager.Instance.fishingMessageText.gameObject.activeInHierarchy) ? 0.1f : 5f, (Action)delegate
|
|
{
|
|
HUDManager.Instance.ShowMessage(Utilities.GetTranslation("HUD_MESSAGE/FEEDER_EMPTY"));
|
|
});
|
|
ResetFeederBait(true);
|
|
}
|
|
else
|
|
{
|
|
feederBaitEquipmentObject.amount--;
|
|
LeanTween.delayedCall((!HUDManager.Instance.fishingMessageText.gameObject.activeInHierarchy) ? 0.1f : 5f, (Action)delegate
|
|
{
|
|
HUDManager.Instance.ShowMessage(Utilities.GetTranslation("HUD_MESSAGE/FEEDER_REFILL"));
|
|
});
|
|
ResetFeederBait(false);
|
|
}
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
GlobalSettings.Instance.equipmentManager.Save();
|
|
}
|
|
}
|
|
}
|