public void selectKit(WorldBase world) { if (!locked) { SoundManager.getSound("click").playWithVariance(0, .25f, 0, SoundType.MONSTER); foreach (Item item in kit) { world.player.inventory.add(item.clone(item.uses)); } if (starterCards[0] != null) { ((Player)(world.player)).cards[0] = CardRegistrar.getCardFromIdPlayerAndLevel(CardRegistrar.getIDFromCard(starterCards[0]), starterCards[0].level, (Player)world.player); } if (starterCards[1] != null) { ((Player)(world.player)).cards[1] = CardRegistrar.getCardFromIdPlayerAndLevel(CardRegistrar.getIDFromCard(starterCards[1]), starterCards[1].level, (Player)world.player); } animations.apply(((Player)(world.player))); world.player.tutorialStringMovement = tutorialStringMovement; world.player.tutorialStringInventory = tutorialStringInventory; world.player.tutorialStringUseItems = tutorialStringUseItems; world.player.tutorialStringPostKeybinds = tutorialStringPostKeybinds; world.player.tutorialStringCrafting = tutorialStringCrafting; world.player.tutorialStringWeapon = tutorialStringWeapon; world.player.rebindAndFinish = rebindAndFinish; if (world is TutorialWorld) { ((TutorialWorld)world).processInstructionStrings(); } } }
public static void load(String path) { Logger.log("Loading game at " + path); bool foundWorld = false; WorldBase world = null; try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } else if (File.Exists(path + "save.txt")) { foundWorld = true; using (System.IO.StreamReader file = new System.IO.StreamReader(path + "save.txt")) { World.universeProperties = new UniverseProperties(file.ReadLine()); int difficulty = int.Parse(file.ReadLine()); world = Game1.instance.getWorldBasedOnDifficulty(difficulty); Player player = ((Player)world.player); PlayerAnimationPackage animationPackage = PlayerAnimationPackage.animationPackageKey[int.Parse(file.ReadLine())]; animationPackage.apply(player); Inventory.PlayerInventory inventory = player.inventory; float playerX = float.Parse(file.ReadLine()); float playerY = float.Parse(file.ReadLine()); player.location = new Vector2(playerX, playerY); player.health = float.Parse(file.ReadLine()); player.hunger = float.Parse(file.ReadLine()); player.warmth = float.Parse(file.ReadLine()); int currentCard = 0; string line = file.ReadLine(); while (!line.StartsWith("Keyed Items:")) { if (line.StartsWith("Inventory:")) { line = line.Replace("Inventory:", ""); string[] entry = line.Split(','); int id = int.Parse(entry[0]); int count = int.Parse(entry[1]); inventory.add(ItemRegistrar.getItemFromIdAndCount(id, count)); } else if (line.StartsWith("Card:")) { line = line.Replace("Card:", ""); string[] entry = line.Split(','); int id = int.Parse(entry[0]); float level = float.Parse(entry[1]); player.cards[currentCard] = CardRegistrar.getCardFromIdPlayerAndLevel(id, level, player); currentCard++; } line = file.ReadLine(); } for (int i = 0; i < player.keyedItems.Length; i++) { int itemData = int.Parse(file.ReadLine()); if (itemData != -1) { player.keyedItems[i] = ItemRegistrar.getItemFromIdAndCount(itemData, 1); } } } File.Delete(path + "save.txt"); } } catch (Exception e) { Logger.log(e.ToString()); } if (!foundWorld) { world = Game1.instance.getWorldBasedOnDifficulty(0); Game1.instance.queuedSplashScreens.Add(new PlayerSelectScreen(MetaData.unlocks.ToArray(), world)); } Card.setUpCards(); Game1.instance.switchWorlds(world); }