//only intended to be used by core if2 classes
    public static void SendTileApply(TileApply tileApply, InteractableTiles interactableTiles, TileInteraction tileInteraction, int tileInteractionIndex)
    {
        //if we are client and the interaction has client prediction, trigger it.
        //Note that client prediction is not triggered for server player.
        if (!CustomNetworkManager.IsServer)
        {
            Logger.LogTraceFormat("Predicting TileApply interaction {0}", Category.Interaction, tileApply);
            tileInteraction.ClientPredictInteraction(tileApply);
        }
        if (!tileApply.Performer.Equals(PlayerManager.LocalPlayer))
        {
            Logger.LogError("Client attempting to perform an interaction on behalf of another player." +
                            " This is not allowed. Client can only perform an interaction as themselves. Message" +
                            " will not be sent.", Category.NetMessage);
            return;
        }

        var msg = new RequestInteractMessage()
        {
            ComponentType        = typeof(InteractableTiles),
            InteractionType      = typeof(TileApply),
            ProcessorObject      = interactableTiles.GetComponent <NetworkIdentity>().netId,
            Intent               = tileApply.Intent,
            TargetVector         = tileApply.TargetVector,
            TileInteractionIndex = tileInteractionIndex
        };

        msg.Send();
    }
Exemplo n.º 2
0
    public void ServerPerformInteraction(PositionalHandApply interaction)
    {
        //which matrix are we clicking on
        var        interactableTiles = InteractableTiles.GetAt(interaction.WorldPositionTarget, true);
        Vector3Int cellPos           = interactableTiles.WorldToCell(interaction.WorldPositionTarget);
        var        tileAtPosition    = interactableTiles.LayerTileAt(interaction.WorldPositionTarget);

        //which way are we placing it
        foreach (var entry in waysToPlace)
        {
            //open space
            if (tileAtPosition == null && entry.placeableOn == LayerType.None && entry.placeableOnlyOnTile == null)
            {
                interactableTiles.TileChangeManager.UpdateTile(cellPos, entry.layerTile);
                break;
            }
            // placing on an existing tile
            else if (tileAtPosition.LayerType == entry.placeableOn &&
                     (entry.placeableOnlyOnTile == null || entry.placeableOnlyOnTile == tileAtPosition))
            {
                interactableTiles.TileChangeManager.UpdateTile(cellPos, entry.layerTile);
                break;
            }
        }

        interactableTiles.TileChangeManager.SubsystemManager.UpdateAt(cellPos);
        Inventory.ServerConsume(interaction.HandSlot, 1);
    }
 private void Awake()
 {
     metaTileMap       = GetComponentInChildren <MetaTileMap>();
     subsystemManager  = GetComponent <SubsystemManager>();
     interactableTiles = GetComponent <InteractableTiles>();
     networkMatrix     = GetComponent <NetworkedMatrix>();
 }
Exemplo n.º 4
0
        //only intended to be used by core if2 classes
        public static void SendTileApply(TileApply tileApply, InteractableTiles interactableTiles, TileInteraction tileInteraction)
        {
            //if we are client and the interaction has client prediction, trigger it.
            //Note that client prediction is not triggered for server player.
            if (!CustomNetworkManager.IsServer)
            {
                Logger.LogTraceFormat("Predicting TileApply interaction {0}", Category.Interaction, tileApply);
                tileInteraction.ClientPredictInteraction(tileApply);
            }
            if (!tileApply.Performer.Equals(PlayerManager.LocalPlayer))
            {
                Logger.LogError("Client attempting to perform an interaction on behalf of another player." +
                                " This is not allowed. Client can only perform an interaction as themselves. Message" +
                                " will not be sent.", Category.Exploits);
                return;
            }

            var msg = new NetMessage()
            {
                ComponentType   = typeof(InteractableTiles),
                InteractionType = typeof(TileApply),
                ProcessorObject = GetNetId(interactableTiles.gameObject),
                Intent          = tileApply.Intent,
                TargetPosition  = tileApply.TargetPosition
            };

            Send(msg);
        }
