CultivateImmortal/Assets/Scripts/GameObject/MonsterObject.cs

164 lines
4.4 KiB
C#
Raw Normal View History

2024-11-14 18:15:51 +08:00
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
2024-11-14 18:15:51 +08:00
using UnityEngine;
using UnityEngine.UI;
public class MonsterObject : MonoBehaviour
{
//Ѫ<><D1AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public RectTransform imgDragHp;
//Ѫ<><D1AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public Text txtDragHp;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public Text txtDragName;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ
public Image imgDrog;
2024-11-14 18:15:51 +08:00
//<2F><>ǰѪ<C7B0><D1AA>
private int hp;
private float hpWide = 240f;
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
2024-11-15 18:10:36 +08:00
public bool isDead;
2024-11-14 18:15:51 +08:00
//<2F><>¼<EFBFBD><C2BC>һ<EFBFBD>ι<EFBFBD><CEB9><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
private float frontTime;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private MonsterData monster;
2024-11-15 18:10:36 +08:00
2024-11-14 18:15:51 +08:00
// Update is called once per frame
void Update()
{
//<2F><><EFBFBD><EFBFBD>ʲôʱ<C3B4><CAB1>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (isDead)
{
return;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ܿ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD> <20>͹<EFBFBD><CDB9><EFBFBD>
if (GameMgr.Instance.isStartAtk)
2024-11-14 18:15:51 +08:00
{
if (Time.time - frontTime >= monster.atkTime)
{
//<2F><>¼<EFBFBD><C2BC><EFBFBD>ι<EFBFBD><CEB9><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD><CAB1>
frontTime = Time.time;
//<2F><><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5>˺<EFBFBD>
EventCenter.Instance.EventTrigger<MonsterData>(E_EventType.E_Player_Wound, monster);
}
2024-11-14 18:15:51 +08:00
}
}
//<2F><><EFBFBD><EFBFBD>
public void Wound(PlayerData player)
{
if (isDead)
{
return;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD>
//<2F><><EFBFBD><EFBFBD>Ѫ<EFBFBD><D1AA>
2024-12-02 18:00:58 +08:00
int damageHP;
//<2F>Ƿ񴥷<C7B7><F1B4A5B7><EFBFBD><EFBFBD><EFBFBD>
if (GameMgr.Instance.ProbaReturn(player.crit))
{
2024-12-02 18:00:58 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
damageHP = (int)((player.atk - monster.def) * (1 + player.critDamage / 100));
//<2F><>ֹû<D6B9><C3BB><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (damageHP < 0)
{
damageHP = 0;
}
hp -= damageHP;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѫ<EFBFBD><D1AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
EventCenter.Instance.EventTrigger<int>(E_EventType.E_Monster_CritDamageNum, damageHP);
}
else
{
damageHP = player.atk - monster.def;
//<2F><>ֹû<D6B9><C3BB><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (damageHP < 0)
{
damageHP = 0;
}
hp -= damageHP;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѫ<EFBFBD><D1AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
EventCenter.Instance.EventTrigger<int>(E_EventType.E_Monster_DamageNum, damageHP);
}
2024-11-14 18:15:51 +08:00
if (hp <= 0)
{
Dead();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϸ
GameMgr.Instance.StartInit();
2024-11-14 18:15:51 +08:00
this.gameObject.SetActive(false);
return;
}
UpdateHp(hp);
}
2024-11-14 18:15:51 +08:00
//<2F><><EFBFBD><EFBFBD>
public void Dead()
{
isDead = true;
//<2F><><EFBFBD>Һ͹<D2BA><CDB9><EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
2024-11-15 18:10:36 +08:00
GameMgr.Instance.isStartAtk = false;
//<2F>ɽ<EFBFBD><C9BD><EFBFBD><EFBFBD>ղֿ<D5B2>
GameMgr.Instance.isFeijianClose = true;
2024-11-14 18:15:51 +08:00
//Ѫ<><D1AA><EFBFBD><EFBFBD><EFBFBD>ȱ<EFBFBD>Ϊ0
UpdateHp(0);
//<2F><><EFBFBD><EFBFBD>ս<EFBFBD><D5BD>ʤ<EFBFBD><CAA4>
EventCenter.Instance.EventTrigger<string>(E_EventType.E_Pool_Register1,"ս<><D5BD>ʤ<EFBFBD><CAA4>");
2024-11-14 18:15:51 +08:00
//<2F><><EFBFBD>һ<EFBFBD><D2BB>ý<EFBFBD><C3BD><EFBFBD>
//<2F><><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>ʯ +=<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʯ<EFBFBD>ӳɣ<D3B3>
int getStone = monster.stone + (int)(monster.stone * (GameDataMgr.Instance.player.stoneAdd/100));
GameDataMgr.Instance.player.stone += getStone;
//<2F><><EFBFBD>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դʯ<D4B4><CAAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>TopPanel<65><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GameMgr.Instance.StartTip(getStone,monster.yuan);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GameDataMgr.Instance.PlayerDataSave();
2024-11-14 18:15:51 +08:00
}
private void UpdateHp(int hp)
{
imgDragHp.sizeDelta = new Vector2(hpWide * hp / monster.hp, imgDragHp.sizeDelta.y);
txtDragHp.text = GameMgr.Instance.SetNumber(hp) + "/" + GameMgr.Instance.SetNumber(monster.hp);
2024-11-14 18:15:51 +08:00
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϲ<EFBFBD><CFB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-11-14 18:15:51 +08:00
public void UpdatePanel()
{
//<2F><><EFBFBD>¹<EFBFBD><C2B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
isDead = false;
monster = GameDataMgr.Instance.nowMonster;
hp = monster.hp;
//ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
EventCenter.Instance.AddEventListener<PlayerData>(E_EventType.E_Monster_Wound, Wound);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>
txtDragName.text = monster.name;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>
txtDragName.color = GameMgr.Instance.HexToColor(monster.color);
//<2F><><EFBFBD><EFBFBD>Ѫ<EFBFBD><D1AA>
2024-11-14 18:15:51 +08:00
imgDragHp.sizeDelta = new Vector2(hpWide, imgDragHp.sizeDelta.y);
txtDragHp.text = GameMgr.Instance.SetNumber(monster.hp) + "/" + GameMgr.Instance.SetNumber(monster.hp);
2024-11-14 18:15:51 +08:00
hp = monster.hp;
imgDrog.color = GameMgr.Instance.HexToColor(monster.color);
//<2F><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ <20>ѹ<EFBFBD><D1B9><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>0
2024-11-15 18:10:36 +08:00
frontTime = Time.time;
2024-11-14 18:15:51 +08:00
}
//ʧ<><CAA7>ҲҪע<D2AA><D7A2><EFBFBD>¼<EFBFBD>
void OnDisable()
{
EventCenter.Instance.Claer(E_EventType.E_Monster_Wound);
}
2024-11-14 18:15:51 +08:00
}