private bool ReadBuilding(MySQLRowsReader reader, out BuildingSaveData result, bool resetReader = true)
        {
            if (resetReader)
            {
                reader.ResetReader();
            }

            if (reader.Read())
            {
                result              = new BuildingSaveData();
                result.Id           = reader.GetString("id");
                result.ParentId     = reader.GetString("parentId");
                result.DataId       = reader.GetInt32("dataId");
                result.CurrentHp    = reader.GetInt32("currentHp");
                result.Position     = new Vector3(reader.GetFloat("positionX"), reader.GetFloat("positionY"), reader.GetFloat("positionZ"));
                result.Rotation     = Quaternion.Euler(reader.GetFloat("rotationX"), reader.GetFloat("rotationY"), reader.GetFloat("rotationZ"));
                result.IsLocked     = reader.GetBoolean("isLocked");
                result.LockPassword = reader.GetString("lockPassword");
                result.CreatorId    = reader.GetString("creatorId");
                result.CreatorName  = reader.GetString("creatorName");
                return(true);
            }
            result = new BuildingSaveData();
            return(false);
        }
Beispiel #2
0
    /// <summary>
    /// 从数据库储存数据加载building
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    public static Building Create(BuildingSaveData data)
    {
        Model model = LocalAssetUtil.GetModel(data.ModelDataId);

        if (model == null)
        {
            return(null);
        }
        GameObject obj = CreateGameObjcet(model, data.Name);

        ((TransformGroup)data.TransformGroupSaveData).Inject(obj.transform);
        Building building = AddComponentBuilding(obj.transform, model);

        if (data.MaterialColorSaveData != null)
        {
            Material material = MaterialUtil.Create();
            material.color    = (Color)data.MaterialColorSaveData;
            building.Material = material;
        }
        #region animation
        building.isAnimOn            = data.IsAnimOn;
        building.appearanceAnimDatas = AnimDataUtil.Parse(data.AppearanceAnimDataSaveDatas);
        building.normalAnimDatas     = AnimDataUtil.Parse(data.NormalAnimDataSaveDatas);
        #endregion
        return(building);
    }
 public override void CreateBuildingEntity(BuildingSaveData saveData, bool initialize)
 {
     base.CreateBuildingEntity(saveData, initialize);
     if (!initialize)
     {
         new CreateBuildingJob(Database, Assets.onlineScene.SceneName, saveData).Start();
     }
 }
    public Building BuildingCreate(BuildingSaveData building)
    {
        string building_Type = null;

        BuildingManager.Instance.arrayList.Clear();

        switch (building.buildingType)
        {
        case Building_Type.Small:
            building_Type = "Apartment_Small";
            break;

        case Building_Type.Middle:
            building_Type = "Apartment_Middle";
            break;

        case Building_Type.Big:
            building_Type = "Apartment_Big";
            break;

        case Building_Type.BathHouse:
            building_Type = "BathHouse";
            break;

        case Building_Type.Church:
            building_Type = "Church";
            break;

        case Building_Type.Karaoke:
            building_Type = "Karaoke";
            break;

        case Building_Type.School:
            building_Type = "School";
            break;

        case Building_Type.Company:
            building_Type = "Company";
            break;
        }

        if (building_Type == null)
        {
            return(null);
        }

        GameObject editorBuilding = Instantiate(Resources.Load <GameObject>("InGame/Building/" + building_Type), builingParant.transform);
        Tile       tile           = tiles[(int)building.pos.x, (int)building.pos.y];

        Building buildingObj = editorBuilding.GetComponent <Building>();

        buildingObj.Init(building);
        buildingObj.ResetPos(tile);
        buildingList.Add(buildingObj);
        SetNodeData(building);

        return(buildingObj);
    }
Beispiel #5
0
    public override object Read(ES2Reader reader)
    {
        var buildingModelName = reader.Read <System.String>();
        var buildingPostion   = reader.Read <UnityEngine.Vector3>();
        var buildingRotate    = reader.Read <UnityEngine.Quaternion>();
        BuildingSaveData data = new BuildingSaveData(buildingModelName, buildingPostion, buildingRotate);

        return(data);
    }