Exemplo n.º 5
0
 public TileMouseDrop(GameObject performer, GameObject usedObject, Intent intent, Vector2Int targetCellPos,
                      InteractableTiles targetInteractableTiles, BasicTile basicTile, Vector2 targetVector) : base(performer, usedObject, intent)
 {
     this.targetCellPos           = targetCellPos;
     this.targetInteractableTiles = targetInteractableTiles;
     this.basicTile    = basicTile;
     this.targetVector = targetVector;
 }
Exemplo n.º 6
0
    public void ServerPerformInteraction(PositionalHandApply interaction)
    {
        //which matrix are we clicking on
        var        interactableTiles = InteractableTiles.GetAt(interaction.WorldPositionTarget, true);
        Vector3Int cellPos           = interactableTiles.WorldToCell(interaction.WorldPositionTarget);
        var        tileAtPosition    = interactableTiles.LayerTileAt(interaction.WorldPositionTarget, layerTypeSelection);

        PlaceableTileEntry placeableTileEntry = null;

        int itemAmount = 1;
        var stackable  = interaction.HandObject.GetComponent <Stackable>();

        if (stackable != null)
        {
            itemAmount = stackable.Amount;
        }
        // find the first valid way possible to place a tile
        foreach (var entry in waysToPlace)
        {
            //skip what can't be afforded
            if (entry.itemCost > itemAmount)
            {
                continue;
            }

            //open space
            if (tileAtPosition == null && entry.placeableOn == LayerType.None && entry.placeableOnlyOnTile == null)
            {
                placeableTileEntry = entry;
                break;
            }

            // placing on an existing tile
            else if (tileAtPosition.LayerType == entry.placeableOn && (entry.placeableOnlyOnTile == null || entry.placeableOnlyOnTile == tileAtPosition))
            {
                placeableTileEntry = entry;
                break;
            }
        }

        if (placeableTileEntry != null)
        {
            GameObject performer      = interaction.Performer;
            Vector2    targetPosition = interaction.WorldPositionTarget;


            void ProgressFinishAction()
            {
                interactableTiles.TileChangeManager.UpdateTile(cellPos, placeableTileEntry.layerTile);
                interactableTiles.TileChangeManager.SubsystemManager.UpdateAt(cellPos);
                Inventory.ServerConsume(interaction.HandSlot, placeableTileEntry.itemCost);
                SoundManager.PlayNetworkedAtPos(placeSound, targetPosition);
            }

            var bar = StandardProgressAction.Create(ProgressConfig, ProgressFinishAction)
                      .ServerStartProgress(targetPosition, placeableTileEntry.timeToPlace, performer);
        }
    }
Exemplo n.º 7
0
        public override bool Interact(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            if (base.Interact(hit, interactableTiles, worldPosition) == false)
            {
                return(true);
            }

            return(ProcessCount());
        }
        public override bool Interact(RaycastHit2D hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            if (base.Interact(hit, interactableTiles, worldPosition) == false)
            {
                return(true);
            }

            return(ProcessCount());
        }
Exemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="performer">performer of the interaction</param>
 /// <param name="usedObject">object in hand</param>
 /// <param name="intent">intent of the performer</param>
 /// <param name="targetCellPos">cell position being targeted on the interactable tiles</param>
 /// <param name="targetInteractableTiles">interactable tiles containing the tile being targeted</param>
 /// <param name="basicTile">info of the tile being targeted</param>
 /// <param name="handSlot">slot being used</param>
 /// <param name="targetVector">vector pointing from perform to the targeted position</param>
 public TileApply(GameObject performer, GameObject usedObject, Intent intent, Vector2Int targetCellPos,
                  InteractableTiles targetInteractableTiles, BasicTile basicTile, ItemSlot handSlot, Vector2 targetVector) : base(performer, usedObject, intent)
 {
     this.targetCellPos           = targetCellPos;
     this.targetInteractableTiles = targetInteractableTiles;
     this.basicTile    = basicTile;
     this.handSlot     = handSlot;
     this.targetVector = targetVector;
 }
