internal virtual void LoadAttribute(XmlReader reader) { if (reader.Name.Equals(ID, StringComparison.OrdinalIgnoreCase)) { m_id = reader.ReadElementString().Trim(); } else if (reader.Name.Equals(NAME, StringComparison.OrdinalIgnoreCase)) { m_name = Helper.Helper.getResourceText(reader.ReadElementString().Trim()); } else if (reader.Name.Equals(ICON_PATH, StringComparison.OrdinalIgnoreCase)) { m_iconPath = reader.ReadElementString().Trim(); } else if (reader.Name.Equals(ATTACK_PRIORITY, StringComparison.OrdinalIgnoreCase)) { string value = reader.ReadElementString().Trim(); m_attackPriority = (AttackPriority)Enum.Parse(s_attackPriorityType, value); } else if (reader.Name.Equals(HEALTH, StringComparison.OrdinalIgnoreCase)) { m_health = int.Parse(reader.ReadElementString().Trim()); } else if (reader.Name.Equals(MIN_DAMAGE, StringComparison.OrdinalIgnoreCase)) { m_minDamage = int.Parse(reader.ReadElementString().Trim()); } else if (reader.Name.Equals(MAX_DAMAGE, StringComparison.OrdinalIgnoreCase)) { m_maxDamage = int.Parse(reader.ReadElementString().Trim()); } else if (reader.Name.Equals(ACCURACY, StringComparison.OrdinalIgnoreCase)) { m_accuracy = byte.Parse(reader.ReadElementString().Trim()); if (m_accuracy < 0 || m_accuracy > 100) { m_accuracy = 0; } } else if (reader.Name.Equals(EXPERIENCE, StringComparison.OrdinalIgnoreCase)) { m_experience = int.Parse(reader.ReadElementString().Trim()); } else if (reader.Name.Equals(ON_AREA, StringComparison.OrdinalIgnoreCase)) { m_attackOnArea = reader.ReadElementString().Trim().Equals("yes", StringComparison.OrdinalIgnoreCase); } else if (reader.Name.Equals(WEAKNESS, StringComparison.OrdinalIgnoreCase)) { m_attackWeaknessTarget = reader.ReadElementString().Trim().Equals("yes", StringComparison.OrdinalIgnoreCase); } else if (reader.Name.Equals(TOWER_BONUS, StringComparison.OrdinalIgnoreCase)) { m_towerBonus = reader.ReadElementString().Trim().Equals("yes", StringComparison.OrdinalIgnoreCase); } else if (reader.Name.Equals(IGNORE_TOWER_BONUS, StringComparison.OrdinalIgnoreCase)) { m_ignoreTowerBonus = byte.Parse(reader.ReadElementString().Trim()); } }
internal virtual void SaveAttributes(XmlWriter writer) { writer.WriteStartElement(ID); writer.WriteValue(m_id); writer.WriteEndElement(); writer.WriteStartElement(NAME); writer.WriteValue("UNIT_" + m_id); writer.WriteEndElement(); writer.WriteStartElement(HEALTH); writer.WriteValue(Health); writer.WriteEndElement(); writer.WriteStartElement(MIN_DAMAGE); writer.WriteValue(MinDamage); writer.WriteEndElement(); writer.WriteStartElement(MAX_DAMAGE); writer.WriteValue(MaxDamage); writer.WriteEndElement(); writer.WriteStartElement(ACCURACY); writer.WriteValue(Accuracy); writer.WriteEndElement(); writer.WriteStartElement(EXPERIENCE); writer.WriteValue(Experience); writer.WriteEndElement(); writer.WriteStartElement(ICON_PATH); writer.WriteValue(IconPath); writer.WriteEndElement(); writer.WriteStartElement(ATTACK_PRIORITY); writer.WriteValue(AttackPriority.ToString()); writer.WriteEndElement(); writer.WriteStartElement(ON_AREA); writer.WriteValue(m_attackOnArea ? "yes" : "no"); writer.WriteEndElement(); writer.WriteStartElement(WEAKNESS); writer.WriteValue(m_attackWeaknessTarget ? "yes" : "no"); writer.WriteEndElement(); writer.WriteStartElement(TOWER_BONUS); writer.WriteValue(m_towerBonus ? "yes" : "no"); writer.WriteEndElement(); writer.WriteStartElement(IGNORE_TOWER_BONUS); writer.WriteValue(m_ignoreTowerBonus); writer.WriteEndElement(); }
void Start() { attack_cooldown_current = attack_cooldown_default; attack_radius_current = attack_radius_default; attack_damage_current = attack_damage_default; current_attack_priority = AttackPriority.hp_lowest; StartAttacking(); OnSpawn?.Invoke(this, new TowerV2RefEventArgs(this)); }
void Start() { attack_cooldown_current = attack_cooldown_default; attack_radius_current = attack_radius_default; attack_damage_current = attack_damage_default; time_since_last_attack = Time.time; flag_show_cooldown_bar = false; current_attack_priority = AttackPriority.hp_lowest; StartTowerBehaviorLoop(); //AttachResourceAttributes(); //obsolete if (selection_options_list == null) { selection_options_list = gameObject.AddComponent <Selection_Option_List>(); } selection_options_list.AttachTo(this); OnSpawn?.Invoke(this, new TowerV2RefEventArgs(this)); }
//There is almost certainly a better way to do this but enums are wonky... private void ChangeAttackPriority() { AttackPriority first = Enum.GetValues(typeof(AttackPriority)).Cast <AttackPriority>().Min(); AttackPriority last = Enum.GetValues(typeof(AttackPriority)).Cast <AttackPriority>().Max(); Debug.Log("first: " + first + "last: " + last); AttackPriority orig = current_attack_priority; foreach (AttackPriority prio in System.Enum.GetValues(typeof(AttackPriority))) { if ((int)current_attack_priority <= (int)orig || ((int)current_attack_priority > (int)prio && (int)orig < (int)prio)) //avoid reassigning original val { current_attack_priority = prio; } Debug.Log("c: " + (int)current_attack_priority + " p: " + (int)prio + " o: " + (int)orig); } if ((int)last == (int)current_attack_priority && (int)current_attack_priority == (int)orig) { Debug.Log("TO FIRST: c: " + (int)current_attack_priority + " o: " + (int)orig + " f: " + (int)first); current_attack_priority = first; } }
internal void Load(SaveFileReader reader) { reader.ReadVersion(5); var numSequentialScripts = reader.ReadUInt16(); for (var i = 0; i < numSequentialScripts; i++) { var sequentialScript = new SequentialScript(); sequentialScript.Load(reader); } var numTimersAndCounters = reader.ReadUInt32(); var unknown2 = reader.ReadUInt32(); if (unknown2 != 0) { throw new InvalidDataException(); } for (var i = 1; i < numTimersAndCounters; i++) { var value = reader.ReadInt32(); var name = reader.ReadAsciiString(); var active = reader.ReadBoolean(); } var numTimersAndCounters2 = reader.ReadUInt32(); if (numTimersAndCounters2 != numTimersAndCounters) { throw new InvalidDataException(); } var numFlags = reader.ReadUInt32(); for (var i = 1; i < numFlags; i++) { var value = reader.ReadBoolean(); var name = reader.ReadAsciiString(); } var numFlags2 = reader.ReadUInt32(); if (numFlags2 != numFlags) { throw new InvalidDataException(); } var numAttackPrioritySets = reader.ReadUInt16(); reader.__Skip(8); // TODO for (var i = 1; i < numAttackPrioritySets; i++) { var attackPriority = new AttackPriority(); attackPriority.Load(reader); } var numAttackPrioritySets2 = reader.ReadUInt32(); if (numAttackPrioritySets2 != numAttackPrioritySets) { throw new InvalidDataException(); } var unknown7 = reader.ReadInt32(); if (unknown7 != -1) { throw new InvalidDataException(); } var unknown8 = reader.ReadInt32(); if (unknown8 != -1) { throw new InvalidDataException(); } var unknownCount = reader.ReadUInt16(); for (var i = 0; i < unknownCount; i++) { var objectName = reader.ReadAsciiString(); var someId = reader.ReadUInt32(); } var unknown9 = reader.ReadByte(); if (unknown9 != 0) { throw new InvalidDataException(); } CameraFadeOverlay.Load(reader); reader.__Skip(12); var numSpecialPowerSets = reader.ReadUInt16(); // Maybe not sides, maybe player count? for (var i = 0; i < numSpecialPowerSets; i++) { var version = reader.ReadByte(); var numSpecialPowers = reader.ReadUInt16(); for (var j = 0; j < numSpecialPowers; j++) { var name = reader.ReadAsciiString(); var timestamp = reader.ReadUInt32(); } } var numUnknown1Sets = reader.ReadUInt16(); for (var i = 0; i < numUnknown1Sets; i++) { var version = reader.ReadByte(); var count = reader.ReadUInt16(); if (count != 0) { throw new InvalidDataException(); } } var numUnknown2Sets = reader.ReadUInt16(); for (var i = 0; i < numUnknown2Sets; i++) { var version = reader.ReadByte(); var count = reader.ReadUInt16(); if (count != 0) { throw new InvalidDataException(); } } var numUpgradeSets = reader.ReadUInt16(); for (var i = 0; i < numUpgradeSets; i++) { var version = reader.ReadByte(); var numUpgrades = reader.ReadUInt16(); for (var j = 0; j < numUpgrades; j++) { var name = reader.ReadAsciiString(); var timestamp = reader.ReadUInt32(); } } var numScienceSets = reader.ReadUInt16(); for (var i = 0; i < numScienceSets; i++) { var version = reader.ReadByte(); var numSciences = reader.ReadUInt16(); for (var j = 0; j < numSciences; j++) { var name = reader.ReadAsciiString(); } } var unknown14_1 = reader.ReadByte(); if (unknown14_1 != 1) { throw new InvalidDataException(); } var unknown14_2 = reader.ReadUInt16(); if (unknown14_2 != 0) { throw new InvalidDataException(); } for (var i = 0; i < 6; i++) { var unknown15 = reader.ReadSingle(); } var unknown16 = reader.ReadUInt32(); if (unknown16 != 150) { throw new InvalidDataException(); } var unknown17 = reader.ReadUInt32(); if (unknown17 != 0 && unknown17 != 1 && unknown17 != 2) { throw new InvalidDataException(); } var unknown18 = reader.ReadByte(); if (unknown18 != 0) { throw new InvalidDataException(); } var numMapReveals = reader.ReadUInt16(); for (var i = 0; i < numMapReveals; i++) { var revealName = reader.ReadAsciiString(); var waypoint = reader.ReadAsciiString(); var radius = reader.ReadSingle(); var player = reader.ReadAsciiString(); } var numObjectTypeLists = reader.ReadUInt16(); for (var i = 0; i < numObjectTypeLists; i++) { var objectTypeList = new ObjectTypeList(); objectTypeList.Load(reader); } var unknown20 = reader.ReadByte(); if (unknown20 != 1) { throw new InvalidDataException(); } var musicTrack = reader.ReadAsciiString(); var unknown21 = reader.ReadByte(); if (unknown21 != 0) { throw new InvalidDataException(); } }
IEnumerator ContinueAttackingTargets(AttackPriority prio, List <enemy> enemies_list) { while (true) { //Debug.Log("ContinueAttackingTargets"); enemy target = null; //get list of all targets in radius List <enemy> enemies_in_range = new List <enemy>(); foreach (enemy en in enemies_list) { if ((transform.position - en.transform.position).sqrMagnitude < attack_radius * attack_radius) //sqrmagnitude cheaper than a costly sqrt operation { enemies_in_range.Add(en); } } // Find the target based on the priority param // Note that a property of newly spawned enemies guarantees that the lower the index, the earlier it was spawned! // Equal values during search will be ignored; in that case first success will always be used if (enemies_in_range.Count > 0) { switch (prio) { case AttackPriority.hp_highest: target = enemies_in_range[0]; foreach (enemy en in enemies_in_range) { if (en.hp > target.hp) { target = en; } } break; case AttackPriority.hp_lowest: target = enemies_in_range[0]; foreach (enemy en in enemies_in_range) { if (en.hp < target.hp) { target = en; } } break; case AttackPriority.speed_fastest: target = enemies_in_range[0]; foreach (enemy en in enemies_in_range) { if (en.speed > target.speed) { target = en; } } break; case AttackPriority.speed_slowest: target = enemies_in_range[0]; foreach (enemy en in enemies_in_range) { if (en.speed < target.speed) { target = en; } } break; case AttackPriority.first: //TODO target = enemies_in_range[0]; break; case AttackPriority.last: //TODO target = enemies_in_range[0]; break; default: target = enemies_in_range[0]; //default to first (only guaranteed) element. break; }//end switch } //attack the targeted enemy if (target != null) { Debug.DrawLine(transform.position, target.transform.position, Color.yellow, .1f); //shows what it is hitting! DummyAttack(transform.position, target.transform.position, .1f); target.ApplyDamage(attack_damage); yield return(new WaitForSeconds(attack_cooldown)); //invoke cooldown if we successfully attacked } else { yield return(null); //we did not attack. No cooldown invoked. } } }
public void StartAttacking(AttackPriority prio, List <enemy> enemies_list) { StartCoroutine(ContinueAttackingTargets(prio, enemies_list)); }