Ejemplo n.º 1
0
        // --------------------------------------------------------------------------------------------------------------------
        //  Constructors
        // --------------------------------------------------------------------------------------------------------------------

        public Player(Enum template, string name, int maxHP, Gender gender, Faction faction, Race race, Location location,
                      Enum weaponTemplate = null, Enum armorTemplate = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException("Error: Player constructor null name error");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException("Error: Player constructor empty name error");
            }
            if (maxHP <= 0)
            {
                throw new ArgumentOutOfRangeException("Error: Player constructor maxHP must be > 0");
            }
            if (weaponTemplate == null)
            {
                weaponTemplate = ItemType.Unarmed;
            }
            if (armorTemplate == null)
            {
                armorTemplate = ItemType.Unarmored;
            }

            this.UnitType = template;
            this.Name     = name;
            this.MaxHP    = maxHP;
            this.HP       = MaxHP;
            this.Gender   = gender;
            this.Faction  = faction;
            this.Race     = race;
            this.Location = location;

            TimeToAct = GameEngine.WorldTime + (ulong)rng.Next(GameEngine.MSTimePerPCAction);

            if (!weaponTemplate.Equals(ItemType.Unarmed))
            {
                this.weapon = (Weapon)Prefabs.NewItem(weaponTemplate);
            }
            if (!armorTemplate.Equals(ItemType.Unarmored))
            {
                this.armor = (Armor)Prefabs.NewItem(armorTemplate);
            }

            this.Flags      = new List <Enum>();
            PersonalEffects = new List <StatusEffect>();
            actions         = new List <ActionOption <Player, MenuOptionType> >();
            notifications   = new List <TimeText>();
            HatedUnits      = new Dictionary <Player, int>();
            causeOfDeath    = "";
        }
Ejemplo n.º 2
0
        private static void DoProdWater(Player player, Location location)
        {
            if (player == null)
            {
                throw new ArgumentNullException($"Error: LocationAction DoProdWater null player.");
            }
            if (location == null)
            {
                throw new ArgumentNullException($"Error: LocationAction DoProdWater null location.");
            }

            if (player.IsAlive && player.Location == location && player.HasItem(ItemType.Stick))
            {
                GameEngine.SayToLocation(location, $"{player.Name} prods the water with a crook...");
                if (!player.HasFlag(QuestFlags.ProddedCloths))
                {
                    player.AddFlag(QuestFlags.ProddedCloths);
                    player.Notify("  *  GET! You found yourself some new clothes!");
                    GameEngine.SayToLocation(location, $"{player.Name} picks up bits of clothing from the putrid water.");
                    Armor newArmor = (Armor)Prefabs.NewItem(ItemType.Cloth);
                    newArmor.AddSocket();
                    player.AddItem(newArmor);
                }
                else if (!player.HasFlag(QuestFlags.ProddedRustSword))
                {
                    player.AddFlag(QuestFlags.ProddedRustSword);
                    player.Notify("  *  GET! You found yourself a rusty sword!");
                    GameEngine.SayToLocation(location, $"{player.Name} picks up a broken, rusty sword from the putrid water.");
                    Weapon newWeapon = (Weapon)Prefabs.NewItem(ItemType.RustySword);
                    newWeapon.AddSocket();
                    player.AddItem(newWeapon);
                }
                else
                {
                    GameEngine.SayToLocation(location, $"...but gets distracted by {player.Genderize("his handsome", "her beautiful", "its mesmerizing")} reflection.");
                }
            }
            else
            {
                GameEngine.SayToLocation(player.Location, $"{player.Name} was about to prod the water with a stick but didn't succeed...");
            }
        }
