Beispiel #1
0
        public void Update(KeyboardState kstate, GameTime gameTime, Camera camera)
        {
            if (onGround)
            {
                msDespawnTime += gameTime.ElapsedGameTime.Milliseconds;
                if (msDespawnTime > 30000) // 30 second despawn time
                {
                    remove = true;
                }
            }
            else
            {
                msDespawnTime = 0;
            }


            if (kstate.IsKeyDown(Keys.E) && canPickUp && !inInventory)
            {
                if (playerNearItem.AddInventoryItem(this))
                {
                    remove      = true;
                    inInventory = true;
                    onGround    = false;
                    teamType    = playerNearItem.teamType;
                }
            }

            canPickUp = false;
        }
Beispiel #2
0
        public void Update(KeyboardState kstate, GameTime gameTime, Camera camera)
        {
            // Update the storage inventory for timedItems
            List <int>           removeExpiredItem = new List <int>();
            List <InventoryItem> addTimedItem      = new List <InventoryItem>();

            foreach (var item in inventory)
            {
                if (item == null)
                {
                    continue;
                }

                // for spoiled food
                if (item is ISpoiles)
                {
                    item.msSpoilTime += gameTime.ElapsedGameTime.Milliseconds;
                    Tuple <int, string> spoilDetails = ItemMappings.SpoilMappings[item.bbKey];

                    if (item.msSpoilTime > spoilDetails.Item1)
                    {
                        InventoryItem spoiled = ItemUtility.CreateInventoryItem(spoilDetails.Item2, item.teamType, regionKey, location, _content, _graphics);
                        item.msSpoilTime = 0;
                        if (item.amountStacked > 1)
                        {
                            item.amountStacked -= 1;
                        }
                        else
                        {
                            removeExpiredItem.Add(inventory.IndexOf(item));
                        }

                        addTimedItem.Add(spoiled);
                    }
                }
            }
            foreach (var remove in removeExpiredItem)
            {
                inventory[remove] = null;
            }
            foreach (var item in addTimedItem)
            {
                if (!AddInventoryItem(item))
                {
                    item.location = new Vector2(GetBoundingBox().Center.ToVector2().X, GetBoundingBox().Center.ToVector2().Y + 40);
                    item.onGround = true;

                    if (inInteriorId != Guid.Empty) // add drops to interior
                    {
                        BoundingBoxLocations.interiorMap[inInteriorId].interiorObjectsToAdd.Add(item);
                    }
                    else // add drops to world
                    {
                        ItemUtility.ItemsToUpdate.Add(item);
                    }
                }
            }



            if (canOpenStorage && !storageOpen && kstate.IsKeyDown(Keys.O))
            {
                storageOpen = true;
            }

            if (storageOpen)
            {
                if (kstate.IsKeyDown(Keys.Escape) || !canOpenStorage)
                {
                    storageOpen = false;
                }
            }


            if (canPickUp)
            {
                // pick up the item
                if (playerNearItem != null && kstate.IsKeyDown(Keys.P))
                {
                    // TODO: might need to switch different chest types here?
                    InventoryItem bci = new BaseChestItem(playerNearItem.teamType, regionKey, location, _content, _graphics);
                    if (playerNearItem.AddInventoryItem(bci))
                    {
                        bci.placeableVersion = this;
                        bci.inInventory      = true;
                        bci.onGround         = false;
                        bci.stackable        = false;
                        bci.amountStacked    = 1;
                        remove    = true;
                        canPickUp = false;
                    }
                }


                // there is a timer for how long you have to pick up item once you have the required number of hits
                msSinceStartPickupTimer += gameTime.ElapsedGameTime.Milliseconds;
                if (msSinceStartPickupTimer > msPickupTimer)
                {
                    msSinceStartPickupTimer = 0;
                    canPickUp = false;
                    nTimesHit = 0;
                }
            }

            if (inWater)
            {
                currRowFrame = 1;
                msThisFrame += gameTime.ElapsedGameTime.Milliseconds;
                if (msThisFrame > msPerFrame)
                {
                    currColumnFrame++;
                    if (currColumnFrame >= nColumns)
                    {
                        currColumnFrame = 0;
                    }
                    msThisFrame = 0;
                }
            }
            else
            {
                currRowFrame = 0;
            }


            inWater        = true;
            canOpenStorage = false;
            playerNearItem = null;
        }
