Beispiel #1
0
        public override void PlaceBuilding()
        {
            ForgeBuilding building = currentBuilding as ForgeBuilding;

            if (building != null)
            {
                var evnt = building.PackData(entity, true);
                evnt.Send(NetworkReceivers.Server);
            }

            DestroyCurrentBuilding();
            ResetBuildingInstance();
        }
Beispiel #2
0
        /// <summary>
        /// Load an entity
        /// </summary>
        /// <param name="evnt">our event</param>
        public static void LoadEntity(CreateNetworkedBuilding evnt)
        {
            GameObject prefab = PrefabDB.instance.GetGO(evnt.prefabID);

            if (prefab != null)
            {
                var instance = GameObject.Instantiate(prefab);

                ForgeBuilding building = instance.GetComponent <ForgeBuilding>();

                building.LoadData(evnt);
                entities.Add(building);
            }
        }
Beispiel #3
0
        public override void DestroyBuilding(BaseBuilding building, RaycastHit hit)
        {
            ForgeBuilding boltBuilding = (ForgeBuilding)building;

            if (boltBuilding == null)
            {
                base.DestroyBuilding(building, hit);
                return;
            }

            var evnt = new UpdateNetworkedBuilding();

            evnt.buildingUID = boltBuilding.networkedID;
            evnt.health      = 0;
            evnt.Send(NetworkReceivers.Server);
        }
Beispiel #4
0
        /// <summary>
        /// Initialize awake
        /// </summary>
        void Awake()
        {
            uConstruct.Core.Saving.BuildingGroupSaveData.OnBuildingLoadedEvent += (BaseBuilding building) =>
            {
                ForgeBuilding forgeBuilding = building as ForgeBuilding;

                if (forgeBuilding != null)
                {
                    entities.Add(forgeBuilding);
                    forgeBuilding.networkedID = entities.Count;
                }
            };

            if (!Networking.PrimarySocket.Connected)
            {
                Networking.connected += Networking_Setup;
            }
            else
            {
                Networking_Setup(Networking.PrimarySocket);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Called when the CreateNetworkBuilding event is called
        /// </summary>
        /// <param name="evnt">event data</param>
        public void CreateNetworkBuildingEvent(CreateNetworkedBuilding evnt)
        {
            if (Networking.PrimarySocket.IsServer)
            {
                GameObject prefab = PrefabDB.instance.GetGO(evnt.prefabID);

                if (prefab != null && evnt.requester != null)
                {
                    var instance = GameObject.Instantiate(prefab);

                    ForgeBuilding building = instance.GetComponent <ForgeBuilding>();

                    building.transform.position = evnt.pos;
                    building.transform.rotation = evnt.rot;

                    if (!building.CheckConditions()) // check conditions serverside
                    {
                        Destroy(instance);
                        return;
                    }

                    entities.Add(building);

                    evnt.id     = entities.Count;
                    evnt.health = building.maxHealth;

                    building.LoadData(evnt);

                    building.PackData(evnt.requester, false).Send(NetworkReceivers.Others);
                }
            }
            else
            {
                LoadEntity(evnt);
            }
        }