Files
back_cantanBuilding/Assets/Scripts/UI/FishingReward/FishingRewardPanel.cs
2026-05-26 16:15:54 +08:00

1356 lines
51 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using asap.core;
using cfg;
using DG.Tweening;
using game;
using Game;
using GameCore;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.EventSystems;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;
public class FishingRewardPanel : BasePanel
{
Tables _tables;
private CanvasGroup canvasGroup;
private CanvasGroup root_success;
GameObject root_target;
private GameObject root_fail;
GameObject target_info;
Image target_info_icon;
Button targetBtn;
private Button playButton;
private TMP_Text text_title;
private TMP_Text text_weight_num;
private TMP_Text text_pound;
private TMP_Text txt_magnification;
GameObject bonus;
RewardItemNew reward_extra;
//Fish Weigh
private GameObject go_weight;
//Bar
private Image img_weighbar;
private TMP_Text txt_weighScore;
private TMP_Text txt_weighWeight;
private RectTransform rect_weighScore;
private FishingWeighBar _weighBar;
private float maxFillPoint;
private float maxFillLen;
private float _reulerSlideSpeed = 250f * 2f * 1.3f;
private float _fillSpeed = 250f * 2f * 2f * 1.3f / 3f;
//Capture Fish Photo
[SerializeField]
private RenderTexture _rt;
private Image img_fishPhoto;
[SerializeField]
private GameObject prefab_cameraCapture;
private Button btn_captureFishPhoto;
private FishingRewardPhoto
go_fishPhoto;
//Fish Info
private GameObject go_info;
private GameObject new_go;
private TMP_Text text_gold_num;
TMP_Text text_num_buff;
private TMP_Text newFish;
private Image img_fishTag;
private GameObject station_powerful;
private GameObject station_weekly;
private GameObject station_nopush;
private GameObject station_more;
Button info1_btn;
Button info2_btn;
Button info3_btn;
private GameObject station_advert;
Image icon_rate_advert;
FishIconRT fishIconRT;
RawImage rawImage;
//Image bg_advert;
public TMP_Text text_info;
private Image image_icon_mark;
private Button btn_green;
TMP_Text text_tryagain_num;
GameObject btn_discount_go;
Button btn_discount;
TMP_Text text_discount_num;
TMP_Text text_old;
TMP_Text tag_text_num;
GameObject btn_tryagain_go;
Button btn_tryagain;
TMP_Text text_tryagain_num1;
private AdvertButton btn_green2;
private Button btn_close;
public Transform icon_rate;
Image bg_target;
int curRateIndex;
public UIDrag dragImage;
FishingRewardSocial fishingRewardSocial;
Animator anim_panel;
public float fishRotateSpeed = 8f; //鱼旋转速度
ulong curGold = 0;
int add = 0;
private int curCollectingID = 0;
//private int curCollecting = 0;
private int addCollecting = 0;
Dictionary<string, TMP_Text> LanguageCenter = new Dictionary<string, TMP_Text>();
float startWeight;
float endWeight;
bool isSocial = false;
//钓鱼结算评级
private Dictionary<string, float> fishingGrade = new Dictionary<string, float>();
private Dictionary<string, float> fishingSpGrade = new Dictionary<string, float>();
int fishID;
[SerializeField]
private List<Transform> _tranMedals = new();
FishingData fishingData;
//AddCash等待时间
public float waitTime1 = 0.2f;
//AddCash持续时间
public float duration1 = 1f;
public float waitTime2 = 0.2f;
public float duration2 = 1f;
bool isEnable = true;
GameObject fx_ui_blingbling_01;
TMP_Text root_target_text_info;
IUIService uiService;
FishingEventData fishingEventData;
PlayerFishData playerFishData;
PlayerData playerData;
void OnChangeLanguage(ChangeLanguageEvent changeLanguageEvent = null)
{
foreach (var tmpText in LanguageCenter)
{
tmpText.Value.text = LocalizationMgr.GetText(tmpText.Key);
}
}
//倍率
int Magnification = 1;
float extraPointEvent = 0;
private void Awake()
{
uiService = GContext.container.Resolve<IUIService>();
text_info = transform.Find("root_fail/bg_info/text_info").GetComponent<TMP_Text>();
icon_rate = transform.Find("root_success/info/score/text_weight/fishing_rate");
// text_tips = transform.Find("root_fail/bg_info/text_tips").GetComponent<TMP_Text>();
dragImage = transform.Find("root_success/UIDrag").GetComponent<UIDrag>();
canvasGroup = GetComponent<CanvasGroup>();
root_success = transform.Find("root_success").GetComponent<CanvasGroup>();
img_fishTag = transform.Find("root_success/info/name/icon_tag").GetComponent<Image>();
anim_panel = GetComponent<Animator>();
root_target = transform.Find("root_target").gameObject;
root_target_text_info = transform.Find("root_target/info/text_info").GetComponent<TMP_Text>();
bg_target = transform.Find("root_success/info/bg/bg_target").GetComponent<Image>();
bonus = transform.Find("root_success/info/bonus").gameObject;
reward_extra = transform.Find("root_success/info/bonus/reward").GetComponent<RewardItemNew>();
text_title = transform.Find("root_success/info/name/text_name").GetComponent<TMP_Text>();
//Fish weigh
go_weight = transform.Find("root_success/weight").gameObject;
img_weighbar = transform.Find("root_success/weight/bar").GetComponent<Image>();
txt_weighScore = transform.Find("root_success/weight/bar/point/text_point").GetComponent<TMP_Text>();
txt_weighWeight = transform.Find("root_success/weight/bg_weight/text_num").GetComponent<TMP_Text>();
rect_weighScore = transform.Find("root_success/weight/bar/point").GetComponent<RectTransform>();
_weighBar = transform.Find("root_success/weight").GetComponent<FishingWeighBar>();
text_weight_num = transform.Find("root_success/info/score/text_point").GetComponent<TMP_Text>();
text_pound = transform.Find("root_success/info/score/text_weight").GetComponent<TMP_Text>();
new_go = transform.Find("root_success/info/tag/bg").gameObject;
newFish = transform.Find("root_success/info/tag/bg/text").GetComponent<TMP_Text>();
txt_magnification = transform.Find("root_success/info/text_beilv").GetComponent<TMP_Text>();
//Fish Info
go_info = transform.Find("root_success/info").gameObject;
//Fish Photo Capture
btn_captureFishPhoto = transform.Find("root_success/info/btn_photo").GetComponent<Button>();
playButton = transform.Find("root_success/info/btn_play/btn_green").GetComponent<Button>();
targetBtn = transform.Find("root_target/reward/btn_play/btn_green").GetComponent<Button>();
text_gold_num = transform.Find("root_success/info/text_num").GetComponent<TMP_Text>();
text_num_buff = transform.Find("root_success/info/text_num/text_num_buff").GetComponent<TMP_Text>();
root_fail = transform.Find("root_fail").gameObject;
target_info = transform.Find("root_fail/station_advert/root_fish/target_info").gameObject;
target_info_icon = transform.Find("root_fail/station_advert/root_fish/target_info/bonus/reward/icon").GetComponent<Image>();
station_powerful = transform.Find("root_fail/station_powerful").gameObject;
station_weekly = transform.Find("root_fail/station_weekly").gameObject;
station_nopush = transform.Find("root_fail/station_nopush").gameObject;
station_more = transform.Find("root_fail/station_more").gameObject;
info1_btn = transform.Find("root_fail/station_more/bg/info/info1/btn_common_green_c/btn_green_c").GetComponent<Button>();
info2_btn = transform.Find("root_fail/station_more/bg/info/info2/btn_common_green_c/btn_green_c").GetComponent<Button>();
info3_btn = transform.Find("root_fail/station_more/bg/info/info3/btn_common_green_c/btn_green_c").GetComponent<Button>();
station_advert = transform.Find("root_fail/station_advert").gameObject;
icon_rate_advert = transform.Find("root_fail/station_advert/root_fish/icon_rate").GetComponent<Image>();
fishIconRT = transform.Find("root_fail/station_advert/icon_fish").GetComponent<FishIconRT>();
rawImage = transform.Find("root_fail/station_advert/root_fish/Viewport/RawImage").GetComponent<RawImage>();
//bg_advert = transform.Find("root_fail/station_advert/root_fish/mask_bg2/bg").GetComponent<Image>();
image_icon_mark = transform.Find("root_fail/icon_fish_empty/icon_mark").GetComponent<Image>();
btn_green = transform.Find("root_fail/btn_tryagain/btn_green").GetComponent<Button>();
text_tryagain_num = transform.Find("root_fail/btn_tryagain/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
btn_discount_go = transform.Find("root_fail/station_advert/btn_2/btn_discount").gameObject;
btn_discount = transform.Find("root_fail/station_advert/btn_2/btn_discount/btn_green").GetComponent<Button>();
text_discount_num = transform.Find("root_fail/station_advert/btn_2/btn_discount/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
text_old = transform.Find("root_fail/station_advert/btn_2/btn_discount/btn_green/Ani_Container/text_old").GetComponent<TMP_Text>();
tag_text_num = transform.Find("root_fail/station_advert/btn_2/btn_discount/btn_green/tag/tag_1/text_num").GetComponent<TMP_Text>();
btn_tryagain_go = transform.Find("root_fail/station_advert/btn_2/btn_tryagain").gameObject;
btn_tryagain = transform.Find("root_fail/station_advert/btn_2/btn_tryagain/btn_green").GetComponent<Button>();
text_tryagain_num1 = transform.Find("root_fail/station_advert/btn_2/btn_tryagain/btn_green/Ani_Container/cost/p_text_num").GetComponent<TMP_Text>();
btn_green2 = transform.Find("root_fail/station_advert/btn_2/btn_tryagain2").GetComponent<AdvertButton>();
btn_close = transform.Find("root_fail/btn_close").GetComponent<Button>();
_tables = GContext.container.Resolve<Tables>();
fishingRewardSocial = transform.Find("root_success/event_social").GetComponent<FishingRewardSocial>();
go_fishPhoto = transform.Find("root_photo").GetComponent<FishingRewardPhoto>();
fx_ui_blingbling_01 = transform.Find("root_success/info/fx_ui_blingbling_01").gameObject;
}
protected override void Start()
{
base.Start();
SetFishingFocalVolume(50);
playerData = GContext.container.Resolve<PlayerData>();
fishingData = GContext.container.Resolve<FishingData>();
Magnification = playerData.GetMagnification();
go_fishPhoto.OnBackClick = OnBackClick;
playButton.onClick.AddListener(OnClickInHome);
targetBtn.onClick.AddListener(OnTargetClosePanel);
btn_green.onClick.AddListener(OnSucceed);
btn_tryagain.onClick.AddListener(OnClickPlay);
btn_discount.onClick.AddListener(OnClickPlay);
btn_green2.SetData(OnAdsSucceed, AdvertPopupType.FishingFail);
info1_btn.onClick.AddListener(InFishRod);
info2_btn.onClick.AddListener(InMap);
info3_btn.onClick.AddListener(InInfo);
btn_captureFishPhoto.onClick.AddListener(OnCaptureFishPhoto);
GContext.OnEvent<ChangeLanguageEvent>().Subscribe(OnChangeLanguage).AddTo(disposables);
GContext.OnEvent<LackOfResourceCloseEvent>().Subscribe(x =>
{
if (x.resultToShop)
{
ResourceCloseEvent();
}
}).AddTo(disposables);
dragImage.OnPointerDownCall += () =>
{
GameEventMgr.Instance.Raise(GameEvents.EventFishingPlay);
};
StartDoRotate();
dragImage.OnBeginDragCall += OnBeginDragCall;
dragImage.OnDragCall += OnDragFish;
dragImage.OnEndDragCall += StartDoRotate;
OnShow();
}
void StartDoRotate()
{
GContext.Publish(new FishRotateEvent(0, 1, fishingData.rodType));
}
void OnDragFish(PointerEventData eventData)
{
float x = Input.GetAxis("Mouse X") * fishRotateSpeed;
GContext.Publish(new FishRotateEvent(x, 2, fishingData.rodType));
}
void OnBeginDragCall()
{
GContext.Publish(new FishRotateEvent(0, 0, fishingData.rodType));
}
void OnShow()
{
var normalRank = _tables.TbGlobalConfig.Rank;
var spRank = _tables.TbGlobalConfig.RankForSpFish;
fishingGrade["fishing_rate_d"] = normalRank[0];
fishingGrade["fishing_rate_c"] = normalRank[1];
fishingGrade["fishing_rate_c+"] = normalRank[2];
fishingGrade["fishing_rate_b"] = normalRank[3];
fishingGrade["fishing_rate_b+"] = normalRank[4];
fishingGrade["fishing_rate_a"] = normalRank[5];
fishingGrade["fishing_rate_a+"] = normalRank[6];
fishingGrade["fishing_rate_s"] = normalRank[7];
fishingGrade["fishing_rate_ss"] = normalRank[8];
fishingGrade["fishing_rate_sss"] = normalRank[9];
fishingGrade["fishing_rate_x"] = normalRank[10];
fishingGrade["fishing_rate_xx"] = normalRank[11];
fishingGrade["fishing_rate_xxx"] = normalRank[12];
fishingSpGrade["fishing_rate_d"] = spRank[0];
fishingSpGrade["fishing_rate_c"] = spRank[1];
fishingSpGrade["fishing_rate_c+"] = spRank[2];
fishingSpGrade["fishing_rate_b"] = spRank[3];
fishingSpGrade["fishing_rate_b+"] = spRank[4];
fishingSpGrade["fishing_rate_a"] = spRank[5];
fishingSpGrade["fishing_rate_a+"] = spRank[6];
fishingSpGrade["fishing_rate_s"] = spRank[7];
fishingSpGrade["fishing_rate_ss"] = spRank[8];
fishingSpGrade["fishing_rate_sss"] = spRank[9];
fishingSpGrade["fishing_rate_x"] = spRank[10];
fishingSpGrade["fishing_rate_xx"] = spRank[11];
fishingSpGrade["fishing_rate_xxx"] = spRank[12];
fishingEventData = GContext.container.Resolve<FishingEventData>();
playerFishData = GContext.container.Resolve<PlayerFishData>();
curGold = playerData.gold;
new_go.SetActive(false);
bonus.SetActive(false);
fishingData.IsFree = false;
if (!string.IsNullOrEmpty(fishingData.curFishData.AudioRewardPanelLoop))
{
GContext.Publish(new EventBGMSound(fishingData.curFishData.AudioRewardPanelLoop));
}
if (!string.IsNullOrEmpty(fishingData.curFishData.AudioRewardPanel))
{
GContext.Publish(new EventFishingSound(fishingData.curFishData.AudioRewardPanel));
}
fishID = fishingData.curFishData.ID;
if (fishingData.fixedFishList != null)
{
fishID = fishingData.fixedFishList.RealFishID;
}
addCollecting = 0;
curCollectingID = 0;
curCollectingID = fishingEventData.collectingTargetInitTokenID;
addCollecting = GContext.container.Resolve<CollectingData>().GetAddCollecting();
if (fishingData.IsGeneralFish()
&& (playerFishData.GetAnglingCount() > GContext.container.Resolve<MMTService>().FixedFish.Count
|| playerData.lastMapId != _tables.TbMapData.DataList[0].ID))
{
playerFishData.SetBotCount(fishingData.curFishData.Quality);
}
if (fishingData.fishingResult == FishingResult.Success)
{
root_fail.SetActive(false);
root_success.gameObject.SetActive(fishingData.IsGeneralFish());
root_target.SetActive(fishingData.IsKeepsakeFish() || fishingData.IsPackItemFish());
Success();
StartCoroutine(Blur());
#if AGG
using (var e = GEvent.GameEvent("go_fishing"))
{
int currentRodLevel = playerFishData.GetRodLevel(playerData.equipRodID);
int currentRodStar = playerFishData.GetRodPiece(playerData.equipRodID);
e.AddContent("map_id", fishingData.MapId)
.AddContent("fishing_state", 1)
.AddContent("fish_id", fishID)
.AddContent("fish_count", playerFishData.GetAnglingCount())
.AddContent("fish_time", fishingData.GetFishingTimer())
.AddContent("charge_count", GContext.container.Resolve<PlayerShopData>().GetBuyPaymentAmount())
.AddContent("hook_count", playerData.GetEnergyRM())
.AddContent("available_hook_num", playerData.Energy)
.AddContent("available_cash_num", playerData.gold)
.AddContent("jerking_count", fishingData.jerking_count)
.AddContent("stickle_state", fishingData.stickle_state)
.AddContent("current_rod", playerData.equipRodID)
.AddContent("current_rod_level", currentRodLevel)
.AddContent("current_rod_star", currentRodStar)
.AddContent("fish_card_lv", fishingData.CardLevel)
.AddContent("reward_cash", add)
.AddContent("retry_ways", fishingData.retry_ways)
.AddContent("retry", fishingData.IsRetry);
e.AddContent("fish_multiple", playerData.GetMagnification());
var _socialData = GContext.container.Resolve<ClubService>();
if (_socialData.myClubInfo != null)
{
e.AddContent("guild_id", _socialData.myClubInfo.id);
}
else
{
e.AddContent("guild_id", 0);
}
}
#endif
GContext.Publish(new OnEventTriggerGuide(GetType().Name));
}
else
{
root_success.gameObject.SetActive(false);
root_target.SetActive(false);
root_fail.SetActive(true);
if (addCollecting > 0)
{
fishingEventData.RefreshTargetGuidance();
}
#if AGG
using (var e = GEvent.GameEvent("go_fishing"))
{
int currentRodLevel = playerFishData.GetRodLevel(playerData.equipRodID);
int currentRodStar = playerFishData.GetRodPiece(playerData.equipRodID);
e.AddContent("map_id", fishingData.MapId)
.AddContent("fishing_state", 2)
.AddContent("fishing_failed_reason", (int)fishingData.fishingResult)
.AddContent("fish_id", fishID)
.AddContent("fish_count", playerFishData.GetAnglingCount())
.AddContent("fish_time", fishingData.GetFishingTimer())
.AddContent("charge_count", GContext.container.Resolve<PlayerShopData>().GetBuyPaymentAmount())
.AddContent("hook_count", playerData.GetEnergyRM())
.AddContent("available_hook_num", playerData.Energy)
.AddContent("available_cash_num", playerData.gold)
.AddContent("jerking_count", fishingData.jerking_count)
.AddContent("stickle_state", fishingData.stickle_state)
.AddContent("current_rod", playerData.equipRodID)
.AddContent("current_rod_level", currentRodLevel)
.AddContent("current_rod_star", currentRodStar)
.AddContent("fish_card_lv", fishingData.CardLevel)
.AddContent("retry_ways", fishingData.retry_ways)
.AddContent("retry", fishingData.IsRetry);
e.AddContent("fish_multiple", playerData.GetMagnification());
var _socialData = GContext.container.Resolve<ClubService>();
if (_socialData.myClubInfo != null)
{
e.AddContent("guild_id", _socialData.myClubInfo.id);
}
else
{
e.AddContent("guild_id", 0);
}
}
#endif
OnFail();
}
fishingData.IsRetry = false;
}
IEnumerator Blur()
{
//Pulling 结束后
float time = fishingData.fishingBehaviorConf.blurDelay;
yield return new WaitForSeconds(time);
//ConvertTools.SetFSBlur(true, fishingData.fishingBehaviorConf.blurDistanceZ);
EnableFishingBlur(true);
}
//钓鱼成功
async void Success()
{
go_info.gameObject.SetActive(false);
playerFishData.SaveFishingFrequency();
if (addCollecting > 0)
{
extraPointEvent = fishingEventData.OnFishReward(fishingData.MapId, fishingData.NewIndex, Magnification);
addCollecting *= Magnification;
GContext.container.Resolve<PlayerItemData>().AddItemCount(curCollectingID, addCollecting);
MaterialChange();
}
PlayAudioRewardFish();
GContext.container.Resolve<BuffDataCenter>().EndCollectionTargetWeight(fishingData.fishItem.ID);
fishingEventData.AddProgress(fishingData.fishItem.Quality, Magnification);
GContext.container.Resolve<GuideDataCenter>().AddIndex(true);
if (fishingData.IsKeepsakeFish())
{
root_target_text_info.text = LocalizationMgr.GetText("UI_FishingTargetPopupPanel_Advanced_9");
}
else if (fishingData.IsPiggyBankFish())
{
fishingEventData.curActivateItemId = fishingData.fishItem.ID;
root_target_text_info.text = LocalizationMgr.GetText("UI_GiftPiggyBankPopupPanel_10");
PiggyBankPackData piggyBankPackData = GContext.container.Resolve<PiggyBankPackData>();
piggyBankPackData.TriggerPack();
}
else if (fishingData.IsBarginPackFish())
{
fishingEventData.curActivateItemId = fishingData.fishItem.ID;
root_target_text_info.text = LocalizationMgr.GetText("UI_GiftBargainPopupPanel_7");
BargainPackData piggyBankPackData = GContext.container.Resolve<BargainPackData>();
piggyBankPackData.TriggerPack();
}
else if (fishingData.IsGeneralFish())
{
var PointBonus = playerFishData.GetRodAscendStats();
PointBonus += extraPointEvent;//额外的Buff加成
isSocial = false;
//ShowStarNum();
DropPackageList dropPackageList = _tables.TbDrop[fishingData.curFishData.DropID].DropList;
float proficiency = dropPackageList.DropCountList[0] * fishingData.random;
var proficiencyExtra = SetProficiency(proficiency, PointBonus);
var endWeight = fishingData.fishWeight;
float extraCashDrop = GContext.container.Resolve<CollectingData>().ExtraCashDrop();
//Data
//金币各种加成
float gold = (dropPackageList.DropCountList[1] + extraCashDrop)
* Magnification
* fishingData.random;
//杆加成
//解锁地图Buff加成
float glodBuff = GContext.container.Resolve<BuffDataCenter>().GetExtraGoldBuffValue(fishingData.MapId, fishingData.fishItem.Quality);
if (glodBuff > 0.001f)
{
text_gold_num.color = Color.black;
text_num_buff.color = Color.white;
}
int Quality = fishingData.curFishData.Quality;
if (Quality > 6)
{
Quality = 6;
}
//权益全局加成
var ExtraPoint = playerData.benefitsCashMag + glodBuff;
int cash = Mathf.RoundToInt(gold * proficiencyExtra * (1 + ExtraPoint));
add = cash;
GContext.Publish(new ConditionTypeEvent(ConditionType.CashFromFishing, add));
GContext.Publish(new ConditionTypeEvent(ConditionType.MaxCashFromFishing, add / Magnification));
//AddEventData
playerData.AddGold((ulong)add);
GContext.Publish(new TargetAddData(dropPackageList.DropIDList[1], 0, add));
var isSpecialFish = fishingData.curFishData.GeneralType == FishGeneralType.SpMapFish || fishingData.curFishData.GeneralType == FishGeneralType.EventFish;
SetTextTitleAsync(proficiencyExtra * fishingData.random, isSpecialFish);
SetFishWeight(fishingData.fishWeight);
MMTService mmService = GContext.container.Resolve<MMTService>();
if (addCollecting > 0 && bonus != null)
{
var collectingTargetInit = fishingEventData.collectingTargetInit;
string BgRewardAdd = collectingTargetInit.BgRewardAdd;
if (!string.IsNullOrEmpty(BgRewardAdd))
{
bg_target.gameObject.SetActive(true);
uiService.SetImageSprite(bg_target, BgRewardAdd, PanelName);
}
bonus.SetActive(true);
reward_extra.SetData(new ItemData() { id = curCollectingID, count = addCollecting / Magnification });
}
_ = StartCoroutine(AddCash());
//Show Fish Info UI
go_info.gameObject.SetActive(true);
go_weight.SetActive(false);
//Show Magnification Animation
if (Magnification > 1)
{
txt_magnification.text = "x" + Magnification;
anim_panel.Play("info_show_2");
await new WaitForSeconds(waitTime1 + duration1 + waitTime2);
if (!isEnable)
{
return;
}
var progress = 0f;
var newCash = add / Magnification;
var addCash = add - newCash;
if (addCollecting > 0 && bonus != null)
{
var newReward = addCollecting / Magnification;
DOTween.To(() => newReward, x => newReward = x, addCollecting, duration2).OnUpdate(() =>
{
reward_extra.text_num.text = $"x{newReward}";
}).SetId("AddCash");
}
DOTween.To(() => progress, x => progress = x, 1f, duration2).OnUpdate(() =>
{
text_gold_num.text = ConvertTools.GetNumberString2((int)(newCash + addCash * progress));
text_num_buff.text = text_gold_num.text;
}).SetId("AddCash");
}
else
{
anim_panel.Play("info_show_1");
}
if (glodBuff > 0.001f)
{
fx_ui_blingbling_01.gameObject.SetActive(true);
}
VibrationData();
fishingRewardSocial.ShowSocial(isSocial);
}
}
async void VibrationData()
{
await Awaiters.Seconds(2.5f);
if (curRateIndex >= _tables.TbGlobalConfig.RankVibration.Count)
curRateIndex = _tables.TbGlobalConfig.RankVibration.Count - 1;
int hapticType = _tables.TbGlobalConfig.RankVibration[curRateIndex];
if (hapticType == 1)
{
GContext.Publish(new VibrationData(HapticTypes.LightImpact));
}
else if (hapticType == 2)
{
GContext.Publish(new VibrationData(HapticTypes.MediumImpact));
}
else if (hapticType == 3)
{
GContext.Publish(new VibrationData(HapticTypes.HeavyImpact));
}
}
private float _fishScore;
void OnBackClick()
{
go_fishPhoto.gameObject.SetActive(false);
root_success.alpha = 1;
GContext.Publish(new FishRotateEvent(0, 5, fishingData.rodType));
SetFishingFocalVolume(50);
}
async void OnCaptureFishPhoto()
{
var fishName = fishingData.curFishData.Name_l10n_key;
//斤
var fishWeight = fishingData.fishWeight;
//Load Photo UI
var go = Instantiate(prefab_cameraCapture);
var captrue = go.transform.GetComponent<FishPhotoCaptrue>();
await Awaiters.NextFrame;
captrue.Init(fishName, fishWeight);
GContext.Publish(new FishRotateEvent(45, 3, fishingData.rodType));
go_fishPhoto.gameObject.SetActive(true);
await captrue.RenderImage(_rt);
Texture2D texture2D = new Texture2D(_rt.width, _rt.height, TextureFormat.RGB24, false);
var currentRt = RenderTexture.active;
RenderTexture.active = _rt;
texture2D.ReadPixels(new Rect(0, 0, _rt.width, _rt.height), 0, 0);
texture2D.Apply();
root_success.alpha = 0;
GContext.Publish(new FishRotateEvent(0, 4, fishingData.rodType));
Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, _rt.width, _rt.height), new Vector2(0.5f, 0.5f));
byte[] bytes = texture2D.EncodeToPNG();
go_fishPhoto.SetData(sprite, bytes);
Destroy(go);
RenderTexture.active = currentRt;
SetFishingFocalVolume(300);
}
void SetFishingFocalVolume(float value)
{
var stage = RootCtx.container.Resolve<IStageService>()?.GetStage("FishingStage");
if (stage != null && stage.Id == "FishingStage")
{
var act = stage.CurrentAct as FishingAct;
if (act != null)
act.SetFishingFocalVolume(value);
}
}
private void EnableFishingBlur(bool enable)
{
var stage = RootCtx.container.Resolve<IStageService>()?.GetStage("FishingStage");
if (stage != null && stage.Id == "FishingStage")
{
var act = stage.CurrentAct as FishingAct;
if (act != null)
act.EnableFishingVolume(enabled);
}
}
IEnumerator AddCash()
{
text_gold_num.text = "";
text_num_buff.text = text_gold_num.text;
text_weight_num.text = "";
text_pound.text = "";
var progress = 0f;
int cash = add / Magnification;
yield return Awaiters.Seconds(waitTime1);
DOTween.To(() => progress, x => progress = x, 1, duration1).OnUpdate(() =>
{
text_weight_num.text = LocalizationMgr.GetFormatTextValue("UI_FishingRewardPanel_101014",
ConvertTools.GetNumberString2((int)(_fishScore * progress)));
text_pound.text = LocalizationMgr.GetWeight(fishingData.fishWeight * progress, true);
text_gold_num.text = ConvertTools.GetNumberString2((int)(cash * progress));
text_num_buff.text = text_gold_num.text;
})
.SetId("AddCash")
.OnComplete(() =>
{
text_pound.text = LocalizationMgr.GetWeight(fishingData.fishWeight);
}
);
}
async void SetTextTitleAsync(float ExtraPoint, bool isSpecialFish)
{
//GContext.container.Resolve<IUIService>().SetImagprite(bg_title, Define.SuccessTitle[fishingData.curFishData.Quality - 1], PanelName);
text_title.text = LocalizationMgr.GetText(fishingData.curFishData.Name_l10n_key);
curRateIndex = 0;
var etor = fishingGrade.GetEnumerator();
if (isSpecialFish)
etor = fishingSpGrade.GetEnumerator();
etor.MoveNext();
string curRate = etor.Current.Key;
do
{
if (ExtraPoint < etor.Current.Value - 0.001)
{
break;
}
curRateIndex++;
curRate = etor.Current.Key;
}
while (etor.MoveNext());
await Addressables.InstantiateAsync(curRate, icon_rate).Task;
}
bool _newRecord;
void SetFishWeight(float fishWeight)
{
playerFishData.SetGetFishCount(fishID);
float max = playerFishData.GetDataMaxWeight(fishID);
bool isNew = max < 0.00001f;
if (isNew)
{
isSocial = true;
new_go.SetActive(true); //新鱼
newFish.text = LocalizationMgr.GetText("UI_FishingRewardPanel_101015");
}
else if (fishWeight > max)
{
isSocial = true;
new_go.SetActive(true);
newFish.text = LocalizationMgr.GetText("UI_FishingRewardPanel_101016");
}
//need local language
playerFishData.SetWeight(fishID, fishWeight);
playerFishData.AddTotalWeight(fishID, fishWeight * Magnification);
uiService.SetImageSprite(img_fishTag, "icon_fish_rate_tag_" + fishingData.curFishData.Quality);
if (fishingData.curFishData.Quality >= 4)
{
isSocial = true;
GContext.Publish(new ConditionTypeEvent(ConditionType.GetBoosFish, Magnification));
if (fishingData.curFishData.Quality == 4 || fishingData.curFishData.Quality == 5)
{
GContext.Publish(new ConditionTypeEvent(ConditionType.GetBiggerThanHugeFishCount, Magnification));
}
}
_newRecord = fishWeight > max;
}
//设置熟练度
float SetProficiency(float proficiency, float proficiencyExtra)
{
int Quality = fishingData.curFishData.Quality;
if (Quality > 6)
{
Quality = 6;
}
float extra1 = fishingData.WeightIncEvent;// Mathf.RoundToInt(proficiency * fishingData.WeightIncEvent);
float extra2 = 0;
if (!fishingData.IsNewItemFish())
{
proficiencyExtra = (1 + fishingData.WeightIncEvent) * (1 + proficiencyExtra);
}
else
{
proficiencyExtra = (1 + proficiencyExtra) * (1 + playerData.benefitsEventFishCashMag);
}
playerFishData.SetRate(fishID, proficiencyExtra * fishingData.random);
proficiency *= proficiencyExtra;
proficiency = Mathf.RoundToInt(proficiency);
playerFishData.SetMaxMastery(fishID, (int)proficiency);
GContext.container.Resolve<FishingChallengeManager>().AddScoreByQuality(Quality, proficiency);
playerFishData.AddTotalMastery(fishID, (int)proficiency);
_fishScore = proficiency;
return proficiencyExtra;
}
void OnFail()
{
GContext.Publish(new PlayNewItemFxEvent() { type = 2 });
text_tryagain_num.text = LocalizationMgr.GetText("UI_FishingRewardPanel_101022");
text_info.text = LocalizationMgr.GetFormatTextValue("UI_FishingRewardPanel_101008", fishingData.curFishData.Quality);
station_powerful.SetActive(false);
station_weekly.SetActive(false);
station_more.SetActive(false);
station_nopush.SetActive(false);
if ((_tables.TbGlobalConfig.FailWithoutEnergyConsuming <=
playerFishData.GetAnglingCount()
|| playerData.lastMapId != _tables.TbMapData.DataList[0].ID))
{
//text_tryagain_num.gameObject.SetActive(true);
//text_tryagain_num.text = playerData.GetMagnification().ToString();
station_advert.SetActive(true);
target_info.SetActive(addCollecting > 0);
if (addCollecting > 0)
{
Item item = _tables.TbItem.GetOrDefault(curCollectingID);
if (item != null)
{
GContext.container.Resolve<IUIService>().SetImageSprite(target_info_icon, item.Icon);
}
}
btn_green.transform.parent.gameObject.SetActive(false);
//text_tryagain_num.gameObject.SetActive(false);
SetAdvertPanel();
fishIconRT.transform.localPosition = Vector3.right * 10000;
var fishData = GContext.container.Resolve<Tables>().TbFishData.GetOrDefault(fishingData.fishItem.RedirectID);
fishIconRT.SetData(rawImage, fishData);
var AquariumBg = transform.Find($"root_fail/station_advert/root_fish/mask_bg2/{fishingData.curMapData.AquariumBg}");
if (AquariumBg != null)
{
AquariumBg.gameObject.SetActive(true);
}
uiService.SetImageSprite(icon_rate_advert, $"icon_fish_rate_tag_{fishData.Quality}", BasePanel.PanelName);
//uiService.SetImageSprite(bg_advert, fishingData.curMapData.AquariumBg, BasePanel.PanelName);
}
else
{
btn_green.transform.parent.gameObject.SetActive(true);
OnClickAdvertClose(true);
//text_tryagain_num.gameObject.SetActive(false);
}
}
void SetAdvertPanel()
{
EnergyDef energyDef = _tables.TbEnergyDef.DataList[playerData.magnification];
if (energyDef.Mag > energyDef.RetryCost)
{
btn_tryagain_go.SetActive(false);
btn_discount_go.SetActive(true);
float cost = (energyDef.Mag - energyDef.RetryCost) * 100f / energyDef.Mag;
int costInt = (int)Mathf.Ceil(cost);
Debug.Log($"RetryCost {costInt} %:");
tag_text_num.text = $"{costInt}%";
text_old.text = Magnification.ToString();
text_discount_num.text = energyDef.RetryCost.ToString();
}
else
{
btn_tryagain_go.SetActive(true);
btn_discount_go.SetActive(false);
text_tryagain_num1.text = Magnification.ToString();
}
btn_close.onClick.RemoveAllListeners();
btn_close.onClick.AddListener(OnClickAdvertClose);
}
private void OnClickAdvertClose()
{
OnClickAdvertClose(false);
}
//第一次失败返回
void OnClickAdvertClose(bool isWithout)
{
station_advert.SetActive(false);
btn_close.onClick.RemoveAllListeners();
btn_close.onClick.AddListener(OnClickClose);
//station_more.SetActive(true);
switch (fishingData.fishingResult)
{
case FishingResult.Success:
break;
case FishingResult.Fail1:
station_powerful.SetActive(true);
break;
case FishingResult.Fail2:
station_weekly.SetActive(true);
break;
default:
station_more.SetActive(!isWithout);
station_nopush.SetActive(isWithout);
break;
}
}
public void OnTargetClosePanel()
{
StopAllCoroutines();
canvasGroup.blocksRaycasts = false;
if (fishingData.IsKeepsakeFish() && OpenSupplyDrop())
{
return;
}
GContext.Publish(new CheckTargetEvent() { itemID = fishingData.fishItem.ID });
GContext.Publish(new ResetFishingStatusEvent());
GContext.Publish(new IsRecastEvent());
RestartShowHomeUIEvent restartShowHomeUIEvent = new RestartShowHomeUIEvent();
GContext.Publish(restartShowHomeUIEvent);
UIManager.Instance.DestroyUI(UITypes.FishingRewardPanel);
}
void OnClickClose()
{
//前置条件达到礼包的解锁条件目前设定的20级
//触发条件:钓鱼失败后,若玩家仍然没有购买此礼包(仅限第一档),则弹出此礼包的拍脸
GContext.container.Resolve<TriggerPackData>().ShowTriggerPack(2, 4001011);
StopAllCoroutines();
canvasGroup.blocksRaycasts = false;
GContext.Publish(new ResetFishingStatusEvent());
GContext.Publish(new IsRecastEvent());
UIManager.Instance.DestroyUI(UITypes.FishingRewardPanel);
InHomePanel();
}
void OnClickInHome()
{
if (fishID > 0)
{
playerData.OpenAppraisePopupPanel(fishID);
}
if (OpenSupplyDrop())
{
return;
}
OnClosePanel();
InHomePanel();
}
bool OpenSupplyDrop()
{
EnergyDef energyDef = _tables.TbEnergyDef.DataList[playerData.magnification];
if (energyDef.SupplyDrop <= 0)
{
return false;
}
SupplyDrop supplyDrop = _tables.TbSupplyDrop[energyDef.SupplyDrop];
int index = 0;
if (fishingData.fixedFishList != null)
{
if (fishingData.fixedFishList.SupplyDrop < 0)
{
return false;
}
index = fishingData.fixedFishList.SupplyDropIndex;
}
else
{
float random = UnityEngine.Random.Range(0, 1f);
if (random > supplyDrop.Prob && playerData.SupplyDropIndex == -1)
{
return false;
}
//开始空投
var supplyDropTypeWeight = supplyDrop.DropWeight;
float allWeight = supplyDropTypeWeight.Sum();
random = UnityEngine.Random.Range(0, allWeight);
allWeight = 0;
for (int i = 0; i < supplyDropTypeWeight.Count; i++)
{
allWeight += supplyDropTypeWeight[i];
if (random <= allWeight)
{
index = i;
break;
}
}
}
if (playerData.SupplyDropIndex >= 0)
{
index = playerData.SupplyDropIndex;
playerData.SupplyDropIndex = -1;
}
if (index < 0 || index >= supplyDrop.DropID.Count)
{
Debug.LogWarning("空投配置错误:" + index);
return false;
}
//开始空投
int supplyDropDropId = supplyDrop.DropID[index];
int fbxID = supplyDrop.FbxID[index];
SupplyDropFbx supplyDropFbx = _tables.TbSupplyDropFbx.GetOrDefault(fbxID);
SupplyDropCtrl supplyDropCtrl = new SupplyDropCtrl();
fishingData.supplyDropCtrl = supplyDropCtrl;
supplyDropCtrl.InitData(supplyDrop.ID, supplyDropFbx,
supplyDrop.Prefab,
supplyDropDropId,
fishingData.fishItem.ID,
fishingData.fishItem.SubType,
fishingData.fishingBehaviorConf);
OnClosePanel();
#if AGG
using (var e = GEvent.GameEvent("supplydrop"))
{
e.AddContent("energy_bet", energyDef.SupplyDrop)
.AddContent("supplydrop_type", index + 1);
}
#endif
return true;
}
void OnClosePanel()
{
StopAllCoroutines();
canvasGroup.blocksRaycasts = false;
GContext.Publish(new ResetFishingStatusEvent());
GContext.Publish(new IsRecastEvent());
UIManager.Instance.DestroyUI(UITypes.FishingRewardPanel);
}
void InHomePanel()
{
RestartShowHomeUIEvent restartShowHomeUIEvent = new RestartShowHomeUIEvent();
restartShowHomeUIEvent.isPopupStore = true;
GContext.Publish(restartShowHomeUIEvent);
}
protected override void OnDestroy()
{
//ConvertTools.SetFSBlur(false);
EnableFishingBlur(false);
GContext.Publish(new PlayNewItemFxEvent() { type = 2 });
StopNewItemAudio();
StopNewItemAudioReward();
_rt.Release();
_rt = null;
isEnable = false;
DOTween.Kill("AddCash");
if (FxRewardLastingHandle.IsValid())
{
Addressables.Release(FxRewardLastingHandle);
}
if (FxRewardLastingGo != null)
{
Destroy(FxRewardLastingGo);
}
base.OnDestroy();
}
//新的失败相关
async void InFishRod()
{
await UIManager.Instance.ShowUI(UITypes.FishingRodBagPanel);
OnClosePanel();
GContext.Publish(new MapShowEvent() { isShow = false });
}
async void InMap()
{
await UIManager.Instance.ShowUI(UITypes.FishingMapPanel);
OnClosePanel();
GContext.Publish(new MapShowEvent() { isShow = false });
}
async void InInfo()
{
await UIManager.Instance.ShowUI(UITypes.FishingRewardInfoPopupPanel);
OnClosePanel();
}
void OnClickPlay()
{
if (playerData.GetCanMagnification() == false)
{
//取消自动钓鱼
GContext.Publish(new VibrationData(HapticTypes.Failure));
OnPlayFailed();
#if AGG
using (var e = GEvent.GameEvent("lack_resources"))
{
e.AddContent("item_id", 1001)
.AddContent("lv", playerData.lv);
}
#endif
}
else
{
fishingData.IsFree = false;
fishingData.IsRetry = true;
fishingData.retry_ways = 1;
OnSucceed();
}
}
async void OnPlayFailed()
{
if (GContext.container.Resolve<PlayerShopData>().IsShopOpen)
{
await UIManager.Instance.ShowUI(UITypes.LackOfResourcePopupPanel);
}
}
void ResourceCloseEvent()
{
OnClosePanel();
GContext.Publish(new MapShowEvent() { isShow = false });
}
void OnAdsSucceed()
{
fishingData.IsRetry = true;
fishingData.IsFree = true;
fishingData.retry_ways = 2;
GContext.container.Resolve<TriggerPackData>().TriggerAdsPack();
OnSucceed();
}
async void OnSucceed()
{
canvasGroup.blocksRaycasts = false;
GContext.Publish(new ResetFishingStatusEvent() { restart = true });
GContext.Publish(new IsRecastEvent() { isRecast = true });
await UIManager.Instance.ShowUI(UITypes.FishingPanel);
UIManager.Instance.DestroyUI(UITypes.FishingRewardPanel);
}
//特殊技能音效
async void PlayAudioRewardFish()
{
if (!string.IsNullOrEmpty(fishingData.AudioRewardFish))
{
NewItemAudio = await Addressables.LoadAssetAsync<AudioClip>(fishingData.AudioRewardFish).Task;
PlayNewItemAudio();
fishingData.AudioRewardFish = "";
}
}
Sound soundNewItem;
AudioClip NewItemAudio;
Sound soundNewItemReward;
AudioClip NewItemAudioReward;
void StopNewItemAudio()
{
if (soundNewItem)
{
soundNewItem.audioSource.Stop();
soundNewItem.ReturnPool();
soundNewItem = null;
}
}
void PlayNewItemAudio()
{
StopNewItemAudio();
soundNewItem = GContext.container.Resolve<ISoundService>().GetNewFishingSound(NewItemAudio);
soundNewItem.audioSource.Play();
soundNewItem.audioSource.loop = true;
}
void StopNewItemAudioReward()
{
if (soundNewItemReward)
{
soundNewItemReward.audioSource.Stop();
soundNewItemReward.ReturnPool();
soundNewItemReward = null;
}
}
async void PlayNewItemAudioReward(string audioName)
{
NewItemAudioReward = await Addressables.LoadAssetAsync<AudioClip>(audioName).Task;
StopNewItemAudioReward();
soundNewItemReward = GContext.container.Resolve<ISoundService>().GetNewFishingSound(NewItemAudioReward);
soundNewItemReward.audioSource.Play();
//soundNewItem.audioSource.loop = true;
}
//目标奖励活动场景特效
AsyncOperationHandle<GameObject> FxRewardLastingHandle;
GameObject FxRewardLastingGo;
public void MaterialChange()
{
ETChangeMaterial eTDropAfterDrop = GContext.container.Resolve<CollectingData>().MaterialChange();
if (eTDropAfterDrop != null)
{
if (eTDropAfterDrop.FxRewardScene != "None")
{
FxRewardLastingHandle = Addressables.LoadAssetAsync<GameObject>(eTDropAfterDrop.FxRewardScene);
FxRewardLastingHandle.Completed += (obj) =>
{
if (!isEnable)
{
Addressables.Release(FxRewardLastingHandle);
return;
}
if (obj.Status == AsyncOperationStatus.Succeeded)
{
GameObject go = obj.Result;
FxRewardLastingGo = Instantiate(go);
}
};
}
return;
}
var etNewItem = GContext.container.Resolve<CollectingData>().ETNewItemFx();
if (etNewItem != null)
{
if (etNewItem.AudioReward.Count <= fishingData.NewIndex)
return;
string AudioName = etNewItem.AudioReward[fishingData.NewIndex];
if (AudioName != "None")
{
if (!string.IsNullOrEmpty(AudioName))
{
PlayNewItemAudioReward(AudioName);
}
//GContext.Publish(new EventUISound(AudioName));
}
//播放音效
return;
}
}
#if UNITY_EDITOR
string mapIndex = "0";
string fishIndex = "0";
string fishName = "0";
private void OnGUI()
{
int fontSize = 40;
GUI.skin.textField.fontSize = fontSize;
GUI.skin.button.fontSize = fontSize;
GUI.skin.label.fontSize = fontSize;
GUILayout.Label("mapIndex:");
mapIndex = GUILayout.TextField(mapIndex);
GUILayout.Label("fishIndex:");
fishIndex = GUILayout.TextField(fishIndex);
if (GUILayout.Button("ChangeFish"))
{
int index = int.Parse(mapIndex);
var MapDataList = _tables.TbMapData.DataList;
if (index >= MapDataList.Count)
{
index = 0;
mapIndex = index.ToString();
}
MapData mapData = _tables.TbMapData.DataList[index];
index = int.Parse(fishIndex);
var FishList = mapData.FishList;
if (index >= FishList.Count)
{
index = 0;
fishIndex = index.ToString();
}
int fishId = mapData.FishList[index];
LoadFish(fishId);
}
if (GUILayout.Button("上一个"))
{
int mapIndexInt = int.Parse(mapIndex);
var MapDataList = _tables.TbMapData.DataList;
if (mapIndexInt >= MapDataList.Count)
{
mapIndexInt = 0;
mapIndex = mapIndexInt.ToString();
}
MapData mapData = _tables.TbMapData.DataList[mapIndexInt];
int index = int.Parse(fishIndex);
index--;
var FishList = mapData.FishList;
if (index < 0)
{
mapIndexInt--;
if (mapIndexInt < 0)
{
mapIndexInt = MapDataList.Count - 1;
}
mapIndex = mapIndexInt.ToString();
index = FishList.Count - 1;
mapData = _tables.TbMapData.DataList[mapIndexInt];
}
fishIndex = index.ToString();
int fishId = mapData.FishList[index];
LoadFish(fishId);
}
if (GUILayout.Button("下一个"))
{
int mapIndexInt = int.Parse(mapIndex);
var MapDataList = _tables.TbMapData.DataList;
if (mapIndexInt >= MapDataList.Count)
{
mapIndexInt = 0;
mapIndex = mapIndexInt.ToString();
}
MapData mapData = _tables.TbMapData.DataList[mapIndexInt];
int index = int.Parse(fishIndex);
index++;
var FishList = mapData.FishList;
if (index >= FishList.Count)
{
mapIndexInt++;
if (mapIndexInt >= MapDataList.Count)
{
mapIndexInt = 0;
}
mapIndex = mapIndexInt.ToString();
index = 0;
mapData = _tables.TbMapData.DataList[mapIndexInt];
}
fishIndex = index.ToString();
int fishId = mapData.FishList[index];
LoadFish(fishId);
}
GUILayout.Space(10);
fishName = GUILayout.TextField(fishName);
if (GUILayout.Button("切换"))
{
GetFishingBehaviorB getFishingBehavior = new GetFishingBehaviorB();
GContext.Publish(getFishingBehavior);
FishingBehaviorB fishingBehavior = getFishingBehavior.fishingBehavior;
fishingBehavior.GMInitFishAsync(fishName, 1);
}
}
void LoadFish(int fishId)
{
FishData curFishData = _tables.GetFishData(fishId);
float _fishScale = curFishData.MinScale * curFishData.ReelingScale * curFishData.PullingScale;
GetFishingBehaviorB getFishingBehavior = new GetFishingBehaviorB();
GContext.Publish(getFishingBehavior);
FishingBehaviorB fishingBehavior = getFishingBehavior.fishingBehavior;
fishingBehavior.GMInitFishAsync(curFishData.Fbx, _fishScale);
}
#endif
}