Beispiel #3
0
        public void Update(KeyboardState kstate, GameTime gameTime, Camera camera)
        {
            // start the fire
            if (playerNearItem != null && kstate.IsKeyDown(Keys.C)) // TODO: and keypress time
            {
                // Remove items from inv TODO: for now this just takes the first ore, grass, wood etc in inventory
                if (!cooking)
                {
                    int nWood  = 0;
                    int nGrass = 0;
                    // check for kindling
                    foreach (var item in playerNearItem.inventory)
                    {
                        if (item is IWood)
                        {
                            nWood += item.amountStacked;
                        }
                        if (item is IGrass)
                        {
                            nGrass += item.amountStacked;
                        }
                    }

                    if (nWood >= 2 && nGrass >= 2)
                    {
                        cooking = true;
                        RemoveKindlingConsumables();
                    }
                }
            }

            if (craftingQueue.Count > 0)
            {
                msCrafting += gameTime.ElapsedGameTime.Milliseconds;
            }

            // create and drop item when crafting
            if (craftingQueue.Count > 0 && msCrafting > craftingQueue.Peek().msCraftTime)
            {
                InventoryItem item    = craftingQueue.Dequeue();
                Vector2       dropLoc = new Vector2(GetBoundingBox().Center.ToVector2().X, GetBoundingBox().Center.ToVector2().Y + 40);

                item.location = dropLoc;
                item.onGround = true;

                if (inInteriorId != Guid.Empty) // add drops to interior
                {
                    BoundingBoxLocations.interiorMap[inInteriorId].interiorObjectsToAdd.Add(item);
                }
                else // add drops to world
                {
                    ItemUtility.ItemsToUpdate.Add(item);
                }

                msCrafting = 0;
                // reset smelting
                if (craftingQueue.Count <= 0)
                {
                    cooking           = false;
                    currColumnFrame   = 0;
                    emittingLight.lit = false;
                }
            }

            if (playerNearItem != null && kstate.IsKeyDown(Keys.C) && !drawCraftingMenu && cooking)
            {
                drawCraftingMenu = true;
            }

            if (drawCraftingMenu)
            {
                if (kstate.IsKeyDown(Keys.Escape) || playerNearItem == null)
                {
                    drawCraftingMenu = false;
                }
            }

            // lighting the furnace when running
            if (emittingLight.lit)
            {
                emittingLight.Update(kstate, gameTime, GetBoundingBox().Center.ToVector2());
            }

            if (cooking)
            {
                emittingLight.lit = true;
                // cooking so animate and being timer
                msCooking   += gameTime.ElapsedGameTime.Milliseconds;
                msThisFrame += gameTime.ElapsedGameTime.Milliseconds;
                if (msThisFrame > msPerFrame)
                {
                    currColumnFrame++;
                    msThisFrame = 0;
                    if (currColumnFrame == nColumns)
                    {
                        currColumnFrame = 1;
                    }
                }
            }


            if (canPickUp)
            {
                // pick up the item
                if (playerNearItem != null && kstate.IsKeyDown(Keys.P))
                {
                    InventoryItem cfi = new ClayFurnaceItem(playerNearItem.teamType, regionKey, location, _content, _graphics);
                    if (playerNearItem.AddInventoryItem(cfi))
                    {
                        cfi.placeableVersion = this;
                        cfi.inInventory      = true;
                        cfi.onGround         = false;
                        cfi.stackable        = false;
                        cfi.amountStacked    = 1;
                        remove = true;
                    }
                }


                // there is a timer for how long you have to pick up item once you have the required number of hits
                msSinceStartPickupTimer += gameTime.ElapsedGameTime.Milliseconds;
                if (msSinceStartPickupTimer > msPickupTimer)
                {
                    msSinceStartPickupTimer = 0;
                    canPickUp = false;
                    nTimesHit = 0;
                }
            }

            playerNearItem = null;
        }
Beispiel #4
0
        public void Update(KeyboardState kstate, GameTime gameTime, Camera camera)
        {
            if (craftingQueue.Count > 0)
            {
                msCrafting += gameTime.ElapsedGameTime.Milliseconds;
            }
            // create and drop item when crafting
            if (craftingQueue.Count > 0 && msCrafting > craftingQueue.Peek().msCraftTime)
            {
                InventoryItem item    = craftingQueue.Dequeue();
                Vector2       dropLoc = new Vector2(GetBoundingBox().Center.ToVector2().X, GetBoundingBox().Center.ToVector2().Y + 40);

                item.location = dropLoc;
                item.onGround = true;

                if (inInteriorId != Guid.Empty) // add drops to interior
                {
                    BoundingBoxLocations.interiorMap[inInteriorId].interiorObjectsToAdd.Add(item);
                }
                else // add drops to world
                {
                    ItemUtility.ItemsToUpdate.Add(item);
                }

                msCrafting = 0;
            }

            if (playerNearItem != null && kstate.IsKeyDown(Keys.C) && !drawCraftingMenu)
            {
                drawCraftingMenu = true;
            }

            if (drawCraftingMenu)
            {
                if (kstate.IsKeyDown(Keys.Escape) || playerNearItem == null)
                {
                    drawCraftingMenu = false;
                }
            }

            if (canPickUp)
            {
                // pick up the item
                if (playerNearItem != null && kstate.IsKeyDown(Keys.P))
                {
                    InventoryItem ai = new AnvilItem(playerNearItem.teamType, regionKey, location, _content, _graphics);
                    if (playerNearItem.AddInventoryItem(ai))
                    {
                        ai.placeableVersion = this;
                        ai.inInventory      = true;
                        ai.onGround         = false;
                        ai.stackable        = false;
                        ai.amountStacked    = 1;
                        remove = true;
                    }
                }

                // there is a timer for how long you have to pick up item once you have the required number of hits
                msSinceStartPickupTimer += gameTime.ElapsedGameTime.Milliseconds;
                if (msSinceStartPickupTimer > msPickupTimer)
                {
                    msSinceStartPickupTimer = 0;
                    canPickUp = false;
                    nTimesHit = 0;
                }
            }

            playerNearItem = null;
        }