/
PredatorAI.cs
96 lines (86 loc) · 2.99 KB
/
PredatorAI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
/*
* PredatorAI, its an animal that can attack
* Dont flee but dont attack if not hurt or attacked
*
*/
namespace Server.Mobiles
{
public class PredatorAI : BaseAI
{
public PredatorAI(BaseCreature m)
: base(m)
{
}
public override bool DoActionWander()
{
if (this.m_Mobile.Combatant != null)
{
this.m_Mobile.DebugSay("I am hurt or being attacked, I kill him");
this.Action = ActionType.Combat;
}
else if (this.AcquireFocusMob(this.m_Mobile.RangePerception, this.m_Mobile.FightMode, true, false, true))
{
this.m_Mobile.DebugSay("There is something near, I go away");
this.Action = ActionType.Backoff;
}
else
{
base.DoActionWander();
}
return true;
}
public override bool DoActionCombat()
{
Mobile combatant = this.m_Mobile.Combatant as Mobile;
if (combatant == null || combatant.Deleted || combatant.Map != this.m_Mobile.Map)
{
this.m_Mobile.DebugSay("My combatant is gone, so my guard is up");
this.Action = ActionType.Wander;
return true;
}
if (this.WalkMobileRange(combatant, 1, true, this.m_Mobile.RangeFight, this.m_Mobile.RangeFight))
{
this.m_Mobile.Direction = this.m_Mobile.GetDirectionTo(combatant);
}
else
{
if (this.m_Mobile.GetDistanceToSqrt(combatant) > this.m_Mobile.RangePerception + 1)
{
this.m_Mobile.DebugSay("I cannot find {0}", combatant.Name);
this.Action = ActionType.Wander;
return true;
}
else
{
this.m_Mobile.DebugSay("I should be closer to {0}", combatant.Name);
}
}
return true;
}
public override bool DoActionBackoff()
{
if (this.m_Mobile.IsHurt() || this.m_Mobile.Combatant != null)
{
this.Action = ActionType.Combat;
}
else
{
if (this.AcquireFocusMob(this.m_Mobile.RangePerception * 2, FightMode.Closest, true, false, true))
{
if (this.WalkMobileRange(this.m_Mobile.FocusMob, 1, false, this.m_Mobile.RangePerception, this.m_Mobile.RangePerception * 2))
{
this.m_Mobile.DebugSay("Well, here I am safe");
this.Action = ActionType.Wander;
}
}
else
{
this.m_Mobile.DebugSay("I have lost my focus, lets relax");
this.Action = ActionType.Wander;
}
}
return true;
}
}
}