예제 #1
0
    public void Launch(CharacterEntity attacker, bool isLeftHandWeapon)
    {
        if (attacker == null || !NetworkServer.active)
        {
            return;
        }

        var characterColliders = Physics.OverlapSphere(attacker.TempTransform.position, damagePrefab.GetAttackRange() + 5f, 1 << GameInstance.Singleton.characterLayer);

        for (int i = 0; i < spread; ++i)
        {
            Transform launchTransform;
            attacker.GetDamageLaunchTransform(isLeftHandWeapon, out launchTransform);
            // An transform's rotation, position will be set when set `Attacker`
            // So don't worry about them before damage entity going to spawn
            // Velocity also being set when set `Attacker` too.
            var addRotationX = Random.Range(-staggerY, staggerY);
            var addRotationY = Random.Range(-staggerX, staggerX);
            var position     = launchTransform.position;
            var direction    = attacker.TempTransform.forward;
            var damageEntity = DamageEntity.InstantiateNewEntity(damagePrefab, isLeftHandWeapon, position, direction, attacker.netId, addRotationX, addRotationY);
            damageEntity.weaponDamage = Mathf.CeilToInt(damage / spread);
            var msg = new OpMsgCharacterAttack();
            msg.weaponId      = GetId();
            msg.position      = position;
            msg.direction     = direction;
            msg.attackerNetId = attacker.netId;
            msg.addRotationX  = addRotationX;
            msg.addRotationY  = addRotationY;
            foreach (var characterCollider in characterColliders)
            {
                var character = characterCollider.GetComponent <CharacterEntity>();
                if (character != null && !(character is BotEntity))
                {
                    NetworkServer.SendToClient(character.connectionToClient.connectionId, msg.OpId, msg);
                }
            }
        }

        attacker.RpcEffect(attacker.netId, CharacterEntity.RPC_EFFECT_DAMAGE_SPAWN);
    }
예제 #2
0
    public static DamageEntity InstantiateNewEntity(
        DamageEntity prefab,
        bool isLeftHandWeapon,
        Vector3 position,
        Vector3 direction,
        NetworkInstanceId attackerNetId,
        float addRotationX,
        float addRotationY)
    {
        if (prefab == null)
        {
            return(null);
        }

        CharacterEntity attacker = null;
        var             go       = NetworkServer.active ? NetworkServer.FindLocalObject(attackerNetId) : ClientScene.FindLocalObject(attackerNetId);

        if (go != null)
        {
            attacker = go.GetComponent <CharacterEntity>();
        }

        if (attacker != null)
        {
            Transform launchTransform;
            attacker.GetDamageLaunchTransform(isLeftHandWeapon, out launchTransform);
            position = launchTransform.position + attacker.TempTransform.forward * prefab.spawnForwardOffset;
        }
        var rotation = Quaternion.LookRotation(direction, Vector3.up);

        rotation = Quaternion.Euler(rotation.eulerAngles + new Vector3(addRotationX, addRotationY));
        var result = Instantiate(prefab, position, rotation);

        result.InitAttackData(isLeftHandWeapon, attackerNetId, addRotationX, addRotationY);
        return(result);
    }