Inheritance: Rocket.Unturned.Player.UnturnedPlayerComponent
        internal static void InternalOnRevived(PlayerLife sender)
        {
            UnturnedPlayerEvents instance = sender.GetComponent <UnturnedPlayerEvents>();
            UnturnedPlayer       rp       = UnturnedPlayer.FromPlayer(sender.player);

            // First parameter of tellLife was health.
            OnPlayerUpdateLife.TryInvoke(rp, sender.health);
            instance.OnUpdateLife.TryInvoke(rp, sender.health);

            // Ideally avoid using this angleToByte method in new code. Please.
            Vector3 position = sender.transform.position;
            byte    angle    = MeasurementTool.angleToByte(sender.transform.rotation.eulerAngles.y);

            OnPlayerRevive.TryInvoke(rp, position, angle);
            instance.OnRevive.TryInvoke(rp, position, angle);
        }
Esempio n. 2
0
        internal static void TriggerSend(SteamPlayer s, string W, ESteamCall X, ESteamPacket l, params object[] R)
        {
            try
            {
                if (s == null || s.Player == null || s.Player.transform == null || R == null)
                {
                    return;
                }
                UnturnedPlayerEvents instance = s.Player.transform.GetComponent <UnturnedPlayerEvents>();
                UnturnedPlayer       rp       = UnturnedPlayer.FromSteamPlayer(s);
#if DEBUG
                //string o = "";
                //foreach (object r in R)
                //{
                //    o += r.ToString();
                //}
                //Logger.Log("Send+" + s.SteamPlayerID.CSteamID.ToString() + ": " + W + " - " + o);
#endif
                if (W.StartsWith("tellWear"))
                {
                    OnPlayerWear.TryInvoke(rp, Enum.Parse(typeof(Wearables), W.Replace("tellWear", "")), (ushort)R[0], R.Count() > 1 ? (byte?)R[1] : null);
                }
                switch (W)
                {
                case "tellBleeding":
                    OnPlayerUpdateBleeding.TryInvoke(rp, (bool)R[0]);
                    instance.OnUpdateBleeding.TryInvoke(rp, (bool)R[0]);
                    break;

                case "tellBroken":
                    OnPlayerUpdateBroken.TryInvoke(rp, (bool)R[0]);
                    instance.OnUpdateBroken.TryInvoke(rp, (bool)R[0]);
                    break;

                case "tellLife":
                    OnPlayerUpdateLife.TryInvoke(rp, (byte)R[0]);
                    instance.OnUpdateLife.TryInvoke(rp, (byte)R[0]);
                    break;

                case "tellFood":
                    OnPlayerUpdateFood.TryInvoke(rp, (byte)R[0]);
                    instance.OnUpdateFood.TryInvoke(rp, (byte)R[0]);
                    break;

                case "tellHealth":
                    OnPlayerUpdateHealth.TryInvoke(rp, (byte)R[0]);
                    instance.OnUpdateHealth.TryInvoke(rp, (byte)R[0]);
                    break;

                case "tellVirus":
                    OnPlayerUpdateVirus.TryInvoke(rp, (byte)R[0]);
                    instance.OnUpdateVirus.TryInvoke(rp, (byte)R[0]);
                    break;

                case "tellWater":
                    OnPlayerUpdateWater.TryInvoke(rp, (byte)R[0]);
                    instance.OnUpdateWater.TryInvoke(rp, (byte)R[0]);
                    break;

                case "tellStance":
                    OnPlayerUpdateStance.TryInvoke(rp, (byte)R[0]);
                    instance.OnUpdateStance.TryInvoke(rp, (byte)R[0]);
                    break;

                case "tellGesture":
                    OnPlayerUpdateGesture.TryInvoke(rp, (PlayerGesture)Enum.Parse(typeof(PlayerGesture), R[0].ToString()));
                    instance.OnUpdateGesture.TryInvoke(rp, (PlayerGesture)Enum.Parse(typeof(PlayerGesture), R[0].ToString()));
                    break;

                case "tellStat":
                    OnPlayerUpdateStat.TryInvoke(rp, (EPlayerStat)(byte)R[0]);
                    instance.OnUpdateStat.TryInvoke(rp, (EPlayerStat)(byte)R[0]);
                    break;

                case "tellExperience":
                    OnPlayerUpdateExperience.TryInvoke(rp, (uint)R[0]);
                    instance.OnUpdateExperience.TryInvoke(rp, (uint)R[0]);
                    break;

                case "tellRevive":
                    OnPlayerRevive.TryInvoke(rp, (Vector3)R[0], (byte)R[1]);
                    instance.OnRevive.TryInvoke(rp, (Vector3)R[0], (byte)R[1]);
                    break;

                case "tellDead":
                    OnPlayerDead.TryInvoke(rp, (Vector3)R[0]);
                    instance.OnDead.TryInvoke(rp, (Vector3)R[0]);
                    break;

                case "tellDeath":
                    OnPlayerDeath.TryInvoke(rp, (EDeathCause)(byte)R[0], (ELimb)(byte)R[1], new CSteamID(ulong.Parse(R[2].ToString())));
                    instance.OnDeath.TryInvoke(rp, (EDeathCause)(byte)R[0], (ELimb)(byte)R[1], new CSteamID(ulong.Parse(R[2].ToString())));
                    break;

                default:
#if DEBUG
                    // Logger.Log("Send+" + s.SteamPlayerID.CSteamID.ToString() + ": " + W + " - " + String.Join(",",R.Select(e => e.ToString()).ToArray()));
#endif
                    break;
                }
                return;
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, "Failed to receive packet \"" + W + "\"");
            }
        }
        internal static void InternalOnGestureChanged(PlayerAnimator animator)
        {
            PlayerGesture rocketGesture;

            switch (animator.gesture)
            {
            case EPlayerGesture.NONE:
                rocketGesture = PlayerGesture.None;
                break;

            case EPlayerGesture.INVENTORY_START:
                rocketGesture = PlayerGesture.InventoryOpen;
                break;

            case EPlayerGesture.INVENTORY_STOP:
                rocketGesture = PlayerGesture.InventoryClose;
                break;

            case EPlayerGesture.PICKUP:
                rocketGesture = PlayerGesture.Pickup;
                break;

            case EPlayerGesture.PUNCH_LEFT:
                rocketGesture = PlayerGesture.PunchLeft;
                break;

            case EPlayerGesture.PUNCH_RIGHT:
                rocketGesture = PlayerGesture.PunchRight;
                break;

            case EPlayerGesture.SURRENDER_START:
                rocketGesture = PlayerGesture.SurrenderStart;
                break;

            case EPlayerGesture.SURRENDER_STOP:
                rocketGesture = PlayerGesture.SurrenderStop;
                break;

            case EPlayerGesture.POINT:
                rocketGesture = PlayerGesture.Point;
                break;

            case EPlayerGesture.WAVE:
                rocketGesture = PlayerGesture.Wave;
                break;

            case EPlayerGesture.SALUTE:
                rocketGesture = PlayerGesture.Salute;
                break;

            case EPlayerGesture.ARREST_START:
                rocketGesture = PlayerGesture.Arrest_Start;
                break;

            case EPlayerGesture.ARREST_STOP:
                rocketGesture = PlayerGesture.Arrest_Stop;
                break;

            case EPlayerGesture.REST_START:
                rocketGesture = PlayerGesture.Rest_Start;
                break;

            case EPlayerGesture.REST_STOP:
                rocketGesture = PlayerGesture.Rest_Stop;
                break;

            case EPlayerGesture.FACEPALM:
                rocketGesture = PlayerGesture.Facepalm;
                break;

            default:
                // Rocket does not have an equivalent. Plugins should use the game's event instead because this
                // listener only exists for backwards compatibility.
                return;
            }

            UnturnedPlayerEvents instance = animator.GetComponent <UnturnedPlayerEvents>();
            UnturnedPlayer       rp       = UnturnedPlayer.FromPlayer(animator.player);

            OnPlayerUpdateGesture.TryInvoke(rp, rocketGesture);
            instance.OnUpdateGesture.TryInvoke(rp, rocketGesture);
        }