Ejemplo n.º 3
0
 private void SetMenu(string userInput)
 {
     if (playerGender == Gender.Unset)
     {
         userInput = userInput.Trim();
         if (userInput.Length > 0 && userInput.Substring(0, 1).ToLower() == "m")
         {
             playerGender = Gender.Male;
             MenuState    = MenuState.Normal;
         }
         else if (userInput.Length > 0 && userInput.Substring(0, 1).ToLower() == "f")
         {
             playerGender = Gender.Female;
             MenuState    = MenuState.Normal;
         }
         else
         {
             MenuState = MenuState.Error;
         }
     }
     else if (playerName == "")
     {
         userInput = userInput.Trim();
         if (userInput.Length >= GameEngine.MinimumNameLength && userInput.Length <= GameEngine.MaximumNameLength)
         {
             playerName = TextUtils.FormatName(userInput);
             MenuState  = MenuState.Normal;
         }
         else
         {
             MenuState = MenuState.Error;
         }
     }
     else
     {
         Prefabs.NewPlayer(playerName, playerGender, client: this);
         MenuState = MenuState.Exiting;
     }
 }
Ejemplo n.º 4
0
        public static void InitializeGame(bool enableListeners)
        {
            Thread.CurrentThread.Name = "Main Game Worker";

            SayToServer("\nGame initializing:\n");

            SayToServer("\nStarting PHASE 1 \"Core Startup\" - Basic worldgen and prefab testing:\n");
            WorldMap.Generate();
            Prefabs.TestGenerationDatabase();
            SayToServer("PHASE 1 completed.\n");

            SayToServer("\nStarting PHASE 2 \"Plugin Startup\" - Run Mapper and Spawner Plugin Startup Procedures:\n");
            Plugins.LoadPlugins();
            Plugins.RunStartupPlugins();
            SayToServer("PHASE 2 completed.\n");

            SayToServer("\nStarting PHASE 3 \"Finalization\" - Syncing plugins w/ core (rehashing dictionaries), cleaning garbage, starting listener (if enabled):\n");
            WorldMap.PopulateLookupDictionary();
            GarbageCollect();
            if (enableListeners)
            {
                NetworkServer.CreateAsyncListener <NetworkClient>();
            }
            SayToServer("PHASE 3 completed.\n");

            SayToServer("\nGame has been initialized!\n\n");
            Running = true;

            RunGame(CancelToken);

            SayToServer("\nGame engine shutdown detected!\n\n");
            if (enableListeners)
            {
                NetworkServer.CloseAsyncListener();
            }
        }
Ejemplo n.º 5
0
        private static void DoCrossBridge(Player player, Location location)
        {
            if (player == null)
            {
                throw new ArgumentNullException($"Error: LocationAction DoCrossBridge null player.");
            }
            if (location == null)
            {
                throw new ArgumentNullException($"Error: LocationAction DoCrossBridge null location.");
            }

            if (player.IsAlive && player.Location == location)
            {
                GameEngine.SayToLocation(location, $"{player.Name} tries to cross the bridge...");
                GameEngine.SayToLocation(location, $"A nasty goblin charges at {player.Genderize("him", "her", "it")} from under the bridge and attacks!");
                Player newGoblin = Prefabs.SpawnUnit(UnitType.WeakGoblin, location);
                PlayerActions.Attack(newGoblin, player);
                newGoblin.ResetTimeToAct();
            }
            else
            {
                GameEngine.SayToLocation(player.Location, $"{player.Name} was about to search the foliage but didn't succeed...");
            }
        }
Ejemplo n.º 6
0
 public void AddItem(Enum itemType)
 {
     Items.Add(Prefabs.NewItem(itemType));
 }
