public virtual void Init(LidServer a_server, int a_type, int a_ownerPid = 0, int a_health = 100, bool a_isNew = true)
    {
        m_isStatic  = false;
        m_server    = a_server;
        m_type      = a_type;
        m_ownerPid  = a_ownerPid;
        m_def       = Buildings.GetBuildingDef(m_type);
        m_decayTime = m_def.decayTime * (double)((float)a_health / 100f);
        if (!m_def.persistent)
        {
            return;
        }
        Vector3 position    = base.transform.position;
        float   a_x         = position.x * 1.00001f;
        Vector3 position2   = base.transform.position;
        float   a_y         = position2.z * 1.00001f;
        Vector3 eulerAngles = base.transform.rotation.eulerAngles;

        m_dbBuilding = new DatabaseBuilding(a_type, a_x, a_y, eulerAngles.y * 1.00001f, a_ownerPid, a_health);
        m_sql        = m_server.GetSql();
        if (null != m_sql)
        {
            if (a_isNew)
            {
                m_dbBuilding.flag = eDbAction.insert;
                m_sql.SaveBuilding(m_dbBuilding);
            }
            m_nextSqlUpdateTime = Random.Range(100f, 300f);
        }
    }
Exemplo n.º 2
0
    private void SQLChangeBuildings(DatabaseBuilding[] a_changedBuildings)
    {
        if (a_changedBuildings == null || a_changedBuildings.Length <= 0)
        {
            return;
        }
        string text = string.Empty;

        for (int i = 0; i < a_changedBuildings.Length; i++)
        {
            DatabaseBuilding databaseBuilding = a_changedBuildings[i];
            string           text2            = " WHERE x > (" + databaseBuilding.x + "-0.2) AND x < (" + databaseBuilding.x + "+0.2) AND y > (" + databaseBuilding.y + "-0.2) AND y < (" + databaseBuilding.y + "+0.2);";
            if (databaseBuilding.flag == eDbAction.delete)
            {
                text = text + "DELETE FROM building" + text2;
            }
            else if (databaseBuilding.flag == eDbAction.update)
            {
                string text3 = text;
                text = text3 + "UPDATE building SET pid=" + databaseBuilding.pid + ", type=" + databaseBuilding.type + ", health=" + databaseBuilding.health + ", x=" + databaseBuilding.x + ", y=" + databaseBuilding.y + ", rot=" + databaseBuilding.rot + text2;
            }
            else if (databaseBuilding.flag == eDbAction.insert)
            {
                string text3 = text;
                text = text3 + "INSERT INTO building (pid, type, health, x, y, rot) VALUES(" + databaseBuilding.pid + ", " + databaseBuilding.type + ", " + databaseBuilding.health + ", " + databaseBuilding.x + ", " + databaseBuilding.y + ", " + databaseBuilding.rot + ");";
            }
        }
        if (text.Length > 1)
        {
            SQLExecute(text);
        }
    }
Exemplo n.º 3
0
 public void SaveBuilding(DatabaseBuilding a_building)
 {
     lock (m_threadLock)
     {
         m_buildingsToWrite.Add(a_building);
     }
 }
Exemplo n.º 4
0
    public void SaveBuilding(DatabaseBuilding a_building)
    {
        object threadLock = this.m_threadLock;

        lock (threadLock)
        {
            this.m_buildingsToWrite.Add(a_building);
        }
    }