This commit is contained in:
Nim-XD
2025-03-15 13:34:03 +05:30
parent e2a6825288
commit 83bbcc5c37
1719 changed files with 427240 additions and 229321 deletions

Binary file not shown.

View File

@@ -5,54 +5,66 @@ using UnityEngine;
public class FarmItem : NetworkBehaviour
{
public string lootDrop;
public float farmingTime = 30f;
[SyncVar]
public bool isAvailable = true;
private void OnTriggerStay2D(Collider2D other) {
if(other.tag == "Player"){
public string lootDrop;
public float farmingTime = 30f;
[SyncVar]
public bool isAvailable = true;
private void OnTriggerStay2D(Collider2D other)
{
if (other.tag == "Player")
{
//ui
other.GetComponent<FarmManager>().ShowPopUp(this);
}
}
}
private void OnTriggerExit2D(Collider2D other) {
if(other.tag == "Player"){
private void OnTriggerExit2D(Collider2D other)
{
if (other.tag == "Player")
{
//
Debug.Log("GameObject : " + gameObject);
if(other.GetComponent<FarmManager>()==null){return;}
if (other.GetComponent<FarmManager>() == null) { return; }
Debug.Log("active item : "+ other.GetComponent<FarmManager>().activeItem);
if(other.GetComponent<FarmManager>().activeItem.gameObject == gameObject){
Debug.Log("active item : " + other.GetComponent<FarmManager>().activeItem);
if (other.GetComponent<FarmManager>().activeItem.gameObject == gameObject)
{
other.GetComponent<FarmManager>().HidePopUp();
Debug.Log("**** player exit from farm item ! ****");
}
}
}
}
public void Farm()
{
public void Farm(){
CmdSetAvailability(false);
}
}
[Command]
void CmdSetAvailability(bool val){
Debug.Log("This farming item is being used", gameObject);
void CmdSetAvailability(bool val)
{
Debug.Log("This farming item is being used", gameObject);
isAvailable = val;
}
isAvailable = val;
}
public void DestroySelf(){
if(isServer){
public void DestroySelf()
{
if (isServer)
{
NetworkServer.Destroy(gameObject);
}else{
}
else
{
CmdDestroySelf();
}
}
[Command]
void CmdDestroySelf(){
void CmdDestroySelf()
{
NetworkServer.Destroy(gameObject);
}
}

View File

@@ -9,82 +9,97 @@ using UnityEngine.UI;
public class FarmManager : NetworkBehaviour
{
public InventoryManager inventory;
public RectTransform uiPopUp;
public RectTransform uiPopUp;
public Image fillupImage;
public FarmItem activeItem;
public FarmItem farmingItem;
public Image fillupImage;
public FarmItem activeItem;
public FarmItem farmingItem;
private void Awake() {
HidePopUp();
private void Awake()
{
HidePopUp();
uiPopUp.GetComponentInChildren<Button>().onClick.AddListener(Interact);
}
uiPopUp.GetComponentInChildren<Button>().onClick.AddListener(Interact);
}
public void ShowPopUp(FarmItem item){
if(farmingItem != null && farmingItem != item){return;}
if(!item.isAvailable && farmingItem != item){return;}
activeItem = item;
uiPopUp.gameObject.SetActive(true);
Vector3 offsetUiPopUp = new Vector3(100, 50, 50);
uiPopUp.position = Camera.main.WorldToScreenPoint(item.transform.position) + offsetUiPopUp;
public void ShowPopUp(FarmItem item)
{
if (farmingItem != null && farmingItem != item) { return; }
if (!item.isAvailable && farmingItem != item) { return; }
activeItem = item;
uiPopUp.gameObject.SetActive(true);
Vector3 offsetUiPopUp = new Vector3(100, 50, 50);
uiPopUp.position = Camera.main.WorldToScreenPoint(item.transform.position) + offsetUiPopUp;
}
}
public void HidePopUp(){
uiPopUp.gameObject.SetActive(false);
fillupImage.fillAmount= 0f;
}
public void HidePopUp()
{
uiPopUp.gameObject.SetActive(false);
fillupImage.fillAmount = 0f;
}
void Interact(){
if(activeItem ==null){Debug.LogError("Cant farm an item without having one"); return;}
if(!activeItem.isAvailable){Debug.Log("This item is already being farmed",gameObject); return;}
if(isServer){
activeItem.isAvailable=false;
}else{
void Interact()
{
if (activeItem == null) { Debug.LogError("Cant farm an item without having one"); return; }
if (!activeItem.isAvailable) { Debug.Log("This item is already being farmed", gameObject); return; }
if (isServer)
{
activeItem.isAvailable = false;
}
else
{
CmdDeactivateItem(activeItem.gameObject);
}
farmingItem= activeItem;
StartCoroutine(CoroutineFarm());
}
[Command]
void CmdDeactivateItem(GameObject item){
item.GetComponent<FarmItem>().isAvailable = false;
}
IEnumerator CoroutineFarm(){
float timer =0f;
uiPopUp.GetComponentInChildren<TMP_Text>().text = "Farming";
fillupImage.gameObject.SetActive(true);
while(timer < activeItem.farmingTime){
timer +=Time.deltaTime;
fillupImage.fillAmount = timer / activeItem.farmingTime;
uiPopUp.position = Camera.main.WorldToScreenPoint(activeItem.transform.position);
uiPopUp.gameObject.SetActive(true);
yield return null;
}
HidePopUp();
// FarmingManager.instance.DestroyItem(activeItem.gameObject);
DestroyItem(farmingItem.GetComponent<NetworkIdentity>().netId);
Debug.Log("Requesting to delete this item ", farmingItem);
farmingItem=null;
uiPopUp.GetComponentInChildren<TMP_Text>().text = "Farm";
inventory.AddInvItem(activeItem.lootDrop);
}
void DestroyItem(uint itemNetId){
if(isServer){
FarmingManager.instance.DestroyItemByID(itemNetId);
}else{
CmdDestroyItem(itemNetId);
farmingItem = activeItem;
StartCoroutine(CoroutineFarm());
}
}
[Command]
void CmdDestroyItem(uint itemNetId){
FarmingManager.instance.DestroyItemByID(itemNetId);
}
[Command]
void CmdDeactivateItem(GameObject item)
{
item.GetComponent<FarmItem>().isAvailable = false;
}
IEnumerator CoroutineFarm()
{
float timer = 0f;
uiPopUp.GetComponentInChildren<TMP_Text>().text = "Farming";
fillupImage.gameObject.SetActive(true);
while (timer < activeItem.farmingTime)
{
timer += Time.deltaTime;
fillupImage.fillAmount = timer / activeItem.farmingTime;
uiPopUp.position = Camera.main.WorldToScreenPoint(activeItem.transform.position);
uiPopUp.gameObject.SetActive(true);
yield return null;
}
HidePopUp();
// FarmingManager.instance.DestroyItem(activeItem.gameObject);
DestroyItem(farmingItem.GetComponent<NetworkIdentity>().netId);
Debug.Log("Requesting to delete this item ", farmingItem);
farmingItem = null;
uiPopUp.GetComponentInChildren<TMP_Text>().text = "Farm";
inventory.AddInvItem(activeItem.lootDrop);
}
void DestroyItem(uint itemNetId)
{
if (isServer)
{
FarmingManager.instance.DestroyItemByID(itemNetId);
}
else
{
CmdDestroyItem(itemNetId);
}
}
[Command]
void CmdDestroyItem(uint itemNetId)
{
FarmingManager.instance.DestroyItemByID(itemNetId);
}
}

View File

@@ -8,12 +8,14 @@ using UnityEngine.UI;
public class Inventory : MonoBehaviour
{
public Transform inventorySlotsParent;
public CraftManager craftManager;
public InventoryItemsCollection lootData;
public InventoryManager inventoryManager;
playerNetwork playerNet;
void Awake(){
playerNet = GetComponent<playerNetwork>();
CraftManager.instance = craftManager;
}

View File

@@ -113,6 +113,22 @@ public class InventoryManager : MonoBehaviour
public bool UseItem(item i)
{
if(i.bowId != -1){
pnet.characterMan.EquipBow(i.bowId);return false;
}
if(i.armorId != -1){
pnet.characterMan.EquipArmor(i.armorId);return false;
}
if(i.helmetId != -1){
pnet.characterMan.EquipHelmet(i.helmetId);return false;
}
if(i.swordId != -1){
pnet.characterMan.EquipSword(i.swordId);return false;
}
if(i.wandId != -1){
pnet.characterMan.EquipWand(i.wandId);return false;
}
if (pnet.health >= 100)
{
return false;
@@ -121,6 +137,8 @@ public class InventoryManager : MonoBehaviour
pnet.SetHealth(pnet.health + i.healthIncrease);
pnet.SavePlayerData();
return true;
}

View File

@@ -10,23 +10,30 @@ public class item : ScriptableObject
public string type;
public bool isUsable;
public Sprite image;
public GameObject prefab;
public int count;
public int spawnProbability = 50;
public GameObject prefab;
public int count;
public int spawnProbability = 50;
public int healthIncrease = 10;
public int bowId = -1;
public int wandId = -1;
public int swordId = -1;
public int armorId = -1;
public int helmetId = -1;
// public InventoryItemType type;
// public InventoryItemAction action;
// public enum InventoryItemType{
// }
// public InventoryItemType type;
// public InventoryItemAction action;
// public enum InventoryItemAction{
// public enum InventoryItemType{
// }
// }
// public enum InventoryItemAction{
// }
}

View File

@@ -1,10 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Assets.HeroEditor4D.Common.Scripts.CharacterScripts;
using Assets.HeroEditor4D.Common.Scripts.Common;
using Assets.HeroEditor4D.Common.Scripts.Data;
using Assets.HeroEditor4D.Common.Scripts.Enums;
using Assets.HeroEditor4D.InventorySystem.Scripts.Elements;
using Unity.VisualScripting;
using UnityEngine;
public class characterManager : MonoBehaviour
@@ -20,6 +22,10 @@ public class characterManager : MonoBehaviour
// GetComponent<Character4D>().FromJson(CharacterCusomizationBridge.characterJson, false);
// }
}
public int armorId = 0;
public int helmetId = 0;
public int wandId = 0;
public int swordId = 0;
void Update(){
@@ -27,9 +33,24 @@ public class characterManager : MonoBehaviour
// ChangeWeapon();
EquipBow();
}
if(Input.GetKeyDown(KeyCode.N)){
EquipArmor(armorId);
}
if(Input.GetKeyDown(KeyCode.B)){
EquipHelmet(helmetId);
}
if(Input.GetKeyDown(KeyCode.V)){
EquipSword(swordId);
}
if(Input.GetKeyDown(KeyCode.C)){
EquipWand(wandId);
}
}
int weaponIndex = 52;
public int bowIndex =0;
public void EquipBow(){
// bowIndex++;
// if(bowIndex >= character.SpriteCollection.Bow.Count){
@@ -37,12 +58,42 @@ public class characterManager : MonoBehaviour
// }
// Debug.Log("Equipping bow index " + bowIndex + " out of " + character.SpriteCollection.Bow.Count);
var item = character.SpriteCollection.Bow[16];
var item = character.SpriteCollection.Bow[bowIndex];
EquipForAll(item, EquipmentPart.Bow);
}
public void EquipBow(int weaponId ){
var item = character.SpriteCollection.Bow[weaponId];
EquipForAll(item, EquipmentPart.Bow);
}
public void EquipArmor(int weaponId ){
var item = character.SpriteCollection.Armor[weaponId];
EquipForAll(item, EquipmentPart.Armor);
}
public void EquipHelmet(int weaponId){
var item = character.SpriteCollection.Armor[weaponId];
EquipForAll(item, EquipmentPart.Helmet);
}
public void EquipSword(int weaponId){
var item = character.SpriteCollection.MeleeWeapon1H[weaponId];
EquipForAll(item, EquipmentPart.MeleeWeapon1H);
}
public void EquipWand(int weaponId){
var item = character.SpriteCollection.MeleeWeapon1H[weaponId];
EquipForAll(item, EquipmentPart.MeleeWeapon1H);
}
void ChangeWeapon(){
// if(weaponIndex < character.SpriteCollection.MeleeWeapon1H.Count){

View File

@@ -616,7 +616,7 @@ public class playerNetwork : NetworkBehaviour
if(attackTimer > 0){
return;
}
characterMan.SetActiveWeapon(78);
//characterMan.SetActiveWeapon(78);
attackTimer = ATTACK_COOLDOWN;
if(isLocalPlayer){
@@ -704,7 +704,8 @@ public class playerNetwork : NetworkBehaviour
}
attackTimer = ATTACK_COOLDOWN;
// characterMan.SetActiveWeapon(MagicAttackWeaponIndex);
//characterMan.SetActiveWeapon(MagicAttackWeaponIndex);
if(isLocalPlayer){
PlayAttackAnim();
//?

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "Recipe", menuName = "ScriptableObjects/Recipe", order = 1)]
public class resipies_so : ScriptableObject
{
public string name;
public string description;
public item output;
public List<RecipeIngredientEntry> ingredients;
}
[Serializable]
public class RecipeIngredientEntry{
public item item;
public int count = 1;
}

View File

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