Ejemplo n.º 7
0
        private static void HandleKeyInput(ConsoleKey key)
        {
            bool subdueMenuRepeat = false;

            if (!GameEngine.Running)
            {
                switch (key)
                {
                case ConsoleKey.X:
                case ConsoleKey.Q:
                    WriteLine("Exiting...");
                    done = true;
                    break;

                case ConsoleKey.S:
                    GameTask = Task.Factory.StartNew(() => LaunchGameWithThreadName());
                    while (!GameEngine.Running)
                    {
                        Thread.Sleep(100);
                    }
                    break;

                case ConsoleKey.L:
                    GameTask = Task.Factory.StartNew(() => LaunchGameWithThreadName());
                    while (!GameEngine.Running)
                    {
                        Thread.Sleep(100);
                    }
                    GameEngine.PlayAsServer();
                    break;

                case ConsoleKey.K:
                    GameTask = Task.Factory.StartNew(() => LaunchGameWithThreadName(false));
                    while (!GameEngine.Running)
                    {
                        Thread.Sleep(100);
                    }
                    GameEngine.PlayAsServer();
                    break;

                case ConsoleKey.C:
                    StandaloneClient.RunClient();
                    break;

                case ConsoleKey.D:
                    StandaloneClient.RunClient("dstults.net", 11111);
                    break;

                default:
                    subdueMenuRepeat = true;
                    break;
                }
            }
            else
            {
                switch (key)
                {
                case ConsoleKey.X:
                case ConsoleKey.Q:
                    WriteLine("Exiting...");
                    GameEngine.Shutdown();
                    GameTask.Wait();
                    done = true;
                    break;

                case ConsoleKey.S:
                    WriteLine(WorldMap.GetLocationList());
                    Write($" Where? > ");
                    Location unitLoc = WorldMap.GetLocation(Console.ReadLine());
                    if (unitLoc == null)
                    {
                        WriteLine("Invalid location name");
                        break;
                    }
                    WriteLine(Prefabs.GetPrefabUnitList());
                    Write($" What unit? > ");
                    Player myUnit = Prefabs.SpawnUnitAtLocation(Console.ReadLine(), unitLoc);
                    if (myUnit != null)
                    {
                        WriteLine($"Playable unit [{myUnit.Name}] spawned at [{unitLoc.Name}].");
                    }
                    else
                    {
                        WriteLine($"Invalid unit type or incomplete unit creation.");
                    }
                    break;

                case ConsoleKey.I:
                    WriteLine(WorldMap.GetLocationList());
                    Write($" Where? > ");
                    Location itemLoc = WorldMap.GetLocation(Console.ReadLine());
                    if (itemLoc == null)
                    {
                        WriteLine("Invalid location name");
                        break;
                    }
                    WriteLine(Prefabs.GetPrefabItemList());
                    Write($" What item? > ");
                    Item myItem = Prefabs.SpawnItemAtLocation(Console.ReadLine(), itemLoc);
                    if (myItem != null)
                    {
                        WriteLine($"Item [{myItem.Title}] spawned at [{itemLoc.Name}].");
                        GameEngine.SayToLocation(itemLoc, $"All of the sudden {myItem.SetName()} appears!");
                    }
                    else
                    {
                        WriteLine($"Invalid item name.");
                    }
                    break;

                case ConsoleKey.P:
                    WriteLine("Polling current clients:");
                    WriteLine(NetworkServer.GetConnectionPolling(verbose: true, detailed: false));
                    break;

                case ConsoleKey.D:
                    WriteLine("Polling current clients (detailed):");
                    WriteLine(NetworkServer.GetConnectionPolling(verbose: true, detailed: true));
                    break;

                case ConsoleKey.G:
                    WriteLine(GameEngine.GameInfo());
                    break;

                case ConsoleKey.V:
                    WriteLine(TextUtils.Borderize(TextUtils.Columnize(TextUtils.GetCustomListFromNamedList(GameEngine.Players, numbered: true, lowered: true))));
                    Write($" ? (1-{GameEngine.Players.Count}) > ");
                    Player viewPlayer = GameEngine.GetPlayer(Console.ReadLine());
                    if (viewPlayer != null)
                    {
                        WriteLine("\n================================================================");
                        WriteLine(viewPlayer.GetFullInGameView());
                    }
                    else
                    {
                        WriteLine("No such player.");
                    }
                    break;

                case ConsoleKey.O:
                    WriteLine(TextUtils.Borderize(TextUtils.Columnize(TextUtils.GetCustomListFromNamedList(GameEngine.Players, numbered: true, lowered: true))));
                    Write($" ? (1-{GameEngine.Players.Count}) > ");
                    Player possessPlayer = GameEngine.GetPlayer(Console.ReadLine());
                    if (possessPlayer != null)
                    {
                        GameEngine.PlayAsServer(possessPlayer);
                    }
                    else
                    {
                        WriteLine("No such player.");
                    }
                    break;

                case ConsoleKey.Z:
                    GameEngine.TogglePause();
                    break;

                default:
                    subdueMenuRepeat = true;
                    break;
                }
            }

            if (!subdueMenuRepeat && !done)
            {
                ShowMenu();
            }
        }
