Beispiel #1
0
        private List <InventoryItem> DeserializeInventory(List <InventoryItemSerialized> inv)
        {
            int index = 0;
            List <InventoryItem> ret = Enumerable.Repeat <InventoryItem>(null, inv.Count()).ToList();

            foreach (InventoryItemSerialized item in inv)
            {
                if (item == null)
                {
                    ret[index] = null;
                    index++;
                    continue;
                }

                // special cases
                if (item.treasureMaps != null)
                {
                    Storage reward = null;
                    if (item.treasureMaps[index].reward != null)
                    {
                        reward           = (Storage)DeserializeInventoryItem(item.treasureMaps[index].storageType).placeableVersion;
                        reward.inventory = DeserializeInventory(item.treasureMaps[index].reward);
                    }
                    TreasureMapItem tm = new TreasureMapItem(reward, TeamType.Gusto, "GustoMap", Vector2.Zero, _content, _graphics);
                    tm.digTileLoc       = item.treasureMaps[index].digLocation;
                    tm.treasureInRegion = item.treasureMaps[index].treasureInRegion;
                    ret[index]          = (InventoryItem)tm;
                    index++;
                    continue;
                }

                InventoryItem ii = DeserializeInventoryItem(item.itemKey);
                ii.amountStacked = item.stackedAmount;
                ii.regionKey     = "GustoMap";
                ii.inInventory   = true;
                ii.remove        = true;

                if (item.storageItems != null)
                {
                    Storage store = (Storage)ii.placeableVersion;
                    store.inventory = DeserializeInventory(item.storageItems[index]);
                }

                ret[index] = ii;
                index++;
            }
            return(ret);
        }
