예제 #1
0
 public void Aggregate(InventoryEvent inventoryEvent)
 {
     if (this.Items.TryGetValue(inventoryEvent.Id, out Item item))
     {
         // Updates dict record if item is found
         // Event types are validated in the orchestrator client so we will always get one of these two types
         if (inventoryEvent.Type == InventoryEventType.OnHandUpdate)
         {
             OnHandUpdate(inventoryEvent, item);
         }
         else if (inventoryEvent.Type == InventoryEventType.ShipmentUpdate)
         {
             ShipmentUpdate(inventoryEvent, item);
         }
     }
     else
     {
         //Creates new record in the dict with newly found item
         this.Items[inventoryEvent.Id] = new Item()
         {
             Id                    = inventoryEvent.Id,
             Upc                   = inventoryEvent.Upc,
             InventoryCount        = inventoryEvent.CountAdjustment,
             ProductName           = inventoryEvent.ProductName,
             Description           = inventoryEvent.Description,
             LastShipmentTimestamp = inventoryEvent.LastShipmentTimestamp,
             LastUpdateTimestamp   = inventoryEvent.LastUpdateTimestamp
         };
     }
 }
예제 #2
0
 private void OnHandUpdate(InventoryEvent incomingEvent, Item currentItem)
 {
     currentItem.InventoryCount      = incomingEvent.CountAdjustment;
     currentItem.ProductName         = incomingEvent.ProductName;
     currentItem.Description         = incomingEvent.Description;
     currentItem.LastUpdateTimestamp = incomingEvent.LastUpdateTimestamp;
 }
예제 #3
0
 // Increment the inventory for a purchase
 private static DocumentResponse <InventoryDocument> addInventory(InventoryEvent e, DocumentResponse <InventoryDocument> doc)
 {
     if (doc.Document.stock == null)
     {
         doc.Document.stock = new JObject();
     }
     doc.Document.stock[e.location] = ((int?)doc.Document.stock[e.location] ?? 0) + e.count;
     return(doc);
 }
예제 #4
0
 public EventManager()
 {
     this.IO        = new IOEvent();
     this.Network   = new NetworkEvent();
     this.Player    = new PlayerEvent();
     this.Entity    = new EntityEvent();
     this.Server    = new ServerEvent();
     this.Block     = new BlockEvent();
     this.Inventory = new InventoryEvent();
 }
예제 #5
0
    public void Given_inactive_inventory_item_When_activate_command_Then_activated_event()
    {
        // Given
        var initialState = new InventoryItem(InventoryId, Name, count: 100, active: false);

        // When
        InventoryEvent @event = null; // TODO: execute activate command to activate the item

        // Then
        Assert.True(@event is InventoryEvent.Activated); // Assert Type for events with no properties
    }
예제 #6
0
    public void Given_initial_inventory_item_When_create_command_Then_created_event()
    {
        // Given
        InventoryItem initialState = InventoryItemEventSourcing.Init;

        // When
        InventoryEvent @event = InventoryItemEventSourcing.Execute(new InventoryCommand.Create(InventoryId, Name), initialState);

        // Then
        Assert.Equal(new InventoryEvent.Created(InventoryId, Name), @event);
    }
예제 #7
0
    public void Given_existing_inventory_item_When_stock_command_Then_stocked_event()
    {
        // Given
        var initialState = new InventoryItem(InventoryId, Name, count: 100, active: true);

        // When
        InventoryEvent @event = null; // TODO: execute stock command to create stocked event with 25 unit increment

        // Then
        var expectedEvent = new InventoryEvent.Stocked(25);

        Assert.Equal(expectedEvent, @event);
    }
예제 #8
0
    public void Given_existing_inventory_item_When_sell_command_Then_sold_event()
    {
        // Given
        var initialState = new InventoryItem(InventoryId, Name, count: 100, active: true);

        // When
        InventoryEvent @event = null; // TODO: execute sell command to create sold event for 10 sold units

        // Then
        var expectedEvent = new InventoryEvent.Sold(10);

        Assert.Equal(expectedEvent, @event);
    }
