public void Setup()
        {
            Mock <ResourceFactoryDef> defMock = new Mock <ResourceFactoryDef>();

            def = defMock.Object;

            Mock <GameController> gameMock = new Mock <GameController>(GameSpeed.Regular, GameState.Paused);

            Mock <Faction_Controller> factionMock = new Mock <Faction_Controller>("test_faction", gameMock.Object);

            faction = factionMock.Object;
        }
示例#2
0
        private static ResourceType GetResourceBuildingValues(int structureId)
        {
            DBConn = OpenConnection("DefDex.db");

            const string query = "SELECT Def_ResourceType.name as resource_type " +
                                 "FROM BuildingDef " +
                                 "JOIN Def_ResourceFactory ON BuildingDef.Id = Def_ResourceFactory.id " +
                                 "JOIN Def_ResourceType ON Def_ResourceFactory.resource_type_id = Def_ResourceType.id " +
                                 "WHERE BuildingDef.Id = @i";
            ResourceType resourceType;

            using (SqliteCommand cmd = new SqliteCommand(query, DBConn))
            {
                cmd.Parameters.Add(new SqliteParameter("@i", structureId));


                using (SqliteDataReader reader = cmd.ExecuteReader())
                {
                    if (!reader.Read())
                    {
                        throw new DataNotFoundException($"ResourceBuilding with id {structureId}");
                    }

                    ResourceFactoryDef resourceFactoryDef = new ResourceFactoryDef();
                    switch (reader["resource_type"].ToString().ToLower())
                    {
                    case "wood":
                        resourceType = ResourceType.Wood;
                        break;

                    case "stone":
                        resourceType = ResourceType.Stone;
                        break;

                    case "food":
                        resourceType = ResourceType.Food;
                        break;

                    default: throw new DataException($"Invalid ResourceType {reader["resource_type"]}");
                    }
                }
            }

            return(resourceType);
        }
示例#3
0
        //FIXME split into multiple methods, GetBuildingDef, GetResourceFactoryDef, etc.
        //FIXME this is horribly designed. Do the above.
        // get the Def from a given building
        public static TStructureDef GetBuildingDef <TStructureDef>(int buildingId) where TStructureDef : BuildingDef
        {
            DBConn = OpenConnection("DefDex.db");

            string query = "SELECT * FROM BuildingDef WHERE Id=@i";

            bool isResourceFactory = IsBuildingResourceFactory(buildingId);

            BuildingDef buildingDef = new BuildingDef();

            if (isResourceFactory)
            {
                ResourceFactoryDef factoryDef = new ResourceFactoryDef
                {
                    ResourceType = GetResourceBuildingValues(buildingId)
                };
                buildingDef = factoryDef;
            }

            bool isTrainingStructure = IsStructureTrainingEntity(buildingId);

            if (isTrainingStructure)
            {
                TrainingStructureDef factoryDef = new TrainingStructureDef
                {
                    TrainableDefs = GetTrainingEntityTrainables(buildingId).ToList()
                };
                buildingDef = factoryDef;
            }

            using (SqliteCommand cmd = new SqliteCommand(query, DBConn))
            {
                cmd.Parameters.Add(new SqliteParameter("@i", buildingId));

                using (SqliteDataReader reader = cmd.ExecuteReader())
                {
                    if (!reader.Read())
                    {
                        throw new BuildingNotFoundException(buildingId);
                    }


                    //buildingDef.HPDef.CurrentHP = int.Parse(reader["CurrentHp"].ToString());
                    //buildingDef.HPDef.MaxHP = int.Parse(reader["MaxHp"].ToString());

                    ViewValues viewValues = new ViewValues(
                        reader["image"].ToString(),
                        float.Parse(reader["width"].ToString()),
                        float.Parse(reader["height"].ToString())
                        );

                    buildingDef.ViewValues = viewValues;

                    buildingDef.BuildingShape = BuildingShapeCalculator.GetShapeFromString(reader["shape"].ToString());

                    buildingDef.Cost       = float.Parse(reader["Cost"].ToString());
                    buildingDef.UpkeepCost = float.Parse(reader["Upkeep"].ToString());

                    buildingDef.ViewRange = int.Parse(reader["ViewRange"].ToString());

                    buildingDef.ConstructionTime = uint.Parse(reader["ConstructionTime"].ToString());
                }
            }

            return((TStructureDef)buildingDef);
        }