#include "in_g_cutscene"
#include "cleanup"
#include "cutscene_ch1"



void CSvoice(float oDelay, object oSelf, int iSet)
{

int iVoice;
float oDice;

 switch (iSet)
      {
       case 1: iVoice = VOICE_CHAT_ATTACK;break;
       case 2: iVoice = VOICE_CHAT_BATTLECRY1;break;
       case 3: iVoice = VOICE_CHAT_BATTLECRY2;break;
       case 4: iVoice = VOICE_CHAT_BATTLECRY3;break;
       case 5: iVoice = VOICE_CHAT_THREATEN;break;
       case 6: iVoice = VOICE_CHAT_CHEER;break;
       case 7: iVoice = VOICE_CHAT_CUSS;break;
       case 8: iVoice = VOICE_CHAT_FLEE;break;
       case 9: iVoice = VOICE_CHAT_GOODBYE;break;
       case 10: iVoice = VOICE_CHAT_THANKS;break;
       case 11: iVoice = VOICE_CHAT_WEAPONSUCKS;break;
       case 12: iVoice = VOICE_CHAT_LAUGH;break;
       case 13: iVoice = VOICE_CHAT_HELLO;break;
       case 14: iVoice = VOICE_CHAT_FOLLOWME;break;
       case 15: iVoice = VOICE_CHAT_GOODIDEA;break;
       case 16: iVoice = VOICE_CHAT_REST;break;
       case 17: iVoice = VOICE_CHAT_YES;break;


      }
DelayCommand(oDelay, AssignCommand(oSelf, PlayVoiceChat(iVoice)));
}


void MoveNPC (object oPC)
{
object oTarget;
object oTarget2;
object oCaster;

effect eEffect = EffectVisualEffect(VFX_IMP_REMOVE_CONDITION);
effect eEffect3 = EffectVisualEffect(VFX_FNF_PWSTUN);
effect eEffect2 = EffectVisualEffect(VFX_IMP_ELEMENTAL_PROTECTION);
oTarget = GetObjectByTag("love_npc");
AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("love_wp1")));
CSvoice(4.0, oTarget, 13);
DelayCommand(5.0, AssignCommand(oTarget, ActionPlayAnimation(ANIMATION_FIREFORGET_BOW)));
DelayCommand(11.0, AssignCommand(oTarget, SpeakString("I was hoping you'd be the one who completed the Arena Challenge")));
DelayCommand(15.0, AssignCommand(oTarget, SpeakString("I would love to get to know you better, so lets go have some fun together.")));
DelayCommand(11.2, AssignCommand(oTarget, ActionPlayAnimation(ANIMATION_LOOPING_TALK_PLEADING, 1.0, 4.0f)));
DelayCommand(15.5, AssignCommand(oTarget, ActionPlayAnimation(ANIMATION_FIREFORGET_VICTORY2)));
CSvoice(19.0, oPC, 15);
CSvoice(21.0, oTarget, 12);
CSvoice(23.0, oTarget, 14);
CSvoice(25.0, oPC, 17);
CSvoice(31.0, oTarget, 12);

oCaster = oTarget;
oTarget2 = GetObjectByTag("fw_portal_wp");
GestaltFace(24.5, oTarget, 0.0, 2, oTarget2);
DelayCommand(26.0, AssignCommand(oCaster,
ActionCastFakeSpellAtLocation(SPELL_BANISHMENT,
GetLocation(oTarget), PROJECTILE_PATH_TYPE_DEFAULT)));
CutsceneEffect(28.0, VFX_FNF_FIREBALL, "fw_portal_wp");
GestaltFace(28.2, oPC, 0.0, 2, oTarget2);
DelayCommand(28.0, CutscenePlace("fw_portal1", "fw_portal_wp"));
//DelayCommand(28.2, CutscenePlace("fw_light", "fw_portal_wp"));

DelayCommand(30.0, AssignCommand(oTarget,
ActionMoveToObject(GetObjectByTag("fw_portal_wpa"))));
DelayCommand(32.0, ApplyEffectAtLocation(DURATION_TYPE_INSTANT,
             eEffect, GetLocation(oTarget)));
DelayCommand(32.1, ApplyEffectAtLocation(DURATION_TYPE_INSTANT,
             eEffect2, GetLocation(oTarget)));
DelayCommand(32.2, ApplyEffectAtLocation(DURATION_TYPE_INSTANT,
             eEffect3, GetLocation(oTarget)));

GestaltJump(32.3, oTarget, OBJECT_INVALID, "lake_wp1" );

}


