コード例 #1
0
        public void GiveResource(int amount)
        {
            amount = Util.ApplyPercentageModifiers(amount, resourceMultipliers.Select(m => m.GetModifier()));

            if (info.UseStorage)
            {
                if (info.DiscardExcessResources)
                {
                    amount = Math.Min(amount, playerResources.ResourceCapacity - playerResources.Resources);
                }

                playerResources.GiveResources(amount);
            }
            else
            {
                amount = playerResources.ChangeCash(amount);
            }

            foreach (var notify in self.World.ActorsWithTrait <INotifyResourceAccepted>())
            {
                if (notify.Actor.Owner != self.Owner)
                {
                    continue;
                }

                notify.Trait.OnResourceAccepted(notify.Actor, self, amount);
            }

            if (info.ShowTicks)
            {
                currentDisplayValue += amount;
            }
        }
コード例 #2
0
        public void GiveResource(int amount)
        {
            if (info.UseStorage)
            {
                if (info.DiscardExcessResources)
                {
                    amount = Math.Min(amount, playerResources.ResourceCapacity - playerResources.Resources);
                }
                playerResources.GiveResources(amount);
            }
            else
            {
                playerResources.GiveCash(amount);
            }

            var purifiers = self.World.ActorsWithTrait <IResourcePurifier>().Where(x => x.Actor.Owner == self.Owner).Select(x => x.Trait);

            foreach (var p in purifiers)
            {
                p.RefineAmount(amount);
            }

            if (info.ShowTicks)
            {
                currentDisplayValue += amount;
            }
        }
コード例 #3
0
ファイル: Refinery.cs プロジェクト: Blackbird88/OpenRA
 public void GiveResource(int amount)
 {
     playerResources.GiveResources(amount);
     if (info.ShowTicks)
     {
         currentDisplayValue += amount;
     }
 }
コード例 #4
0
 public void GiveResource(int amount)
 {
     if (info.DiscardExcessResources)
     {
         amount = Math.Min(amount, playerResources.ResourceCapacity - playerResources.Resources);
     }
     playerResources.GiveResources(amount);
     if (info.ShowTicks)
     {
         currentDisplayValue += amount;
     }
 }
コード例 #5
0
ファイル: Refinery.cs プロジェクト: AttacqueSuperior/Engine
        int IAcceptResources.AcceptResources(string resourceType, int count)
        {
            if (!playerResources.Info.ResourceValues.TryGetValue(resourceType, out var resourceValue))
            {
                return(0);
            }

            var value = Util.ApplyPercentageModifiers(count * resourceValue, resourceValueModifiers);

            if (info.UseStorage)
            {
                var storageLimit = Math.Max(playerResources.ResourceCapacity - playerResources.Resources, 0);
                if (!info.DiscardExcessResources)
                {
                    // Reduce amount if needed until it will fit the available storage
                    while (value > storageLimit)
                    {
                        value = Util.ApplyPercentageModifiers(--count * resourceValue, resourceValueModifiers);
                    }
                }
                else
                {
                    value = Math.Min(value, playerResources.ResourceCapacity - playerResources.Resources);
                }

                playerResources.GiveResources(value);
            }
            else
            {
                value = playerResources.ChangeCash(value);
            }

            foreach (var notify in self.World.ActorsWithTrait <INotifyResourceAccepted>())
            {
                if (notify.Actor.Owner != self.Owner)
                {
                    continue;
                }

                notify.Trait.OnResourceAccepted(notify.Actor, self, resourceType, count, value);
            }

            if (info.ShowTicks)
            {
                currentDisplayValue += value;
            }

            return(count);
        }
コード例 #6
0
ファイル: Refinery.cs プロジェクト: patrickwieth/ToW-Engine
        public void GiveResource(int amount)
        {
            amount = Util.ApplyPercentageModifiers(amount, resourceMultipliers.Select(m => m.GetModifier()));

            if (info.UseStorage)
            {
                if (info.DiscardExcessResources)
                {
                    amount = Math.Min(amount, playerResources.ResourceCapacity - playerResources.Resources);
                }

                playerResources.GiveResources(amount);
            }
            else
            {
                amount = playerResources.ChangeCash(amount);
            }

            foreach (var notify in self.World.ActorsWithTrait <INotifyResourceAccepted>())
            {
                if (notify.Actor.Owner != self.Owner)
                {
                    continue;
                }

                notify.Trait.OnResourceAccepted(notify.Actor, self, amount);
            }

            foreach (var rrd in refineryResourceDelivereds)
            {
                rrd.ResourceGiven(self, amount);
            }

            var purifiers = self.World.ActorsWithTrait <IResourcePurifier>().Where(x => x.Actor.Owner == self.Owner).Select(x => x.Trait);

            foreach (var p in purifiers)
            {
                p.RefineAmount(amount);
            }

            if (info.ShowTicks)
            {
                currentDisplayValue += amount;
            }
        }
コード例 #7
0
        void ModifyCash(Actor self, Player newOwner, int amount)
        {
            if (info.UseResourceStorage)
            {
                var initialAmount = resources.Resources;
                resources.GiveResources(amount);
                amount = resources.Resources - initialAmount;
            }
            else
            {
                amount = resources.ChangeCash(amount);
            }

            if (info.ShowTicks && amount != 0)
            {
                AddCashTick(self, amount);
            }
        }
コード例 #8
0
        public void GiveResource(int amount)
        {
            if (info.UseStorage)
            {
                if (info.DiscardExcessResources)
                {
                    amount = Math.Min(amount, playerResources.ResourceCapacity - playerResources.Resources);
                }

                playerResources.GiveResources(amount);
            }
            else
            {
                amount = playerResources.ChangeCash(amount);
            }

            if (info.ShowTicks)
            {
                currentDisplayValue += amount;
            }
        }