123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using CommonAI.RTS; using CommonLang.Vector;
- using CommonAI.Zone.Helper;
- using CommonAI.Zone.Formula;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace CommonAI.Zone.Instance
- {
- /// <summary>
- /// 中立AI
- /// </summary>
- public class InstanceNature : InstanceUnit
- {
- private Vector2 mBasePos = new Vector2();
- private HateSystem mHateSystem;
- private StateFollowAndAttack mTracing;
- override public bool IsNature { get { return true; } }
- public InstanceNature(InstanceZone zone, UnitInfo info, string name, int force, int level)
- : base(zone, info, name, force, level)
- {
- mHateSystem = TemplateManager.Factory.CreateHateSystem(this);
- }
- override protected void onResetAI()
- {
- mTracing = null;
- mHateSystem.Clear();
- doSomething();
- }
- public bool followAndAttack(InstanceUnit src, AttackReason reason)
- {
- if (IsNoneSkill)
- {
- return false;
- }
- if (src != null)
- {
- if (Parent.IsAttackable(this, src, SkillTemplate.CastTarget.Enemy, reason, Info))
- {
- mHateSystem.Add(src);
- if ((mTracing == null) || (mTracing.Target != src))
- {
- mTracing = new StateFollowAndAttack(this, src);
- }
- changeState(mTracing);
- return true;
- }
- else
- {
- mHateSystem.Remove(src);
- }
- }
- return false;
- }
-
- protected override void onAdded(bool pointLv)
- {
- mBasePos.SetX(X);
- mBasePos.SetY(Y);
- base.onAdded(pointLv);
- }
- override protected void onUpdate(bool slowRefresh)
- {
- base.onUpdate(slowRefresh);
- }
- protected override void onStateChanged(State old_state, State state)
- {
- if (state is StateIdle)
- {
- followAndAttack(mHateSystem.GetHated(), AttackReason.Tracing);
- }
- }
- protected override void onMoveBlockWithObject(InstanceZoneObject obj)
- {
- if (obj is InstanceUnit)
- {
- var unit = obj as InstanceUnit;
- if (unit is InstancePet)
- {
- followAndAttack((unit as InstancePet).Master, AttackReason.MoveBlocked);
- return;
- }
- followAndAttack(obj as InstanceUnit, AttackReason.MoveBlocked);
- }
- }
- protected override void onDamaged(InstanceUnit attacker, AttackSource attack, int reduceHP)
- {
- if (attacker is InstancePet)
- {
- attacker = (attacker as InstancePet).Master;
- }
- mHateSystem.OnHitted(attacker, attack, reduceHP);
- followAndAttack(attacker, AttackReason.Damaged);
- }
- }
- //--------------------------------------------------------------------------------------------------------
- }
|