Ejemplo n.º 1
0
        public static Player NewPlayer(string playerName, Gender gender, Location location = null, GameClient client = null)
        {
            if (playerName == null)
            {
                throw new ArgumentNullException("Error: Player name string null at Prefabs.NewPlayer player creation");
            }
            if (playerName.Length == 0)
            {
                throw new ArgumentNullException("Error: Player name set to blank at Prefabs.NewPlayer player creation");
            }
            if (playerName.Length < GameEngine.MinimumNameLength || playerName.Length > GameEngine.MaximumNameLength)
            {
                throw new ArgumentOutOfRangeException($"Error: Player.NewPlayer name length must be between {GameEngine.MinimumNameLength} and {GameEngine.MaximumNameLength} characters.");
            }
            if (location == null)
            {
                location = WorldMap.PlayerSpawnPoint;
            }
            // client null OK

            Player player = new Player(UnitType.PlayerCharacter, TextUtils.FormatName(playerName), 20, gender, Faction.Players, Race.Human, location: location);

            if (client != null)
            {
                player.AssignClient(client);
                client.AssignAvatar(player);
            }

            player.AddItem(ItemType.RabbitsFoot);
            GameEngine.AddPlayer(player);

            foreach (IPlayerModifiable playerMod in Plugins.PlayerMods)
            {
                player = playerMod.ModifyNewPlayer(player);
            }
            GameEngine.SayToLocation(location, $"{player.Name} appears!");

            return(player);
        }
Ejemplo n.º 2
0
        public static Player SpawnUnit(Enum template, Location location, Gender gender = Gender.Unset)
        {
            // Location == null : valid

            Player newUnit = null;

            foreach (IFabricable templateMod in Plugins.TemplateMods)
            {
                newUnit = templateMod.NewUnit(template);
                if (newUnit != null)
                {
                    break;
                }
            }

            if (newUnit == null && template is UnitType)
            {
                template = (UnitType)template;
                string unitName = "";
                if (gender == Gender.Unset)
                {
                    gender = GetRandomGender();
                }
                switch (template)
                {
                case UnitType.NorthGateGuard:
                    unitName = $"{GetRandomName(Race.Human, gender, template)} the Guard";
                    newUnit  = new Player(template, unitName, 30, gender, Faction.Townsfolk, Race.Human, location,
                                          ItemType.Longsword, ItemType.ChainMail);
                    break;

                case UnitType.SouthGateGuard:
                    unitName = $"{GetRandomName(Race.Human, gender, template)} the Guard";
                    newUnit  = new Player(template, unitName, 30, gender, Faction.Townsfolk, Race.Human, location,
                                          ItemType.Longsword, ItemType.ChainMail);
                    break;

                case UnitType.KeepGuard:
                    unitName = $"{GetRandomName(Race.Human, gender, template)} the Guard";
                    newUnit  = new Player(template, unitName, 40, gender, Faction.Townsfolk, Race.Human, location,
                                          ItemType.MythrilSword, ItemType.PlateArmor);
                    break;

                case UnitType.Chancellor:
                    unitName = $"Chancellor {GetRandomName(Race.Human, gender, template)}";
                    newUnit  = new Player(template, unitName, 50, gender, Faction.Townsfolk, Race.Human, location,
                                          ItemType.MythrilSword, ItemType.PlateArmor);
                    break;

                case UnitType.KingQueen:
                    unitName = gender == Gender.Male ? $"King {GetRandomName(Race.Human, gender, template)}" : $"Queen {GetRandomName(Race.Human, gender, template)}";
                    newUnit  = new Player(template, unitName, 50, gender, Faction.Townsfolk, Race.Human, location,
                                          ItemType.MythrilSword, ItemType.PlateArmor);
                    break;

                case UnitType.WeakGoblin:
                    unitName = GetRandomName(Race.Goblin, gender, template) + " the Goblin";
                    newUnit  = new Player(template, unitName, 20, gender, Faction.Monsters, Race.Goblin, location,
                                          ItemType.BoneClub, ItemType.Leather);
                    AddGoblinLoot(newUnit);
                    break;

                case UnitType.Cultist:
                    unitName = $"{GetRandomName(Race.Human, gender, template)} the Cultist";
                    newUnit  = new Player(template, unitName, 20, gender, Faction.Monsters, Race.Human, location,
                                          ItemType.CultistKris, ItemType.Robes);
                    AddCultistLoot(newUnit);
                    break;

                case UnitType.Skeleton:
                    unitName = "Skeleton";
                    newUnit  = new Player(template, unitName, 15, Gender.Genderless, Faction.Monsters, Race.UndeadHuman, location,
                                          ItemType.Longsword, ItemType.HardBone);
                    break;

                case UnitType.Spiderling:
                    unitName = "Spiderling";
                    newUnit  = new Player(template, unitName, 8, Gender.Genderless, Faction.Monsters, Race.Arachnid, location,
                                          ItemType.WeakPoisonFangs, ItemType.Chitin);
                    AddSpiderlingLoot(newUnit);
                    break;

                case UnitType.Spider:
                    unitName = "Spider";
                    newUnit  = new Player(template, unitName, 20, Gender.Genderless, Faction.Monsters, Race.Arachnid, location,
                                          ItemType.PoisonFangs, ItemType.Chitin);
                    AddSpiderLoot(newUnit);
                    break;

                case UnitType.BroodMother:
                    unitName = "Brood Mother";
                    newUnit  = new Player(template, unitName, 50, Gender.Female, Faction.Monsters, Race.Arachnid, location,
                                          ItemType.StrongPoisonFangs, ItemType.ThickChitin);
                    AddBroodMotherLoot(newUnit);
                    break;
                }
            }
            if (newUnit == null)
            {
                throw new ArgumentOutOfRangeException($"[NewNpc] Unhandled NPC template: {template}");
            }

            if (location != null)
            {
                GameEngine.AddPlayer(newUnit);
                GameEngine.SayToLocation(location, $"{newUnit.Name} appears!");
            }
            return(newUnit);
        }