Exemple #1
0
        public void ProcessRandomEvent()
        {
            if (Percent(50))     // 100 / 2 = 50%
            {
                if (Percent(25)) // 100 / 4 = 25%
                {
                    CurrentForestEvent = ForestEvent.Battle;
                    var Enemies = new Humanoid();

                    Enemies.Gender = (Gender)random.Next(2);
                    Enemies.Race   = (Race)random.Next(3);

                    Enemies.SetLevel(MainCharacter.CombatLevel.Value);
                    if (Percent(50))
                    {
                        Enemies.Hands = WeaponItem.Clone(Database.Weapons[random.Next(Database.Weapons.Count)]);
                    }

                    WriteLineColor($"You are under attack by a {Enemies.Gender} {Enemies.Race} level {Enemies.CombatLevel.Value}!!!!", ConsoleColor.Red, ConsoleColor.Black);
                    var power = Enemies.GetWearablePower();
                    WriteLineColor($"this enemy has {power.Strength} strength {power.Defence} defence and {power.Inteligence} inteligence", ConsoleColor.DarkCyan, ConsoleColor.Black);
                    ProcessAttackScreen(Enemies);
                    if (CurrentLocation == Location.Forest)
                    {
                        WriteLine($"Your current location is now {CurrentX}, {CurrentY}.");
                    }
                    CurrentForestEvent = ForestEvent.None;
                    stats.UpdateWorld(this);
                }
                else if (Percent(10))
                {
                    var orens = random.Next(30, 101);

                    MainCharacter.Orens += orens;
                    WriteLineColor($"You found {GetOrenLabel(orens)} on the ground!!!", ConsoleColor.Yellow, ConsoleColor.Black);
                    WriteLineColor($"You now have {GetOrenLabel(MainCharacter.Orens)}", ConsoleColor.Yellow, ConsoleColor.Black);
                }
                else if (Percent(10))
                {
                    CurrentForestEvent = ForestEvent.Stranger;
                    var person = new Humanoid();
                    person.Gender = (Gender)random.Next(2);
                    person.Race   = (Race)random.Next(3);
                    person.SetRandomNewName();
                    person.SetLevel(random.Next(MainCharacter.CombatLevel.Value + 5));
                    stats.UpdateWorld(this);
                    WriteLineColor($"Stranger approachers...\r\n i'm looking for somewhere to live", ConsoleColor.Red, ConsoleColor.Black);
                    string input = Question("Do you want to help this stranger?", "no", "yes");
                    if (input == "yes")
                    {
                        TotalStrangersCollected += 1;

                        WriteLine($"Sure you can come to my town {HomeTown.Name}.");
                        WriteLine($"The Coordinates are {HomeTown.X}, {HomeTown.Y}.");
                        int xp = 100;

                        if (Percent(15))
                        {
                            person.Smithing.AddXP(person.Smithing.GetXPToLevelUp(RandomNumber(30)));

                            if (person.Smithing.Value > 15)
                            {
                                HomeTown.Buildings.Add(new Buildings()
                                {
                                    Owner = person, Type = BuildingType.Blacksmith
                                });

                                WriteLineColor($"{person.Name}, Just opened a new Blacksmith at your home town.", ConsoleColor.Yellow, ConsoleColor.Black);
                                xp += 100;
                            }
                        }
                        else if (Percent(15))
                        {
                            person.Barter.AddXP(person.Barter.GetXPToLevelUp(RandomNumber(30)));

                            if (person.Barter.Value > 10)
                            {
                                HomeTown.Buildings.Add(new Buildings()
                                {
                                    Owner = person, Type = BuildingType.Store
                                });

                                WriteLineColor($"{person.Name}, Just opened a new store at your home town.", ConsoleColor.Yellow, ConsoleColor.Black);
                                xp += 100;
                            }
                        }

                        WriteLineColor($"{person.Name}: Well i better get going then, Thank you so much, Catch you soon.", ConsoleColor.Yellow, ConsoleColor.Black);

                        int orens = RandomNumber(50);
                        if (orens > 0)
                        {
                            MainCharacter.Orens += orens;

                            WriteLineColor($"Hope this helps you, {person.Name} gave you {GetOrenLabel(orens)}", ConsoleColor.Yellow, ConsoleColor.Black);
                            WriteLineColor($"You now have {GetOrenLabel(MainCharacter.Orens)}", ConsoleColor.Yellow, ConsoleColor.Black);

                            UpdateStats(MainCharacter);

                            xp += 10;
                        }

                        MainCharacter.Barter.AddXP(xp);

                        WriteLineColor($"You received {xp} xp for Barter Skill.", ConsoleColor.DarkCyan, ConsoleColor.Black);

                        HomeTown.PeopleWhoLiveHere.Add(person);
                    }
                    else
                    {
                        int orens = 100;

                        MainCharacter.Orens += orens;

                        WriteLine("I'm a bandit, give me all your orens and you wont get hurt!");
                        WriteLineColor($"You stole {GetOrenLabel(orens)}!!!", ConsoleColor.Yellow, ConsoleColor.Black);
                        WriteLineColor($"You now have {GetOrenLabel(MainCharacter.Orens)}", ConsoleColor.Yellow, ConsoleColor.Black);

                        UpdateStats(MainCharacter);
                    }
                    CurrentForestEvent = ForestEvent.None;
                    stats.UpdateWorld(this);
                    WriteLine($"Your current location is now {CurrentX}, {CurrentY}.");
                }
            }
            UpdateStats(MainCharacter);
        }
