Exemple #1
0
    public void PrimaryFire(float Sens)
    {
        if (Sens > 0 && !IsPrimaryFiring)
        {
            IsPrimaryFiring = true;

            if (Inventory[InventorySlot] != null)
            {
                //Assume for now that all primary fire opertations are to build
                RayCast BuildRayCast = GetNode("SteelCamera/RayCast") as RayCast;
                if (BuildRayCast.IsColliding())
                {
                    Structure Hit = BuildRayCast.GetCollider() as Structure;
                    if (Hit != null && GhostInstance.CanBuild)
                    {
                        Vector3?PlacePosition = BuildPositions.Calculate(Hit, GhostInstance.CurrentMeshType);
                        if (PlacePosition != null && Game.Mode.ShouldPlaceStructure(GhostInstance.CurrentMeshType, PlacePosition.Value, BuildRotations.Calculate(Hit, GhostInstance.CurrentMeshType)))
                        {
                            World.PlaceOn(Hit, GhostInstance.CurrentMeshType, 1);                        //ID 1 for now so all client own all non-default structures
                        }
                    }
                }
            }
        }
        if (Sens <= 0 && IsPrimaryFiring)
        {
            IsPrimaryFiring = false;
        }
    }
Exemple #2
0
    public override void _PhysicsProcess(float Delta)
    {
        Items.Instance Item = Game.PossessedPlayer.Inventory[Game.PossessedPlayer.InventorySlot];
        if (Item != null && Item.Type != CurrentMeshType)        //null means no item in slot
        {
            GhostMesh.Mesh  = Meshes[Item.Type];
            CurrentMeshType = Item.Type;
        }

        GhostMesh.Translation     = OldPositions[0];
        GhostMesh.RotationDegrees = OldRotations[0];
        GhostMesh.Visible         = OldVisible[0];

        Player Plr = Game.PossessedPlayer;

        OldVisible.RemoveAt(0);
        OldVisible.Add(false);
        if (Plr.Inventory[Plr.InventorySlot] != null)
        {
            RayCast BuildRayCast = Plr.GetNode("SteelCamera/RayCast") as RayCast;
            if (BuildRayCast.IsColliding())
            {
                Structure Hit = BuildRayCast.GetCollider() as Structure;
                if (Hit != null)
                {
                    System.Nullable <Vector3> GhostPosition = BuildPositions.Calculate(Hit, Plr.Inventory[Plr.InventorySlot].Type);
                    if (GhostPosition != null)
                    {
                        Vector3 GhostRotation = BuildRotations.Calculate(Hit, Plr.Inventory[Plr.InventorySlot].Type);
                        Translation     = (Vector3)GhostPosition;
                        RotationDegrees = GhostRotation;
                        OldVisible[1]   = true;
                    }
                }
            }
        }
        if (OldVisible[1] == false)
        {
            OldVisible[0]     = false;
            GhostMesh.Visible = false;
        }

        OldCanBuild.RemoveAt(0);
        if (GetOverlappingBodies().Count > 0)
        {
            GhostMesh.MaterialOverride = RedMat;
            OldCanBuild.Add(false);
        }
        else
        {
            GhostMesh.MaterialOverride = GreenMat;
            OldCanBuild.Add(true);
        }
        CanBuild = OldCanBuild[0];

        OldPositions.RemoveAt(0);
        OldPositions.Add(Translation);
        OldRotations.RemoveAt(0);
        OldRotations.Add(RotationDegrees);
    }
Exemple #3
0
 public static void PlaceOn(Structure Base, Items.TYPE BranchType, int OwnerId)
 {
     System.Nullable <Vector3> Position = BuildPositions.Calculate(Base, BranchType);
     if (Position != null)        //If null then unsupported branch/base combination
     {
         Vector3 Rotation = BuildRotations.Calculate(Base, BranchType);
         Place(BranchType, (Vector3)Position, Rotation, OwnerId);
     }
 }
Exemple #4
0
    Building()
    {
        foreach (Items.TYPE Type in System.Enum.GetValues(typeof(Items.TYPE)))
        {
            File ToLoad = new File();
            if (ToLoad.FileExists("res://Building/Scenes/" + Type.ToString() + ".tscn"))
            {
                Scenes.Add(Type, GD.Load("res://Building/Scenes/" + Type.ToString() + ".tscn") as PackedScene);
            }
            else
            {
                Scenes.Add(Type, GD.Load("res://Building/Scenes/ERROR.tscn") as PackedScene);
            }
        }

        BuildPositionsInstance = new BuildPositions();
        BuildRotationsInstance = new BuildRotations();
    }