예제 #9
0
        public static void EventHandler(string script)
        {
            var e = new InventoryEvent(script);

            switch (script)
            {
            case BEFORE_INVENTORY_ADD_ITEM:     BeforeAddItem(e); break;

            case AFTER_INVENTORY_ADD_ITEM:      AfterAddItem(e); break;

            case BEFORE_INVENTORY_REMOVE_ITEM:      BeforeRemoveItem(e); break;

            case AFTER_INVENTORY_REMOVE_ITEM:       AfterRemoveItem(e); break;
            }
        }
예제 #10
0
    void checkClick()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 pos = Input.mousePosition;
            pos.y = Screen.height - pos.y;
            for (int i = 0; i < QuickBar_Capacity; i++)
            {
                if (slot_bounds[i].Contains(pos))
                {

                    selected_bounds.x = slot_bounds[i].x - QuickBar_Scale;
                    selected_bounds.y = slot_bounds[i].y - QuickBar_Scale;
                    InventoryEvent e = new InventoryEvent(OmniWorld.tick, localBag.id, 's', i);
                    OmniEvents.AddEvent(e);
                }
            }
        }
    }
예제 #11
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(this);
        }

        availableItems   = new Dictionary <Id, Item>();
        unavailableItems = new Dictionary <Id, Item>();

        onAddAvailableItem   = new InventoryEvent();
        onAddUnavailableItem = new InventoryEvent();
        onBuyItem            = new InventoryEvent();
        onSelectItem         = new InventoryEvent();
    }
예제 #12
0
    private void Awake()
    {
        if (!instance)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
        }

        onBuy    = new InventoryEvent();
        onSelect = new InventoryEvent();

        inventory = new Item[5, 6];

        Inventory.instance.onAddAvailableItem.AddListener(AddAvailableItem);
        Inventory.instance.onAddUnavailableItem.AddListener(AddUnavailableItem);
        Inventory.instance.onBuyItem.AddListener(BuyItem);
    }
예제 #13
0
        public static void OnAdded(uint stackNumber, InventoryEvent inventoryEvent, IGameObject obj)
        {
            try
            {
                switch (inventoryEvent)
                {
                case InventoryEvent.kStackAddedTo:
                case InventoryEvent.kStackCreated:
                    break;

                default:
                    return;
                }

                Inventory inventory = Inventories.ParentInventory(obj);
                if (inventory == null)
                {
                    return;
                }

                Sim sim = inventory.Owner as Sim;
                if (sim == null)
                {
                    return;
                }

                Tracer tracer = new Tracer();
                tracer.Perform();

                if (tracer.mPurchase)
                {
                    ManagerMoney.AdjustFundsTask.Perform(sim.SimDescription, "BuyItem", -obj.Value);
                }
            }
            catch (Exception e)
            {
                Common.Exception(obj, e);
            }
        }
예제 #14
0
        public static async Task RunAsync(
            [ServiceBusTrigger("starter", Connection = "ServiceBusConnectionString")] string inputMessage,
            [CosmosDB("inventoryDb", "inventory", ConnectionStringSetting = "CosmosDbConnectionString", SqlQuery = "SELECT * FROM r")] IEnumerable <InventoryDocument> docs,
            ILogger log)
        {
            log.LogInformation($"Starter function triggered and requests # of messages: {inputMessage}");

            if (int.TryParse(inputMessage, out int messageCount))
            {
                var productNames  = GetProductNames(docs);
                var locationNames = GetLocationNames(docs);
                var messages      = new List <Message>();

                for (int x = 0; x < messageCount; x++)
                {
                    string         type     = rnd.Next(2) == 1 ? "sell" : "buy";
                    int            maxCount = type.Equals("sell") ? 300 : 335;
                    InventoryEvent @event   = new InventoryEvent
                    {
                        count     = rnd.Next(1, maxCount),
                        location  = locationNames[rnd.Next(0, locationNames.Count())],
                        productId = productNames[rnd.Next(0, productNames.Count())],
                        time      = DateTime.UtcNow,
                        type      = type
                    };

                    var message = new Message(@event.GetJsonBytes())
                    {
                        ScheduledEnqueueTimeUtc = DateTime.UtcNow.AddSeconds(rnd.Next(0, 240))
                    };
                    messages.Add(message);
                }
                await sendClient.SendAsync(messages);
            }
            else
            {
                log.LogInformation($"Unable to parse int from {inputMessage}");
            }
        }
