private void Awake()
 {
     _HandPosParticleSystem.Stop();
     _Rigidbody = GetComponent <Rigidbody>();
     if (Instance != null)
     {
         Destroy(Instance.gameObject);
     }
     Instance = this;
 }
Exemplo n.º 2
0
 // Main Bullet
 IEnumerator MainBulletsFireContinuously()
 {
     while (true)
     {
         // Create a new bullet where the mouse is
         GameObject mainBullet = Instantiate(mainBulletPrefab, transform.position, Quaternion.identity) as GameObject;
         // Set a gameSpace as the bullet's parent
         mainBullet.transform.SetParent(gameSpace);
         // Conenct to the script of the bullet
         MainBullet mainBulletScript = mainBullet.GetComponent <MainBullet>();
         // Move the bullet to the head of its gun
         mainBullet.transform.Translate(mainBulletScript.GetOffset());
         // Move the bullet in its direction until it hits something
         mainBulletScript.Move();
         // Repeat every fireRate times a seconds
         yield return(new WaitForSeconds(mainBulletScript.GetFireRate()));
     }
 }
Exemplo n.º 3
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);
        }
    }
Exemplo n.º 4
0
    public static string GetDescriptionByID(int ID, int tier, string secondaryData)
    {
        switch (ID)
        {
        case 0:
            return("Does nothing.");

        case 1:
            return($"+{SpeedThrust.boost * tier} speed for 10 seconds.");

        case 2:
            return($"Instantly heal {HealthHeal.heals[0] * tier} shell.");

        case 3:
            return($"Projectile that deals {MainBullet.GetDamage(tier)} damage. \nStays with you no matter what.");

        case 4:
            return($"Instant attack that deals {Beam.beamDamage * tier} damage.");

        case 5:
            return($"Projectile that deals {Bullet.bulletDamage * tier} damage.");

        case 6:
            return($"Instant attack that deals {Cannon.cannonDamage * tier} damage.");

        case 7:
            return($"Slow homing projectile that deals {Missile.missileDamage * tier} damage.");

        case 8:
            return($"Slow projectile that deals {Torpedo.torpedoDamage * tier} damage to ground entities.");

        case 9:
            return($"Fast projectile that deals {Laser.laserDamage * tier} damage. 25% pierces to core.");

        case 10:
            if (string.IsNullOrEmpty(secondaryData))
            {
                return("Spawns a drone.");
            }

            DroneSpawnData data = DroneUtilities.GetDroneSpawnDataByShorthand(secondaryData);
            return(DroneUtilities.GetDescriptionByType(data.type));

        case 11:
            return($"Instantly heal {HealthHeal.heals[1] * tier} core.");

        case 12:
            return($"Instantly heal {HealthHeal.heals[2] * tier} energy.");

        case 13:
            return($"+{Speed.boost * tier} speed.");

        case 17:
            return($"Passively increases shell regen by {ShellRegen.regens[0] * tier} points.");

        case 18:
            return($"Passively increases maximum shell by {ShellMax.maxes[0] * tier} points.");

        case 19:
            return($"Passively increases energy regen by {ShellRegen.regens[2] * tier} points.");

        case 20:
            return($"Passively increases maximum energy by {ShellMax.maxes[2] * tier} points.");

        case 21:
            return($"Passively increases the maximum allowed number of controlled units by {Command.commandUnitIncrease}.");

        case 22:
            return($"Passively increases core regen by {ShellRegen.regens[1] * tier} points.");

        case 23:
            return($"Passively increases maximum core by {ShellMax.maxes[1] * tier} points.");

        case 24:
            return("Become invisible to enemies.");

        case 25:
            return($"All weapon damage increased by {DamageBoost.damageAddition * Mathf.Max(1, tier)}.");

        case 26:
            return($"Instantly heals self and nearby allies by {AreaRestore.heal * Mathf.Max(1, tier)} shell");

        case 27:
            return("Immobilizes the target.");

        case 28:
            return("Respawn at base.");

        case 29:
            return("Absorb damage and turn it into energy.");

        case 30:
            return($"Temporarily increase shell regen by { ActiveRegen.healAmounts[0] } per second.");

        case 31:
            return("Temporarily increase core... wait, this isn't supposed to exist!");

        case 32:
            return($"Temporarily increase energy regen by { ActiveRegen.healAmounts[2] } per second.");

        case 33:
            return("Disrupt enemy ability cooldowns.");

        case 34:
            return($"Gives allies additional {Control.baseControlFractionBoost * 100}% shell and {Control.damageAddition} weapon damage.");

        case 35:
            return("Temporarily pulls you to your tractor target and allows you to tractor most entities.");

        case 36:
            return($"Stationary projectile that deals {Bomb.bombDamage} damage. \nProjectile lasts {45F * tier} seconds.");

        case 37:
            return($"Slow moving beam that deals {IonLineController.damageC * tier} damage per second for 5 seconds. "
                   + $"\nBeam costs {IonLineController.energyC * tier} energy per second.");

        case 38:
            return($"Fires at most 5 projectiles at different targets that each deal {Flak.bulletDamage * tier} damage.");

        default:
            return("Description unset");
        }
    }
