Ejemplo n.º 1
0
    public void ServerPerformInteraction(HandApply interaction)
    {
        GameObject target    = interaction.TargetObject;
        GameObject performer = interaction.Performer;

        // Direction for lerp
        Vector2 dir = (target.transform.position - performer.transform.position).normalized;

        WeaponNetworkActions wna = performer.GetComponent <WeaponNetworkActions>();

        // If we're not on help intent we deal damage!
        // Note: this has to be done before the stun, because otherwise if we hit ourselves with an activated stun baton on harm intent
        // we wouldn't deal damage to ourselves because CmdRequestMeleeAttack checks whether we're stunned
        if (interaction.Intent != Intent.Help)
        {
            // Direction of attack towards the attack target.
            wna.ServerPerformMeleeAttack(target, dir, interaction.TargetBodyPart, LayerType.None);
        }

        RegisterPlayer registerPlayerVictim = target.GetComponent <RegisterPlayer>();

        // Stun the victim. We checke whether the baton is activated in WillInteract
        if (registerPlayerVictim)
        {
            registerPlayerVictim.ServerStun(stunTime);
            SoundManager.PlayNetworkedAtPos(stunSound, target.transform.position, sourceObj: target.gameObject);

            // Special case: If we're on help intent (only stun), we should still show the lerp (unless we're hitting ourselves)
            if (interaction.Intent == Intent.Help && performer != target)
            {
                wna.RpcMeleeAttackLerp(dir, gameObject);
            }
        }
    }
Ejemplo n.º 2
0
    public void ServerPerformInteraction(HandApply interaction)
    {
        GameObject target    = interaction.TargetObject;
        GameObject performer = interaction.Performer;

        // Direction for lerp
        Vector2 dir = (target.transform.position - performer.transform.position).normalized;

        WeaponNetworkActions wna = performer.GetComponent <WeaponNetworkActions>();

        // If we're not on help intent we deal damage!
        // Note: this has to be done before the stun, because otherwise if we hit ourselves with an activated stun baton on harm intent
        // we wouldn't deal damage to ourselves because CmdRequestMeleeAttack checks whether we're stunned
        if (interaction.Intent != Intent.Help)
        {
            // Direction of attack towards the attack target.
            wna.ServerPerformMeleeAttack(target, dir, interaction.TargetBodyPart, LayerType.None);
        }

        RegisterPlayer registerPlayerVictim = target.GetComponent <RegisterPlayer>();

        // Stun the victim. We check whether the baton is activated in WillInteract and if the user has a charge to stun
        if (registerPlayerVictim && canStun)
        {
            if (delay != 0)
            {
                canStun = false;
                timer   = delay;
            }

            registerPlayerVictim.ServerStun(stunTime);
            SoundManager.PlayNetworkedAtPos(stunSound, target.transform.position, sourceObj: target.gameObject);
            // deactivates the stun and makes you wait;

            // Special case: If we're on help intent (only stun), we should still show the lerp (unless we're hitting ourselves)
            if (interaction.Intent == Intent.Help && performer != target)
            {
                wna.RpcMeleeAttackLerp(dir, gameObject);
            }
        }
        else if (!canStun)
        {
            if (coolDownMessage)
            {
                return;
            }
            coolDownMessage = true;
            Chat.AddExamineMsg(performer, $"{gameObject.ExpensiveName()} is on cooldown.");
        }
    }
Ejemplo n.º 3
0
        public void ServerPerformInteraction(HandApply interaction)
        {
            GameObject target    = interaction.TargetObject;
            GameObject performer = interaction.Performer;

            // Direction for lerp
            Vector2 dir = (target.transform.position - performer.transform.position).normalized;

            WeaponNetworkActions wna = performer.GetComponent <WeaponNetworkActions>();
            ToggleableEffect     toggleableEffect = gameObject.GetComponent <ToggleableEffect>();

            // If we're on harm intent we deal damage!
            // Note: this has to be done before the teleport, otherwise the target may be moved out of range.
            if (interaction.Intent == Intent.Harm &&
                (toggleableEffect.CurrentWeaponState == ToggleableEffect.WeaponState.Off ||
                 toggleableEffect.CurrentWeaponState == ToggleableEffect.WeaponState.NoCell))
            {
                // Direction of attack towards the attack target.
                wna.ServerPerformMeleeAttack(target, dir, interaction.TargetBodyPart, LayerType.None);
                return;                 //Only do damage to the target, do not do anything afterwards.
            }
            //If the thing is off on any intent, tell the player that it won't do anything.
            else if (toggleableEffect.CurrentWeaponState == ToggleableEffect.WeaponState.Off ||
                     toggleableEffect.CurrentWeaponState == ToggleableEffect.WeaponState.NoCell)
            {
                Chat.AddActionMsgToChat(interaction.Performer,
                                        $"You attempt to prod {interaction.TargetObject.ExpensiveName()} but the {gameObject.ExpensiveName()} was off!",
                                        $"{interaction.Performer.ExpensiveName()} prods {interaction.TargetObject.ExpensiveName()}, luckily the {gameObject.ExpensiveName()} was off!");
                SoundManager.PlayNetworkedAtPos(CommonSounds.Instance.Tap, gameObject.RegisterTile().WorldPosition);
                return;
            }

            if (canEffect && hasBattery)
            {
                if (Battery.Watts >= chargeUsage)
                {
                    Battery.Watts -= chargeUsage;
                }
                else
                {
                    if (toggleableEffect != null)
                    {
                        toggleableEffect.TurnOff();
                    }

                    timer     = cooldown;
                    canEffect = false;
                }
            }

            RegisterPlayer registerPlayerVictim = target.GetComponent <RegisterPlayer>();

            // Teleport and stun the victim (if needed). We check if there is a cooldown preventing the attacker from effecting the victim.
            if (registerPlayerVictim && canEffect)
            {
                // deactivates the weapon and makes you wait.
                if (cooldown != 0)
                {
                    canEffect = false;
                    timer     = cooldown;
                }

                if (canStun)
                {
                    registerPlayerVictim.ServerStun(stunTime);
                }

                if (canTeleport)
                {
                    TeleportUtils.ServerTeleportRandom(target, minTeleportDistance, maxTeleportDistance, avoidSpace, avoidImpassable);
                }

                SoundManager.PlayNetworkedAtPos(useSound, target.transform.position, sourceObj: target.gameObject);

                // Special case: If we're off harm intent (only teleporting and/or stunning), we should still show the lerp (unless we're hitting ourselves).
                if (interaction.Intent != Intent.Harm && performer != target)
                {
                    wna.RpcMeleeAttackLerp(dir, gameObject);
                }
            }
            else if (!canEffect)
            {
                if (coolDownMessage)
                {
                    return;
                }
                coolDownMessage = true;
                if (hasBattery)
                {
                    if (Battery.Watts >= chargeUsage)
                    {
                        Chat.AddExamineMsg(performer, $"{gameObject.ExpensiveName()} is on cooldown.");
                    }
                    else
                    {
                        Chat.AddExamineMsg(performer, $"{gameObject.ExpensiveName()} is out of power.");
                    }
                }
                else
                {
                    Chat.AddExamineMsg(performer, $"{gameObject.ExpensiveName()} is on cooldown.");
                }
            }
        }