Beispiel #2
0
        public void Update(KeyboardState kstate, GameTime gameTime, Camera camera)
        {
            timeSinceLastTurnFrame += gameTime.ElapsedGameTime.Milliseconds;
            timeSinceLastWalkFrame += gameTime.ElapsedGameTime.Milliseconds;

            // check inventory
            BoundingBoxLocations.treasureLocationsList.Clear();
            List <int>           removeSolvedOrSpoiled = 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, teamType, regionKey, location, _content, _graphics);
                        item.msSpoilTime = 0;
                        if (item.amountStacked > 1)
                        {
                            item.amountStacked -= 1;
                        }
                        else
                        {
                            removeSolvedOrSpoiled.Add(inventory.IndexOf(item));
                        }

                        addTimedItem.Add(spoiled);
                    }
                }

                // for treasure maps
                if (item.bbKey.Equals("treasureMapItem"))
                {
                    TreasureMap map = (TreasureMap)item;
                    if (map.solved)
                    {
                        removeSolvedOrSpoiled.Add(inventory.IndexOf(item));
                    }
                    else
                    {
                        BoundingBoxLocations.treasureLocationsList.Add(map);
                    }
                }
            }
            foreach (var remove in removeSolvedOrSpoiled)
            {
                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 (showHealthBar)
            {
                timeShowingHealthBar += gameTime.ElapsedGameTime.Milliseconds;
            }
            if (timeShowingHealthBar > GameOptions.millisecondsToShowHealthBar)
            {
                showHealthBar        = false;
                timeShowingHealthBar = 0;
            }

            if (colliding)
            {
                moving = false;
            }

            // update any water wake
            wake.EmitterLocation = location;
            wake.Update(currentSpeed, (swimming && moving));

            colliding = false;
            swimming  = true;

            if (timeSinceLastTurnFrame > millisecondsPerTurnFrame)
            {
                // toggle inventory (use turn frame speed here for convenience)
                if (kstate.IsKeyDown(Keys.Tab))
                {
                    if (showInventory)
                    {
                        showInventory = false;
                    }
                    else
                    {
                        showInventory = true;
                    }
                }

                if (!onShip || playerInInterior != null)
                {
                    moving = true;
                    // player direction
                    if (kstate.IsKeyDown(Keys.W))
                    {
                        currRowFrame     = 3;
                        directionalFrame = 0;
                        if (kstate.IsKeyDown(Keys.A))
                        {
                            directionalFrame = 1;
                        }
                        else if (kstate.IsKeyDown(Keys.D))
                        {
                            directionalFrame = 7;
                        }
                    }
                    else if (kstate.IsKeyDown(Keys.S))
                    {
                        currRowFrame     = 0;
                        directionalFrame = 4;
                        if (kstate.IsKeyDown(Keys.A))
                        {
                            directionalFrame = 3;
                        }
                        else if (kstate.IsKeyDown(Keys.D))
                        {
                            directionalFrame = 5;
                        }
                    }
                    else if (kstate.IsKeyDown(Keys.A))
                    {
                        currRowFrame     = 2;
                        directionalFrame = 2;
                    }
                    else if (kstate.IsKeyDown(Keys.D))
                    {
                        currRowFrame     = 1;
                        directionalFrame = 6;
                    }
                    else
                    {
                        moving = false;
                    }
                    inHand.currRowFrame = currRowFrame;
                }
                else
                {
                    moving = false;
                }

                timeSinceLastTurnFrame -= millisecondsPerTurnFrame;
            }

            // combat
            if (!onShip || playerInInterior != null)
            {
                inHand.Update(kstate, gameTime, camera);
                if (playerInInterior != null)
                {
                    inHand.inInteriorId = playerInInterior.interiorId;
                }
                else
                {
                    inHand.inInteriorId = Guid.Empty;
                }
            }

            if (Mouse.GetState().LeftButton == ButtonState.Pressed && (!onShip || playerInInterior != null) && !showInventory)
            {
                inCombat        = true;
                inHand.inCombat = true;
                currColumnFrame = 8;
                if (inHand is IRanged)
                {
                    currColumnFrame = 9; // better frame for "holding" a ranged weapon

                    //load ammo
                    if (inHand.ammoLoaded == null)
                    {
                        foreach (var item in inventory)
                        {
                            if (item != null && item.GetType() == inHand.ammoItemType)
                            {
                                if (item.amountStacked > 0)
                                {
                                    inHand.LoadAmmo(item);
                                }
                                else
                                {
                                    inventory[inventory.IndexOf(item)] = null;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            else if (inCombat)
            {
                if (timeSinceSwordSwing > millisecondsCombatSwing)
                {
                    currColumnFrame++;
                    inHand.location  = location;
                    inHand.nextFrame = true;
                    if (currColumnFrame == nColumns)
                    {
                        inCombat        = false;
                        inHand.inCombat = false;
                        currColumnFrame = 0;
                    }
                    timeSinceSwordSwing = 0;
                }
                timeSinceSwordSwing += gameTime.ElapsedGameTime.Milliseconds;
            }

            inHand.location = location;
            inHand.SetBoundingBox();


            // hop on ship
            if (nearShip && kstate.IsKeyDown(Keys.X) && !onShip && playerOnShip != null && timeSinceExitShipStart < 2000)
            {
                location = playerOnShip.GetBoundingBox().Center.ToVector2();
                onShip   = true;
                playerOnShip.playerAboard          = true;
                playerOnShip.shipSail.playerAboard = true;

                // can't control non player ships (until taken over)
                if (playerOnShip.teamType != TeamType.Player)
                {
                    playerInInterior = playerOnShip.shipInterior;
                }
            }
            // exit ship
            else if (kstate.IsKeyDown(Keys.X) && onShip)
            {
                timeSinceExitShipStart += gameTime.ElapsedGameTime.Milliseconds;
                if (timeSinceExitShipStart > 2000)
                {
                    onShip = false;
                    if (playerInInterior != null)
                    {
                        playerInInterior.showingInterior = false;
                        playerInInterior.interiorObjects.Remove(this);
                        playerInInterior = null;
                        inInteriorId     = Guid.Empty;
                    }
                    playerOnShip.playerAboard          = false;
                    playerOnShip.shipSail.playerAboard = false;
                    location.X   = playerOnShip.GetBoundingBox().Center.ToVector2().X - playerOnShip.GetBoundingBox().Width / 2 - 20;
                    location.Y   = playerOnShip.GetBoundingBox().Center.ToVector2().Y;
                    playerOnShip = null;
                }
            }
            else
            {
                timeSinceExitShipStart = 0;
            }
            nearShip = false;

            // player moves with ship when controlling
            if (onShip && playerInInterior == null)
            {
                location.X = playerOnShip.GetBoundingBox().Center.ToVector2().X;
                location.Y = playerOnShip.GetBoundingBox().Center.ToVector2().Y;
            }

            if (playerOnShip != null && playerOnShip.sinking)
            {
                onShip           = false;
                playerInInterior = null;
                playerOnShip     = null;
                inInteriorId     = Guid.Empty;
            }

            else if (moving && !inCombat)
            {
                // walking animation
                if (timeSinceLastWalkFrame > millisecondsPerWalkFrame)
                {
                    currColumnFrame++;
                    if (currColumnFrame == 7) // stop before combat frames
                    {
                        currColumnFrame = 0;
                    }
                    timeSinceLastWalkFrame = 0;
                }

                currentSpeed = new Vector2(PlayerMovementVectorMappings.PlayerDirectionVectorValues[directionalFrame].Item1,
                                           PlayerMovementVectorMappings.PlayerDirectionVectorValues[directionalFrame].Item2);

                // actual "regular" movement
                location += currentSpeed;
            }
            else
            {
                if (!inCombat)
                {
                    currColumnFrame = 0;
                }
            }

            // burying storage
            int?removeChestIndex = null;

            if (canBury && kstate.IsKeyDown(Keys.B))
            {
                timeSincePressedBury += gameTime.ElapsedGameTime.Milliseconds;
                if (timeSincePressedBury > 1000)
                {
                    // remove first chest
                    foreach (var item in inventory)
                    {
                        if (item == null)
                        {
                            continue;
                        }
                        if (item.placeableVersion != null && item.placeableVersion is IStorage)
                        {
                            removeChestIndex = inventory.IndexOf(item);
                            break;
                        }
                    }

                    // create map
                    if (removeChestIndex != null)
                    {
                        Storage         toBury   = (Storage)inventory[(int)removeChestIndex].placeableVersion;
                        TreasureMapItem mapToAdd = new TreasureMapItem(toBury, teamType, regionKey, location, _content, _graphics);
                        mapToAdd.digTileLoc       = buryTile.location;
                        mapToAdd.treasureInRegion = buryTile.regionKey;
                        mapToAdd.inInventory      = false;
                        mapToAdd.remove           = false;
                        mapToAdd.onGround         = true;
                        buryTile.currColumnFrame  = 0;
                        ItemUtility.ItemsToUpdate.Add(mapToAdd);
                        inventory[(int)removeChestIndex] = null;
                    }
                    timeSincePressedBury = 0;
                }
            }
            buryTile = null;
            canBury  = false;

            // entering/toggling interior
            if (kstate.IsKeyDown(Keys.I))
            {
                msToggleInterior += gameTime.ElapsedGameTime.Milliseconds;
                if (msToggleInterior > 1000)
                {
                    if (playerInInterior != null)
                    {
                        playerInInterior.showingInterior = false;
                        playerInInterior.interiorObjects.Remove(this);
                        inInteriorId     = Guid.Empty;
                        playerInInterior = null;

                        location = entranceLoc; // player exits where they entered

                        if (playerOnShip != null)
                        {
                            playerOnShip.playerInInterior          = false;
                            playerOnShip.shipSail.playerInInterior = false;
                        }
                    }
                    else
                    {
                        // enter an interior
                        if (onShip)  // the interior of the ship the player is in
                        {
                            playerInInterior = playerOnShip.shipInterior;
                            playerOnShip.playerInInterior          = true;
                            playerOnShip.shipSail.playerInInterior = true;
                            inInteriorId = playerInInterior.interiorId;
                        }
                        else if (playerNearStructure != null)
                        {
                            entranceLoc      = location;
                            playerInInterior = playerNearStructure.structureInterior;
                            inInteriorId     = playerInInterior.interiorId;
                        }
                    }
                    msToggleInterior = 0;
                }
            }
            playerNearStructure = null;
        }
Beispiel #3
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);
        }