Example #1
0
        private void OnPlaced()
        {
            base.enabled = false;
            Transform child = this._ghosts[this._currentGhost]._go.transform.GetChild(0);

            if (!BoltNetwork.isRunning)
            {
                if (LocalPlayer.Create.BuildingPlacer.LastHit != null && LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>())
                {
                    child.parent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>().transform;
                }
                else
                {
                    child.parent = null;
                }
                child.SendMessage("OnPlaced", SendMessageOptions.DontRequireReceiver);
                GameObject gameObject = child.Find("Trigger").gameObject;
                gameObject.SetActive(true);
                if (this._ghosts[this._currentGhost]._initialize)
                {
                    gameObject.GetComponent <Craft_Structure>().Initialize();
                }
                UnityEngine.Object.Destroy(base.gameObject);
            }
            else
            {
                CoopConstructionEx component = child.GetComponent <CoopConstructionEx>();
                if (component)
                {
                    BoltEntity component2   = child.GetComponent <BoltEntity>();
                    BoltEntity parentEntity = LocalPlayer.Create.GetParentEntity(child.gameObject);
                    component.SendMessage("OnSerializing");
                    CoopConstructionExToken coopConstructionExToken = LocalPlayer.Create.GetCoopConstructionExToken(component, parentEntity);
                    PlaceFoundationEx       placeFoundationEx       = PlaceFoundationEx.Create(GlobalTargets.OnlyServer);
                    placeFoundationEx.Parent   = parentEntity;
                    placeFoundationEx.Position = child.transform.position;
                    placeFoundationEx.Prefab   = component2.prefabId;
                    placeFoundationEx.Token    = coopConstructionExToken;
                    placeFoundationEx.Send();
                }
                else
                {
                    PlaceConstruction placeConstruction = PlaceConstruction.Create(GlobalTargets.OnlyServer);
                    if (LocalPlayer.Create.BuildingPlacer.LastHit != null)
                    {
                        placeConstruction.Parent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>();
                    }
                    placeConstruction.PrefabId = child.GetComponent <BoltEntity>().prefabId;
                    placeConstruction.Position = child.position;
                    placeConstruction.Rotation = child.rotation;
                    FoundationArchitect component3 = child.GetComponent <FoundationArchitect>();
                    if (component3)
                    {
                        placeConstruction.AboveGround = component3._aboveGround;
                    }
                    placeConstruction.Send();
                }
                UnityEngine.Object.Destroy(base.gameObject, 0.05f);
            }
        }
Example #2
0
    private void SpawnFoodPrefab(Cook foodPrefab)
    {
        Vector3 center  = this.dryingGrid.center;
        Vector3 vector  = this.dryingGrid.size * 0.5f;
        Vector3 vector2 = center;
        Vector3 vector3 = center;

        vector2.x += vector.x;
        vector2.z += vector.z;
        vector3.x -= vector.x;
        vector3.z -= vector.z;
        Vector3 position = new Vector3(UnityEngine.Random.Range(vector3.x, vector2.x), center.y, UnityEngine.Random.Range(vector3.z, vector2.z));

        position.x -= position.x % this.gridChunkSize.x;
        position.z -= position.z % this.gridChunkSize.y;
        if (BoltNetwork.isRunning)
        {
            PlaceConstruction placeConstruction = PlaceConstruction.Create(GlobalTargets.OnlyServer);
            placeConstruction.PrefabId = foodPrefab.GetComponent <BoltEntity>().prefabId;
            placeConstruction.Position = this.dryingGrid.transform.TransformPoint(position);
            placeConstruction.Rotation = Quaternion.identity;
            placeConstruction.Parent   = base.transform.parent.GetComponent <BoltEntity>();
            placeConstruction.Send();
        }
        else
        {
            Cook cook = (Cook)UnityEngine.Object.Instantiate(foodPrefab, this.dryingGrid.transform.TransformPoint(position), Quaternion.identity);
            cook.transform.parent = base.transform.parent;
        }
    }
