예제 #1
0
 public Placement(Block block, Vector2Int position, BlockOrientation orientation, BlockMaterial material)
 {
     Block       = block;
     Position    = position;
     Orientation = orientation;
     Material    = material;
 }
예제 #2
0
        void HandleTool_ColorPickModeFromBlock(PaintMaterial paintMaterial, BlockMaterial blockMaterial, bool trigger)
        {
            if (trigger)
            {
                Main.Palette.ColorPickMode = false;
                Main.Palette.GrabPaletteFromPaint(new PaintMaterial(blockMaterial.ColorMask, blockMaterial.Skin));
                return;
            }

            if (!ToolPreviewPaint.HasValue || !ToolPreviewPaint.Value.PaintEquals(blockMaterial))
            {
                ToolPreviewPaint = new PaintMaterial(blockMaterial.ColorMask, blockMaterial.Skin);
                Main.HUDSounds.PlayItem();
            }

            if (paintMaterial.ColorMask.HasValue && !paintMaterial.Skin.HasValue)
            {
                Main.SelectionGUI.SetGUIStatus(0, "Click to get this color.", "lime");
            }
            else if (!paintMaterial.ColorMask.HasValue && paintMaterial.Skin.HasValue)
            {
                Main.SelectionGUI.SetGUIStatus(0, "Click to select this skin.", "lime");
            }
            else
            {
                Main.SelectionGUI.SetGUIStatus(0, "Click to get this material.", "lime");
            }

            Main.SelectionGUI.SetGUIStatus(1, null);
        }
예제 #3
0
        //detects if you are in the air
        private void TouchingSomething()
        {
            //int playerLayerMask = LayerMask.GetMask("Ignore Raycast", "Player");
            //Invert the layer mask to check all but the player's layer:
            int playerLayerMask = ~excludeLayersAsGround;

            // Raycast Implementation:
            //RaycastHit temp; Physics.Raycast(new Vector3(foot.position.x, foot.position.y + 0.2f, foot.position.z), new Vector3(0, -1, 0), out temp, .2f, playerLayerMask); Debug.DrawRay(new Vector3(foot.position.x, foot.position.y + 0.2f, foot.position.z), new Vector3(0, .2f, 0), Color.red);

            Collider[] touching = Physics.OverlapSphere(new Vector3(foot.position.x, foot.position.y - 0.2f, foot.position.z), groundDetectionRadius, playerLayerMask);
            //Takes first touching object
            if (touching.Length > 0)
            {
                //print(touching[0]);
                this.transform.parent = touching[0].transform.parent;
                if (touching[0].gameObject.tag == "Wood" || touching[0].gameObject.tag == "Ice" || touching[0].gameObject.tag == "Sand")
                {
                    curMat = (BlockMaterial)Enum.Parse(typeof(BlockMaterial), touching[0].gameObject.tag);
                }
                else
                {
                    curMat = BlockMaterial.Wood;
                }
                if (inAir)
                {
                    soundPlayer.PlayOneShot(landing[(int)curMat]);
                }
                inAir = false;
            }
            else
            {
                this.transform.parent = null;
                inAir = true;
            }
        }
예제 #4
0
 public override bool IsMatch(BlockMaterial blockMaterial)
 {
     return(blockMaterial == BlockMaterial.RockI ||
            blockMaterial == BlockMaterial.RockII ||
            blockMaterial == BlockMaterial.RockIII ||
            blockMaterial == BlockMaterial.RockIV);
 }
예제 #5
0
        public override void Received(ref RelayMode relay)
        {
            // no way to check if creative tools is enabled for sender but it's enough to check their access level.
            if (Main.IsServer && MyAPIGateway.Session.GetUserPromoteLevel(OriginalSenderSteamId) < MyPromoteLevel.SpaceMaster)
            {
                MyLog.Default.WriteLineAndConsole($"{PaintGunMod.MOD_NAME} Warning: Player {Utils.PrintPlayerName(OriginalSenderSteamId)} tried to use replace paint while not being at least SpaceMaster promote level.");
                Main.NetworkLibHandler.PacketWarningMessage.Send(OriginalSenderSteamId, "Failed to replace paint server side, access denied.");
                return;
            }

            bool modified = false;

            if (!Main.Palette.ValidateSkinOwnership(NewPaint.Skin, OriginalSenderSteamId))
            {
                NewPaint = new SerializedPaintMaterial(NewPaint.ColorMaskPacked, null);
                modified = true;
            }

            MyCubeGrid grid = Utils.GetEntityOrError <MyCubeGrid>(this, GridEntId, Constants.NETWORK_DESYNC_ERROR_LOGGING);

            if (grid == null)
            {
                if (Main.IsServer)
                {
                    Main.NetworkLibHandler.PacketWarningMessage.Send(OriginalSenderSteamId, "Failed to replace paint server side, grid no longer exists.");
                }

                return;
            }

            if (Main.IsServer)
            {
                // ensure server side if safezone permissions are respected
                if (!Utils.SafeZoneCanPaint(grid, OriginalSenderSteamId))
                {
                    Main.NetworkLibHandler.PacketWarningMessage.Send(OriginalSenderSteamId, "Failed to replace paint server side, denied by safe zone.");
                    return;
                }

                long identity = MyAPIGateway.Players.TryGetIdentityId(OriginalSenderSteamId);
                if (!Utils.AllowedToPaintGrid(grid, identity))
                {
                    Main.NetworkLibHandler.PacketWarningMessage.Send(OriginalSenderSteamId, "Failed to replace paint server side, ship not allied.");
                    return;
                }
            }

            PaintMaterial newPaint = new PaintMaterial(NewPaint);
            BlockMaterial oldPaint = new BlockMaterial(OldPaint);

            Main.Painting.ReplaceColorInGrid(false, grid, oldPaint, newPaint, IncludeSubgrids, OriginalSenderSteamId);

            if (Main.IsServer)
            {
                relay = modified ? RelayMode.RelayWithChanges : RelayMode.RelayOriginal;
            }
        }