예제 #15
0
        // INITIALIZE: ----------------------------------------------------------------------------

        protected override void OnCreate()
        {
            DatabaseInventory dbInventory = DatabaseInventory.Load();

            if (INVENTORY == null)
            {
                INVENTORY = dbInventory;
            }

            this.eventChangePlayerInventory = new InventoryEvent();
            this.eventChangePlayerCurrency  = new InventoryEvent();

            this.itemsCatalogue = new Dictionary <int, Item>();
            for (int i = 0; i < dbInventory.inventoryCatalogue.items.Length; ++i)
            {
                this.itemsCatalogue.Add(
                    dbInventory.inventoryCatalogue.items[i].uuid,
                    dbInventory.inventoryCatalogue.items[i]
                    );
            }

            this.recipes = new Dictionary <Recipe.Key, Recipe>();
            for (int i = 0; i < dbInventory.inventoryCatalogue.recipes.Length; ++i)
            {
                this.recipes.Add(
                    new Recipe.Key(
                        dbInventory.inventoryCatalogue.recipes[i].itemToCombineA.item.uuid,
                        dbInventory.inventoryCatalogue.recipes[i].itemToCombineB.item.uuid
                        ),
                    dbInventory.inventoryCatalogue.recipes[i]
                    );
            }

            this.playerInventory = new PlayerInventory();
            SaveLoadManager.Instance.Initialize(this, 25);

            SaveLoadManager.Instance.eventOnChangeProfile.AddListener(this.OnChangeProfile);
        }
예제 #16
0
        public static async Task <Item> RunOrchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context, ILogger log)
        {
            InventoryEvent data = context.GetInput <InventoryEvent>();

            if (data == null)
            {
                throw new ArgumentException("data received to orchestrator is null");
            }

            var entityId = new EntityId("StoreEntity", data.StoreId);
            var proxy    = context.CreateEntityProxy <IStoreEntity>(entityId);

            proxy.Aggregate(data);
            Item sampleItem = await proxy.GetItem(data.Id);

            if (sampleItem != null)
            {
                log.LogInformation(sampleItem.Id);
            }

            return(sampleItem);
        }
예제 #17
0
        public static async Task Run([CosmosDBTrigger(
                                          databaseName: "inventory",
                                          collectionName: "onHand",
                                          ConnectionStringSetting = "CosmosDBConnection",
                                          LeaseCollectionName = "leases",
                                          CreateLeaseCollectionIfNotExists = true)] IReadOnlyList <Document>
                                     input, ILogger log,
                                     [DurableClient] IDurableOrchestrationClient starter)
        {
            foreach (var item in input)
            {
                try
                {
                    //deserializes payload to object and "transform" it
                    string           stringifiedItem = item.ToString();
                    InputOnHandEvent inputItem       = InputOnHandEvent.Deserialize(stringifiedItem);

                    if (inputItem == null)
                    {
                        throw new InvalidOperationException("InputOnHandEvent not deserialized from payload string");
                    }

                    log.LogInformation(inputItem.Id);
                    InventoryEvent inventoryEvent = InputOnHandEvent.ResolveToInventoryEvent(inputItem);

                    //re-serializes payload and sends it to orchestrator
                    string instanceId = await starter.StartNewAsync("StoreOrchestrator", null, inventoryEvent).ConfigureAwait(false);

                    var mgmtUrls = starter.CreateHttpManagementPayload(instanceId);
                    log.LogInformation(inputItem.Id, mgmtUrls.ToString());
                }
                catch (Exception e)
                {
                    log.LogError(e.Message);
                }
            }
        }
