void CheckThreat() { if (threat_table.Count == 0) { return; } Sort(); ThreatEntry current = FindEntry(current_target); ThreatEntry top = threat_table[0]; if (top.threat == 0) { return; } float distance = Vector3.Distance(transform.position, top.unit.transform.position); if (current.unit != top.unit) { if (distance > MeleeRange && top.threat >= current.threat * 1.3) { current_target = top.unit; } else if (distance <= MeleeRange && top.threat >= current.threat * 1.1) { current_target = top.unit; } } }
void ReplaceEntry(ThreatEntry entry) { for (int i = 0; i < threat_table.Count; i++) { if (threat_table[i].unit == entry.unit) { threat_table[i] = entry; } } }
public void AddNewThreat(Creature newThreat, uint amount = 0) { var entry = new ThreatEntry(newThreat.Guid) { Threat = amount }; ThreatTableByCreature.Add(newThreat.Guid, entry); ThreatTableByThreat.Add(entry, newThreat.Guid); }
void CheckTarget() { if (current_target == null) { return; } if (current_target.hp == 0) { ThreatEntry temp = FindEntry(current_target); temp.threat = 0; ReplaceEntry(temp); CheckThreat(); } }
void Taunt(Unit unit) { ThreatEntry entry = FindEntry(unit); if (entry.unit == null) { return; } ThreatEntry top = threat_table[0]; entry.threat = top.threat * 1.3f; CheckThreat(); }
public void AddThreat(Unit unit, float threat) { ThreatEntry entry = FindEntry(unit); if (entry.unit == null) { Debug.Log("No entry for unit"); return; } entry.threat += threat; ReplaceEntry(entry); CheckThreat(); }
int CompareThreatEntry(ThreatEntry x, ThreatEntry y) { if (x.threat == y.threat) { return(0); } else if (x.threat < y.threat) { return(1); } else { return(-1); } }