Exemple #1
0
        protected override void ActOnTile(Vector3Int worldPos, Vector3 dir)
        {
            var matrix = MatrixManager.AtPoint(worldPos, true);

            var pos = (worldPos - registerObj.WorldPositionServer).sqrMagnitude;

            //Greater than 4 means more than one tile away
            if (pos > 4)
            {
                //Attack adjacent tiles instead
                var normalised = (worldPos - registerObj.WorldPositionServer).Normalize();
                var posShift   = registerObj.WorldPositionServer;
                var xSuccess   = false;

                //x must be either -1, or 1 for us to attack it
                if (normalised.x != 0)
                {
                    posShift.x += normalised.x;

                    //Check for the tiles on the x tile
                    xSuccess = CheckTile(true);

                    //Check for impassable objects to hit on the x tile
                    if (TryAttackObjects(posShift, dir))
                    {
                        return;
                    }
                }

                //x must have failed and y must be either -1, or 1 for us to attack it
                if (xSuccess == false && normalised.y != 0)
                {
                    //Remove x change and then add y change
                    posShift.x -= normalised.x;
                    posShift.y += normalised.y;

                    //Check for impassable objects to hit first before tile
                    if (TryAttackObjects(posShift, new Vector3(0, normalised.y, 0)))
                    {
                        return;
                    }

                    if (CheckTile() == false)
                    {
                        //Else nothing to attack, x and y failed so stop
                        return;
                    }
                }

                bool CheckTile(bool isX = false)
                {
                    dir = new Vector3(isX ? normalised.x : 0, isX ? 0 : normalised.y, 0);

                    if (MatrixManager.IsWindowAtAnyMatrix(posShift, true) || MatrixManager.IsGrillAtAnyMatrix(posShift, true))
                    {
                        worldPos = posShift;
                        return(true);
                    }

                    return(false);
                }
            }
            else
            {
                //This is the target tile so check for impassable objects to hit before attacking tile
                if (TryAttackObjects(worldPos, dir))
                {
                    return;
                }
            }

            matrix.MetaTileMap.ApplyDamage(MatrixManager.WorldToLocalInt(worldPos, matrix), hitDamage * 2, worldPos);
            ServerDoLerpAnimation(dir);
        }