예제 #6
0
    private void Start()
    {
        _rigidbody     = GetComponent <Rigidbody2D>();
        _collider      = GetComponent <BoxCollider2D>();
        _blockMaterial = GetComponent <BlockMaterial>();
        _blockScore    = GetComponent <BlockScore>();

        _collider.enabled = false;
        IsStay            = false;
        SetStartSettings();
    }
예제 #7
0
파일: Block.cs 프로젝트: LegacyGamerHD/Alex
        public virtual IItem[] GetDrops(IItem tool)
        {
            if (BlockMaterial.IsToolRequired() && !BlockMaterial.CanUseTool(tool.ItemType, tool.Material))
            {
                return(new IItem[0]);
            }

            return(new IItem[] { new ItemBlock(BlockState)
                                 {
                                     Count = 1
                                 } });
        }
예제 #8
0
 void Awake()
 {
     cameraTracking    = FindObjectOfType <CameraTracking>();
     magnitude         = 0f;
     curMat            = BlockMaterial.Wood;
     respawnTimerReset = respawnTimer;
     originalScale     = this.transform.localScale;
     rgbdy             = this.gameObject.GetComponent <Rigidbody>();
     //state machine init
     machine    = new PlayerStateMachine();
     doState    = new state[] { Idle, Moving, InAir, Jump, Attack, Hit, Dead };
     invunTimer = 0;
 }
예제 #9
0
        }                               // Empty constructor required for deserialization

        public void Send(IMyCubeGrid grid, BlockMaterial oldPaint, PaintMaterial newPaint, bool includeSubgrids)
        {
            GridEntId       = grid.EntityId;
            OldPaint        = new SerializedBlockMaterial(oldPaint);
            NewPaint        = new SerializedPaintMaterial(newPaint);
            IncludeSubgrids = includeSubgrids;

            Network.SendToServer(this);

            // do the action for local client too
            if (!MyAPIGateway.Session.IsServer)
            {
                Main.Painting.ReplaceColorInGrid(false, grid, oldPaint, newPaint, includeSubgrids, OriginalSenderSteamId);
            }
        }
예제 #10
0
        public bool IsMirrorBlockValid(IMySlimBlock block, PaintMaterial paintMaterial)
        {
            if (block == null)
            {
                return(false);
            }

            if (Main.Palette.ColorPickMode)
            {
                return(false);
            }

            if (!paintMaterial.ColorMask.HasValue && !paintMaterial.Skin.HasValue)
            {
                return(false);
            }

            if (!Utils.AllowedToPaintGrid(block.CubeGrid, MyAPIGateway.Session.Player.IdentityId))
            {
                return(false);
            }

            if (!Utils.SafeZoneCanPaint(block, MyAPIGateway.Multiplayer.MyId))
            {
                return(false);
            }

            BlockMaterial blockMaterial  = new BlockMaterial(block);
            bool          materialEquals = paintMaterial.PaintEquals(blockMaterial);

            if (Main.Palette.ReplaceMode)
            {
                return(!materialEquals);
            }

            if (!Main.InstantPaintAccess)
            {
                MyCubeBlockDefinition def = (MyCubeBlockDefinition)block.BlockDefinition;
                bool built = (block.BuildLevelRatio >= def.CriticalIntegrityRatio);

                if (!built || block.CurrentDamage > (block.MaxIntegrity / 10.0f))
                {
                    return(false);
                }
            }

            return(!materialEquals);
        }
예제 #11
0
    private void LoadFromLevelPatternAsset()
    {
        // don't write into level pattern save asset while loading
        var editor = IsEditor;

        IsEditor = false;
        foreach (var placement in LevelPatternSaveAsset.Placements)
        {
            BlockMaterial m = MaterialRegistry.Materials[0];
            if (placement.Material)
            {
                m = placement.Material;
            }
            InstantiateBlock(placement.Block, placement.Orientation, placement.Position.x, placement.Position.y, m);
        }
        IsEditor = editor;
    }
        public void SetAllTo(BlockMaterial material)
        {
            var total = Tiles.Count;

            if (total <= 0)
            {
                Debug.LogWarning("Selection is empty!");
                return;
            }

            var i      = 0;
            var chunks = new List <Chunk>();

            do
            {
                var tile = Tiles[i++];
                if (tile.Material == material)
                {
                    continue;
                }

                var tilePos = tile.Position;
                CheckAdd(tilePos, chunks, Vector2Int.left);
                CheckAdd(tilePos, chunks, Vector2Int.right);
                CheckAdd(tilePos, chunks, Vector2Int.down);
                CheckAdd(tilePos, chunks, Vector2Int.up);

                var chunk = world.GetChunkAt(tilePos);
                if (!chunks.Contains(chunk))
                {
                    chunks.Add(chunk);
                }

                chunk[world.ToLocalChunkPosition(tilePos)] = material;
            } while (i < total);

            foreach (var chunk in chunks)
            {
                chunk.LoadMesh(World.Instance);
            }
        }
