void Start() { agent = GetComponent <NavMeshAgent>(); anim = GetComponent <Animator>(); health = GetComponent <HealthObject>(); Billboard stats = Instantiate(statsPrefab, transform.position, Quaternion.identity).GetComponent <Billboard>(); health.healthSlider = stats.GetComponent <Slider>(); health.speedText = stats.transform.Find("Speed").GetComponent <Text>(); health.defenseText = stats.transform.Find("Defense").GetComponent <Text>(); health.strengthText = stats.transform.Find("Strength").GetComponent <Text>(); stats.target = transform; stats.transform.SetParent(canvasParent, false); health.toDestroy.Add(stats.gameObject); health.strengthMultiplier = strengthMultipler; health.speedMultiplier = speedMultiplier; health.defenseMultiplier = defenseMultipler; health.strength = baseDamage * strengthMultipler; health.speed = baseSpeed * speedMultiplier; health.defense = baseProtection * defenseMultipler; agent.speed = health.speed; }
public void SetHealthState(HealthObject.HealthState health) { foreach (HealthObject o in this.healthObjects) { if (o.healthState == health) { this.Health = o; this.lastDead = Time.time; return; } } }
void OnTriggerEnter(Collider col) { if (col.CompareTag("Player")) { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } else { HealthObject health = col.GetComponent <HealthObject>(); if (health != null) { health.LoseHealth(health.maxHealth); } } }
public void Initialize(int combatLevel) { m_Random = new System.Random(); m_HealthObject = GetComponent <HealthObject>(); CombatLevel = combatLevel; m_BaseStats = new Dictionary <StatBonus, int> { { StatBonus.Attack, combatLevel * 1 }, { StatBonus.Strength, combatLevel * 1 }, { StatBonus.Defence, combatLevel * 1 }, { StatBonus.Agility, combatLevel * 1 } }; Damage = new Stat(); Defence = new Stat(); UpdateStats(); }
void Update() { //initialize bord if data had recevied if (!bordInitialized) { foreach (Vector3 vec in walles) { Instantiate(wall, vec, initializingRotation); } foreach (Vector3 vec in stones) { Instantiate(stone, vec, initializingRotation); } foreach (Vector3 vec in waters) { Instantiate(water, vec, initializingRotation); } bordInitialized = true; } while (coinsToDraw.Count > 0) { CoinObject c = coinsToDraw[0]; coinsToDraw.RemoveAt(0); GameObject game = Instantiate(coin, c.getPosition(), initializingRotation) as GameObject; //Send data to coin. So that it can work independently later game.SendMessage("setValues", new int[] { c.getTimeLeft(), c.getCoinValue() }); UnityEngine.Debug.logger.Log("Coin " + c.getX() + "," + c.getY() + " " + c.getCoinValue() + " time" + c.getTimeLeft()); } while (healthToDraw.Count > 0) { HealthObject c = healthToDraw[0]; healthToDraw.RemoveAt(0); GameObject game = Instantiate(health, c.getPosition(), initializingRotation) as GameObject; //Send data to coin. So that it can work independently later game.SendMessage("setValues", c.getTimeLeft()); UnityEngine.Debug.logger.Log("Health " + c.getX() + "," + c.getY() + " time" + c.getTimeLeft()); } }
private void Game_OnGameUpdate(EventArgs args) { if (!IsActive() || lastGameUpdateTime + new Random().Next(500, 1000) > Environment.TickCount) return; lastGameUpdateTime = Environment.TickCount; if (HealthTimer.GetActive()) { HealthObject healthDestroyed = null; foreach (HealthObject health in Healths) { if (health.Obj.IsValid) { if (health.Obj.Health > 0) { health.Locked = false; health.NextRespawnTime = 0; health.Called = false; } else if (health.Obj.Health < 1 && health.Locked == false) { health.Locked = true; health.NextRespawnTime = health.RespawnTime + (int)Game.ClockTime; } } if (health.NextRespawnTime < (int)Game.ClockTime && health.Locked) { healthDestroyed = health; } } if (healthDestroyed != null) { healthDestroyed.TextMinimap.Dispose(); healthDestroyed.TextMinimap.Remove(); healthDestroyed.TextMap.Dispose(); healthDestroyed.TextMap.Remove(); Healths.Remove(healthDestroyed); } foreach (Obj_AI_Minion health in ObjectManager.Get<Obj_AI_Minion>()) { HealthObject nHealth = null; if (health.Name.Contains("Health")) { HealthObject health1 = Healths.Find(jm => jm.Obj.NetworkId == health.NetworkId); if (health1 == null) nHealth = new HealthObject(health); } if (nHealth != null) Healths.Add(nHealth); } } ///// if (HealthTimer.GetActive()) { foreach (HealthObject health in Healths) { if (health.Locked) { if (health.NextRespawnTime - (int)Game.ClockTime <= 0 || health.MapType != GMap.Type) continue; int time = Timer.Timers.GetMenuItem("SAssembliesTimersRemindTime").GetValue<Slider>().Value; if (!health.Called && health.NextRespawnTime - (int)Game.ClockTime <= time && health.NextRespawnTime - (int)Game.ClockTime >= time - 1) { health.Called = true; Timer.PingAndCall("Heal respawns in " + time + " seconds!", health.Position); if (HealthTimer.GetMenuItem("SAssembliesTimersHealthSpeech").GetValue<bool>()) { Speech.Speak("Heal respawns in " + time + " seconds!"); } } } } } }
void listen() { try { //UnityEngine.Debug.logger.Log("Thread started"); // Create the listener providing the IP Address and the port to listen on. var listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 7000); listener.Start(); // Listen in an endless loop. while (true) { // We will store the textual representation of the bytes we receive. string value; // Accept the sender and take message as a stream. using (var networkStream = listener.AcceptTcpClient().GetStream()) { // Create a memory stream to copy the message. var bytes = new System.Collections.Generic.List <byte>(); int asw = 0; while (asw != -1) { asw = networkStream.ReadByte(); bytes.Add((Byte)asw); } // Convert bytes to text. value = Encoding.UTF8.GetString(bytes.ToArray()); } String[] datas = value.Split(':'); UnityEngine.Debug.logger.Log(datas[0] + " " + value); if (datas[0].Equals("I")) { String walls = datas[2]; walles = getVecotors(walls); String stone = datas[3]; stones = getVecotors(stone); String water = datas[4].Trim(); //At the end String there are unwanter characters. one is # and other is a unicode water = water.Substring(0, water.Length - 2); waters = getVecotors(water); bordInitialized = false; } else if (datas[0].ToUpper().Equals("C")) { String[] cod = datas[1].Split(','); Vector3 coinPosition = new Vector3(Int32.Parse(cod[0]), -Int32.Parse(cod[1])); int coinCountTime = Int32.Parse(datas[2]); datas[3] = datas[3].Trim(); datas[3] = datas[3].Substring(0, datas[3].Length - 2); int coinValue = Int32.Parse(datas[3]); CoinObject o = new CoinObject(coinPosition, coinValue, coinCountTime); coinsToDraw.Add(o); //UnityEngine.Debug.logger.Log("Coin " + coinPosition.x+","+coinPosition.y+" "+coinValue+" time"+coinCountTime); } else if (datas[0].ToUpper().Equals("L")) { String[] cod = datas[1].Split(','); Vector3 healthPosition = new Vector3(Int32.Parse(cod[0]), -Int32.Parse(cod[1])); datas[2] = datas[2].Trim(); datas[2] = datas[2].Substring(0, datas[2].Length - 2); int healthCountTime = Int32.Parse(datas[2]); HealthObject he = new HealthObject(healthPosition, healthCountTime); healthToDraw.Add(he); //UnityEngine.Debug.logger.Log("Health " + healthPosition.x + "," + healthPosition.y + " " + healthCountTime); } // Call an external function (void) given. //else if (datas[0].ToUpper().Equals("P")) //{ //Debug.logger.Log(datas.ToString()); // Tank Status Update [Pn;x,y;d;shot;health;coins;points] /*var state = d.Split(';'); * var currentTank = tanks[int.Parse(state[0].Substring(1))]; * currentTank.x = int.Parse(state[1].Split(',')[0]); * currentTank.y = int.Parse(state[1].Split(',')[1]); * currentTank.direction = (Direction)int.Parse(state[2]); * currentTank.isShot = int.Parse(state[3]) == 1; * currentTank.health = int.Parse(state[4]); * currentTank.coins = int.Parse(state[5]); * currentTank.points = int.Parse(state[6]);*/ //} } } catch (Exception ex) { Console.WriteLine("Exception occured"); } }
private void Game_OnGameUpdate(EventArgs args) { if (!IsActive() || lastGameUpdateTime + new Random().Next(500, 1000) > Environment.TickCount) { return; } lastGameUpdateTime = Environment.TickCount; if (HealthTimer.GetActive()) { HealthObject healthDestroyed = null; foreach (HealthObject health in Healths) { if (health.Obj.IsValid) { if (health.Obj.Health > 0) { health.Locked = false; health.NextRespawnTime = 0; health.Called = false; } else if (health.Obj.Health < 1 && health.Locked == false) { health.Locked = true; health.NextRespawnTime = health.RespawnTime + (int)Game.ClockTime; } } if (health.NextRespawnTime < (int)Game.ClockTime && health.Locked) { healthDestroyed = health; } } if (healthDestroyed != null) { healthDestroyed.TextMinimap.Dispose(); healthDestroyed.TextMinimap.Remove(); healthDestroyed.TextMap.Dispose(); healthDestroyed.TextMap.Remove(); Healths.Remove(healthDestroyed); } foreach (Obj_AI_Minion health in ObjectManager.Get <Obj_AI_Minion>()) { HealthObject nHealth = null; if (health.Name.Contains("Health")) { HealthObject health1 = Healths.Find(jm => jm.Obj.NetworkId == health.NetworkId); if (health1 == null) { nHealth = new HealthObject(health); } } if (nHealth != null) { Healths.Add(nHealth); } } } ///// if (HealthTimer.GetActive()) { foreach (HealthObject health in Healths) { if (health.Locked) { if (health.NextRespawnTime - (int)Game.ClockTime <= 0 || health.MapType != GMap.Type) { continue; } int time = Timer.Timers.GetMenuItem("SAssembliesTimersRemindTime").GetValue <Slider>().Value; if (!health.Called && health.NextRespawnTime - (int)Game.ClockTime <= time && health.NextRespawnTime - (int)Game.ClockTime >= time - 1) { health.Called = true; Timer.PingAndCall("Heal respawns in " + time + " seconds!", health.Position); if (HealthTimer.GetMenuItem("SAssembliesTimersHealthSpeech").GetValue <bool>()) { Speech.Speak("Heal respawns in " + time + " seconds!"); } } } } } }
void Update() { if (!bordcreated) { foreach (Vector3 vec in wallList) { Instantiate(wall, vec, initializingRotation); } foreach (Vector3 vec in stoneList) { Instantiate(stone, vec, initializingRotation); } foreach (Vector3 vec in waterList) { Instantiate(water, vec, initializingRotation); } bordcreated = true; } while (coinsToDraw.Count > 0) { CoinObject c = coinsToDraw[0]; coinsToDraw.RemoveAt(0); GameObject game = Instantiate(coin, c.getPosition(), initializingRotation) as GameObject; game.SendMessage("setValues", new int[] { c.getTimeLeft(), c.getCoinValue() }); UnityEngine.Debug.logger.Log("Coin " + c.getX() + "," + c.getY() + " " + c.getCoinValue() + " time" + c.getTimeLeft()); } while (healthToDraw.Count > 0) { HealthObject c = healthToDraw[0]; healthToDraw.RemoveAt(0); GameObject game = Instantiate(health, c.getPosition(), initializingRotation) as GameObject; game.SendMessage("setValues", c.getTimeLeft()); UnityEngine.Debug.logger.Log("Health " + c.getX() + "," + c.getY() + " time" + c.getTimeLeft()); } while (toInstanciate.Count > 0) { //toInstanciate.RemoveAt(0); List <string> list = toInstanciate.Dequeue() as List <string>; String[] cod = list[1].ToString().Split(','); Vector3 pPosition = new Vector3(Int32.Parse(cod[0]), -Int32.Parse(cod[1])); Quaternion rotation = Quaternion.Euler(0, 0, 0); int pDirection = Int32.Parse(list[2].ToString()); if (pDirection == 0) { rotation = Quaternion.Euler(0, 0, 0); } if (pDirection == 1) { rotation = Quaternion.Euler(0, 0, -90); } if (pDirection == 2) { rotation = Quaternion.Euler(0, 0, 180); } if (pDirection == 3) { rotation = Quaternion.Euler(0, 0, 90); } /*if (list[0].ToString()=="P0") * { * if (!isInstanciate) * { * GameObject clone = (GameObject)Instantiate(player, pPosition, rotation); * //Destroy(clone, 1.25f); * isInstanciate = true; * } * }*/ if (list[0].ToString() == "P0") { GameObject clone = (GameObject)Instantiate(tank, pPosition, rotation); Destroy(clone, 1.25f); } if (list[0].ToString() == "P1") { GameObject clone = (GameObject)Instantiate(tank, pPosition, rotation); Destroy(clone, 1.25f); } if (list[0].ToString() == "P2") { GameObject clone = (GameObject)Instantiate(tank, pPosition, rotation); Destroy(clone, 1.25f); } if (list[0].ToString() == "P3") { GameObject clone = (GameObject)Instantiate(tank, pPosition, rotation); Destroy(clone, 1.25f); } if (list[0].ToString() == "P4") { GameObject clone = (GameObject)Instantiate(tank, pPosition, rotation); Destroy(clone, 1.25f); } if (list[0].ToString() == "P5") { GameObject clone = (GameObject)Instantiate(tank, pPosition, rotation); Destroy(clone, 1.25f); } } }
void listen() { try { var listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 7000); listener.Start(); while (true) { string value; using (var networkStream = listener.AcceptTcpClient().GetStream()) { var bytes = new List <byte>(); int asw = 0; while (asw != -1) { asw = networkStream.ReadByte(); bytes.Add((Byte)asw); } value = Encoding.UTF8.GetString(bytes.ToArray()); } String[] datas = value.Split(':'); if (datas[0].Equals("I")) { String walls = datas[2]; wallList = getVecotors(walls); String stone = datas[3]; stoneList = getVecotors(stone); String water = datas[4].Trim(); water = water.Substring(0, water.Length - 2); waterList = getVecotors(water); bordcreated = false; } else if (datas[0].ToUpper().Equals("C")) { String[] cod = datas[1].Split(','); Vector3 coinPosition = new Vector3(Int32.Parse(cod[0]), -Int32.Parse(cod[1])); int coinCountTime = Int32.Parse(datas[2]); datas[3] = datas[3].Trim(); datas[3] = datas[3].Substring(0, datas[3].Length - 2); int coinValue = Int32.Parse(datas[3]); CoinObject o = new CoinObject(coinPosition, coinValue, coinCountTime); coinsToDraw.Add(o); } else if (datas[0].ToUpper().Equals("L")) { String[] cod = datas[1].Split(','); Vector3 healthPosition = new Vector3(Int32.Parse(cod[0]), -Int32.Parse(cod[1])); datas[2] = datas[2].Trim(); datas[2] = datas[2].Substring(0, datas[2].Length - 2); int healthCountTime = Int32.Parse(datas[2]); HealthObject he = new HealthObject(healthPosition, healthCountTime); healthToDraw.Add(he); } else if (datas[0].ToUpper().Equals("G")) { var tanks = datas; for (int i = 1; i < tanks.Length - 1; i++) { String[] pdata = tanks[i].Split(';'); if (true) { String pShot = pdata[3]; String pHealth = pdata[4]; String pCoins = pdata[5]; String pPoints = pdata[6]; List <string> temp = new List <string>(); temp.Add(pdata[0]); temp.Add(pdata[1]); temp.Add(pdata[2]); toInstanciate.Enqueue(temp); } } } } } catch (Exception ex) { Console.WriteLine("Exception occured"); } }
private void Awake() { m_HealthObject = GetComponent <HealthObject>(); m_Random = new Random(); }