/// <summary>
        /// Process a shopping command in the world
        /// </summary>
        /// <param name="world">Processing world</param>
        /// <param name="command">Command to process</param>
        /// <returns></returns>
        public Core.CommandResult ProcessCommand(World world, Core.LogicCommands.ShoppingCommand command)
        {
            switch (command.CommandType)
            {
            case Core.LogicCommands.ShoppingCommandType.kBuy:
                Core.LogicCommands.ShoppingPurchaseCommand purchaseCommand = command as Core.LogicCommands.ShoppingPurchaseCommand;
                ShopItem shopItem = world.Shoppings.FindShopItem(purchaseCommand.purchasingShopId, purchaseCommand.purchasingItemId);
                if (shopItem == null)
                {
                    return(new Core.CommandResult(false, new CommandFailReason_NoSuchShopItem()));
                }

                if (!world.Protagonist.SpendMoney((ulong)shopItem.Price))
                {
                    return(new Core.CommandResult(false, new CommandFailReason_NotEnoughMoney()));
                }

                Core.Game.Shopping.Order placedOrder = world.Shoppings.DoOrder(purchaseCommand.purchasingShopId, shopItem, world);

                return(new Core.CommandResult(true, null,
                                              new PurchaseCommandResult()
                {
                    placedOrder = placedOrder
                }));
            }

            return(new Core.CommandResult(false, new Processing.CommandFailReason_CannotProcess()));
        }
示例#2
0
        private void _ProcessFrameResultLogic(Core.LogicCommand frameCommand, Game.Processing.StepResult stepProcessResult)
        {
            if (frameCommand.CoarseType == Core.LogicCommand.CommandCoarseType.kShopping)
            {
                Core.LogicCommands.ShoppingCommand shoppingCommand = frameCommand as Core.LogicCommands.ShoppingCommand;
                if (shoppingCommand.CommandType == Core.LogicCommands.ShoppingCommandType.kBuy)
                {
                    if (stepProcessResult.commandResult.isSuccess)
                    {
                        Core.Game.Shopping.Order     order         = (stepProcessResult.commandResult.payloadData as Game.Shop.PurchaseCommandResult).placedOrder;
                        Core.Game.Shopping.IShopItem purchasedItem = order.orderedShopItem;

                        WriteLog(string.Format("(Order No. {0}) Purchaed \"{1}\" at {2} money.", order.serialNumber, purchasedItem.View.SellingItemName, purchasedItem.Price));
                        _SoundPlayPurchase();
                    }
                }
            }
            else if (frameCommand.CoarseType == Core.LogicCommand.CommandCoarseType.kBroadcasting)
            {
                if (stepProcessResult.commandResult.isSuccess)
                {
                    if (frameCommand is Game.Broadcasting.StartBroadcastingCommand)
                    {
                        _SetSoundStreamingOn();
                    }
                    else if (frameCommand is Game.Broadcasting.FinishBroadcastingCommand)
                    {
                        _SetSoundStreamingOff();
                    }
                }
            }

            // Process Receive
            if (stepProcessResult.receivedItems.Count > 0)
            {
                foreach (Core.Game.Item currentReceivedItem in stepProcessResult.receivedItems)
                {
                    m_inventoryUIWaitingQueue.Enqueue(new InventoryListItemEntry(currentReceivedItem));
                    WriteLog(string.Format("Item Received!! - {0}: {1}", currentReceivedItem.View.VisibleName, currentReceivedItem.View.Description));

                    ++m_itemCount;
                }

                _SoundPlayReceived();
            }
        }
        /// <summary>
        /// Apply command to the world
        /// </summary>
        /// <param name="targetWorld">Target world</param>
        /// <param name="stepCommand">Applying command</param>
        /// <returns>Result of command processing</returns>
        public Core.CommandResult ApplyCommand(World targetWorld, Core.LogicCommand stepCommand)
        {
            switch (stepCommand.CoarseType)
            {
            case Core.LogicCommand.CommandCoarseType.kIdle:
                return(Core.CommandResult.SimpleSuccess);

            case Core.LogicCommand.CommandCoarseType.kBroadcasting:
                Broadcasting.BroadcastingCommand broadcastingCommand = stepCommand as Broadcasting.BroadcastingCommand;
                return(broadcastingCommand.DoCommand(targetWorld));

            case Core.LogicCommand.CommandCoarseType.kShopping:
                Core.LogicCommands.ShoppingCommand shoppingCommand = stepCommand as Core.LogicCommands.ShoppingCommand;
                return(m_shoppingCommandProcessor.ProcessCommand(targetWorld, shoppingCommand));
            }

            return(new Core.CommandResult(false, new CommandFailReason_CannotProcess()));
        }