예제 #13
0
    public void Start()
    {
        BlockMaterial mat      = Material;
        Rigidbody2D   body     = gameObject.GetComponent <Rigidbody2D>();
        Collider2D    collider = AddCollider();

        if (type != BlockType.Tower)
        {
            body.isKinematic = true;
        }
        collider.sharedMaterial = mat.physics;
        if (body.useAutoMass)
        {
            collider.density = mat.density;
        }
        Mesh       mesh   = MakeMesh();
        MeshFilter filter = gameObject.GetComponent <MeshFilter>();

        filter.mesh = mesh;
        MeshRenderer renderer = gameObject.GetComponent <MeshRenderer>();

        renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
        renderer.materials         = new Material[] { mat.material };
    }
예제 #14
0
        PaintMaterial HandleTool_PaintProcess(PaintMaterial paintMaterial, BlockMaterial blockMaterial, float paintSpeed, string blockName)
        {
            if (Main.Palette.ReplaceMode)
            {
                // notification for this is done in the ReceivedPacket method to avoid re-iterating blocks

                return(paintMaterial);
            }

            if (!paintMaterial.ColorMask.HasValue && !paintMaterial.Skin.HasValue)
            {
                return(paintMaterial);
            }

            if (Main.InstantPaintAccess)
            {
                Main.SelectionGUI.SetGUIStatus(0, "Painted!", "lime");
                Main.SelectionGUI.SetGUIStatus(1, Main.SelectionGUI.SymmetryStatusText);
                return(paintMaterial);
            }

            if (!paintMaterial.ColorMask.HasValue && paintMaterial.Skin.HasValue)
            {
                Main.SelectionGUI.SetGUIStatus(0, "Skinned!", "lime");
                Main.SelectionGUI.SetGUIStatus(1, Main.SelectionGUI.SymmetryStatusText);
                return(paintMaterial);
            }

            Vector3 paintColorMask = (paintMaterial.ColorMask.HasValue ? paintMaterial.ColorMask.Value : blockMaterial.ColorMask);
            Vector3 blockColorMask = blockMaterial.ColorMask;

            // If hue is within reason change saturation and value directly.
            if (Math.Abs(blockColorMask.X - paintColorMask.X) < PAINT_HUE_TOLERANCE)
            {
                paintSpeed *= PAINT_SPEED * PAINT_UPDATE_TICKS;
                paintSpeed *= MyAPIGateway.Session.WelderSpeedMultiplier;

                for (int i = 0; i < 3; i++)
                {
                    if (blockColorMask.GetDim(i) > paintColorMask.GetDim(i))
                    {
                        blockColorMask.SetDim(i, Math.Max(blockColorMask.GetDim(i) - paintSpeed, paintColorMask.GetDim(i)));
                    }
                    else
                    {
                        blockColorMask.SetDim(i, Math.Min(blockColorMask.GetDim(i) + paintSpeed, paintColorMask.GetDim(i)));
                    }
                }

                if (Utils.ColorMaskEquals(blockColorMask, paintColorMask))
                {
                    blockColorMask = paintColorMask;

                    Main.SelectionGUI.SetGUIStatus(0, "Painting done!", "lime");
                    Main.HUDSounds.PlayColor();
                }
                else
                {
                    int percent = Utils.ColorPercent(blockColorMask, paintColorMask);

                    Main.SelectionGUI.SetGUIStatus(0, $"Painting {percent.ToString()}%...");
                }
            }
            else // if hue is too far off, first "remove" the paint.
            {
                Vector3 defaultColorMask = Main.Palette.DefaultColorMask;

                paintSpeed *= DEPAINT_SPEED * PAINT_UPDATE_TICKS;
                paintSpeed *= MyAPIGateway.Session.GrinderSpeedMultiplier;

                blockColorMask.Y = Math.Max(blockColorMask.Y - paintSpeed, defaultColorMask.Y);
                blockColorMask.Z = (blockColorMask.Z > 0 ? Math.Max(blockColorMask.Z - paintSpeed, defaultColorMask.Z) : Math.Min(blockColorMask.Z + paintSpeed, defaultColorMask.Z));

                // when saturation and value reach the default color, change hue and begin painting
                if (Math.Abs(blockColorMask.Y - defaultColorMask.Y) < COLOR_EPSILON && Math.Abs(blockColorMask.Z - defaultColorMask.Z) < COLOR_EPSILON)
                {
                    blockColorMask.X = paintColorMask.X;
                }

                // block was stripped of color
                if (Utils.ColorMaskEquals(blockColorMask, defaultColorMask))
                {
                    // set the X (hue) to the paint's hue so that the other condition starts painting it saturation&value.
                    blockColorMask = new Vector3(paintColorMask.X, defaultColorMask.Y, defaultColorMask.Z);

                    if (Utils.ColorMaskEquals(paintColorMask, defaultColorMask))
                    {
                        blockColorMask = paintColorMask;
                        Main.SelectionGUI.SetGUIStatus(0, "Removing paint done!");
                    }
                    else
                    {
                        Main.SelectionGUI.SetGUIStatus(0, "Removing paint 100%...");
                    }
                }
                else
                {
                    int percent = Utils.ColorPercent(blockColorMask, defaultColorMask);

                    Main.SelectionGUI.SetGUIStatus(0, $"Removing paint {percent.ToString()}%...");
                }
            }

            return(new PaintMaterial(blockColorMask, paintMaterial.Skin));
        }
