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
60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using Base;
|
|
using Data;
|
|
using Item;
|
|
using Managers;
|
|
using UnityEngine;
|
|
|
|
namespace Entity
|
|
{
|
|
public class Monster : LivingEntity
|
|
{
|
|
private WeaponResource weapon;
|
|
|
|
private void OnCollisionStay2D(Collision2D other)
|
|
{
|
|
if (!other.gameObject.CompareTag("Player")) return;
|
|
var playerEntity = other.gameObject.GetComponent<Entity>();
|
|
playerEntity?.OnHit(10);
|
|
}
|
|
|
|
public override void Init(EntityDef entityDefine)
|
|
{
|
|
base.Init(entityDefine);
|
|
var monsterDef = entityDefine as MonsterDef;
|
|
if (monsterDef != null)
|
|
{
|
|
weapon = ItemResourceManager.Instance.GetItem(monsterDef.weapon?.defName) as WeaponResource;
|
|
if (monsterDef.defaultHediff != null)
|
|
{
|
|
foreach (var hediffDef in monsterDef.defaultHediff)
|
|
{
|
|
AddHediff(new Hediff(hediffDef));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void ExecuteMeleeAttack(WeaponResource weapon)
|
|
{
|
|
var attackRange = AttributesNow.attackRange;
|
|
var attackTargetCount = AttributesNow.attackTargetCount;
|
|
|
|
var hits = EntityManager.FindEntity<LivingEntity>(Position, attackRange);
|
|
|
|
foreach (var hit in hits)
|
|
{
|
|
if (attackTargetCount <= 0) break; // 已达到最大攻击目标数
|
|
if (hit.gameObject == gameObject) continue; // 不攻击自己
|
|
var relation = AffiliationManager.Instance.GetRelation(affiliation, hit.affiliation);
|
|
if (!Setting.Instance.CurrentSettings.friendlyFire && relation != Relation.Hostile) continue;
|
|
hit.OnHit(this);
|
|
attackTargetCount--;
|
|
}
|
|
}
|
|
|
|
public override WeaponResource GetCurrentWeapon()
|
|
{
|
|
return weapon;
|
|
}
|
|
}
|
|
} |