DESKTOP-DDTRVOR\asus 9c3a2645ac Merge branch 'main' into TT
# Conflicts:
#	Blacksmith/Assets/Script/GameSystem.cs
#	Blacksmith/Assets/Script/UI/StorePanel/PrizeDrawItem.cs
2024-12-26 11:45:43 +08:00

447 lines
15 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using TTSDK;
using Unity.VisualScripting;
using UnityEngine;
using Random = UnityEngine.Random;
public class GameSystem : MonoBehaviour
{
public static GameSystem ins;
public SoundSystem soundSystem;
public UIMgr uiMgr;
public JsonTab tab;
public DrawingManager drawingManager;
public AssetBundleManager abManager;
public List<ItemDataNum> List;
public List<NPCBuyData> saveStart;
public ItemDataAsset DataAsset;
public float maxTime = 100;
public float nowTime;
public int goldCoin = 0;
public int playingGold = 0;
[SerializeField] public ForgePanel forgePanel;
[SerializeField] public List<NPCBuyData> _npcBuyDatas;
[SerializeField] private RectTransform seleTransform;
private int id = 0;
private int index = -1;
private bool getNpc = false;
#if UNITY_EDITOR
[InspectorButton]
private void ClearPlayerPrefs()
{
PlayerPrefs.DeleteAll();
}
[InspectorButton]
#endif
private void AddDicData()
{
DataManager.SetLevelLock(int.Parse(JsonTab.Instance.tables.Main.Get(20).ConstantValue),true);
DataManager.SaveItemUnLock(int.Parse(JsonTab.Instance.tables.Main.Get(21).ConstantValue), true);
UnlockItem(int.Parse(JsonTab.Instance.tables.Main.Get(21).ConstantValue));
DataManager.SaveItemUnLock(int.Parse(JsonTab.Instance.tables.Main.Get(22).ConstantValue), true);
UnlockItem(int.Parse(JsonTab.Instance.tables.Main.Get(22).ConstantValue));
DataManager.SaveItemUnLock(int.Parse(JsonTab.Instance.tables.Main.Get(23).ConstantValue), true);
UnlockItem(int.Parse(JsonTab.Instance.tables.Main.Get(23).ConstantValue));
DataManager.SaveItemUnLock(int.Parse(JsonTab.Instance.tables.Main.Get(24).ConstantValue), true);
UnlockItem(int.Parse(JsonTab.Instance.tables.Main.Get(24).ConstantValue));
DataManager.SaveItemUnLock(int.Parse(JsonTab.Instance.tables.Main.Get(25).ConstantValue), true);
UnlockItem(int.Parse(JsonTab.Instance.tables.Main.Get(25).ConstantValue));
DataManager.SaveItemUnLock(int.Parse(JsonTab.Instance.tables.Main.Get(26).ConstantValue), true);
UnlockItem(int.Parse(JsonTab.Instance.tables.Main.Get(26).ConstantValue));
DataManager.SaveItemUnLock(int.Parse(JsonTab.Instance.tables.Main.Get(27).ConstantValue), true);
UnlockItem(int.Parse(JsonTab.Instance.tables.Main.Get(27).ConstantValue));
DataManager.SaveItemUnLock(1, true);
DataManager.SaveItemUnLock(2, true);
DataManager.SaveItemUnLock(3, true);
DataManager.SaveItem(1,int.Parse(JsonTab.Instance.tables.Main.Get(1).ConstantValue));
DataManager.SaveItem(2,int.Parse(JsonTab.Instance.tables.Main.Get(18).ConstantValue));
DataManager.SaveItem(3,int.Parse(JsonTab.Instance.tables.Main.Get(19).ConstantValue));
DataManager.SaveDrawLevel(302011, 1);
DataManager.SaveDrawLevel(302101, 1);
DataManager.SaveDrawLevel(302201, 1);
DataManager.SaveDrawLevel(302301, 1);
DataManager.SaveDrawLevel(302401, 1);
DataManager.SaveDrawLevel(302501, 1);
DataManager.SaveDrawLevel(302601, 1);
DataManager.SaveItem(1011,int.Parse(JsonTab.Instance.tables.Main.Get(28).ConstantValue));
DataManager.SaveItem(1021,int.Parse(JsonTab.Instance.tables.Main.Get(29).ConstantValue));
DataManager.SaveItem(1031,int.Parse(JsonTab.Instance.tables.Main.Get(30).ConstantValue));
DataManager.SaveItem(1041,int.Parse(JsonTab.Instance.tables.Main.Get(31).ConstantValue));
DataManager.SaveItem(1051,int.Parse(JsonTab.Instance.tables.Main.Get(32).ConstantValue));
}
private void UnlockItem(int id)
{
var data = JsonTab.Instance.tables.CraftingRecipes.Get(id);
if (data.Levelprops1!=0)
{
DataManager.SaveItemUnLock(data.Levelprops1,true);
}
if (data.Levelprops2!=0)
{
DataManager.SaveItemUnLock(data.Levelprops2,true);
}
if (data.Levelprops3!=0)
{
DataManager.SaveItemUnLock(data.Levelprops3,true);
}
if (data.Levelprops4!=0)
{
DataManager.SaveItemUnLock(data.Levelprops4,true);
}
}
private void Awake()
{
ins = this;
TT.InitSDK((code, env) =>
{
foreach (var data in List)
{
DataManager.AddItem(data.id, data.num);
}
soundSystem.Init();
foreach (var data in List)
{
DataManager.AddItem(data.id, data.num);
}
tab = new JsonTab();
tab.InitData();
abManager.InitAsset((() => {}));
if (!DataManager.GetFirst())
{
AddDicData();
//JsonTab.Instance.tables.Main.
// var data = JsonTab.Instance.tables.Main.Get(18);
// var idStr = data.ConstantValue;
// var idList = idStr.Split(',');
// foreach (var id in idList)
// {
// var intId = int.Parse(id);
// DataManager.SaveItemUnLock(intId,true);
// var pData = JsonTab.Instance.tables.CraftingRecipes.Get(intId);
// if (pData.Levelprops1!=0)
// {
// DataManager.SaveItemUnLock(pData.Levelprops1,true);
// }
// if (pData.Levelprops2!=0)
// {
// DataManager.SaveItemUnLock(pData.Levelprops2,true);
// }
// if (pData.Levelprops3!=0)
// {
// DataManager.SaveItemUnLock(pData.Levelprops3,true);
// }
// if (pData.Levelprops4!=0)
// {
// DataManager.SaveItemUnLock(pData.Levelprops4,true);
// }
// }
// var dataItem=JsonTab.Instance.tables.Main.Get(19).ConstantValue;
// var dataItemList = dataItem.Split(',');
// DataManager.SaveItem(int.Parse(dataItemList[0]), int.Parse(dataItemList[1]));
DataManager.SaveFirst();
}
AssetBundleManager.ins.LoadAtlas();
goldCoin = 5;
drawingManager = transform.AddComponent<DrawingManager>();
forgePanel.ResetItemData();
forgePanel.ResetSlotItem();
_npcBuyDatas = new List<NPCBuyData>();
getNpc = false;
uiMgr.Init();
SaveFirstID();
UIMgr.ins.OpenForgePanel();
forgePanel.ResetGold();
if (DataManager.GetPrefab("firstGuideV1")!=1)
{
uiMgr.OpenFirstGuidePanel();
}
});
// abManager.InitAsset(() =>
// {
// if (!DataManager.GetFirst())
// {
// //JsonTab.Instance.tables.Main.
// // var data = JsonTab.Instance.tables.Main.Get(18);
// // var idStr = data.ConstantValue;
// // var idList = idStr.Split(',');
// // foreach (var id in idList)
// // {
// // var intId = int.Parse(id);
// // DataManager.SaveItemUnLock(intId,true);
// // var pData = JsonTab.Instance.tables.CraftingRecipes.Get(intId);
// // if (pData.Levelprops1!=0)
// // {
// // DataManager.SaveItemUnLock(pData.Levelprops1,true);
// // }
// // if (pData.Levelprops2!=0)
// // {
// // DataManager.SaveItemUnLock(pData.Levelprops2,true);
// // }
// // if (pData.Levelprops3!=0)
// // {
// // DataManager.SaveItemUnLock(pData.Levelprops3,true);
// // }
// // if (pData.Levelprops4!=0)
// // {
// // DataManager.SaveItemUnLock(pData.Levelprops4,true);
// // }
// // }
// // var dataItem=JsonTab.Instance.tables.Main.Get(19).ConstantValue;
// // var dataItemList = dataItem.Split(',');
// // DataManager.SaveItem(int.Parse(dataItemList[0]), int.Parse(dataItemList[1]));
// DataManager.SaveFirst();
// }
//
// goldCoin = 5;
// drawingManager = transform.AddComponent<DrawingManager>();
// forgePanel.ResetItemData();
// forgePanel.ResetSlotItem();
// _npcBuyDatas = new List<NPCBuyData>();
// getNpc = false;
// SaveFirstID();
// forgePanel.ResetGold();
// });
}
/// <summary>
/// 重置商店刷新
/// </summary>
public void ResetItem()
{
forgePanel.ResetItemData();
}
/// <summary>
/// 开始添加npc
/// </summary>
public void StartNpcData()
{
_npcBuyDatas.Clear();
foreach (var data in JsonTab.Instance.tables.Item.DataList)
{
if (DataManager.GetItemUnLock(data.ID) && data.NPC.Count != 0)
{
NPCBuyData npcBuyData = new NPCBuyData();
npcBuyData.buyID = data.ID;
npcBuyData.npcID = data.NPC[Random.Range(0, data.NPC.Count)];
_npcBuyDatas.Add(npcBuyData);
}
}
nowTime = 0;
SaveFirstID();
}
public void GuidData()
{
NPCBuyData npcBuyData = new NPCBuyData();
npcBuyData.buyID = 2011;
npcBuyData.npcID = 50007;
_npcBuyDatas.Add(npcBuyData);
NPCBuyData npcBuyData1 = new NPCBuyData();
npcBuyData1.buyID = 2011;
npcBuyData1.npcID = 50008;
_npcBuyDatas.Add(npcBuyData);
DataManager.SaveGuidItem(1011,3);
nowTime = 0;
SaveFirstID();
}
public void SaveNPCbo(bool bo)
{
getNpc = bo;
}
/// <summary>
/// 默认获得金币
/// </summary>
public void GoldRest()
{
goldCoin += playingGold;
DataManager.AddItem(2,playingGold);
forgePanel.ResetGold();
}
/// <summary>
/// 双倍获得金币
/// </summary>
public void DoubleGoldRest()
{
goldCoin += (playingGold * 2);
DataManager.AddItem(2,playingGold * 2);
forgePanel.ResetGold();
}
public void StartGamePanel()
{
forgePanel.OpenStartPanel();
}
public void CloseStore()
{
_npcBuyDatas.Clear();
forgePanel.OpenStartPanel();
nowTime = maxTime;
}
/// <summary>
/// 设置购买物品和无物品判断
/// </summary>
private void SaveFirstID()
{
if (_npcBuyDatas.Count > 0)
{
drawingManager.itemID = _npcBuyDatas[0].buyID;
forgePanel.ResetCrafting(drawingManager.itemID,_npcBuyDatas[0].npcID);
forgePanel.Open();
}
else
{
forgePanel.Close();
}
}
// Start is called before the first frame update
void Start()
{
}
public void Crafting(bool bo)
{
drawingManager.CraftItem(bo, () =>
{
ResetItemPanel();
});
}
public void ResetItemPanel()
{
forgePanel.ResetItemData();
forgePanel.ResetSlotItem();
}
public void SaveSeledID(int sendID)
{
id = sendID;
index = -1;
seleTransform.GetComponent<SeletItemUI>().SaveSprite(id);
}
public void SaveIndex(int slotIndex)
{
index = slotIndex;
}
private void FixedUpdate()
{
if (_npcBuyDatas.Count > 0)
{
nowTime += Time.deltaTime;
if (nowTime > maxTime)
{
_npcBuyDatas = new List<NPCBuyData>();
nowTime = 0;
SaveFirstID();
}
}
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonUp(0))
{
if (id != 0)
{
if ( Input.mousePosition.y > Screen.height*0.6)
{
var itemData = JsonTab.Instance.tables.Item.Get(drawingManager.itemID);
if (drawingManager.itemID == id)
{
playingGold += itemData.Itemprice;
DataManager.RemoveItem(id, (bool bo) =>
{
if (bo)
{
var npcData = _npcBuyDatas[0];
_npcBuyDatas.Remove(_npcBuyDatas[0]);
SaveFirstID();
if (_npcBuyDatas.Count > 0)
{
forgePanel.SetData(true,npcData);
}
else
{
forgePanel.OpenStartPanel();
}
}
});
}
else
{
var itemprice = itemData.Itemprice * 0.01f;
playingGold += (int)itemprice;
DataManager.RemoveItem(id, (bool bo) =>
{
if (bo)
{
var npcData = _npcBuyDatas[0];
_npcBuyDatas.Remove(_npcBuyDatas[0]);
SaveFirstID();
if (_npcBuyDatas.Count > 0)
{
forgePanel.SetData(false,npcData);
}
else
{
forgePanel.OpenStartPanel();
}
}
});
}
}
else
{
if (index != -1)
{
drawingManager.SaveIndexID(index, id);
}
}
id = 0;
seleTransform.position = new Vector3(-3000, 0, 0);
index = -1;
getNpc = false;
forgePanel.ResetSlotItem();
forgePanel.ResetItemData();
}
}
if (Input.GetMouseButton(0))
{
if (id != 0)
{
Vector2 mouse = Input.mousePosition;
seleTransform.position = mouse;
}
}
}
public void GuideV2()
{
var npcData = _npcBuyDatas[0];
_npcBuyDatas.Remove(_npcBuyDatas[0]);
SaveFirstID();
forgePanel.SetData(true,npcData);
}
}