Example #3
0
        private IEnumerator OnPlaced()
        {
            base.enabled = false;
            yield return(null);

            Transform ghost;

            if (this._snappedGo.activeSelf)
            {
                ghost = this._snappedGo.transform.GetChild(0);
            }
            else
            {
                ghost = this._freeGo.transform.GetChild(0);
            }
            if (!BoltNetwork.isRunning)
            {
                if (LocalPlayer.Create.BuildingPlacer.LastHit != null && LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>())
                {
                    ghost.parent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>().transform;
                }
                else if (LocalPlayer.Create.ParentEntity)
                {
                    DynamicBuilding component = LocalPlayer.Create.ParentEntity.GetComponent <DynamicBuilding>();
                    ghost.transform.parent = ((!component || !component._parentOverride) ? LocalPlayer.Create.ParentEntity.transform : component._parentOverride);
                }
                else
                {
                    ghost.parent = null;
                }
                ghost.SendMessage("OnPlaced", SendMessageOptions.DontRequireReceiver);
                GameObject gameObject = ghost.Find("Trigger").gameObject;
                gameObject.SetActive(true);
                if ((this._snappedGo.activeSelf && this._initializeSnapped) || (this._freeGo.activeSelf && this._initializeAirborne))
                {
                    gameObject.GetComponent <Craft_Structure>().Initialize();
                }
                UnityEngine.Object.Destroy(base.gameObject);
            }
            else
            {
                PlaceConstruction placeConstruction = PlaceConstruction.Create(GlobalTargets.OnlyServer);
                if (LocalPlayer.Create.BuildingPlacer.LastHit != null)
                {
                    placeConstruction.Parent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>();
                }
                placeConstruction.PrefabId = ghost.GetComponent <BoltEntity>().prefabId;
                placeConstruction.Position = ghost.position;
                placeConstruction.Rotation = ghost.rotation;
                FoundationArchitect component2 = ghost.GetComponent <FoundationArchitect>();
                if (component2)
                {
                    placeConstruction.AboveGround = component2._aboveGround;
                }
                placeConstruction.Send();
                UnityEngine.Object.Destroy(base.gameObject, 0.05f);
            }
            yield break;
        }
Example #4
0
 private void FixedUpdate()
 {
     if (this._targetObject)
     {
         if (LocalPlayer.Inventory.HasInSlot(Item.EquipmentSlot.RightHand, this._itemId))
         {
             if (Physics.Raycast(LocalPlayer.MainCamTr.position + Vector3.up, LocalPlayer.MainCamTr.forward, out this._hit, 10f, this._layerMask.value))
             {
                 DynamicBuilding componentInParent = this._hit.collider.GetComponentInParent <DynamicBuilding>();
                 if (!componentInParent || componentInParent._allowParenting)
                 {
                     if (!this._placeIconSheen.activeSelf)
                     {
                         this._placeIconSheen.transform.parent = null;
                         this._placeIconSheen.SetActive(true);
                     }
                     this._placeIconSheen.transform.position = this._hit.point + Vector3.down * 0.5f;
                     if (TheForest.Utils.Input.GetButtonDown("Craft") && LocalPlayer.Inventory.ShuffleRemoveRightHandItem())
                     {
                         int     num    = this._diiv.PopLast();
                         Vector3 normal = this._hit.normal;
                         Vector3 point  = this._hit.point;
                         if (!BoltNetwork.isRunning)
                         {
                             Transform transform = UnityEngine.Object.Instantiate <Transform>(Prefabs.Instance.TimmyDrawingsPrefab[num], point, Quaternion.LookRotation(normal));
                             transform.parent = this._targetObjectRoot;
                         }
                         else
                         {
                             PlaceConstruction placeConstruction = PlaceConstruction.Create(GlobalTargets.OnlyServer);
                             placeConstruction.Parent   = this._targetObjectRoot.GetComponent <BoltEntity>();
                             placeConstruction.PrefabId = Prefabs.Instance.TimmyDrawingsPrefab[num].GetComponent <BoltEntity>().prefabId;
                             placeConstruction.Position = point;
                             placeConstruction.Rotation = Quaternion.LookRotation(normal);
                             placeConstruction.Send();
                         }
                         this._placeIconSheen.SetActive(false);
                         this._placeIconSheen.transform.parent = base.transform;
                         this.Deactivate();
                         LocalPlayer.Grabber.RefreshCollider();
                     }
                 }
             }
         }
         else if (this._placeIconSheen.activeSelf)
         {
             this._placeIconSheen.transform.parent = base.transform;
             this._placeIconSheen.SetActive(false);
         }
     }
     else
     {
         this.Deactivate();
     }
 }
Example #5
0
    public override void OnEvent(PlaceConstruction evnt)
    {
        BoltEntity boltEntity = BoltNetwork.Instantiate(evnt.PrefabId, evnt.Position, evnt.Rotation);

        if (boltEntity.GetComponent <TreeStructure>())
        {
            boltEntity.GetComponent <TreeStructure>().TreeId = evnt.TreeIndex;
        }
        if (evnt.Parent)
        {
            boltEntity.transform.parent = evnt.Parent.transform;
        }
        if (evnt.AboveGround)
        {
            FoundationArchitect component = boltEntity.GetComponent <FoundationArchitect>();
            if (component)
            {
                component._aboveGround = evnt.AboveGround;
            }
        }
        boltEntity.SendMessage("OnDeserialized", SendMessageOptions.DontRequireReceiver);
        LocalPlayer.Create.RefreshGrabber();
    }
