Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using OpenRA.Traits;
  3. using System;
  4. using OpenRA.Mods.Common.Effects;
  5.  
  6. namespace OpenRA.Mods.Common.Traits
  7. {
  8.     class BloodCashTricklerInfo : ITraitInfo
  9.     {
  10.         public readonly int Delay = 50;
  11.         public readonly int Percentage = 30;
  12.        
  13.         public object Create(ActorInitializer init) { return new BloodCashTrickler(init.Self, this); }
  14.     }
  15.  
  16.     class BloodCashTrickler : ITick, ISync
  17.     {
  18.         readonly BloodCashTricklerInfo info;
  19.         [Sync] int ticks;
  20.         List< Tuple<int,int> > timesAndBounties = new List<Tuple<int,int> >();
  21.         public BloodCashTrickler(Actor self, BloodCashTricklerInfo info)
  22.         {
  23.             this.info = info;
  24.         }
  25.  
  26.         public void Tick(Actor self)
  27.         {
  28.             ++ticks;
  29.             if (timesAndBounties.Count > 0 && ticks == timesAndBounties[0].Item1)
  30.             {
  31.                 var cash = timesAndBounties[0].Item2;
  32.                 timesAndBounties.RemoveAt(0);
  33.                 self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(cash);
  34.                 self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(cash), 30)));
  35.             }
  36.         }
  37.  
  38.         public void GiveBloodCash(int x)
  39.         {
  40.             timesAndBounties.Add(new Tuple<int,int>(ticks + info.Delay, x * info.Percentage / 100));
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement