Ejemplo n.º 1
0
    public override void OnEvent(DeclineBlockFreeze evnt)
    {
        if (entity.IsOwner)
        {
            if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Shoot)
            {
                BoltNetwork.Destroy(gameObject);
                return;
            }

            gameObject.transform.position = evnt.OldBlockPosition;
            gameObject.transform.rotation = evnt.OldBlockRotation;

            GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;

            if (gameObject.GetComponent <ConstantForce>() == null)
            {
                gameObject.AddComponent <ConstantForce>();
            }

            gameObject.layer = 8;

            if (gameObject.GetComponent <ConnectionScanning>() == null)
            {
                var scan = gameObject.AddComponent <ConnectionScanning>();
                scan.WaitSeconds = 1;
            }

            if (gameObject.GetComponent <PartBehaviour>() == null)
            {
                gameObject.AddComponent <PartBehaviour>();
            }
        }
    }
Ejemplo n.º 2
0
    //Events
    #region
    public override void OnEvent(CheckBlockFreeze evnt)
    {
        if (BoltNetwork.IsServer)
        {
            Part p          = gameObject.GetComponent <Part>();
            Part parentPart = GlobalReferences.FrozenParts[evnt.ParentID].GetComponent <Part>();

            Connection bestOnPart        = p.Connections[evnt.ConnectionID];
            Connection closestConnection = parentPart.Connections[evnt.ParentCon];

            gameObject.transform.position = evnt.BlockPosition;
            gameObject.transform.rotation = evnt.BlockRotation;
            //AlignPlane.Orient(bestOnPart.Pln, closestConnection.Pln, gameObject);

            if (!ConnectionScanning.CollisionDetection(gameObject) && CheckOriginAlignment(bestOnPart, closestConnection, evnt.BlockPosition, evnt.BlockRotation))// && CheckConncetionAlignment(bestOnPart, closestConnection))//, transform, parentPart.transform))
            {
                var token = new PartTokenParent();
                token.TemplateID = p.TemplateID;

                token.ID = UnityEngine.Random.Range(int.MinValue, int.MaxValue);

                while (GlobalReferences.FrozenParts.ContainsKey(token.ID))
                {
                    token.ID = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
                }


                token.Parent    = evnt.ParentID;
                token.ParentCon = evnt.ParentCon;

                token.Con = evnt.ConnectionID;

                var spawn = SpawnFrozenBlock.Create();
                spawn.token    = token;
                spawn.Position = evnt.BlockPosition;
                spawn.Rotation = evnt.BlockRotation;
                spawn.Send();

                var destroy = BlockDestroy.Create(entity);
                destroy.Send();

                //Debug.Log("#43 Spawning Block: " + token.ID + ", Position = " + evnt.BlockPosition.ToString("F2") + ", Rotation = " + evnt.BlockRotation.eulerAngles.ToString("F2"));
            }
            else
            {
                var decline = DeclineBlockFreeze.Create(entity);
                decline.OldBlockPosition = evnt.OldBlockPosition;
                decline.OldBlockRotation = evnt.OldBlockRotation;

                decline.Send();
            }
        }
    }