Exemplo n.º 10
0
    private void ScrewInPlace(HandApply interaction)
    {
        var        interactableTiles = InteractableTiles.GetAt(interaction.TargetObject.TileWorldPosition(), true);
        Vector3Int cellPos           = interactableTiles.WorldToCell(interaction.TargetObject.TileWorldPosition());

        interactableTiles.TileChangeManager.UpdateTile(cellPos, layerTile);
        interactableTiles.TileChangeManager.SubsystemManager.UpdateAt(cellPos);
        Despawn.ServerSingle(gameObject);
    }
Exemplo n.º 11
0
        private void SpawnTable(HandApply interaction, LayerTile tableToSpawn)
        {
            var        interactableTiles = InteractableTiles.GetAt(interaction.TargetObject.TileWorldPosition(), true);
            Vector3Int cellPos           = interactableTiles.WorldToCell(interaction.TargetObject.TileWorldPosition());

            interaction.HandObject.GetComponent <Stackable>().ServerConsume(2);
            interactableTiles.TileChangeManager.UpdateTile(cellPos, tableToSpawn);
            interactableTiles.TileChangeManager.SubsystemManager.UpdateAt(cellPos);
            _ = Despawn.ServerSingle(gameObject);
        }
Exemplo n.º 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="performer">performer of the interaction</param>
 /// <param name="usedObject">object in hand</param>
 /// <param name="intent">intent of the performer</param>
 /// <param name="targetCellPos">cell position being targeted on the interactable tiles</param>
 /// <param name="targetInteractableTiles">interactable tiles containing the tile being targeted</param>
 /// <param name="basicTile">info of the tile being targeted</param>
 /// <param name="handSlot">slot being used</param>
 /// <param name="targetVector">vector pointing from perform to the targeted position</param>
 public TileApply(GameObject performer, GameObject usedObject, Intent intent, Vector2Int targetCellPos,
                  InteractableTiles targetInteractableTiles, BasicTile basicTile, ItemSlot handSlot, Vector2 targetPosition, ApplyType type = ApplyType.HandApply) : base(performer, usedObject, intent)
 {
     this.targetCellPos           = targetCellPos;
     this.targetInteractableTiles = targetInteractableTiles;
     this.basicTile      = basicTile;
     this.handSlot       = handSlot;
     this.targetPosition = targetPosition;
     this.applyType      = type;
 }
Exemplo n.º 13
0
        public bool Interact(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            if (CheckConditions(hit, interactableTiles, worldPosition) == false)
            {
                return(true);
            }

            movingProjectile.position = hit.HitWorld;
            RotateBullet(GetNewDirection(hit));

            return(IsCountReached());
        }
Exemplo n.º 14
0
        public bool Interact(RaycastHit2D hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            if (CheckConditions(hit, interactableTiles, worldPosition) == false)
            {
                return(true);
            }

            movingProjectile.position = hit.point;
            RotateBullet(GetNewDirection(hit));

            return(IsCountReached());
        }
Exemplo n.º 15
0
        public bool Interact(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            var layerToHit = GetLayerToHitOrGetNull(interactableTiles.MetaTileMap.DamageableLayers);

            if (layerToHit == null)
            {
                return(false);
            }

            layerToHit.TilemapDamage.ApplyDamage(damageData.Damage, damageData.AttackType, worldPosition);

            return(true);
        }
Exemplo n.º 16
0
        /// <summary>
        ///  Invokes cached behaviours
        /// </summary>
        /// <param name="hit"></param>
        /// <param name="interactableTile"></param>
        /// <param name="bulletHitTarget"></param>
        /// <returns> True if at least one behaviour returned true </returns>
        private bool TryProcessBehaviours(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTile, Vector3 bulletHitTarget)
        {
            bool isAnyProcessed = false;

            foreach (var behaviour in behavioursInteractTile)
            {
                if (behaviour.Interact(hit, interactableTile, bulletHitTarget))
                {
                    isAnyProcessed = true;
                }
            }

            return(isAnyProcessed);
        }