예제 #18
0
    public void addToInventory(ItemScript item)
    {
        bool found = false;

        foreach (ItemScript i in inventory)
        {
            if (i.itemName == item.itemName)
            {
                i.AddItem();
                i.OnPickUp();
                //Debug.Log("Player has item " + item.itemName +" Count: "+i.count);
                InventoryEvent?.Invoke(inventory);
                found = true;
            }
        }
        //Debug.Log("Adding " + item.itemName + " to inventory first time.");
        if (!found)
        {
            inventory.Add(item);
            item.AddItem();
            item.OnPickUp();
            InventoryEvent?.Invoke(inventory);
        }
    }
예제 #19
0
        public static async Task UpdateInventory(
            [EventHubTrigger("inventory-transactions", Connection = "EventHubsConnectionString", ConsumerGroup = "cloud")] InventoryEvent inventoryEvent,
            [SignalR(HubName = "inventory")] IAsyncCollector <SignalRMessage> signalRMessages,
            ILogger log)
        {
            log.LogInformation($"Processed a message: {inventoryEvent.type} at {inventoryEvent.time}");

            // Get the inventory information from CosmosDB
            var doc = await client.ReadDocumentAsync <InventoryDocument>(documentUrlBase + inventoryEvent.productId);

            // Modify the inventory based on the event
            doc = string.Equals(inventoryEvent.type, "sell") ? removeInventory(inventoryEvent, doc) : addInventory(inventoryEvent, doc);

            // Update the inventory in CosmosDB
            var res = await client.ReplaceDocumentAsync(documentUrlBase + inventoryEvent.productId, doc.Document);

            // Notify the dashboard
            await signalRMessages.AddAsync(
                new SignalRMessage
            {
                Target    = "inventory",
                Arguments = new[] { GenerateInventoryMessage(doc.Document) }
            });
        }
 public void AddChangeItemEventListener(InventoryEvent @event)
 {
     _changeItem += @event;
 }
 public void RemoveChangeItemEventListener(InventoryEvent @event)
 {
     _changeItem -= @event;
 }
예제 #22
0
 private void ShipmentUpdate(InventoryEvent incomingEvent, Item currentItem)
 {
     currentItem.InventoryCount       += incomingEvent.CountAdjustment;
     currentItem.LastShipmentTimestamp = incomingEvent.LastShipmentTimestamp;
     currentItem.LastUpdateTimestamp   = incomingEvent.LastUpdateTimestamp;
 }
예제 #23
0
    void giv(NetworkPlayer pl)
    {
        int[] giv = new int[OmniItems.itemTypes.Length * 2];
        int c = 0;
        for (int i = 0; i < OmniItems.itemTypes.Length; i++)
        {
            giv[c++] = OmniItems.itemTypes[i].id;
            giv[c++] = 1;
        }

        InventoryEvent e = new InventoryEvent(OmniWorld.tick, connectedClients[pl].id, 'a', giv);
        e.player = pl;
        OmniEvents.AddEvent(e);
    }
 private static InventoryItem When(InventoryItem state, InventoryEvent @event) => InventoryItem.Apply(@event, state);
예제 #25
0
 private void Awake()
 {
     onBuy    = new InventoryEvent();
     onSelect = new InventoryEvent();
 }
