Пример #1
0
        public static void LoadFromTable(this Kingdom.Behavior behavior, Table table)
        {
            // Events in lua actually have an additional parameter to each event - "date",
            // which is "today's date" in form of a table object

            behavior.onNewDay = new Action <Kingdom>((kingdom) =>
            {
                var tKingdom = kingdom.Serialize(table.OwnerScript);
                table.Get("onNewDay").Function.Call(
                    tKingdom,
                    DateHelper.Serialize(Game.clock.GetDate(), table.OwnerScript)
                    );
                kingdom.LoadValuesFromTable(tKingdom);
            });

            behavior.onNewMonth = new Action <Kingdom>((kingdom) =>
            {
                var tKingdom = kingdom.Serialize(table.OwnerScript);
                table.Get("onNewMonth").Function.Call(
                    tKingdom,
                    DateHelper.Serialize(Game.clock.GetDate(), table.OwnerScript)
                    );
                kingdom.LoadValuesFromTable(tKingdom);
            });

            behavior.onNewYear = new Action <Kingdom>((kingdom) =>
            {
                var tKingdom = kingdom.Serialize(table.OwnerScript);
                table.Get("onNewYear").Function.Call(
                    tKingdom,
                    DateHelper.Serialize(Game.clock.GetDate(), table.OwnerScript)
                    );
                kingdom.LoadValuesFromTable(tKingdom);
            });
        }
Пример #2
0
        public static Race MakeRaceFrom(this Table table)
        {
            var race = new Race();

            race.id   = (int)table.Get("id").Number;
            race.name = table.Get("name").String;
            race.characterNameFormat = table.Get("characterNameFormat").String;
            race.plural     = table.Get("plural").String;
            race.isPlayable = table.Get("isPlayable").Boolean;

            // Names
            race.names          = new Race.Names();
            race.names.family   = new List <string>(table.Get("names").Table.Get("family").Table.Values.Select(o => o.String).ToArray());
            race.names.first    = new List <string>(table.Get("names").Table.Get("first").Table.Values.Select(o => o.String).ToArray());
            race.names.kingdoms = new List <string>(table.Get("names").Table.Get("kingdoms").Table.Values.Select(o => o.String).ToArray());

            // Images
            foreach (var portraitUrl in table.Get("portraits").Table.Values)
            {
                race.portraits.Add(new Image(portraitUrl.String));
            }
            race.pawn = new Image(table.Get("pawnImage").String);

            // Ruler rules
            var rules = table.Get("rulerCreationRules").Table;

            race.rulerCreationRules = new Ruler.CreationRules()
            {
                lifespanToStockRatio = (float)rules.Get("lifespanToStockRatio").Number,
                majority             = (int)rules.Get("majority").Number,
                maximumLifespan      = (int)rules.Get("maximumLifespan").Number,
                maxStartingAge       = (int)rules.Get("maxStartingAge").Number,
                stock = (int)rules.Get("stock").Number
            };

            race.rulerCreationRules.characteristicDefinitions = CharacteristicsHelper.MakeCharacteristicDefinitionsFrom(rules.Get("characteristicDefinitions").Table);

            var behavior = new Kingdom.Behavior();

            behavior.LoadFromTable(table.Get("kingdomBehavior").Table);
            race.kingdomBehavior = behavior;

            race.resourceDefinitions = new Resource.Definitions();
            race.resourceDefinitions.LoadFromTable(table.Get("resourceDefinitions").Table);

            //TODO: Implement
            //race.genders = table.Get("genders").Number;

            return(race);
        }