Exemplo n.º 1
0
    public PhysPart SpawnPartInHand(PartBlueprint bp)
    {
        PhysPart p = SetCurrPart(SpawnEditorPart(bp));

        p.transform.rotation = lastObjRot;
        return(p);
    }
Exemplo n.º 2
0
    public PartBlueprint GetBlueprint()
    {
        PartBlueprint bp = new PartBlueprint();

        bp.partName = partName;
        bp.position = transform.localPosition; //All parts should be direct children of "body". If that weren't the standard, things could get weird considering multiple connections per part etc.
        bp.rotation = transform.localEulerAngles;

        bp.health = health;
        bp.heat   = currentHeat;

        //if supported, save each component's extra info
        int i = 0;

        foreach (PartComponent component in components)
        {
            ComponentBlueprint cbp = component.GetBlueprint();
            if (cbp == null)
            {
                continue;
            }

            cbp.componentIndex = i; //keep track of the index of this component to apply it correctly when loading.
            bp.componentDatas.Add(cbp);
            i++;
        }

        return(bp);
    }
Exemplo n.º 3
0
    private void SetupRewards(GameObject gameObject, RewardWrapper wrapper)
    {
        gameObject.transform.Find("Credit Reward Text").GetComponent <Text>().text =
            "Credit reward: " + wrapper.creditReward;

        gameObject.transform.Find("Reputation Reward Text").GetComponent <Text>().text =
            "Reputation reward: " + wrapper.reputationReward;
        // Part reward
        if (wrapper.partReward)
        {
            // Part image:
            PartBlueprint blueprint = ResourceManager.GetAsset <PartBlueprint>(wrapper.partID);
            if (!blueprint)
            {
                Debug.LogWarning("Part reward of Start Task wrapper not found!");
            }

            var partImage = gameObject.transform.Find("Part").GetComponent <Image>();
            partImage.sprite = ResourceManager.GetAsset <Sprite>(blueprint.spriteID);
            partImage.rectTransform.sizeDelta = partImage.sprite.bounds.size * 45;
            partImage.color = Color.green;

            // Ability image:
            if (wrapper.partAbilityID > 0)
            {
                var backgroudBox   = gameObject.transform.Find("backgroundbox");
                var abilityIcon    = backgroudBox.Find("Ability").GetComponent <Image>();
                var tierIcon       = backgroudBox.Find("Tier").GetComponent <Image>();
                var type           = backgroudBox.Find("Type").GetComponent <Text>();
                var abilityTooltip = backgroudBox.GetComponent <AbilityButtonScript>();

                abilityIcon.sprite = AbilityUtilities.GetAbilityImageByID(wrapper.partAbilityID, wrapper.partSecondaryData);
                if (wrapper.partTier >= 1)
                {
                    tierIcon.sprite = ResourceManager.GetAsset <Sprite>("AbilityTier" + Mathf.Clamp(wrapper.partTier, 1, 3));
                }
                else
                {
                    tierIcon.enabled = false;
                }

                type.text = AbilityUtilities.GetAbilityNameByID(wrapper.partAbilityID, null) + (wrapper.partTier > 0 ? " " + wrapper.partTier : "");
                string description = "";
                description += AbilityUtilities.GetAbilityNameByID(wrapper.partAbilityID, null) + (wrapper.partTier > 0 ? " " + wrapper.partTier : "") + "\n";
                description += AbilityUtilities.GetDescriptionByID(wrapper.partAbilityID, wrapper.partTier, null);
                abilityTooltip.abilityInfo = description;
            }
            else
            {
                gameObject.transform.Find("backgroundbox").gameObject.SetActive(false);
            }
        }
        else
        {
            gameObject.transform.Find("Part").GetComponent <Image>().enabled = false;
            gameObject.transform.Find("backgroundbox").gameObject.SetActive(false);
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Build Part
    /// </summary>
    /// <param name="blueprint">blueprint of the part</param>
    public static GameObject BuildPart(PartBlueprint blueprint)
    {
        if (shaderMaterials == null)
        {
            shaderMaterials = new List <Material>();
            shaderMaterials.Add(ResourceManager.GetAsset <Material>("part_shader0"));
            shaderMaterials.Add(ResourceManager.GetAsset <Material>("part_shader1"));
        }

        GameObject holder;

        if (!GameObject.Find("Part Holder"))
        {
            holder = new GameObject("Part Holder");
        }
        else
        {
            holder = GameObject.Find("Part Holder");
        }


        GameObject obj = Instantiate(ResourceManager.GetAsset <GameObject>("base_part"));

        obj.transform.SetParent(holder.transform);

        //Part sprite
        var spriteRenderer = obj.GetComponent <SpriteRenderer>();

        spriteRenderer.material = shaderMaterials[partShader];
        spriteRenderer.sprite   = ResourceManager.GetAsset <Sprite>(blueprint.spriteID);
        var part = obj.GetComponent <ShellPart>();

        part.partMass      = blueprint.mass;
        part.partHealth    = blueprint.health;
        part.currentHealth = blueprint.health;
        var collider = obj.GetComponent <PolygonCollider2D>();

        collider.isTrigger = true;
        part.detachible    = blueprint.detachible;

        var partSys = obj.GetComponent <ParticleSystem>();
        var sh      = partSys.shape;

        if (spriteRenderer.sprite)
        {
            sh.scale = spriteRenderer.sprite.bounds.extents * 2;
        }

        var e = partSys.emission;

        e.rateOverTime = new ParticleSystem.MinMaxCurve(3 * (blueprint.size + 1));
        e.enabled      = false;
        part.partSys   = partSys;
        return(obj);
    }
Exemplo n.º 5
0
    public PhysPart GrabPartFromList(string name)
    {
        if (!PartDatabase.PartsList.ContainsKey(name))
        {
            Debug.LogError("Invalid Part Grab attempt from List - \"" + name + "\"");
            return(null);
        }

        ScriptablePartBP bpScriptable = PartDatabase.PartsList[name];
        PartBlueprint    bp           = bpScriptable.partPrefab.GetComponent <PhysPart>().GetBlueprint();

        return(SpawnPartInHand(bp));
    }
Exemplo n.º 6
0
    /// <summary>
    /// Applies blueprint's properties to this part.
    /// </summary>
    public void ApplyBlueprint(PartBlueprint bp)
    {
        transform.localPosition    = bp.position;
        transform.localEulerAngles = bp.rotation;

        health      = bp.health;
        currentHeat = bp.heat;

        //if supported, apply each component's extra info
        foreach (ComponentBlueprint cbp in bp.componentDatas)
        {
            PartComponent component = components[cbp.componentIndex];
            component.ApplyBlueprint(cbp);
        }
    }
Exemplo n.º 7
0
    public static CraftBlueprint GetBlueprintFromCraft(MultipartPhysBody craft)
    {
        CraftBlueprint bp = new CraftBlueprint();

        bp.craftName = craft.name;

        //Generate parts list
        int i = 0;

        foreach (PhysPart part in craft.Parts)
        {
            //save part info
            PartBlueprint p = part.GetBlueprint();

            //Check if this is the origin part if originPartIndex isn't assigned yet. If it is the origin part, assign originPartIndex to reference it.
            if (bp.originPartIndex == -1 && part == craft.originPart)
            {
                bp.originPartIndex = i;
            }

            bp.parts.Add(p);
            i++;
        }

        //Generate part connections list now that we have all the parts.
        //We can use indices interchangably between the physical craft and the blueprint because the parts were added in the same order.
        int partIndex = 0;

        foreach (PhysPart part in craft.Parts)
        {
            foreach (PartConnection connection in part.connections)
            {
                ConnectionBlueprint c = new ConnectionBlueprint();
                c.fromIndex = partIndex; //set fromIndex to reference the part we are currently processing
                int toIndex = craft.Parts.IndexOf(connection.toPart);
                c.toIndex = toIndex;

                bp.connections.Add(c);
            }
            partIndex++;
        }

        return(bp);
    }
    // Update is called once per frame
    void Update()
    {
        float[] totalHealths = CoreUpgraderScript.defaultHealths;
        float[] totalRegens  = CoreUpgraderScript.GetRegens(cursorScript?.player?.blueprint?.coreShellSpriteID);
        float   shipMass     = 1;
        float   enginePower  = 200;
        float   weight       = Entity.coreWeight;
        float   speed        = Craft.initSpeed;

        foreach (DisplayPart part in statsDatabase.GetParts())
        {
            switch (part.info.abilityID)
            {
            case 13:
                enginePower *= Mathf.Pow(1.1F, part.info.tier);
                speed       += 15 * part.info.tier;
                break;

            case 17:
                totalRegens[0] += 50 * part.info.tier;
                break;

            case 18:
                totalHealths[0] += 250 * part.info.tier;
                break;

            case 19:
                totalRegens[2] += 50 * part.info.tier;
                break;

            case 20:
                totalHealths[2] += 250 * part.info.tier;
                break;
            }
            PartBlueprint blueprint = ResourceManager.GetAsset <PartBlueprint>(part.info.partID);
            totalHealths[0] += blueprint.health / 2;
            totalHealths[1] += blueprint.health / 4;
            shipMass        += blueprint.mass;
            weight          += blueprint.mass * Entity.weightMultiplier;
        }
        string buildStat = "";

        if (statsDatabase.GetMode() == BuilderMode.Yard || statsDatabase.GetMode() == BuilderMode.Workshop)
        {
            buildStat = "\nTOTAL BUILD VALUE: \n" + statsDatabase.GetBuildValue() + " CREDITS";
        }
        else
        {
            string colorTag = "<color=white>";
            if (cursorScript.buildCost > 0)
            {
                colorTag = "<color=red>";
            }
            else if (cursorScript.buildCost < 0)
            {
                colorTag = "<color=lime>";
            }
            buildStat = "TOTAL BUILD COST: " + "\n" + colorTag + statsDatabase.GetBuildCost() + " CREDITS</color>";
        }
        display.text = "SHELL: " + totalHealths[0] + "\n"
                       + "CORE: " + totalHealths[1] + "\n"
                       + "ENERGY: " + totalHealths[2] + "\n"
                       + "SPEED: " + (int)Craft.GetPhysicsSpeed(speed, weight) + "\n"
                       + "WEIGHT: " + (int)weight + "\n"
                       + buildStat;
        regenDisplay.text = "REGEN: " + totalRegens[0] + "\n\n" + "REGEN: " + totalRegens[2];
    }
Exemplo n.º 9
0
        public override void NodeGUI()
        {
            GUILayout.BeginHorizontal();
            inputLeft.DisplayLayout();
            outputRight.DisplayLayout();
            GUILayout.EndHorizontal();

            showPopup = RTEditorGUI.Toggle(showPopup, "Show popup:");
            GUILayout.Label("Credit reward:");
            wrapper.creditReward = RTEditorGUI.IntField(wrapper.creditReward, GUILayout.Width(208f));
            GUILayout.Label("Reputation reward:");
            wrapper.reputationReward = RTEditorGUI.IntField(wrapper.reputationReward, GUILayout.Width(208f));
            GUILayout.Label("Shard reward:");
            wrapper.shardReward = RTEditorGUI.IntField(wrapper.shardReward, GUILayout.Width(208f));

            wrapper.partReward = RTEditorGUI.Toggle(wrapper.partReward, "Part reward", GUILayout.Width(200f));
            if (wrapper.partReward)
            {
                height += 320f;
                GUILayout.Label("Part ID:");
                wrapper.partID = GUILayout.TextField(wrapper.partID, GUILayout.Width(200f));
                if (ResourceManager.Instance != null && wrapper.partID != null && (GUI.changed || !init))
                {
                    init = true;
                    PartBlueprint partBlueprint = ResourceManager.GetAsset <PartBlueprint>(wrapper.partID);
                    if (partBlueprint != null)
                    {
                        partTexture = ResourceManager.GetAsset <Sprite>(partBlueprint.spriteID).texture;
                    }
                    else
                    {
                        partTexture = null;
                    }
                }

                if (partTexture != null)
                {
                    GUILayout.Label(partTexture);
                    height += partTexture.height + 8f;
                }
                else
                {
                    NodeEditorGUI.nodeSkin.label.normal.textColor = Color.red;
                    GUILayout.Label("<Part not found>");
                    NodeEditorGUI.nodeSkin.label.normal.textColor = NodeEditorGUI.NE_TextColor;
                }

                wrapper.partAbilityID = RTEditorGUI.IntField("Ability ID", wrapper.partAbilityID, GUILayout.Width(200f));
                string abilityName = AbilityUtilities.GetAbilityNameByID(wrapper.partAbilityID, null);
                if (abilityName != "Name unset")
                {
                    GUILayout.Label("Ability: " + abilityName);
                    height += 24f;
                }

                wrapper.partTier = RTEditorGUI.IntField("Part tier", wrapper.partTier, GUILayout.Width(200f));
                GUILayout.Label("Part Secondary Data:");
                wrapper.partSecondaryData = GUILayout.TextField(wrapper.partSecondaryData, GUILayout.Width(200f));
            }
            else
            {
                height += 160f;
            }
        }
Exemplo n.º 10
0
        public override void NodeGUI()
        {
            GUILayout.BeginHorizontal();
            inputLeft.DisplayLayout();
            outputAccept.DisplayLayout();
            GUILayout.EndHorizontal();
            outputDecline.DisplayLayout();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Task Name:");
            height   = 270f;
            taskName = GUILayout.TextArea(taskName, GUILayout.Width(200f));
            GUILayout.EndHorizontal();
            GUILayout.Label("Dialogue:");
            dialogueText = GUILayout.TextArea(dialogueText, GUILayout.Width(200f));
            height      += GUI.skin.textArea.CalcHeight(new GUIContent(dialogueText), 200f);
            GUILayout.Label("Dialogue Color:");
            float r, g, b;

            GUILayout.BeginHorizontal();
            r = RTEditorGUI.FloatField(dialogueColor.r);
            g = RTEditorGUI.FloatField(dialogueColor.g);
            b = RTEditorGUI.FloatField(dialogueColor.b);
            GUILayout.EndHorizontal();
            dialogueColor = new Color(r, g, b);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Accept Player Response:");
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            acceptResponse = GUILayout.TextArea(acceptResponse, GUILayout.Width(200f));
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Decline Player Response:");
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            declineResponse = GUILayout.TextArea(declineResponse, GUILayout.Width(200f));
            GUILayout.EndHorizontal();
            GUILayout.Label("Objective list:");
            objectiveList = GUILayout.TextArea(objectiveList, GUILayout.Width(200f));
            height       += GUI.skin.textArea.CalcHeight(new GUIContent(objectiveList), 200f);
            GUILayout.Label("Credit reward:");
            creditReward = RTEditorGUI.IntField(creditReward, GUILayout.Width(200f));
            GUILayout.Label("Reputation reward:");
            reputationReward = RTEditorGUI.IntField(reputationReward, GUILayout.Width(200f));
            partReward       = RTEditorGUI.Toggle(partReward, "Part reward", GUILayout.Width(200f));
            if (partReward)
            {
                height += 320f;
                GUILayout.Label("Part ID:");
                partID = GUILayout.TextField(partID, GUILayout.Width(200f));
                if (ResourceManager.Instance != null && partID != null && (GUI.changed || !init))
                {
                    init = true;
                    PartBlueprint partBlueprint = ResourceManager.GetAsset <PartBlueprint>(partID);
                    if (partBlueprint != null)
                    {
                        partTexture = ResourceManager.GetAsset <Sprite>(partBlueprint.spriteID).texture;
                    }
                    else
                    {
                        partTexture = null;
                    }
                }
                if (partTexture != null)
                {
                    GUILayout.Label(partTexture);
                    height += partTexture.height + 8f;
                }
                else
                {
                    NodeEditorGUI.nodeSkin.label.normal.textColor = Color.red;
                    GUILayout.Label("<Part not found>");
                    NodeEditorGUI.nodeSkin.label.normal.textColor = NodeEditorGUI.NE_TextColor;
                }
                partAbilityID = RTEditorGUI.IntField("Ability ID", partAbilityID, GUILayout.Width(200f));
                string abilityName = AbilityUtilities.GetAbilityNameByID(partAbilityID, null);
                if (abilityName != "Name unset")
                {
                    GUILayout.Label("Ability: " + abilityName);
                    height += 24f;
                }
                partTier = RTEditorGUI.IntField("Part tier", partTier, GUILayout.Width(200f));
                GUILayout.Label("Part Secondary Data:");
                partSecondaryData = GUILayout.TextField(partSecondaryData, GUILayout.Width(200f));
            }
            else
            {
                height += 160f;
            }
            forceTask = Utilities.RTEditorGUI.Toggle(forceTask, "Force Task Acceptance");
            height   += GUI.skin.textArea.CalcHeight(new GUIContent(dialogueText), 50f);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Entity ID for Confirmed Dialogue");
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            entityIDforConfirmedResponse = GUILayout.TextField(entityIDforConfirmedResponse);
            GUILayout.EndHorizontal();

            GUILayout.Label("Task Confirmed Dialogue:");
            taskConfirmedDialogue = GUILayout.TextArea(taskConfirmedDialogue, GUILayout.Width(200f));
            height += GUI.skin.textArea.CalcHeight(new GUIContent(taskConfirmedDialogue), 200f);
        }
Exemplo n.º 11
0
    protected ShellPart SetUpPart(EntityBlueprint.PartInfo part)
    {
        var           drone         = this as Drone;
        var           isLightDrone  = drone && drone.type == DroneType.Light; // used for light drone weight reduction
        PartBlueprint partBlueprint = ResourceManager.GetAsset <PartBlueprint>(part.partID);

        GameObject partObject = ShellPart.BuildPart(partBlueprint);
        ShellPart  shellPart  = partObject.GetComponent <ShellPart>();

        shellPart.info = part;
        partObject.transform.SetParent(transform, false);
        partObject.transform.SetAsFirstSibling();

        //Add an ability to the part:

        WeaponAbility ab = AbilityUtilities.AddAbilityToGameObjectByID(partObject, part.abilityID, part.secondaryData, part.tier) as WeaponAbility;

        if (ab)
        {
            // add weapon diversity
            ab.type = DroneUtilities.GetDiversityTypeByEntity(this);
        }

        partObject.transform.localEulerAngles = new Vector3(0, 0, part.rotation);
        partObject.transform.localPosition    = new Vector3(part.location.x, part.location.y, 0);
        SpriteRenderer sr  = partObject.GetComponent <SpriteRenderer>();
        var            tmp = partObject.transform.localScale;

        tmp.x = part.mirrored ? -1 : 1;
        partObject.transform.localScale = tmp;
        sr.sortingOrder = ++sortingOrder;
        var partWeight = isLightDrone ? partBlueprint.mass * 0.6F * weightMultiplier : partBlueprint.mass * weightMultiplier;

        weight       += partWeight;
        maxHealth[0] += partBlueprint.health / 2;
        maxHealth[1] += partBlueprint.health / 4;

        string shooterID = AbilityUtilities.GetShooterByID(part.abilityID, part.secondaryData);

        // Add shooter
        if (shooterID != null)
        {
            var shooter = new GameObject("Shooter");
            shooter.transform.SetParent(partObject.transform);
            shooter.transform.localPosition = Vector3.zero;
            shooter.transform.localRotation = Quaternion.identity;
            var shooterSprite = shooter.AddComponent <SpriteRenderer>();
            shooterSprite.sprite = ResourceManager.GetAsset <Sprite>(shooterID);
            shellPart.shooter    = shooter;
            if (AbilityUtilities.GetAbilityTypeByID(part.abilityID) == AbilityHandler.AbilityTypes.Weapons)
            {
                shellPart.weapon = true;
            }
        }

        var weaponAbility = partObject.GetComponent <WeaponAbility>();

        if (weaponAbility)
        {
            // if the terrain and category wasn't preset set to the enitity's properties

            if (weaponAbility.terrain == TerrainType.Unset)
            {
                weaponAbility.terrain = Terrain;
            }

            if (weaponAbility.category == EntityCategory.Unset)
            {
                weaponAbility.category = category;
            }
        }

        var shellRenderer = transform.Find("Shell Sprite").GetComponent <SpriteRenderer>();

        if (shellRenderer)
        {
            shellRenderer.sortingOrder = ++sortingOrder;
        }

        var coreRenderer = GetComponent <SpriteRenderer>();

        if (coreRenderer)
        {
            coreRenderer.sortingOrder = ++sortingOrder;
        }

        parts.Add(partObject.GetComponent <ShellPart>());
        if (partObject.GetComponent <Ability>())
        {
            abilities.Insert(0, partObject.GetComponent <Ability>());
        }

        // Disable collider if no sprite
        if (!(partObject.GetComponent <SpriteRenderer>() && partObject.GetComponent <SpriteRenderer>().sprite) &&
            partObject.GetComponent <Collider2D>() && !partObject.GetComponent <Harvester>())
        {
            partObject.GetComponent <Collider2D>().enabled = false;
        }

        return(partObject.GetComponent <ShellPart>());
    }
Exemplo n.º 12
0
    // Update is called once per frame
    void Update()
    {
        float[] totalHealths = CoreUpgraderScript.defaultHealths;
        float[] totalRegens  = CoreUpgraderScript.GetRegens(cursorScript?.player?.blueprint?.coreShellSpriteID);
        float   shipMass     = 1;
        float   enginePower  = 200;
        float   weight       = Entity.coreWeight;
        float   speed        = Craft.initSpeed;

        foreach (DisplayPart part in statsDatabase.GetParts())
        {
            switch (part.info.abilityID)
            {
            case 13:
                enginePower *= Mathf.Pow(1.1F, part.info.tier);
                speed       += 15 * part.info.tier;
                break;

            case 17:
                totalRegens[0] += ShellRegen.regens[0] * part.info.tier;
                break;

            case 18:
                totalHealths[0] += ShellMax.maxes[0] * part.info.tier;
                break;

            case 19:
                totalRegens[2] += ShellRegen.regens[2] * part.info.tier;
                break;

            case 20:
                totalHealths[2] += ShellMax.maxes[2] * part.info.tier;
                break;

            case 22:
                totalRegens[1] += ShellRegen.regens[1] * part.info.tier;
                break;

            case 23:
                totalHealths[1] += ShellMax.maxes[1] * part.info.tier;
                break;
            }
            PartBlueprint blueprint = ResourceManager.GetAsset <PartBlueprint>(part.info.partID);
            totalHealths[0] += blueprint.health / 2;
            totalHealths[1] += blueprint.health / 4;
            shipMass        += blueprint.mass;
            weight          += blueprint.mass * Entity.weightMultiplier;
        }

        string buildStat;

        if (statsDatabase.GetMode() == BuilderMode.Yard || statsDatabase.GetMode() == BuilderMode.Workshop)
        {
            buildStat = $"\nTOTAL BUILD VALUE: \n{statsDatabase.GetBuildValue()} CREDITS";
        }
        else
        {
            string colorTag = "<color=white>";
            if (cursorScript.buildCost > 0)
            {
                colorTag = "<color=red>";
            }
            else if (cursorScript.buildCost < 0)
            {
                colorTag = "<color=lime>";
            }

            buildStat = $"TOTAL BUILD COST: \n{colorTag}{statsDatabase.GetBuildCost()} CREDITS</color>";
        }

        string displayText = string.Join("\n", new string[]
        {
            $"SHELL: {totalHealths[0]}",
            $"CORE: {totalHealths[1]}",
            $"ENERGY: {totalHealths[2]}",
            $"SPEED: {(int)Craft.GetPhysicsSpeed(speed, weight)}",
            $"WEIGHT: {(int)weight}",
            buildStat
        });

        display.text      = displayText;
        regenDisplay.text = $"REGEN: {totalRegens[0]}\nREGEN: {totalRegens[1]}\nREGEN: {totalRegens[2]}";
    }
Exemplo n.º 13
0
    private void showTaskPrompt(NodeEditorFramework.Standard.StartTaskNode node, Entity speaker) //TODO: reward part image
    {
        if (window)
        {
            endDialogue(0, false);
        }
        CreateWindow(taskDialogueBoxPrefab, node.dialogueText, node.dialogueColor, speaker);
        DialogueViewTransitionIn(speaker);
        AudioManager.PlayClipByID("clip_select", true); // task button cannot create a noise because it launches endDialogue()
                                                        // so cover for its noise here

        // Objective list
        var objectiveList = background.transform.Find("ObjectiveList").GetComponent <Text>();

        objectiveList.text = node.objectiveList;

        background.transform.Find("Credit Reward Text").GetComponent <Text>().text =
            "Credit reward: " + node.creditReward;

        background.transform.Find("Reputation Reward Text").GetComponent <Text>().text =
            "Reputation reward: " + node.reputationReward;
        // Part reward
        if (node.partReward)
        {
            // Part image:
            PartBlueprint blueprint = ResourceManager.GetAsset <PartBlueprint>(node.partID);
            if (!blueprint)
            {
                Debug.LogWarning("Part reward of Start Task node not found!");
            }
            var partImage = background.transform.Find("Part").GetComponent <Image>();
            partImage.sprite = ResourceManager.GetAsset <Sprite>(blueprint.spriteID);
            partImage.rectTransform.sizeDelta = partImage.sprite.bounds.size * 45;
            partImage.color = Color.green;

            // Ability image:
            if (node.partAbilityID > 0)
            {
                var backgroudBox   = background.transform.Find("backgroundbox");
                var abilityIcon    = backgroudBox.Find("Ability").GetComponent <Image>();
                var tierIcon       = backgroudBox.Find("Tier").GetComponent <Image>();
                var type           = backgroudBox.Find("Type").GetComponent <Text>();
                var abilityTooltip = backgroudBox.GetComponent <AbilityButtonScript>();

                abilityIcon.sprite = AbilityUtilities.GetAbilityImageByID(node.partAbilityID, node.partSecondaryData);
                if (node.partTier >= 1)
                {
                    tierIcon.sprite = ResourceManager.GetAsset <Sprite>("AbilityTier" + Mathf.Clamp(node.partTier, 1, 3));
                }
                else
                {
                    tierIcon.enabled = false;
                }
                type.text = AbilityUtilities.GetAbilityNameByID(node.partAbilityID, null) + (node.partTier > 0 ? " " + node.partTier : "");
                string description = "";
                description += AbilityUtilities.GetAbilityNameByID(node.partAbilityID, null) + (node.partTier > 0 ? " " + node.partTier : "") + "\n";
                description += AbilityUtilities.GetDescriptionByID(node.partAbilityID, node.partTier, null);
                abilityTooltip.abilityInfo = description;
            }
            else
            {
                background.transform.Find("backgroundbox").gameObject.SetActive(false);
            }
        }
        else
        {
            background.transform.Find("Part").GetComponent <Image>().enabled = false;
            background.transform.Find("backgroundbox").gameObject.SetActive(false);
        }

        string[] answers =
        {
            node.declineResponse,
            node.acceptResponse
        };

        // create buttons
        buttons = new GameObject[answers.Length];

        for (int i = 0; i < answers.Length; i++)
        {
            //TODO: createButton()
            int index = i;
            buttons[i] = CreateButton(answers[i], () => {
                if (index == 1)
                {
                    DialogueViewTransitionOut();
                    SectorManager.instance.player.alerter.showMessage("New Task", "clip_victory");
                    endDialogue(index, false);
                }
                else
                {
                    endDialogue(index, true);
                }
            }, 24 + 24 * i);
        }
    }
Exemplo n.º 14
0
    private void Update()
    {
        if (currCraft != null)
        {
            //Shortcuts
            if (Input.GetKeyDown(KeyCode.C))
            {
                PlayerManager.instance.cam.ReturnToOrigin();
                CraftSpawnMenu.instance.SpawnCraftFromBlueprint(GetBlueprintFromCurrCraft());
                ClearCurrCraft();
            }
            if (Input.GetKeyDown(KeyCode.O))
            {
                HighlightPart(currCraft.GetOriginPart(), Color.yellow);
            }

            //Temp
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                GrabPartFromList("StructuralCube0");
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                GrabPartFromList("Engine0");
            }
            if (Input.GetKeyDown(KeyCode.Alpha0))
            {
                GrabPartFromList("ControlChip0");
            }

            //Part Actions Input
            if (canDoActions)
            {
                if (currPart != null)
                {
                    if (Input.GetMouseButtonDown(0)) //Place
                    {
                        SetCurrPart(null);
                    }
                    if (Input.GetMouseButtonDown(1))        //Remove
                    {
                        currPart.transform.SetParent(null); //So it instantly is recognised as not a part anymore
                        currPart.DestroyPartLite();
                        SetCurrPart(null, false);
                        MakeAllDisconnectedPartsGhosty(); //In case destroyed part was the origin, make sure that parts connected to new origin are non-ghosty.
                    }

                    //Rotate
                    if (Input.GetKeyDown(KeyCode.A))
                    {
                        currPart.transform.Rotate(0, -15f, 0, Space.Self);
                    }
                    if (Input.GetKeyDown(KeyCode.D))
                    {
                        currPart.transform.Rotate(0, 15f, 0, Space.Self);
                    }

                    if (Input.GetKeyDown(KeyCode.W))
                    {
                        currPart.transform.Rotate(15f, 0, 0, Space.Self);
                    }
                    if (Input.GetKeyDown(KeyCode.S))
                    {
                        currPart.transform.Rotate(-15f, 0, 0, Space.Self);
                    }

                    if (Input.GetKeyDown(KeyCode.Q))
                    {
                        currPart.transform.Rotate(0, 0, -15f, Space.Self);
                    }
                    if (Input.GetKeyDown(KeyCode.E))
                    {
                        currPart.transform.Rotate(0, 0, 15f, Space.Self);
                    }

                    if (Input.GetKeyDown(KeyCode.R))
                    {
                        currPart.transform.eulerAngles = Vector3.zero;
                    }
                }
                else if (currPart == null)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        if (Input.GetKey(KeyCode.O)) //Set Origin
                        {
                            RaycastHit h = CastRayThroughMouse();
                            if (h.collider != null && h.collider.GetComponent <PhysPart>())
                            {
                                PhysPart p = h.collider.GetComponent <PhysPart>();
                                currCraft.SetOriginPart(p);
                                HighlightPart(p, Color.yellow);

                                MakeAllDisconnectedPartsGhosty();
                            }
                        }
                        else if (Input.GetKey(KeyCode.LeftAlt)) //Clone
                        {
                            RaycastHit h = CastRayThroughMouse();
                            if (h.collider != null && h.collider.GetComponent <PhysPart>())
                            {
                                PhysPart      p  = h.collider.GetComponent <PhysPart>();
                                PartBlueprint bp = p.GetBlueprint();
                                lastObjRot = p.transform.rotation;

                                SpawnPartInHand(bp);
                            }
                        }
                        else //Pick Up
                        {
                            RaycastHit h = CastRayThroughMouse();
                            if (h.collider != null && h.collider.GetComponent <PhysPart>())
                            {
                                SetCurrPart(h.collider.GetComponent <PhysPart>());
                            }
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 15
0
    public PhysPart SpawnEditorPart(PartBlueprint bp)
    {
        PhysPart p = bp.SpawnPart(currCraft.transform.GetChild(0));

        return(MakePartEditorFriendly(p));
    }
Exemplo n.º 16
0
    /// <summary>
    /// Generate shell parts in the blueprint, change ship stats accordingly
    /// </summary>
    protected virtual void BuildEntity()
    {
        // all created entities should have blueprints!
        if (!blueprint)
        {
            Debug.LogError(this + " does not have a blueprint! EVERY constructed entity should have one!");
        }

        DestroyOldParts();

        parts.Clear();
        blueprint.shellHealth.CopyTo(maxHealth, 0);
        blueprint.baseRegen.CopyTo(regenRate, 0);

        if (blueprint)
        {
            this.dialogue = blueprint.dialogue;
        }

        AttemptAddComponents();
        var renderer = GetComponent <SpriteRenderer>();

        if (blueprint)
        { // check if it contains a blueprint (it should)
            if (blueprint.coreSpriteID == "" && blueprint.intendedType == EntityBlueprint.IntendedType.ShellCore)
            {
                Debug.Log(this + "'s blueprint does not contain a core sprite ID!");
                // check if the blueprint does not contain a core sprite ID (it should)
            }
            renderer.sprite = ResourceManager.GetAsset <Sprite>(blueprint.coreSpriteID);
        }
        else
        {
            renderer.sprite = ResourceManager.GetAsset <Sprite>("core1_light");
        }
        renderer.sortingOrder = 101;

        renderer = transform.Find("Minimap Image").GetComponent <SpriteRenderer>();
        if (category == EntityCategory.Station && !(this is Turret))
        {
            if (this as Outpost)
            {
                renderer.sprite = ResourceManager.GetAsset <Sprite>("outpost_minimap_sprite");
            }
            else if (this as Bunker)
            {
                renderer.sprite = ResourceManager.GetAsset <Sprite>("bunker_minimap_sprite");
            }
            else
            {
                renderer.sprite = ResourceManager.GetAsset <Sprite>("minimap_sprite");
            }
            renderer.transform.localScale = new Vector3(3.5F, 3.5F, 3.5F);
        }
        else
        {
            renderer.sprite = ResourceManager.GetAsset <Sprite>("minimap_sprite");
        }


        abilities = new List <Ability>();

        entityName = blueprint.entityName;
        name       = blueprint.entityName;
        GetComponent <Rigidbody2D>().mass = 1; // reset mass
        weight = this as Drone ? 25 : coreWeight;

        var isLightDrone = this as Drone && (this as Drone).type == DroneType.Light; // used for light drone weight reduction

        //For shellcores, create the tractor beam
        // Create shell parts
        if (blueprint != null)
        {
            for (int i = 0; i < blueprint.parts.Count; i++)
            {
                EntityBlueprint.PartInfo part          = blueprint.parts[i];
                PartBlueprint            partBlueprint = ResourceManager.GetAsset <PartBlueprint>(part.partID);

                GameObject partObject = ShellPart.BuildPart(partBlueprint);
                ShellPart  shellPart  = partObject.GetComponent <ShellPart>();
                shellPart.info = part;
                partObject.transform.SetParent(transform, false);
                partObject.transform.SetAsFirstSibling();

                //Add an ability to the part:

                WeaponAbility ab = AbilityUtilities.AddAbilityToGameObjectByID(partObject, part.abilityID, part.secondaryData, part.tier) as WeaponAbility;
                if (ab)  // add weapon diversity
                {
                    ab.type = DroneUtilities.GetDiversityTypeByEntity(this);
                }
                partObject.transform.localEulerAngles = new Vector3(0, 0, part.rotation);
                partObject.transform.localPosition    = new Vector3(part.location.x, part.location.y, 0);
                SpriteRenderer sr = partObject.GetComponent <SpriteRenderer>();
                // sr.flipX = part.mirrored; this doesn't work, it does not flip the collider hitbox
                var tmp = partObject.transform.localScale;
                tmp.x = part.mirrored ? -1 : 1;
                partObject.transform.localScale = tmp;
                sr.sortingOrder = i + 2;
                //entityBody.mass += (isLightDrone ? partBlueprint.mass * 0.6F : partBlueprint.mass);
                var partWeight = isLightDrone ? partBlueprint.mass * 0.6F * weightMultiplier : partBlueprint.mass * weightMultiplier;
                weight       += partWeight;
                maxHealth[0] += partBlueprint.health / 2;
                maxHealth[1] += partBlueprint.health / 4;

                // Drone shell and core health penalty
                if (this as Drone)
                {
                    maxHealth[0] /= 2;
                    maxHealth[1] /= 4;
                }

                string shooterID = AbilityUtilities.GetShooterByID(part.abilityID, part.secondaryData);
                // Add shooter
                if (shooterID != null)
                {
                    var shooter = new GameObject("Shooter");
                    shooter.transform.SetParent(partObject.transform);
                    shooter.transform.localPosition = Vector3.zero;
                    var shooterSprite = shooter.AddComponent <SpriteRenderer>();
                    shooterSprite.sprite = ResourceManager.GetAsset <Sprite>(shooterID);
                    // if(blueprint.parts.Count < 2) shooterSprite.sortingOrder = 500; TODO: Figure out what these lines do
                    // shooterSprite.sortingOrder = sr.sortingOrder + 1;
                    shooterSprite.sortingOrder = 500;
                    shellPart.shooter          = shooter;
                    if (AbilityUtilities.GetAbilityTypeByID(part.abilityID) == AbilityHandler.AbilityTypes.Weapons)
                    {
                        shellPart.weapon = true;
                    }
                }

                var weaponAbility = partObject.GetComponent <WeaponAbility>();
                if (weaponAbility)
                {
                    // if the terrain and category wasn't preset set to the enitity's properties

                    if (weaponAbility.terrain == TerrainType.Unset)
                    {
                        weaponAbility.terrain = Terrain;
                    }
                    if (weaponAbility.category == EntityCategory.Unset)
                    {
                        weaponAbility.category = category;
                    }
                }


                parts.Add(partObject.GetComponent <ShellPart>());
                if (partObject.GetComponent <Ability>())
                {
                    abilities.Insert(0, partObject.GetComponent <Ability>());
                }

                // Disable collider if no sprite
                if (!(partObject.GetComponent <SpriteRenderer>() && partObject.GetComponent <SpriteRenderer>().sprite) &&
                    partObject.GetComponent <Collider2D>() && !partObject.GetComponent <Harvester>())
                {
                    partObject.GetComponent <Collider2D>().enabled = false;
                }
            }
        }

        if (this as ShellCore)
        {
            if (!gameObject.GetComponentInChildren <MainBullet>())
            {
                MainBullet mainBullet = gameObject.AddComponent <MainBullet>();
                mainBullet.SetTier(Mathf.Min(3, 1 + CoreUpgraderScript.GetCoreTier(blueprint.coreShellSpriteID)));
                mainBullet.bulletPrefab = ResourceManager.GetAsset <GameObject>("bullet_prefab");
                mainBullet.terrain      = TerrainType.Air;
                mainBullet.SetActive(true);
                abilities.Insert(0, mainBullet);
            }
            else
            {
                MainBullet mainBullet = gameObject.GetComponentInChildren <MainBullet>();
                mainBullet.SetTier(Mathf.Min(3, 1 + CoreUpgraderScript.GetCoreTier(blueprint.coreShellSpriteID)));
                mainBullet.SetDestroyed(false);
                abilities.Insert(0, mainBullet);
            }
        }

        // unique abilities for mini and worker drones here
        if (this as Drone)
        {
            Drone drone = this as Drone;
            switch (drone.type)
            {
            case DroneType.Mini:
                var     shellObj = transform.Find("Shell Sprite").gameObject;
                Ability ab       = AbilityUtilities.AddAbilityToGameObjectByID(shellObj, 6, null, 1);
                var     shooter  = new GameObject("Shooter");
                shooter.transform.SetParent(shellObj.transform);
                shooter.transform.localPosition = Vector3.zero;
                var shooterSprite = shooter.AddComponent <SpriteRenderer>();
                shooterSprite.sprite       = ResourceManager.GetAsset <Sprite>(AbilityUtilities.GetShooterByID(6));
                shooterSprite.sortingOrder = 500;
                shellObj.GetComponent <ShellPart>().shooter = shooter;
                (ab as WeaponAbility).terrain = TerrainType.Air;
                abilities.Insert(0, ab);
                break;

            default:
                break;
            }
        }
        IsInvisible = false;

        // check to see if the entity is interactible
        if (dialogue && faction == 0)
        {
            interactible = true;
        }

        Transform shellSprite = shell.transform;

        if (shellSprite)
        {
            parts.Add(shellSprite.GetComponent <ShellPart>());
        }
        ConnectedTreeCreator();

        maxHealth.CopyTo(currentHealth, 0);
        ActivatePassives(); // activate passive abilities here to avoid race condition BS

        if (OnEntitySpawn != null)
        {
            OnEntitySpawn.Invoke(this);
        }
    }