Ejemplo n.º 1
0
            public async Task Sort()
            {
                ChatCraftState state = ChatCraft.Instance.State;

                state.items.Sort((a, b) => a.name.CompareTo(b.name));
                state.recipes.Sort((a, b) => a.name.CompareTo(b.name));
                state.locations.Sort((a, b) => a.name.CompareTo(b.name));
                state.connections.Sort((a, b) =>
                {
                    int result = a.locationA.name.CompareTo(b.locationA.name);

                    if (result == 0)
                    {
                        result = a.locationB.name.CompareTo(b.locationB.name);
                    }

                    return(result);
                });

                state.encounters.Sort((a, b) => a.name.CompareTo(b.name));
                state.stats.Sort((a, b) => a.name.CompareTo(b.name));

                await ReplyAsync("Everything sorted");
            }
Ejemplo n.º 2
0
        void Load()
        {
            state = FileDatabase.Read <ChatCraftState>("ChatCraft/craftConfig", new SlotDictionaryConverter());

            if (state == null)
            {
                state = new ChatCraftState();
                state.stats.Add(new Stat());
                state.settings.defaultStats.Add(new StatCount()
                {
                    stat = state.stats[0]
                });
                state.items.Add(new Item());
                state.items[0].craftForwardChances.Add(new ItemWeight());
                state.items[0].statModifications.Add(new StatCount());
                state.recipes.Add(new Recipe());
                state.recipes[0].consumed.Add(new ItemCount());
                state.recipes[0].creates.Add(new ItemCount());
                state.itemSets.Add(new ItemSet());
                state.locations.Add(new Location());
                state.connections.Add(new Connection());
                state.encounters.Add(new Encounter());
                state.encounters[0].possibleEnemies.Add(new EnemyDefinition());
                state.encounters[0].possibleLoot.Add(new ItemWeightCount());
                state.players.Add(new Player()
                {
                    identifier = 0, currentLocation = state.locations[0]
                });
                state.players[0].items.Add(new ItemCount());
                state.players[0].locations.Add(new Location());
                state.players[0].recipes.Add(new Recipe());
            }

            if (state.combatInstances == null)
            {
                state.combatInstances = new List <CombatInstance>();
            }

            foreach (Connection connection in state.connections)
            {
                if (connection.locationA == null || connection.locationB == null)
                {
                    Console.WriteLine("Missing location on connection.");
                    continue;
                }

                connection.locationA.connections.Add(connection);
                connection.locationB.connections.Add(connection);
            }

            foreach (Party party in state.parties)
            {
                foreach (Unit unit in party.currentUnits)
                {
                    unit.party = party;
                }
            }

            state.combatInstances.RemoveAll(item => item == null);

            foreach (CombatInstance instance in state.combatInstances)
            {
                for (int i = 0; i < 2; i++)
                {
                    if (instance == null || instance.teams[i] == null || instance.teams[i].currentUnits == null)
                    {
                        Console.WriteLine(instance == null);

                        Console.WriteLine(instance?.teams[i] == null);

                        Console.WriteLine(instance?.teams[i]?.currentUnits == null);

                        continue;
                    }

                    foreach (Unit unit in instance.teams[i].currentUnits)
                    {
                        if (unit.combatState == null)
                        {
                            unit.combatState = new CombatState();
                        }

                        unit.combatState.instance  = instance;
                        unit.combatState.teamIndex = i;
                    }
                }
            }

            foreach (Player player in state.players)
            {
                Slot[] slots = player.equipped.Keys.ToArray();

                foreach (Slot slot in slots)
                {
                    if (!state.slots.Contains(slot))
                    {
                        player.equipped.Remove(slot);
                    }
                }

                foreach (Slot slot in state.slots)
                {
                    if (!player.equipped.ContainsKey(slot))
                    {
                        player.equipped.Add(slot, null);
                    }
                }
            }

            foreach (Item item in state.items)
            {
                for (int i = 0; i < item.statModifications.Count; i++)
                {
                    if (item.statModifications[i].stat == null)
                    {
                        item.statModifications.RemoveAt(i);
                        i--;
                    }
                }
            }

            foreach (Player player in state.players)
            {
                playerMap.Add(player.identifier, player);
            }

            Console.WriteLine("Craft State Loaded");
        }