Super Knight : Enter the Dungeon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.5 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerInfomation : MonoBehaviour
{
Character player;
InputController input;
Inventory inven;
public void OnInitialized(MapManager mapManager)
{
player = mapManager.player.character;
player.ec.Remove(OnEvent);
player.ec.Add(OnEvent);
input = player.GetComponent<InputController>();
inven = mapManager.player.inven;
inven.ec.Remove(OnEvent);
inven.ec.Add(OnEvent);
}
void OnEvent(int type, object value)
{
switch((Character.State)type)
{
case Character.State.HP_Change:
HPDraw();
break;
case Character.State.Inventory:
HoldDraw((ItemData)value);
break;
case Character.State.Status:
Status();
break;
}
}
public Text txtHP;
public List<Image> hearts;
public List<Image> armorHearts;
public Color colorAH;
void HPDraw()
{
txtHP.text = $"{player.HP}/{player.HP_Max}";
//int HP_Max = (int)(player.HP_Max / 100f);
//int HP = (int)(player.HP / 100f);
//int AH = (int)(player.AH / 100f);
int HP_Max = player.HP_Max;
int HP = player.HP;
int AH = player.AH;
int cntMax = (int)(HP_Max / 2f);
int cnt = (int)(HP / 2f);
int cnt2 = (int)(HP % 2f);
int i = 0;
for(; i < hearts.Count; i++)
{
hearts[i].gameObject.SetActive(true);
if (i < cnt)
hearts[i].sprite = SpriteManager.Instance.SpriteGet($"AtlasIngame", $"itemHeart2");
else if (cnt2 == 1)
{
hearts[i].sprite = SpriteManager.Instance.SpriteGet($"AtlasIngame", $"itemHeart1");
cnt2 = 0;
}
else if (i < cntMax)
hearts[i].sprite = SpriteManager.Instance.SpriteGet($"AtlasIngame", $"itemHeartEmpty");
else
break;
}
cntMax += (int)(AH / 2f);
cnt = (int)(AH / 2f);
cnt2 = (int)(AH % 2f);
for (; i < hearts.Count; i++)
{
hearts[i].gameObject.SetActive(true);
if (0 < cnt--)
hearts[i].sprite = SpriteManager.Instance.SpriteGet($"AtlasIngame", $"itemArmorHeart2");
else if (cnt2 == 1)
{
hearts[i].sprite = SpriteManager.Instance.SpriteGet($"AtlasIngame", $"itemArmorHeart1");
cnt2 = 0;
}
else if (i < cntMax)
hearts[i].sprite = SpriteManager.Instance.SpriteGet($"AtlasIngame", $"itemArmorHeartEmpty");
else
hearts[i].gameObject.SetActive(false);
}
}
[Space(10)]
public Text txtValue_Coin;
public Text txtValue_Bomb;
public Text txtValue_Key;
void HoldDraw(ItemData item)
{
switch(item.idx)
{
case "Coin":
txtValue_Coin.text = $"{item.hold}";
break;
case "Bomb":
txtValue_Bomb.text = $"{item.hold}";
break;
case "Key":
txtValue_Key.text = $"{item.hold}";
break;
}
}
[Space(10)]
public Text txtStatus;
[Space(10)]
public GameObject uiPause;
void Status()
{
string txt = string.Empty;
txt = $"ATK : {player.CalculateATK()}({player.ATK}*{player.ATK_PER})\n";
txt += $"ATK SPD : {player.SPDATK_PER}\n";
float ATK_DLA = player.CalculateAttackDelay();
string str = ATK_DLA == 0.3f ? "ff0000" : "ffffff";
txt += $"ATK DLA : <color=#{str}>{ATK_DLA}</color>({player.DLAATK}*{player.DLAATK_PER})\n";
txt += $"RANGE : {player.RANGE + input.fire.prefabProjectile.distance}({input.fire.prefabProjectile.distance} + {player.RANGE})\n";
float MOVE_SPD = player.CalculateMoveSpeed();
str = MOVE_SPD == 60 ? "ff0000" : "ffffff";
txt += $"MOVE SPD : <color=#{str}>{MOVE_SPD}</color>({player.SPDMOVE}*{player.SPDMOVE_PER})\n";
txtStatus.text = txt;
}
static public bool TEST = false;
void Update()
{
if (Input.GetKeyDown(KeyCode.Z))
{
txtStatus.gameObject.SetActive(TEST = !TEST);
EventManager.Instance.Invoke("TestMode", TEST);
}
if (Input.GetKeyDown(KeyCode.Escape))
uiPause.gameObject.SetActive(true);
}
}