【战斗】增加建筑 地雷

main
刘涛 2024-09-10 13:10:31 +08:00
parent 177c44ae88
commit 804c2c22f8
7 changed files with 148 additions and 2 deletions

View File

@ -1,11 +1,32 @@
namespace Gameplay.Building.Impl
using Gameplay.Building.Impl.Common;
using Gameplay.Building.Impl.Mine;
using UnityEngine;
namespace Gameplay.Building.Impl
{
public class BuildMine : UnitBuild
{
public int bulletId;
public BuildMine(uint id,
int troopId) : base(id, troopId)
{
}
protected override void _InitFsm()
{
base._InitFsm();
_fsm.Add(new MineStateIdle(this));
_fsm.Add(new CommonBuildStateDestroy(this));
_fsm.Add(new CommonBuildStateWaitRemove(this));
}
protected override void _AfterInitConfig()
{
base._AfterInitConfig();
bulletId = Mathf.RoundToInt(configData.rawConfig.FloatParams[0]);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 050ab9f3c6274bb2b40b341699ae3f03
timeCreated: 1725944578

View File

@ -0,0 +1,27 @@
using LTGame;
namespace Gameplay.Building.Impl.Mine
{
public class BaseMineState : NBaseState
{
public BuildMine owner;
public BaseMineState(BuildMine owner,
int stateId) : base(stateId)
{
this.owner = owner;
}
protected override void _OnEnter(NBaseState exitState,
object param)
{
}
protected override void _OnRunning()
{
}
protected override void _OnExit(NBaseState exitState,
object param)
{
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a3a44f0e1e324ea48817b9b889987439
timeCreated: 1725944585

View File

@ -0,0 +1,89 @@
using System.Collections.Generic;
using Gameplay.Area;
using Gameplay.Building.Impl.Common;
using Gameplay.Bullet;
using Gameplay.Unit;
using Gameplay.Unit.Data;
using LTGame;
namespace Gameplay.Building.Impl.Mine
{
public class MineStateIdle : BaseMineState
{
public MineStateIdle(BuildMine owner) : base(owner, EBuildState.Idle)
{
}
protected override void _OnRunning()
{
base._OnRunning();
if ( owner.statusData.canBeAttack && owner.aliveData.currentHp <= 0)
{
isFinished = true;
nextState = EBuildState.Destroy;
return;
}
var hasUnit = _CheckEnterUnits();
if (hasUnit)
{
isFinished = true;
nextState = EBuildState.Destroy;
return;
}
}
protected override void _OnExit(NBaseState exitState,
object param)
{
base._OnExit(exitState, param);
_EmitBulletToCell();
}
private void _EmitBulletToCell()
{
var bulletId = owner.bulletId;
var cellIndex = owner.transData.cellIndex;
BulletManager.instance.EmitBullet(bulletId, cellIndex, owner);
}
private bool _CheckEnterUnits()
{
var allUnits = AreaManager.instance.GetUnitsByCellIndex(owner.transData.cellIndex);
for (int i = 0; i < allUnits.Count; i++)
{
var unit = allUnits[i];
if (unit == null)
{
continue;
}
if (!(unit.gameunitType == EGameUnitType.Character
|| unit.gameunitType == EGameUnitType.Vehicle
|| unit.gameunitType == EGameUnitType.BeProtect))
{
continue;
}
// 只检测敌人
if (owner.commonData.troopId == unit.commonData.troopId)
{
continue;
}
if (!unit.statusData.CheckCanAttack())
{
continue;
}
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8e1aa621c3e14c6c84f1a258702545b4
timeCreated: 1725944628

View File

@ -120,7 +120,7 @@ namespace Gameplay.Level
{
DebugUtil.LogError("临时创建建筑");
var tempCellIndex = 37;
var tempBuildId = 1003;
var tempBuildId = 1004;
var teamId = ETroopsId.Enemy1;
var createUnit = await GameUnitManager.instance.PrepareBuild(tempBuildId, teamId);
if (createUnit == null)