|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class Inventory : ResourcePool
|
|
|
|
|
{
|
|
|
|
|
public Character owner;
|
|
|
|
|
public Equipment equipment;
|
|
|
|
|
|
|
|
|
|
[Space(10)]
|
|
|
|
|
public List<ItemData> items;
|
|
|
|
|
public EventConnect ec = new EventConnect();
|
|
|
|
|
[Space(10)]
|
|
|
|
|
public Transform hand;
|
|
|
|
|
public DropItem dropItem;
|
|
|
|
|
public TileCameraEvent camShake;
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
target.SetParent(hand);
|
|
|
|
|
target.localPosition = Vector3.zero;
|
|
|
|
|
target.localEulerAngles = Vector3.zero;
|
|
|
|
|
target.SetParent(transform);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 필드에 떯어져있는 드랍아이템을 획득하여 이를 처리합니다.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="drop">드랍아이템</param>
|
|
|
|
|
public void GainItem(DropItem drop)
|
|
|
|
|
{
|
|
|
|
|
if (this.drop != null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//상점에서 판매 하는 아이템일 경우 보유 코인을 확인하고 처리
|
|
|
|
|
if (drop.PRODUCT && !ItemUse("Coin", drop.item.price))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
target.SetParent(hand);
|
|
|
|
|
target.localPosition = Vector3.zero;
|
|
|
|
|
target.localEulerAngles = Vector3.zero;
|
|
|
|
|
target.SetParent(transform);
|
|
|
|
|
target.localEulerAngles = new Vector3(65, 0, 0);
|
|
|
|
|
|
|
|
|
|
this.drop = drop;
|
|
|
|
|
Invoke("GainEnd_Force", 1f);
|
|
|
|
|
switch (drop.item.type)
|
|
|
|
|
{
|
|
|
|
|
case "Pickup":
|
|
|
|
|
case "Use":
|
|
|
|
|
{
|
|
|
|
|
GainItemApply();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
switch (drop.item.type)
|
|
|
|
|
{
|
|
|
|
|
case "Armor":
|
|
|
|
|
case "Weapon":
|
|
|
|
|
case "Accessory":
|
|
|
|
|
if (!equipment.InstallCheck_Item(drop.item))
|
|
|
|
|
{
|
|
|
|
|
this.drop = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "Active":
|
|
|
|
|
if (owner.skill.HoldingItemCheck(drop.item.idx))
|
|
|
|
|
{
|
|
|
|
|
this.drop = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "Passive":
|
|
|
|
|
if (owner.skill.HoldingItemCheck(drop.item.idx))
|
|
|
|
|
{
|
|
|
|
|
this.drop = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(drop.item.skills.Find(a => a.work.Equals("AHRestore")) != null)
|
|
|
|
|
{
|
|
|
|
|
if (!equipment.InstallCheck_Part(EquipType.Armor))
|
|
|
|
|
{
|
|
|
|
|
this.drop = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drop.sprite.gameObject.SetActive(false);
|
|
|
|
|
|
|
|
|
|
dropItem.item = drop.item;
|
|
|
|
|
dropItem.OnInitialized();
|
|
|
|
|
|
|
|
|
|
owner.OnGain(drop.gameObject, () =>
|
|
|
|
|
{
|
|
|
|
|
ec.Invoke((int)Character.State.EquipItem, drop.item);
|
|
|
|
|
|
|
|
|
|
GameObject eff = EffectPrefabGet(drop.item.type, EffectTargetGet(drop.item.type));
|
|
|
|
|
if (eff != null)
|
|
|
|
|
{
|
|
|
|
|
eff.gameObject.SetActive(true);
|
|
|
|
|
|
|
|
|
|
bool chk = !drop.item.type.Equals("Armor");
|
|
|
|
|
if (!chk)
|
|
|
|
|
camShake.Shake();
|
|
|
|
|
|
|
|
|
|
dropItem.gameObject.SetActive(chk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GainItemApply();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Space(10)]
|
|
|
|
|
public GameObject particleArmor;
|
|
|
|
|
public GameObject particlePassive;
|
|
|
|
|
public GameObject particle;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 아이템 종류에 따른 이팩트 처리
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type">아이템 종류</param>
|
|
|
|
|
/// <param name="target">이팩트가 붙을 위치</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
GameObject EffectPrefabGet(string type, Transform target)
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case "Armor":
|
|
|
|
|
return ObjectCreateLocalPos(particleArmor, target, Vector3.one, Vector3.zero);
|
|
|
|
|
case "Passive":
|
|
|
|
|
return ObjectCreateLocalPos(particlePassive, target, Vector3.one, Vector3.zero);
|
|
|
|
|
default:
|
|
|
|
|
return ObjectCreateLocalPos(particle, target, Vector3.one, Vector3.zero);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Space(10)]
|
|
|
|
|
public Transform targetArmor;
|
|
|
|
|
public Transform targetPassive;
|
|
|
|
|
public Transform target;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 아이템 종류에 따른 타겟을 넘깁니다.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type">아이템 종류</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
Transform EffectTargetGet(string type)
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case "Armor":
|
|
|
|
|
return targetArmor;
|
|
|
|
|
case "Passive":
|
|
|
|
|
return targetPassive;
|
|
|
|
|
default:
|
|
|
|
|
return target;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Space(10)]
|
|
|
|
|
public DropItem drop = null;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 획득한 아이템을 적용합니다.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void GainItemApply()
|
|
|
|
|
{
|
|
|
|
|
if (drop == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (drop.item.type)
|
|
|
|
|
{
|
|
|
|
|
case "Pickup":
|
|
|
|
|
Type_Pickup(drop.item, drop);
|
|
|
|
|
break;
|
|
|
|
|
case "Use":
|
|
|
|
|
Type_Use(drop.item, drop);
|
|
|
|
|
break;
|
|
|
|
|
case "Armor":
|
|
|
|
|
case "Weapon":
|
|
|
|
|
case "Accessory":
|
|
|
|
|
bool chk = !equipment.Install(drop.item);
|
|
|
|
|
drop.gameObject.SetActive(chk);
|
|
|
|
|
|
|
|
|
|
GainEnd();
|
|
|
|
|
break;
|
|
|
|
|
case "Active":
|
|
|
|
|
drop.gameObject.SetActive(false);
|
|
|
|
|
|
|
|
|
|
ec.Invoke((int)Character.State.ActiveItem, drop.item);
|
|
|
|
|
|
|
|
|
|
GainEnd();
|
|
|
|
|
break;
|
|
|
|
|
case "Passive":
|
|
|
|
|
owner.skill.Install(drop.item);
|
|
|
|
|
drop.gameObject.SetActive(false);
|
|
|
|
|
|
|
|
|
|
GainEnd();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 획득 이벤트를 종료합니다.
|
|
|
|
|
/// </summary>
|
|
|
|
|
void GainEnd()
|
|
|
|
|
{
|
|
|
|
|
owner.map.blkCurrent.DropItemChanged(drop);
|
|
|
|
|
GetSound(drop.item.type);
|
|
|
|
|
drop = null;
|
|
|
|
|
|
|
|
|
|
//target.SetParent(transform);
|
|
|
|
|
CancelInvoke();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 획득 이벤트를 강제 종료합니다.
|
|
|
|
|
/// </summary>
|
|
|
|
|
void GainEnd_Force()
|
|
|
|
|
{
|
|
|
|
|
drop = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 아이템 종류별 획득 사운드를 넘깁니다.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
public void GetSound(string type)
|
|
|
|
|
{
|
|
|
|
|
SoundPlayer sp = SoundManager.Instance.PrefabGet($"Sound/SFX item_get_{type.ToLower()}");
|
|
|
|
|
if (sp != null)
|
|
|
|
|
SoundManager.Instance.EffectPlay(sp.gameObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Pickup 타입의 아이템을 처리합니다.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item"></param>
|
|
|
|
|
/// <param name="drop"></param>
|
|
|
|
|
void Type_Pickup(ItemData item, DropItem drop)
|
|
|
|
|
{
|
|
|
|
|
GainEnd();
|
|
|
|
|
drop.OnAnimaionStart(() =>
|
|
|
|
|
{
|
|
|
|
|
drop.gameObject.SetActive(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ItemData itemHold = items.Find(a => a.idx == item.idx);
|
|
|
|
|
|
|
|
|
|
if (itemHold != null)
|
|
|
|
|
{
|
|
|
|
|
if (item.OVERLAP)//중첩되는 아이템인치 확인
|
|
|
|
|
{
|
|
|
|
|
itemHold.Add(item.hold);
|
|
|
|
|
ec.Invoke((int)Character.State.Inventory, itemHold);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itemHold = item;
|
|
|
|
|
ec.Invoke((int)Character.State.Inventory, itemHold);
|
|
|
|
|
items.Add(itemHold);
|
|
|
|
|
}
|
|
|
|
|
//bool Type_Check(ItemData item)
|
|
|
|
|
//{
|
|
|
|
|
// switch (item.work)
|
|
|
|
|
// {
|
|
|
|
|
// case "HP_Restore":
|
|
|
|
|
// return owner.RestoreCheck((int)item.value);
|
|
|
|
|
// case "AH_Added":
|
|
|
|
|
// return owner.ArmorHeartCheck((int)item.value);
|
|
|
|
|
// case "Mana_Added":
|
|
|
|
|
// return owner.ManaCheck();
|
|
|
|
|
// default:
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// USE 타입의 아이템을 처리합니다.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item"></param>
|
|
|
|
|
/// <param name="drop"></param>
|
|
|
|
|
void Type_Use(ItemData item, DropItem drop)
|
|
|
|
|
{
|
|
|
|
|
bool CHK = false;
|
|
|
|
|
switch(item.work)
|
|
|
|
|
{
|
|
|
|
|
case "HP_Restore":
|
|
|
|
|
{
|
|
|
|
|
CHK = owner.Restore((int)item.value);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "AH_Added":
|
|
|
|
|
{
|
|
|
|
|
if (equipment.InstallCheck_Part(EquipType.Armor))
|
|
|
|
|
CHK = owner.OnAdded_ArmorHeart((int)item.value);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "Mana_Added":
|
|
|
|
|
{
|
|
|
|
|
CHK = owner.OnAdded_Mana((int)item.value);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CHK)
|
|
|
|
|
{
|
|
|
|
|
GainEnd();
|
|
|
|
|
drop.OnAnimaionStart(() =>
|
|
|
|
|
{
|
|
|
|
|
drop.gameObject.SetActive(false);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
this.drop = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Pickup 아이템을 사용합니다.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idx">Pickup 아이템 idx</param>
|
|
|
|
|
/// <param name="value">사용 개수</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool ItemUse(string idx, int value)
|
|
|
|
|
{
|
|
|
|
|
ItemData item = items.Find(a => a.idx == idx);
|
|
|
|
|
|
|
|
|
|
if(item != null && value <= item.hold)
|
|
|
|
|
{
|
|
|
|
|
item.Add(-value);
|
|
|
|
|
ec.Invoke((int)Character.State.Inventory, item);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|