备份CatanBuilding瘦身独立工程
This commit is contained in:
255
Assets/Scripts/SandDig/GameBroadLogic_Event.cs
Normal file
255
Assets/Scripts/SandDig/GameBroadLogic_Event.cs
Normal file
@@ -0,0 +1,255 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using Script.RuntimeScript.GameLogic;
|
||||
using Script.RuntimeScript.model.Data;
|
||||
using System.Collections.Generic;
|
||||
using UniRx;
|
||||
namespace Script.RuntimeScript
|
||||
{
|
||||
public partial class GameBroadLogic
|
||||
{
|
||||
private CompositeDisposable _disposable = null;
|
||||
|
||||
public void AddEvent()
|
||||
{
|
||||
if (_disposable == null)
|
||||
{
|
||||
_disposable = new CompositeDisposable();
|
||||
GContext.OnEvent<EventGridClick>().Subscribe(OnClickGrid).AddTo(_disposable);
|
||||
GContext.OnEvent<GridPropEffectOver>().Subscribe(OnGridPropEffectOver).AddTo(_disposable);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearEvent()
|
||||
{
|
||||
_disposable?.Dispose();
|
||||
_disposable = null;
|
||||
}
|
||||
|
||||
#region 点击grid
|
||||
|
||||
private void OnClickGrid(EventGridClick param)
|
||||
{
|
||||
GridData gridData = param.Data;
|
||||
DiggingGameManager diggingGameManager = GContext.container.Resolve<DiggingGameManager>();
|
||||
if (gridData.ConfigData != null)
|
||||
{
|
||||
int level = diggingGameManager.GetCurLevel();
|
||||
int clickCount = diggingGameManager.DataModel.GetClickCount();
|
||||
bool boo = false;
|
||||
if (gridData.ConfigData.Config.DiggingType is Normal)
|
||||
{
|
||||
boo = CheckPropOpen(gridData);
|
||||
if (boo)
|
||||
diggingGameManager.SandDigPoint(GridType.Normal, level, clickCount);
|
||||
else
|
||||
diggingGameManager.SandDigPoint(GridType.None, level, clickCount);
|
||||
}
|
||||
else if (gridData.ConfigData.Config.DiggingType is Resource)
|
||||
{
|
||||
boo = CheckResoucePropOpen(gridData);
|
||||
if (boo)
|
||||
diggingGameManager.SandDigPoint(GridType.Resource, level, clickCount);
|
||||
else
|
||||
diggingGameManager.SandDigPoint(GridType.None, level, clickCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
boo = CheckSpecialEventOpen(gridData);
|
||||
if (boo)
|
||||
diggingGameManager.SandDigPoint(GridType.Special, level, clickCount);
|
||||
else
|
||||
diggingGameManager.SandDigPoint(GridType.None, level, clickCount);
|
||||
}
|
||||
if (!param.PassiveClick)
|
||||
{
|
||||
if (boo)
|
||||
{
|
||||
diggingGameManager.ShowDigEffect(ClickDigType.Big, gridData.LocalPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
diggingGameManager.ShowDigEffect(ClickDigType.Smail, gridData.LocalPos);
|
||||
}
|
||||
}
|
||||
param.IsBigDig = boo;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!param.PassiveClick)
|
||||
{
|
||||
diggingGameManager.ShowDigEffect(ClickDigType.Smail, gridData.LocalPos);
|
||||
}
|
||||
}
|
||||
|
||||
diggingGameManager.DataModel.SaveAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查道具开启
|
||||
/// </summary>
|
||||
private bool CheckPropOpen(GridData gridData)
|
||||
{
|
||||
bool isCheckPass = false;
|
||||
for (int i = 0; i < _allGridProps.Count; i++)
|
||||
{
|
||||
if (!_allGridProps[i].Data.AlreadyOpen && _allGridProps[i].Data.IsCanOpen() && _allGridProps[i].Data.Config.DiggingType is Normal)
|
||||
{
|
||||
GContext.container.Resolve<DiggingGameManager>().DataModel.AddProp(_allGridProps[i].Data.PropId);
|
||||
PropData targetProp = UpdatePropState(_allGridProps[i].Data.PropId);
|
||||
isCheckPass = true;
|
||||
PropItem item = GetPropItemById(targetProp);
|
||||
if (item == null)
|
||||
{
|
||||
DiggingGameManager.LogError($"挖出的道具id:{_allGridProps[i].Data.PropId},上面的任务栏没有相应的道具槽位 ,检查去吧!");
|
||||
}
|
||||
else
|
||||
{
|
||||
_allGridProps[i].Data.SetTargetPropItem(item);
|
||||
GContext.container.Resolve<DiggingGameManager>().GameState = SandDigGameState.PropEffect;
|
||||
AddToEffectList(_allGridProps[i]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (isCheckPass)
|
||||
{
|
||||
CheckClampPass();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新 新获得的道具状态
|
||||
/// </summary>
|
||||
/// <param name="propId"></param>
|
||||
private PropData UpdatePropState(int propId)
|
||||
{
|
||||
PropData[] allData = GContext.container.Resolve<DiggingGameManager>().DataModel.GetAllPropData();
|
||||
PropData propData;
|
||||
for (int i = 0; i < allData.Length; i++)
|
||||
{
|
||||
propData = allData[i];
|
||||
if (propData.IsOk == false && propData.PropId == propId)
|
||||
{
|
||||
propData.IsOk = true;
|
||||
return propData;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool CheckResoucePropOpen(GridData gridData)
|
||||
{
|
||||
for (int i = 0; i < _allGridProps.Count; i++)
|
||||
{
|
||||
if (!_allGridProps[i].Data.AlreadyOpen && _allGridProps[i].Data.IsCanOpen() && _allGridProps[i].Data.Config.DiggingType is Resource)
|
||||
{
|
||||
AddToEffectList(_allGridProps[i]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private bool CheckSpecialEventOpen(GridData gridData)
|
||||
{
|
||||
for (int i = 0; i < _allSpecialGridProps.Count; i++)
|
||||
{
|
||||
if (!_allSpecialGridProps[i].Data.AlreadyOpen && _allSpecialGridProps[i].Data.IsCanOpen())
|
||||
{
|
||||
_allSpecialGridProps[i].ShowSandpit();
|
||||
AddToEffectList(_allSpecialGridProps[i]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private PropItem GetPropItemById(PropData propData)
|
||||
{
|
||||
for (int i = 0; i < _allProps.Count; i++)
|
||||
{
|
||||
if (_allProps[i].Data == propData)
|
||||
{
|
||||
return _allProps[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 开启道具,且道具动画播放完毕
|
||||
|
||||
private void OnGridPropEffectOver(GridPropEffectOver param)
|
||||
{
|
||||
int propId = param.propId;
|
||||
DiggingGameManager.LogWarning("道具动画播放完毕:propId::" + propId);
|
||||
|
||||
|
||||
//格子内道具 飞到目标后,自己消失 加载新的模型
|
||||
//ShowProp(propId); 如何这个执行 需要检查 propData.IsOk = true 的逻辑
|
||||
//if (param.isNormal)
|
||||
//{
|
||||
this._broadState = BroadEffectState.OverCheck;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// this._broadState = BroadEffectState.Check;
|
||||
//}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 检查是否通关
|
||||
|
||||
private async void CheckClampPass()
|
||||
{
|
||||
bool allFinded = true;
|
||||
for (int i = 0; i < _allProps.Count; i++)
|
||||
{
|
||||
if (!_allProps[i].Data.IsOk)
|
||||
{
|
||||
allFinded = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allFinded)
|
||||
{
|
||||
DiggingGameManager.LogError("恭喜你 通关了!");
|
||||
GContext.container.Resolve<DiggingGameManager>().DataModel.PassClamp();
|
||||
await System.Threading.Tasks.Task.Delay(SandDigEventConst.BigShovelEffectTime);
|
||||
//爆炸所有剩余棋子
|
||||
List<GridItem> allRemainingGrids = new List<GridItem>();
|
||||
for (int i = 0; i < _allGrids.Count; i++)
|
||||
{
|
||||
if (_allGrids[i].Data.IsBorder == false && _allGrids[i].Data.IsOpen == false)
|
||||
{
|
||||
allRemainingGrids.Add(_allGrids[i]);
|
||||
}
|
||||
}
|
||||
int MaxCount = 20;
|
||||
//间隔时间
|
||||
int intervalTime = 100;
|
||||
|
||||
int allRemainingCount = allRemainingGrids.Count;
|
||||
if (allRemainingCount > MaxCount)
|
||||
{
|
||||
int count = allRemainingCount / MaxCount;
|
||||
intervalTime /= (count + 1);
|
||||
}
|
||||
for (int i = 0; i < allRemainingCount; i++)
|
||||
{
|
||||
allRemainingGrids[i].PlayPassClampEffect();
|
||||
await System.Threading.Tasks.Task.Delay(intervalTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user