123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using CommonLang;
- using CommonAI.ZoneServer;
- using CommonLang.IO;
- namespace CommonAI.Zone.Instance.Helper
- {
- public abstract class IUnitStatistic
- {
- public InstanceUnit Owner { get; private set; }
- public IUnitStatistic(InstanceUnit owner)
- {
- this.Owner = owner;
- }
-
-
-
-
- public virtual UnitStatisticData ToUnitStatisticData()
- {
- var ret = new UnitStatisticData();
- ret.ObjectID = Owner.ID;
- ret.DeadCount = this.DeadCount;
- ret.KillUnitCount = this.KillUnitCount;
- ret.KillPlayerCount = this.KillPlayerCount;
- ret.SelfDamage = this.SelfDamage;
- ret.TotalDamage = this.TotalDamage;
- ret.PlayerDamage = this.PlayerDamage;
- ret.TotalHealing = this.TotalHealing;
- ret.PlayerHealing = this.PlayerHealing;
- return ret;
- }
- public abstract void Reset();
-
-
-
-
- public abstract int DeadCount { get; }
-
-
-
- public abstract int KillPlayerCount { get; }
-
-
-
- public abstract int KillUnitCount { get; }
-
-
-
- public abstract long SelfDamage { get; }
-
-
-
- public abstract long TotalDamage { get; }
-
-
-
- public abstract long PlayerDamage { get; }
-
-
-
- public abstract long TotalHealing { get; }
-
-
-
- public abstract long PlayerHealing { get; }
-
-
-
- public abstract long preKillTime { get; set; }
- public abstract short continueKills { get; set; }
-
-
-
-
- public abstract int GetKillUnitCount(UnitInfo.UnitType type);
-
-
-
-
-
- public abstract void onDead(InstanceUnit killer);
-
-
-
-
- public abstract void onKill(InstanceUnit target);
-
-
-
-
-
- public abstract void onDamage(InstanceUnit attacker, int reduceHP);
-
-
-
-
-
- public abstract void onAttack(InstanceUnit target, int reduceHP);
-
-
-
-
- public abstract void onUseItem(ItemTemplate item);
-
- internal void LogDamage(IUnitStatistic attacker, int reduceHP)
- {
- if (reduceHP > 0 && this.Owner.CurrentHP < reduceHP)
- {
- reduceHP = this.Owner.CurrentHP;
- }
- if (reduceHP < 0 && this.Owner.MaxHP - this.Owner.CurrentHP < -reduceHP)
- {
- reduceHP = this.Owner.CurrentHP - this.Owner.MaxHP;
- }
- this.onDamage(attacker.Owner, reduceHP);
- attacker.onAttack(this.Owner, reduceHP);
- }
- internal void LogDead(IUnitStatistic attacker)
- {
- this.onDead(attacker.Owner);
- attacker.onKill(this.Owner);
- }
- internal void LogUseItem(ItemTemplate item)
- {
- this.onUseItem(item);
- }
-
- }
-
- public class UnitStatistic : IUnitStatistic
- {
- private int m_DeadCount = 0;
- private int m_KillPlayerCount = 0;
- private int m_KillUnitCount = 0;
- private long m_SelfDamage = 0;
- private long m_TotalDamage = 0;
- private long m_PlayerDamage = 0;
- private long m_TotalHealing = 0;
- private long m_PlayerHealing = 0;
-
- private long m_preKillTime = 0;
- private short m_continueKills = 0;
- private Dictionary<UnitInfo.UnitType, int> m_KillUnitCountMap = new Dictionary<UnitInfo.UnitType, int>();
- public UnitStatistic(InstanceUnit owner) : base(owner)
- {
- }
- public override void Reset()
- {
- this.m_DeadCount = 0;
- this.m_KillPlayerCount = 0;
- this.m_KillUnitCount = 0;
- this.m_SelfDamage = 0;
- this.m_TotalDamage = 0;
- this.m_PlayerDamage = 0;
- this.m_TotalHealing = 0;
- this.m_PlayerHealing = 0;
-
- this.m_preKillTime = 0;
- this.m_continueKills = 0;
- this.m_KillUnitCountMap.Clear();
- }
- public override int DeadCount { get { return m_DeadCount; } }
- public override int KillPlayerCount { get { return m_KillPlayerCount; } }
- public override int KillUnitCount { get { return m_KillUnitCount; } }
- public override long SelfDamage { get { return m_SelfDamage; } }
- public override long TotalDamage { get { return m_TotalDamage; } }
- public override long PlayerDamage { get { return m_PlayerDamage; } }
- public override long TotalHealing { get { return m_TotalHealing; } }
- public override long PlayerHealing { get { return m_PlayerHealing; } }
-
-
-
- public override long preKillTime { get { return m_preKillTime; } set { m_preKillTime = value; } }
- public override short continueKills { get { return m_continueKills; } set { m_continueKills = value; } }
- public override int GetKillUnitCount(UnitInfo.UnitType type)
- {
- int ret = 0;
- if (m_KillUnitCountMap.TryGetValue(type, out ret))
- return ret;
- return 0;
- }
- public override void onDead(InstanceUnit killer)
- {
- this.m_DeadCount += 1;
- }
- public override void onKill(InstanceUnit target)
- {
- this.m_KillUnitCount += 1;
- if (target.IsPlayer) { this.m_KillPlayerCount += 1; }
- int count = 0;
- if (this.m_KillUnitCountMap.TryGetValue(target.Info.UType, out count))
- {
- count += 1;
- this.m_KillUnitCountMap[target.Info.UType] = count;
- }
- else
- {
- this.m_KillUnitCountMap.Add(target.Info.UType, 1);
- }
- }
- public override void onDamage(InstanceUnit attacker, int reduceHP)
- {
- if (reduceHP > 0)
- {
- this.m_SelfDamage += reduceHP;
- }
- }
- public override void onAttack(InstanceUnit target, int reduceHP)
- {
- if (reduceHP > 0)
- {
- this.m_TotalDamage += reduceHP;
- if (target.IsPlayer)
- {
- this.m_PlayerDamage += reduceHP;
- }
- }
- else
- {
- this.m_TotalHealing += -reduceHP;
- if (target.IsPlayer)
- {
- this.m_PlayerHealing += -reduceHP;
- }
- }
- }
- public override void onUseItem(ItemTemplate item)
- {
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
|