当前位置: 首页>>代码示例>>C#>>正文


C# Container.ConsumeTotal方法代码示例

本文整理汇总了C#中Server.Items.Container.ConsumeTotal方法的典型用法代码示例。如果您正苦于以下问题:C# Container.ConsumeTotal方法的具体用法?C# Container.ConsumeTotal怎么用?C# Container.ConsumeTotal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Server.Items.Container的用法示例。


在下文中一共展示了Container.ConsumeTotal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Consume

        /// <summary>
        /// Tries to consume the given amount out of the total amount of currency in the provided container.
        /// Automatically redistributes coins.
        /// </summary>
        /// <param name="cont">the container to consume from</param>
        /// <param name="currencyType">the target currency to consume from</param>
        /// <param name="amount">the amount of the target currency to consume</param>
        /// <returns>true if the container has the exact amount of the currencyType, or if the container has enough total monies</returns>
        public static bool Consume( Container cont, Type currencyType, int amount )
        {
            if( cont == null )
                return false;

            if( cont.ConsumeTotal(currencyType, amount) )
                return true;

            int availableCopper = 0;
            Item[] coins = cont.FindItemsByType(AllCurrencies);

            //calculate monies as copper total
            for( int i = 0; i < coins.Length; i++ )
                availableCopper += ConvertTo(FindType(coins[i].GetType()), CurrencyType.Copper, coins[i].Amount);

            //if we have enough to pay...
            if( availableCopper >= amount )
            {
                //delete all the coins
                for( int i = 0; i < coins.Length; i++ )
                    coins[i].Consume(coins[i].Amount);

                availableCopper -= amount;

                //if we should still have money, redistribute
                if( availableCopper > 0 )
                    DistributeCoins(cont, Compress(availableCopper, 0, 0));

                return true;
            }

            return false;
        }
开发者ID:ITLongwell,项目名称:Ulmeta,代码行数:41,代码来源:Currency.cs

示例2: EndDryDock

        public void EndDryDock( Mobile from, Mobile master, Container bank )
        {
            if ( Deleted || CheckDecay() )
                return;

            DryDockResult result = CheckDryDock( from );

            /*if (result == DryDockResult.Dead)
                master.Say(true, "You appear to be dead.");
            //from.SendAsciiMessage("You appear to be dead."); // You appear to be dead.
            else if (result == DryDockResult.NoKey)
                master.Say(true, "You must have the key to the ship you wish to dock.");
            //from.SendAsciiMessage("You must have a key to the ship to dock the boat."); // You must have a key to the ship to dock the boat.
            else if (result == DryDockResult.NotAnchored)
                from.SendAsciiMessage("You must lower the anchor to dock the boat."); // You must lower the anchor to dock the boat.
            else if (result == DryDockResult.Mobiles)
                master.Say(true, "Make sure the deck is clear and the hold is empty.");
            //from.SendAsciiMessage("You cannot dock the ship with beings on board!"); // You cannot dock the ship with beings on board!
            else if (result == DryDockResult.Items)
                master.Say(true, "Make sure the deck is clear and the hold is empty.");
            //from.SendAsciiMessage("You cannot dock the ship with a cluttered deck."); // You cannot dock the ship with a cluttered deck.
            else if (result == DryDockResult.Hold)
                master.Say(true, "Make sure the deck is clear and the hold is empty.");
                //from.SendAsciiMessage("Make sure your hold is empty, and try again!"); // Make sure your hold is empty, and try again!*/

            if (result == DryDockResult.Dead)
                from.SendAsciiMessage("You appear to be dead."); // You appear to be dead.
            else if (result == DryDockResult.NoKey)
                from.SendAsciiMessage("You must have a key to the ship to dock the boat."); // You must have a key to the ship to dock the boat.
            else if (result == DryDockResult.NotAnchored)
                from.SendAsciiMessage("You must lower the anchor to dock the boat."); // You must lower the anchor to dock the boat.
            else if (result == DryDockResult.Mobiles)
                from.SendAsciiMessage("You cannot dock the ship with beings on board!"); // You cannot dock the ship with beings on board!
            else if (result == DryDockResult.Items)
                from.SendAsciiMessage("You cannot dock the ship with a cluttered deck."); // You cannot dock the ship with a cluttered deck.
            else if (result == DryDockResult.Hold)
                from.SendAsciiMessage("Make sure your hold is empty, and try again!"); // Make sure your hold is empty, and try again!

            if ( result != DryDockResult.Valid )
                return;

            BaseDockedBoat boat = DockedBoat;

            if ( boat == null )
                return;

            RemoveKeys( from );

            from.AddToBackpack( boat );
            Delete();
            bank.ConsumeTotal(typeof(Gold), 25);
            master.Say(true, "Here is your claim ticket.  I suggest you store it in your safety deposit box for safety.");
        }
