private Ship GetRandomShip(Ship.Faction shipFaction) { if (ships.Count > 0) { int randomIndex = 0; foreach (Ship currentShip in ships.Values) { if (currentShip.faction == shipFaction) { randomIndex++; } } if (randomIndex > 0) { randomIndex = Random.Range(0, randomIndex); foreach (Ship currentShip in ships.Values) { if (currentShip.faction == shipFaction) { if (randomIndex > 0) { randomIndex--; } else { return(currentShip); } } } } } return(null); }
public float GetFactionTotalLevel(Ship.Faction faction) { float level = 0f; switch (faction) { case Ship.Faction.Ally: foreach (GameObject a in allies) { if (a == null) { continue; } var n = a.GetComponent <Character> (); level += n.Level; } break; case Ship.Faction.Neutral: foreach (GameObject a in neutrals) { if (a == null) { continue; } var n = a.GetComponent <Character> (); level += n.Level; } break; case Ship.Faction.Enemy: foreach (GameObject a in enemies) { if (a == null) { continue; } var n = a.GetComponent <Character> (); level += n.Level; } break; } return(level); }
public float GetFactionTotalHealth(Ship.Faction faction) { float health = 0f; switch (faction) { case Ship.Faction.Ally: foreach (GameObject a in allies) { if (a == null) { continue; } var n = a.GetComponent <Character> (); health += n.Health; } break; case Ship.Faction.Neutral: foreach (GameObject a in neutrals) { if (a == null) { continue; } var n = a.GetComponent <Character> (); health += n.Health; } break; case Ship.Faction.Enemy: foreach (GameObject a in enemies) { if (a == null) { continue; } var n = a.GetComponent <Character> (); health += n.Health; } break; } return(health); }
public Ship BiggestThreat(Vector3 threatPosition, Ship.Faction friendlyFaction, float startingDistance) { float closestDistance = startingDistance; Ship threatShip = null; foreach (KeyValuePair <uint, Ship> otherShip in ShipManager.main.ships) { if ((otherShip.Value.faction != friendlyFaction) && (otherShip.Value != emporer) && (otherShip.Value.isActiveAndEnabled)) { float otherShipDistance = Vector3.Distance(otherShip.Value.transform.position, threatPosition); //The biggest this variable the less dangerous the ship is otherShipDistance += otherShip.Value.pursuers * 250f; //The more pursuers the ship has the less the ship's dangerous if (otherShipDistance < closestDistance) { threatShip = otherShip.Value; closestDistance = otherShipDistance; } } } return(threatShip); }
} // The current Faction of the ship public virtual void SetupShip(Ship.Type npcType, Ship.Faction npcFaction, int identifier, float npcHealth, float npcSpeed, float npcFireRate, float npcBurstRate, float npcFireDamage, float npcFireRange, Sprite npcBullet, bool isPlayer) { SetShipType(npcType); SetShipFaction(npcFaction); SetMaxHealth(npcHealth); SetSpeed(npcSpeed); IncreaseLevel(1); HealthToMaxHealth(); shipBullet = npcBullet; fireRate = npcFireRate; fireBurstCount = npcBurstRate; fireDamage = npcFireDamage; fireRange = npcFireRange; Identifier = identifier; gameObject.tag = shipFaction.ToString(); if (isPlayer == true) { return; } InvokeRepeating("UpdateNearestEnemy", Random.Range(1.25f, 6.75f), Random.Range(1.25f, 6.75f)); }
public void SpawnRandomShip(Vector2 pos, bool isPlayer = false) { Ship.Type npcType = GetRandomShipType(); Ship.Faction npcFaction = GetRandomShipFaction(); SpawnManager.current.SpawnShip(npcType, npcFaction, pos, isPlayer); }
public void SpawnShip(Ship.Type shipType, Ship.Faction shipFaction, Vector2 position, bool isPlayer = false) { Sprite shipSprite; Sprite bulletSprite; int minHealth; int maxHealth; float engineOffset = 0f; float healthBarOffset = 0f; float shipSpeed = 0f; float fireRate = 0f; float fireDamage = 0f; float fireRange = 0f; float fireBurstCount = 1f; switch (shipType) { case Ship.Type.TraderShip: minHealth = 20; maxHealth = 50; engineOffset = 0f; healthBarOffset = 1.25f; shipSpeed = 3.25f; fireRate = 3f; fireDamage = 5f; fireBurstCount = 4f; fireRange = 20f; bulletSprite = ObjectController.current.traderShipBullet; shipSprite = ObjectController.current.traderShip; break; case Ship.Type.PrisonShip: minHealth = 50; maxHealth = 150; engineOffset = 0.25f; healthBarOffset = 1.625f; shipSpeed = 2.5f; fireRate = 3f; fireDamage = 7.5f; fireBurstCount = 5f; fireRange = 22f; bulletSprite = ObjectController.current.prisonShipBullet; shipSprite = ObjectController.current.prisonShip; break; case Ship.Type.FighterShip: minHealth = 50; maxHealth = 100; engineOffset = -0.125f; healthBarOffset = 1f; shipSpeed = 3.5f; fireRate = 2f; fireDamage = 5f; fireBurstCount = 9f; fireRange = 25f; bulletSprite = ObjectController.current.fighterShipBullet; shipSprite = ObjectController.current.fighterShip; break; case Ship.Type.AdvancedFighterShip: minHealth = 100; maxHealth = 350; engineOffset = 0.175f; healthBarOffset = 1.275f; shipSpeed = 4.75f; fireRate = 2.5f; fireDamage = 15f; fireBurstCount = 4f; fireRange = 30f; bulletSprite = ObjectController.current.advancedFighterShipBullet; shipSprite = ObjectController.current.advancedFighterShip; break; case Ship.Type.HeavyFighterShip: minHealth = 250; maxHealth = 500; engineOffset = 0.300f; healthBarOffset = 1.75f; shipSpeed = 2.325f; fireRate = 4.5f; fireDamage = 25f; fireBurstCount = 3f; fireRange = 36f; bulletSprite = ObjectController.current.heavyFighterShipBullet; shipSprite = ObjectController.current.heavyFighterShip; break; case Ship.Type.DestroyerShip: minHealth = 500; maxHealth = 1000; engineOffset = 0.500f; healthBarOffset = 2.00f; shipSpeed = 2.125f; fireRate = 4f; fireDamage = 10f; fireBurstCount = 8f; fireRange = 50f; bulletSprite = ObjectController.current.destroyerShipBullet; shipSprite = ObjectController.current.destroyerShip; break; case Ship.Type.DroneShip: minHealth = 25; maxHealth = 65; engineOffset = -0.5f; healthBarOffset = 0.75f; shipSpeed = 5f; fireRate = 2f; fireDamage = 2.5f; fireBurstCount = 12f; fireRange = 28f; bulletSprite = ObjectController.current.droneShipBullet; shipSprite = ObjectController.current.droneShip; break; default: minHealth = 50; maxHealth = 125; shipSpeed = 2.5f; fireDamage = 5f; fireRate = 2f; fireRange = 20f; bulletSprite = ObjectController.current.fighterShipBullet; shipSprite = ObjectController.current.fighterShip; break; } // Create the body and attach sprites var npc_body = Object.Instantiate(ObjectController.current.shipPrefab, GameController.current.canvas.transform); Character npc; if (isPlayer) { npc = npc_body.AddComponent <Player> (); } else { npc = npc_body.AddComponent <NPC> (); } var npc_sprite = npc_body.GetComponent <SpriteRenderer> (); npc_sprite.sprite = shipSprite; var npc_thrusters = Object.Instantiate(ObjectController.current.enginePrefab, npc_body.transform); npc_thrusters.transform.position = new Vector3(npc_body.transform.position.x, npc_body.transform.position.y - engineOffset, npc_body.transform.position.z); var npc_healthBar = Object.Instantiate(ObjectController.current.healthBarPrefab, npc_body.transform); npc_healthBar.transform.position = new Vector3(npc_body.transform.position.x, npc_body.transform.position.y + healthBarOffset, npc_body.transform.position.z); // Set up RigidBody2D and Collider var npc_rb = npc_body.AddComponent <Rigidbody2D> (); npc_rb.gravityScale = 0f; npc_rb.isKinematic = false; npc_rb.collisionDetectionMode = CollisionDetectionMode2D.Discrete; var npc_col = npc_body.AddComponent <PolygonCollider2D> (); int identifier = Random.Range(100, 999); npc.gameObject.name = shipType + "" + identifier + " [" + shipFaction + "]"; // Initial Setup npc.SetupShip(shipType, shipFaction, identifier, Random.Range(minHealth, maxHealth), shipSpeed, fireRate, fireBurstCount, fireDamage, fireRange, bulletSprite, isPlayer); npc_body.transform.position = position; // Final Setup npc_rb.mass = npc.MaxHealth; //Debug.Log ("Spawned Ship of type \'<b>" + shipType + "</b>\' and of faction \'<b>" + shipFaction + "</b>\'."); }
public void SetShipFaction(Ship.Faction newFaction) { shipFaction = newFaction; }
float GetFactionTotalLevel(Ship.Faction faction) { return(NPCManager.current.GetFactionTotalLevel(faction)); }
float GetFactionTotalHealth(Ship.Faction faction) { return(NPCManager.current.GetFactionTotalHealth(faction) / NPCManager.current.GetAllTotalHealth()); }