예제 #26
0
    public void CheckCommands()
    {
        //        bool enter = ConsoleCommand.Contains("\r") || ConsoleCommand.Contains("\n");
        //        if (enter)
        //        {
            if (ConsoleCommand.Length > 0)
            {

                string[] cmd = ConsoleCommand.Split(' ');
                if (cmd[0] == "host")
                {
                    if (cmd.Length > 1)
                    {
                        int port = Int16.Parse(cmd[1]);
                        Network.InitializeServer(128, port,false);
                    }
                }
                else if (cmd[0] == "connect")
                {
                    if (cmd.Length > 1)
                    {
                        string[] address = cmd[1].Split(':');
                        if (address.Length > 1)
                        {
                            OmniWorld.Clear();
                            int port = Int16.Parse(address[1]);
                            Network.Connect(address[0], port);
                        }
                    }
                }

                else if (cmd[0] == "omnigive")
                {
                      //OmniWorld.netView.RPC("giveItem", RPCMode.Server, Network.player, cmd[1], int.Parse(cmd[2])); //HAX
                        if (Network.isClient)
                            OmniWorld.netView.RPC("giv", RPCMode.Server, Network.player);
                        else
                        {
                            int[] giv = new int[OmniItems.itemTypes.Length * 2];
                            int c = 0;
                            for (int i = 0; i < OmniItems.itemTypes.Length; i++)
                            {
                                giv[c++] = OmniItems.itemTypes[i].id;
                                giv[c++] = 1;
                            }
                            InventoryEvent e = new InventoryEvent(OmniWorld.tick, OmniLocal.LocalID, 'a', giv);
                            OmniEvents.AddEvent(e);
                        }
                }

                else if (cmd[0] == "spawn")
                {
                    if (cmd.Length > 1)
                    {
                        if (Network.isClient)
                        {
                            OmniWorld.netView.RPC("SpawnHax", RPCMode.Server, Network.player, cmd[1].Trim()); //HAX
                        }
                        else
                        {
                           // new NetworkEvent(0);\
                            if (OmniItems.getItem(cmd[1].Trim()) >= 0)
                            {
                                OmniObject localplayer = OmniLocal.getLocalPlayer();
                                SpawnEvent e = new SpawnEvent(OmniWorld.tick, cmd[1].Trim(),null, new Vector2(localplayer.bounds.x, localplayer.bounds.y + 4),Vector2.zero, -1, typeof(ControllableObject));
                                e.onHandle += ConsoleSpawn;
                                OmniEvents.AddEvent(e);
                            }
                        }

                    }
                }

                else if (cmd[0] == "delay")
                {

                    OmniWorld.netView.RPC("delay", RPCMode.All, int.Parse(cmd[1]));
                }
                else if (cmd[0] == "ms")
                {
                    if (Network.isServer)
                        MasterServer.RegisterHost("OmniDig", "OmniDig", "OmniDig");
                    else
                    {
                        MasterServer.RequestHostList("OmniDig");
                        HostData[] d = MasterServer.PollHostList();
                    }
                }

                ConsoleCommand = "";
          //  }
        }
    }
예제 #27
0
    void PlayerSpawned(OmniEvent e)
    {
        if (!Network.isServer)
            return;

        SpawnEvent ev = e as SpawnEvent;
        ClientControllable cl = OmniWorld.instance.SpawnedObjectsNew[ev.id] as ClientControllable;
        cl.Name = name;
        cl.guid = guid;

        cl.delay = (int)(Network.GetAveragePing(ev.player) * OmniWorld.timeStep) + 2;
        Debug.Log(cl.Name + " ping is " + Network.GetAveragePing(ev.player) + " setting delay to " + cl.delay);
        OmniWorld.netView.RPC("delay", ev.player, cl.delay);
        OmniNetwork.AddClient(cl, ev.player);

        int[] giv = new int[OmniItems.itemTypes.Length * 2];
        int c = 0;
        for (int i = 0; i < OmniItems.itemTypes.Length; i++)
        {
            giv[c++] = OmniItems.itemTypes[i].id;
            giv[c++] = 1;
        }

        InventoryEvent invevent = new InventoryEvent(OmniWorld.tick + 2 + cl.delay, ev.id, 'a', giv);
        invevent.player = ev.player;
        OmniEvents.AddEvent(invevent);
    }
예제 #28
0
 void Released()
 {
     if (heldItem != null)
     {
         for (int i = 0; i < Bag_MaxItems; i++)
         {
             if (slotBounds[i % Bag_Width, i / Bag_Width].Contains(clickPos))
                 if (localBag != null)
                 {
                     InventoryEvent e = new InventoryEvent(OmniWorld.tick, localBag.id, 'm', heldId, i, heldAmt);
                     OmniEvents.AddEvent(e);
                     break;
                 }
         }
         heldItem = null;
     }
 }
예제 #29
0
 public static void giveall(int id)
 {
     int[] giv = new int[OmniItems.itemTypes.Length * 2];
     int c = 0;
     for (int i = 0; i < OmniItems.itemTypes.Length; i++)
     {
         giv[c++] = OmniItems.itemTypes[i].id;
         giv[c++] = 1;
     }
     InventoryEvent e = new InventoryEvent(OmniWorld.tick+3, id, 'a', giv);
     OmniEvents.AddEvent(e);
 }