Example #1
0
 public IEnumerator Collect(Resource target, int fuel, int metal)
 {
     yield return AimAtPosition(target.transform.WorldCenterOfElement());
     var elapsedTime = Mathf.Max((fuel * Settings.Replay.FuelMultiplier + metal * Settings.Replay.MetalMultiplier) / Settings.Replay.CollectRate, 0.1f);
     target.StartCoroutine(target.Beam(this, elapsedTime, BeamType.Collect));
     yield return new WaitForSeconds((transform.TransformPoint(Center()) - target.transform.WorldCenterOfElement()).magnitude / Settings.Replay.BeamSpeed);
     target.FlashingOn();
     var score = (fuel + metal) >= Constants.Score.ValidCollectionThreshold ? Constants.Score.PerValidCollection : 0;
     var effectedFuel = 0;
     var effectedMetal = 0;
     var effectedScore = 0;
     for (float t, startTime = Time.time; (t = (Time.time - startTime) / elapsedTime) < 1;)
     {
         if (!Data.GamePaused)
         {
             var deltaFuel = Mathf.RoundToInt(fuel * t - effectedFuel);
             if (deltaFuel > 0)
             {
                 targetFuel += deltaFuel;
                 target.targetFuel -= deltaFuel;
                 effectedFuel += deltaFuel;
             }
             var deltaMetal = Mathf.RoundToInt(metal * t - effectedMetal);
             if (deltaMetal > 0)
             {
                 targetMetal += deltaMetal;
                 target.targetMetal -= deltaMetal;
                 effectedMetal += deltaMetal;
             }
             var deltaScore = Mathf.RoundToInt(score * t - effectedScore);
             if (deltaScore > 0)
             {
                 Data.Replay.TargetScores[team] += deltaScore;
                 effectedScore += deltaScore;
             }
         }
         yield return null;
     }
     targetFuel += fuel - effectedFuel;
     target.targetFuel -= fuel - effectedFuel;
     targetMetal += metal - effectedMetal;
     target.targetMetal -= metal - effectedMetal;
     target.FlashingOff();
     Data.Replay.TargetScores[team] += score - effectedScore;
     string message;
     if (metal == 0)
         message = fuel > 0 ? "F: +" + fuel : "0";
     else
         message = (fuel > 0 ? "F: +" + fuel + "  " : "") + "M: +" + metal;
     yield return StartCoroutine(Data.Replay.Instance.ShowMessageAt(this, message));
     --Data.Replay.CollectsLeft;
 }