Major Fishing changes

This commit is contained in:
s-prechtl 2022-06-08 22:19:40 +02:00
parent 1a12d986c4
commit 9e91220be4
11 changed files with 173 additions and 49 deletions

View file

@ -0,0 +1,20 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f096d187f76a734fac022700054dfec, type: 3}
m_Name: Fish
m_EditorClassIdentifier:
displayName:
description:
id: 0
selectedSprite: {fileID: 0}
defaultSprite: {fileID: 0}
cost: 0

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7fc4aaa640c1c1e49a0c0a9241fbcf07
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1536,7 +1536,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 2006577138}
m_Direction: 2
m_Value: 1
m_Size: 0.5932421
m_Size: 0.59324205
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
@ -6739,6 +6739,7 @@ GameObject:
- component: {fileID: 1800469989}
- component: {fileID: 1800469991}
- component: {fileID: 1800469992}
- component: {fileID: 1800469993}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
@ -6804,6 +6805,18 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 05183797fdda4aa9ac518eee0d2d85d4, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1800469993
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1800469988}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 00d85fb65e728cd429cb33d865a5d31a, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &1805366398
PrefabInstance:
m_ObjectHideFlags: 0

View file

@ -0,0 +1,82 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using UnityEngine;
using Random = UnityEngine.Random;
public class FishingController : MonoBehaviour {
#region Singleton
public static FishingController instance;
private void Awake() {
if (instance != null) {
Debug.LogWarning("More than one instance of FishingController found");
}
instance = this;
}
#endregion
private double _fishingTime;
private bool _fishing;
private bool _catchable;
private bool _caught;
private double _fishCooldown;
private readonly double _totalFishCooldown = 1.5f;
private readonly double _maxTime = 2f;
private bool _spawnFish;
public bool Fishing => _fishing;
// Start is called before the first frame update
void Start() {
ResetFishing();
}
// Update is called once per frame
void Update() {
if (_fishing) {
if (!_catchable) {
_fishCooldown += Time.deltaTime;
if (_spawnFish && _fishCooldown >= _totalFishCooldown && Random.Range(0, 100) <= 1) {
_spawnFish = false;
//particles for fish -> catchable true
}
} else {
if (!_caught) {
_fishingTime += Time.deltaTime;
}
}
}
}
private void ResetFishing() {
_fishing = false;
_catchable = false;
_fishingTime = 0f;
_fishCooldown = 1.5f;
_spawnFish = true;
}
public void StartFishing() {
_fishing = true;
}
public void TryCatch() {
if (_fishing && _catchable) {
if (_fishingTime <= _maxTime) {
_fishing = false;
_caught = true;
Inventory.instance.AddItem(ItemContainer.Instance.GetItemByName("Fish"), (int)(3/_fishingTime));
} else {
_spawnFish = true;
_catchable = false;
_fishingTime = 0f;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 00d85fb65e728cd429cb33d865a5d31a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -5,18 +5,26 @@ using UnityEngine;
public class Item : ScriptableObject, IComparable<Item> {
public string displayName;
public string description;
public int id; //TODO: create an actual ID System that makes snens
private int _id = -1;
public Sprite selectedSprite;
public Sprite defaultSprite;
public int cost;
public int ID => _id;
public Item(string displayName, string description, int id) {
this.displayName = displayName;
this.description = description;
this.id = id;
this._id = id;
}
public int CompareTo(Item other) {
return this.id - other.id;
return this._id - other._id;
}
public void SetID(int id) {
if (_id != -1) {
_id = id;
}
}
}

View file

@ -26,8 +26,10 @@ public class ItemContainer : MonoBehaviour {
string[] files =
Directory.GetFiles("Assets\\Resources\\Items", "*.asset", SearchOption.AllDirectories);
foreach (string file in files) {
String path = file.Replace("Assets\\Resources\\", "").Replace(".asset", "");
_allItems.Add(Resources.Load<Item>(path));
String path = StripPath(file);
Item currItem = Resources.Load<Item>(path);
currItem.SetID(_allItems.Count);
_allItems.Add(currItem);
}
}
@ -41,7 +43,11 @@ public class ItemContainer : MonoBehaviour {
return null;
}
private String StripPath(String path) {
return path.Replace("Assets\\Resources\\", "").Replace(".asset", "");
}
public int GetItemIdByName(String name) {
return GetItemByName(name).id;
return GetItemByName(name).ID;
}
}

View file

@ -14,16 +14,6 @@ namespace Tiles
this._sprite = GenerateSpriteFromFile(pathToImageFile);
}
protected void Start()
{
}
protected void Update()
{
}
public void DayLightStep()
{

View file

@ -21,18 +21,18 @@ namespace Tiles
ItemContainer ic = ItemContainer.Instance;
if (usable.id == ic.GetItemIdByName("Hoe"))
if (usable.ID == ic.GetItemIdByName("Hoe"))
{
Debug.Log("Farmland hydrated");
//_hydrated = true;
}
if (usable.id == ic.GetItemIdByName("Wheat Seed") && _crop == null)
if (usable.ID == ic.GetItemIdByName("Wheat Seed") && _crop == null)
{
Plant();
}
if (usable.id == ic.GetItemIdByName("Scythe") && _crop != null && _crop.FullyGrown)
if (usable.ID == ic.GetItemIdByName("Scythe") && _crop != null && _crop.FullyGrown)
{
Harvest();
}

View file

@ -20,9 +20,9 @@ namespace Tiles
if (usable != null)
{
base.Clicked(usable);
if (usable.id == ic.GetItemIdByName("Hoe")) {
if (usable.ID == ic.GetItemIdByName("Hoe")) {
rv = new FarmlandTile();
} else if (usable.id == ic.GetItemIdByName("Shovel")) {
} else if (usable.ID == ic.GetItemIdByName("Shovel")) {
rv = new WaterTile();
}
}

View file

@ -1,43 +1,29 @@
using System.Collections;
using UnityEngine;
namespace Tiles
{
namespace Tiles {
public class WaterTile : BaseTile {
private double _fishingTime;
private bool _fishing = false;
private bool _catchable = false;
private int _lastCall = 0;
public WaterTile() : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_023.png") {
}
public override BaseTile Clicked(UsableItem usable) {
base.Clicked(usable);
BaseTile rv = null;
ItemContainer ic = ItemContainer.Instance;
if (usable.id == ic.GetItemIdByName("Fishing Rod")) {
if (!_fishing) {
_fishing = true;
_fishingTime = 0f;
Fish();
} else if (_catchable) {
_fishing = false;
Debug.Log("Fished for" + _fishingTime/1000);
if (usable.ID == ic.GetItemIdByName("Fishing Rod")) {
FishingController fc = FishingController.instance;
if (!fc.Fishing) {
fc.StartFishing();
} else {
fc.TryCatch();
}
}
return null;
}
private void Fish() {
if (_fishing) {
if (_catchable) {
// _fishingTime += _lastCall - System.DateTime.Now; deltaTime between last recursive call
}
//Fish();
} else if (usable.ID == ic.GetItemIdByName("Shovel")) {
rv = new GrassTile();
}
return rv;
}
}
}