Exemplo n.º 5
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);
        }
    }
Exemplo n.º 6
0
    public static string GetDescriptionByID(int ID, int tier, string secondaryData)
    {
        switch (ID)
        {
        case 0:
            return("Does nothing.");

        case 1:
            return("+" + SpeedThrust.boost * tier + " speed for 10 seconds.");

        case 2:
            return("Instantly heal " + HealthHeal.heals[0] * tier + " shell.");

        case 3:
            return("Projectile that deals " + MainBullet.GetDamage(tier) + " damage. \nStays with you no matter what.");

        case 4:
            return("Instant attack that deals " + Beam.beamDamage * tier + " damage.");

        case 5:
            return("Projectile that deals " + Bullet.bulletDamage * tier + " damage.");

        case 6:
            return("Instant attack that deals " + Cannon.cannonDamage * tier + " damage.");

        case 7:
            return("Slow homing projectile that deals " + Missile.missileDamage * tier + " damage.");

        case 8:
            return("Slow projectile that deals " + Torpedo.torpedoDamage * tier + " damage to ground entities.");

        case 9:
            return("Fast projectile that deals " + Laser.laserDamage * tier + " damage. 25% pierces to core.");

        case 10:
            if (secondaryData == null || secondaryData == "")
            {
                return("Spawns a drone.");
            }
            DroneSpawnData data = DroneUtilities.GetDroneSpawnDataByShorthand(secondaryData);
            return(DroneUtilities.GetDescriptionByType(data.type));

        case 11:
            return("Instantly heal " + HealthHeal.heals[1] * tier + " core.");

        case 12:
            return("Instantly heal " + HealthHeal.heals[2] * tier + " energy.");

        case 13:
            return("+" + Speed.boost * tier + " speed.");

        case 17:
            return("Passively increases shell regen by " + ShellRegen.regen * tier + " points.");

        case 18:
            return("Passively increases maximum shell by " + ShellMax.max * tier + " points.");

        case 19:
            return("Passively increases energy regen by " + ShellRegen.regen * tier + " points.");

        case 20:
            return("Passively increases maximum energy by " + ShellMax.max * tier + " points.");

        case 21:
            return("Passively increases the maximum allowed number of controlled units by " + Command.commandUnitIncrease + ".");

        case 24:
            return("Become invisible to enemies.");

        case 25:
            return("All weapon damage increased by 150.");

        case 26:
            return("Instantly heals self and nearby allies by +500 shell and +500 core.");

        case 27:
            return("Immobilizes the target.");

        case 28:
            return("Respawn at base.");

        case 29:
            return("Absorb damage and turn it into energy.");

        case 30:
            return("Temporarily increase shell regen.");

        case 31:
            return("Temporarily increase core... wait, this isn't supposed to exist!");

        case 32:
            return("Temporarily increase energy regen.");

        case 33:
            return("Disrupt enemy ability cooldowns.");

        case 34:
            return("Makes allies stronger.");

        case 35:
            return("Temporarily pulls you to your tractor target.");

        case 36:
            return($"Stationary projectile that deals {Bomb.bombDamage} damage. \nProjectile lasts {45F * tier} seconds.");

        case 37:
            return($"Slow moving beam that deals {IonLineController.damageC} damage per second for 5 seconds. \nBeam costs {IonLineController.energyC} energy per");

        default:
            return("Description unset");
        }
    }