예제 #15
0
 public override bool IsMatch(BlockMaterial blockMaterial)
 {
     return(blockMaterial == BlockMaterial.Wood);
 }
예제 #16
0
        bool ValidateMainBlock(IMySlimBlock block, PaintMaterial paintMaterial, BlockMaterial blockMaterial, bool trigger)
        {
            if (!paintMaterial.ColorMask.HasValue && !paintMaterial.Skin.HasValue)
            {
                string assigned = InputHandler.GetFriendlyStringForControl(MyAPIGateway.Input.GetGameControl(MyControlsSpace.CUBE_COLOR_CHANGE));

                Main.Notifications.Show(0, "No paint or skin enabled.", MyFontEnum.Red);
                Main.Notifications.Show(1, $"Press [{assigned}] to toggle color or combined with [Shift] to toggle skin.", MyFontEnum.Debug);

                Main.SelectionGUI.SetGUIStatus(0, "No paint or skin enabled.", "red");
                Main.SelectionGUI.SetGUIStatus(1, null);
                return(false);
            }

            if (!Utils.AllowedToPaintGrid(block.CubeGrid, MyAPIGateway.Session.Player.IdentityId))
            {
                if (trigger)
                {
                    Main.HUDSounds.PlayUnable();
                    Main.Notifications.Show(0, "Can't paint enemy ships.", MyFontEnum.Red, 2000);
                }

                Main.SelectionGUI.SetGUIStatus(0, "Not allied ship.", "red");
                Main.SelectionGUI.SetGUIStatus(1, null);
                return(false);
            }

            if (!Utils.SafeZoneCanPaint(block, MyAPIGateway.Multiplayer.MyId))
            {
                if (trigger)
                {
                    Main.HUDSounds.PlayUnable();
                    Main.Notifications.Show(0, "Can't paint in this safe zone.", MyFontEnum.Red, 2000);
                }

                Main.SelectionGUI.SetGUIStatus(0, "Protected by safe zone", "red");
                Main.SelectionGUI.SetGUIStatus(1, null);
                return(false);
            }

            bool materialEquals = paintMaterial.PaintEquals(blockMaterial);

            if (Main.Palette.ReplaceMode)
            {
                AimedState = (materialEquals ? SelectionState.Invalid : SelectionState.Valid);

                string assigned = InputHandler.GetFriendlyStringForControl(MyAPIGateway.Input.GetGameControl(MyControlsSpace.USE_SYMMETRY));

                if (AimedState == SelectionState.Invalid)
                {
                    Main.SelectionGUI.SetGUIStatus(0, "Already this material.", "red");
                }
                else
                {
                    Main.SelectionGUI.SetGUIStatus(0, "Click to replace material.", "lime");
                }

                Main.SelectionGUI.SetGUIStatus(1, $"[{assigned}] {(Main.Palette.ReplaceShipWide ? "<color=yellow>" : "")}Replace mode: {(Main.Palette.ReplaceShipWide ? "Ship-wide" : "Grid")}");

                return(AimedState == SelectionState.Valid);
            }

            if (!Main.InstantPaintAccess)
            {
                MyCubeBlockDefinition def = (MyCubeBlockDefinition)block.BlockDefinition;
                bool built = (block.BuildLevelRatio >= def.CriticalIntegrityRatio);

                if (!built || block.CurrentDamage > (block.MaxIntegrity / 10.0f))
                {
                    AimedState = SelectionState.Invalid;

                    if (trigger)
                    {
                        Main.HUDSounds.PlayUnable();
                        Main.Notifications.Show(0, "Unfinished blocks can't be painted!", MyFontEnum.Red);
                    }

                    Main.SelectionGUI.SetGUIStatus(0, (!built ? "Block not built" : "Block damaged"), "red");
                    Main.SelectionGUI.SetGUIStatus(1, null);
                    return(false);
                }
            }

            MyCubeGrid grid              = (MyCubeGrid)block.CubeGrid;
            bool       symmetry          = Main.SymmetryAccess && MyCubeBuilder.Static.UseSymmetry && (grid.XSymmetryPlane.HasValue || grid.YSymmetryPlane.HasValue || grid.ZSymmetryPlane.HasValue);
            bool       symmetrySameColor = true;

            if (materialEquals)
            {
                AimedState = SelectionState.Invalid;

                if (symmetry)
                {
                    Vector3I?mirrorX  = null;
                    Vector3I?mirrorY  = null;
                    Vector3I?mirrorZ  = null;
                    Vector3I?mirrorYZ = null;

                    // NOTE: do not optimize, all methods must be called
                    if (!MirrorCheckSameColor(grid, 0, block.Position, paintMaterial, out mirrorX))
                    {
                        symmetrySameColor = false;
                    }

                    if (!MirrorCheckSameColor(grid, 1, block.Position, paintMaterial, out mirrorY))
                    {
                        symmetrySameColor = false;
                    }

                    if (!MirrorCheckSameColor(grid, 2, block.Position, paintMaterial, out mirrorZ))
                    {
                        symmetrySameColor = false;
                    }

                    if (mirrorX.HasValue && grid.YSymmetryPlane.HasValue) // XY
                    {
                        if (!MirrorCheckSameColor(grid, 1, mirrorX.Value, paintMaterial, out mirrorX))
                        {
                            symmetrySameColor = false;
                        }
                    }

                    if (mirrorX.HasValue && grid.ZSymmetryPlane.HasValue) // XZ
                    {
                        if (!MirrorCheckSameColor(grid, 2, mirrorX.Value, paintMaterial, out mirrorX))
                        {
                            symmetrySameColor = false;
                        }
                    }

                    if (mirrorY.HasValue && grid.ZSymmetryPlane.HasValue) // YZ
                    {
                        if (!MirrorCheckSameColor(grid, 2, mirrorY.Value, paintMaterial, out mirrorYZ))
                        {
                            symmetrySameColor = false;
                        }
                    }

                    if (grid.XSymmetryPlane.HasValue && mirrorYZ.HasValue) // XYZ
                    {
                        if (!MirrorCheckSameColor(grid, 0, mirrorYZ.Value, paintMaterial, out mirrorX))
                        {
                            symmetrySameColor = false;
                        }
                    }

                    if (!symmetrySameColor)
                    {
                        AimedState = SelectionState.InvalidButMirrorValid;
                    }
                }

                if (!symmetry || symmetrySameColor)
                {
                    AimedState = SelectionState.Invalid;

                    if (symmetry)
                    {
                        Main.SelectionGUI.SetGUIStatus(0, "All materials match.", "lime");
                    }
                    else
                    {
                        Main.SelectionGUI.SetGUIStatus(0, "Materials match.", "lime");
                    }

                    Main.SelectionGUI.SetGUIStatus(1, Main.SelectionGUI.SymmetryStatusText);
                    return(false);
                }
            }

            if (!trigger)
            {
                if (symmetry && !symmetrySameColor)
                {
                    Main.SelectionGUI.SetGUIStatus(0, "Click to update symmetry paint.");
                }
                else if (Main.InstantPaintAccess)
                {
                    Main.SelectionGUI.SetGUIStatus(0, "Click to paint.");
                }
                else
                {
                    Main.SelectionGUI.SetGUIStatus(0, "Hold click to paint.");
                }

                Main.SelectionGUI.SetGUIStatus(1, Main.SelectionGUI.SymmetryStatusText);
            }

            return(true);
        }
