Skip to content

Commit

Permalink
Add behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
WoutProvost committed Jul 11, 2017
1 parent fa80358 commit 714da0c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 49 deletions.
1 change: 0 additions & 1 deletion examples/leatherface.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public OnFilterScriptInit()
{
BossLeatherface = FAI_CreateBoss("BossLeatherface");
FAI_SetBossMaxHealth(BossLeatherface, 2000.0);
FAI_SetBossAggroRange(BossLeatherface, 0.0);
FAI_SetBossMoveInfo(BossLeatherface, MOVE_TYPE_SPRINT);
FAI_SetBossMeleeAttackInfo(BossLeatherface, 1.5, -1, false);
SetBossAtSpawn(BossLeatherface);
Expand Down
12 changes: 7 additions & 5 deletions examples/mmo.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public OnFilterScriptInit()
FAI_SetBossDisplayRange(BossBigSmoke, 100.0);
FAI_SetBossMoveInfo(BossBigSmoke, MOVE_TYPE_SPRINT, MOVE_SPEED_AUTO, true);
FAI_SetBossAllowNPCTargets(BossBigSmoke, false);
FAI_SetBossBehaviour(BossBigSmoke, FAI_BOSS_BEHAVIOUR_UNFRIENDLY);
SetBossAtSpawn(BossBigSmoke);
SpellCarpetOfFire = FAI_CreateSpell("Carpet of Fire");
SpellWallOfFire = FAI_CreateSpell("Wall of Fire");
Expand Down Expand Up @@ -83,7 +84,8 @@ public OnFilterScriptInit()
new name[MAX_PLAYER_NAME + 1];
format(name, sizeof(name), "BossBigSmokeAdd%d", add);
BossAdds[add] = FAI_CreateBoss(name);
FAI_SetBossAggroRange(BossAdds[add], 0.0);
FAI_SetBossAggroRange(BossAdds[add], 1000.0);
FAI_SetBossBehaviour(BossAdds[add], FAI_BOSS_BEHAVIOUR_FRIENDLY);
FAI_SetBossMoveInfo(BossAdds[add], MOVE_TYPE_AUTO, MOVE_SPEED_AUTO, true);
FAI_SetBossAllowNPCTargets(BossAdds[add], false);
new npcid = FAI_GetBossNPCID(BossAdds[add]);
Expand Down Expand Up @@ -207,7 +209,7 @@ public FCNPC_OnTakeDamage(npcid, damagerid, weaponid, bodypart, Float:health_los
- Next: boss gets damaged to 90%, we don't want to call make the boss yell again because he passed the same point
*/
new BossHealthPercent = FAI_GetBossCurrentHealthPercent(bossid);
if(BossHealthPercent < BossBigSmokeHealthState) {
if(BossHealthPercent < BossBigSmokeHealthState && FAI_GetBossBehaviour(bossid) != FAI_BOSS_BEHAVIOUR_FRIENDLY) {
BossBigSmokeHealthState = BossHealthPercent;
switch(BossBigSmokeHealthState) {
case 90: {BossYell(bossid, "Fry, motherfuckers", 35713); ExecuteSpell(bossid);}
Expand Down Expand Up @@ -352,7 +354,7 @@ public FAI_OnBossEncounterStop(bossid, bool:reasonDeath, lastTarget)
new npcid = FAI_GetBossNPCID(BossAdds[add]);
SetPlayerColor(npcid, 0xffffff00);
FCNPC_SetPosition(npcid, 1086.9752, 1074.7021, -50.0);
FAI_SetBossAggroRange(BossAdds[add], 0.0);
FAI_SetBossBehaviour(BossAdds[add], FAI_BOSS_BEHAVIOUR_FRIENDLY);
}
}
if(SpellRockOfLifeTarget != INVALID_PLAYER_ID) {
Expand All @@ -365,7 +367,7 @@ public FAI_OnBossEncounterStop(bossid, bool:reasonDeath, lastTarget)
new npcid = FAI_GetBossNPCID(bossid);
SetPlayerColor(npcid, 0xffffff00);
FCNPC_SetPosition(npcid, 1086.9752, 1074.7021, -50.0);
FAI_SetBossAggroRange(bossid, 0.0);
FAI_SetBossBehaviour(bossid, FAI_BOSS_BEHAVIOUR_FRIENDLY);
break;
}
}
Expand Down Expand Up @@ -664,7 +666,7 @@ public FAI_OnBossStopCasting(bossid, spellid, targetid, bool:castComplete)
FCNPC_SetInvulnerable(addplayerid, false);
FAI_SetBossMaxHealth(BossAdds[add], 100.0);
FAI_SetBossCurrentHealth(BossAdds[add], 100.0);
FAI_SetBossAggroRange(BossAdds[add], 1000.0);
FAI_SetBossBehaviour(BossAdds[add], FAI_BOSS_BEHAVIOUR_UNFRIENDLY);
SetPlayerColor(addplayerid, 0xb31a1eff);
}
}
Expand Down
33 changes: 30 additions & 3 deletions include/FAI.inc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ native FAI_GetBossMeleeAttackInfo(bossid, &Float:range, &delay, &bool:useFightSt
native FAI_SetBossMeleeAttackInfo(bossid, Float:range = 1.0, delay = -1, bool:useFightStyle = false);
native FAI_GetBossAllowNPCTargets(bossid);
native FAI_SetBossAllowNPCTargets(bossid, bool:allowNPCTargets, bool:checkForTarget = false);
native FAI_GetBossBehaviour(bossid);
native FAI_SetBossBehaviour(bossid, behaviour, bool:checkForTarget = false);
native FAI_DestroyBoss(bossid);
native FAI_DestroyAllBosses();
native bool:FAI_IsValidBoss(bossid);
Expand Down Expand Up @@ -609,7 +611,7 @@ stock FAI_DamageBoss(bossid, damagerid, Float:amount) {
//4th part of condition: neccesary to reject invalid damage done: the NPC is visible and thus damagable in other interiors
if(FCNPC_IsSpawned(bossplayerid) && !FCNPC_IsDead(bossplayerid) && (damagerid == INVALID_PLAYER_ID || FAI_IsBossValidForPlayer(damagerid, bossid))) {
//Only set target if the encounter has not yet started AND the behaviour is neutral or unfriendly
if(FAI_Bosses[bossid][TARGET] == INVALID_PLAYER_ID) {
if(FAI_Bosses[bossid][TARGET] == INVALID_PLAYER_ID && FAI_Bosses[bossid][BEHAVIOUR] != FAI_BOSS_BEHAVIOUR_FRIENDLY) {
//Set target to damagerid if no target yet (valid damagerid + no target yet check in setter)
FAI_SetBossTargetWithReason(bossid, damagerid, 1);
}
Expand Down Expand Up @@ -747,8 +749,11 @@ public FAI_Update() {
FAI_IncreaseBossCastProgress(bossid);
//Get new target if no target, or if old target invalid, or if the boss is not streamed in anymore for his old target
if(!FAI_IsBossValidForPlayer(FAI_Bosses[bossid][TARGET], bossid) || !IsPlayerStreamedIn(FAI_Bosses[bossid][NPCID], FAI_Bosses[bossid][TARGET])) {
//Set target to closestPlayerid (valid closestPlayerid check in setter)
FAI_SetBossTargetWithReason(bossid, FAI_GetClosestPlayerToTakeAggro(bossid), 3);
//Only set target if the encounter has already started OR if the behaviour is unfriendly
if(FAI_Bosses[bossid][TARGET] != INVALID_PLAYER_ID || FAI_Bosses[bossid][BEHAVIOUR] == FAI_BOSS_BEHAVIOUR_UNFRIENDLY) {
//Set target to closestPlayerid (valid closestPlayerid check in setter)
FAI_SetBossTargetWithReason(bossid, FAI_GetClosestPlayerToTakeAggro(bossid), 3);
}
}
//Attack target (which can be set above) if target known
if(FAI_Bosses[bossid][TARGET] != INVALID_PLAYER_ID) {
Expand Down Expand Up @@ -977,6 +982,7 @@ stock FAI_CreateBoss(name[]) {
FAI_SetBossRangedAttackInfo(bossid, 20.0, -1, true);
FAI_SetBossMeleeAttackInfo(bossid, 1.0, -1, false);
FAI_SetBossAllowNPCTargets(bossid, true, false);
FAI_SetBossBehaviour(bossid, FAI_BOSS_BEHAVIOUR_NEUTRAL, false);
return bossid;
} else {
//FCNPC_Create failed
Expand Down Expand Up @@ -1351,6 +1357,27 @@ stock FAI_SetBossAllowNPCTargets(bossid, bool:allowNPCTargets, bool:checkForTarg
}
return 0;
}
stock FAI_GetBossBehaviour(bossid) {
if(FAI_IsValidBoss(bossid)) {
return FAI_Bosses[bossid][BEHAVIOUR];
}
return -1;
}
stock FAI_SetBossBehaviour(bossid, behaviour, bool:checkForTarget = false) {
if(FAI_IsValidBoss(bossid)) {
if(behaviour == FAI_BOSS_BEHAVIOUR_FRIENDLY || behaviour == FAI_BOSS_BEHAVIOUR_NEUTRAL || behaviour == FAI_BOSS_BEHAVIOUR_UNFRIENDLY) {
FAI_Bosses[bossid][BEHAVIOUR] = behaviour;
if(checkForTarget) {
if(behaviour == FAI_BOSS_BEHAVIOUR_FRIENDLY && FAI_Bosses[bossid][TARGET] != INVALID_PLAYER_ID) {
//Reset target
FAI_SetBossTargetWithReason(bossid, INVALID_PLAYER_ID, 0);
}
}
return 1;
}
}
return 0;
}
stock FAI_GetBossNPCID(bossid) {
if(FAI_IsValidBoss(bossid)) {
return FAI_Bosses[bossid][NPCID];
Expand Down
33 changes: 30 additions & 3 deletions src/FAI.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ native FAI_GetBossMeleeAttackInfo(bossid, &Float:range, &delay, &bool:useFightSt
native FAI_SetBossMeleeAttackInfo(bossid, Float:range = 1.0, delay = -1, bool:useFightStyle = false);
native FAI_GetBossAllowNPCTargets(bossid);
native FAI_SetBossAllowNPCTargets(bossid, bool:allowNPCTargets, bool:checkForTarget = false);
native FAI_GetBossBehaviour(bossid);
native FAI_SetBossBehaviour(bossid, behaviour, bool:checkForTarget = false);
native FAI_DestroyBoss(bossid);
native FAI_DestroyAllBosses();
native bool:FAI_IsValidBoss(bossid);
Expand Down Expand Up @@ -609,7 +611,7 @@ stock FAI_DamageBoss(bossid, damagerid, Float:amount) {
//4th part of condition: neccesary to reject invalid damage done: the NPC is visible and thus damagable in other interiors
if(FCNPC_IsSpawned(bossplayerid) && !FCNPC_IsDead(bossplayerid) && (damagerid == INVALID_PLAYER_ID || FAI_IsBossValidForPlayer(damagerid, bossid))) {
//Only set target if the encounter has not yet started AND the behaviour is neutral or unfriendly
if(FAI_Bosses[bossid][TARGET] == INVALID_PLAYER_ID) {
if(FAI_Bosses[bossid][TARGET] == INVALID_PLAYER_ID && FAI_Bosses[bossid][BEHAVIOUR] != FAI_BOSS_BEHAVIOUR_FRIENDLY) {
//Set target to damagerid if no target yet (valid damagerid + no target yet check in setter)
FAI_SetBossTargetWithReason(bossid, damagerid, 1);
}
Expand Down Expand Up @@ -747,8 +749,11 @@ public FAI_Update() {
FAI_IncreaseBossCastProgress(bossid);
//Get new target if no target, or if old target invalid, or if the boss is not streamed in anymore for his old target
if(!FAI_IsBossValidForPlayer(FAI_Bosses[bossid][TARGET], bossid) || !IsPlayerStreamedIn(FAI_Bosses[bossid][NPCID], FAI_Bosses[bossid][TARGET])) {
//Set target to closestPlayerid (valid closestPlayerid check in setter)
FAI_SetBossTargetWithReason(bossid, FAI_GetClosestPlayerToTakeAggro(bossid), 3);
//Only set target if the encounter has already started OR if the behaviour is unfriendly
if(FAI_Bosses[bossid][TARGET] != INVALID_PLAYER_ID || FAI_Bosses[bossid][BEHAVIOUR] == FAI_BOSS_BEHAVIOUR_UNFRIENDLY) {
//Set target to closestPlayerid (valid closestPlayerid check in setter)
FAI_SetBossTargetWithReason(bossid, FAI_GetClosestPlayerToTakeAggro(bossid), 3);
}
}
//Attack target (which can be set above) if target known
if(FAI_Bosses[bossid][TARGET] != INVALID_PLAYER_ID) {
Expand Down Expand Up @@ -977,6 +982,7 @@ stock FAI_CreateBoss(name[]) {
FAI_SetBossRangedAttackInfo(bossid, 20.0, -1, true);
FAI_SetBossMeleeAttackInfo(bossid, 1.0, -1, false);
FAI_SetBossAllowNPCTargets(bossid, true, false);
FAI_SetBossBehaviour(bossid, FAI_BOSS_BEHAVIOUR_NEUTRAL, false);
return bossid;
} else {
//FCNPC_Create failed
Expand Down Expand Up @@ -1351,6 +1357,27 @@ stock FAI_SetBossAllowNPCTargets(bossid, bool:allowNPCTargets, bool:checkForTarg
}
return 0;
}
stock FAI_GetBossBehaviour(bossid) {
if(FAI_IsValidBoss(bossid)) {
return FAI_Bosses[bossid][BEHAVIOUR];
}
return -1;
}
stock FAI_SetBossBehaviour(bossid, behaviour, bool:checkForTarget = false) {
if(FAI_IsValidBoss(bossid)) {
if(behaviour == FAI_BOSS_BEHAVIOUR_FRIENDLY || behaviour == FAI_BOSS_BEHAVIOUR_NEUTRAL || behaviour == FAI_BOSS_BEHAVIOUR_UNFRIENDLY) {
FAI_Bosses[bossid][BEHAVIOUR] = behaviour;
if(checkForTarget) {
if(behaviour == FAI_BOSS_BEHAVIOUR_FRIENDLY && FAI_Bosses[bossid][TARGET] != INVALID_PLAYER_ID) {
//Reset target
FAI_SetBossTargetWithReason(bossid, INVALID_PLAYER_ID, 0);
}
}
return 1;
}
}
return 0;
}
stock FAI_GetBossNPCID(bossid) {
if(FAI_IsValidBoss(bossid)) {
return FAI_Bosses[bossid][NPCID];
Expand Down
37 changes: 0 additions & 37 deletions src/FAI_Threat_TODO.pwn
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
//BEHAVIOUR
//Wrapper native
, behaviour = FAI_BOSS_BEHAVIOUR_NEUTRAL
//Natives
native FAI_GetBossBehaviour(bossid);
native FAI_SetBossBehaviour(bossid, behaviour, bool:checkForTarget = false);
//Damageboss
&& FAI_Bosses[bossid][BEHAVIOUR] != FAI_BOSS_BEHAVIOUR_FRIENDLY
//Update
//Only set target if the encounter has already started OR if the behaviour is unfriendly
if(FAI_Bosses[bossid][TARGET] != INVALID_PLAYER_ID || FAI_Bosses[bossid][BEHAVIOUR] == FAI_BOSS_BEHAVIOUR_UNFRIENDLY) {
}
//Wrapper implementation
, behaviour = FAI_BOSS_BEHAVIOUR_NEUTRAL
FAI_SetBossBehaviour(bossid, behaviour, false);
//Implementation
stock FAI_GetBossBehaviour(bossid) {
if(FAI_IsValidBoss(bossid)) {
return FAI_Bosses[bossid][BEHAVIOUR];
}
return -1;
}
stock FAI_SetBossBehaviour(bossid, behaviour, bool:checkForTarget = false) {
if(FAI_IsValidBoss(bossid)) {
FAI_Bosses[bossid][BEHAVIOUR] = behaviour;
if(checkForTarget) {
if(behaviour == FAI_BOSS_BEHAVIOUR_FRIENDLY && FAI_Bosses[bossid][TARGET] != INVALID_PLAYER_ID) {
//Reset target
FAI_SetBossTargetWithReason(bossid, INVALID_PLAYER_ID, 0);
}
}
return 1;
}
return 0;
}

//THREAT
//Natives
native FAI_GetBossThreatForPlayer(bossid, playerid);
native FAI_SetBossThreatForPlayer(bossid, playerid, threat, bool:checkForAggroRange = false);
Expand Down

0 comments on commit 714da0c

Please sign in to comment.