Beispiel #6
0
    public override void Write(object obj, ES2Writer writer)
    {
        BuildingSaveData data = (BuildingSaveData)obj;

        // Add your writer.Write calls here.
        writer.Write(data.BuildingModelName);
        writer.Write(data.BuildingPostion);
        writer.Write(data.BuildingRotate);
    }
    public override void Init(BuildingSaveData buildingSaveData)
    {
        base.Init(buildingSaveData);

        DataSet();

        FoodSliderReSet();

        initOn = true;
    }
Beispiel #8
0
    void BuildingSet()
    {
        BuildingSaveData buildingSaveData = new BuildingSaveData();

        buildingSaveData.buildingType        = Building_Type.Small;
        buildingSaveData.pos                 = new Vector2(7, 11);
        buildingSaveData.chitizen_normal_num = 1;

        building = (Apartment)tileController.BuildingCreate(buildingSaveData);
    }
Beispiel #9
0
    public override void Read(ES2Reader reader, object c)
    {
        BuildingSaveData saveData = (BuildingSaveData)c;
        // Add your reader.Read calls here to read the data into the object.
        var buildingModelName = reader.Read <System.String>();
        var buildingPostion   = reader.Read <UnityEngine.Vector3>();
        var buildingRotate    = reader.Read <UnityEngine.Quaternion>();
        BuildingSaveData data = new BuildingSaveData(buildingModelName, buildingPostion, buildingRotate);

        saveData = data;
    }
Beispiel #10
0
 private async UniTask CreateBuildingEntityRoutine(BuildingSaveData saveData, bool initialize)
 {
     if (!initialize)
     {
         await DbServiceClient.CreateBuildingAsync(new CreateBuildingReq()
         {
             MapName      = Assets.onlineScene.SceneName,
             BuildingData = saveData.ToByteString()
         });
     }
 }
Beispiel #11
0
 public void Add(BuildingSaveData building)
 {
     if (data == null)
     {
         CustomLogger.Instance.Error("Start_Saving needs to be called before Add");
     }
     else
     {
         data.City.Buildings.Add(building);
     }
 }
 private async UniTask CreateBuildingEntityRoutine(BuildingSaveData saveData, bool initialize)
 {
     if (!initialize)
     {
         await DbServiceClient.CreateBuildingAsync(new CreateBuildingReq()
         {
             MapName      = CurrentMapInfo.Id,
             BuildingData = saveData,
         });
     }
 }
 public override BuildingEntity CreateBuildingEntity(BuildingSaveData saveData, bool initialize)
 {
     if (!initialize)
     {
         DbServiceClient.CreateBuildingAsync(new CreateBuildingReq()
         {
             MapName      = Assets.onlineScene.SceneName,
             BuildingData = saveData.ToByteString()
         });
     }
     return(base.CreateBuildingEntity(saveData, initialize));
 }
    public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
    {
        BuildingSaveData data = (BuildingSaveData)obj;

        info.AddValue("id", data.id);
        info.AddValue("parentId", data.parentId);
        info.AddValue("dataId", data.dataId);
        info.AddValue("currentHp", data.currentHp);
        info.AddValue("position", data.position);
        info.AddValue("rotation", data.rotation);
        info.AddValue("creatorId", data.creatorId);
        info.AddValue("creatorName", data.creatorName);
    }
    public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
    {
        BuildingSaveData data = (BuildingSaveData)obj;

        data.id          = info.GetString("id");
        data.parentId    = info.GetString("parentId");
        data.dataId      = info.GetInt32("dataId");
        data.currentHp   = info.GetInt32("currentHp");
        data.position    = (Vector3)info.GetValue("position", typeof(Vector3));
        data.rotation    = (Quaternion)info.GetValue("rotation", typeof(Quaternion));
        data.creatorId   = info.GetString("creatorId");
        data.creatorName = info.GetString("creatorName");
        obj = data;
        return(obj);
    }