예제 #17
0
 public int RegisterMaterial(BlockMaterial material)
 {
     var id = (byte)_materialToId.Count;
     _idToMaterial[id] = material;
     _materialToId[material] = id;
     return id;
 }
예제 #18
0
 public virtual bool IsMatch(BlockMaterial blockMaterial)
 {
     return(blockMaterial == BlockMaterial.Ground);
 }
예제 #19
0
파일: Block.cs 프로젝트: LegacyGamerHD/Alex
        public double GetBreakTime(IItem miningTool)
        {
            double secondsForBreak = Hardness;
            bool   isHarvestable   = GetDrops(miningTool)?.Length > 0;

            if (BlockMaterial.IsToolRequired())
            {
                isHarvestable = BlockMaterial.CanUseTool(miningTool.ItemType, miningTool.Material);
            }

            if (isHarvestable)
            {
                secondsForBreak *= 1.5;
            }
            else
            {
                secondsForBreak *= 5;
            }
            if (secondsForBreak == 0D)
            {
                secondsForBreak = 0.05;
            }

            int tierMultiplier = 1;

            if (BlockMaterial.CanUseTool(miningTool.ItemType, miningTool.Material))
            {
                switch (miningTool.Material)
                {
                case ItemMaterial.Wood:
                    tierMultiplier = 2;
                    break;

                case ItemMaterial.Stone:
                    tierMultiplier = 4;
                    break;

                case ItemMaterial.Gold:
                    tierMultiplier = 12;
                    break;

                case ItemMaterial.Iron:
                    tierMultiplier = 6;
                    break;

                case ItemMaterial.Diamond:
                    tierMultiplier = 8;
                    break;
                }
            }

            if (isHarvestable)
            {
                switch (miningTool.ItemType)
                {
                case ItemType.Shears:
                    if (this is Wool)
                    {
                        return(secondsForBreak / 5);
                    }
                    else if (this is Leaves || this is AcaciaLeaves || this is Cobweb)
                    {
                        return(secondsForBreak / 15);
                    }
                    break;

                case ItemType.Sword:
                    if (this is Cobweb)
                    {
                        return(secondsForBreak / 15);
                    }
                    return(secondsForBreak / 1.5);

                case ItemType.Shovel:
                case ItemType.Axe:
                case ItemType.PickAxe:
                case ItemType.Hoe:
                    return(secondsForBreak / tierMultiplier);
                }
            }

            return(secondsForBreak);
        }
 public WorldTile(Vector3Int position, BlockMaterial material)
 {
     this.Position = position;
     this.Material = material;
 }