Exemple #2
0
        public void Play()
        {
            var thr = new Thread(() => {
                stats.ActiveWorld = this;
                stats.ActiveHuman = MainCharacter;
                stats.ShowDialog();
            });

            thr.SetApartmentState(ApartmentState.STA);
            thr.Start();

            running = true;

            Save(false);

            string input = "";

            while (running)
            {
                MakeVisible();

                Program.UpdateStats(MainCharacter);
                Program.stats.UpdateWorld(this);

                switch (CurrentLocation)
                {
                case Location.LocationSpot:
                    ActiveBuilding     = null;
                    CurrentForestEvent = ForestEvent.None;
                    if (MainCharacter.Health < MainCharacter.MaxHealth)
                    {
                        MainCharacter.AddHealth(MainCharacter.MaxHealth - MainCharacter.Health);
                        WriteLineColor("Your feel rested and now have full health.", ConsoleColor.Green, ConsoleColor.Black);
                        Program.UpdateStats(MainCharacter);
                        Save();
                    }
                    List <Tuple <string, string, Action> > Commands = new List <Tuple <string, string, Action> >();

                    Commands.Add(new Tuple <string, string, Action>($"{Commands.Count}: Explore outside.", $"leave,outside,explore,{Commands.Count}", () => { CurrentLocation = Location.Forest; }));

                    if (ActiveLocation == HomeTown)
                    {
                        Commands.Add(new Tuple <string, string, Action>($"{Commands.Count}: Enter your (home) and (sleep).", $"home,sleep,{Commands.Count}", () => {
                            if (!IsDayTime())
                            {
                                IncrementTime(12);
                                Save();
                                WriteLineColor("You feel rested...", ConsoleColor.Green, ConsoleColor.Black);
                            }
                            else
                            {
                                WriteLineColor("You don't feel tired it is only " + TimeInDay + ":00. (24 hr time)", ConsoleColor.Red, ConsoleColor.Black);
                            }
                        }));
                    }

                    foreach (var item in ActiveLocation.Buildings)
                    {
                        switch (item.Type)
                        {
                        case BuildingType.Store:
                            Commands.Add(new Tuple <string, string, Action>($"{Commands.Count}: Enter {item.Owner.Name}'s Store.", $"{item.Owner.Name},store,{Commands.Count}", () => {
                                CurrentLocation = Location.Building;
                                ActiveBuilding  = item;
                            }));
                            break;

                        case BuildingType.Blacksmith:
                            Commands.Add(new Tuple <string, string, Action>($"{Commands.Count}: Enter {item.Owner.Name}'s Blacksmith.", $"{item.Owner.Name},blacksmith,{Commands.Count}", () => {
                                CurrentLocation = Location.Building;
                                ActiveBuilding  = item;
                            }));
                            break;

                        default:
                            break;
                        }
                    }

                    Commands.Add(new Tuple <string, string, Action>($"{Commands.Count}: Close.", $"close,{Commands.Count}", () => {
                        Save();
                        running = false;

                        Application.Exit();
                    }));

                    List <string> Options = new List <string>();
                    var           Builder = new StringBuilder($"What would you like to do in {ActiveLocation.Name}?\r\n");

                    foreach (var item in Commands)
                    {
                        Options.Add(item.Item2);
                        Builder.AppendLine(item.Item1);
                    }

                    input = Question(Builder.ToString(), Options.ToArray());


                    for (int i = 0; i < Options.Count; i++)
                    {
                        if (input == Commands[i].Item2.ToLower())
                        {
                            Commands[i].Item3();
                            break;
                        }
                    }

                    break;

                case Location.Building:
                    CurrentForestEvent = ForestEvent.None;
                    string        Type      = ActiveBuilding.Type == BuildingType.Blacksmith ? "Can you make me a " : "Can I buy some ";
                    List <string> Commands4 = new List <string>()
                    {
                        "0,weapon", "1,head", "2,chest", "3,legs", "4,feet", "5,nothing,sorry,leave", "6,sell"
                    };
                    if (ActiveBuilding.Type == BuildingType.Store)
                    {
                        Commands4.Add("7,tool");
                    }
                    {
                        Commands4.Add("8,Quests");
                    }
                    input = Question(string.Format(
                                         ActiveBuilding.Owner.Name + @": Welcome to my {1:G}, Can I help you with something?
0: {0}weapon's.
1: {0}head wear.
2: {0}chest wear.
3: {0}leg wear.
4: {0}feet wear.
5: Nothing, Sorry.
6: Sell something." + (ActiveBuilding.Type == BuildingType.Store ? "\r\n7: Buy a Tool." : ""), Type, ActiveBuilding.Type), Commands4.ToArray());

                    switch (input)
                    {
                    case "0,weapon":
                        ProcessBuyOrMakeItem(Database.Weapons, "Weapons");

                        break;

                    case "1,head":
                        ProcessBuyOrMakeItem(Database.HeadWear, "Head Wear");

                        break;

                    case "2,chest":
                        ProcessBuyOrMakeItem(Database.ChestWear, "Chest Wear");

                        break;

                    case "3,legs":
                        ProcessBuyOrMakeItem(Database.LegWear, "leg Wear");

                        break;

                    case "4,feet":
                        ProcessBuyOrMakeItem(Database.FeetWear, "feet Wear");

                        break;

                    case "5,nothing,sorry,leave":
                        WriteLine($"You shut {ActiveBuilding.Owner.Name}'s door and leave the {ActiveBuilding.Type.ToString("G").ToLower()}.");
                        CurrentLocation = Location.LocationSpot;
                        ActiveBuilding  = null;

                        break;

                    case "6,sell":
                        stats.ToSellSomething = true;
                        Question($"What do you want to sell? Double click on the item you wish to sell", "yes", "no");

                        CurrentLocation = Location.LocationSpot;
                        ActiveBuilding  = null;
                        break;

                    case "7,tool":
                        ProcessBuyOrMakeItem(Database.Tools, "Tools");

                        break;
                    }

                    break;

                case Location.Forest:
                    // some kind of person has appeared.
                    CurrentForestEvent = ForestEvent.None;
                    List <Tuple <string, string, Action> > Commands3 = new List <Tuple <string, string, Action> >();

                    // get town From X Y
                    var mapItem = Map[CurrentX, CurrentY];
                    mapItem.Visible = true;

                    Commands3.Add(new Tuple <string, string, Action>($"{Commands3.Count}: Go West?", $"west,left,{Commands3.Count}", () => {
                        stats.ProcessMovement(CurrentX - 1, CurrentY);
                    }));
                    Commands3.Add(new Tuple <string, string, Action>($"{Commands3.Count}: Go North?", $"north,up,{Commands3.Count}", () => {
                        stats.ProcessMovement(CurrentX, CurrentY - 1);
                    }));
                    Commands3.Add(new Tuple <string, string, Action>($"{Commands3.Count}: Go East?", $"east,up,{Commands3.Count}", () => {
                        stats.ProcessMovement(CurrentX + 1, CurrentY);
                    }));
                    Commands3.Add(new Tuple <string, string, Action>($"{Commands3.Count}: Go South?", $"south,up,{Commands3.Count}", () => {
                        stats.ProcessMovement(CurrentX, CurrentY + 1);
                    }));

                    if (mapItem is LocationSpot)
                    {
                        ActiveLocation = mapItem as LocationSpot;
                        WriteLineColor($"You have found a town called {ActiveLocation.Name}", ConsoleColor.Yellow, ConsoleColor.Black);

                        Commands3.Add(new Tuple <string, string, Action>($"{Commands3.Count}: Would you like to enter {ActiveLocation.Name}?", $"{ActiveLocation.Name},yes,{Commands3.Count}", () => {
                            CurrentLocation = Location.LocationSpot;
                        }));
                    }
                    else
                    {
                        ActiveLocation = null;
                    }

                    List <string> Options3 = new List <string>();
                    var           Builder3 = new StringBuilder($"which direction do you want to go?\r\n");

                    foreach (var item in Commands3)
                    {
                        Options3.Add(item.Item2);
                        Builder3.AppendLine(item.Item1);
                    }

                    if (mapItem is Ground)
                    {
                        ProcessRandomEvent();
                        if (CurrentLocation == Location.LocationSpot)
                        {
                            continue;
                        }
                    }

                    input = Question(Builder3.ToString(), Options3.ToArray());

                    for (int i = 0; i < Options3.Count; i++)
                    {
                        if (input == Commands3[i].Item2.ToLower())
                        {
                            Commands3[i].Item3();
                            break;
                        }
                    }

                    if (CurrentLocation == Location.Forest)
                    {
                        WriteLine($"Your current location is now {CurrentX}, {CurrentY}.");
                    }

                    break;
                }
            }
        }