本文整理汇总了C#中IContainer.RemoveQuantity方法的典型用法代码示例。如果您正苦于以下问题:C# IContainer.RemoveQuantity方法的具体用法?C# IContainer.RemoveQuantity怎么用?C# IContainer.RemoveQuantity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContainer
的用法示例。
在下文中一共展示了IContainer.RemoveQuantity方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddQuantity
public double AddQuantity(IContainer pullFrom, double amount, bool exactAmountOnly)
{
lock (_lock)
{
double actualAmount = amount;
// See if I can handle that much
double max = _quantityMax_Usable ?? _quantityMax;
if (_quantityCurrent + actualAmount > max)
{
actualAmount = max - _quantityCurrent;
}
if (exactAmountOnly && !Math1D.IsNearValue(actualAmount, amount))
{
actualAmount = 0d;
}
if (actualAmount != 0d)
{
// Now try to pull that much out of the source container
actualAmount -= pullFrom.RemoveQuantity(actualAmount, exactAmountOnly);
// Add the value
_quantityCurrent += actualAmount;
}
// Exit function
return amount - actualAmount;
}
}
示例2: AddQuantity_priv
private double AddQuantity_priv(IContainer pullFrom, double amount, bool exactAmountOnly)
{
if (pullFrom is ITakesDamage && ((ITakesDamage)pullFrom).IsDestroyed)
{
return 0d;
}
double current = GetQuantityCurrent();
double max = GetQuantityMax().Item1; // using the destroyed aware max
double actualAmount = amount;
// See if I can handle that much
if (current + actualAmount > max)
{
actualAmount = max - current;
}
if (exactAmountOnly && !Math1D.IsNearValue(actualAmount, amount))
{
actualAmount = 0d;
}
if (actualAmount != 0d)
{
// Now try to pull that much out of the source container
actualAmount -= pullFrom.RemoveQuantity(actualAmount, exactAmountOnly);
if (actualAmount != 0d)
{
#region Add it
// Ensure that the containers are equalized
switch (_ownership)
{
case ContainerOwnershipType.GroupIsSoleOwner:
// Nothing to do
break;
case ContainerOwnershipType.QuantitiesCanChange:
EqualizeContainers(false);
break;
case ContainerOwnershipType.QuantitiesMaxesCanChange:
EqualizeContainers(true);
break;
default:
throw new ApplicationException("Unknown ContainerOwnershipType: " + _ownership.ToString());
}
// Add the value evenly
for (int cntr = 0; cntr < _containers.Count; cntr++)
{
if (!_destroyed[cntr])
{
_containers[cntr].Item1.QuantityCurrent += actualAmount * _ratios[cntr].Item1; // using the destroyed aware ratio
}
}
// Cache the new value (this is used if sole owner)
_current = current + actualAmount;
#endregion
}
}
// Exit function
return amount - actualAmount;
}
示例3: AddPoisonSprtContainer
private static bool AddPoisonSprtContainer(ref double mass, IContainer container, double ratio)
{
if (container == null)
{
return false;
}
double needed = mass * ratio;
double unmet = container.RemoveQuantity(needed, false);
// If unmet is zero, then there was enough in this container
if (Math1D.IsNearZero(unmet))
{
mass = 0d;
return true;
}
// Reduce mass by the amount removed
double removed = needed - unmet;
mass -= removed * (1d / ratio);
return false;
}
示例4: Transfer
public static double Transfer(IContainer source, double amountToPull, IContainer destination, double conversionRate, bool exactAmountOnly)
{
//NOTE: If the containers are being manipulated outside this thread, the transfer won't be accurate (but this method will likely
//be called from a timer, so the transfer amounts would be somewhat small. So small blips of innacuracy shouldn't be too bad)
double requestAmountToPull;
// See if the amount to pull passed in is more than what the source class holds
if (amountToPull > source.QuantityCurrent)
{
if (exactAmountOnly)
{
return amountToPull;
}
requestAmountToPull = source.QuantityCurrent;
}
else
{
requestAmountToPull = amountToPull;
}
// If source only allows multiples to be pulled, then get a multiple it likes
requestAmountToPull = Container.GetRemoveAmount(source, requestAmountToPull, exactAmountOnly);
if (requestAmountToPull == 0d)
{
return amountToPull;
}
// Figure out how much can actually be pulled, and what that equates to
double actualAmountToPull;
double actualAmountToPush;
GetMaxAmountToPull(out actualAmountToPull, out actualAmountToPush, requestAmountToPull, destination.QuantityMaxMinusCurrent, conversionRate, exactAmountOnly);
if (actualAmountToPull != requestAmountToPull && source.OnlyRemoveMultiples)
{
// The destination couldn't hold it all, try again
actualAmountToPull = Container.GetRemoveAmount(source, actualAmountToPull, exactAmountOnly);
GetMaxAmountToPull(out actualAmountToPull, out actualAmountToPush, requestAmountToPull, destination.QuantityMaxMinusCurrent, conversionRate, exactAmountOnly);
}
if (actualAmountToPull > 0d)
{
// Pull this from the source
source.RemoveQuantity(actualAmountToPull, exactAmountOnly);
// Add this to the destination
destination.AddQuantity(actualAmountToPush, exactAmountOnly);
}
// Return how much of the source couldn't be used
return amountToPull - actualAmountToPull;
}
示例5: AddQuantity
public double AddQuantity(IContainer pullFrom, double amount, bool exactAmountOnly)
{
double actualAmount = amount;
// See if I can handle that much
if (_quantityCurrent + actualAmount > _quantityMax)
{
actualAmount = _quantityMax - _quantityCurrent;
}
if (exactAmountOnly && actualAmount != amount)
{
actualAmount = 0d;
}
if (actualAmount != 0d)
{
// Now try to pull that much out of the source container
actualAmount -= pullFrom.RemoveQuantity(actualAmount, exactAmountOnly);
// Add the value
_quantityCurrent += actualAmount;
}
// Exit function
return amount - actualAmount;
}