예제 #21
0
    private KinematicBlock InstantiateBlock(Block block, BlockOrientation orientation, int x, int y, BlockMaterial m, bool place = true)
    {
        Vector3 position      = new Vector3(x, y, 0);
        Vector3 worldSpacePos = transform.TransformPoint(position);
        var     go            = Instantiate(block.Prefab, worldSpacePos, KinematicBlock.OrientationToRotation(orientation), transform);
        var     kblock        = go.AddComponent <KinematicBlock>();

        kblock.Initialize(this, block, m, BlockMaterial);

        Vector2Int simPos   = kblock.GetTopLeftPoint();
        var        localpos = go.transform.localPosition;

        localpos.x += x - simPos.x;
        localpos.y += y - simPos.y;
        go.transform.localPosition = localpos;
        Debug.DrawLine(Vector3.zero, worldSpacePos);
        Debug.Log($"InstantiateBlock [{x}, {y}] => {worldSpacePos} => {simPos}");
        if (!place)
        {
            return(kblock);
        }

        if (!CanPlace(kblock))
        {
            Destroy(go);
            return(null);
        }

        PlaceBlock(kblock, true);

        var goBackground =
            Instantiate(block.Prefab, go.transform.position - new Vector3(0, 0, -0.25f),
                        go.transform.rotation, transform);

        goBackground.GetComponent <MeshRenderer>().sharedMaterial = m.MaterialPrefab;

        return(kblock);
    }
예제 #22
0
        protected override Material ParseModelFromJavaField(string line)
        {
            System.Globalization.CultureInfo invariancy = System.Globalization.CultureInfo.InvariantCulture;

            int    startIndex = 0;
            int    endIndex   = line.IndexOf(" ", startIndex);
            string type       = line.Substring(startIndex, endIndex - startIndex);

            startIndex = endIndex + 1;
            endIndex   = line.IndexOf(" ", startIndex);
            string name = line.Substring(startIndex, endIndex - startIndex);

            Material material = null;

            if (type == "ToolMaterial")
            {
                material = new ToolMaterial()
                {
                    Name = name
                };
                ToolMaterial toolMaterial = (ToolMaterial)material;

                startIndex = line.IndexOf(",", endIndex) + 1;
                endIndex   = line.IndexOf(",", startIndex);
                string harvestLevel = line.Substring(startIndex, endIndex - startIndex);
                toolMaterial.HarvestLevel = int.Parse(harvestLevel, invariancy);

                startIndex = line.IndexOf(",", endIndex) + 1;
                endIndex   = line.IndexOf(",", startIndex);
                string maxUses = line.Substring(startIndex, endIndex - startIndex);
                toolMaterial.MaxUses = int.Parse(maxUses, invariancy);

                startIndex = line.IndexOf(",", endIndex) + 1;
                endIndex   = line.IndexOf(",", startIndex);
                string efficiency = line.Substring(startIndex, endIndex - startIndex);
                toolMaterial.Efficiency = float.Parse(efficiency, invariancy);

                startIndex = line.IndexOf(",", endIndex) + 1;
                endIndex   = line.IndexOf(",", startIndex);
                string damage = line.Substring(startIndex, endIndex - startIndex);
                toolMaterial.AttackDamage = float.Parse(damage, invariancy);

                startIndex = line.IndexOf(",", endIndex) + 1;
                endIndex   = line.IndexOf(",", startIndex);
                string enchantability = line.Substring(startIndex, endIndex - startIndex);
                toolMaterial.Enchantability = int.Parse(enchantability, invariancy);
            }
            else if (type == "ArmorMaterial")
            {
                material = new ArmorMaterial()
                {
                    Name = name
                };
                ArmorMaterial armorMaterial = (ArmorMaterial)material;

                startIndex = line.IndexOf(",", endIndex) + 1;
                endIndex   = line.IndexOf(",", startIndex);
                string textureName = line.Substring(startIndex, endIndex - startIndex);
                armorMaterial.TextureName = textureName;

                startIndex = line.IndexOf(",", endIndex) + 1;
                endIndex   = line.IndexOf(",", startIndex);
                string durability = line.Substring(startIndex, endIndex - startIndex);
                armorMaterial.Durability = int.Parse(durability, invariancy);

                startIndex = line.IndexOf("{", endIndex) + 1;
                endIndex   = line.IndexOf("}", startIndex);
                string reductionAmounts = line.Substring(startIndex, endIndex - startIndex).Trim();
                armorMaterial.HelmetDamageReduction = (int)char.GetNumericValue(reductionAmounts, 0);
                armorMaterial.PlateDamageReduction  = (int)char.GetNumericValue(reductionAmounts, 2);
                armorMaterial.LegsDamageReduction   = (int)char.GetNumericValue(reductionAmounts, 4);
                armorMaterial.BootsDamageReduction  = (int)char.GetNumericValue(reductionAmounts, 6);

                startIndex = line.IndexOf(",", endIndex) + 1;
                endIndex   = line.IndexOf(",", startIndex);
                string enchantability = line.Substring(startIndex, endIndex - startIndex);
                armorMaterial.Enchantability = int.Parse(enchantability, invariancy);

                startIndex = line.IndexOf(",", endIndex) + 1;
                endIndex   = line.IndexOf(",", startIndex);
                string soundOnEquip = line.Substring(startIndex, endIndex - startIndex);
                armorMaterial.SoundEvent = soundOnEquip;

                startIndex = line.IndexOf(",", endIndex) + 1;
                endIndex   = line.IndexOf(",", startIndex);
                string toughness = line.Substring(startIndex, endIndex - startIndex);
                armorMaterial.Toughness = float.Parse(toughness, invariancy);
            }
            else if (type == "Material")
            {
                material = new BlockMaterial()
                {
                    Name = name
                };
                BlockMaterial blockMaterial = (BlockMaterial)material;

                startIndex = line.IndexOf("(", endIndex) + 1;
                endIndex   = line.IndexOf(")", startIndex);
                string solid = line.Substring(startIndex, endIndex - startIndex);
                blockMaterial.IsSolid = bool.Parse(solid);

                startIndex = line.IndexOf("(", endIndex) + 1;
                endIndex   = line.IndexOf(")", startIndex);
                string liquid = line.Substring(startIndex, endIndex - startIndex);
                blockMaterial.IsLiquid = bool.Parse(liquid);

                startIndex = line.IndexOf("(", endIndex) + 1;
                endIndex   = line.IndexOf(")", startIndex);
                string blockLight = line.Substring(startIndex, endIndex - startIndex);
                blockMaterial.BlocksLight = bool.Parse(blockLight);

                startIndex = line.IndexOf("(", endIndex) + 1;
                endIndex   = line.IndexOf(")", startIndex);
                string blockMovement = line.Substring(startIndex, endIndex - startIndex);
                blockMaterial.BlocksMovement = bool.Parse(blockMovement);

                startIndex = line.IndexOf("(", endIndex) + 1;
                endIndex   = line.IndexOf(")", startIndex);
                string translucent = line.Substring(startIndex, endIndex - startIndex);
                blockMaterial.IsTranslucent = bool.Parse(translucent);

                startIndex = line.IndexOf("(", endIndex) + 1;
                endIndex   = line.IndexOf(")", startIndex);
                string requiresNoTool = line.Substring(startIndex, endIndex - startIndex);
                blockMaterial.RequiresNoTool = bool.Parse(requiresNoTool);

                startIndex = line.IndexOf("(", endIndex) + 1;
                endIndex   = line.IndexOf(")", startIndex);
                string burning = line.Substring(startIndex, endIndex - startIndex);
                blockMaterial.CanBurn = bool.Parse(burning);

                startIndex = line.IndexOf("(", endIndex) + 1;
                endIndex   = line.IndexOf(")", startIndex);
                string replaceable = line.Substring(startIndex, endIndex - startIndex);
                blockMaterial.IsReplaceable = bool.Parse(replaceable);

                startIndex = line.IndexOf("(", endIndex) + 1;
                endIndex   = line.IndexOf(")", startIndex);
                string adventureModeExempt = line.Substring(startIndex, endIndex - startIndex);
                blockMaterial.IsAdventureModeExempt = bool.Parse(adventureModeExempt);

                startIndex = line.IndexOf("(", endIndex) + 1;
                endIndex   = line.IndexOf(")", startIndex);
                string mobilityFlag = line.Substring(startIndex, endIndex - startIndex);
                blockMaterial.MobilityFlag = (PushReaction)System.Enum.Parse(typeof(PushReaction), mobilityFlag.Remove(0, "EnumPushReaction.".Length), true);
            }
            else
            {
                throw new System.NotImplementedException($"Implementation of {type} was not found");
            }

            material.IsDirty = false;
            return(material);
        }
예제 #23
0
 public void Add(Block block, BlockOrientation orientation, BlockMaterial material, Vector2Int position)
 {
     block = block.Original;
     Placements.Add(new Placement(block, position, orientation, material));
     SetDirtyReally();
 }
