Exemplo n.º 1
0
        public List <AirCarrier> GetAirCarrier(string sqlWhere)
        {
            List <AirCarrier> listAirCarrier = new List <AirCarrier>();
            string            sql            = "select * from dbo.AirCarrier";

            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sql += " where " + sqlWhere;
            }
            using (SqlConnection conn = new SqlConnection(strConnectionString))
            {
                try
                {
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }
                    SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    while (rdr.Read())
                    {
                        AirCarrier ac = new AirCarrier();
                        //ac._id = rdr["_id"] != null ? rdr["_id"].ToString() : "";
                        ac.AirName    = rdr["AirName"] != null ? rdr["AirName"].ToString() : "";
                        ac.Code       = rdr["Code"] != null ? rdr["Code"].ToString() : "";
                        ac.SettleCode = rdr["SettleCode"] != null ? rdr["SettleCode"].ToString() : "";
                        ac.ShortName  = rdr["ShortName"] != null ? rdr["ShortName"].ToString() : "";
                        ac.YDOffice   = rdr["YDOffice"] != null ? rdr["YDOffice"].ToString() : "";
                        ac.CPOffice   = rdr["CPOffice"] != null ? rdr["CPOffice"].ToString() : "";
                        ac.ShortName  = rdr["PrintNo"] != null ? rdr["PrintNo"].ToString() : "";
                        listAirCarrier.Add(ac);
                    }
                    rdr.Close();
                }
                catch (SqlException ex)
                {
                    JoveZhao.Framework.Logger.WriteLog(JoveZhao.Framework.LogType.ERROR, "航班数据库查询[GetAirCarrier]", ex);
                }
                catch (Exception e)
                {
                    JoveZhao.Framework.Logger.WriteLog(JoveZhao.Framework.LogType.ERROR, "航班数据库查询[GetAirCarrier]", e);
                }
            }
            return(listAirCarrier);
        }