Exemplo n.º 17
0
        public override bool CheckCondition(RaycastHit2D hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            var layers = interactableTiles.MetaTileMap.DamageableLayers;

            foreach (var layer in layers)
            {
                if (CheckType(layer.LayerType))
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        ///  Invokes cached behaviours
        /// </summary>
        /// <param name="hit"></param>
        /// <param name="interactableTile"></param>
        /// <param name="bulletHitTarget"></param>
        /// <returns> True if at least one behaviour returned true </returns>
        private bool TryProcessBehaviours(RaycastHit2D hit, InteractableTiles interactableTile, Vector3 bulletHitTarget)
        {
            bool isAnyProcessed = false;

            foreach (var behaviour in behavioursInteractTile)
            {
                if (behaviour.Interact(hit, interactableTile, bulletHitTarget))
                {
                    isAnyProcessed = true;
                }
            }

            return(isAnyProcessed);
        }
Exemplo n.º 19
0
    public void ServerPerformInteraction(PositionalHandApply interaction)
    {
        //which matrix are we clicking on

        var matrix = InteractableTiles.TryGetNonSpaceMatrix(interaction.WorldPositionTarget.RoundToInt(), true);

        if (matrix.IsSpaceMatrix)
        {
            matrix = interaction.Performer.RegisterTile().Matrix;
        }


        var interactableTiles = matrix.TileChangeManager.InteractableTiles;

        Vector3Int cellPos        = interactableTiles.WorldToCell(interaction.WorldPositionTarget);
        var        tileAtPosition = interactableTiles.LayerTileAt(interaction.WorldPositionTarget, layerTypeSelection);

        PlaceableTileEntry placeableTileEntry = null;

        int itemAmount = 1;
        var stackable  = interaction.HandObject.GetComponent <Stackable>();

        if (stackable != null)
        {
            itemAmount = stackable.Amount;
        }

        placeableTileEntry = FindValidTile(itemAmount, tileAtPosition);

        if (placeableTileEntry != null)
        {
            GameObject performer      = interaction.Performer;
            Vector2    targetPosition = interaction.WorldPositionTarget;


            void ProgressFinishAction()
            {
                ProgressFinishActionPriv(interaction, placeableTileEntry, interactableTiles, cellPos, targetPosition);
            }

            void ProgressInterruptedAction(ActionInterruptionType reason)
            {
                ProgressInterruptedActionPriv(interaction, reason, placeableTileEntry);
            }

            var bar = StandardProgressAction.Create(ProgressConfig, ProgressFinishAction, ProgressInterruptedAction)
                      .ServerStartProgress(targetPosition, placeableTileEntry.timeToPlace, performer);
        }
    }
Exemplo n.º 20
0
        public bool Interact(RaycastHit2D hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            var layerToHit = GetLayerToHitOrGetNull(interactableTiles.MetaTileMap.DamageableLayers);

            if (layerToHit == null)
            {
                return(false);
            }

            float newDamage = projectileKineticDamage.DamageByPressureModifier(damageData.Damage);

            layerToHit.TilemapDamage.ApplyDamage(damageData.Damage, damageData.AttackType, worldPosition);

            return(true);
        }
Exemplo n.º 21
0
 private void ProgressFinishActionPriv(PositionalHandApply interaction, PlaceableTileEntry placeableTileEntry,
                                       InteractableTiles interactableTiles, Vector3Int cellPos, Vector2 targetPosition)
 {
     if (Inventory.ServerConsume(interaction.HandSlot, placeableTileEntry.itemCost))
     {
         interactableTiles.TileChangeManager.MetaTileMap.SetTile(cellPos, placeableTileEntry.layerTile);
         interactableTiles.TileChangeManager.SubsystemManager.UpdateAt(cellPos);
         SoundManager.PlayNetworkedAtPos(placeSound, targetPosition);
     }
     else
     {
         Chat.AddExamineMsgFromServer(interaction.PerformerPlayerScript.connectedPlayer,
                                      $"You lack the materials to finish placing {placeableTileEntry.layerTile.DisplayName}");
     }
 }
Exemplo n.º 22
0
        public bool Interact(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            var layers = interactableTiles.MetaTileMap.DamageableLayers;

            foreach (var layer in layers)
            {
                if (layerType.CheckType(layer.LayerType) == false)
                {
                    continue;
                }

                if (layer.TilemapDamage.ApplyDamage(damageData.Damage, damageData.AttackType, worldPosition) <= 0)
                {
                    continue;
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 23
0
    public static void SendTileMouseDrop(TileMouseDrop mouseDrop, InteractableTiles interactableTiles)
    {
        if (!mouseDrop.Performer.Equals(PlayerManager.LocalPlayer))
        {
            Logger.LogError("Client attempting to perform an interaction on behalf of another player." +
                            " This is not allowed. Client can only perform an interaction as themselves. Message" +
                            " will not be sent.", Category.NetMessage);
            return;
        }

        var msg = new RequestInteractMessage()
        {
            ComponentType   = typeof(InteractableTiles),
            InteractionType = typeof(TileMouseDrop),
            ProcessorObject = interactableTiles.GetComponent <NetworkIdentity>().netId,
            Intent          = mouseDrop.Intent,
            UsedObject      = mouseDrop.UsedObject.NetId(),
            TargetVector    = mouseDrop.TargetVector
        };

        msg.Send();
    }
Exemplo n.º 24
0
    public bool WillInteract(PositionalHandApply interaction, NetworkSide side)
    {
        if (!DefaultWillInteract.Default(interaction, side))
        {
            return(false);
        }
        if (interaction.HandObject != gameObject)
        {
            return(false);
        }

        //it's annoying to place something when you're trying to pick up instead to add to your current stack,
        //so if it's possible to stack what is being targeted with what's in your hand, we will defer to that
        if (Validations.CanStack(interaction.HandObject, interaction.TargetObject))
        {
            return(false);
        }

        //check if we are clicking a spot we can place a tile on
        var interactableTiles = InteractableTiles.GetAt(interaction.WorldPositionTarget, side);
        var tileAtPosition    = interactableTiles.LayerTileAt(interaction.WorldPositionTarget);

        foreach (var entry in waysToPlace)
        {
            //open space
            if (tileAtPosition == null && entry.placeableOn == LayerType.None && entry.placeableOnlyOnTile == null)
            {
                return(true);
            }
            // placing on an existing tile
            else if (tileAtPosition.LayerType == entry.placeableOn &&
                     (entry.placeableOnlyOnTile == null || entry.placeableOnlyOnTile == tileAtPosition))
            {
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 25
0
        public static void SendTileMouseDrop(TileMouseDrop mouseDrop, InteractableTiles interactableTiles)
        {
            if (!mouseDrop.Performer.Equals(PlayerManager.LocalPlayer))
            {
                Logger.LogError("Client attempting to perform an interaction on behalf of another player." +
                                " This is not allowed. Client can only perform an interaction as themselves. Message" +
                                " will not be sent.", Category.Exploits);
                return;
            }

            var msg = new NetMessage()
            {
                ComponentType   = typeof(InteractableTiles),
                InteractionType = typeof(TileMouseDrop),
                ProcessorObject = GetNetId(interactableTiles.gameObject),
                Intent          = mouseDrop.Intent,
                UsedObject      = GetNetId(mouseDrop.UsedObject),
                TargetVector    = mouseDrop.TargetVector
            };

            Send(msg);
        }
Exemplo n.º 26
0
 private void Start()
 {
     interactableTiles = GetComponent <InteractableTiles>();
 }
Exemplo n.º 27
0
 public virtual bool Interact(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTiles, Vector3 worldPosition)
 {
     return(interactableTiles.TryMine(worldPosition));
 }
Exemplo n.º 28
0
 private void Start()
 {
     gameObjectRoot    = transform.root.gameObject;
     interactableTiles = GetComponent <InteractableTiles>();
 }
Exemplo n.º 29
0
        /// <summary>
        /// Really simple check for determining if the wall can reflect bullet
        /// Hard coded only to check wall LayerType
        /// </summary>
        /// <param name="hit"></param>
        /// <param name="interactableTiles"></param>
        /// <param name="worldPosition"></param>
        /// <returns></returns>
        public override bool CheckCondition(RaycastHit2D hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            var tile = interactableTiles.MetaTileMap.GetTileAtWorldPos(worldPosition, LayerType.Walls) as BasicTile;

            return(tile != null && tile.DoesReflectBullet);
        }
Exemplo n.º 30
0
 private bool CheckConditions(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTiles, Vector3 worldPosition)
 {
     return(hitInteractTileConditions.Conditions.Any(condition => condition.CheckCondition(hit, interactableTiles, worldPosition)));
 }