Пример #1
0
        public IResponseFormatter Add()
        {
            var skillDefinitions = GnomanEmpire.Instance.GetSkillDefs();
            var faction = GnomanEmpire.Instance.World.AIDirector.PlayerFaction;
            var entryPosition = faction.FindRegionEntryPosition();

            var gnomadRaceClassDefs = faction.FactionDef.Squads.SelectMany(squad => squad.Classes.Where(squadClass => squadClass.Name == "Gnomad")).ToList();
            Int32 defCount = gnomadRaceClassDefs.Count;
            Int32 raceClassDefIndex = GnomanEmpire.Instance.Rand.Next(defCount);
            var raceClassDef = gnomadRaceClassDefs[raceClassDefIndex];
            var gnomad = new Character(entryPosition, raceClassDef, faction.ID);
            gnomad.SetBehavior(BehaviorType.PlayerCharacter);

            Dictionary<String, Int32> orderedProfessions = GetBestProfessions(gnomad);
            var bestProfession = orderedProfessions.OrderByDescending(obj => obj.Value).First().Key;
            SetProfession(gnomad, bestProfession);

            GnomanEmpire.Instance.EntityManager.SpawnEntityImmediate(gnomad);
            GnomanEmpire.Instance.World.NotificationManager.AddNotification(String.Format("The Gnomad {0} has arrived and been assigned as a {1}", gnomad.Name(), bestProfession));

            Gnome gnome = new Gnome(gnomad, skillDefinitions);
            return JsonResponse(gnome);
        }