Exemplo n.º 1
0
        private List <Region> LoadFromFile()
        {
            if (!File.Exists(_filename))
            {
                return(new List <Region>());
            }

            List <Region> listReg = new List <Region>();

            XmlDocument doc = new XmlDocument();

            doc.Load(_filename);

            //get inventories
            XmlNode regions = doc.GetElementsByTagName("regions").Item(0);

            //Pour chaque inventaire
            foreach (XmlElement region in regions.ChildNodes)
            {
                if (!ulong.TryParse(region.GetAttribute("id"), out ulong id))
                {
                    break;
                }

                Region reg = new Region
                {
                    Id   = id,
                    Name = region.GetAttribute("name"),
                    Type = GetTypeFromString(region.GetAttribute("type"))
                };

                //Pour chaque case
                foreach (XmlElement caseXml in region.ChildNodes)
                {
                    Case c = CaseFactory.BuildCase(caseXml);
                    reg.AddCase(c);
                }
                listReg.Add(reg);
            }

            return(listReg);
        }
Exemplo n.º 2
0
        public async Task CreateVillageCommand(CommandContext ctx)
        {
            //Vérification de base character + guild
            if (!dep.Entities.Characters.IsPresent(ctx.User.Id) ||
                !dep.Entities.Guilds.IsPresent(ctx.Guild.Id))
            {
                return;
            }

            Guild     guild     = dep.Entities.Guilds.GetGuildById(ctx.Guild.Id);
            Region    region    = dep.Entities.Map.GetRegionByName(guild.RegionName);
            Character character = dep.Entities.Characters.GetCharacterByDiscordId(ctx.User.Id);


            if (region == null || region.GetVillageId() != ulong.MinValue || !character.Location.Equals(region.GetCentralCase().Location))
            {
                //Region n'appartient pas à un serveur, a déjà un village ou case pas adaptée, impossible de construire ici
                DiscordEmbedBuilder embedNotPossible = dep.Embed.CreateBasicEmbed(ctx.User, dep.Dialog.GetString("createVillageNotPossible", character: character, region: region));
                await ctx.RespondAsync(embed : embedNotPossible);

                return;
            }

            Inventory inv = dep.Entities.Inventories.GetInventoryById(character.Id);

            if (inv.GetMoney() < 500)
            {
                //Trop pauvre pour construire un village ..
                DiscordEmbedBuilder embedNoMoney = dep.Embed.CreateBasicEmbed(ctx.User, dep.Dialog.GetString("createVillageNoMoney", character: character));
                await ctx.RespondAsync(embed : embedNoMoney);

                return;
            }


            ////////Sinon, on peut envisager la construction ... !
            InteractivityModule interactivity = ctx.Client.GetInteractivityModule();
            Village             village       = new Village();
            //1 Demander le nom
            DiscordEmbedBuilder embedVillageName = dep.Embed.CreateBasicEmbed(ctx.User, dep.Dialog.GetString("createVillageAskName"));
            await ctx.RespondAsync(embed : embedVillageName);

            bool VillageName = false;

            do
            {
                MessageContext msgTrueName = await interactivity.WaitForMessageAsync(
                    xm => xm.Author.Id == ctx.User.Id && xm.ChannelId == ctx.Channel.Id, TimeSpan.FromMinutes(1));

                if (msgTrueName != null)
                {
                    if (msgTrueName.Message.Content.Length <= 50 &&
                        !dep.Entities.Villages.IsNameTaken(msgTrueName.Message.Content) &&
                        msgTrueName.Message.Content.Length > 2)
                    {
                        village.Name = msgTrueName.Message.Content;
                        village.Name = dep.Dialog.RemoveMarkdown(village.Name);
                        VillageName  = true;
                    }
                    else
                    {
                        DiscordEmbedBuilder embedErrorTrueName = dep.Embed.CreateBasicEmbed(ctx.User, dep.Dialog.GetString("startIntroTrueTaken"));
                        await ctx.RespondAsync(embed : embedErrorTrueName);
                    }
                }
            } while (!VillageName);

            //2 Nom ok, on créer le village de base
            village.Id         = ctx.Guild.Id;
            village.RegionName = region.Name;
            village.KingId     = character.Id;

            //Coût du village retiré au joueur
            inv.RemoveMoney(500);

            //250 va dans les caisses du villages, le reste servant à la "contructions" des bâtiments de base
            Inventory inventory = new VillageInventory();

            inventory.AddMoney(250);
            inventory.Id = village.Id;
            dep.Entities.Inventories.AddInventory(inventory);


            //Ajout des bâtiment de base
            Castle castle = new Castle()
            {
                Level         = 1,
                Name          = "Castle",
                ProprietaryId = character.Id
            };
            House house = new House()
            {
                Level         = 1,
                Name          = "Hut",
                ProprietaryId = character.Id
            };

            village.AddBuilding(castle);
            village.AddBuilding(house);

            //Add the king as inhabitant
            village.AddInhabitant(character);
            character.VillageName = village.Name;
            dep.Entities.Characters.EditCharacter(character);

            //become king
            character.Profession = Profession.King;

            //Village rattaché à la région
            region.SetVillageId(village.Id);

            //Case de la région mise en non valable
            region.GetCentralCase().IsAvailable = false;
            region.SetCentralCase(CaseFactory.BuildCase("village", region.GetCentralCase().Location));

            dep.Entities.Villages.AddVillage(village);

            //Bravo, village créé
            DiscordEmbedBuilder embedVillageCreated = dep.Embed.CreateBasicEmbed(ctx.User, dep.Dialog.GetString("createVillageDone", character: character, village: village));
            await ctx.RespondAsync(embed : embedVillageCreated);
        }