Example #6
0
        private void OnPlaced()
        {
            base.enabled = false;
            Transform child;

            if (this._inWaterGo.activeSelf)
            {
                child = this._inWaterGo.transform.GetChild(0);
            }
            else
            {
                child = this._outWaterGo.transform.GetChild(0);
            }
            if (!BoltNetwork.isRunning)
            {
                if (LocalPlayer.Create.BuildingPlacer.LastHit != null && LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>())
                {
                    child.parent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>().transform;
                }
                else if (LocalPlayer.Create.ParentEntity)
                {
                    DynamicBuilding component = LocalPlayer.Create.ParentEntity.GetComponent <DynamicBuilding>();
                    child.transform.parent = ((!component || !component._parentOverride) ? LocalPlayer.Create.ParentEntity.transform : component._parentOverride);
                }
                else
                {
                    child.parent = null;
                }
                child.SendMessage("OnPlaced", SendMessageOptions.DontRequireReceiver);
                GameObject gameObject = child.Find("Trigger").gameObject;
                gameObject.SetActive(true);
                if ((this._inWaterGo.activeSelf && this._initializeOutWater) || (this._outWaterGo.activeSelf && this._initializeInWater))
                {
                    gameObject.GetComponent <Craft_Structure>().Initialize();
                }
                UnityEngine.Object.Destroy(base.gameObject);
            }
            else
            {
                CoopConstructionEx component2 = child.GetComponent <CoopConstructionEx>();
                if (component2)
                {
                    BoltEntity component3 = child.GetComponent <BoltEntity>();
                    BoltEntity boltEntity = LocalPlayer.Create.GetParentEntity(child.gameObject) ?? LocalPlayer.Create.ParentEntity;
                    component2.SendMessage("OnSerializing");
                    CoopConstructionExToken coopConstructionExToken = LocalPlayer.Create.GetCoopConstructionExToken(component2, boltEntity);
                    PlaceFoundationEx       placeFoundationEx       = PlaceFoundationEx.Create(GlobalTargets.OnlyServer);
                    placeFoundationEx.Parent   = boltEntity;
                    placeFoundationEx.Position = child.transform.position;
                    placeFoundationEx.Prefab   = component3.prefabId;
                    placeFoundationEx.Token    = coopConstructionExToken;
                    placeFoundationEx.Send();
                }
                else
                {
                    PlaceConstruction placeConstruction = PlaceConstruction.Create(GlobalTargets.OnlyServer);
                    if (LocalPlayer.Create.BuildingPlacer.LastHit != null)
                    {
                        placeConstruction.Parent = LocalPlayer.Create.BuildingPlacer.LastHit.Value.transform.GetComponentInParent <BoltEntity>();
                    }
                    placeConstruction.PrefabId = child.GetComponent <BoltEntity>().prefabId;
                    placeConstruction.Position = child.position;
                    placeConstruction.Rotation = child.rotation;
                    FoundationArchitect component4 = child.GetComponent <FoundationArchitect>();
                    if (component4)
                    {
                        placeConstruction.AboveGround = component4._aboveGround;
                    }
                    placeConstruction.Send();
                }
                UnityEngine.Object.Destroy(base.gameObject, 0.05f);
            }
        }
