339 lines
15 KiB
C#
339 lines
15 KiB
C#
using System.Collections.Generic;
|
||
using asap.core;
|
||
using cfg;
|
||
using Script.RuntimeScript.GameLogic;
|
||
using Script.RuntimeScript.model.Data;
|
||
using UnityEngine;
|
||
|
||
namespace Script.RuntimeScript
|
||
{
|
||
public partial class GameBroadLogic
|
||
{
|
||
private List<BroadItem> _allBroads = new List<BroadItem>();
|
||
private List<GridItem> _allGrids = new List<GridItem>();
|
||
private List<PropItem> _allProps = new List<PropItem>();
|
||
private List<GridPropItem> _allGridProps = new List<GridPropItem>();
|
||
private List<SpecialEventItem> _allSpecialGridProps = new List<SpecialEventItem>();
|
||
/// <summary>
|
||
/// 已经加载完成的 grid数量
|
||
/// </summary>
|
||
private int _gridLoadedCount = 0;
|
||
|
||
public void InitEvent()
|
||
{
|
||
AddEvent();
|
||
}
|
||
|
||
public void Reset()
|
||
{
|
||
DiggingGameManager.LogError("管卡重置!!!!!!!!");
|
||
ClearEffect();
|
||
|
||
_allBroads.ForEach(item => { if (item != null) GameObject.Destroy(item.gameObject); });
|
||
_allGrids.ForEach(item => { if (item != null) GameObject.Destroy(item.gameObject); });
|
||
_allProps.ForEach(item => { if (item != null) GameObject.Destroy(item.gameObject); });
|
||
_allGridProps.ForEach(item => { if (item != null) GameObject.Destroy(item.gameObject); });
|
||
_allSpecialGridProps.ForEach(item => { if (item != null) GameObject.Destroy(item.gameObject); });
|
||
|
||
_allBroads.Clear();
|
||
_allGrids.Clear();
|
||
_allProps.Clear();
|
||
_allGridProps.Clear();
|
||
_allSpecialGridProps.Clear();
|
||
|
||
GContext.container.Resolve<DiggingGameManager>().ClearPropContianer();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 构建棋盘背景
|
||
/// </summary>
|
||
public void BuildBroadBack()
|
||
{
|
||
BroadData[] allData = GContext.container.Resolve<DiggingGameManager>().DataModel.GetAllBroadData();
|
||
Dictionary<int, DiggingCheckerBoardList> DiggingCheckerBoardList = GContext.container.Resolve<Tables>().TbDiggingCheckerBoardList.DataMap;
|
||
string ResourceTopic = GContext.container.Resolve<DiggingGameManager>().DataModel.ResourceTopic;
|
||
foreach (var data in allData)
|
||
{
|
||
DiggingCheckerBoardList boardList = DiggingCheckerBoardList.GetValueOrDefault(data.ID);
|
||
LoadAndInstantiateBroad(ResourceTopic + boardList.GenericName, data);
|
||
}
|
||
GContext.container.Resolve<DiggingGameManager>().DgSandBox();
|
||
}
|
||
/// <summary>
|
||
/// 构建棋子
|
||
/// </summary>
|
||
public void BuildGrid()
|
||
{
|
||
List<GridPropData> allGridPropData = new List<GridPropData>();
|
||
List<GridPropData> allSpecialPropData = new List<GridPropData>();
|
||
|
||
GridData[] allData = GContext.container.Resolve<DiggingGameManager>().DataModel.GetAllGridData();
|
||
Dictionary<int, DiggingCheckerBoardList> DiggingCheckerBoardList = GContext.container.Resolve<Tables>().TbDiggingCheckerBoardList.DataMap;
|
||
string ResourceTopic = GContext.container.Resolve<DiggingGameManager>().DataModel.ResourceTopic;
|
||
_gridLoadedCount = 0;
|
||
//棋子显示
|
||
for (int i = 0; i < allData.Length; i++)
|
||
{
|
||
GridData data = allData[i];
|
||
//string address = DiggingGameManager.GetUrl(UrlType.Grid, data.ResName);
|
||
|
||
// 道具
|
||
GridPropData gridData = data.ConfigData;
|
||
if (gridData != null && data.PropId > 0)
|
||
{
|
||
gridData.Init(data.PropId, data.Row, data.Col);
|
||
|
||
// 普通道具 + 金币
|
||
if (gridData.Config.DiggingType is Normal || gridData.Config.DiggingType is Resource)
|
||
{
|
||
DiggingGameManager.LogError("普通道具:propId::::" + gridData.PropId + " row::" + data.Row + " col::" + data.Col);
|
||
allGridPropData.Add(gridData);
|
||
}
|
||
else // 特殊事件
|
||
{
|
||
DiggingGameManager.LogError("特殊事件:propId::::" + gridData.PropId + " row::" + data.Row + " col::" + data.Col);
|
||
allSpecialPropData.Add(gridData);
|
||
}
|
||
gridData.ParentGird = GetGridItemByRowAndCol(data.Row, data.Col);
|
||
}
|
||
DiggingCheckerBoardList boardList = DiggingCheckerBoardList.GetValueOrDefault(data.ID);
|
||
LoadAndInstantiateGrid(ResourceTopic + boardList.GenericName, data);
|
||
}
|
||
|
||
|
||
//格子下面道具显示
|
||
for (int i = 0; i < allGridPropData.Count; i++)
|
||
{
|
||
GridPropData gridData = allGridPropData[i];
|
||
//string address = DiggingGameManager.GetUrl(UrlType.GridProp, gridData.Config.ItemGridResource);
|
||
// 格子下道具绑定格子
|
||
CheckPropNeedGridData(gridData);
|
||
LoadAndInstantiateGridProp(ResourceTopic + gridData.Config.ItemGridResource, gridData);
|
||
}
|
||
|
||
//特殊事件显示
|
||
for (int i = 0; i < allSpecialPropData.Count; i++)
|
||
{
|
||
GridPropData spData = allSpecialPropData[i];
|
||
//string address = DiggingGameManager.GetUrl(UrlType.SpecialEvent, spData.Config.ItemGridResource);
|
||
//当前格子记录道具数据
|
||
spData.ParentGird.ConfigData = spData;
|
||
spData.AddGrid(spData.ParentGird);
|
||
|
||
LoadAndInstantiateSpecialEvent(ResourceTopic + spData.Config.ItemGridResource, spData);
|
||
}
|
||
}
|
||
//void ShowAllGridProps()
|
||
//{
|
||
// int gridCount = _allGridProps.Count;
|
||
// for (int i = 0; i < gridCount; i++)
|
||
// {
|
||
// _allGridProps[i].SetShowShadow(true);
|
||
// }
|
||
//}
|
||
private void CheakAllGridPrefabLoaded()
|
||
{
|
||
GridData[] allData = GContext.container.Resolve<DiggingGameManager>().DataModel.GetAllGridData();
|
||
if (_gridLoadedCount == allData.Length)
|
||
{
|
||
//所有grid 加载完毕
|
||
BeginWaveEffect();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 构建模板道具 *** 每一关只有第一次进入管卡才会有数据
|
||
/// </summary>
|
||
public void BuildTempProp()
|
||
{
|
||
List<PropTempData> props = GContext.container.Resolve<DiggingGameManager>().DataModel.GetOnePropTempData();
|
||
if (props == null) return;
|
||
string ResourceTopic = GContext.container.Resolve<DiggingGameManager>().DataModel.ResourceTopic;
|
||
|
||
GridPropData gridData;
|
||
for (int i = 0; i < props.Count; i++)
|
||
{
|
||
PropTempData prop = props[i];
|
||
DiggingGameManager.LogError("随机道具:propId:::" + prop.PropId + " angle:::" + prop.ConfigData.PropDirection + " x::" + prop.x + " y::" + prop.y);
|
||
gridData = prop.ConfigData;
|
||
gridData.Init(prop.PropId, prop.x, prop.y);
|
||
GridData gridScript = GetGridItemByRowAndCol(prop.x, prop.y);
|
||
gridData.ParentGird = gridScript;
|
||
//将随机的道具 绑定到格子上
|
||
GridData modelGridData = GContext.container.Resolve<DiggingGameManager>().DataModel.GetGridData(prop.x, prop.y);
|
||
if (modelGridData == null)
|
||
{
|
||
DiggingGameManager.LogError("数据中不存在 GridData ,位置 x:" + prop.x + " y:" + prop.y);
|
||
}
|
||
else
|
||
{
|
||
modelGridData.PropId = gridData.PropId;
|
||
modelGridData.ConfigData = gridData;
|
||
}
|
||
|
||
UrlType urlType;
|
||
if (gridData.Config.DiggingType is Normal || gridData.Config.DiggingType is Resource)
|
||
{
|
||
urlType = UrlType.GridProp;
|
||
|
||
//格子下道具绑定格子
|
||
CheckPropNeedGridData(gridData);
|
||
}
|
||
else
|
||
{
|
||
urlType = UrlType.SpecialEvent;
|
||
|
||
//当前格子记录道具数据
|
||
gridData.ParentGird.ConfigData = gridData;
|
||
gridData.AddGrid(gridData.ParentGird);
|
||
}
|
||
|
||
//string address = DiggingGameManager.GetUrl(urlType, gridData.Config.ItemGridResource);
|
||
|
||
LoadAndInstantiateTempGridProp(ResourceTopic + gridData.Config.ItemGridResource, gridData, prop, urlType);
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 构建目标道具
|
||
/// </summary>
|
||
public void BuildProp()
|
||
{
|
||
int broadHight = GContext.container.Resolve<DiggingGameManager>().GetBroadHeight();
|
||
//背景宝箱位置处理
|
||
Vector3 taskBoxPosition = GContext.container.Resolve<DiggingGameManager>().DataModel.GetTaskPosPositon();
|
||
Vector3 posCopy = new Vector3(taskBoxPosition.x, taskBoxPosition.y, taskBoxPosition.z);
|
||
DiggingDisplayInit config = GContext.container.Resolve<DiggingGameManager>().TableData.TbDiggingDisplayInit.GetOrDefault(broadHight);
|
||
if (config != null)
|
||
{
|
||
posCopy.y = config.PropContainerY;
|
||
}
|
||
GContext.container.Resolve<DiggingGameManager>().PropContainer.transform.position = posCopy;
|
||
string ResourceTopic = GContext.container.Resolve<DiggingGameManager>().DataModel.ResourceTopic;
|
||
|
||
//先处理 已经获得的数据
|
||
List<int> allHaveProps = GContext.container.Resolve<DiggingGameManager>().DataModel.GetAllPassIds();
|
||
|
||
for (int i = 0; i < allHaveProps.Count; i++)
|
||
{
|
||
ShowProp(allHaveProps[i]);
|
||
}
|
||
|
||
//处理道具
|
||
PropData[] allData = GContext.container.Resolve<DiggingGameManager>().DataModel.GetAllPropData();
|
||
var TbDiggingItemList = GContext.container.Resolve<DiggingGameManager>().TableData.TbDiggingItemList;
|
||
foreach (var data in allData)
|
||
{
|
||
var item = TbDiggingItemList.Get(data.PropId);
|
||
//string address = DiggingGameManager.GetUrl(UrlType.Prop, data.ResName);
|
||
LoadAndInstantiateTaskProp(ResourceTopic + item.ItemBoxResource, data);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 显示目标道具
|
||
/// </summary>
|
||
/// <param name="propId"></param>
|
||
private void ShowProp(int propId)
|
||
{
|
||
DiggingGameManager.LogError("完成目标道具::" + propId);
|
||
|
||
PropData[] allData = GContext.container.Resolve<DiggingGameManager>().DataModel.GetAllPropData();
|
||
string ResourceTopic = GContext.container.Resolve<DiggingGameManager>().DataModel.ResourceTopic;
|
||
|
||
PropData propData;
|
||
for (int i = 0; i < allData.Length; i++)
|
||
{
|
||
propData = allData[i];
|
||
if (propData.IsOk == false && propData.PropId == propId)
|
||
{
|
||
propData.IsOk = true;
|
||
DiggingItemList propConfig = GContext.container.Resolve<DiggingGameManager>().TableData.TbDiggingItemList.Get(propId);
|
||
|
||
//string address = DiggingGameManager.GetUrl(UrlType.GridProp, propConfig.ItemGridResource); //完成的道具 加载的Grid 道具中的资源!
|
||
LoadAndInstantiateGetedTaskProp(ResourceTopic + propConfig.ItemGridResource, propData, propConfig.ItemFxScale);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
public GridData GetGridItemByRowAndCol(int row, int col)
|
||
{
|
||
|
||
GridData[] allData = GContext.container.Resolve<DiggingGameManager>().DataModel.GetAllGridData();
|
||
|
||
for (int i = 0; i < allData.Length; i++)
|
||
{
|
||
if (allData[i].Row == row && allData[i].Col == col)
|
||
{
|
||
return allData[i];
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 格子下道具绑定格子
|
||
/// </summary>
|
||
public void CheckPropNeedGridData(GridPropData data)
|
||
{
|
||
int rows = data.TempArr.GetLength(0);
|
||
int cols = data.TempArr.GetLength(1);
|
||
|
||
|
||
// 起始
|
||
Vector3 startPoint = new Vector3(data.ParentGird.Row, data.ParentGird.Col, 0);
|
||
for (int i = 0; i < rows; i++)
|
||
{
|
||
for (int j = 0; j < cols; j++)
|
||
{
|
||
int value = data.TempArr[i, j];
|
||
if (value > 0)
|
||
{
|
||
// 初始位置
|
||
Vector3 positionB = new Vector3(j, i, 0); //空间转换
|
||
// DiggingGameManager.LogError($"positionB::row:: {i}" + " col::" + j + " data.PropDirection::" + data.PropDirection);
|
||
Vector3 endPosition = startPoint + GetRotatePoint(data.PropDirection, Vector3.zero, positionB);
|
||
// DiggingGameManager.LogError($"获取Grid::{endPosition.x}" + " col::" + endPosition.y);
|
||
GridData grid = GetGridItemByRowAndCol((int)Mathf.Round(endPosition.x), (int)Mathf.Round(endPosition.y));
|
||
if (grid != null)
|
||
{
|
||
// DiggingGameManager.LogError("PropId:::" + data.PropId + " x::" + grid.Data.Row + " y::" + grid.Data.Col);
|
||
//当前格子记录道具数据
|
||
grid.ConfigData = data;
|
||
data.AddGrid(grid);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取旋转后道具的位置
|
||
/// </summary>
|
||
/// <param name="angles"></param>
|
||
/// <param name="positionA"></param>
|
||
/// <param name="positionB"></param>
|
||
/// <returns></returns>
|
||
private Vector3 GetRotatePoint(int angles, Vector3 positionA, Vector3 positionB)
|
||
{
|
||
return RotatePointAroundPivot(positionB, positionA, new Vector3(0, 0, -angles));
|
||
}
|
||
|
||
private Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles)
|
||
{
|
||
Vector3 dir = point - pivot; // 获取点到枢轴的向量
|
||
dir = Quaternion.Euler(angles) * dir; // 旋转向量
|
||
point = dir + pivot; // 将点移动回枢轴
|
||
return point;
|
||
}
|
||
|
||
public List<GridItem> GetAllGrids()
|
||
{
|
||
return _allGrids;
|
||
}
|
||
}
|
||
} |