Exemplo n.º 3
0
        public Region GenerateNewRegion(int size, ulong id, string name, RegionType regionType, Location centralCase = null, bool forceValable = false)
        {
            Random random = new Random();
            Region r      = new Region
            {
                Name = name,
                Id   = id,
                Type = regionType
            };


            if (centralCase == null)
            {
                centralCase = GetRandomNextCentralCase();
            }

            int baseX = centralCase.XPosition - (int)Math.Floor(Convert.ToDecimal(size / 2));
            int endX  = centralCase.XPosition + (int)Math.Floor(Convert.ToDecimal(size / 2));
            int baseY = centralCase.YPosition - (int)Math.Floor(Convert.ToDecimal(size / 2));
            int endY  = centralCase.YPosition + (int)Math.Floor(Convert.ToDecimal(size / 2));

            for (int i = baseX; i <= endX; i++)
            {
                for (int j = baseY; j <= endY; j++)
                {
                    Case c;

                    if (r.Type == RegionType.Sea)
                    {
                        c = CaseFactory.BuildCase("water", new Location(i, j));
                    }
                    else if (r.Type == RegionType.Desert)
                    {
                        c = CaseFactory.BuildCase("desert", new Location(i, j));
                    }
                    else if (r.Type == RegionType.Mountain)
                    {
                        int rndValue = random.Next(1, 10);
                        if (rndValue < 2)
                        {
                            c = CaseFactory.BuildCase("water", new Location(i, j));
                        }
                        else if (rndValue < 4)
                        {
                            c = CaseFactory.BuildCase("land", new Location(i, j));
                        }
                        else if (rndValue < 6)
                        {
                            c = CaseFactory.BuildCase("forest", new Location(i, j));
                        }
                        else
                        {
                            c = CaseFactory.BuildCase("mountain", new Location(i, j));
                        }
                    }
                    else
                    {
                        int rndValue = random.Next(1, 10);
                        if (rndValue < 3)
                        {
                            c = CaseFactory.BuildCase("water", new Location(i, j));
                        }
                        else if (rndValue < 6)
                        {
                            c = CaseFactory.BuildCase("forest", new Location(i, j));
                        }
                        else
                        {
                            c = CaseFactory.BuildCase("land", new Location(i, j));
                        }
                    }
                    r.AddCase(c);
                }
            }

            //Force this region to have a valid central case
            if (forceValable)
            {
                r.SetCentralCase(CaseFactory.BuildCase("land", r.GetCentralCase().Location));
            }

            _regions.Add(r);
            SaveToFile();

            return(r);
        }