2022-06-08 13:23:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
|
using URandom = UnityEngine.Random;
|
|
|
|
|
|
|
|
|
|
|
|
public class BlockManager : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
[SerializeField] int mBP = 0;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] bool mIsPlayer;
|
|
|
|
|
|
[SerializeField] Transform mCtnSlots;
|
2022-06-08 13:23:44 +00:00
|
|
|
|
[SerializeField] SellSlot mMySellSlot;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
[SerializeField] Renderer mRdrFloor;
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
private List<BlockSlot> mBlocks;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
private BlockSlot mPickedBlock;
|
|
|
|
|
|
private BlockSlot mTouchedBlock;
|
|
|
|
|
|
private SellSlot mTouchedSellSlot;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
|
|
|
|
|
private bool mInteractable;
|
|
|
|
|
|
private bool mIsForbidden = false;
|
|
|
|
|
|
private List<int> mExcludeIndexes;
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
private bool mIsAutoMerge;
|
|
|
|
|
|
private Queue<Vector2Int> mAutoMergeQueue = new Queue<Vector2Int>();
|
2022-05-23 13:39:59 +00:00
|
|
|
|
private string mNewCardID;
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mBlocks = Utils.GetChildListFirstLayer<BlockSlot>(mCtnSlots);
|
|
|
|
|
|
for (int i = 0; i < mBlocks.Count; i++)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (mIsPlayer)
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mBlocks[i].Init(i, OnPickUpSlot, OnMoveSlot, OnDropDownSlot);
|
|
|
|
|
|
mBlocks[i].ShowFloor(true);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mBlocks[i].Init(i);
|
|
|
|
|
|
mBlocks[i].ShowFloor(false);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EnableInteraction(mIsPlayer);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<SoldierUnit> GetAllSoldier()
|
|
|
|
|
|
{
|
|
|
|
|
|
List<SoldierUnit> tSoldierlist = new List<SoldierUnit>();
|
2022-06-08 13:23:44 +00:00
|
|
|
|
for (int i = 0; i < mBlocks.Count; i++)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (mBlocks[i].HasUnit)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-09-09 14:35:49 +00:00
|
|
|
|
tSoldierlist.AddRange(mBlocks[i].MyUnit.AllSoldiers);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tSoldierlist;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void CreateBaseHumanBlock()//only for player
|
|
|
|
|
|
{
|
|
|
|
|
|
CreateBlockAtRandomPos(BlockType.Human);
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
CheckAutoMerge();
|
|
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
AudioManager.Instance.PlaySound(AudioClipType.BuyUnit);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void CreateBaseMonsterBlock()//only for player
|
|
|
|
|
|
{
|
|
|
|
|
|
CreateBlockAtRandomPos(BlockType.Monster);
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
CheckAutoMerge();
|
|
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
AudioManager.Instance.PlaySound(AudioClipType.BuyUnit);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void CreateBlockAtRandomPos(BlockType pBType, int pLevel = 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<int> tEmptyList = new List<int>();
|
2022-06-08 13:23:44 +00:00
|
|
|
|
for (int i = 0; i < mBlocks.Count; i++)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (!mBlocks[i].HasUnit)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
|
|
|
|
|
tEmptyList.Add(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tEmptyList.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
CreateBlock(tEmptyList[URandom.Range(0, tEmptyList.Count)], pBType, pLevel);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void CreateBlocksByData(string pDataStr)//eg:0_0_1;1_1_5
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] tData = pDataStr.Split(';');
|
|
|
|
|
|
|
|
|
|
|
|
int tPosIndex = 0, tBType = 0, tLevel = 1;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < tData.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(tData[i]))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
string[] tNums = tData[i].Split('_');
|
|
|
|
|
|
tPosIndex = int.Parse(tNums[0]);
|
|
|
|
|
|
tBType = int.Parse(tNums[1]);
|
|
|
|
|
|
tLevel = int.Parse(tNums[2]);
|
|
|
|
|
|
|
|
|
|
|
|
CreateBlock(tPosIndex, (BlockType)tBType, tLevel);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public BlockUnit CreateBlock(int pIndex, BlockType pBType, int pLevel)
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (pIndex < 0 || pIndex >= mBlocks.Count)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (mBlocks[pIndex].HasUnit)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-09 14:35:49 +00:00
|
|
|
|
if (GameConfig.Instance.IsFakeMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
pBType = BlockType.Human;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-04 11:17:39 +00:00
|
|
|
|
BlockUnit tNewUnit = Instantiate(ResourceManager.Instance.LoadRes<BlockUnit>(Const.Path.GetBlockUnit(pBType, pLevel, mIsPlayer)));
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mBlocks[pIndex].SetUnit(tNewUnit);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
|
|
|
|
|
mBP += Utils.GetBpByLv(tNewUnit.Level);
|
|
|
|
|
|
RefreshBPUI();
|
|
|
|
|
|
|
|
|
|
|
|
if (mIsPlayer)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (tNewUnit != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DisplayNewUnit(tNewUnit);
|
|
|
|
|
|
VibrateManager.Instance.Vibrate(VibrateType.Medium);
|
|
|
|
|
|
}
|
|
|
|
|
|
SavePlayerArmy();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tNewUnit;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-04 11:17:39 +00:00
|
|
|
|
public void SetAsBoss()
|
|
|
|
|
|
{
|
|
|
|
|
|
BlockUnit tMaxLvUnit = null;
|
|
|
|
|
|
for (int i = 0; i < mBlocks.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mBlocks[i].HasUnit)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mBlocks[i].MyUnit.Level > (tMaxLvUnit == null ? 0 : tMaxLvUnit.Level))
|
|
|
|
|
|
{
|
|
|
|
|
|
tMaxLvUnit = mBlocks[i].MyUnit;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tMaxLvUnit != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
tMaxLvUnit.SetAsBoss();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
public string GetFormationStr()
|
|
|
|
|
|
{
|
|
|
|
|
|
string tDataStr = "";
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < mBlocks.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mBlocks[i].HasUnit)
|
|
|
|
|
|
{
|
|
|
|
|
|
tDataStr += string.Format("{0}_{1}_{2}", i, (int)mBlocks[i].MyUnit.BType, mBlocks[i].MyUnit.Level) + ";";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(tDataStr))
|
|
|
|
|
|
{
|
|
|
|
|
|
tDataStr = tDataStr.Remove(tDataStr.LastIndexOf(';'));//remove last ';'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tDataStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
public void ClearAll()
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
for (int i = 0; i < mBlocks.Count; i++)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (mBlocks[i].HasUnit)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
Destroy(mBlocks[i].MyUnit.gameObject);
|
|
|
|
|
|
mBlocks[i].SetUnit(null);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mIsPlayer)
|
|
|
|
|
|
{
|
|
|
|
|
|
SavePlayerArmy();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mBP = 0;
|
|
|
|
|
|
RefreshBPUI();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
private void MergeBlock(BlockSlot pBlockSrc, BlockSlot pBlockDst)
|
|
|
|
|
|
{
|
|
|
|
|
|
int tOldBP = Utils.GetBpByLv(pBlockSrc.MyUnit.Level) * 2;
|
2022-07-04 11:17:39 +00:00
|
|
|
|
BlockUnit tNewUnit = Instantiate(ResourceManager.Instance.LoadRes<BlockUnit>(Const.Path.GetBlockUnit(pBlockSrc.MyUnit.BType, pBlockSrc.MyUnit.Level + 1, mIsPlayer)));
|
2022-06-08 13:23:44 +00:00
|
|
|
|
Destroy(pBlockDst.MyUnit.gameObject);
|
|
|
|
|
|
Destroy(pBlockSrc.MyUnit.gameObject);
|
|
|
|
|
|
|
|
|
|
|
|
pBlockDst.SetUnit(tNewUnit);
|
|
|
|
|
|
pBlockSrc.SetUnit(null);
|
|
|
|
|
|
|
|
|
|
|
|
mBP += Utils.GetBpByLv(tNewUnit.Level) - tOldBP;
|
|
|
|
|
|
RefreshBPUI();
|
|
|
|
|
|
AudioManager.Instance.PlaySound(AudioClipType.MergeUnit);
|
|
|
|
|
|
|
|
|
|
|
|
if (mIsPlayer)
|
|
|
|
|
|
{
|
2022-07-04 11:17:39 +00:00
|
|
|
|
DisplayNewUnit(tNewUnit, true);
|
2022-06-08 13:23:44 +00:00
|
|
|
|
|
2022-09-09 14:35:49 +00:00
|
|
|
|
string tCardID = Utils.GetUnitID(tNewUnit.BType, tNewUnit.Level, mIsPlayer);
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (!PlayerData.Instance.HasCard(tCardID))
|
|
|
|
|
|
{
|
|
|
|
|
|
mNewCardID = tCardID;
|
|
|
|
|
|
PlayerData.Instance.GetCard(mNewCardID);
|
2022-09-09 14:35:49 +00:00
|
|
|
|
if (!GameConfig.Instance.IsFakeMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
TimerManager.Instance.Schedule(ShowNewCard, PlayerData.Instance.CurrentLevel == 1 ? -1 : 0.3f);
|
|
|
|
|
|
}
|
2022-06-08 13:23:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mNewCardID = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-04 11:17:39 +00:00
|
|
|
|
if (GuideManager.Instance.CurGuideIndex == 0)
|
2022-06-08 13:23:44 +00:00
|
|
|
|
{
|
|
|
|
|
|
GuideManager.Instance.FinishCurrentStep();
|
|
|
|
|
|
}
|
2022-07-04 11:17:39 +00:00
|
|
|
|
|
|
|
|
|
|
//if (GuideManager.Instance.CurGuideIndex == 2)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// GuideManager.Instance.FinishCurrentStep();
|
|
|
|
|
|
//}
|
2022-06-08 13:23:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SwitchBlock(BlockSlot pBlockA, BlockSlot pBlockB)
|
|
|
|
|
|
{
|
|
|
|
|
|
BlockUnit tTempUnit = pBlockB.MyUnit;
|
2022-09-09 14:35:49 +00:00
|
|
|
|
pBlockB.SetUnit(pBlockA.MyUnit, true);
|
2022-06-08 13:23:44 +00:00
|
|
|
|
pBlockA.SetUnit(tTempUnit);
|
|
|
|
|
|
|
2022-07-04 11:17:39 +00:00
|
|
|
|
//if (GuideManager.Instance.CurGuideIndex == 1)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// GuideManager.Instance.FinishCurrentStep();
|
|
|
|
|
|
//}
|
2022-06-08 13:23:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void RemoveBlock(BlockSlot pBlockA)
|
|
|
|
|
|
{
|
|
|
|
|
|
BlockUnit tUnit = pBlockA.MyUnit;
|
|
|
|
|
|
pBlockA.SetUnit(null);
|
|
|
|
|
|
Destroy(tUnit.gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
public void EnableInteraction(bool pEnabled)
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (!pEnabled && mPickedBlock != null)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
OnDropDownSlot(mPickedBlock.Index);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mInteractable = pEnabled;
|
2022-06-08 13:23:44 +00:00
|
|
|
|
for (int i = 0; i < mBlocks.Count; i++)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (mInteractable)
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mBlocks[i].SetDelegate(OnPickUpSlot, OnMoveSlot, OnDropDownSlot);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mBlocks[i].SetDelegate(null, null, null);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ShowFloor(bool pShow)
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
for (int i = 0; i < mBlocks.Count; i++)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mBlocks[i].ShowFloor(pShow);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mIsPlayer)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mRdrFloor != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
mRdrFloor.material.DOFloat(pShow ? 0 : 1, "_Dissolve", 1f);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mRdrFloor.gameObject.SetActive(pShow);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetForbidden(bool pIsForbidden, List<int> pExcludeIndexes = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
mIsForbidden = pIsForbidden;
|
|
|
|
|
|
mExcludeIndexes = pExcludeIndexes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnPickUpSlot(int pIndex)
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (!mInteractable || mIsAutoMerge)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
VibrateManager.Instance.Vibrate(VibrateType.Light);
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mPickedBlock = mBlocks[pIndex];
|
|
|
|
|
|
mPickedBlock.SetState(IsSlotForbidden(pIndex) ? BlockState.Forbidden : BlockState.Picked);
|
|
|
|
|
|
|
|
|
|
|
|
if (PlayerData.Instance.IsAutoMergeEnabled && mPickedBlock.MyUnit != null && mMySellSlot != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
int tSellPrice = PlayerData.Instance.CurrentSellBase * Mathf.RoundToInt(Mathf.Pow(2, mPickedBlock.MyUnit.Level - 1));
|
|
|
|
|
|
mMySellSlot.SetSellPrice(tSellPrice);
|
|
|
|
|
|
mMySellSlot.Show(true);
|
|
|
|
|
|
}
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnMoveSlot(int pIndex)
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (!mInteractable || mIsAutoMerge)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (mPickedBlock == null || mPickedBlock.MyUnit == null || IsSlotForbidden(pIndex))
|
2022-05-23 13:39:59 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
RaycastHit[] tHits = Physics.RaycastAll(Camera.main.ScreenPointToRay(Input.mousePosition), 100, Const.Layer.OpLayer);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mTouchedSellSlot = null;
|
|
|
|
|
|
BlockSlot tHitBlock = null;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
GameObject tGround = null;
|
|
|
|
|
|
RaycastHit tGroundHit = new RaycastHit();
|
|
|
|
|
|
for (int i = 0; i < tHits.Length; i++)
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (tHitBlock == null && tHits[i].collider.gameObject.layer == Const.Layer.BlockSlot)
|
|
|
|
|
|
{
|
|
|
|
|
|
tHitBlock = tHits[i].collider.gameObject.GetComponent<BlockSlot>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tHits[i].collider.gameObject.layer == Const.Layer.SellSlot)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mTouchedSellSlot = tHits[i].collider.gameObject.GetComponent<SellSlot>();
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tHits[i].collider.gameObject.layer == Const.Layer.Ground)
|
|
|
|
|
|
{
|
|
|
|
|
|
tGround = tHits[i].collider.gameObject;
|
|
|
|
|
|
tGroundHit = tHits[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (mTouchedBlock != null && mTouchedBlock != tHitBlock)//reset last touched
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mTouchedBlock.SetState(BlockState.Normal);
|
|
|
|
|
|
mTouchedBlock = null;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
VibrateManager.Instance.Vibrate(VibrateType.Light);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (tHitBlock != null && tHitBlock != mPickedBlock)//if hit new slot,set new touched
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mTouchedBlock = tHitBlock;
|
|
|
|
|
|
if (!IsSlotForbidden(mTouchedBlock.Index))
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (mTouchedBlock.MyUnit != null && mPickedBlock.MyUnit != null && mTouchedBlock.MyUnit.IsMergable(mPickedBlock.MyUnit))
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mTouchedBlock.SetState(BlockState.Mergable);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mTouchedBlock.SetState(BlockState.Movable);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mTouchedBlock.SetState(BlockState.Forbidden);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (mMySellSlot != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
mMySellSlot.SetTouched(mTouchedSellSlot == mMySellSlot);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
if (tGround != null)
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mPickedBlock.MyUnit.transform.position = tGroundHit.point + Vector3.up * 2;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnDropDownSlot(int pIndex)
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (!mInteractable || mIsAutoMerge)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
VibrateManager.Instance.Vibrate(VibrateType.Light);
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (mPickedBlock == null || mPickedBlock.MyUnit == null || IsSlotForbidden(pIndex))
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mPickedBlock?.SetState(BlockState.Normal);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (mMySellSlot != null && mTouchedSellSlot == mMySellSlot)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
BlockSlot tSellBlock = mPickedBlock;
|
|
|
|
|
|
mPickedBlock = null;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
2022-09-09 14:35:49 +00:00
|
|
|
|
if (tSellBlock.MyUnit.Level < TKGSDKManager.Instance.GetConfigInt(TKGParamKey.SellWarningLevel))
|
2022-06-08 13:23:44 +00:00
|
|
|
|
{
|
|
|
|
|
|
RemoveBlock(tSellBlock);
|
|
|
|
|
|
mMySellSlot.Sell();
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
tSellBlock.SetState(BlockState.Normal);
|
|
|
|
|
|
mMySellSlot.SetSellPrice(0);
|
|
|
|
|
|
mMySellSlot.Show(false);
|
|
|
|
|
|
SavePlayerArmy();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
PanelDialog tUIDialog = UIManager.Instance.OpenUI<PanelDialog>();
|
|
|
|
|
|
tUIDialog.Init(LanguageConfig.Instance.GetText("Caution"), string.Format(LanguageConfig.Instance.GetText("SellUnit"), UIUtils.NumForShort(mMySellSlot.CurPrice), tSellBlock.MyUnit.Level),
|
|
|
|
|
|
() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
RemoveBlock(tSellBlock);
|
|
|
|
|
|
mMySellSlot.Sell();
|
|
|
|
|
|
|
|
|
|
|
|
tSellBlock.SetState(BlockState.Normal);
|
|
|
|
|
|
mMySellSlot.SetSellPrice(0);
|
|
|
|
|
|
mMySellSlot.Show(false);
|
|
|
|
|
|
SavePlayerArmy();
|
|
|
|
|
|
},
|
|
|
|
|
|
() =>
|
|
|
|
|
|
{
|
2022-09-09 14:35:49 +00:00
|
|
|
|
tSellBlock.SetUnit(tSellBlock.MyUnit, true);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
tSellBlock.SetState(BlockState.Normal);
|
|
|
|
|
|
mMySellSlot.SetSellPrice(0);
|
|
|
|
|
|
mMySellSlot.Show(false);
|
|
|
|
|
|
SavePlayerArmy();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mTouchedBlock != null && mTouchedBlock != mPickedBlock)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!IsSlotForbidden(mTouchedBlock.Index))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mTouchedBlock.MyUnit != null && mPickedBlock.MyUnit != null && mTouchedBlock.MyUnit.IsMergable(mPickedBlock.MyUnit))
|
|
|
|
|
|
{
|
|
|
|
|
|
MergeBlock(mPickedBlock, mTouchedBlock);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
SwitchBlock(mPickedBlock, mTouchedBlock);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-09-09 14:35:49 +00:00
|
|
|
|
mPickedBlock.SetUnit(mPickedBlock.MyUnit, true);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
2022-06-08 13:23:44 +00:00
|
|
|
|
|
|
|
|
|
|
mTouchedBlock.SetState(BlockState.Normal);
|
|
|
|
|
|
mTouchedBlock = null;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-09-09 14:35:49 +00:00
|
|
|
|
mPickedBlock.SetUnit(mPickedBlock.MyUnit, true);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
if (PlayerData.Instance.IsAutoMergeEnabled && mMySellSlot != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
mMySellSlot.SetSellPrice(0);
|
|
|
|
|
|
mMySellSlot.Show(false);
|
|
|
|
|
|
}
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
mPickedBlock.SetState(BlockState.Normal);
|
|
|
|
|
|
mPickedBlock = null;
|
|
|
|
|
|
|
|
|
|
|
|
SavePlayerArmy();
|
|
|
|
|
|
}
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool IsSlotForbidden(int pIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
return mIsForbidden && (mExcludeIndexes == null || !mExcludeIndexes.Contains(pIndex));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-04 11:17:39 +00:00
|
|
|
|
private void DisplayNewUnit(BlockUnit pUnit, bool pIsMerge = false)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-10-09 09:30:50 +00:00
|
|
|
|
//int tMergeFxID = pIsMerge ? PlayerData.Instance.CurrentPetID : -1;
|
2022-09-09 14:35:49 +00:00
|
|
|
|
GameObject tFx = ResourceManager.Instance.LoadRes<GameObject>(Const.Path.GetMergeFxByLevel(pUnit.Level));
|
2022-07-04 11:17:39 +00:00
|
|
|
|
Instantiate(tFx, pUnit.transform.position, Quaternion.identity);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
2022-07-04 11:17:39 +00:00
|
|
|
|
if (pIsMerge)
|
|
|
|
|
|
{
|
|
|
|
|
|
PetManager.Instance.Happy();
|
|
|
|
|
|
}
|
2022-09-09 14:35:49 +00:00
|
|
|
|
|
2022-09-09 15:01:44 +00:00
|
|
|
|
if (!GameConfig.Instance.IsSimpleAni)
|
|
|
|
|
|
{
|
|
|
|
|
|
pUnit.SetTrigger(SoldierACTrigger.TriggerHappy);
|
|
|
|
|
|
}
|
2022-09-09 14:35:49 +00:00
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
pUnit.transform.localScale = Vector3.zero;
|
|
|
|
|
|
pUnit.transform.DOScale(1, 0.5f).SetEase(Ease.OutBounce);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ShowNewCard()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!mIsPlayer)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(mNewCardID))
|
|
|
|
|
|
{
|
|
|
|
|
|
PanelNewCard tUINew = UIManager.Instance.OpenUI<PanelNewCard>();
|
|
|
|
|
|
tUINew.InitCard(mNewCardID);
|
|
|
|
|
|
|
|
|
|
|
|
AudioManager.Instance.PlaySound(AudioClipType.NewCard);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SavePlayerArmy()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!mIsPlayer)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
PlayerData.Instance.ArmyStr = GetFormationStr();
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void RefreshBPUI()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mIsPlayer)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.GetUI<PanelTopBar>().SetPlayerBP(mBP);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.GetUI<PanelTopBar>().SetEnemyBP(mBP);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-06-08 13:23:44 +00:00
|
|
|
|
|
|
|
|
|
|
public void CheckAutoMerge()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!PlayerData.Instance.IsAutoMergeEnabled || PlayerData.Instance.AutoMergeCount <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<string, List<int>> tCheckDic = new Dictionary<string, List<int>>();
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < mBlocks.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mBlocks[i].MyUnit != null && mBlocks[i].MyUnit.Level < GameConfig.Instance.BlockMaxLevel)
|
|
|
|
|
|
{
|
|
|
|
|
|
string tKey = mBlocks[i].MyUnit.BType.ToString() + mBlocks[i].MyUnit.Level.ToString();
|
|
|
|
|
|
if (!tCheckDic.ContainsKey(tKey))
|
|
|
|
|
|
{
|
|
|
|
|
|
tCheckDic[tKey] = new List<int>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tCheckDic[tKey].Add(i);
|
|
|
|
|
|
|
|
|
|
|
|
if (tCheckDic[tKey].Count >= 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
mAutoMergeQueue.Enqueue(new Vector2Int(tCheckDic[tKey][0], tCheckDic[tKey][1]));
|
|
|
|
|
|
mIsAutoMerge = true;
|
|
|
|
|
|
UIManager.Instance.GetUI<PanelMain>().EnableRecruitBtns(!mIsAutoMerge);
|
|
|
|
|
|
mBlocks[tCheckDic[tKey][0]].MyUnit.transform.DOMove(mBlocks[tCheckDic[tKey][1]].MyUnit.transform.position, 0.3f).SetEase(Ease.Linear).onComplete = ExcuteAutoMerge;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ExcuteAutoMerge()
|
|
|
|
|
|
{
|
|
|
|
|
|
Vector2Int tMergePair = mAutoMergeQueue.Dequeue();
|
|
|
|
|
|
MergeBlock(mBlocks[tMergePair.x], mBlocks[tMergePair.y]);
|
|
|
|
|
|
SavePlayerArmy();
|
|
|
|
|
|
|
|
|
|
|
|
PlayerData.Instance.AutoMergeCount--;
|
|
|
|
|
|
UIManager.Instance.GetUI<PanelMain>().RefreshAutoMerge();
|
|
|
|
|
|
mIsAutoMerge = false;
|
|
|
|
|
|
UIManager.Instance.GetUI<PanelMain>().EnableRecruitBtns(!mIsAutoMerge);
|
|
|
|
|
|
|
|
|
|
|
|
CheckAutoMerge();
|
|
|
|
|
|
}
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|