using asap.core; using cfg; using DG.Tweening; using game; using Game; using GameCore; using System; using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; using UnityEngine.AddressableAssets; public class SupplyDropCtrl : IDisposable { SupplyDropData supplyDropData; FishingBehaviorConf conf; SupplyDropModel supplyDropModel; SupplyDropRewardPanel supplyDropPanel; GameObject supplyDropGo; GameObject containerGo; GameObject fx_supplydrop_containerdisappear; ItemData itemData; ResetFishingStatusEvent resetFishing; Tables tables; public TargetAddData targetAddData; public Vector3 targetPos; public ISupplyDropGameCtrl supplyDropGameCtrl; public void InitData(int supplyDropId, SupplyDropFbx supplyDropFbx, string supplyDropPrefab, int supplyDropDropId, int fishItemId, int fishSubType, FishingBehaviorConf conf) { tables = GContext.container.Resolve(); supplyDropData = new SupplyDropData(); supplyDropData.supplyDropId = supplyDropId; supplyDropData.fishItemID = fishItemId; supplyDropData.fishSubType = fishSubType; supplyDropData.supplyDropFbx = supplyDropFbx; supplyDropData.supplyDropPrefab = supplyDropPrefab; supplyDropData.supplyDropDropId = supplyDropDropId; this.conf = conf; } public async void ShowSupplyDropModel() { string supplyDropName = supplyDropData.supplyDropPrefab; string airscplane = "prop_supplydrop_airscplane"; float randX = UnityEngine.Random.value; float startX = UnityEngine.Random.Range(conf.supplyDropPlaneStartX[0], conf.supplyDropPlaneStartX[1]); float endX = UnityEngine.Random.Range(conf.supplyDropPlaneEndX[0], conf.supplyDropPlaneEndX[1]); float packFlyStartRandX = UnityEngine.Random.Range(0, conf.supplyDropPackFlyStartRand.x); float YRand = UnityEngine.Random.Range(conf.supplyDropFlyTargetRotationYRand[0], conf.supplyDropFlyTargetRotationYRand[1]); if (randX < 0.5f) { startX = -startX; endX = -endX; packFlyStartRandX = -packFlyStartRandX; YRand = -YRand; } Vector3 target = conf.supplyDropPlaneEndPos; target.x = endX; Vector3 planeRelativePos = conf.supplyDropPlaneStartPos; planeRelativePos.x = startX; Quaternion quaternion = Quaternion.LookRotation(target - planeRelativePos); GameObject plane = await Addressables.InstantiateAsync(airscplane, planeRelativePos, quaternion * Quaternion.Euler(-90, 0, 0)).Task; if (plane != null) { GContext.Publish(new EventFishingSound("audio_supplydrop_airplane")); plane.transform.DOMove(target, conf.supplyDropPlaneFlyTime).OnComplete(() => { Addressables.ReleaseInstance(plane); }).SetEase(Ease.Linear); } //显示横幅 ShowPanel(); await Awaiters.Seconds(conf.supplyDropAppearDelay); Vector3 flyStart = new Vector3(); flyStart.x = conf.supplyDropFlyTargetPos.x + packFlyStartRandX; flyStart.y = conf.supplyDropPackFlyStartRand.y; flyStart.z = conf.supplyDropFlyTargetPos.z + UnityEngine.Random.Range(0, conf.supplyDropPackFlyStartRand.z); supplyDropGo = await Addressables.InstantiateAsync(supplyDropName, flyStart, Quaternion.identity).Task; if (supplyDropGo != null) { GContext.Publish(new EventFishingSound("audio_supplydrop_fly")); supplyDropModel = supplyDropGo.GetComponent(); supplyDropGo.transform.DOMove(conf.supplyDropFlyTargetPos, conf.supplyDropFlyTime).OnComplete(() => { GContext.Publish(new EventFishingSound("audio_supplydrop_drop")); supplyDropModel.SetTrigger("Drop"); }).SetEase(conf.supplyDropFlyCurve); supplyDropGo.transform.DORotateQuaternion(Quaternion.Euler(0, YRand, 0), conf.supplyDropFlyTime); //supplyDropFlyTargetRotationYRand await Awaiters.Seconds(conf.supplyDropFlyTime); } supplyDropModel.FxSmokeDelay(conf.supplyDropFxSmokeDelay, conf.supplyDropPackIdleDelay); await ClaimDelay(); } async Task ShowPanel() { GameObject go = await UIManager.Instance.ShowUINotLoading(UITypes.SupplyDropRewardPanel); if (go != null) { supplyDropPanel = go.GetComponent(); SupplyDrop supplyDrop = tables.TbSupplyDrop[supplyDropData.supplyDropId]; supplyDropPanel.Init(LocalizationMgr.GetText(supplyDrop.Name_l10n_key),conf.supplyDropTitleDelay, OnCloseClaim); } else { await Awaiters.Seconds(5); OnCloseClaim(); } } async Task ClaimDelay() { //按钮出现 if (supplyDropPanel != null) { await Awaiters.Seconds(conf.supplyDropClaimDelay); supplyDropPanel.ShowClaim(); } } async Task OpenSupplyDropModel() { Item item = null; List itemdatas = GContext.container.Resolve().AddItemByDrop(supplyDropData.supplyDropDropId, false); itemData = itemdatas[0]; item = tables.TbItem.Get(itemData.id); Debug.Log("OpenSupplyDrop :" + itemData.id + " " + itemData.count); if (item.Type == 11 && item.SubType == 1) { GContext.container.Resolve().SetGlobalBucffNew(item.RedirectID, true); } else if (item.Type != 14 || item.SubType == 1) { targetAddData = new TargetAddData(itemData.id, (int)itemData.curCount, (int)itemData.count); } GContext.Publish(new EventFishingSound("audio_supplydrop_open")); supplyDropModel.SupplyDropOpen(conf.supplyDropOpenDelay); resetFishing = new ResetFishingStatusEvent(); resetFishing.isSupplyDrop = true; if (supplyDropData.fishSubType == 4) { resetFishing.fishItemId = supplyDropData.fishItemID; } await ContainerDelay(); await Awaiters.NextFrame; if (item.Type != 14 || item.SubType == 1) { GContext.Publish(resetFishing); } else { NewAirdopGameCtrl(); } Dispose(); } void NewAirdopGameCtrl() { if (itemData.id == 14011) { //小玩法,钞票枪 Debug.Log("OpenSupplyDrop:钞票枪"); supplyDropGameCtrl = new SupplyDropGameplayCashCtrl(); } else if (itemData.id == 14012) { //小玩法,卡牌 Debug.Log("OpenSupplyDrop:卡牌"); supplyDropGameCtrl = new SupplyDropGameplayLureCtrl(); } supplyDropGameCtrl.containerModel = containerGo; containerGo = null; supplyDropGameCtrl.InitData(this, supplyDropData.supplyDropId, resetFishing); } async Task ClaimCameraBackDelay() { ResetFishingStatusEvent resetFishingStatus = new ResetFishingStatusEvent(); resetFishingStatus.isSupplyDrop = true; resetFishingStatus.playSupplyDropClaim = true; await Awaiters.Seconds(conf.supplyDropCameraBackDelay); GContext.Publish(resetFishingStatus); } void SetLurecardsShow() { SupplyDropItemLurecards supplyDropItemLurecards = containerGo.GetComponent(); var supplyDropGameplayLure = tables.TbSupplyDropGameplayLure.DataMap[supplyDropData.supplyDropId]; PlayerItemData playerItemData = GContext.container.Resolve(); int lurecardCount = supplyDropGameplayLure.DropID.Count; List indexs = new List() { 0, 1, 2 }; //打乱顺序 for (int i = 0; i < lurecardCount; i++) { ItemData itemData = playerItemData.GetItemDataOne(supplyDropGameplayLure.DropID[i]); int randomIndex = UnityEngine.Random.Range(0, indexs.Count); int j = indexs[randomIndex]; indexs.RemoveAt(randomIndex); supplyDropItemLurecards.text_num[j].text = $"x{itemData.count}"; supplyDropItemLurecards.skinned_meshes[j].material = supplyDropItemLurecards.material[i]; } } async Task ContainerDelay() { await Awaiters.Seconds(conf.supplyDropContainerDelay); float Delay = conf.supplyDropVanishDelay; containerGo = await Addressables.InstantiateAsync(supplyDropData.supplyDropFbx.Fbx, supplyDropModel.Content.position, Quaternion.identity).Task; if (containerGo != null) { if (itemData.id == 14012) { SetLurecardsShow(); } SupplyDropContentModel supplyDropContentModel = containerGo.GetComponent(); if (supplyDropContentModel != null) { supplyDropContentModel.SetTrigger("Fly"); } containerGo.transform.DOMove(conf.supplyDropContainerFirstFlyRelativePos, conf.supplyDropContainerFirstFlyTime) .SetEase(conf.supplyDropContainerFirstFlyCurve).SetRelative(); await Awaiters.Seconds(conf.supplyDropContainerFirstFlyTime); Vector3 scale = Vector3.one * containerGo.transform.localScale.x * conf.supplyDropContainerFlyScale; containerGo.transform.DOScale(scale, conf.supplyDropContainerFlyTime).SetEase(conf.supplyDropContainerFlyCurve); Vector3 FlyPos = conf.supplyDropContainerFlyPos; containerGo.transform.DOMove(FlyPos, conf.supplyDropContainerFlyTime).SetEase(conf.supplyDropContainerFlyCurve); await Awaiters.Seconds(conf.supplyDropContainerFlyTime); if (supplyDropContentModel != null) { supplyDropContentModel.SetTrigger("Show"); } if (supplyDropData.supplyDropFbx.ItemID == 14011 || supplyDropData.supplyDropFbx.ItemID == 14012) { if (!string.IsNullOrEmpty(supplyDropData.supplyDropFbx.AudioShow)) { GContext.Publish(new EventFishingSound(supplyDropData.supplyDropFbx.AudioShow)); } await Awaiters.Seconds(conf.supplyDropContainerFxDelay); } else { await Awaiters.Seconds(conf.supplyDropContainerFxDelay); if (!string.IsNullOrEmpty(supplyDropData.supplyDropFbx.AudioShow)) { GContext.Publish(new EventFishingSound(supplyDropData.supplyDropFbx.AudioShow)); } } Delay -= conf.supplyDropContainerFxDelay; if (!string.IsNullOrEmpty(supplyDropData.supplyDropFbx.FxShow)) { fx_supplydrop_containerdisappear = await Addressables.InstantiateAsync(supplyDropData.supplyDropFbx.FxShow, containerGo.transform.position, Quaternion.identity).Task; } targetPos = ConvertTools.WorldToScreenPoint(containerGo.transform.position, false); } if (Delay > 0) { await Awaiters.Seconds(Delay); } } void OnCloseClaim() { try { ClaimCameraBackDelay(); OpenSupplyDropModel(); ReleaseSupplyDropGo(); } catch (Exception e) { Debug.LogError($"Error in OnCloseClaim: {e.Message}"); } UIManager.Instance.DestroyUI(UITypes.SupplyDropRewardPanel); } async Task ReleaseSupplyDropGo() { if (supplyDropGo != null) { await Awaiters.Seconds(conf.supplyDropPackVanishDelay); supplyDropModel.Hide(); Addressables.ReleaseInstance(supplyDropGo); supplyDropGo = null; } } public void Dispose() { if (containerGo != null) { Addressables.ReleaseInstance(containerGo); containerGo = null; } if (fx_supplydrop_containerdisappear != null) { Addressables.ReleaseInstance(fx_supplydrop_containerdisappear); fx_supplydrop_containerdisappear = null; } } }