Starsector API
Loading...
Searching...
No Matches
DuelEnemyAIImpl.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.eventide;
2
3public class DuelEnemyAIImpl implements DuelEnemyAI {
4
5 public static class WaitThenAct {
6 float delay;
7 String actionId;
8 public WaitThenAct(float delay, String actionId) {
9 this.delay = delay;
10 this.actionId = actionId;
11 }
12 }
13
14
15 public float initialDelay = 1f;
16 public float moveDelay = 0f;
17 public WaitThenAct next;
18 public float recentBlocks = 0;
19 public float noBlockDur = 0f;
20
21 public DuelEnemyAIImpl() {
22
23 }
24
25
26 public void advance(float amount, DuelPanel duel) {
27 Actor actor = duel.enemy;
28 Actor opponent = duel.player;
29
30 if (opponent.health <= 0) return;
31
32 initialDelay -= amount;
33 if (initialDelay > 0) return;
34
35 recentBlocks -= amount * 0.25f;
36 if (recentBlocks < 0) recentBlocks = 0;
37
38 moveDelay -= amount;
39 if (moveDelay < 0) moveDelay = 0;
40 noBlockDur -= amount;
41 if (noBlockDur < 0) noBlockDur = 0;
42
43 if (next != null) {
44 next.delay -= amount;
45 if (next.delay <= 0) {
46 actor.doAction(next.actionId, false);
47 next = null;
48 }
49 return;
50 }
51
52 //float attackRange = 165;
53 float attackRange = 142;
54 float tooCloseRange = 50;
55 float waitRange = attackRange + 50;
56
57 float dist = duel.getDistance();
58
59 boolean actorAttacking = actor.currAction != null && actor.currAction.anim.hasAttackFrames() &&
60 !actor.currAction.scoredHit && !actor.currAction.wasBlocked;
61 boolean actorBlocking = actor.currAction != null && actor.currAction.anim.hasBlockFrames() &&
63 if (actor.nextAction != null && actor.nextAction.anim.hasBlockFrames()) {
64 actorBlocking = true;
65 }
66
67 boolean actorPerformedBlock = actor.currAction != null && actor.currAction.performedBlock;
68 boolean opponentAttacking = opponent.currAction != null && opponent.currAction.anim.hasAttackFrames() &&
69 !opponent.currAction.scoredHit && !opponent.currAction.wasBlocked;
70 boolean opponentBlocking = opponent.currAction != null && opponent.currAction.anim.hasBlockFrames() &&
71 !opponent.currAction.performedBlock;
72
73 if (actorBlocking || actorAttacking) return;
74
75 boolean blockOnlyMode = false;
76 boolean allowAttack = true;
77 // blockOnlyMode = true;
78 // allowAttack = false;
79
80 if (opponentAttacking && dist < attackRange + 10 && opponent.currAction.framesUntilAttackFrame() < 4) {
81 if (noBlockDur > 0) return;
82
83 if (1f + (float) Math.random() * 4f < recentBlocks) {
84 noBlockDur = 0.5f + (float) Math.random() * 0.2f;
85 if (!blockOnlyMode) {
86 actor.doAction(Actions.MOVE_BACK, false);
87 next = new WaitThenAct(0.1f, Actions.MOVE_BACK);
88 }
89 return;
90 }
91 //next = new WaitThenAct(0.1f + (float) Math.random() * 0.1f, Actions.BLOCK_LOW);
92 float delay = 0.2f * (float) Math.random();
93 //delay = 0f;
94 //delay += (float) Math.random() * Math.min(0.2f, recentBlocks * 0.1f);
95 next = new WaitThenAct(delay, Actions.BLOCK);
97 if (blockOnlyMode) recentBlocks = 0;
98 if (recentBlocks > 4f) recentBlocks = 4f;
99 return;
100 }
101
102 if (opponentAttacking) {
103 return;
104 }
105
106 if (actorPerformedBlock) {
107 moveDelay = 0.1f + (float) Math.random() * 0.05f;
108 //moveDelay = 0.1f;
109 //moveDelay = 0f;
110 return;
111 }
112
113 if (moveDelay <= 0 && !blockOnlyMode) {
114 if (dist > waitRange) {
115 actor.doAction(Actions.MOVE_FORWARD, false);
116 moveDelay = 0.3f + (float) Math.random() * 0.2f;
117 return;
118 } else if (dist > attackRange) {
119 actor.doAction(Actions.MOVE_FORWARD, false);
120 moveDelay = 0.3f + (float) Math.random() * 0.2f;
121 return;
122 }
123 }
124
125 if ((dist < attackRange || actorPerformedBlock) && moveDelay <= 0 && (!blockOnlyMode || allowAttack)) {
126 actor.doAction(Actions.ATTACK, false);
127 moveDelay = 0.1f + (float) Math.random() * 2f;
128 //next = new WaitThenAct((float) Math.random() * 0.1f, Actions.ATTACK_HIGH);
129 return;
130 }
131
132 //if (true) return;
133// if (dist < tooCloseRange && !opponentAttacking) {
134//
135// }
136
137
138// if (opponentAttacking && !actorBlocking) {
139// actor.doAction(Actions.BLOCK_LOW, false);
140// //moveDelay = 0.4f;
141// } else {
142
143// else if (moveDelay <= 0) {
144// actor.doAction(Actions.ATTACK_HIGH, false);
145// moveDelay = 0.5f;
146// }
147
148 //System.out.println("Dist: " + dist);
149
150 }
151
152 public void render(float alphaMult) {
153
154 }
155}
void doAction(String action, boolean forceInterruptCurrent)
Definition Actor.java:81