using System.Collections; using System.Collections.Generic; using System.Linq; using TMPro; using UnityEngine; using UnityEngine.UI; namespace Fateforge { public sealed partial class FateforgeApp { public string MotionPhase {get;private set;}="idle"; public double DisplayedScore {get;private set;} public double DisplayedPreviewTotal=>displayedTotal; public int PresentationGroupCount {get;private set;} bool scoreAnimating,presentationPaused,numbersRunning; float idlePulse; RectTransform motionLayer; RollingCounter pointsCounter,multiplierCounter,totalCounter,scoreCounter,runScoreCounter,coinCounter; readonly List presentationMatches=new List(); void InitializeMotion() { motionLayer=Ui.Rect(view.play,"PresentationEffects",0,0,750,1334);Ui.Stretch(motionLayer); pointsCounter=RollingCounter.Attach(view.previewPoints);multiplierCounter=RollingCounter.Attach(view.previewMultiplier);totalCounter=RollingCounter.Attach(view.previewTotal);scoreCounter=RollingCounter.Attach(view.score); runScoreCounter=RollingCounter.Attach(view.level); coinCounter=RollingCounter.Attach(view.coins); if(view.collectLever && view.collectLever.lever)view.collectLever.lever.gameObject.SetActive(false); } void UpdateMotion() { if(!HomeActive && activeSkill!="" && !Busy) { skillAge+=Delta; int index=activeSkill=="swap"?0:1; if(skillOrbs[index])skillOrbs[index].Show(true,true,skillAge); } if(HomeActive||Busy||Game==null||Game.State.stage!=Stage.Battle||MotionPhase!="idle"||presentationMatches.Count==0)return; idlePulse+=Delta;PaintGroups(presentationMatches,null,.035f+.025f*Mathf.Sin(idlePulse*2.6f),1); } void ResetPresentation() { numberEpoch++;numbersRunning=false;scoreAnimating=false;MotionPhase="idle";PresentationGroupCount=0;presentationMatches.Clear(); if(bossIntroduction){Destroy(bossIntroduction.gameObject);bossIntroduction=null;} if(motionLayer)Ui.Clear(motionLayer);if(view.connections)view.connections.Clear(); foreach(var card in cards.Values)if(card){var fx=card.GetComponent();if(fx)fx.ResetVisuals();} if(pointsCounter)pointsCounter.Cancel(displayedPoints);if(multiplierCounter)multiplierCounter.Cancel(displayedMultiplier);if(totalCounter)totalCounter.Cancel(displayedTotal); if(runScoreCounter && runScoreCounter.IsRolling) runScoreCounter.Finish(); if(coinCounter && coinCounter.IsRolling) coinCounter.Finish(); DisplayedScore=Game==null?0:Game.Board.score;if(scoreCounter)scoreCounter.Cancel(DisplayedScore); } CardMatchEffects CardEffects(CardView card) { var effects=card.GetComponent();if(!effects){effects=card.gameObject.AddComponent();effects.Configure(card,view.theme,view.art.Sprite("spark"));}return effects; } void PaintGroups(IEnumerable matches,Match focus=null,float pulse=0,float background=1) { var masks=new Dictionary();var focused=new HashSet(); foreach(var match in matches)foreach(int i in match.cells)if(i>=0&&i=0&&i=0 && first visible,Match match,int token,double points,double multiplier,bool settlement) { TMP_Text pointsLabel=null,multiplierLabel=null;Vector2 origin=Vector2.zero; var matched=match.cells.Where(i=>i>=0&&icards[Game.Board.cells[i].id]).ToArray(); if(matched.Length>0){foreach(var card in matched)origin+=MotionPoint(card.Rect);origin/=matched.Length;} if(settlement){pointsLabel=FloatingNumber("+"+English.Number(match.points),view.theme.cyan,origin+new Vector2(-44,22));multiplierLabel=FloatingNumber("+"+English.Multiplier(match.multiplier),new Color(1,.38f,.69f),origin+new Vector2(53,-12));} float duration=settlement?.58f:.30f,t=0;bool sent=false;Sound("match"); while(t=.54f){sent=true;RollNumbers(points,multiplier);}yield return null; } if(pointsLabel)Destroy(pointsLabel.gameObject);if(multiplierLabel)Destroy(multiplierLabel.gameObject); if(token==epoch&&!sent)RollNumbers(points,multiplier); } IEnumerator RevealMagnet(MagnetStep step,double priorPoints,double priorMultiplier,int token) { string name=view.art.Name(step.id); Message(name); PlayEffect(view.theme.magnetActivation,.85f); RollNumbers(step.points,step.multiplier); var slot=view.magnetRack.Find("Magnet_"+step.index) as RectTransform; if(!slot){yield return Delay(1.15f,token);yield break;} string effect=""; double points=step.points-priorPoints, multiplier=step.multiplier-priorMultiplier; if(points!=0)effect=(points>0?"+":"")+English.Number(points)+" points"; else if(System.Math.Abs(multiplier)>.00001)effect="+"+English.Multiplier(multiplier)+" mult"; else if(step.id=="ticket_or")effect="+"+Game.State.tickets.Count+" coins"; else if(step.id=="chevaliere")effect="+5 per matched card"; var origin=MotionPoint(slot); string lettering=""+name+""+(effect==""?"":"\n"+effect+""); var ribbon=Ui.Glyph(motionLayer,"MagnetActivation",UiGlyph.Shape.Ribbon,0,0,310,88,view.theme.gold); var display=ribbon.rectTransform;display.pivot=Vector2.one*.5f; var label=Ui.Text(display,"Lettering",lettering,0,2,253,82,27,view.theme); label.font=view.theme.titleFont;label.fontStyle=FontStyles.Bold|FontStyles.Italic; label.characterSpacing=1.5f;label.lineSpacing=-13; label.enableVertexGradient=true; label.colorGradient=new VertexGradient(Color.white,new Color(1,.96f,.73f),new Color(1,.67f,.31f),new Color(1,.85f,.49f)); label.color=Color.white;label.outlineColor=new Color32(49,13,32,255);label.outlineWidth=.17f; float width=Mathf.Clamp(label.GetPreferredValues(lettering).x+55,218,310); display.sizeDelta=new Vector2(width,88);label.rectTransform.sizeDelta=new Vector2(width-45,82); float margin=width*.55f+12; origin.x=Mathf.Clamp(origin.x,motionLayer.rect.xMin+margin,motionLayer.rect.xMax-margin); var fade=ribbon.gameObject.AddComponent();fade.blocksRaycasts=false; for(int side=-1;side<=1;side+=2) Ui.Glyph(display,"Spark",UiGlyph.Shape.Glint,side*(width/2-15),35,10,18,view.theme.gold); for(float t=0;t<1.15f && token==epoch;t+=Delta) { float u=Mathf.Clamp01(t/1.15f); display.localPosition=origin+Vector2.down*Mathf.Lerp(102,64,u); float pop=Mathf.Sin(Mathf.Clamp01(u/.30f)*Mathf.PI); display.localScale=Vector3.one*(.98f+.09f*pop); display.localRotation=Quaternion.Euler(0,0,2*pop); fade.alpha=Mathf.Min(1,u*14,(1-u)*5); slot.localScale=Vector3.one*(1+.16f*Mathf.Sin(Mathf.Clamp01(u*2)*Mathf.PI)); yield return null; } if(slot)slot.localScale=Vector3.one; if(ribbon)Destroy(ribbon.gameObject); } IEnumerator RollCounter(RollingCounter counter, long before, long after, int token, string prefix = "") { const float duration = .65f; counter.Begin(before, after, prefix); float elapsed = 0; while (elapsed < duration && token == epoch) { elapsed += Delta; counter.Sample(elapsed / duration); yield return null; } } IEnumerator TransferScore(ScoreResult result,int token) { MotionPhase="transfer";PaintGroups(result.matches);var starts=new List(); var matched=result.matches.SelectMany(m=>m.cells).Distinct().Where(i=>i>=0&&icards[Game.Board.cells[i].id]).ToArray(); Vector2 end=MotionPoint(view.score.rectTransform);int count=matched.Length==0?0:Mathf.Clamp(matched.Length*5,18,52); for(int i=0;i();streaks.Configure(starts.ToArray(),end); double from=DisplayedScore,to=result.hasScoreSnapshot?result.scoreAfter:Game.Board.score;scoreCounter.Begin(from,to,false);float t=0;const float duration=1.55f; int tick=0; while(ttick && progress<1){tick=beat;PlayEffect(view.theme.scoreTick,.50f);} streaks.Sample(u); view.score.rectTransform.localScale=Vector3.one*(1+.065f*Mathf.Sin(progress*Mathf.PI));yield return null; } if(streaks)Destroy(streaks.gameObject);view.score.rectTransform.localScale=Vector3.one; if(token==epoch){DisplayedScore=to;scoreCounter.Finish();scoreAnimating=false;if(from!=to)PlayEffect(view.theme.scoreImpact);} } } }