void DrawSlots(int type)
    {
        DestroySlots(type);
        int extras = CoreUpgraderScript.GetExtraAbilities(coreID)[type];

        for (int i = 0; i < extras; i++)
        {
            var slot = Instantiate(slotPrefab, slotHolders[type], false);
            slot.transform.SetSiblingIndex(i + 1);
            slot.GetComponent <RectTransform>().anchoredPosition = new Vector2(-840 + 40 * i, 0);
            slot.GetComponent <Image>().color = Color.yellow;
        }

        for (int i = extras; i < CoreUpgraderScript.maxAbilityCap[type] + extras; i++)
        {
            var slot = Instantiate(slotPrefab, slotHolders[type], false);
            slot.transform.SetSiblingIndex(i + 1);
            slot.GetComponent <RectTransform>().anchoredPosition = new Vector2(-840 + 40 * i, 0);
        }

        var text = slotHolders[type].GetComponentInChildren <Text>();

        text.text = $"{(AbilityHandler.AbilityTypes)type}: {(caps[type] + extras)}";
        for (int i = extras + 1; i < CoreUpgraderScript.maxAbilityCap[type] + extras + 1; i++)
        {
            slotHolders[type].GetChild(i).GetComponent <Image>().color = Color.green;
        }
    }
Beispiel #2
0
    private bool CheckAbilityCaps()
    {
        if (editorMode)
        {
            return(true);
        }
        var currentAbilitynumbers = new int[] { 0, 0, 0, 0, 0 };

        foreach (ShipBuilderPart shipBuilderPart in cursorScript.parts)
        {
            var type = (int)AbilityUtilities.GetAbilityTypeByID(shipBuilderPart.info.abilityID);
            currentAbilitynumbers[type]++;
        }

        var extras = CoreUpgraderScript.GetExtraAbilities(player.blueprint.coreShellSpriteID);

        for (int i = 0; i < 4; i++)
        {
            if (currentAbilitynumbers[i] > abilityLimits[i] + extras[i])
            {
                SetReconstructButton((ReconstructButtonStatus)(3 + i));
                return(false);
            }
        }
        return(true);
    }
Beispiel #3
0
    private void LateUpdate()
    {
        if (initialized)
        {
            if (eventSystem && !eventSystem.IsPointerOverGameObject())
            {
                if (Input.GetAxis("Mouse ScrollWheel") < 0f)
                {
                    zLevel = Mathf.Min(10 + 2.5F * (1 +
                                                    CoreUpgraderScript.GetCoreTier(PlayerCore.Instance.blueprint.coreShellSpriteID)), zLevel + 0.5F);
                    Focus(transform.position);
                }
                else if (Input.GetAxis("Mouse ScrollWheel") > 0f)
                {
                    zLevel = Mathf.Max(5, zLevel - 0.5F);
                    Focus(transform.position);
                }
            }

            if (panning)
            {
                Pan();
            }
            else if (core.IsMoving()) // lock camera
            {
                Focus(core.transform.position);
            }
            ProximityInteractScript.Focus();
        }
    }
Beispiel #4
0
    public static PlayerSave CreateSave(string name, string checkpointName = null, string resourcePath = "")
    {
        string     currentVersion = VersionNumberScript.version;
        PlayerSave save           = new PlayerSave();

        save.name             = name;
        save.timePlayed       = 0;
        save.presetBlueprints = new string[5];
        save.currentHealths   = new float[] { 1000, 250, 500 };
        save.partInventory    = new List <EntityBlueprint.PartInfo>();
        save.sectorsSeen      = new List <string>();
        save.missions         = new List <Mission>();

        // this section contains default information for a new save. Edit this to change how the default save
        // is created.
        EntityBlueprint blueprint = ScriptableObject.CreateInstance <EntityBlueprint>();

        blueprint.name              = "Player Save Blueprint";
        blueprint.parts             = new List <EntityBlueprint.PartInfo>();
        blueprint.coreSpriteID      = "core1_light";
        blueprint.coreShellSpriteID = "core1_shell";
        blueprint.baseRegen         = CoreUpgraderScript.GetRegens(blueprint.coreShellSpriteID);
        blueprint.shellHealth       = CoreUpgraderScript.defaultHealths;
        save.currentPlayerBlueprint = JsonUtility.ToJson(blueprint);
        save.abilityCaps            = CoreUpgraderScript.minAbilityCap;
        save.shards         = 0;
        save.version        = currentVersion;
        save.resourcePath   = resourcePath;
        save.abilityHotkeys = new AbilityHotkeyStruct();
        File.WriteAllText(Application.persistentDataPath + "\\Saves" + "\\" + name, JsonUtility.ToJson(save));
        return(save);
    }