Ejemplo n.º 8
0
 public void AddItem(ItemType itemType)
 {
     AddItem(Prefabs.NewItem(itemType));
 }
Ejemplo n.º 9
0
        private static void DoSearchForest(Player player, Location location)
        {
            if (player == null)
            {
                throw new ArgumentNullException($"Error: LocationAction DoSearchForest null player.");
            }
            if (location == null)
            {
                throw new ArgumentNullException($"Error: LocationAction DoSearchForest null location.");
            }

            if (player.IsAlive && player.Location == location)
            {
                GameEngine.SayToLocation(location, $"{player.Name} searches the area.");
                if (!player.HasFlag(QuestFlags.ForestEmerald))
                {
                    player.AddFlag(QuestFlags.ForestEmerald);
                    if (player is Player)
                    {
                        GameEngine.SayToLocation(location, $"{player.Name} looks very closely at a green object...it's an emerald! {player.Genderize("He", "She", "It")} picks it up.");
                        (player).AddItem(ItemType.Emerald);
                        player.Notify("  *  Once you find some armor you can insert this to gain a passive ability!");
                    }
                    else
                    {
                        GameEngine.SayToLocation(location, $"{player.Name} looks very closely at a green object...it's an emerald!");
                        location.AddItem(ItemType.Emerald);
                    }
                }
                else if (player is Player && !(player).HasItem(ItemType.Stick))
                {
                    GameEngine.SayToLocation(location, $"{player.Name} discovers a nice stick!");
                    player.Notify("  *  It has a crooked head. You might even be able to pull something from the river.");
                    GameEngine.SayToLocation(location, $"{player.Name} picks up a stick.");
                    (player).AddItem(ItemType.Stick);
                }
                else
                {
                    switch (new Random().Next(5))
                    {
                    case 0:
                        player.Notify("  *  You discovered a Long Sword and some Chain Mail hidden behind a tree!");
                        GameEngine.SayToLocation(location, $"{player.Name} suddenly looks very excited! Then not.");
                        player.Notify("  *  Oh wait...it was just a shadow.");
                        break;

                    case 1:
                        player.Notify("  *  A huge spider is crawling up one of the trees! Prepare yourself!");
                        GameEngine.SayToLocation(location, $"{player.Name} gets startled by the local wildlife!");
                        Prefabs.SpawnUnit(UnitType.Spiderling, location);
                        break;

                    case 2:
                        GameEngine.SayToLocation(location, $"{player.Name} looks very closely at a blue object.");
                        player.Notify("  *  You discovered a beautiful blue butterfly. A shame it serves no purpose.");
                        break;

                    case 3:
                        player.Notify("  *  You don't find anything of interest.");
                        break;

                    case 4:
                        GameEngine.SayToLocation(location, $"{player.Name} discovers a nice stick!");
                        if (player is Player)
                        {
                            (player).AddItem(ItemType.Stick);
                        }
                        else
                        {
                            player.Location.AddItem(ItemType.Stick);
                        }
                        break;
                    }
                }
            }
            else
            {
                GameEngine.SayToLocation(player.Location, $"{player.Name} was about to search the foliage but didn't succeed...");
            }
        }