예제 #24
0
        /// <summary>
        /// Returns True if tool has painted.
        /// </summary>
        void HandleTool(bool trigger)
        {
            AimedPlayer            = null;
            AimedBlock             = null;
            AimedState             = SelectionState.Invalid;
            SymmetryInputAvailable = false;

            IMyCharacter character = MyAPIGateway.Session.Player.Character;
            IMyCubeGrid  targetGrid;
            IMySlimBlock targetBlock;
            IMyPlayer    targetPlayer;
            Vector3D     aimPoint;

            GetTarget(character, out targetGrid, out targetBlock, out targetPlayer, out aimPoint);

            if (targetPlayer != null && Main.Palette.ColorPickMode)
            {
                HandleTool_ColorPickFromPlayer(trigger, targetPlayer);
                return;
            }

            if (targetBlock == null)
            {
                if (Main.Palette.ColorPickMode)
                {
                    Main.Notifications.Show(0, "Aim at a block or player and click to pick color.", MyFontEnum.Blue);
                }
                else if (!Utils.SafeZoneCanPaint(aimPoint, MyAPIGateway.Multiplayer.MyId))
                {
                    // sound likely already played by the shoot restriction in the safe zone
                    //HUDSounds.PlayUnable();

                    if (trigger)
                    {
                        Main.Notifications.Show(0, "Can't paint in this safe zone.", MyFontEnum.Red);
                    }
                }
                else if (Main.Palette.ReplaceMode)
                {
                    Main.Notifications.Show(0, $"Aim at a block to replace its color on {(Main.Palette.ReplaceShipWide ? "the entire ship" : "this grid")}.", MyFontEnum.Blue);
                }
                else if (trigger)
                {
                    //Main.HUDSounds.PlayUnable();

                    if (!Main.IgnoreAmmoConsumption && LocalTool.Ammo == 0)
                    {
                        Main.Notifications.Show(0, "No ammo and no target.", MyFontEnum.Red);
                    }
                    else
                    {
                        Main.Notifications.Show(0, "Aim at a block to paint it.", MyFontEnum.Red);
                    }
                }

                return;
            }

            Main.SelectionGUI.UpdateSymmetryStatus(targetBlock);

            PaintMaterial paintMaterial = Main.Palette.GetLocalPaintMaterial();
            BlockMaterial blockMaterial = new BlockMaterial(targetBlock);

            AimedBlock = targetBlock;

            if (Main.Palette.ColorPickMode)
            {
                HandleTool_ColorPickModeFromBlock(paintMaterial, blockMaterial, trigger);
                return;
            }

            if (!ValidateMainBlock(targetBlock, paintMaterial, blockMaterial, trigger))
            {
                return;
            }

            string blockName = Utils.GetBlockName(targetBlock);

            if (!Main.IgnoreAmmoConsumption && LocalTool.Ammo == 0)
            {
                if (trigger)
                {
                    //Main.HUDSounds.PlayUnable();
                    Main.Notifications.Show(1, "No ammo.", MyFontEnum.Red);
                }

                Main.SelectionGUI.SetGUIStatus(0, "No ammo!", "red");
                return;
            }

            AimedState = SelectionState.Valid;

            if (trigger)
            {
                float         paintSpeed    = (1.0f / Utils.GetBlockSurface(targetBlock));
                PaintMaterial finalMaterial = HandleTool_PaintProcess(paintMaterial, blockMaterial, paintSpeed, blockName);

                if (Main.Palette.ReplaceMode && Main.ReplaceColorAccess)
                {
                    Main.Painting.ToolReplacePaint(targetGrid, blockMaterial, finalMaterial, Main.Palette.ReplaceShipWide);
                }
                else
                {
                    bool useMirroring = (Main.SymmetryAccess && MyAPIGateway.CubeBuilder.UseSymmetry);
                    Main.Painting.ToolPaintBlock(targetGrid, targetBlock.Position, finalMaterial, useMirroring);
                }
            }
        }
예제 #25
0
파일: Block.cs 프로젝트: LegacyGamerHD/Alex
        public virtual bool ShouldRenderFace(BlockFace face, Block neighbor)
        {
            if (Transparent)
            {
                if (Solid)
                {
                    //	if (IsFullCube && Name.Equals(block.Name)) return false;
                    if (neighbor.Solid && (neighbor.Transparent || !neighbor.IsFullCube))
                    {
                        //var block = world.GetBlock(pos.X, pos.Y, pos.Z);
                        if (!BlockMaterial.IsOpaque() && !neighbor.BlockMaterial.IsOpaque())
                        {
                            return(false);
                        }

                        if (!IsFullBlock || !neighbor.IsFullBlock)
                        {
                            return(true);
                        }
                    }

                    //If neighbor is solid & not transparent. Hmmm?
                    if (neighbor.Solid && !(neighbor.Transparent || !neighbor.IsFullCube))
                    {
                        return(true);
                    }
                }
                else
                {
                    //  if (neighbor.Solid && neighbor.Transparent && neighbor.IsFullCube)
                    //     return true;

                    if (neighbor.Solid && !(neighbor.Transparent || neighbor.IsFullCube))
                    {
                        return(false);
                    }
                }
            }


            if (Solid && (neighbor.Transparent || !neighbor.IsFullCube))
            {
                return(true);
            }
            //   if (me.Transparent && block.Transparent && !block.Solid) return false;
            if (Transparent)
            {
                return(true);
            }
            if (!Transparent && (neighbor.Transparent || !neighbor.IsFullCube))
            {
                return(true);
            }
            if (neighbor.Solid && !(neighbor.Transparent || !neighbor.IsFullCube))
            {
                return(false);
            }
            if (Solid && neighbor.Solid && neighbor.IsFullCube)
            {
                return(false);
            }

            return(true);
        }
예제 #26
0
 public int GetMaterialId(BlockMaterial material)
 {
     return _materialToId[material];
 }