Beispiel #5
0
    protected override void BuildEntity()
    {
        intrinsicCommandLimit = 0;
        if (!tractor.initialized)
        {
            tractor.BuildTractor();
            switch (CoreUpgraderScript.GetCoreTier(blueprint.coreShellSpriteID))
            {
            case 0:
                tractor.maxRangeSquared          = 225;
                tractor.energyPickupRangeSquared = 160;
                tractor.maxBreakRangeSquared     = 600;
                break;

            case 1:
                tractor.maxRangeSquared          = 325;
                tractor.energyPickupRangeSquared = 240;
                tractor.maxBreakRangeSquared     = 900;
                break;

            case 2:
                tractor.maxRangeSquared          = 450;
                tractor.energyPickupRangeSquared = 320;
                tractor.maxBreakRangeSquared     = 1200;
                break;

            case 3:
                tractor.maxRangeSquared          = 550;
                tractor.energyPickupRangeSquared = 400;
                tractor.maxBreakRangeSquared     = 1500;
                break;
            }
        }
        base.BuildEntity();
    }
Beispiel #6
0
 // returns max zoom level based on player core tier
 public static float GetMaxZoomLevel()
 {
     if (!PlayerCore.Instance)
     {
         return(10);
     }
     return(10 + 2.5F * (1 +
                         CoreUpgraderScript.GetCoreTier(PlayerCore.Instance.blueprint.coreShellSpriteID)));
 }
Beispiel #7
0
    public void initialize()
    {
        instance = this;
        player.SetIsInteracting(true);

        Activate();
        gameObject.SetActive(true);
        drawScreen();
        // TODO: Fix the shard count script
        ShardCountScript.StickySlideIn(player.shards);
    }
Beispiel #8
0
    private bool CheckPartSizes()
    {
        int maxTier = !editorMode && !heavyCheat?CoreUpgraderScript.GetPartTierLimit(player.blueprint.coreShellSpriteID) : 3;

        foreach (ShipBuilderPart shipPart in cursorScript.parts)
        {
            if (ResourceManager.GetAsset <PartBlueprint>(shipPart.info.partID).size > maxTier)
            {
                SetReconstructButton(ReconstructButtonStatus.PartTooHeavy);
                return(false);
            }
        }
        return(true);
    }
Beispiel #9
0
 public void OnPointerClick(PointerEventData eventData)
 {
     if (player.reputation >= repCost)
     {
         player.blueprint.coreShellSpriteID = coreID;
         player.blueprint.baseRegen         = CoreUpgraderScript.GetRegens(coreID);
         player.Rebuild();
         CoreUpgraderScript.DrawScreen();
         NodeEditorFramework.Standard.UpgradeCoreCondition.OnCoreUpgrade.Invoke();
     }
     else
     {
         Debug.Log("Not enough reputation!" + player.reputation + " " + repCost);
     }
 }
Beispiel #10
0
    public void OnPointerEnter(PointerEventData eventData)
    {
        tooltip = Instantiate(tooltipPrefab);
        tooltip.GetComponent <Image>().color = Color.grey;
        RectTransform rect = tooltip.GetComponent <RectTransform>();

        rect.position = eventData.position;
        rect.SetParent(transform.parent, true);
        rect.SetAsLastSibling();

        Text text = tooltip.transform.Find("Text").GetComponent <Text>();

        text.text = CoreUpgraderScript.GetDescription(coreID);

        rect.sizeDelta = new Vector2(text.preferredWidth + 16f, text.preferredHeight + 16);
    }
    private void initialize(int[] caps, string coreID)
    {
        this.caps   = caps;
        this.coreID = coreID;

        for (int i = 0; i < 4; i++)
        {
            DrawSlots(i);
            var x      = i;
            var button = slotHolders[i].GetChild(0).GetComponent <Button>();
            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() => {
                if (CoreUpgraderScript.GetUpgradeCost(x) <= CoreUpgraderScript.GetShards())
                {
                    CoreUpgraderScript.IncrementAbilityCap(x);
                }
                DrawSlots(x);
            });
        }
    }