Exemplo n.º 2
0
    public Entity SpawnEntity(EntityBlueprint blueprint, Sector.LevelEntity data)
    {
        GameObject gObj = new GameObject(data.name);
        string     json = null;

        switch (blueprint.intendedType)
        {
        case EntityBlueprint.IntendedType.ShellCore:
        {
            ShellCore shellcore = gObj.AddComponent <ShellCore>();
            try
            {
                // Check if data has blueprint JSON, if it does override the current blueprint
                // this now specifies the path to the JSON file instead of being the JSON itself
                json = data.blueprintJSON;
                if (json != null && json != "")
                {
                    blueprint = ScriptableObject.CreateInstance <EntityBlueprint>();

                    // try parsing directly, if that fails try fetching the entity file
                    try
                    {
                        JsonUtility.FromJsonOverwrite(json, blueprint);
                    }
                    catch
                    {
                        JsonUtility.FromJsonOverwrite(System.IO.File.ReadAllText
                                                          (resourcePath + "\\Entities\\" + json + ".json"), blueprint);
                    }

                    //Debug.Log(data.name);
                    blueprint.entityName = data.name;
                }
                else
                {
                    shellcore.entityName = blueprint.entityName = data.name;
                }

                if (current.type == Sector.SectorType.BattleZone)
                {
                    // add core arrow
                    if (MinimapArrowScript.instance && !(shellcore is PlayerCore))
                    {
                        shellcore.faction = data.faction;
                        MinimapArrowScript.instance.AddCoreArrow(shellcore);
                    }


                    // set the carrier of the shellcore to the associated faction's carrier
                    if (carriers.ContainsKey(data.faction))
                    {
                        shellcore.SetCarrier(carriers[data.faction]);
                    }

                    battleZone.AddTarget(shellcore);
                }
            }
            catch (System.Exception e)
            {
                Debug.Log(e.Message);
                //blueprint = obj as EntityBlueprint;
            }
            shellcore.sectorMngr = this;
            break;
        }

        case EntityBlueprint.IntendedType.PlayerCore:
        {
            if (player == null)
            {
                player            = gObj.AddComponent <PlayerCore>();
                player.sectorMngr = this;
            }
            else
            {
                Destroy(gObj);
                return(null);
            }

            break;
        }

        case EntityBlueprint.IntendedType.Turret:
        {
            gObj.AddComponent <Turret>();
            break;
        }

        case EntityBlueprint.IntendedType.Tank:
        {
            gObj.AddComponent <Tank>();
            break;
        }

        case EntityBlueprint.IntendedType.Bunker:
        {
            json = data.blueprintJSON;
            if (json != null && json != "")
            {
                var dialogueRef = blueprint.dialogue;
                blueprint = ScriptableObject.CreateInstance <EntityBlueprint>();

                // try parsing directly, if that fails try fetching the entity file
                try
                {
                    JsonUtility.FromJsonOverwrite(json, blueprint);
                }
                catch
                {
                    JsonUtility.FromJsonOverwrite(System.IO.File.ReadAllText
                                                      (resourcePath + "\\Entities\\" + json + ".json"), blueprint);
                }

                blueprint.dialogue = dialogueRef;
            }

            blueprint.entityName = data.name;
            Bunker bunker = gObj.AddComponent <Bunker>();
            stations.Add(bunker);
            bunker.vendingBlueprint =
                blueprint.dialogue != null
                        ? blueprint.dialogue.vendingBlueprint
                        : ResourceManager.GetAsset <VendingBlueprint>(data.vendingID);
            break;
        }

        case EntityBlueprint.IntendedType.Outpost:
        {
            json = data.blueprintJSON;
            if (json != null && json != "")
            {
                var dialogueRef = blueprint.dialogue;
                blueprint = ScriptableObject.CreateInstance <EntityBlueprint>();

                // try parsing directly, if that fails try fetching the entity file
                try
                {
                    JsonUtility.FromJsonOverwrite(json, blueprint);
                }
                catch
                {
                    JsonUtility.FromJsonOverwrite(System.IO.File.ReadAllText
                                                      (resourcePath + "\\Entities\\" + json + ".json"), blueprint);
                }
                blueprint.dialogue = dialogueRef;
            }

            blueprint.entityName = data.name;
            Outpost outpost = gObj.AddComponent <Outpost>();
            stations.Add(outpost);
            outpost.vendingBlueprint =
                blueprint.dialogue != null
                        ? blueprint.dialogue.vendingBlueprint
                        : ResourceManager.GetAsset <VendingBlueprint>(data.vendingID);
            break;
        }

        case EntityBlueprint.IntendedType.Tower:
        {
            break;
        }

        case EntityBlueprint.IntendedType.Drone:
        {
            Drone drone = gObj.AddComponent <Drone>();
            //drone.path = ResourceManager.GetAsset<Path>(data.pathID);
            break;
        }

        case EntityBlueprint.IntendedType.AirCarrier:
            json = data.blueprintJSON;
            if (json != null && json != "")
            {
                blueprint = ScriptableObject.CreateInstance <EntityBlueprint>();

                // try parsing directly, if that fails try fetching the entity file
                try
                {
                    JsonUtility.FromJsonOverwrite(json, blueprint);
                }
                catch
                {
                    JsonUtility.FromJsonOverwrite(System.IO.File.ReadAllText
                                                      (resourcePath + "\\Entities\\" + json + ".json"), blueprint);
                }
            }

            blueprint.entityName = data.name;
            AirCarrier carrier = gObj.AddComponent <AirCarrier>();
            if (!carriers.ContainsKey(data.faction))
            {
                carriers.Add(data.faction, carrier);
            }
            carrier.sectorMngr = this;
            break;

        case EntityBlueprint.IntendedType.GroundCarrier:
            json = data.blueprintJSON;
            if (json != null && json != "")
            {
                blueprint = ScriptableObject.CreateInstance <EntityBlueprint>();

                // try parsing directly, if that fails try fetching the entity file
                try
                {
                    JsonUtility.FromJsonOverwrite(json, blueprint);
                }
                catch
                {
                    JsonUtility.FromJsonOverwrite(System.IO.File.ReadAllText
                                                      (resourcePath + "\\Entities\\" + json + ".json"), blueprint);
                }
            }

            blueprint.entityName = data.name;
            GroundCarrier gcarrier = gObj.AddComponent <GroundCarrier>();
            if (!carriers.ContainsKey(data.faction))
            {
                carriers.Add(data.faction, gcarrier);
            }
            gcarrier.sectorMngr = this;
            break;

        case EntityBlueprint.IntendedType.Yard:
            Yard yard = gObj.AddComponent <Yard>();
            yard.mode = BuilderMode.Yard;
            break;

        case EntityBlueprint.IntendedType.WeaponStation:
            gObj.AddComponent <WeaponStation>();
            break;

        case EntityBlueprint.IntendedType.CoreUpgrader:
            gObj.AddComponent <CoreUpgrader>();
            break;

        case EntityBlueprint.IntendedType.Trader:
            Yard trade = gObj.AddComponent <Yard>();
            trade.mode = BuilderMode.Trader;
            try
            {
                bool ok = true;
                if (blueprint.dialogue == null)
                {
                    ok = false;
                }
                if (blueprint.dialogue.traderInventory == null)
                {
                    ok = false;
                }
                if (data.blueprintJSON == null || data.blueprintJSON == "")
                {
                    ok = false;
                }
                if (ok)
                {
                    ShipBuilder.TraderInventory inventory = JsonUtility.FromJson <ShipBuilder.TraderInventory>(data.blueprintJSON);
                    if (inventory.parts != null)
                    {
                        blueprint.dialogue.traderInventory = inventory.parts;
                    }
                }
                else
                {
                    blueprint.dialogue.traderInventory = new List <EntityBlueprint.PartInfo>();
                }
            }
            catch (System.Exception e)
            {
                Debug.LogWarning(e);
                blueprint.dialogue.traderInventory = new List <EntityBlueprint.PartInfo>();
            }
            break;

        case EntityBlueprint.IntendedType.DroneWorkshop:
            Yard workshop = gObj.AddComponent <Yard>();
            workshop.mode = BuilderMode.Workshop;
            break;

        default:
            break;
        }
        Entity entity = gObj.GetComponent <Entity>();

        // TODO: These lines should perhaps be moved somewhere inside Entity itself, they need to run before even Awake is called
        if (!AIData.entities.Contains(entity))
        {
            AIData.entities.Add(entity);
        }
        entity.sectorMngr = this;
        entity.faction    = data.faction;
        entity.spawnPoint = entity.transform.position = data.position;
        entity.blueprint  = blueprint;

        if (entity as AirCraft && data.patrolPath != null && data.patrolPath.waypoints != null && data.patrolPath.waypoints.Count > 0)
        {
            // patrolling
            (entity as AirCraft).GetAI().setPath(data.patrolPath, null, true);
        }

        if (data.ID == "" || data.ID == null || (objects.ContainsKey(data.ID) && !objects.ContainsValue(gObj)))
        {
            data.ID = objects.Count.ToString();
        }
        entity.ID = data.ID;

        if (!objects.ContainsKey(data.ID))
        {
            objects.Add(data.ID, gObj);
        }
        return(entity);
    }