Beispiel #16
0
        public virtual void CreateBuildingEntity(BuildingSaveData saveData, bool initialize)
        {
            BuildingEntity prefab;

            if (GameInstance.BuildingEntities.TryGetValue(saveData.DataId, out prefab))
            {
                var buildingIdentity = Assets.NetworkSpawn(prefab.Identity, saveData.Position, saveData.Rotation);
                var buildingEntity   = buildingIdentity.GetComponent <BuildingEntity>();
                buildingEntity.Id                   = saveData.Id;
                buildingEntity.ParentId             = saveData.ParentId;
                buildingEntity.CurrentHp            = saveData.CurrentHp;
                buildingEntity.CreatorId            = saveData.CreatorId;
                buildingEntity.CreatorName          = saveData.CreatorName;
                buildingEntities[buildingEntity.Id] = buildingEntity;
            }
        }
        private async UniTask SaveBuildingRoutine(BuildingSaveData buildingSaveData)
        {
            if (!savingBuildings.Contains(buildingSaveData.Id))
            {
                savingBuildings.Add(buildingSaveData.Id);
                // Update building
                await DbServiceClient.UpdateBuildingAsync(new UpdateBuildingReq()
                {
                    MapName      = Assets.onlineScene.SceneName,
                    BuildingData = buildingSaveData.ToByteString()
                });

                savingBuildings.Remove(buildingSaveData.Id);
                if (LogInfo)
                {
                    Logging.Log(LogTag, "Building [" + buildingSaveData.Id + "] Saved");
                }
            }
        }
        private async UniTask SaveBuildingRoutine(BuildingSaveData buildingSaveData)
        {
            if (!savingBuildings.Contains(buildingSaveData.Id))
            {
                savingBuildings.Add(buildingSaveData.Id);
                // Update building
                await DbServiceClient.UpdateBuildingAsync(new UpdateBuildingReq()
                {
                    MapName      = CurrentMapInfo.Id,
                    BuildingData = buildingSaveData,
                });

                savingBuildings.Remove(buildingSaveData.Id);
                if (LogInfo)
                {
                    Logging.Log(LogTag, "Building [" + buildingSaveData.Id + "] Saved");
                }
            }
        }
    void SetNodeData(BuildingSaveData building)
    {
        //건물 사이즈 별로 좌표값 가져옴
        for (int x = 0; x < (int)building.buildSize.x; x++)
        {
            for (int y = 0; y < (int)building.buildSize.y; y++)
            {
                if (x == 0 && y == 0 || wall == null)
                {
                    continue;
                }

                int posX = (int)building.pos.x + x;
                int posY = (int)building.pos.y + y;

                wall[posX, posY] = true;
            }
        }
    }
Beispiel #20
0
        public virtual BuildingEntity CreateBuildingEntity(BuildingSaveData saveData, bool initialize)
        {
            BuildingEntity prefab;

            if (GameInstance.BuildingEntities.TryGetValue(saveData.DataId, out prefab))
            {
                GameObject     spawnObj       = Instantiate(prefab.gameObject, saveData.position, saveData.Rotation);
                BuildingEntity buildingEntity = spawnObj.GetComponent <BuildingEntity>();
                buildingEntity.Id          = saveData.Id;
                buildingEntity.ParentId    = saveData.ParentId;
                buildingEntity.CurrentHp   = saveData.CurrentHp;
                buildingEntity.CreatorId   = saveData.CreatorId;
                buildingEntity.CreatorName = saveData.CreatorName;
                Assets.NetworkSpawn(spawnObj);
                buildingEntities[buildingEntity.Id] = buildingEntity;
                return(buildingEntity);
            }
            return(null);
        }
 private bool ReadBuilding(SqliteDataReader reader, out BuildingSaveData result)
 {
     if (reader.Read())
     {
         result                 = new BuildingSaveData();
         result.Id              = reader.GetString(0);
         result.ParentId        = reader.GetString(1);
         result.EntityId        = reader.GetInt32(2);
         result.CurrentHp       = reader.GetInt32(3);
         result.RemainsLifeTime = reader.GetFloat(4);
         result.IsLocked        = reader.GetBoolean(5);
         result.LockPassword    = reader.GetString(6);
         result.CreatorId       = reader.GetString(7);
         result.CreatorName     = reader.GetString(8);
         result.Position        = new Vector3(reader.GetFloat(9), reader.GetFloat(10), reader.GetFloat(11));
         result.Rotation        = Quaternion.Euler(reader.GetFloat(12), reader.GetFloat(13), reader.GetFloat(14));
         return(true);
     }
     result = new BuildingSaveData();
     return(false);
 }
Beispiel #22
0
        protected virtual void NetFuncBuild(short itemIndex, Vector3 position, Quaternion rotation, PackedUInt parentObjectId)
        {
            if (!CanDoActions() ||
                itemIndex >= NonEquipItems.Count)
            {
                return;
            }

            BuildingEntity buildingEntity;
            CharacterItem  nonEquipItem = NonEquipItems[itemIndex];

            if (!nonEquipItem.NotEmptySlot() ||
                nonEquipItem.GetBuildingItem() == null ||
                nonEquipItem.GetBuildingItem().buildingEntity == null ||
                !GameInstance.BuildingEntities.TryGetValue(nonEquipItem.GetBuildingItem().buildingEntity.DataId, out buildingEntity) ||
                !this.DecreaseItemsByIndex(itemIndex, 1))
            {
                return;
            }

            BuildingSaveData buildingSaveData = new BuildingSaveData();

            buildingSaveData.Id       = GenericUtils.GetUniqueId();
            buildingSaveData.ParentId = string.Empty;
            BuildingEntity parentBuildingEntity;

            if (TryGetEntityByObjectId(parentObjectId, out parentBuildingEntity))
            {
                buildingSaveData.ParentId = parentBuildingEntity.Id;
            }
            buildingSaveData.DataId      = buildingEntity.DataId;
            buildingSaveData.CurrentHp   = buildingEntity.maxHp;
            buildingSaveData.Position    = position;
            buildingSaveData.Rotation    = rotation;
            buildingSaveData.CreatorId   = Id;
            buildingSaveData.CreatorName = CharacterName;
            gameManager.CreateBuildingEntity(buildingSaveData, false);
        }
Beispiel #23
0
        /// <summary>
        /// Creates the loot bag entity building and configures it according to configuration settings.
        /// </summary>
        /// <param name="position">position in gameworld to spawn loot bag entity</param>
        /// <param name="rotation">rotation to use for lootbag entity</param>
        /// <param name="lootItems">items to place on lootbag</param>
        protected void CreateLootBag(Vector3 position, Quaternion rotation, List <CharacterItem> lootItems)
        {
            BuildingEntity buildingEntity;

            if (!GameInstance.BuildingEntities.TryGetValue(lootBagEntity.EntityId, out buildingEntity))
            {
                return;
            }

            if (!(buildingEntity is LootBagEntity))
            {
                return;
            }

            string creatorName = EntityTitle;

            if (this is BasePlayerCharacterEntity)
            {
                creatorName = CharacterName;
            }

            BuildingSaveData bsd = new BuildingSaveData();

            bsd.Id              = GenericUtils.GetUniqueId();
            bsd.ParentId        = string.Empty;
            bsd.EntityId        = buildingEntity.EntityId;
            bsd.CurrentHp       = buildingEntity.MaxHp;
            bsd.RemainsLifeTime = buildingEntity.LifeTime;
            bsd.Position        = position;
            bsd.Rotation        = rotation;
            bsd.CreatorId       = Id;
            bsd.CreatorName     = creatorName;
            LootBagEntity lbe = CurrentGameManager.CreateBuildingEntity(bsd, false) as LootBagEntity;

            lbe.SetOwnerEntity(this);
            lbe.AddItems(lootItems).Forget();
            lbe.SetDestroyDelay(characterDB.lootBagDestroyDelay);
        }
 public virtual void Init(BuildingSaveData buildingSaveData)
 {
     this.buildingSaveData = buildingSaveData;
     CitizenSet();
 }
 public override BuildingEntity CreateBuildingEntity(BuildingSaveData saveData, bool initialize)
 {
     CreateBuildingEntityRoutine(saveData, initialize).Forget();
     return(base.CreateBuildingEntity(saveData, initialize));
 }
Beispiel #26
0
 public void Deserialize(NetDataReader reader)
 {
     BuildingData = reader.GetValue <BuildingSaveData>();
 }
 public void Deserialize(NetDataReader reader)
 {
     MapName      = reader.GetString();
     BuildingData = reader.GetValue <BuildingSaveData>();
 }