-
Notifications
You must be signed in to change notification settings - Fork 2
explain EquipmentManagementSystem
Yoo Hyeokjin edited this page Jun 27, 2023
·
2 revisions
public List<Weapon> Weapons; // 현재 가지고 있는 Weapon List
public List<Accessory> Accessories; // 현재 가지고 있는 Accessory List
public List<int> MasteredWeapons; // 현재 가지고 있는 Master한 Weapon List
public List<int> MasteredAccessories; // 현재 가지고 있는 Master한 Weapon List
public int[] TransWeaponIndex; // 해당 index의 weapon이 현재 보유중인 Weapons의 몇 번째 index에 있는지 반환하는 배열, 없다면 -1 반환
public int[] TransAccessoryIndex; // 위와 같으나 Accessory에 해당
public void Set(int startingWeapon)
{
Weapons = new List<Weapon>(); // List를 만들어준다.
Accessories = new List<Accessory>(); // List를 만들어준다.
TransWeaponIndex = Enumerable.Repeat<int>(-1, Constants.MAX_WEAPON_NUMBER).ToArray<int>(); // MAX_WEAPON_NUMBER만큼 -1로 채운다.
TransAccessoryIndex = Enumerable.Repeat<int>(-1, Constants.MAX_ACCESSORY_NUMBER).ToArray<int>(); // MAX_ACCESSORY_NUMBER만큼 -1로 채운다.
MasteredWeapons = new List<int>(); // List를 만들어준다.
MasteredAccessories = new List<int>(); // List를 만들어준다.
SetNewWeapon(startingWeapon); // Weapon을 얻었을 때 실행하는 코드
}
public void SetNewWeapon(int weaponIndex)
{
GameManager.instance.WeaponGetTime[weaponIndex] = GameManager.instance.GameTime; // Weapon을 얻은 시간을 저장한다.
AddNewWeapon(weaponIndex); // 새로 얻은 무기를 Weapon List에 추가하는 Method
TransWeaponIndex[weaponIndex] = Weapons.Count - 1; // 해당하는 무기가 Weapon List에 몇 번째에 해당하는 저장한다.
Weapons.Last().WeaponDefalutSetting(weaponIndex); // 가지고 있는 무기들을 기본 Setting을 한다.
GameManager.instance.WeaponSlot.GetComponent<SlotUI>().AddSlot(weaponIndex, 0); // Slot UI 에 해당 Weapon을 넣는다.
ProcessWeaponSub(weaponIndex, Weapons.Last()); // 비둘기 관련된 Method
}
private void ProcessWeaponSub(int weaponIndex, Weapon weapon)
{
switch(weaponIndex)
{
case 7: // peachOne
weapon.GetComponent<Peachone>().SpawnBlueBird(SkillFiringSystem.instance.Birds[0]);
break;
case 8: // ebonyWings
weapon.GetComponent<EbonyWings>().SpawnBlackBird(SkillFiringSystem.instance.Birds[1]);
break;
}
}
private void AddNewWeapon(int weaponIndex) // SkillFiringSystem에 저장된 해당되는 무기의 Prefab을 불러온다.
{
switch (weaponIndex)
{
case 0: // Whip
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<Whip>());
break;
case 1: // MagicWand
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<MagicWand>());
break;
case 2: // Knife
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<Knife>());
break;
case 3: // Cross
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<Cross>());
break;
case 4: // KingBible
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<KingBible>());
break;
case 5: // FireWand
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<FireWand>());
break;
case 6: // Garlic
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<Gralic>());
break;
case 7: // peachOne
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<Peachone>());
break;
case 8: // ebonyWings
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<EbonyWings>());
break;
case 9: // LightningRing
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<LightningRing>());
break;
}
}
public void GetAccessory(int accessoryIndex)
{
TransAccessoryIndex[accessoryIndex] = Accessories.Count; // 얻은 Accessory가 몇 번째인지 저장한다.
Accessories.Add(new Accessory(accessoryIndex)); // Accessory List에 얻은 Accessory를 추가한다.
UpgradeAccessory(accessoryIndex); // Accessory를 Upgrade한다.
GameManager.instance.AccessorySlot.GetComponent<SlotUI>().AddSlot(accessoryIndex, 1); // Slot UI 에 해당 Accessory를 넣는다.
}
public bool HasWeapon(int weaponIndex)
{
if (weaponIndex < 0 || weaponIndex >= Constants.MAX_WEAPON_NUMBER)
return false;
return TransWeaponIndex[weaponIndex] >= 0;
}
public bool HasAcc(int accIndex)
{
if (accIndex < 0 || accIndex >= Constants.MAX_ACCESSORY_NUMBER)
return false;
return TransAccessoryIndex[accIndex] >= 0;
}
public void ApplyItem(Tuple<int, int, int> pickUp)
{
switch ((Enums.EPickUpType)pickUp.Item1)
{
case Enums.EPickUpType.Weapon: // Weapon을 얻었다면
ApplyWeapon(pickUp.Item2, pickUp.Item3); // Weapon을 적용한다.
break;
case Enums.EPickUpType.Accessory: // Accessory를 얻었다면
ApplyAccessory(pickUp.Item2, pickUp.Item3); // Accessory를 적용한다.
break;
default:
ApplyEtc(pickUp.Item2); // Etc를 얻었다면 그것을 적용한다.
break;
}
}
private void ApplyWeapon(int weaponIndex, int hasWeapon)
{ // Weapon을 가지고 있으면 Upgrade를 하고 없으면 Set해라
if (hasWeapon == 0)
SetNewWeapon(weaponIndex);
else
UpgradeWeapon(weaponIndex);
}
private void ApplyAccessory(int accessoryIndex, int hasAccessory)
{ // Accessory를 가지고 있으면 Upgrade를 하고 없으면 Set해라
if (hasAccessory == 0)
GetAccessory(accessoryIndex);
else
UpgradeAccessory(accessoryIndex);
}
private void ApplyEtc(int etcIndex)
{ // 얻은 Etc를 적용
switch ((Enums.EEtc)etcIndex)
{
case Enums.EEtc.Food:
// TODO: 체력 회복 함수와 연결
break;
case Enums.EEtc.Money:
// TODO: 재화 획득 함수와 연결
break;
default:
break;
}
}
public Weapon GetWeapon(int weaponIndex)
{ // 해당하는 무기를 return한다.
if (TransWeaponIndex[weaponIndex] < 0)
Debug.Log("없는 무기 호출");
// TODO: 없는 무기 호출시 에러! 제대로 작성
Debug.Log(TransWeaponIndex[weaponIndex]);
Debug.Log(Weapons[TransWeaponIndex[weaponIndex]]);
return Weapons[TransWeaponIndex[weaponIndex]];
}
public void UpgradeWeapon(int weaponIndex)
{ // Weapon을 Upgrade한다. 만약 MaxLevel이라면 Master한 Weapon에 추가한다.
Weapons[TransWeaponIndex[weaponIndex]].Upgrade();
if (Weapons[TransWeaponIndex[weaponIndex]].IsMaster())
{
MasteredWeapons.Add(weaponIndex);
}
}
public void UpgradeAccessory(int accessoryIndex)
{ // Accessory을 Upgrade한다. 만약 MaxLevel이라면 Master한 Accessory에 추가한다.
Accessories[TransAccessoryIndex[accessoryIndex]].Upgrade();
if (Accessories[TransAccessoryIndex[accessoryIndex]].IsMaster())
{
MasteredAccessories.Add(accessoryIndex);
}
}
using System.Collections.Generic;
using System.Linq;
using System;
using UnityEngine;
public class EquipmentManagementSystem
{
public List<Weapon> Weapons;
public List<Accessory> Accessories;
public List<int> MasteredWeapons;
public List<int> MasteredAccessories;
public int[] TransWeaponIndex; // 해당 index의 weapon이 현재 보유중인 Weapons의 몇 번째 index에 있는지 반환하는 배열, 없다면 -1 반환
public int[] TransAccessoryIndex; // 위와 같으나 Accessory에 해당
public void Set(int startingWeapon)
{
Weapons = new List<Weapon>();
Accessories = new List<Accessory>();
TransWeaponIndex = Enumerable.Repeat<int>(-1, Constants.MAX_WEAPON_NUMBER).ToArray<int>();
TransAccessoryIndex = Enumerable.Repeat<int>(-1, Constants.MAX_ACCESSORY_NUMBER).ToArray<int>();
MasteredWeapons = new List<int>();
MasteredAccessories = new List<int>();
SetNewWeapon(startingWeapon);
}
public void ApplyItem(Tuple<int, int, int> pickUp)
{
switch ((Enums.EPickUpType)pickUp.Item1)
{
case Enums.EPickUpType.Weapon:
ApplyWeapon(pickUp.Item2, pickUp.Item3);
break;
case Enums.EPickUpType.Accessory:
ApplyAccessory(pickUp.Item2, pickUp.Item3);
break;
default:
ApplyEtc(pickUp.Item2);
break;
}
}
public bool HasWeapon(int weaponIndex)
{
if (weaponIndex < 0 || weaponIndex >= Constants.MAX_WEAPON_NUMBER)
return false;
return TransWeaponIndex[weaponIndex] >= 0;
}
public bool HasAcc(int accIndex)
{
if (accIndex < 0 || accIndex >= Constants.MAX_ACCESSORY_NUMBER)
return false;
return TransAccessoryIndex[accIndex] >= 0;
}
public void SetNewWeapon(int weaponIndex)
{
GameManager.instance.WeaponGetTime[weaponIndex] = GameManager.instance.GameTime;
AddNewWeapon(weaponIndex);
TransWeaponIndex[weaponIndex] = Weapons.Count - 1;
Weapons.Last().WeaponDefalutSetting(weaponIndex);
GameManager.instance.WeaponSlot.GetComponent<SlotUI>().AddSlot(weaponIndex, 0);
ProcessWeaponSub(weaponIndex, Weapons.Last());
}
public Weapon GetWeapon(int weaponIndex)
{
if (TransWeaponIndex[weaponIndex] < 0)
Debug.Log("없는 무기 호출");
// TODO: 없는 무기 호출시 에러! 제대로 작성
Debug.Log(TransWeaponIndex[weaponIndex]);
Debug.Log(Weapons[TransWeaponIndex[weaponIndex]]);
return Weapons[TransWeaponIndex[weaponIndex]];
}
public void UpgradeWeapon(int weaponIndex)
{
Weapons[TransWeaponIndex[weaponIndex]].Upgrade();
if (Weapons[TransWeaponIndex[weaponIndex]].IsMaster())
{
MasteredWeapons.Add(weaponIndex);
}
}
public void GetAccessory(int accessoryIndex)
{
TransAccessoryIndex[accessoryIndex] = Accessories.Count;
Accessories.Add(new Accessory(accessoryIndex));
UpgradeAccessory(accessoryIndex);
GameManager.instance.AccessorySlot.GetComponent<SlotUI>().AddSlot(accessoryIndex, 1);
}
public void UpgradeAccessory(int accessoryIndex)
{
Accessories[TransAccessoryIndex[accessoryIndex]].Upgrade();
if (Accessories[TransAccessoryIndex[accessoryIndex]].IsMaster())
{
MasteredAccessories.Add(accessoryIndex);
}
}
private void ProcessWeaponSub(int weaponIndex, Weapon weapon)
{
switch(weaponIndex)
{
case 7: // peachOne
weapon.GetComponent<Peachone>().SpawnBlueBird(SkillFiringSystem.instance.Birds[0]);
break;
case 8: // ebonyWings
weapon.GetComponent<EbonyWings>().SpawnBlackBird(SkillFiringSystem.instance.Birds[1]);
break;
}
}
private void AddNewWeapon(int weaponIndex)
{
switch (weaponIndex)
{
case 0: // Whip
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<Whip>());
break;
case 1: // MagicWand
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<MagicWand>());
break;
case 2: // Knife
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<Knife>());
break;
case 3: // Cross
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<Cross>());
break;
case 4: // KingBible
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<KingBible>());
break;
case 5: // FireWand
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<FireWand>());
break;
case 6: // Garlic
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<Gralic>());
break;
case 7: // peachOne
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<Peachone>());
break;
case 8: // ebonyWings
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<EbonyWings>());
break;
case 9: // LightningRing
Weapons.Add((SkillFiringSystem.instance.weaponPrefabs[weaponIndex]).GetComponent<LightningRing>());
break;
}
}
private void ApplyWeapon(int weaponIndex, int hasWeapon)
{
if (hasWeapon == 0)
SetNewWeapon(weaponIndex);
else
UpgradeWeapon(weaponIndex);
}
private void ApplyAccessory(int accessoryIndex, int hasAccessory)
{
if (hasAccessory == 0)
GetAccessory(accessoryIndex);
else
UpgradeAccessory(accessoryIndex);
}
private void ApplyEtc(int etcIndex)
{
switch ((Enums.EEtc)etcIndex)
{
case Enums.EEtc.Food:
// TODO: 체력 회복 함수와 연결
break;
case Enums.EEtc.Money:
// TODO: 재화 획득 함수와 연결
break;
default:
break;
}
}
}