Example #7
0
        private IEnumerator PlaceGhostRoutine(bool chain)
        {
            BuildingTypes bType = this.CurrentBlueprint._type;

            yield return(null);

            if (this.CreateMode)
            {
                this.ShownPlace = false;
                this.CreateMode = false;
                if (!this.ToolsShown)
                {
                    base.SendMessage("BuildToolsTut");
                    this.ToolsShown = true;
                }
                TreeStructure ts = this._currentGhost.GetComponentInChildren <TreeStructure>();
                if (ts && this.TargetTree)
                {
                    if (this.TargetTree.CompareTag("conTree"))
                    {
                        ts.TreeId = this.TargetTree.parent.GetComponent <TreeHealth>().LodTree.GetComponentInChildren <CoopTreeId>().Id;
                    }
                    else
                    {
                        ts.TreeId = this.TargetTree.GetComponent <TreeHealth>().LodTree.GetComponentInChildren <CoopTreeId>().Id;
                    }
                    ts.enabled = true;
                    if (!BoltNetwork.isRunning)
                    {
                        Scene.ActiveMB.StartCoroutine(ts.OnDeserialized());
                    }
                }
                CoopConstructionEx     coopEx            = this._currentGhost.GetComponent <CoopConstructionEx>();
                WallArchitect          wallArch          = this.CurrentGhost.GetComponent <WallArchitect>();
                ICoopTokenConstruction tokenConstruction = this._currentGhost.GetComponent <ICoopTokenConstruction>();
                this.ParentEntity = this.GetParentEntity(this._currentGhost);
                if (BoltNetwork.isRunning && !wallArch)
                {
                    BoltEntity component = this._currentGhost.GetComponent <BoltEntity>();
                    if (tokenConstruction != null)
                    {
                        PlaceFoundationEx placeFoundationEx = PlaceFoundationEx.Create(GlobalTargets.OnlyServer);
                        placeFoundationEx.Position = this._currentGhost.transform.position;
                        placeFoundationEx.Rotation = this._currentGhost.transform.rotation;
                        placeFoundationEx.Prefab   = component.prefabId;
                        placeFoundationEx.Token    = tokenConstruction.CustomToken;
                        placeFoundationEx.Parent   = this.ParentEntity;
                        placeFoundationEx.Send();
                        UnityEngine.Object.Destroy(this._currentGhost);
                    }
                    else if (coopEx)
                    {
                        coopEx.SendMessage("OnSerializing");
                        CoopConstructionExToken coopConstructionExToken = this.GetCoopConstructionExToken(coopEx, this.ParentEntity);
                        PlaceFoundationEx       placeFoundationEx2      = PlaceFoundationEx.Create(GlobalTargets.OnlyServer);
                        placeFoundationEx2.Parent   = this.ParentEntity;
                        placeFoundationEx2.Position = this._currentGhost.transform.position;
                        placeFoundationEx2.Rotation = this._currentGhost.transform.rotation;
                        placeFoundationEx2.Prefab   = component.prefabId;
                        placeFoundationEx2.Token    = coopConstructionExToken;
                        placeFoundationEx2.Send();
                        UnityEngine.Object.Destroy(this._currentGhost);
                    }
                    else if (!this._currentGhost.GetComponent(typeof(IAnchorableStructure)) && component)
                    {
                        this._currentGhost.AddComponent <CoopDestroyPredictedGhost>();
                        this._currentGhost.AddComponent <destroyAfter>().destroyTime = 2f;
                        PlaceConstruction placeConstruction = PlaceConstruction.Create(GlobalTargets.OnlyServer);
                        placeConstruction.Parent   = this.ParentEntity;
                        placeConstruction.PrefabId = component.prefabId;
                        placeConstruction.Position = this._currentGhost.transform.position;
                        placeConstruction.Rotation = this._currentGhost.transform.rotation;
                        if (ts)
                        {
                            placeConstruction.TreeIndex = ts.TreeId;
                        }
                        placeConstruction.Send();
                        this._currentGhost.SendMessage("OnPlacingRemotely", SendMessageOptions.DontRequireReceiver);
                    }
                    else
                    {
                        this._currentGhost.SendMessage("OnPlaced", false, SendMessageOptions.DontRequireReceiver);
                    }
                }
                else
                {
                    this._currentGhost.SendMessage("OnPlaced", false, SendMessageOptions.DontRequireReceiver);
                    this._currentGhost.transform.Find("Trigger").gameObject.SetActive(true);
                    Transform transform = this._currentGhost.transform.Find("LastBuiltLocation");
                    if (transform)
                    {
                        transform.gameObject.SetActive(true);
                    }
                    if (this.ParentEntity)
                    {
                        DynamicBuilding component2 = this.ParentEntity.GetComponent <DynamicBuilding>();
                        this._currentGhost.transform.parent = ((!component2 || !component2._parentOverride) ? this.ParentEntity.transform : component2._parentOverride);
                    }
                }
                this.ClearReferences(!chain);
                LocalPlayer.Sfx.PlayPlaceGhost();
                this.RefreshGrabber();
                yield return(YieldPresets.WaitPointFiveSeconds);

                if (chain)
                {
                    this.MultiPlaceAction(bType);
                }
            }
            yield break;
        }
 public override void OnEvent(PlaceConstruction evnt)
 {
     BoltEntity boltEntity = BoltNetwork.Instantiate(evnt.PrefabId, evnt.Position, evnt.Rotation);
     if (boltEntity.GetComponent<TreeStructure>())
     {
         boltEntity.GetComponent<TreeStructure>().TreeId = evnt.TreeIndex;
     }
     if (evnt.Parent)
     {
         boltEntity.transform.parent = evnt.Parent.transform;
     }
     if (evnt.AboveGround)
     {
         FoundationArchitect component = boltEntity.GetComponent<FoundationArchitect>();
         if (component)
         {
             component._aboveGround = evnt.AboveGround;
         }
     }
     boltEntity.SendMessage("OnDeserialized", SendMessageOptions.DontRequireReceiver);
     LocalPlayer.Create.RefreshGrabber();
 }