Example #1
0
        public static InventoryItem CreateInventoryItem(string key, TeamType team, string region, Vector2 location, ContentManager content, GraphicsDevice graphics)
        {
            InventoryItem item          = null;
            int           amountStacked = 1;

            switch (key)
            {
            case ("tribalTokens"):
                item = new TribalTokens(team, region, location, content, graphics);
                break;

            case ("basePlank"):
                item = new BasePlank(team, region, location, content, graphics);
                break;

            case ("shortSword"):
                item = new ShortSword(team, region, location, content, graphics);
                break;

            case ("softWood"):
                item = new SoftWood(team, region, location, content, graphics);
                break;

            case ("islandGrass"):
                item = new IslandGrass(team, region, location, content, graphics);
                break;

            case ("coal"):
                item = new Coal(team, region, location, content, graphics);
                break;

            case ("ironOre"):
                item = new IronOre(team, region, location, content, graphics);
                break;

            case ("baseSword"):
                item = new BaseSword(team, region, location, content, graphics);
                break;

            case ("anvilItem"):
                item = new AnvilItem(team, region, location, content, graphics);
                item.placeableVersion = new CraftingAnvil(team, region, location, content, graphics);
                break;

            case ("baseChestItem"):
                item = new BaseChestItem(team, region, location, content, graphics);
                item.placeableVersion = new BaseChest(team, region, location, content, graphics);
                break;

            case ("nails"):
                item          = new Nails(team, region, location, content, graphics);
                amountStacked = 5;
                break;

            case ("cannonBallItem"):
                item          = new CannonBallItem(team, region, location, content, graphics);
                amountStacked = 3;
                break;

            case ("pistolShotItem"):
                item          = new PistolShotItem(team, region, location, content, graphics);
                amountStacked = 5;
                break;

            case ("ironBar"):
                item = new IronBar(team, region, location, content, graphics);
                break;

            case ("treasureMapItem"):
                item = new TreasureMapItem(null, team, region, location, content, graphics);
                break;

            case ("chiliFish"):
                item = new ChiliFish(team, region, location, content, graphics);
                break;

            case ("chiliPepper"):
                item = new ChiliPepper(team, region, location, content, graphics);
                break;

            case ("cookedFish"):
                item = new CookedFish(team, region, location, content, graphics);
                break;

            case ("cookedMeat"):
                item = new CookedMeat(team, region, location, content, graphics);
                break;

            case ("rawFish"):
                item = new RawFish(team, region, location, content, graphics);
                break;

            case ("rawMeat"):
                item = new RawMeat(team, region, location, content, graphics);
                break;

            case ("spoiledFish"):
                item = new SpoiledFish(team, region, location, content, graphics);
                break;

            case ("spoiledMeat"):
                item = new SpoiledMeat(team, region, location, content, graphics);
                break;

            case ("feather"):
                item = new Feather(team, region, location, content, graphics);
                break;

            case ("scales"):
                item = new Scales(team, region, location, content, graphics);
                break;

            case ("fishOil"):
                item = new FishOil(team, region, location, content, graphics);
                break;

            case ("goldCoins"):
                item = new GoldCoins(team, region, location, content, graphics);
                break;
            }
            item.itemKey       = key;
            item.amountStacked = amountStacked;
            return(item);
        }
Example #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;
        }
Example #3
0
        private InventoryItem DeserializeInventoryItem(string itemKey)
        {
            InventoryItem item = null;

            switch (itemKey)
            {
            // TODO: ALL THE ITEMS :(
            case "scales":
                return(new Scales(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "feather":
                return(new Feather(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "fishOil":
                return(new FishOil(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "goldCoins":
                return(new GoldCoins(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "chiliFish":
                return(new ChiliFish(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "chiliPepper":
                return(new ChiliPepper(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "cookedFish":
                return(new CookedFish(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "cookedMeat":
                return(new CookedMeat(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "rawFish":
                return(new RawFish(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "rawMeat":
                return(new RawMeat(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "spoiledFish":
                return(new SpoiledFish(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "spoiledMeat":
                return(new SpoiledMeat(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "islandGrass":
                return(new IslandGrass(TeamType.GroundObject, "GustoMap", Vector2.Zero, _content, _graphics));

            case "baseSword":
                return(new BaseSword(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "lantern":
                return(new Lantern(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "baseBarrelItem":
                return(new BaseBarrelItem(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "basePlank":
                return(new BasePlank(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "cannonBallItem":
                return(new CannonBallItem(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "arrowItem":
                return(new ArrowItem(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "rustyHarpoonItem":
                return(new RustyHarpoonItem(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "coal":
                return(new Coal(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "ironBar":
                return(new IronBar(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "tribalTokens":
                return(new TribalTokens(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "ironOre":
                return(new IronOre(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "nails":
                return(new Nails(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "pickaxe":
                return(new Pickaxe(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "pistol":
                return(new Pistol(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "baseCannon":
                return(new BaseCannon(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "ballista":
                return(new Ballista(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "crossBow":
                return(new CrossBow(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "pistolShotItem":
                return(new PistolShotItem(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "shortSword":
                return(new ShortSword(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "shovel":
                return(new Shovel(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "softWood":
                return(new SoftWood(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics));

            case "baseChestItem":
                BaseChestItem bci = new BaseChestItem(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics);
                bci.placeableVersion = new BaseChest(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics);
                return(bci);

            case "anvilItem":
                AnvilItem ai = new AnvilItem(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics);
                ai.placeableVersion = new CraftingAnvil(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics);
                return(ai);

            case "clayFurnaceItem":
                ClayFurnaceItem cfi = new ClayFurnaceItem(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics);
                cfi.placeableVersion = new ClayFurnace(TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics);
                return(cfi);

            case "treasureMapItem":
                return(null);    // This is handled in calling method to deserialize some speical detials
            }
            return(item);
        }