开发者ID:Godkong,项目名称:Origins,代码行数:53,代码来源:BaseBoat.cs

示例3: Consume

		//this performs a consume operation on a list of source items.  Since resources can be distributed among different items,
		//this handles a distributed search and take operation
		public static bool Consume( Container pack, Type[] types, int[] amounts )
		{
			//check if there are any BaseStoreKey or MasterItemStoreKey objects in the caster's backpack
			Item[] keysources = pack.FindItemsByType( new Type[]{ typeof( BaseStoreKey ), typeof( MasterItemStoreKey ) } );
			
			if( keysources == null || types == null || amounts == null )
			{
				return false;
			}
			
			//a list of any items that are found in the backpack after they were not found in the keys
			List<Type> backpacksources = new List<Type>();
			
			//the corresponding amounts to be withdrawn from the items found in the backpack
			List<int> backpackwithdrawamounts = new List<int>();
			
			
			//boolean array flag used to indicate which types have been found while in the middle of scanning all sources
			bool[] foundentries = new bool[ types.Length ];
			
			List<StoreEntry> consumeentries = new List<StoreEntry>();
			
			//go thru the list of found objects			
			foreach( Item key in keysources )
			{
				//utilizes IItemStoreObject interface function, defined by keys
				if( key is IItemStoreObject )
				{
					//scan this object for any usable candidates to withdraw from
					consumeentries.AddRange( ((IItemStoreObject)key).FindConsumableEntries( types, amounts, ref foundentries ) );
					
					//check if we're done
					if( consumeentries.Count == types.Length )
					{
						break;
					}
				}
			}
			
			//check if the operation was complete.  If not, look for any more in the backpack
			if( consumeentries.Count < types.Length )
			{
				for( int i = 0; i < types.Length; i++ )
				{
					//if this isn't found yet
					if( !foundentries[i] )
					{
						//find any item, and check if there's enough to consume
						
						Item[] items = pack.FindItemsByType( types[i] );

						int total = 0;
			
						for ( int j = 0; j < items.Length; j++ )
						{
							total += items[j].Amount;
						}
			
						//make sure the total found is sufficient
						if ( total >= amounts[i] )
						{
							//add this source to the list to be extracted from the backpack
							backpacksources.Add( types[i] );
							backpackwithdrawamounts.Add( amounts[i] );
							foundentries[i] = true;
						}
					}
				}
				
				//second pass, check if scanning the backpack has given us enough now	
				if( consumeentries.Count + backpacksources.Count < types.Length )
				{
					return false;
				}
			}
					
			//if we found everything we need, then consume them
			
			//perform the consumption from backpack
			foreach( StoreEntry entry in consumeentries )
			{
				entry.Consume(); 
				entry.RefreshParentGump();
			}
			
			//perform the consumption from backpack (if it was necessary)
			for( int i = 0; i < backpacksources.Count; i++ )
			{
				pack.ConsumeTotal( backpacksources[i], backpackwithdrawamounts[i] );
			}
			
			return true;
		}//static consume
开发者ID:greeduomacro,项目名称:cov-shard-svn-1,代码行数:95,代码来源:BaseStoreKey.cs

示例4: Cook

 public static void Cook(TreeResourceItem resource, Mobile from, HarvestSuccessRating rating, TreeProduct product,
     Container pack)
 {
     switch (rating)
     {
         case HarvestSuccessRating.PartialSuccess:
         case HarvestSuccessRating.Success:
         {
             TreeProductItem item = new TreeProductItem(product);
             if (item.ItemID == 0x183B && !pack.ConsumeTotal(typeof (LargeEmptyFlask), 1))
             {
                 from.SendMessage(
                     "You need an empty flask in your pack to store the {0}. The resource was lost.", item.Name);
                 resource.Consume(1);
                 item.Delete();
             }
             else if (item.ItemID == 0x1604 && !pack.ConsumeTotal(typeof (EmptyWoodenBowl), 1))
             {
                 from.SendMessage(
                     "You need an empty bowl in your pack to store the {0}. The resource was lost.", item.Name);
                 resource.Consume(1);
                 item.Delete();
             }
             else if (from.AddToBackpack(item) || item.DropToWorld(from, from.Location))
             {
                 from.SendMessage("You cook the resource and turn it in to {0}.", item.Name);
                 resource.Consume(1);
             }
             else
             {
                 from.SendMessage("Unable to create the {0}.", item.Name);
                 item.Delete();
             }
             break;
         }
         case HarvestSuccessRating.Failure:
         {
             from.SendMessage("You fail to cook the resource.");
             break;
         }
     }
 }
开发者ID:greeduomacro,项目名称:RuneUO,代码行数:42,代码来源:TreeResources.cs


注:本文中的Server.Items.Container.ConsumeTotal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。