// PRIVATE

        private void SendSuccessfulThrowEvent()
        {
            TotemThrown totemThrownEvent = TotemThrown.Create();

            totemThrownEvent.OwnerID = -1;
            totemThrownEvent.Send();
        }
 public override void OnEvent(TotemThrown evnt)
 {
     if (evnt.OwnerID == GetKartState().OwnerID)
     {
         OnTotemLost.Invoke();
     }
 }
Esempio n. 3
0
        // PRIVATE

        private void ThrowTotem()
        {
            if (_totemOwnership.IsLocalOwner(state.OwnerID) && _totemOwnership.IsSynchronized())
            {
                TotemThrown totemThrownEvent = TotemThrown.Create();
                totemThrownEvent.KartEntity       = entity;
                totemThrownEvent.OwnerID          = state.OwnerID;
                totemThrownEvent.ForwardDirection = _throwingDirection.LastDirectionUp != Direction.Backward; // TO DO BETTER
                totemThrownEvent.Send();
            }
        }
Esempio n. 4
0
        // PUBLIC

        public void RespawnTotem()
        {
            var totem = GameObject.FindGameObjectWithTag(Constants.Tag.Totem);

            totem.GetComponent <TotemOwnership>().UnsetOwner();
            totem.GetComponent <TotemPhysics>().SetVelocityToZero();
            totem.GetComponent <TotemPhysics>().EnableCollider(true);
            totem.transform.position = transform.position;

            TotemThrown totemThrownEvent = TotemThrown.Create();

            totemThrownEvent.OwnerID = -1;
            totemThrownEvent.Send();
        }
        public override void OnEvent(TotemThrown evnt)
        {
            if (BoltNetwork.IsServer)
            {
                if (evnt.OwnerID != -1 && evnt.OwnerID == _totemOwnership.ServerOwnerID) // The owner of the totem is throwing it || or it is a totem reset
                {
                    SendSuccessfulThrowEvent();

                    var kartThrowing = SWExtensions.KartExtensions.GetKartWithID(evnt.OwnerID);
                    if (kartThrowing)
                    {
                        Direction throwingDirection = evnt.ForwardDirection ? Direction.Forward : Direction.Backward;
                        kartThrowing.GetComponentInChildren <ThrowableLauncher>().Throw(GetComponent <Throwable>(), throwingDirection); // The server make the player throw the totem
                    }
                }
            }
            if (evnt.OwnerID == -1)
            {
                _totemOwnership.UnsetOwner();
            }
        }