// A quick test of the newly added script commands
// Tests functions in script.c
//    specialmonster (map, x, y, name, class, OnDieEvent);
//      note: uses the newly added function in clif.c
//            clif_update_being_name (bl, name)
//   getmonsterstate (id, opt);
//   setmonsterstate (id, opt, val);
//   setmonsterstats (id, lvl, curhp, maxhp, str, agi, vit, int, dex, luk, att1, att2, aspd, def, mdef, spd)
//       movemonster (id, flag, x, y)

-m "Added 5 new script commands in script.c for better mob control, and 1 new function to clif.c to support dynamic mob naming."

001-1.gat,31,25,0	script	Vash	115,{
	// Uncomment line below to do specialized testing
	//goto L_TESTING;

	// Don't interact if in the middle of a maggot battle!
	if ($@VashFight == 1) end;
	
	
	mes "[Vash]";
	
	// Explain maggot battle
	if ($@VashLevel == 1) goto L_INTRO;
	
	// Message for 2+ interaction
	if ($@VashLevel < 10) goto L_REMATCH;
	
	// Else give completed message
	mes "\"Wow you are strong. I don't think I can beat you after all."
	+ " Too bad I dont have a special item like a sand badge to give you."
	+ " I guess you will just have to settle for a pat on the back.";
	close;

L_INTRO:
	mes "\"I am a maggot trainer. I only challenge the very best."
	+ " Do you think you are strong enough to face my maggot?\"";
	
	menu
	"Show me the maggot!", L_SPAWN,
	"Yuck, get away from me.",-;
	mes "Ha, only the weak back away from a challenge.";
	close;

L_REMATCH:
	mes "\"I have trained my maggot better than he was before. Better..."
	+ "stronger...faster. Are you ready for round " + $@VashLevel + "?\"";
	
	menu
	"Let's get ready to rumble!", L_SPAWN,
	"Your maggotfu is too strong.",-;
	mes "Yes, I am the greatest trainer there ever was and ever will be";
	close;
	goto L_SPAWN;

L_SPAWN:
	set $@VashFight, 1;
	
	// Spawns a mob and returns its ID for later use.
	// It also sets its target name for anyone on the map when it is spawned (if someone logs in or warps, they see the default).
	set $@maggotID, specialmonster("001-1.gat",31,28,"Magachu",1002,"Vash::OnDeadMaggot");
	
	// Alter the mob's default mob_db combat stats. NOTE: must be able to provide the mob's ID.
	// ID, lvl, curHP, maxHP, str, agi, vit, int, dex, luk, minDMG, maxDMG, aspd, def, mdef, spd
	// use -1 to leave as original value
	setmonsterstats $@maggotID, ($@VashLevel * 11), ($@VashLevel * 1100), ($@VashLevel * 1100),
		($@VashLevel * 11), ($@VashLevel * 11), ($@VashLevel * 11),
		($@VashLevel * 11), ($@VashLevel * 11), ($@VashLevel * 11),
		($@VashLevel * 10), ($@VashLevel * 13), -1,
		($@VashLevel * 2), ($@VashLevel * 5), -1;
	
	// Make the otherwise unagressive mob be aggressive at spawn time.
	// The mode numbers work just like the ones used in mob_db.
	// NOTE: must be able to provide the mob's ID.
	setmonsterstate $@maggotID, mob_mode, 141;	
	
	// Some visual spice.
	npctalk "Magachu, I choose you!!";
	misceffect 3, $@maggotID;	// NOTE: you can now place misc effects directly on mobs if you have their id.
	
	// Start timer to trigger special moves every 5 seconds.
	initnpctimer;
	
	mes "Challenge Accepted. Now Fight!";
	close;


// -------------------------------------
// -----  Special Attack Routines  -----
// -------------------------------------

L_TAUNT:
	// Use the random number already generated to pick the taunt message.
	npctalk $@VashStrings$[$@VashAttack];
	end;

L_ATT1:
	npctalk "Magachu teleport";
	
	// Warps the mob to the location
	// NOTE: To testing the moveto versio put a 1 instead of 0 as the second parameter.
	movemonster $@maggotID, 0, (27 + rand(9)),(25 + rand(7));
	
	end;

L_ATT2:
	set $@VashTemp, getmonsterstate($@maggotID, $@mob_target);
	
	// IMPORTANT: Don't do anything if the targeted character is not logged in anymore!
	if (isloggedin($@VashTemp) == 0) end;
	
	npctalk "Magachu poison sting";
	sc_start sc_poison, 1, 20, $@VashTemp;
	end;

L_ATT3:
	set $@VashTemp, (getmonsterstate($@maggotID, $@mob_pdef) + 5);

	// Don't do anything if the defense is already too high.
	if($@VashTemp > 95) end;
	
	// Else increase defense
	setmonsterstate $@maggotID, mob_pdef, $@VashTemp;
	
	npctalk "Magachu harden";
	misceffect 6, $@maggotID;
	end;

L_ATT4:
	set $@VashTemp, getmonsterstate($@maggotID, $@mob_target);
	
	// IMPORTANT: Don't do anything if the targeted character is not logged in anymore!
	if (isloggedin($@VashTemp) == 0) end;
	
	attachrid($@VashTemp);
	
	npctalk "Magachu thundershock";
	heal ($@VashLevel * -30), 0;
	misceffect (17 + rand(3)), $@VashTemp;
	end;


// --------------------------
// -----  Event Labels  -----
// --------------------------

OnDeadMaggot:
	if ($@VashLevel < 9) npctalk "I will train harder and beat you next time!";
	misceffect 5, $@maggotID;
	getexp ($@VashLevel * 1000), 0;
	set $@VashFight, 0;
	set $@VashLevel, $@VashLevel + 1;
	end;

OnTimer10000:
	// Do nothing if the special maggot has already been killed.
	if ($@VashFight == 0) end;
	
	// Else, the battle is still going.
	// Reset the timer to start the special attack countdown again.
	setnpctimer 0;
	
	// Use to test a specific attack
	//goto L_ATT1;
	//goto L_ATT2;
	//goto L_ATT3;
	//goto L_ATT4;
	
	set $@VashAttack, (rand(100) + ($@VashLevel * 3));
	
	// there is a 30 - 3 * lvl % chance of doing nothing every 10 seconds.
	if ($@VashAttack < 30) end;
	
	// Just says something
	if ($@VashAttack < 45) goto L_TAUNT;
	
	// Does a short distance teleport.
	if ($@VashAttack < 60) goto L_ATT1;
	
	// Poisons the player
	if ($@VashAttack < 85) goto L_ATT2;
	
	// Increases def and mdef
	if ($@VashAttack < 95) goto L_ATT3;
	
	// Else  there is a 5 + 3 * lvl % chance of doing a big attack.
	goto L_ATT4;
	
	end;

OnInit:
	set $@VashFight, 0;
	set $@VashLevel, 1;
	set $@VashAttack, 0;
	
	// temporary listing of vars placed in my copy of const.txt
	set $@mob_pdef, 11;
	set $@mob_target, 19;
	
	// Taunt strings with offset based on the random number range to trigger.
	// Note: some entries are duplicated to increase the chance of being used.
	set $@VashStrings$[30], "Grrraaa....CRAB BATTLE!!!";
	set $@VashStrings$[31], "Attack its weak point for massive damage";
	set $@VashStrings$[32], $@VashStrings$[31];
	set $@VashStrings$[33], "Gotta catch 'em all!";
	set $@VashStrings$[34], $@VashStrings$[33];
	set $@VashStrings$[35], "It's time to duel!";
	set $@VashStrings$[36], "BELIEVE IT!";
	set $@VashStrings$[37], "Its over 9000!";
	set $@VashStrings$[38], $@VashStrings$[37];
	set $@VashStrings$[39], $@VashStrings$[37];
	set $@VashStrings$[40], "Knowing is half the battle!";
	set $@VashStrings$[41], "Do You Feel Lucky Punk?";
	set $@VashStrings$[42], "Say Hello To My Little Friend";
	set $@VashStrings$[43], $@VashStrings$[42];
	set $@VashStrings$[44], "I feel a great disturbance in the force";
	
	end;


// ------------------------------------------
// -----  Supplemental Testing Section  -----
// ------------------------------------------

L_TESTING:
	// Create a test mob if one isn't already in existence.
	if ($@VashFight == 0) goto L_TEST_INIT;
	
	// Uncomment the corresponding goto line to start that test
	
	// Thorough test for getmonsterstate/setmonsterstate
	//goto L_GETSET;
	
	// Testing the set target option, kind of fun to play around with ;)
	//goto L_TARGETING;
	
	end;

L_TEST_INIT:
	set $@maggotID, specialmonster("001-1.gat",31,28,"TEST",1002,"Vash::OnDeadMaggot");
	set $@VashFight, 1;
	goto L_TESTING;

L_GETSET:	// Just check that nothing crashes the map-server.
	setmonsterstate $@maggotID, 0, 0;
	npctalk "New level: " + getmonsterstate($@maggotID, 0);
	setmonsterstate $@maggotID, 1, 1;
	npctalk "New max HP: " + getmonsterstate($@maggotID, 1);
	setmonsterstate $@maggotID, 2, 2;
	npctalk "New STR: " + getmonsterstate($@maggotID, 2);
	setmonsterstate $@maggotID, 3, 3;
	npctalk "New AGI: " + getmonsterstate($@maggotID, 3);
	setmonsterstate $@maggotID, 4, 4;
	npctalk "New VIT: " + getmonsterstate($@maggotID, 4);
	setmonsterstate $@maggotID, 5, 5;
	npctalk "New INT: " + getmonsterstate($@maggotID, 5);
	setmonsterstate $@maggotID, 6, 40;
	npctalk "New DEX: " + getmonsterstate($@maggotID, 6);
	setmonsterstate $@maggotID, 7, 7;
	npctalk "New LUK: " + getmonsterstate($@maggotID, 7);
	setmonsterstate $@maggotID, 8, 8;
	npctalk "New min damage: " + getmonsterstate($@maggotID, 8);
	setmonsterstate $@maggotID, 9, 9;
	npctalk "New max damage: " + getmonsterstate($@maggotID, 9);
	setmonsterstate $@maggotID, 10, 500;
	npctalk "New attack speed: " + getmonsterstate($@maggotID, 10);
	setmonsterstate $@maggotID, 11, 11;
	npctalk "New phys def: " + getmonsterstate($@maggotID, 11);
	setmonsterstate $@maggotID, 12, 12;
	npctalk "New magic def: " + getmonsterstate($@maggotID, 12);
	setmonsterstate $@maggotID, 13, 500 ;
	npctalk "New speed: " + getmonsterstate($@maggotID, 13);
	setmonsterstate $@maggotID, 14, 200; 	// Seems like xp bonus is only effective from 0-63 and anything higher has an effect of mod 63 on xp.
	npctalk "New xp bonus: " + getmonsterstate($@maggotID, 14);
	setmonsterstate $@maggotID, 15, 133;	// maggots are normally non agressive
	npctalk "New mode: " + getmonsterstate($@maggotID, 15);
	setmonsterstate $@maggotID, 16, 25;
	npctalk "New x: " + getmonsterstate($@maggotID, 16) + " Old y: " + getmonsterstate($@maggotID, 17);
	setmonsterstate $@maggotID, 17, 29;
	npctalk "Old x: " + getmonsterstate($@maggotID, 16) + " New y: " + getmonsterstate($@maggotID, 17);
	setmonsterstate $@maggotID, 18, 18;	// NOTE: set to 18 but cur > max, when attacked it is set to max.
	npctalk "New cur hp: " + getmonsterstate($@maggotID, 18);
	setmonsterstate $@maggotID, 19, getcharid(3);	// NOTE: does nothing right now, couldn't get it to work.
	npctalk "Currently targeting: " + getmonsterstate($@maggotID, 19);	// It does get the account id of the current target (which is also the blocklist ref number for the character)
	setmonsterstate $@maggotID, 20, 20;	// use the default types, not sure what random vals do
	npctalk "New elemental type: " + getmonsterstate($@maggotID, 20);
	setmonsterstate $@maggotID, 21, 21 ;	// I havent ever tested this, not sure how size affects combat
	npctalk "New size: " + getmonsterstate($@maggotID, 21);
	end;

// Setting targets isn't very reliable.
// It would be better to not rely on this feature until I can find out why it doesn't always switch.
L_TARGETING:
	setmonsterstate $@maggotID, 15, 133;
	mes "Who to target? Input their name exactly as it appears (case sensitive).";
	input $VashTarget$;
	setmonsterstate $@maggotID, 19, getcharid(3, $VashTarget$);
	mes "Currently targeting: " + getmonsterstate($@maggotID, 19);
	close;
}
