/// <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())); }
public Core.Game.Shopping.Order DoOrder(long shopId, Shop.ShopItem purchasingItem, World world) { Core.Game.Shopping.Order order = new Core.Game.Shopping.Order(purchasingItem, world.LogicTime); m_shopFindTable[shopId].Order(order); m_orderHistory.Add(order); return(order); }
public void RequestDeliver(World world, Core.Game.Shopping.Order deliveringOrder) { Shop.Delivery delivery = new Shop.Delivery(); delivery.deliveryingOrder = deliveringOrder; delivery.deliveryDate = Core.Common.GameLogicTime.FromDays(world.LogicTime.TotalDays + 1); deliveringOrder.orderState = Core.Game.Shopping.OrderState.kDelivering; m_processingDeliveries.Add(delivery); }
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> /// Update state of order and return is ready to deliver. /// </summary> /// <param name="order">Updating order</param> /// <param name="worldState">Current world state</param> /// <returns>Whether is ready to deliver</returns> public bool UpdateOrder(Core.Game.Shopping.Order order, Core.Interface.IWorldState worldState) { switch (order.orderState) { case Core.Game.Shopping.OrderState.kPlaced: if (m_workDays.Contains(worldState.LogicTime.DayOfWeek)) { if (worldState.LogicTime.Hours >= 9 && worldState.LogicTime.Hours < 18) { order.orderState = Core.Game.Shopping.OrderState.kManufactoring; m_manufactoringTable.Add(order.serialNumber, worldState.LogicTime + Core.Common.GameLogicTime.FromHours(28)); } } return(false); case Core.Game.Shopping.OrderState.kManufactoring: bool isFinished = true; if (m_manufactoringTable.ContainsKey(order.serialNumber)) { if (m_manufactoringTable[order.serialNumber] <= worldState.LogicTime) { m_manufactoringTable.Remove(order.serialNumber); order.orderItem = order.orderedShopItem.Generate(worldState); } else { isFinished = false; } } if (isFinished) { if (worldState.LogicTime.Hours >= 9 && worldState.LogicTime.Hours < 18) { order.orderState = Core.Game.Shopping.OrderState.kWaitSending; return(true); } } return(false); } return(true); }
public void Order(Core.Game.Shopping.Order order) { m_processingOrders.Add(order); }