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

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

parent f10c39a4
...@@ -5,14 +5,16 @@ using UnityEngine; ...@@ -5,14 +5,16 @@ using UnityEngine;
public class AttackProperty : MonoBehaviour{ public class AttackProperty : MonoBehaviour{
public float damage = 0; public float damage = 0;
public float knockBackMultiplier = 1f; public float knockBackMultiplier = 1f;
public int debuffNum = 0; public float[] debuffTime = new float[(int)EnemyDebuffCase.END_POINTER];
public EnemyDebuffCase[] debuffType = new EnemyDebuffCase[10];
public int[] debuffTime = new int[10];
EffectManager effectManager; EffectManager effectManager;
PlayerAttack playerAttack;
InventoryManager inventoryManager;
private void Awake() private void Awake()
{ {
effectManager = EffectManager.Instance; effectManager = EffectManager.Instance;
playerAttack = transform.parent.GetComponentInChildren<PlayerAttack>();
inventoryManager = InventoryManager.Instance;
} }
private void OnTriggerEnter2D(Collider2D collision) private void OnTriggerEnter2D(Collider2D collision)
...@@ -21,10 +23,21 @@ public class AttackProperty : MonoBehaviour{ ...@@ -21,10 +23,21 @@ public class AttackProperty : MonoBehaviour{
Bounds tmpBounds = new Bounds(); Bounds tmpBounds = new Bounds();
if (collision.CompareTag("Enemy") && !collision.transform.GetChild(0).GetComponent<Enemy>().Invisible) 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>(); Enemy enemyInfo = collision.transform.GetChild(0).GetComponent<Enemy>();
collision.transform.GetChild(0).GetComponent<Enemy>().GetDamaged(curAttack);
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 //make effect
foreach (Collider2D col in GetComponents<Collider2D>()) foreach (Collider2D col in GetComponents<Collider2D>())
......
...@@ -49,7 +49,7 @@ public class Enemy : MonoBehaviour { ...@@ -49,7 +49,7 @@ public class Enemy : MonoBehaviour {
private void Awake() private void Awake()
{ {
enemyManager = EnemyManager.Instance; enemyManager = EnemyManager.Instance;
inventoryManager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>(); inventoryManager = InventoryManager.Instance;
lifeStoneManager = GameObject.Find("UI Canvas").transform.GetChild(0).GetComponent<LifeStoneManager>(); lifeStoneManager = GameObject.Find("UI Canvas").transform.GetChild(0).GetComponent<LifeStoneManager>();
animator = GetComponent<Animator>(); animator = GetComponent<Animator>();
} }
......
...@@ -14,7 +14,7 @@ public class PlayerAttack : MonoBehaviour { ...@@ -14,7 +14,7 @@ public class PlayerAttack : MonoBehaviour {
public Animator anim; public Animator anim;
public AnimatorOverrideController aoc; public AnimatorOverrideController aoc;
public AnimationClip[] normalAttack = new AnimationClip[3]; public AnimationClip[] normalAttack = new AnimationClip[3];
public InventoryManager inventoryManager; InventoryManager inventoryManager;
public LifeStoneManager lifeStoneManager; public LifeStoneManager lifeStoneManager;
float comboEndTime; float comboEndTime;
...@@ -24,6 +24,7 @@ public class PlayerAttack : MonoBehaviour { ...@@ -24,6 +24,7 @@ public class PlayerAttack : MonoBehaviour {
void Awake () void Awake ()
{ {
inventoryManager = InventoryManager.Instance;
playerController = GetComponent<PlayerController>(); playerController = GetComponent<PlayerController>();
anim = GetComponent<Animator>(); anim = GetComponent<Animator>();
aoc = new AnimatorOverrideController(anim.runtimeAnimatorController); aoc = new AnimatorOverrideController(anim.runtimeAnimatorController);
......
...@@ -5,15 +5,18 @@ using UnityEngine; ...@@ -5,15 +5,18 @@ using UnityEngine;
public class PlayerAttackInfo { public class PlayerAttackInfo {
public float damage = 0; public float damage = 0;
public float knockBackMultiplier = 1f; public float knockBackMultiplier = 1f;
public int debuffNum = 0; public float[] debuffTime = new float[(int)EnemyDebuffCase.END_POINTER];
public EnemyDebuffCase[] debuffType = new EnemyDebuffCase[10]; public PlayerAttackInfo(float damage, float knockBackMultiplier, float[] debuffTime)
public int[] debuffTime = new int[10];
public PlayerAttackInfo(float damage, float knockBackMultiplier, int debuffNum, EnemyDebuffCase[] debuffType, int[] debuffTime)
{ {
this.damage = damage; this.damage = damage;
this.knockBackMultiplier = knockBackMultiplier; this.knockBackMultiplier = knockBackMultiplier;
this.debuffNum = debuffNum;
this.debuffType = debuffType;
this.debuffTime = debuffTime; this.debuffTime = debuffTime;
} }
public PlayerAttackInfo(PlayerAttackInfo origin)
{
damage = origin.damage;
knockBackMultiplier = origin.knockBackMultiplier;
debuffTime = origin.debuffTime;
}
} }
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
ice, ice,
stun, stun,
blind, blind,
charm charm,
END_POINTER
}; };
public enum PlayerDebuffCase public enum PlayerDebuffCase
{ {
......
...@@ -24,4 +24,34 @@ public abstract class Addon { ...@@ -24,4 +24,34 @@ public abstract class Addon {
highlight = null; highlight = null;
sizeInventory = new Vector2(0, 0); 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 ...@@ -12,7 +12,7 @@ public class AddonDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDra
void Start() void Start()
{ {
ui = GameObject.Find("InventoryCanvas").GetComponent<InventoryUI>(); ui = GameObject.Find("InventoryCanvas").GetComponent<InventoryUI>();
manager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>(); manager = InventoryManager.Instance;
addonGroup = ui.gameObject.transform.Find("AddonGroup"); addonGroup = ui.gameObject.transform.Find("AddonGroup");
discardBin = ui.gameObject.transform.Find("DiscardBin"); discardBin = ui.gameObject.transform.Find("DiscardBin");
} }
......
...@@ -34,7 +34,7 @@ public class DroppedItem : MonoBehaviour, IPlayerInteraction ...@@ -34,7 +34,7 @@ public class DroppedItem : MonoBehaviour, IPlayerInteraction
} }
public void Init(Addon _addon, Vector3 pos) public void Init(Addon _addon, Vector3 pos)
{ {
inventoryManager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>(); inventoryManager = InventoryManager.Instance;
addon = _addon; addon = _addon;
itemAddon = true; itemAddon = true;
rb2D = GetComponent<Rigidbody2D>(); rb2D = GetComponent<Rigidbody2D>();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class InventoryManager : MonoBehaviour { public class InventoryManager : Singleton<InventoryManager> {
public List<Item> itemList = new List<Item>(); public List<Item> itemList = new List<Item>();
public List<Addon> addonList = new List<Addon>(); public List<Addon> addonList = new List<Addon>();
......
...@@ -64,10 +64,75 @@ public abstract class Item { ...@@ -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 ...@@ -12,7 +12,7 @@ public class ItemDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDrag
void Start() void Start()
{ {
ui = GameObject.Find("InventoryCanvas").GetComponent<InventoryUI>(); ui = GameObject.Find("InventoryCanvas").GetComponent<InventoryUI>();
manager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>(); manager = InventoryManager.Instance;
discardBin = ui.gameObject.transform.Find("DiscardBin"); discardBin = ui.gameObject.transform.Find("DiscardBin");
} }
public void OnBeginDrag(PointerEventData eventData) public void OnBeginDrag(PointerEventData eventData)
......
...@@ -8,7 +8,7 @@ public class ItemRoomInGame : RoomInGame { ...@@ -8,7 +8,7 @@ public class ItemRoomInGame : RoomInGame {
{ {
base.RoomEnter(); base.RoomEnter();
Room room = transform.parent.GetComponent<Room>(); Room room = transform.parent.GetComponent<Room>();
InventoryManager inventoryManager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>(); InventoryManager inventoryManager = InventoryManager.Instance;
LifeStoneManager lifeStoneManager = GameObject.Find("LifeStoneUI").GetComponent<LifeStoneManager>(); LifeStoneManager lifeStoneManager = GameObject.Find("LifeStoneUI").GetComponent<LifeStoneManager>();
int probability = Random.Range(0, 100); int probability = Random.Range(0, 100);
Vector3 itemPosition = transform.Find("item spot").position; 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