void DoDamage(int dmg, GameObject go) { m_curHealth -= dmg; if (m_curHealth <= 0) { m_curHealth = 0; if (m_messageHandler) { DeathData deathData = new DeathData(); deathData.attacker = go; deathData.attacked = gameObject; m_messageHandler.GiveMessage(MessageTurret.DIED, gameObject, deathData); } } if (m_messageHandler) { HealthData hpData = new HealthData(); hpData.maxHealth = maxHealth; hpData.curHealth = m_curHealth; m_messageHandler.GiveMessage(MessageTurret.HEALTHCHANGED, gameObject, hpData); } }
void DoDamage(int dmg, GameObject go) { m_curHealth -= dmg; if (m_curHealth <= 0) { m_curHealth = 0; if (m_messageHandler) { DeathData deathData = new DeathData(); deathData.attacker = go; deathData.attacked = gameObject; m_messageHandler.GiveMessage(MessageType.DIED, gameObject, deathData); } } if (m_messageHandler) { HealthData hpData = new HealthData(); hpData.maxHealth = maxHealth; hpData.curHealth = m_curHealth; m_messageHandler.GiveMessage(MessageType.HEALTHCHANGED, gameObject, hpData); } }
void DoDamage(int dmg, GameObject attacker) { _curHealth -= dmg; if (_curHealth <= 0) { _curHealth = 0; if (_msgHandler) { DeathData deathData = new DeathData(); deathData.attacker = attacker; deathData.attacked = gameObject; MessageEventArgs messageEventArgs = new MessageEventArgs(MessageType.DIED, attacker, deathData); _msgHandler.OnGiveMessage(messageEventArgs); } } if (_msgHandler) { HealthData healthData = new HealthData { maxHealth = maxHealth, curHealth = _curHealth }; MessageEventArgs messageEventArgs = new MessageEventArgs(MessageType.HEALTHCHANGED, gameObject, healthData); _msgHandler.OnGiveMessage(messageEventArgs); } }
/// <summary> /// Method to save the data to a file /// </summary> public void Save() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/deaths.dat"); DeathData data = new DeathData(); j = 0; t = 0; for (int i = 0; i < 11; i++) { if (deaths[i] == 9999) { j++; } } for (int i = 0; i < 11; i++) { if (bestTime[i] == 999.99f) { t++; } } //Calculate the total deaths and time before saving bestTime[0] = bestTime[1] + bestTime[2] + bestTime[3] + bestTime[4] + bestTime[5] + bestTime[6] + bestTime[7] + bestTime[8] + bestTime[9] + bestTime[10] - (t * 999.99f); deaths[0] = deaths[1] + deaths[2] + deaths[3] + deaths[4] + deaths[5] + deaths[6] + deaths[7] + deaths[8] + deaths[9] + deaths[10] - (j * 9999); data.deaths = deaths; data.bestTime = bestTime; bf.Serialize(file, data); file.Close(); }
void DoDamage(int dmg, GameObject go) { // Damage-ul efectiv m_curHealth -= dmg; if (m_curHealth <= 0) { m_curHealth = 0; if (m_messageHandler) { // trimite mesaj catre scriptul Death DeathData deathData = new DeathData(); deathData.attacker = go; deathData.attacked = gameObject; m_messageHandler.GiveMessage(Messagetype.DIED, gameObject, deathData); } } if (m_messageHandler) { HealthData hpData = new HealthData(); hpData.maxHealth = maxHealth; hpData.curHealth = m_curHealth; m_messageHandler.GiveMessage(Messagetype.HEALTHCHANGED, gameObject, hpData); } }
public virtual void ApplyDamage(int damage, GameObject go) { m_currentHealth -= damage; // We died! if (m_currentHealth <= 0) { m_currentHealth = 0; // Send out message letting other know I died. if (m_messageHandler) { DeathData deathData = new DeathData(); deathData.attacker = go; deathData.attacked = gameObject; // this object was attacked m_messageHandler.CustomSendMessage(MessageType.DIED, gameObject, deathData); } } if (m_messageHandler) { HealthData healthData = new HealthData(); healthData.curHealth = m_currentHealth; healthData.maxHealth = maxHealth; } }
private void HandleExceptions(ref DeathData data) { if (data.KillerEntity is FireBall) { data.DamageType = DamageType.Heat; } // Get previous attacker when bleeding out if (data.VictimEntityType == CombatEntityType.Player && (data.DamageType == DamageType.Bleeding || data.HitInfo == null)) { var userId = data.VictimEntity.ToPlayer().userID; if (_previousAttack.ContainsKey(userId)) { var attack = _previousAttack[userId]; data.KillerEntity = attack.Attacker; data.KillerEntityType = GetCombatEntityType(data.KillerEntity); // Restore previous hitInfo for weapon determination if (attack.HitInfo != null) { data.HitInfo = attack.HitInfo; } // Use previous damagetype if this is a selfinflicted death, // so falling to death etc. is also shown when wounded and bleeding out if (data.KillerEntity == null || data.KillerEntity == data.VictimEntity) { data.DamageType = attack.DamageType; } else { data.DamageType = DamageType.Bleeding; } } } // Workaround for deaths caused by flamethrower or rocket fire var flame = data.KillerEntity?.GetComponent <Flame>(); if (flame != null && flame.Initiator != null) { data.KillerEntity = flame.Initiator; data.KillerEntityType = CombatEntityType.Player; return; } // Bradley kill with main cannon if (data.HitInfo?.WeaponPrefab?.ShortPrefabName == "maincannonshell") { data.KillerEntityType = CombatEntityType.Bradley; return; } if (data.HitInfo?.WeaponPrefab?.ShortPrefabName?.StartsWith("rocket_heli") ?? false) { data.KillerEntityType = CombatEntityType.Helicopter; return; } }
private void Start() { if (death == null) { death = FindObjectOfType <DeathData>(); } if (demon == null) { demon = FindObjectOfType <DemonData>(); } if (ghost == null) { ghost = FindObjectOfType <GhostData>(); } if (grunt == null) { grunt = FindObjectOfType <GruntData>(); } if (lobber == null) { lobber = FindObjectOfType <LobberData>(); } if (sorcerer == null) { sorcerer = FindObjectOfType <SorcererData>(); } if (thief == null) { thief = FindObjectOfType <ThiefData>(); } }
public void ApplyDamage(int damage, GameObject go) { CurrentHealth -= damage; //Will need to change this if statement, pretty sure I need to remove the spawn part if (CurrentHealth <= 0f /*&& GameObject.Find("Cube-Spawn").GetComponent<HealthController>().currentHealth > 0*/) { // PlaySoundOnKill(); CurrentHealth = 0; if (messageHandler) { DeathData deathData = new DeathData(); deathData.attacker = go; deathData.attacked = gameObject; messageHandler.GiveMessage(MessageTypes.DIED, gameObject, deathData); } if (transform.parent != null) { if (gameObject.GetComponentInParent <TotemDestroyed>()) { gameObject.GetComponentInParent <TotemDestroyed>()._IsDestroyed = true; } } if (gameObject.tag == "Player/Boy" || gameObject.tag == "Player/Girl") { DoDeath(); } if (this.gameObject.tag == "Enemy") { GameObject.Find("/PlayerUI").GetComponent <UISpellSwap>().currentEnemy = null; Destroy(transform.parent.gameObject, 0.15f); if (isBoss) { EventManager.TriggerEvent("bossDied"); } EventManager.TriggerEvent("checkVictory"); } } else if (CurrentHealth >= 0f && CurrentHealth <= totalHealth && this.GetComponent <HealthUI>()) { this.GetComponent <HealthUI>().UpdateUi(totalHealth, currentHealth); } if (messageHandler) { HealthData hpData = new HealthData(); hpData.maxHealth = totalHealth; hpData.curHealth = currentHealth; messageHandler.GiveMessage(MessageTypes.HEALTHCHANGED, gameObject, hpData); } }
public void CloneTo(Unit unit) { base.CloneTo(unit as UnitBase); //copy character controller CharacterController cc = unit.gameObject.AddComponent <CharacterController> (); cc.center = this.GetComponent <CharacterController> ().center; cc.radius = this.GetComponent <CharacterController> ().radius; cc.height = this.GetComponent <CharacterController> ().height; //copy animation foreach (AnimationState ani in this.animation) { AnimationClip clip = ani.clip; unit.animation.AddClip(clip, ani.name); } //copy idledata foreach (IdleData idleData in this.IdleData) { IdleData clone = idleData.GetClone(); unit.IdleData = Util.AddToArray <IdleData> (clone, unit.IdleData); } //copy movedata foreach (MoveData moveData in this.MoveData) { MoveData clone = moveData.GetClone(); unit.MoveData = Util.AddToArray <MoveData> (clone, unit.MoveData); } //copy attackdata foreach (AttackData attackData in this.AttackData) { AttackData clone = attackData.GetClone(); unit.AttackData = Util.AddToArray <AttackData> (clone, unit.AttackData); } //copy ReceiveDamageData foreach (ReceiveDamageData receiveDamageData in this.ReceiveDamageData) { ReceiveDamageData clone = receiveDamageData.GetClone(); unit.ReceiveDamageData = Util.AddToArray <ReceiveDamageData> (clone, unit.ReceiveDamageData); } //copy DeathData foreach (DeathData deathData in this.DeathData) { DeathData clone = deathData.GetClone(); unit.DeathData = Util.AddToArray <DeathData> (clone, unit.DeathData); } //copy AudioData foreach (AudioData audioData in this.AudioData) { AudioData clone = audioData.GetClone(); unit.AudioData = Util.AddToArray <AudioData> (clone, unit.AudioData); } //copy DecalData foreach (DecalData decalData in this.DecalData) { DecalData clone = decalData.GetClone(); unit.DecalData = Util.AddToArray <DecalData> (clone, unit.DecalData); } }
/// <summary> /// Knocks target unit in a line with a given direction. /// </summary> /// <param name="target"></param> /// <param name="knockback"></param> /// <param name="kbDirection"></param> public static void DisplaceUnit(Unit target, Unit source, Attack ability, int knockback, Direction kbDirection) { //look for collisions Vector2Int pushbackLoc = target.GetMapPosition() + (MapMath.DirToRelativeLoc(kbDirection) * knockback); List <Vector2Int> pushbackArea = GetLineAOE(target.GetMapPosition(), kbDirection, knockback); Vector2Int? searchResult = null; foreach (Vector2Int tile in pushbackArea) { if (MapController.instance.weightedMap[tile] == (int)TileWeight.OBSTRUCTED) { searchResult = tile; break; } } if (searchResult != null) { //deal damage when we cant go full knockback dist target.ChangeHealth(-1, source, ability); Vector2Int diff = (Vector2Int)searchResult - target.GetMapPosition(); Vector2Int absDiff = new Vector2Int(Mathf.Abs(diff.x), Mathf.Abs(diff.y)); Debug.Assert(source.GetDirection() != Direction.NO_DIR); //Debug.Log(pushbackLoc); switch (source.GetDirection()) { case Direction.N: pushbackLoc = new Vector2Int(target.GetMapPosition().x, target.GetMapPosition().y + (absDiff.y - 1)); break; case Direction.S: pushbackLoc = new Vector2Int(target.GetMapPosition().x, target.GetMapPosition().y - (absDiff.y - 1)); break; case Direction.W: pushbackLoc = new Vector2Int(target.GetMapPosition().x - (absDiff.x - 1), target.GetMapPosition().y); break; case Direction.E: pushbackLoc = new Vector2Int(target.GetMapPosition().x + (absDiff.x - 1), target.GetMapPosition().y); break; } //Debug.Log(newLocation); } if (MapMath.InMapBounds(pushbackLoc)) { // ******************************** target.Move(pushbackLoc.x, pushbackLoc.y, MovementType.KNOCKBACK); target.hasMoved = false; } //else if() else { DeathData data = new DeathData(source, ability, ability.GetDamage(), target.GetMapPosition()); target.KillMe(data); } }
/// <summary> /// Method to load data from the file into variables. /// </summary> public void Load() { if (File.Exists(Application.persistentDataPath + "/deaths.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/deaths.dat", FileMode.Open); DeathData data = (DeathData)bf.Deserialize(file); deaths = data.deaths; bestTime = data.bestTime; } }
public void CreateNewGame() { Debug.Log("Game Reset"); DeathData data = SaveSystem.LoadDeaths(); totalDeaths = 0; totalTime = 0f; startTime = 0f; stoppedTime = 0f; SaveSystem.SaveDeaths(this); }
public static void SaveDeaths(DeathCount death) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/death_info"; FileStream stream = new FileStream(path, FileMode.Create); DeathData data = new DeathData(death); formatter.Serialize(stream, data); stream.Close(); }
private void EmitRawDeathNotice(DeathData data, Dictionary <string, string> values, string message) { // Post-process the values values.Add("killerId", data.KillerEntity.ToPlayer()?.userID.ToString()); values.Add("victimId", data.VictimEntity.ToPlayer()?.userID.ToString()); values.Add("damageType", data.DamageType.ToString()); values.Add("killerEntityType", data.KillerEntityType.ToString()); values.Add("victimEntityType", data.VictimEntityType.ToString()); // Emit data hook Interface.Call("OnRawDeathNotice", values, message); }
void OutputDeath() { StreamWriter file = new StreamWriter(thisFolder + "/Death" + thisFolder.Substring(thisFolder.Length - 6) + ".csv"); file.WriteLine("Time,State,LastTime"); for (int i = 0; i < deathData.Count; ++i) { DeathData d = deathData [i]; file.WriteLine(d.time + "," + d.State + "," + d.lastTime); } file.Close(); }
public void CreateNewGame() { FindObjectOfType <AudioManager>().Play("ClickButton"); Debug.Log("Game Reset"); DeathData data = SaveSystem.LoadDeaths(); totalDeaths = 0; totalTime = 0f; startTime = 0f; stoppedTime = 0f; SaveSystem.SaveDeaths(this); }
private string GetDeathMessage(DeathData data) { foreach (var matchingStage in _messageMatchingStages) { var match = _configuration.Translations.Messages.Find(m => matchingStage.Invoke(m, data)); if (match != null) { return(match.Messages.GetRandom((uint)DateTime.UtcNow.Millisecond)); } } return(null); }
void RecieveMessage(MessageTurret msgType, GameObject go, MessageData msgData) { switch (msgType) { case MessageTurret.DIED: DeathData dthData = msgData as DeathData; if (dthData != null) { Die(); } break; } }
public DeathData GetClone() { DeathData clone = new DeathData(); base.CloneBasic(clone); clone.ApplicableDamageForm = Util.CloneArray <DamageForm>(this.ApplicableDamageForm); clone.UseDieReplacement = this.UseDieReplacement; clone.ReplaceAfterAnimationFinish = this.ReplaceAfterAnimationFinish; clone.DieReplacement = this.DieReplacement; clone.CopyChildrenTransformToDieReplacement = this.CopyChildrenTransformToDieReplacement; clone.EffectDataName = Util.CloneArray <string>(this.EffectDataName); clone.DecalDataName = Util.CloneArray <string>(this.DecalDataName); return(clone); }
private string GetWeaponName(DeathData deathData) { if (deathData.HitInfo == null) { return(null); } Item item = deathData.HitInfo.Weapon?.GetItem(); /*var parentEntity = hitInfo.Weapon?.GetParentEntity(); * Item item = null; * * if (parentEntity is BasePlayer) * { * (parentEntity as BasePlayer).inventory.FindItemUID(hitInfo.Weapon.ownerItemUID); * } * else if (parentEntity is ContainerIOEntity) * { * (parentEntity as ContainerIOEntity).inventory.FindItemByUID(hitInfo.Weapon.ownerItemUID); * }*/ if (item != null) { return(item.info.displayName.english); } var prefab = deathData.HitInfo.Initiator?.GetComponent <Flame>()?.SourceEntity?.ShortPrefabName ?? deathData.HitInfo.WeaponPrefab?.ShortPrefabName; if (prefab != null) { if (_weaponPrefabs.Contents.ContainsKey(prefab)) { return(_weaponPrefabs.Contents[prefab]); } return(prefab); } // Vehicles are the only thing we classify as a weapon, while not being classified as such by the game. // TODO: Having this here kinda sucks, make this better. if (deathData.DamageType == DamageType.Collision) { return("Vehicle"); } return(null); }
private string GetCustomizedWeaponName(DeathData deathData) { var name = GetWeaponName(deathData); if (string.IsNullOrEmpty(name)) { return(null); } if (!_configuration.Translations.Weapons.ContainsKey(name)) { _configuration.Translations.Weapons.Add(name, name); Config.WriteObject(_configuration); } return(_configuration.Translations.Weapons[name]); }
private string PopulateMessageVariables(string message, DeathData data) { if (string.IsNullOrEmpty(message)) { return(null); } var replacements = new Dictionary <string, string> { ["victim"] = GetCustomizedEntityName(data.VictimEntity, data.VictimEntityType) }; if (data.KillerEntityType != CombatEntityType.None) { replacements.Add("killer", GetCustomizedEntityName(data.KillerEntity, data.KillerEntityType)); replacements.Add("bodypart", GetCustomizedBodypartName(data.HitInfo)); replacements.Add("positionStr", data.PositionStr); replacements.Add("positionKillerStr", data.PositionKillerStr); if (data.KillerEntity != null) { var distance = data.KillerEntity.Distance(data.VictimEntity); replacements.Add("distance", GetDistance(distance, _configuration.UseMetricDistance)); } if (data.KillerEntityType == CombatEntityType.Player) { replacements.Add("hp", data.KillerEntity.Health().ToString("#0.#")); replacements.Add("weapon", GetCustomizedWeaponName(data.HitInfo)); replacements.Add("attachments", string.Join(", ", GetCustomizedAttachmentNames(data.HitInfo).ToArray())); } else if (data.KillerEntityType == CombatEntityType.Turret || data.KillerEntityType == CombatEntityType.Lock || data.KillerEntityType == CombatEntityType.Trap) { replacements.Add("owner", covalence.Players.FindPlayerById(data.KillerEntity.OwnerID.ToString())?.Name ?? "unknown owner" ); // TODO: Work on the potential unknown owner case } } message = InsertPlaceholderValues(message, replacements); replacements = null; return(message); }
// "Kill me." // "Later." // this function essentially destroys the Unit (but not actually) by doing 3 things: // - hide the sprite renderer // - remove the Unit from the Global Positional Data // - reset the tile that it was occupying // it then calls out that it's dying, so that other scripts can do what they're supposed to public virtual void KillMe(DeathData data) { if (deathSoundEvent.isValid()) { deathSoundEvent.start(); } health = 0; Deaths.Push(data); hasMoved = true; hasActed = true; this.gameObject.GetComponent <SpriteRenderer>().enabled = false; globalPositionalData.RemoveUnit(mapPosition); MapController.instance.weightedMap[mapPosition] = (int)tile; // "Hey guys, I'm dying. If anyone needs a reference to me, here it is." DeathEvent.Invoke(this); }
public void OnReceiveMessage(MessageEventArgs msgEventArgs) { switch (msgEventArgs.MsgType) { case MessageType.DIED: DeathData deathData = msgEventArgs.MsgData as DeathData; if (deathData != null) { UpdateStats(deathData.attacker, deathData.attacked); // Send out info that this entity died OnEntityDeath(deathData.attacked); Die(); } break; } }
void ReceiveMessage(MessageType messageType, GameObject go, MessageData data) { switch (messageType) { case MessageType.DIED: // Debug.Log("Death Note: " + gameObject.name); DeathData deathData = data as DeathData; if (deathData != null) { Die(); } break; default: break; } }
public static DeathData LoadDeaths() { string path = Application.persistentDataPath + "/death_info"; if (File.Exists(path)) { NoSaveFileForDeaths = false; BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); Debug.Log("There exists a path"); DeathData data = formatter.Deserialize(stream) as DeathData; stream.Close(); return(data); } else { NoSaveFileForDeaths = true; Debug.Log("Save file not found in " + path); return(null); } }
public void ChangeHealth(int amount, Unit source, UnitAbility attack) { int newDamage = 0; if (amount > 0) { newDamage = amount; } else { newDamage = amount - damageReduction; } health += (newDamage); if (health <= 0) { DeathData data = new DeathData(source, attack, amount, mapPosition); data.DebugLog(); KillMe(data); } }
public void LoadDeaths() { DeathData data = SaveSystem.LoadDeaths(); string path = Application.persistentDataPath + "/death_info"; if (!File.Exists(path)) { totalDeaths = 0; totalTime = 0f; startTime = 0f; stoppedTime = 0f; } else { totalDeaths = data.deathsFromData; totalTime = data.timeFromData; startTime = data.startTimeFromData; stoppedTime = data.stoppedTimeFromData; } Debug.Log("InLoadDeaths: " + totalDeaths); }
public DeathData GetClone() { DeathData clone = new DeathData(); base.CloneBasic(clone); clone.ApplicableDamageForm = Util.CloneArray<DamageForm>(this.ApplicableDamageForm); clone.UseDieReplacement = this.UseDieReplacement; clone.ReplaceAfterAnimationFinish = this.ReplaceAfterAnimationFinish; clone.DieReplacement = this.DieReplacement; clone.CopyChildrenTransformToDieReplacement = this.CopyChildrenTransformToDieReplacement; clone.EffectDataName = Util.CloneArray<string>(this.EffectDataName); clone.DecalDataName = Util.CloneArray<string>(this.DecalDataName); return clone; }
private void OnEntityDeath(BaseCombatEntity victimEntity, HitInfo hitInfo) { // Ignore - there is no victim for some reason if (victimEntity == null) { return; } var data = new DeathData { VictimEntity = victimEntity, KillerEntity = victimEntity.lastAttacker ?? hitInfo?.Initiator, VictimEntityType = GetCombatEntityType(victimEntity), KillerEntityType = GetCombatEntityType(victimEntity.lastAttacker), DamageType = victimEntity.lastDamage, HitInfo = hitInfo }; // Handle inconsistencies/exceptions HandleExceptions(ref data); #if DEBUG LogDebug("[DEATHNOTES DEBUG]"); LogDebug($"VictimEntity: {data.VictimEntity?.GetType().Name ?? "NULL"} / {data.VictimEntity?.name ?? "NULL"}"); LogDebug($"KillerEntity: {data.KillerEntity?.GetType().Name ?? "NULL"} / {data.KillerEntity?.name ?? "NULL"}"); LogDebug($"VictimEntityType: {data.VictimEntityType}"); LogDebug($"KillerEntityType: {data.KillerEntityType}"); LogDebug($"DamageType: {data.DamageType}"); LogDebug($"Bodypart: {GetCustomizedBodypartName(data.HitInfo)}"); LogDebug($"Weapon: {hitInfo?.WeaponPrefab?.ShortPrefabName ?? "NULL"}"); #endif // Ignore deaths of other entities if (data.KillerEntityType == CombatEntityType.Other || data.VictimEntityType == CombatEntityType.Other) { return; } // Ignore deaths which don't involve players or the helicopter which usually does not track a player as killer if (data.VictimEntityType != CombatEntityType.Player && data.KillerEntityType != CombatEntityType.Player && data.VictimEntityType != CombatEntityType.Helicopter) { return; } // Populate the variables in the message string message = PopulateMessageVariables( // Find the best matching death message for this death GetDeathMessage(data), data ); if (message == null) { return; } Interface.Call("OnDeathNotice", data.ToDictionary(), message); if (_configuration.ShowInChat) { foreach (var player in BasePlayer.activePlayerList) { if (_configuration.MessageRadius != -1 && player.Distance(data.VictimEntity) > _configuration.MessageRadius) { continue; } Player.Reply( player, _configuration.ChatFormat.Replace("{message}", message), ulong.Parse(_configuration.ChatIcon) ); } } if (_configuration.ShowInConsole) { Puts(StripRichText(message)); } }
protected override void ReadBody(ByteReader reader) { this.DeathData = reader.ReadDeathDataPacket(); }