void CutScene2(int oNum, string sChallenge, object oPC)
{

//FloatingTextStringOnCreature("cutscene fired", oPC);

object oMod = GetModule();
object oStarfall=GetObjectByTag("starfall");
effect eEffect = EffectVisualEffect(VFX_IMP_REMOVE_CONDITION);

SetLocalInt(oPC, "cutscene_on",0);

int iSwing = GetLocalInt(oPC, "pc_CHswing");
int iHit = GetLocalInt(oPC, "pc_CHhit");
int iDam = GetLocalInt(oPC, "pc_CHdam");
int aScore = GetLocalInt(oPC, "a_score");
int oMode = GetLocalInt(oMod, "gamemode");

int iAv;
float fPerc;
int iPerc;
int tScore;


if (iHit!=0){iAv = iDam / iHit; }
else {iAv = 0;}

if (iSwing!=0){fPerc = (IntToFloat(iHit) / IntToFloat(iSwing))*100;}
else {fPerc = 0.0;}

iPerc = FloatToInt(fPerc);

tScore = iPerc * iAv;
if (tScore!=0){aScore+=tScore;}
else {aScore += 0;}

SetLocalInt(oPC, "a_score", aScore);

object oArea = GetArea(oPC);
object oNPC;

object oSface = GetWaypointByTag("mc_facing");
object oShome = GetWaypointByTag("starfall_wp");
object oWP1=GetWaypointByTag("starfall_cswp");
object oWP2=GetWaypointByTag("pc_cswp");
object oWP3=GetWaypointByTag("test_wp");
object oWP4=GetWaypointByTag("love_wp1");
object oWP5=GetWaypointByTag("fw_portal_wp");
object oGate = GetObjectByTag("arena_gate");

string sSFtalk1, sSFtalk2,sSFtalk3,sSFtalk4,sSFtalk5,sSFtalk6,sSFtalk7,
       sSFtalk7a, sSFtalk8,sSFtalk9,sSFtalk10;

float oDelay1 = 8.0;  // congrats
float oDelay2 = 12.0; // hit & miss
float oDelay3 = 17.0; // hit %
float oDelay4 = 20.0; // damage
float oDelay7 = 26.0; // performance
float oDelay8 = 32.0; // points
float oDelay5 = 39.0; // present you with...
float oDelay6 = 50.0; // you'll enjoy
float oDelay9 = 40.0; // spawn reward
float oDelay10 = 48.0; //run to player
float oDelay9a = 51.5; //starfall dissapear effect
float oDelay9b = 52.0; //starfall port

float oDelay11 = 54.5; //Greet NPC
float oDelay12 = 54.0; //Greet PC
float oDelay13 = 40.0; //intro
float oDelay14 = 40.0; //PC: I'm....
float oDelay15 = 40.0; //NPC: I know who...
float oDelay16 = 40.0; //NPC: follwow me
float oDelay17 = 40.0; //PC: good idea
float oDelay18 = 40.0; //
float oDelay20 = 90.0; //

DelayCommand(80.0, SetLocalInt(oMod, "chest_here", 0));
CleanArea(oPC);


sSFtalk1 = "Congratulations, "+GetName(oPC)+
                  "! You have mastered the Arena of Champions Challenge";
sSFtalk2 = "During the ultimate challenge, you took "+IntToString(iSwing)+" swings and landed "+IntToString(iHit)+" blows.";
sSFtalk3 = IntToString(iPerc)+"% of your attacks found their mark.";
sSFtalk4 = "You dealt a total of "+IntToString(iDam)+" damage with an average of "+IntToString(iAv)+" per hit.";
sSFtalk5 = "I now present you with your final prize";
sSFtalk6 = "I think you'll enjoy this one...*chuckle*";

if (iPerc>=0) {sSFtalk7 = "Your final performance was one of little or no skill "; }
if (iPerc>10) {sSFtalk7 = "Your final performance was one of very low skill "; }
if (iPerc>20) {sSFtalk7 = "Your final performance was one of average skill "; }
if (iPerc>30) {sSFtalk7 = "Your final performance was one of moderate skill "; }
if (iPerc>40) {sSFtalk7 = "Your final performance was one of high skill "; }
if (iPerc>50) {sSFtalk7 = "Your final performance was one of very high skill "; }
if (iPerc>60) {sSFtalk7 = "Your final performance was one of impressive skill "; }
if (iPerc>70) {sSFtalk7 = "Your final performance was one of superior skill "; }
if (iPerc>80) {sSFtalk7 = "Your final performance was one of incredible skill "; }
if (iPerc>90) {sSFtalk7 = "Your final performance was one of supreme skill "; }

if (iAv>=0) {sSFtalk7a = "and almost no power!"; }
if (iAv>10) {sSFtalk7a = "and very low power!"; }
if (iAv>20) {sSFtalk7a = "and low power!"; }
if (iAv>30) {sSFtalk7a = "and average power!"; }
if (iAv>50) {sSFtalk7a = "and threatening power!"; }
if (iAv>70) {sSFtalk7a = "and overwhelming power!"; }
if (iAv>100) {sSFtalk7a = "and formidible power!"; }
if (iAv>110) {sSFtalk7a = "and incredible power!"; }
if (iAv>120) {sSFtalk7a = "and supreme power!"; }
if (iAv>150) {sSFtalk7a = "and devastating power!"; }

sSFtalk7+=sSFtalk7a;

sSFtalk8 = "You have been awarded a special bonus of "+IntToString(tScore)+" championship points, giving you a grand total of "+IntToString(aScore)+" points";

GestaltStartCutscene(oPC, "",TRUE,TRUE,TRUE,TRUE,2);
GestaltCameraFade(0.0,  oPC,   FADE_IN,FADE_SPEED_SLOW);

GestaltPlayMusic(0.0, oArea, TRUE, TRACK_HOTU_BATTLE_LARGE);

PortIn(2.5, oStarfall, oWP1, oWP1, oWP2, 0);

GestaltActionMove(0.0,oPC, oWP2, TRUE, 0.0, 5.0);
GestaltFace(6.0, oPC, 0.0, 2, oWP1);


GestaltSpeak(oDelay1,  oStarfall, sSFtalk1,
             ANIMATION_FIREFORGET_VICTORY1);
GestaltSpeak(oDelay2,  oStarfall, sSFtalk2,
             ANIMATION_NONE);
GestaltSpeak(oDelay3,  oStarfall, sSFtalk3,
             ANIMATION_NONE);
GestaltSpeak(oDelay4,  oStarfall, sSFtalk4,
             ANIMATION_NONE);
GestaltSpeak(oDelay7,  oStarfall, sSFtalk7,
             ANIMATION_NONE);
GestaltSpeak(oDelay8,  oStarfall, sSFtalk8,
             ANIMATION_NONE);

GestaltSpeak(oDelay5,  oStarfall, sSFtalk5,
             ANIMATION_FIREFORGET_BOW);
GestaltSpeak(oDelay6,  oStarfall, sSFtalk6,
             ANIMATION_NONE);
GestaltFace(oDelay5+4.0, oPC, 0.0, 2, oWP3);

CSvoice(oDelay5+8.0, oPC, 6);

if (oMode==1){DelayCommand(oDelay9, Reward(oPC, 10));}
else {DelayCommand(oDelay9, Reward(oPC, 9));}

PortIn(48.0, oStarfall, oWP1, oShome, oSface, 1);

DelayCommand(oDelay10, MoveNPC(oPC));

GestaltActionAnimate(oDelay11, oPC, ANIMATION_FIREFORGET_BOW);
CSvoice(oDelay11, oPC, 13);

SetLocalFloat(oPC,"fCameraDirection",120.0);
SetLocalFloat(oPC,"fCameraRange",18.0);
SetLocalFloat(oPC,"fCameraPitch",60.0);


GestaltCameraMove       (0.0,
                             120.0,18.0,60.0,
                             300.0, 20.0,60.0,
                            10.0,30.0,oPC);

 GestaltCameraMove       (10.0,
                           300.0,20.0,60.0,
                           325.0,22.0,60.0,
                            5.0,30.0,oPC);

GestaltCameraMove       (15.0,
                            325.0,22.0,60.0,
                            330.0,17.0,60.0,
                            5.0,30.0,oPC);

GestaltCameraMove       (20.0,
                            330.0,17.0,60.0,
                            345.0,9.0,76.0,
                            5.0,30.0,oPC);

GestaltCameraMove       (71.0,
                            345.0,9.0,76.0,
                            390.0,10.0,67.0,
                            5.0,30.0,oPC);



GestaltCameraFade       (84.0, oPC,   FADE_OUT, FADE_SPEED_SLOW);
GestaltStopCutscene     (87.0, oPC);

DelayCommand(88.0, MusicBackgroundChangeDay(GetArea(oPC), 0));
DelayCommand(88.0, MusicBackgroundChangeNight(GetArea(oPC), 0));
DelayCommand(89.0, MusicBackgroundStop(GetArea(oPC)));

}

//void main () {}