Author Topic: Help Thinking About a Function (or two)  (Read 450 times)

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Help Thinking About a Function (or two)
« on: November 16, 2011, 04:09:13 am »


               I'd like the community's help thinking about the best way to approach a problem that I've been wrestling with lately and can't seem to wrap my head around an elegant way to solve.

I have a quest-based server.  PCs go to a quest-giver in their respective faction area and are assigned a quest to complete.  Once complete, they return and get a new quest.  Each quest is assigned a unique identifying integer for scripting purposes (098 - 120, for example).  In standard fashion, quests are assigned a status (1, 2, or 3) to indicate the level of completion for that quest.  1= quest started.  2= completed, but not yet advanced to next quest.  3= quest completed fully and advanced to next quest.  Quests and their status are stored on a player database item.

Where it gets tricky is that not everyone follows the same quest progression path.  Members of the elven faction may do quests 101, 103, 104, and 106 as their first quests.  Dwarves may do quests 105, 107, 108 as theirs.  Eventually the quests do combine into a single thread that everyone follows, though I may still want to diverge paths again for future quests.  Some factions have "starting" quests that are specific to only that faction (such as the first dwarven quest - 105) before joining up with quests that may also include other, but possibly not all, factions (such as quests 107 and 108 in the dwarven example).

I've scripted everything and it works fine...at least it did when I railroaded PCs into a faction and did not allow them to voluntarily switch factions (why would a dwarf want to leave the dwarven faction anyway??).  I've recently overhauled my faction rules and added the ability for PCs to switch factionswithin some limitations (dwarves can now go live among the humans, though humans are not allowed to go live among the dwarves).

The problem with this is I now need to add functionality to my quest system to do a couple of things to accomodate new/changed faction members:

1)  Identify whether or not the faction has a "starting quest" and if it does, check to see if the quest has been assigned (quest status >=1).  To my mind this is fairly straightforward.  I can create a simple function that identifies the quest numbers of all the starting factions.  When a PC joins as a new member of a faction, check to see if the starting quest is completed.  If it isn't, the quest assigned becomes the starting quest.  If it is, well, see below.

2)  Identify the appropriate non-starting quest.  Here's where I run into trouble.  It's possibly best explained through an example:  A dwarf starts his life in the dwarven faction and completes the starting quest (105).  He then leaves the dwarves to live among humans.  He does that starting quest (99) and subsequently finishes another quest (100).  After that, he comes to his senses and returns to join the dwarven faction again.  He's successfully finished the starting quest (as identified through the function of #1 above), but now I need to determine what his next quest is.  For a dwarf it would be 107.  I need to figure out a way to sort through the different non-consecutive permutations of a quests, check to see if a quest should be completed by that faction, and if it has been competed, check the next one.  If it hasn't been completed/assigned - assign it.

I could probably do something kludgy, but figure that the community myght have some thoughts about how to approach this connundrum. 

Thanks!