Beispiel #12
0
 public void UpdateButtonCost(bool mouseOver)
 {
     if (CoreUpgraderScript.maxAbilityCap[type] > CoreUpgraderScript.instance.player.abilityCaps[type])
     {
         if (mouseOver)
         {
             text.text  = $"{CoreUpgraderScript.GetUpgradeCost(type)} Shards";
             text.color = CoreUpgraderScript.GetUpgradeCost(type) - CoreUpgraderScript.GetShards() <= 0 ? Color.green : Color.red;
         }
         else
         {
             text.text  = "Upgrade";
             text.color = Color.white;
         }
     }
     else
     {
         text.text  = "MAX";
         text.color = Color.yellow;
     }
 }
Beispiel #13
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);
        }
    }
Beispiel #14
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]}";
    }
Beispiel #15
0
    public void Initialize()
    {
        string currentPath;

        if (!File.Exists(Application.persistentDataPath + "\\CurrentSavePath"))
        {
            currentPath = Application.persistentDataPath + "\\TestSave";
        }
        else
        {
            currentPath = File.ReadAllLines(Application.persistentDataPath + "\\CurrentSavePath")[0];
        }

        if (File.Exists(currentPath))
        {
            // Load
            string json = File.ReadAllText(currentPath);
            save = JsonUtility.FromJson <PlayerSave>(json);
            if (save.timePlayed != 0)
            {
                player.spawnPoint = save.position;
            }

            if (SectorManager.testJsonPath != null)
            {
                save.resourcePath = SectorManager.testJsonPath;
            }
            else if (save.resourcePath == "")
            {
                save.resourcePath = SectorManager.jsonPath;
            }
            player.cursave = save;

            SectorManager.instance.LoadSectorFile(save.resourcePath);
            taskManager.Initialize(true);             // Re-init
            DialogueSystem.InitCanvases();

            player.blueprint      = ScriptableObject.CreateInstance <EntityBlueprint>();
            player.blueprint.name = "Player Save Blueprint";
            if (save.currentPlayerBlueprint != null && save.currentPlayerBlueprint != "")
            {
                JsonUtility.FromJsonOverwrite(save.currentPlayerBlueprint, player.blueprint);
            }
            else
            {
                Debug.LogError("Save should have been given a currentPlayerBlueprint by now.");
                player.blueprint.parts             = new List <EntityBlueprint.PartInfo>();
                player.blueprint.coreSpriteID      = "core1_light";
                player.blueprint.coreShellSpriteID = "core1_shell";
                player.blueprint.baseRegen         = CoreUpgraderScript.GetRegens(player.blueprint.coreShellSpriteID);
                player.blueprint.shellHealth       = CoreUpgraderScript.defaultHealths;
            }
            player.abilityCaps = save.abilityCaps;
            player.shards      = save.shards;
            player.SetCredits(save.credits);
            player.reputation = save.reputation;
            if (save.presetBlueprints.Length != 5)
            {
                save.presetBlueprints = new string[5];
            }
            Camera.main.GetComponent <CameraScript>().Initialize(player);

            taskManager.taskVariables.Clear();
            for (int i = 0; i < save.taskVariableNames.Length; i++)
            {
                taskManager.taskVariables.Add(save.taskVariableNames[i], save.taskVariableValues[i]);
            }
        }
        else
        {
            Debug.LogError("There was not a save or test save that was ready on load.");
            save = new PlayerSave();
            save.presetBlueprints = new string[5];
            save.currentHealths   = new float[] { 1000, 250, 500 };
            save.partInventory    = new List <EntityBlueprint.PartInfo>();

            player.blueprint                   = ScriptableObject.CreateInstance <EntityBlueprint>();
            player.blueprint.name              = "Player Save Blueprint";
            player.blueprint.coreSpriteID      = "core1_light";
            player.blueprint.coreShellSpriteID = "core1_shell";
            player.blueprint.baseRegen         = CoreUpgraderScript.GetRegens(player.blueprint.coreShellSpriteID);
            player.blueprint.shellHealth       = CoreUpgraderScript.defaultHealths;
            player.blueprint.parts             = new List <EntityBlueprint.PartInfo>();
            player.cursave     = save;
            player.abilityCaps = CoreUpgraderScript.minAbilityCap;
        }
    }
