Skip to content

Commit 865dd57

Browse files
unknownunknown
authored andcommitted
ActorStateMachine.cpp .h:
function PlayAttackAction, just copy lyubu code; BattleRoom.cpp .h use AppendAttackCode Main.cpp reset robber
1 parent e14dc52 commit 865dd57

File tree

5 files changed

+63
-8
lines changed

5 files changed

+63
-8
lines changed

ActorStateMachine.cpp

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ int ActorStateMachine::ChangeState(ActorState s, BOOL forceSet){
9797
actor.Object(this->character);
9898
actor.MoveForward(-MOVE_LENGTH,TRUE, FALSE, 0.0, TRUE);
9999
//this->SetNewAction("LightDamage");
100+
this->currentAttackIndex = 0;
101+
this->lastAttackIndex = 0;
100102
this->SetNewAction("HeavyDamage");
101103
this->life --;
102104
sprintf(debug, "%s life=%d\n", debug, this->life);
@@ -164,8 +166,60 @@ BOOL ActorStateMachine::PlayAction(int skip){
164166
}
165167

166168
BOOL ActorStateMachine::PlayAttackAction(int skip){
167-
//this->
168-
return FALSE;
169+
FnActor actor;
170+
actor.Object(this->character);
171+
ACTIONid actionID;
172+
173+
char attackName[20] = "\0";
174+
if (this->startAttack == TRUE){// first attack
175+
this->startAttack = FALSE; // reset
176+
//sprintf(debug, "%sstart attack\n", debug);
177+
if (this->attackKeyQueue[currentAttackIndex] == NORMAL_ATT ){
178+
sprintf(attackName, "N%d", currentAttackIndex + 1);
179+
// attackName should be "N1"
180+
}else if (this->attackKeyQueue[currentAttackIndex] == HEAVY_ATT){
181+
sprintf(attackName, "H%d", currentAttackIndex + 1);
182+
// attackName should be "H1"
183+
}
184+
string systemName(attackName);
185+
this->SetNewAction(systemName);
186+
// it performs the new attack
187+
// set the flag here and BattleRoom will check it.
188+
this->newAttack = TRUE;
189+
}else{
190+
// the attack name should be refine from reading the file
191+
BOOL ret = actor.Play(0,ONCE, (float)skip, TRUE,TRUE);
192+
this->UpdateEffectiveAttack();
193+
if (ret == FALSE){
194+
// play the next one
195+
this->effectiveAttack = FALSE;
196+
currentAttackIndex++;
197+
if (currentAttackIndex >= lastAttackIndex){
198+
// finish attacking
199+
this->ChangeState(STATEIDLE);// should be change into combatidle;
200+
this->attackDisable = FALSE;
201+
currentAttackIndex = 0;
202+
lastAttackIndex = 0;
203+
return FALSE;
204+
}else if (this->attackKeyQueue[currentAttackIndex] == NORMAL_ATT){
205+
// get the next one attacking pos
206+
sprintf(attackName, "N%d", currentAttackIndex + 1);
207+
}else if (this->attackKeyQueue[currentAttackIndex] == HEAVY_ATT){
208+
// get the next one attacking pos
209+
sprintf(attackName, "H%d", currentAttackIndex);
210+
}else{
211+
sprintf(debug, "%s next Attack fail condition\n", debug);
212+
return FALSE;
213+
}
214+
string systemName(attackName);
215+
this->SetNewAction(systemName);
216+
// it performs the new attack
217+
// set the flag here and BattleRoom will check it and set the flag to FALSE after checking.
218+
this->newAttack = TRUE;
219+
}
220+
}
221+
//sprintf(debug, "%s lastAttack%d\n", debug, lastAttackIndex );
222+
return TRUE;
169223
}
170224

171225
BOOL ActorStateMachine::SetNewAction(string systemName){

BattleRoom.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ void BattleRoom::RefreshArena(){
3131
for (int i =0;i< this->npcStateMachineList.size();i++){
3232
npc.Object(this->npcStateMachineList[i]->character);
3333
npc.GetWorldPosition(npcPos);
34+
this->npcStateMachineList[i]->AppendAttackCode(NORMAL_ATT);
3435

3536
if (this->CheckDistanceAndState(playerPos, npcPos,
3637
this->playerStateMachine->state, this->npcStateMachineList[i]->state ) == TRUE){
3738
this->JoinArena( this->npcStateMachineList[i] );
38-
this->npcStateMachineList[i]->ChangeState(STATEATTACK,TRUE);
39+
//this->npcStateMachineList[i]->ChangeState(STATEATTACK,TRUE);
3940
}
4041
}
4142
//sprintf(debug, "%s npc state machine list size = %d\n",debug,this->npcStateMachineList.size());

LyubuStateMachine.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ void LyubuStateMachine::setAttackState(void) { //set var attackState
2727
}
2828
*/
2929
BOOL LyubuStateMachine::PlayAttackAction(int skip){
30+
//duplicate with parrent's PlayAttackAction
31+
//this function can be removed (in future);
3032
FnActor actor;
3133
actor.Object(this->character);
3234
ACTIONid actionID;

LyubuStateMachine.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class LyubuStateMachine :
88
LyubuStateMachine(void);
99
virtual ~LyubuStateMachine(void);
1010
LyubuStateMachine(ACTORid character, char *ActionFilename);
11-
//virtual BOOL PlayAction(int skip);
1211
virtual BOOL PlayAttackAction(int skip);
1312
protected:
1413
virtual BOOL UpdateEffectiveAttack();

Main.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void CharacterInit(){
139139
initLyubu();
140140
initNPC();
141141
initBattleRoom(kc, npc);
142-
initFX();
142+
//initFX();
143143
}
144144

145145
BOOL initLyubu(){ // init Lyubu and Camera
@@ -268,6 +268,7 @@ BOOL initNPC(){
268268

269269
robber = scene.LoadActor("Robber02");
270270
if (robber == FAILED_ID){
271+
sprintf(debug, "%s Robber02 load fail\n", debug);
271272
return FALSE;
272273
}
273274
FnActor actor_robber;
@@ -281,7 +282,6 @@ BOOL initNPC(){
281282
flag = actor_robber.PutOnTerrain(tID,FALSE,0.0);
282283

283284
if (flag == FALSE){
284-
sprintf(debug, "%s put on fail\n", debug);
285285
return FALSE;
286286
}
287287
// set donzo idle action
@@ -348,6 +348,7 @@ void Reset(WORLDid gID, BYTE code, BOOL value){
348348
scene.Object(sID);
349349
scene.DeleteActor(lyubu);
350350
scene.DeleteActor(donzo);
351+
scene.DeleteActor(robber);
351352
debug[0] = '\0';
352353
ActorStateMachine * lyubuState = kc->mainChar;
353354
delete lyubuState;
@@ -359,8 +360,6 @@ void Reset(WORLDid gID, BYTE code, BOOL value){
359360
}
360361
fx00 = NULL;
361362
CharacterInit();
362-
//initLyubu();
363-
//initNPC();
364363
}
365364
}
366365
}

0 commit comments

Comments
 (0)