Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Simple quest tutorial. (Kill a monster X times, then return for reward template.)
- * Author: Slowhand
- * Reviewer:
- */
- #include "math.fos"
- #include "_colors.fos"
- #define LOCATION_TUT_KILLMOBS (91)
- /**< Spawn a location from a dialogue at random location withing the specified parameters. */
- void r_SpawnLoc(Critter& player, Critter@ npc, int locationGameVar, int locationId, int minCoordX, int minCoordY, int maxCoordX, int maxCoordY)
- {
- /**< Get a randomized position on the map within limits */
- uint worldCoordX = getRandomXCoordsBetween(minCoordX, maxCoordX);
- uint worldCoordY = getRandomYCoordsBetween(minCoordY, maxCoordY);
- /**< Get the local game variable, which will be used to store the location Id, so it can be deleted later. */
- GameVar@ locationVariable = GetLocalVar(locationGameVar, player.Id);
- /**< Spawns the quest location. Use the macro LOCATION_YOUR_QUEST_NAME to specify the unique location that you saved your map and location to, in world editor. */
- spawnQuestLocationWithCoords(player, locationVariable, locationId, worldCoordX, worldCoordY, true);
- }
- /**< Dialog function used in request to delete quest location (after player report finishing the quest) */
- void r_DeleteLoc(Critter& player, Critter@ npc, int locationGameVar)
- {
- if (isQuestLocationIdValid(Critter& player, locationGameVar))
- {
- DeleteLocation(getQuestLocationId(Critter& player, locationGameVar));
- }
- }
- /**< LOGIC */
- void spawnQuestLocationWithCoords(Critter& player, GameVar@ gameVariable, int locationId, int coordX, int coordY, bool turnBasedAvailable)
- {
- if (locationId < 1)
- return;
- /**< Create quest location with the specified Id */
- Critter@[] critters = { player };
- int loc = CreateLocation(locationId, coordX, coordY, critters);
- if(loc == 0)
- return;
- /**< Make the location visible to the player. */
- player.SetKnownLoc(true, loc);
- /**< Set the location color on the map */
- Location@ location = GetLocation(loc);
- if (!valid(location))
- {
- /**< Log and return. This should never happen. */
- return;
- }
- location.Color = COLOR_QUEST_LOC;
- /**< Allow Turned Based fights in location */
- if (turnBasedAvailable)
- {
- SetTurnBasedAvailability(location);
- }
- /**< Set location id to the quests local variable (used when you need to delete location) */
- setQuestLocationId(loc);
- /**< Player can die and come back, but location has to be deleted later */
- location.AutoGarbage = false;
- /**< Update the location */
- location.Update();
- }
- /**< END OF: Logic */
- /**< AUX */
- uint getRandomXCoordsBetween(uint minCoordX, uint maxCoordX)
- {
- uint zoneCoordX = CLAMP(Random(minCoordX, maxCoordX), 0, __GlobalMapWidth - 1);
- uint worldCoordX = zoneCoordX * __GlobalMapZoneLength;
- return worldCoordX;
- }
- uint getRandomYCoordsBetween(uint minCoordY, uint maxCoordY)
- {
- uint zoneCoordY = CLAMP(Random(minCoordY, maxCoordY), 0, __GlobalMapWidth - 1);
- uint worldCoordY = zoneCoordY * __GlobalMapZoneLength;
- return worldCoordY;
- }
- /**< END OF: Aux */
- /**< Setters */
- void setQuestLocationId(Critter& player, int locationId)
- {
- GameVar@ locid = GetLocalVar(LVAR_q_tut_killmobs_loc, player.Id);
- if (valid(locid))
- {
- locid = locationId;
- }
- }
- /**< Getters */
- /**< This feels off, because the return value reports errors as well. */
- int getQuestLocationId(Critter& player, int locationGameVarId)
- {
- GameVar@ locationId = GetLocalVar(locationGameVarId, player.Id);
- if (valid(locationId))
- {
- return locationId.GetValue();
- }
- else
- {
- /**< Need to do some logging here. */
- return -1;
- }
- }
- /**< Checkers */
- /**< Check if the location is exists. */
- bool isQuestLocationIdValid(Critter& player, int locationGameVarId)
- {
- GameVar@ locationId = GetLocalVar(locationGameVarId, player.Id);
- if (valid(locationId))
- {
- if (locationId.GetValue() > 0)
- {
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement