changesparty

This commit is contained in:
Nim-XD
2025-06-07 23:53:54 +05:30
parent 5ade16b0eb
commit d3fd9e9620
24 changed files with 1336 additions and 195 deletions

View File

@@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClickWorldObj : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnMouseDown()
{
CraftManager.instance.ShowCraftUI();
}
}

View File

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

View File

@@ -0,0 +1,82 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CraftManager : MonoBehaviour
{
public InventoryManager inventoryManager;
public RectTransform CraftUI;
public List<CraftingEntry> craftingEntries;
public static CraftManager instance;
public void ShowCraftUI()
{
Debug.Log("Crafting UI is shown");
CraftUI.gameObject.SetActive(true);
}
public void HideCraftUI()
{
Debug.Log("Crafting UI is hidden");
CraftUI.gameObject.SetActive(false);
}
void Awake(){
instance = this;
foreach (var entry in craftingEntries)
{
entry.btn.onClick.AddListener(() => OnClickRecipe(entry.recipe));
}
}
void OnClickRecipe(resipies_so recipe){
foreach(var entry in craftingEntries){
if(entry.recipe == recipe){
entry.panel.SetActive(true);
}else{
entry.panel.SetActive(false);
}
}
}
public void OnCraftButtonClicked(){
foreach(var entry in craftingEntries){
if(entry.panel.activeSelf){
bool canCraft = true;
foreach(var ingredient in entry.recipe.ingredients){
if(inventoryManager.GetStock(ingredient.item.name) < ingredient.count){
canCraft = false;
Debug.Log("Not enough " + ingredient.item.name);
break;
}
// if(ingredient.count <= 0){
// canCraft = false;
// break;
// }
}
if(canCraft){
Debug.Log("Crafting item: " + entry.recipe.output.name);
inventoryManager.AddInvItem(entry.recipe.output);
foreach(RecipeIngredientEntry ingredient in entry.recipe.ingredients){
inventoryManager.RemoveItem(ingredient.item.name, ingredient.count);
}
}else{
Debug.Log("Cannot craft item: " + entry.recipe.output.name);
}
}
}
}
}
[System.Serializable]
public class CraftingEntry{
public resipies_so recipe;
public Button btn;
public GameObject panel;
}

View File

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

View File

@@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CraftStation : MonoBehaviour
{
private void OnTriggerStay2D(Collider2D other)
{
if (other.tag == "Player")
{
//ui enable
// other.GetComponent<CraftManager>().ShowCraftUI(this);
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.tag == "Player")
{
//ui disable
other.GetComponent<CraftManager>().HideCraftUI();
}
}
}

View File

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

View File

@@ -46,6 +46,7 @@ public class FarmingManager : NetworkBehaviour
}
}
public void Spawn(int index){
FarmingPositionEntry item = farmingItems[index];
GameObject spawn = Instantiate(item.prefab , item.spawnLocation.position , Quaternion.identity);
@@ -95,7 +96,6 @@ public class FarmingPositionEntry{
}
[System.Serializable]
public class FarmingSpawnPoints{
public Transform pointsParent;

View File

@@ -0,0 +1,70 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Assets.HeroEditor4D.Common.Scripts.CharacterScripts;
using UnityEngine;
public class InGameCharacterMgr : MonoBehaviour
{
// [SerializeField] private GameObject SwordBtn;
// [SerializeField] private GameObject MageBtn;
// [SerializeField] private GameObject BawBtn;
public GameObject[] attackBtns;
public string selectedCharacter;
public List<CharacterDataSO> characterDataScriptable ;
public Character4D character4D;
float timer= 10;
void Update()
{
if(timer < 5){timer+=Time.deltaTime; return;}
timer=0;
SetAttackBtn();
}
void Start()
{
// SetAttackBtn();
}
public string currentJson;
void SetAttackBtn(){
currentJson = character4D.ToJson();
selectedCharacter = "attack";
foreach(CharacterDataSO character in characterDataScriptable){
if(character.jsonCharData == currentJson){
selectedCharacter = character.charName;
break;
}
}
//
foreach(GameObject button in attackBtns){
button.SetActive(false);
}
//
switch (selectedCharacter){
case "attack":
attackBtns[0].SetActive(true);
break;
case "mage":
attackBtns[1].SetActive(true);
break;
case "range":
attackBtns[2].SetActive(true);
break;
default:
//set sword btn
attackBtns[0].SetActive(true) ;
break;
}
}
}

View File

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

136
Assets/Script/LostNpc.cs Normal file
View File

@@ -0,0 +1,136 @@
using System.Collections;
using System.Collections.Generic;
using Assets.HeroEditor4D.Common.Scripts.CharacterScripts;
using Assets.HeroEditor4D.Common.Scripts.Enums;
using UnityEngine;
public class LostNpc : MonoBehaviour
{
//check if the quest is active on local player
public Character4D character;
[SerializeField] private bool _isQuestActive;
public QuestScriptable[] questData;
private playerNetwork player;
[SerializeField] private float followSpeed = 2f;
[SerializeField] private float stopDistance = 1f;
[SerializeField] private float maxDistance = 15f;
public bool _isFollowing;
/// <summary>
/// Start is called on the frame when a script is enabled just before
/// any of the Update methods is called the first time.
/// </summary>
void Start()
{
character.AnimationManager.SetState(CharacterState.Dance);
}
void Update()
{
if (_isQuestActive)
{
FollowPlayer();
}
// if (player != null)
// {
// isPlayerInRange = Vector3.Distance(transform.position, player.transform.position) < followRadius;
// }
// else
// {
// isPlayerInRange = false;
// }
// if (player != null)
// {
// FollowPlayer();
// }
}
// check if the activequest is for finding the lost npc
// if the player is close to the npc - the npc will start following the player
// once the player go back to quest npc - the quest will be completed and npc will stop follow / destroy after few minutes
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
if (other.transform == playerNetwork.localPlayerTransform)
{
player = playerNetwork.localPlayerTransform.GetComponent<playerNetwork>();
//check if the quest match for finding lost npc
if (player.currentQuest == questData[0])
{
_isQuestActive = true;
_isFollowing = true;
npcFinalCollider.isTrigger = true;
}
}
}
}
float endTimer = 5f;
public void FollowPlayer()
{
float distance = Vector2.Distance(transform.position, player.transform.position);
if (distance <= stopDistance || distance >= maxDistance)
{
character.AnimationManager.SetState(CharacterState.Idle);
_isFollowing = false; // Stop following
return;
}
if(player.currentQuest==null){
if(endTimer > 0 ){
endTimer -= Time.deltaTime;
}else{
Destroy(gameObject);
}
character.AnimationManager.SetState(CharacterState.Idle);
_isFollowing = false;
return;
}
// Move
Vector2 direction = (player.transform.position - transform.position).normalized;
transform.position = Vector2.MoveTowards(transform.position, player.transform.position, followSpeed * Time.deltaTime);
//
if (direction.x > 0) character.SetDirection(Vector2.right);
else if (direction.x < 0) character.SetDirection(Vector2.left);
else if (direction.y > 0) character.SetDirection(Vector2.up);
else if (direction.y < 0) character.SetDirection(Vector2.down);
//
character.AnimationManager.SetState(CharacterState.Walk);
}
public void StopFollowing()
{
_isFollowing = false;
character.AnimationManager.SetState(CharacterState.Idle);
}
public BoxCollider2D npcFinalCollider;
public void SetFinalQuestAction()
{
//enable npc is trigger
npcFinalCollider.isTrigger = true;
//StopFollowing();
//destroy npc after few minutes
}
}

View File

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

View File

@@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class autoDisableGameObj : MonoBehaviour
{
public float disableTime = 5f;
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
void OnEnable()
{
StartCoroutine(DisableIteself());
}
private IEnumerator DisableIteself()
{
yield return new WaitForSeconds(disableTime);
gameObject.SetActive(false);
}
}

View File

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

View File

@@ -32,4 +32,6 @@ public class cameraRPG : MonoBehaviour
public void Teleport(Vector3 newLocation){
transform.position = newLocation - offset;
}
}

View File

@@ -0,0 +1,151 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using Mirror;
using TMPro;
public class invitePlayer : NetworkBehaviour
{
[Header("UI References")]
[SerializeField] private GameObject inviteUI, beingInviteUI;
[SerializeField] private GameObject inPartyUI;
[SerializeField] private TMP_Text inPartyOwnerNameTxt;
[SerializeField] private TMP_Text inPartyPlayersTxt;
[SerializeField] private TMP_Text inviteOwnerNameTxt;
[SerializeField] private CanvasGroup uiCanvasGroup, bUiCanvasGroup;
[SerializeField] private RectTransform uiRectTransform, panelRect;
[Header("Animation Settings")]
[SerializeField] private float appearDuration = 0.3f;
[SerializeField] private float disappearDuration = 0.2f;
[SerializeField] private Ease appearEase = Ease.OutBack;
[SerializeField] private Ease disappearEase = Ease.InBack;
[SerializeField] private Vector2 offScreenPosition = new Vector2(1200, -140);
[SerializeField] private Vector2 onScreenPosition = new Vector2(1300, -140);
private void Start()
{
uiRectTransform.localScale = Vector3.zero;
uiCanvasGroup.alpha = 0;
inviteUI.SetActive(false);
beingInviteUI.SetActive(false);
onScreenPosition = panelRect.anchoredPosition;
offScreenPosition = new Vector2(
+Screen.width, // Use screen width for consistent off-screen positioning
onScreenPosition.y
);
panelRect.anchoredPosition = offScreenPosition;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.L))
{
ShowInvite("keyBoard");
}
}
private void OnMouseDown() //clicking on collider
{
ShowInviteUI();
}
public void ShowInviteUI()
{
inviteUI.SetActive(true);
uiCanvasGroup.alpha = 0;
uiRectTransform.localScale = Vector3.zero;
Sequence showSequence = DOTween.Sequence();
showSequence.Append(uiRectTransform.DOScale(1, appearDuration).SetEase(appearEase))
.Join(uiCanvasGroup.DOFade(1, appearDuration))
.SetUpdate(true);
Camera.main.DOShakePosition(0.2f, 0.1f, 1, 90f, false);
}
public void CloseInviteUI()
{
Sequence hideSequence = DOTween.Sequence();
hideSequence.Append(uiRectTransform.DOScale(0, disappearDuration).SetEase(disappearEase))
.Join(uiCanvasGroup.DOFade(0, disappearDuration))
.OnComplete(() => inviteUI.SetActive(false));
}
public void InvitePlayer()
{
string thisPlayerName = GetComponent<playerNetwork>().playerName;
playerNetwork.localPlayer.CmdInvitePlayer(thisPlayerName);
HidePanel();
}
public string InviteOwner = "";
public void ShowInvite(string ownerName)
{
InviteOwner = ownerName;
inviteOwnerNameTxt.text = "You are being invited to a Party by " + ownerName;
Debug.Log("ShowPanel called");
beingInviteUI.SetActive(true);
panelRect.DOAnchorPos(onScreenPosition, 0.5f)
.SetEase(Ease.OutBack);
}
public void AcceptInvite()
{
playerNetwork.localPlayer.CmdAcceptInvite(InviteOwner);
HidePanel();
}
public void DeclineInvite()
{
HidePanel();
}
public void HidePanel()
{
panelRect.DOAnchorPos(offScreenPosition, 0.5f)
.SetEase(Ease.OutBack)
.OnComplete(() => beingInviteUI.SetActive(false));
}
public void InParty(string ownerName)
{
if (ownerName.Length == 0)
{
inPartyUI.SetActive(false);
}
else
{
inPartyUI.SetActive(true);
inPartyOwnerNameTxt.text = $"{ownerName}'s Party";
playerNetwork[] players = FindObjectsOfType<playerNetwork>();
List<string> playerNames = new List<string>();
foreach (playerNetwork player in players)
{
if (player.myPartyOwner == ownerName)
{
playerNames.Add(player.playerName);
}
}
inPartyPlayersTxt.text = string.Join(", ", playerNames);
}
}
public void LeaveParty(){
//playerNetwork.localPlayer.CmdLeaveParty();
inPartyUI.SetActive(false);
}
}

