private bool ValidateFloating(Vector3 origin, Vector3 goal)
    {
//		Logger.Log( $"{gameObject.name} check {origin}->{goal}. Speed={serverState.Speed}" );
        Vector3Int             intOrigin = Vector3Int.RoundToInt(origin);
        Vector3Int             intGoal   = Vector3Int.RoundToInt(goal);
        var                    info      = serverState.ActiveThrow;
        List <HealthBehaviour> hitDamageables;

        if (CanDriftTo(intOrigin, intGoal) & !HittingSomething(intGoal, info.ThrownBy, out hitDamageables))
        {
            return(true);
        }

        //Hurting what we can
        if (hitDamageables != null && hitDamageables.Count > 0 && !Equals(info, ThrowInfo.NoThrow))
        {
            for (var i = 0; i < hitDamageables.Count; i++)
            {
                //Remove cast to int when moving health values to float
                var damage = ( int )(ItemAttributes.throwDamage * 2);
                hitDamageables[i].ApplyDamage(info.ThrownBy, damage, DamageType.BRUTE, info.Aim);
                PostToChatMessage.SendThrowHitMessage(gameObject, hitDamageables[i].gameObject, damage, info.Aim);
            }
            //todo:hit sound
        }

        return(false);
//				RpcForceRegisterUpdate();
    }
Exemple #2
0
    protected virtual void OnHit(Vector3Int pos, ThrowInfo info, List <LivingHealthBehaviour> objects, List <TilemapDamage> tiles)
    {
        if (!ItemAttributes)
        {
            Logger.LogWarningFormat("{0}: Tried to hit stuff at pos {1} but have no ItemAttributes.", Category.Throwing, gameObject.name, pos);
            return;
        }
        //Hurting tiles
        for (var i = 0; i < tiles.Count; i++)
        {
            var tileDmg = tiles[i];
            var damage  = ( int )(ItemAttributes.throwDamage * 2);
            tileDmg.DoThrowDamage(pos, info, damage);
        }

        //Hurting objects
        if (objects != null && objects.Count > 0 && !Equals(info, ThrowInfo.NoThrow))
        {
            for (var i = 0; i < objects.Count; i++)
            {
                //Remove cast to int when moving health values to float
                var damage  = (int)(ItemAttributes.throwDamage * 2);
                var hitZone = info.Aim.Randomize();
                objects[i].ApplyDamage(info.ThrownBy, damage, DamageType.Brute, hitZone);
                PostToChatMessage.SendThrowHitMessage(gameObject, objects[i].gameObject, damage, hitZone);
            }
            //hit sound
            SoundManager.PlayNetworkedAtPos("GenericHit", transform.position, 1f);
        }
        else
        {
            //todo different sound for no-damage hit?
            SoundManager.PlayNetworkedAtPos("GenericHit", transform.position, 0.8f);
        }
    }
Exemple #3
0
    private bool ValidateFloating(Vector3 origin, Vector3 goal)
    {
//		Logger.Log( $"{gameObject.name} check {origin}->{goal}. Speed={serverState.Speed}" );
        Vector3Int             intOrigin = Vector3Int.RoundToInt(origin);
        Vector3Int             intGoal   = Vector3Int.RoundToInt(goal);
        var                    info      = serverState.ActiveThrow;
        List <HealthBehaviour> hitDamageables;

        if (CanDriftTo(intOrigin, intGoal) & !HittingSomething(intGoal, info.ThrownBy, out hitDamageables))
        {
            //if object is solid, check if player is nearby to make it stop
            return(registerTile.IsPassable() ? true : !IsPlayerNearby(serverState));
        }
        else
        {
            //Can't drift to goal for some reason:
            //Check Tile damage from throw
            var hit2D = Physics2D.RaycastAll(origin, info.Trajectory.normalized, 1.5f, tileDmgMask);

            for (int i = 0; i < hit2D.Length; i++)
            {
                //Debug.Log("THROW HIT: " + hit2D[i].collider.gameObject.name);

                //TilemapDamage automatically detects if a layer is below another damageable layer and won't affect it
                var tileDmg = hit2D[i].collider.gameObject.GetComponent <TilemapDamage>();
                if (tileDmg != null)
                {
                    var damage = ( int )(ItemAttributes.throwDamage * 2);
                    tileDmg.DoThrowDamage(intGoal, info, damage);
                }
            }
        }

        //Hurting what we can
        if (hitDamageables != null && hitDamageables.Count > 0 && !Equals(info, ThrowInfo.NoThrow))
        {
            for (var i = 0; i < hitDamageables.Count; i++)
            {
                //Remove cast to int when moving health values to float
                var damage = ( int )(ItemAttributes.throwDamage * 2);
                hitDamageables[i].ApplyDamage(info.ThrownBy, damage, DamageType.BRUTE, info.Aim);
                PostToChatMessage.SendThrowHitMessage(gameObject, hitDamageables[i].gameObject, damage, info.Aim);
            }
            //hit sound
            PlaySoundMessage.SendToAll("GenericHit", transform.position, 1f);
        }

        return(false);
    }