Commit 5b77dbee authored by 18류지석's avatar 18류지석

InventoryManager Singleton으로 개편. 애드온 아이템효과를 적용할 준비가 다 되었다.

parent f10c39a4
......@@ -5,14 +5,16 @@ using UnityEngine;
public class AttackProperty : MonoBehaviour{
public float damage = 0;
public float knockBackMultiplier = 1f;
public int debuffNum = 0;
public EnemyDebuffCase[] debuffType = new EnemyDebuffCase[10];
public int[] debuffTime = new int[10];
public float[] debuffTime = new float[(int)EnemyDebuffCase.END_POINTER];
EffectManager effectManager;
PlayerAttack playerAttack;
InventoryManager inventoryManager;
private void Awake()
{
effectManager = EffectManager.Instance;
playerAttack = transform.parent.GetComponentInChildren<PlayerAttack>();
inventoryManager = InventoryManager.Instance;
}
private void OnTriggerEnter2D(Collider2D collision)
......@@ -21,11 +23,22 @@ public class AttackProperty : MonoBehaviour{
Bounds tmpBounds = new Bounds();
if (collision.CompareTag("Enemy") && !collision.transform.GetChild(0).GetComponent<Enemy>().Invisible)
{
PlayerAttackInfo curAttack = new PlayerAttackInfo(damage, knockBackMultiplier, debuffNum, debuffType, debuffTime);
PlayerAttackInfo curAttack = new PlayerAttackInfo(damage, knockBackMultiplier, debuffTime);
Enemy enemyInfo = collision.transform.GetChild(0).GetComponent<Enemy>();
string combo = playerAttack.comboArray;
foreach (Item tmpItem in inventoryManager.itemList)
for (int i = 0; i < tmpItem.skillNum; i++)
{
if (tmpItem.combo[i].Equals(combo))
{
tmpItem.AttackCalculation(curAttack, enemyInfo, combo);
break;
}
}
collision.transform.GetChild(0).GetComponent<Enemy>().GetDamaged(curAttack);
//make effect
foreach (Collider2D col in GetComponents<Collider2D>())
if (col.isActiveAndEnabled)
......
......@@ -49,7 +49,7 @@ public class Enemy : MonoBehaviour {
private void Awake()
{
enemyManager = EnemyManager.Instance;
inventoryManager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>();
inventoryManager = InventoryManager.Instance;
lifeStoneManager = GameObject.Find("UI Canvas").transform.GetChild(0).GetComponent<LifeStoneManager>();
animator = GetComponent<Animator>();
}
......
......@@ -14,7 +14,7 @@ public class PlayerAttack : MonoBehaviour {
public Animator anim;
public AnimatorOverrideController aoc;
public AnimationClip[] normalAttack = new AnimationClip[3];
public InventoryManager inventoryManager;
InventoryManager inventoryManager;
public LifeStoneManager lifeStoneManager;
float comboEndTime;
......@@ -24,6 +24,7 @@ public class PlayerAttack : MonoBehaviour {
void Awake ()
{
inventoryManager = InventoryManager.Instance;
playerController = GetComponent<PlayerController>();
anim = GetComponent<Animator>();
aoc = new AnimatorOverrideController(anim.runtimeAnimatorController);
......
......@@ -5,15 +5,18 @@ using UnityEngine;
public class PlayerAttackInfo {
public float damage = 0;
public float knockBackMultiplier = 1f;
public int debuffNum = 0;
public EnemyDebuffCase[] debuffType = new EnemyDebuffCase[10];
public int[] debuffTime = new int[10];
public PlayerAttackInfo(float damage, float knockBackMultiplier, int debuffNum, EnemyDebuffCase[] debuffType, int[] debuffTime)
public float[] debuffTime = new float[(int)EnemyDebuffCase.END_POINTER];
public PlayerAttackInfo(float damage, float knockBackMultiplier, float[] debuffTime)
{
this.damage = damage;
this.knockBackMultiplier = knockBackMultiplier;
this.debuffNum = debuffNum;
this.debuffType = debuffType;
this.debuffTime = debuffTime;
}
public PlayerAttackInfo(PlayerAttackInfo origin)
{
damage = origin.damage;
knockBackMultiplier = origin.knockBackMultiplier;
debuffTime = origin.debuffTime;
}
}
......@@ -4,7 +4,8 @@
ice,
stun,
blind,
charm
charm,
END_POINTER
};
public enum PlayerDebuffCase
{
......
......@@ -24,4 +24,34 @@ public abstract class Addon {
highlight = null;
sizeInventory = new Vector2(0, 0);
}
public virtual float DamageAdder(PlayerAttackInfo attackInfo, Enemy enemInfo, string combo)
{
return 0f;
}
public virtual float DamageMultiplier(PlayerAttackInfo attackInfo, Enemy enemInfo, string combo)
{
return 1f;
}
public virtual float[] DebuffAdder(PlayerAttackInfo attackInfo, Enemy enemInfo, string combo)
{
float[] varArray = new float[(int)EnemyDebuffCase.END_POINTER];
for (int i = 0; i < (int)EnemyDebuffCase.END_POINTER; i++) varArray[i] = 0f;
return varArray;
}
public virtual float[] DebuffMultiplier(PlayerAttackInfo attackInfo, Enemy enemInfo, string combo)
{
float[] varArray = new float[(int)EnemyDebuffCase.END_POINTER];
for (int i = 0; i < (int)EnemyDebuffCase.END_POINTER; i++) varArray[i] = 1f;
return varArray;
}
public virtual float KnockBackAdder(PlayerAttackInfo attackInfo, Enemy enemInfo, string combo)
{
return 0f;
}
public virtual float KnockBackMultiplier(PlayerAttackInfo attackInfo, Enemy enemInfo, string combo)
{
return 1f;
}
}
......@@ -12,7 +12,7 @@ public class AddonDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDra
void Start()
{
ui = GameObject.Find("InventoryCanvas").GetComponent<InventoryUI>();
manager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>();
manager = InventoryManager.Instance;
addonGroup = ui.gameObject.transform.Find("AddonGroup");
discardBin = ui.gameObject.transform.Find("DiscardBin");
}
......
......@@ -34,7 +34,7 @@ public class DroppedItem : MonoBehaviour, IPlayerInteraction
}
public void Init(Addon _addon, Vector3 pos)
{
inventoryManager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>();
inventoryManager = InventoryManager.Instance;
addon = _addon;
itemAddon = true;
rb2D = GetComponent<Rigidbody2D>();
......
......@@ -2,7 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
public class InventoryManager : MonoBehaviour {
public class InventoryManager : Singleton<InventoryManager> {
public List<Item> itemList = new List<Item>();
public List<Addon> addonList = new List<Addon>();
......
......@@ -64,10 +64,75 @@ public abstract class Item {
{
}
public void AttackCalculation(PlayerAttackInfo attackInfo, Enemy enemyInfo)
public virtual void AttackCalculation(PlayerAttackInfo attackInfo, Enemy enemyInfo, string combo)
{
PlayerAttackInfo originInfo = new PlayerAttackInfo(attackInfo);
float[] tmpArray;
attackInfo.damage += DamageAdder(originInfo, enemyInfo, combo);
attackInfo.knockBackMultiplier += KnockBackAdder(originInfo, enemyInfo, combo);
tmpArray = DebuffAdder(originInfo, enemyInfo, combo);
for (int i = 0; i < (int)EnemyDebuffCase.END_POINTER; i++)
attackInfo.debuffTime[i] += tmpArray[i];
for (int j = 0; j < attachable.Length; j++)
{
if (attachable[j] && addons[j] != null)
{
attackInfo.damage += addons[j].DamageAdder(originInfo, enemyInfo, combo);
attackInfo.knockBackMultiplier += addons[j].KnockBackAdder(originInfo, enemyInfo, combo);
tmpArray = addons[j].DebuffAdder(originInfo, enemyInfo, combo);
for (int i = 0; i < (int)EnemyDebuffCase.END_POINTER; i++)
attackInfo.debuffTime[i] += tmpArray[i];
}
}
attackInfo.damage *= DamageMultiplier(originInfo, enemyInfo, combo);
attackInfo.knockBackMultiplier *= KnockBackMultiplier(originInfo, enemyInfo, combo);
tmpArray = DebuffMultiplier(originInfo, enemyInfo, combo);
for (int i = 0; i < (int)EnemyDebuffCase.END_POINTER; i++)
attackInfo.debuffTime[i] *= tmpArray[i];
for (int j = 0; j < attachable.Length; j++)
{
if (attachable[j] && addons[j] != null)
{
attackInfo.damage *= addons[j].DamageMultiplier(originInfo, enemyInfo, combo);
attackInfo.knockBackMultiplier *= addons[j].KnockBackMultiplier(originInfo, enemyInfo, combo);
tmpArray = addons[j].DebuffMultiplier(originInfo, enemyInfo, combo);
for (int i = 0; i < (int)EnemyDebuffCase.END_POINTER; i++)
attackInfo.debuffTime[i] *= tmpArray[i];
}
}
}
public virtual float DamageAdder(PlayerAttackInfo attackInfo, Enemy enemInfo, string combo)
{
return 0f;
}
public virtual float DamageMultiplier(PlayerAttackInfo attackInfo, Enemy enemInfo, string combo)
{
return 1f;
}
public virtual float[] DebuffAdder(PlayerAttackInfo attackInfo, Enemy enemInfo, string combo)
{
float[] varArray = new float[(int)EnemyDebuffCase.END_POINTER];
for (int i = 0; i< (int)EnemyDebuffCase.END_POINTER; i++) varArray[i] = 0f;
return varArray;
}
public virtual float[] DebuffMultiplier(PlayerAttackInfo attackInfo, Enemy enemInfo, string combo)
{
float[] varArray = new float[(int)EnemyDebuffCase.END_POINTER];
for (int i = 0; i < (int)EnemyDebuffCase.END_POINTER; i++) varArray[i] = 1f;
return varArray;
}
public virtual float KnockBackAdder(PlayerAttackInfo attackInfo, Enemy enemInfo, string combo)
{
return 0f;
}
public virtual float KnockBackMultiplier(PlayerAttackInfo attackInfo, Enemy enemInfo, string combo)
{
return 1f;
}
}
......@@ -12,7 +12,7 @@ public class ItemDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDrag
void Start()
{
ui = GameObject.Find("InventoryCanvas").GetComponent<InventoryUI>();
manager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>();
manager = InventoryManager.Instance;
discardBin = ui.gameObject.transform.Find("DiscardBin");
}
public void OnBeginDrag(PointerEventData eventData)
......
......@@ -8,7 +8,7 @@ public class ItemRoomInGame : RoomInGame {
{
base.RoomEnter();
Room room = transform.parent.GetComponent<Room>();
InventoryManager inventoryManager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>();
InventoryManager inventoryManager = InventoryManager.Instance;
LifeStoneManager lifeStoneManager = GameObject.Find("LifeStoneUI").GetComponent<LifeStoneManager>();
int probability = Random.Range(0, 100);
Vector3 itemPosition = transform.Find("item spot").position;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment