101 lines
3.7 KiB
C#
101 lines
3.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using asap.core;
|
|
using cfg;
|
|
using Game;
|
|
using Script.RuntimeScript.GameLogic;
|
|
using UnityEngine;
|
|
|
|
namespace Script.RuntimeScript.ExplosionEffect.Effect
|
|
{
|
|
public class BombExplosion : IExplosion
|
|
{
|
|
private SpecialEventItem _target;
|
|
public void Play(SpecialEventItem item)
|
|
{
|
|
_target = item;
|
|
|
|
GContext.container.Resolve<DiggingGameManager>().BaseMono.StartCoroutine(PlayCoroutine());
|
|
}
|
|
|
|
private IEnumerator PlayCoroutine()
|
|
{
|
|
List<List<GridItem>> targetGridsLayer = GetBombGrids(_target);
|
|
int allCount = targetGridsLayer.Where(x => x.Count > 0).Sum(x => x.Count);
|
|
if (allCount > 0)
|
|
{
|
|
GContext.Publish(new EventUISound("audio_ui_sanddig_griddispear"));
|
|
}
|
|
for (int i = 0; i < targetGridsLayer.Count; i++)
|
|
{
|
|
List<GridItem> layer = targetGridsLayer[i];
|
|
for (int j = 0; j < layer.Count; j++)
|
|
{
|
|
layer[j].GridEffectType = GridEffectType.PassiveBomb;
|
|
layer[j].PassiveClick();
|
|
}
|
|
yield return new WaitForSeconds(0.5f);
|
|
}
|
|
DiggingGameManager diggingGameManager = GContext.container.Resolve<DiggingGameManager>();
|
|
var configInit = diggingGameManager.DataModel.digActivityConfig;
|
|
yield return new WaitForSeconds(configInit.BombBlockAniTime);
|
|
GContext.Publish(new GridPropEffectOver(_target.Data.PropId, false));
|
|
}
|
|
|
|
private List<List<GridItem>> GetBombGrids(SpecialEventItem item)
|
|
{
|
|
if (item.Data.Config.DiggingType is BombClear)
|
|
{
|
|
Dictionary<Vector2Int, GridItem> gridDic = new Dictionary<Vector2Int, GridItem>();
|
|
List<GridItem> allGrids = GContext.container.Resolve<DiggingGameManager>().BroadLogic.GetAllGrids();
|
|
for (int i = 0; i < allGrids.Count; i++)
|
|
{
|
|
if (allGrids[i].Data.IsBorder || allGrids[i].Data.IsOpen)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
Vector2Int gridVec = new Vector2Int(allGrids[i].Data.Row, allGrids[i].Data.Col);
|
|
gridDic[gridVec] = allGrids[i];
|
|
}
|
|
|
|
int layers = (item.Data.Config.DiggingType as BombClear).Param;
|
|
Vector2Int cellPos = new Vector2Int(item.Data.ParentGird.Row, item.Data.ParentGird.Col);
|
|
return GetCellsInLayers(cellPos, layers, gridDic);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
private List<List<GridItem>> GetCellsInLayers(Vector2Int center, int layers, Dictionary<Vector2Int, GridItem> gridDic)
|
|
{
|
|
List<List<GridItem>> cellsInLayers = new List<List<GridItem>>();
|
|
|
|
for (int layer = 1; layer <= layers; layer++)
|
|
{
|
|
List<GridItem> currentLayer = new List<GridItem>();
|
|
|
|
for (int x = -layer; x <= layer; x++)
|
|
{
|
|
for (int y = -layer; y <= layer; y++)
|
|
{
|
|
if (Math.Abs(x) == layer || Math.Abs(y) == layer)
|
|
{
|
|
Vector2Int cellPos = new Vector2Int(center.x + x, center.y + y);
|
|
if (gridDic.ContainsKey(cellPos))
|
|
{
|
|
currentLayer.Add(gridDic[cellPos]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
cellsInLayers.Add(currentLayer);
|
|
}
|
|
|
|
return cellsInLayers;
|
|
}
|
|
}
|
|
} |