#include "prc_inc_spells"

// * colors are: "darkred",  "darkblue",  "darkgreen",
//               "lightred", "lightblue", "lightgreen",
//               "white",    "random"
const string DEBUGCOLOR = "white";

void Debug(string sData, string sLabel = "String");
void Debugi(int iData, string sLabel = "Int   ");
void Debugf(float fData, string sLabel = "Float ");
void Debugo(object oData, string sLabel = "Object");
void ToAll(string s);
void ObjectRoleCall();
void ItemRoleCall();
string GetAllIPs(object oItem);
string IPType(int i);
void ObjectAquisitionLastRoleCall();
void ObjectAquisitionTagBasedRoleCall();

// 0-255:  !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ¡¢£¤¥§¨©ª«¬­®¯°±²³´µ¶·¸¸º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïñòóôõö÷øùúûüýþ
string Colorfy(string s, string color = "random");

// returns a three digit string usable by other textblitz functions
string RandomColor();

void Debug(string sData, string sLabel = "String")
{
  ToAll(sLabel + ": " + sData);
}

void Debugi(int iData, string sLabel = "Int")
{
  ToAll(sLabel + ": " + IntToString(iData));
}

void Debugf(float fData, string sLabel = "Float")
{
  ToAll(sLabel + ": " + FloatToString(fData));
}

void ToAll(string s)
{
  object oPC = GetFirstPC();
  while(GetIsObjectValid(oPC))
  {
    FloatingTextStringOnCreature(Colorfy(s, DEBUGCOLOR), oPC, FALSE);
    oPC = GetNextPC();
  }
}

// returns a three digit string usable by other textblitz functions
string RandomColor()
{
  string x = "!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ¡¢£¤¥§¨©ª«¬­®¯°±²³´µ¶·¸¸º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïñòóôõö÷øùúûüýþ";
  string c1 = "";
  string c2 = "";
  string c3 = "";
  while (c1 == "") c1 = GetSubString(x, Random(251), 1);
  while (c2 == "") c2 = GetSubString(x, Random(251), 1);
  while (c3 == "") c3 = GetSubString(x, Random(251), 1);
  return c1 + c2 + c3;
}

string Colorfy(string s, string color = "random")
{
  if (color == "darkred")    color = "~  ";
  if (color == "lightred")   color = "þ  ";
  if (color == "darkblue")   color = "  ~";
  if (color == "lightblue")  color = "  þ";
  if (color == "darkgreen")  color = " ~ ";
  if (color == "lightgreen") color = " þ ";
  if (color == "white")      color = "þþþ";
  if (color == "random")     color = RandomColor();
  return "<c" + color + ">" + s + "</c>";
}

void ObjectRoleCall()
{
  ToAll("*** *** *** OBJECT ROLE CALL *** *** ***");
  object oArea = GetArea(GetFirstPC());
  object o = GetFirstObjectInArea(oArea);
  while(GetIsObjectValid(o))
  {
    Debug("Here", GetName(o));
    o = GetNextObjectInArea(oArea);
  }
}

void ItemRoleCall()
{
  ToAll("*** *** *** ITEM ROLE CALL *** *** ***");
  object oPC = GetFirstPC();
  object oItem = GetFirstItemInInventory(oPC);
  while(GetIsObjectValid(oItem))
  {
    Debug(GetAllIPs(oItem), GetName(oItem));
    oItem = GetNextItemInInventory(oPC);
  }
  int i = 0;
  for(i=0;i<14;i++)
  {
    oItem = GetItemInSlot(i, oPC);
    if (GetIsObjectValid(oItem)) Debug(GetAllIPs(oItem), GetName(oItem));
  }
}

string GetAllIPs(object oItem)
{
  string s = "IPs are: ";
  itemproperty ip = GetFirstItemProperty(oItem);
  while(GetIsItemPropertyValid(ip))
  {
    s += " > " + IntToString(GetItemPropertyType(ip)) + " " + IntToString(GetItemPropertySubType(ip)) + " " + IntToString(GetItemPropertyDurationType(ip)) + " < ";
    ip = GetNextItemProperty(oItem);
  }
  return s;
}

void Debugo(object oData, string sLabel = "Object")
{
  ToAll(sLabel + ": " + GetName(oData));
}

void ObjectAquisitionLastRoleCall()
{
  ToAll("*** *** *** AQUISITION LAST ROLE CALL *** *** ***");
  Debugo(GetLastAttacker(), "GetLastAttacker");
  Debugo(GetLastClosedBy(), "GetLastClosedBy");
  Debugo(GetLastDamager(), "GetLastDamager");
  Debugo(GetLastDisarmed(), "GetLastDisarmed");
  Debugo(GetLastDisturbed(), "GetLastDisturbed");
  Debugo(GetLastHostileActor(), "GetLastHostileActor");
  Debugo(GetLastKiller(), "GetLastKiller");
  Debugo(GetLastLocked(), "GetLastLocked");
  Debugo(GetLastOpenedBy(), "GetLastOpenedBy");
  Debugo(GetLastPCRested(), "GetLastPCRested");
  Debugo(GetLastPCToCancelCutscene(), "GetLastPCToCancelCutscene");
  Debugo(GetLastPerceived(), "GetLastPerceived");
  Debugo(GetLastPlayerDied(), "GetLastPlayerDied");
  Debugo(GetLastPlayerDying(), "GetLastPlayerDying");
  Debugo(GetLastRespawnButtonPresser(), "GetLastRespawnButtonPresser");
  Debugo(GetLastSpeaker(), "GetLastSpeaker");
  Debugo(GetLastSpellCaster(), "GetLastSpellCaster");
  Debugo(GetLastTrapDetected(), "GetLastTrapDetected");
  Debugo(GetLastUnlocked(), "GetLastUnlocked");
  Debugo(GetLastUsedBy(), "GetLastUsedBy");
  Debugo(GetPCItemLastEquipped(), "GetPCItemLastEquipped");
  Debugo(GetPCItemLastEquippedBy(), "GetPCItemLastEquippedBy");
  Debugo(GetPCItemLastUnequipped(), "GetPCItemLastUnequipped");
  Debugo(GetPCItemLastUnequippedBy(), "GetPCItemLastUnequippedBy");
  Debugo(GetPlaceableLastClickedBy(), "GetPlaceableLastClickedBy");
}

void ObjectAquisitionTagBasedRoleCall()
{
  ToAll("*** *** *** AQUISITION TAGBASED ROLE CALL *** *** ***");
  Debugo(PRCGetSpellCastItem(), "PRCGetSpellCastItem");
  Debugo(PRCGetSpellTargetObject(), "PRCGetSpellTargetObject");
  Debugo(GetItemActivator(), "GetItemActivator");
  Debugo(GetItemActivated(), "GetItemActivated");
  Debugo(GetPCItemLastEquippedBy(), "GetPCItemLastEquippedBy");
  Debugo(GetPCItemLastEquipped(), "GetPCItemLastEquipped");
  Debugo(GetPCItemLastUnequippedBy(), "GetPCItemLastUnequippedBy");
  Debugo(GetPCItemLastUnequipped(), "GetPCItemLastUnequipped");
  Debugo(GetModuleItemAcquiredBy(), "GetModuleItemAcquiredBy");
  Debugo(GetModuleItemAcquired(), "GetModuleItemAcquired");
  Debugo(GetModuleItemLostBy(), "GetModuleItemLostBy");
  Debugo(GetModuleItemLost(), "GetModuleItemLost");
  Debugo(PRCGetSpellTargetObject(), "PRCGetSpellTargetObject");
}