2024-11-14 18:15:51 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2024-11-21 18:05:42 +08:00
|
|
|
|
using System.Threading;
|
2024-11-14 18:15:51 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class PlayerObject : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
//<2F>ɽ<EFBFBD><C9BD><EFBFBD><EFBFBD>ɵ<EFBFBD>
|
|
|
|
|
public RectTransform feijianPos;
|
|
|
|
|
//Ѫ<><D1AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public RectTransform imgUserHp;
|
|
|
|
|
//Ѫ<><D1AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public Text txtUserHp;
|
|
|
|
|
|
|
|
|
|
private PlayerData player;
|
|
|
|
|
|
|
|
|
|
//<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;
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʲôʱ<C3B4><CAB1>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (isDead)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-15 18:10:36 +08:00
|
|
|
|
if (GameMgr.Instance.isStartAtk)
|
2024-11-14 18:15:51 +08:00
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD>ﵽ<EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>ʱ <20><EFBFBD><CDB9><EFBFBD>
|
2024-12-02 18:00:58 +08:00
|
|
|
|
if (Time.time - frontTime >= player.atkTime-(player.atkTime*player.atkSpeed/100))
|
2024-11-14 18:15:51 +08:00
|
|
|
|
{
|
2024-12-02 18:00:58 +08:00
|
|
|
|
Debug.Log(Application.persistentDataPath);
|
2024-11-14 18:15:51 +08:00
|
|
|
|
//<2F><>¼<EFBFBD><C2BC><EFBFBD>ι<EFBFBD><CEB9><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD><CAB1>
|
|
|
|
|
frontTime = Time.time;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
GameObject obj = PoolMgr.Instance.GetObj("Object/FeiJian");
|
|
|
|
|
obj.transform.SetParent(feijianPos, false);
|
2024-11-28 17:59:14 +08:00
|
|
|
|
obj.transform.localScale=Vector3.one;
|
2024-11-14 18:15:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
public void Wound(MonsterData monster)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
if (GameMgr.Instance.ProbaReturn(monster.crit))
|
2024-11-21 18:05:42 +08:00
|
|
|
|
{
|
2024-12-02 18:00:58 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
damageHP =(int)((monster.atk - player.def) * (1 + monster.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_Player_CritDamageNum, damageHP);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
damageHP = monster.atk - player.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_Player_DamageNum, damageHP);
|
2024-11-21 18:05:42 +08:00
|
|
|
|
}
|
2024-11-14 18:15:51 +08:00
|
|
|
|
|
|
|
|
|
if (hp <= 0)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
isDead = true;
|
2024-11-21 18:05:42 +08:00
|
|
|
|
//<2F>ɽ<EFBFBD><C9BD><EFBFBD><EFBFBD>ղֿ<D5B2>
|
|
|
|
|
GameMgr.Instance.isFeijianClose = true;
|
2024-11-14 18:15:51 +08:00
|
|
|
|
UpdateHp(0);
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܿ<EFBFBD>
|
2024-11-15 18:10:36 +08:00
|
|
|
|
EventCenter.Instance.EventTrigger<string>(E_EventType.E_Pool_Register1, "ս<><D5BD>ʧ<EFBFBD><CAA7>");
|
2024-11-28 17:59:14 +08:00
|
|
|
|
//<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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateHp(int hp)
|
|
|
|
|
{
|
|
|
|
|
imgUserHp.sizeDelta = new Vector2(hpWide*hp / player.hp , imgUserHp.sizeDelta.y);
|
2024-11-21 18:05:42 +08:00
|
|
|
|
txtUserHp.text = GameMgr.Instance.SetNumber(hp) + "/" + GameMgr.Instance.SetNumber(player.hp);
|
2024-11-14 18:15:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public void UpdatePanel()
|
|
|
|
|
{
|
2024-11-21 18:05:42 +08:00
|
|
|
|
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
isDead = false;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
player = GameDataMgr.Instance.player;
|
|
|
|
|
hp = player.hp;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
EventCenter.Instance.AddEventListener<MonsterData>(E_EventType.E_Player_Wound, Wound);
|
|
|
|
|
|
2024-11-14 18:15:51 +08:00
|
|
|
|
imgUserHp.sizeDelta = new Vector2(hpWide, imgUserHp.sizeDelta.y);
|
2024-11-21 18:05:42 +08:00
|
|
|
|
txtUserHp.text = GameMgr.Instance.SetNumber(player.hp) + "/" + GameMgr.Instance.SetNumber(player.hp);
|
2024-11-14 18:15:51 +08:00
|
|
|
|
hp=player.hp;
|
2024-11-15 18:10:36 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ <20>ѹ<EFBFBD><D1B9><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>0
|
|
|
|
|
frontTime = Time.time;
|
2024-11-21 18:05:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//ʧ<><CAA7>ҲҪע<D2AA><D7A2><EFBFBD>¼<EFBFBD>
|
|
|
|
|
void OnDisable()
|
|
|
|
|
{
|
|
|
|
|
EventCenter.Instance.Claer(E_EventType.E_Player_Wound);
|
2024-11-14 18:15:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|