Beispiel #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();

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

        AttemptAddComponents();
        var coreRenderer = 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)
            }

            coreRenderer.sprite = ResourceManager.GetAsset <Sprite>(blueprint.coreSpriteID);
        }
        else
        {
            coreRenderer.sprite = ResourceManager.GetAsset <Sprite>("core1_light");
        }

        var 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

        var drone = this as Drone;

        ResetWeight();

        sortingOrder = 1;
        //For shellcores, create the tractor beam
        // Create shell parts
        SetUpParts(blueprint);

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

        maxHealth.CopyTo(baseMaxHealth, 0);

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

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

        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 (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 = ++sortingOrder;
                shellObj.GetComponent <ShellPart>().shooter = shooter;
                shellObj.GetComponent <ShellPart>().weapon  = ab as WeaponAbility;
                (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 && FactionManager.IsAllied(0, faction))
        {
            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);
        }
    }
    // 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];
    }
Beispiel #18
0
    public void Initialize()
    {
        instance = this;
        string currentPath;
        var    CurrentSavePath = System.IO.Path.Combine(Application.persistentDataPath, "CurrentSavePath");

        if (!File.Exists(CurrentSavePath))
        {
            currentPath = System.IO.Path.Combine(Application.persistentDataPath, "TestSave");
        }
        else
        {
            currentPath = File.ReadAllLines(CurrentSavePath)[0];
        }

        if (File.Exists(currentPath))
        {
            // Load
            string json = File.ReadAllText(currentPath);
            save = JsonUtility.FromJson <PlayerSave>(json);
            if (save.timePlayed != 0)
            {
                player.spawnPoint = save.position;
                player.Dimension  = save.lastDimension;
            }

            if (SectorManager.testJsonPath != null)
            {
                save.resourcePath = SectorManager.testJsonPath;
            }
            else if (save.resourcePath == "")
            {
                save.resourcePath = SectorManager.jsonPath;
            }

            player.cursave = save;

            if (save.factions != null)
            {
                for (int i = 0; i < save.factions.Length; i++)
                {
                    FactionManager.SetFactionRelations(save.factions[i], save.relations[i]);
                }
            }

            SectorManager.instance.LoadSectorFile(save.resourcePath);
            save.missions.RemoveAll(m => !taskManager.questCanvasPaths.Exists(p =>
                                                                              System.IO.Path.GetFileNameWithoutExtension(p) == m.name));
            taskManager.Initialize(true); // Re-init
            DialogueSystem.InitCanvases();


            player.blueprint      = ScriptableObject.CreateInstance <EntityBlueprint>();
            player.blueprint.name = "Player Save Blueprint";
            if (!string.IsNullOrEmpty(save.currentPlayerBlueprint))
            {
                var print = SectorManager.TryGettingEntityBlueprint(save.currentPlayerBlueprint);
                player.blueprint = print;
            }
            else
            {
                Debug.LogError("Save should have been given a currentPlayerBlueprint by now.");
                player.blueprint.parts             = new List <EntityBlueprint.PartInfo>();
                player.blueprint.coreSpriteID      = "core1_light";
                player.blueprint.coreShellSpriteID = "core1_shell";
                player.blueprint.baseRegen         = CoreUpgraderScript.GetRegens(player.blueprint.coreShellSpriteID);
                player.blueprint.shellHealth       = CoreUpgraderScript.defaultHealths;
            }

            player.abilityCaps = save.abilityCaps;
            player.shards      = save.shards;
            player.SetCredits(save.credits);
            player.reputation = save.reputation;
            if (save.presetBlueprints.Length != 5)
            {
                save.presetBlueprints = new string[5];
            }

            Camera.main.GetComponent <CameraScript>().Initialize(player);

            taskManager.taskVariables.Clear();
            for (int i = 0; i < save.taskVariableNames.Length; i++)
            {
                taskManager.taskVariables.Add(save.taskVariableNames[i], save.taskVariableValues[i]);
            }
        }
        else
        {
            Debug.LogError("There was not a save or test save that was ready on load.");
            save = new PlayerSave();
            save.presetBlueprints = new string[5];
            save.currentHealths   = new float[] { 1000, 250, 500 };
            save.partInventory    = new List <EntityBlueprint.PartInfo>();

            player.blueprint                   = ScriptableObject.CreateInstance <EntityBlueprint>();
            player.blueprint.name              = "Player Save Blueprint";
            player.blueprint.coreSpriteID      = "core1_light";
            player.blueprint.coreShellSpriteID = "core1_shell";
            player.blueprint.baseRegen         = CoreUpgraderScript.GetRegens(player.blueprint.coreShellSpriteID);
            player.blueprint.shellHealth       = CoreUpgraderScript.defaultHealths;
            player.blueprint.parts             = new List <EntityBlueprint.PartInfo>();
            player.cursave     = save;
            player.abilityCaps = CoreUpgraderScript.minAbilityCap;
        }
    }