mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 04:07:13 +08:00
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/60
76 lines
2.2 KiB
C#
76 lines
2.2 KiB
C#
using Base;
|
|
using Data;
|
|
using Managers;
|
|
using Prefab;
|
|
using UnityEngine;
|
|
using Utils;
|
|
|
|
namespace Entity
|
|
{
|
|
public class Bullet : Entity
|
|
{
|
|
public float lifeTime = 10;
|
|
|
|
private BulletDef bulletDef;
|
|
public Entity bulletSource { get; private set; }
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
var entity = other.GetComponent<EntityPrefab>()?.entity;
|
|
if (!entity)
|
|
{
|
|
Kill();
|
|
return;
|
|
}
|
|
|
|
if (IsDead || entity == bulletSource || entity is not CombatantEntity) return;
|
|
|
|
if (AffiliationManager.Instance.GetRelation(bulletSource.affiliation, entity.affiliation) !=
|
|
Relation.Friendly || Setting.Instance.CurrentSettings.friendlyFire)
|
|
{
|
|
entity.OnHit(bulletSource);
|
|
bulletSource.OnDealHit(entity);
|
|
if (bulletDef?.hitHediffs != null && entity is LivingEntity livingEntity)
|
|
foreach (var hediff in bulletDef.hitHediffs)
|
|
livingEntity.AddHediff(new Hediff(hediff));
|
|
}
|
|
else
|
|
{
|
|
return; // 如果是友好关系且不允许友军伤害,则不处理
|
|
}
|
|
|
|
OnHit(1, false);
|
|
}
|
|
|
|
public override void Init(EntityDef entityDefine)
|
|
{
|
|
base.Init(entityDefine);
|
|
bulletDef = entityDefine as BulletDef;
|
|
}
|
|
|
|
|
|
public void SetBulletSource(Entity source)
|
|
{
|
|
bulletSource = source;
|
|
AttributesNow.attack = source.AttributesNow.attack;
|
|
var weapon = source.GetCurrentWeapon();
|
|
if (weapon != null) lifeTime = weapon.Attributes.attackRange / AttributesNow.moveSpeed;
|
|
|
|
affiliation = source.affiliation;
|
|
}
|
|
|
|
public override bool SetTarget(Vector3 pos)
|
|
{
|
|
base.SetTarget(pos);
|
|
RotateTool.RotateTransformToDirection(transform, Direction);
|
|
return true;
|
|
}
|
|
|
|
protected override void AutoBehave()
|
|
{
|
|
Move();
|
|
lifeTime -= Time.deltaTime;
|
|
if (lifeTime <= 0) Kill();
|
|
}
|
|
}
|
|
} |