56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
|
|
public class HpExplosion : Explosion
|
|
{
|
|
[Header("毒气设置")]
|
|
public float radius = 3f; // 毒圈半径
|
|
public float tickInterval = 1f; // 每秒伤害间隔
|
|
public float damagePerTick = 10f; // 每次伤害
|
|
public override void OnSpawn(TeamType team,float curDurationTime,int id)
|
|
{
|
|
base.OnSpawn(team,curDurationTime,id);
|
|
GunInfo info = GameManager.Ins.GunInfos[(GunType)type][1];
|
|
damagePerTick = info.Buff;
|
|
transform.position=new Vector3(transform.position.x,0.1f,transform.position.z);
|
|
transform.eulerAngles=Vector3.zero;
|
|
if (isServer) // 只在服务端计算伤害
|
|
{
|
|
StartCoroutine(DamageRoutine(curDurationTime));
|
|
}
|
|
}
|
|
|
|
[Server]
|
|
private IEnumerator DamageRoutine(float duration)
|
|
{
|
|
float elapsed = 0f;
|
|
while (elapsed < duration)
|
|
{
|
|
elapsed += tickInterval;
|
|
ApplyDamageToPlayers();
|
|
yield return new WaitForSeconds(tickInterval);
|
|
}
|
|
}
|
|
|
|
[Server]
|
|
private void ApplyDamageToPlayers()
|
|
{
|
|
// 假设你有一个所有玩家的列表 GameManager.Ins.AllPlayers
|
|
foreach (var item in NetworkServer.spawned.Values)
|
|
{
|
|
Player player = item.GetComponent<Player>();
|
|
if (player == null|| player.teamType!= curTeam) continue;
|
|
|
|
// 计算玩家与回复圈中心的距离
|
|
float dist = Vector3.Distance(transform.position, player.transform.position);
|
|
if (dist <= radius)
|
|
{
|
|
GameManager.Ins.RpcShowDamageNumber(-damagePerTick,player.helmet.position+new Vector3(0,1,0),false);
|
|
player.ApplyDamage(-damagePerTick, playerId, transform);
|
|
}
|
|
}
|
|
}
|
|
}
|