View File

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

View File

@@ -19,6 +19,9 @@ using Newtonsoft.Json;
public class playerNetwork : NetworkBehaviour
{
public static playerNetwork localPlayer;
public invitePlayer invitePlayer;
public const float ATTACK_COOLDOWN = 0.6f;
[HideInInspector]
public StatManager statManager;
@@ -44,6 +47,8 @@ public class playerNetwork : NetworkBehaviour
[SyncVar(hook = nameof(OnXpChanged))]
public int XP;
[SyncVar]
public string myPartyOwner;
public int lvl2 { get{
return GetLevelForKills2(enemyKillCount);
@@ -204,7 +209,10 @@ public class playerNetwork : NetworkBehaviour
localPlayerTransform.GetComponent<playerNetwork>().questActions.Add(action);
}
void Awake(){
invitePlayer = GetComponent<invitePlayer>();
rangeEnemyFind = GetComponent<rangeEnemyFinder>();
}
void Start(){
// for(int i =0; i < 2000; i+=10){
@@ -221,6 +229,7 @@ public class playerNetwork : NetworkBehaviour
}else{
localPlayerTransform = transform;
localPlayer = this;
cameraRPG.instance.SetTarget(transform);
#if UNITY_EDITOR
ResetHealthAndArmor();
@@ -244,6 +253,43 @@ public class playerNetwork : NetworkBehaviour
}
[Command]
public void CmdInvitePlayer(string otherPlayerName){
if(myPartyOwner == null || myPartyOwner.Length == 0){
FindPlayerByName(otherPlayerName).ShowInvite(playerName);
}else{
FindPlayerByName(otherPlayerName).ShowInvite(myPartyOwner);
}
}
public void ShowInvite(string ownerName){
RpcInvitePlayer(ownerName);
}
[ClientRpc]
void RpcInvitePlayer(string playerName){
if(!isLocalPlayer){return;}
invitePlayer.ShowInvite(playerName);
}
[Command]
public void CmdAcceptInvite(string otherPlayerName){
myPartyOwner = otherPlayerName;
}
playerNetwork FindPlayerByName(string playerName){
playerNetwork[] players = FindObjectsOfType<playerNetwork>();
foreach(playerNetwork player in players){
if(player.playerName == playerName){
return player;
}
}
return null;
}
void LoadCharFromJson(string json){
if(json.Length <=0){return;}
character.FromJson(json,true);
@@ -372,9 +418,7 @@ public class playerNetwork : NetworkBehaviour
rangeEnemyFinder rangeEnemyFind;
enemyScript closestEnemy => rangeEnemyFind.targetEnemy;
void Awake(){
rangeEnemyFind = GetComponent<rangeEnemyFinder>();
}
float attackTimer = 0;
[HideInInspector]
@@ -395,6 +439,12 @@ public class playerNetwork : NetworkBehaviour
txtEnemyKillCount.text = enemyKillCount.ToString();
coinText.text = playerCoin.ToString();
txtPlayerName.text = gplayAuth.userNameCloud;
if(myPartyOwner != null && myPartyOwner.Length > 0){
invitePlayer.InParty(myPartyOwner);
}else{
invitePlayer.InParty("");
}
}
ShowXP();
ShowLevel();