UPDATED FEB13: Inventory+Random Item Gen

Talk about making games.

UPDATED FEB13: Inventory+Random Item Gen

Postby EvanAgain » Thu Jan 24, 2013 11:34 pm

Updated GED February 13, 2013


HOW TO USE:

Notes:
The green background canvas is not a part of the inventory. This area is used for generating items to display the random creation function.

The white box is the display information for hovered items. It does not clear on mouse exit. Its just a debug box.


Left Mouse Button Down on GREEN Canvas Generates a random Item.

Left Mouse Button Down on ITEM will add it to an available slot in the inventory.

Right Mouse Button HELD Down on an ITEM will allow you to drag the ITEM around.

KEYBOARD Key 'i' for INVENTORY will display the inventory.

Hover over ANY option and LEFT Mouse Button Down and it will display ALL contents of the inventory. THIS IS NOT A BUG. (Apparel and Quest Features yet to be implemented)

Hover over inventory item to display the stats of the item in the display window.

Keyboard 'i' Down again will "close" the inventory.

______________________________

Template Code, Just Add Actor Variables:

Code: Select all
//Script for items

//*************************************************************************
//
//   THIS AREA IS FOR NOTES FOR FUTURE IMPLEMENTATION:
//
//   Formula for Measured Attack Speed:
//    Attack speed = (Attack Speed * Weapon Attack Speed) +
//                   ((Attack Speed * Weapon Attack Speed)* EQUIPMODS)
//
//
//


//*************************
// Actor Variables:       |
//   ItemName             |
//   ItemMagicType        |
//   ItemBaseType         |
//   ItemMod1             |
//   ItemMod2             |
//   ItemMod3             |
//   ItemMod4             |
//*************************



//*************************
//   BaseItem Struct      |
//   is used to create    |
//   basic items for use. |
//*************************


struct BaseItem;

typedef struct BaseItem{
    char itemName[30];
    int  itemType; //0-None, 1-Weapon, 2-Off-hand, 3-Chest, 4-Pants, 5-Boots,
                   //      6-Gloves, 7-Helm, 8-Rings, 9-Amulet, 10-Potion, 11-Quest
 
    int  itemPoints;  //Damage, Defense, Healing
 
    float itemRate;   //Attack Speed, Healing Speed, Blocking Rate
 
    int  itemValue;   //Sell price
 
    int  itemStack; //0: Not stackable;; 1 or more: Stackable
 
}BaseItem;


//*******************************************************************************************
//   This is used to template new Item Modifiers for items                                  |
//                                                                                          |
//   prefix array: is used to give a Prefix to an item in naming                            |
//                                                                                          |
//   suffix array: is used to give a Suffix to an item in naming                            |
//                                                                                          |
//   modDescription: Gives a description of what the modifier does, use %d                  |
//                    for point mods such as Damage increases.                              |
//                                                                                          |
//   modType: This is used to identify the type of modification.                            |
//                                                                                          |
//                                                                                          |
//   modPointsPrefix:  Add points based on if its a Prefix.                                 |
//                                                                                          |
//   modPointsSuffix:  Add points based on if its a Suffix.                                 |
//                                                                                          |
//   modPercPrefix:    Add percentage mod for Prefix.                                       |
//                                                                                          |
//   modPercSuffix:    Add percentage mod for Suffix.                                       |
//                                                                                          |
//   special:   Idenifier for adding special effects.                                       |
//                                                                                          |
//*******************************************************************************************

 
struct ItemModifier;

typedef struct ItemModifier{
    char prefix[30];
    char suffix[30];
    char modDescription[150];
    int  modType; //Types of mods availible based on integer value
    int  modPointsPrefix;
    int  modPointsSuffix;
    float  modPercPrefix;      //0.0 - 1.0
    float  modPercSuffix;
    float  modValue;         //Percentage of value increase
    int  special;        //Special Modifiers for increased funness and awesome.
}ItemModifer;





struct SimpleRect;
typedef struct SimpleRect{
    int x;
    int y;
    int width;
    int height;
 
}SimpleRect;


SimpleRect WF_Selector = {0,0,0,0};






const int INVENTORY_MAX = 20;
const int INVEN_MAX_NAME_VALUE = 30;
int Inventory[INVENTORY_MAX][8];
char Inventory_ItemName[INVENTORY_MAX][150];

const int MENU_MAX_INDEX = 5;
int MenuButtons[MENU_MAX_INDEX];
char MenuButtonTexts[MENU_MAX_INDEX][10] = {"Weapons", "Apparel", "Potions", "Quest", "Misc"};

int MenuOpened = 0;








       //**************************************************
       //  When adding more items to the mod list,
       //  or to the base items list, the array size
       //  will have to be increased to the exact number
       //  of Modifers, or Base Items, respectively.
       //
       //**************************************************

          const int MODNUM = 6;
          const int BASENUM = 6;
          ItemModifer ItemModList[MODNUM+1];
          BaseItem BaseItemList[BASENUM];






char MagicTypes[10][50] = {"Normal", "Magic", "Magic", "Magic" , "Rare", "Rare", "Epic"};

char RareNamePrefix[10][50] = {"Wolf ", "Brutal ", "Raven ", "Toad ", "Dark ",
                                "Regal ", "Heavy ", "Torch ", "Cold ", "Bloody "};
 
char RareNameSuffix[10][50] = {"Tower", "Finger", "Wood", "Steel", "Grip",
                                "Stare", "Killer", "Shank", "Spike", "Water"};
 
char EpicNamePrefix[10][50] = {"Cow ", "Forgotten ", "Tasty ", "Horrid ", "Spectral ",
                                "Eclipsing ", "Red ", "For The ", "Historical ", "Buried "};
 
char EpicNameSuffix[10][50] = {"Pie", "Forever", "Hand", "Me", "Razor",
                                "Dawn", "Horde", "Ransom", "Rum", "...yeah"};


//******************************
//   Function Prototyping      |
//******************************

Actor* ITEM_CreateRandom(int x, int y);
void ITEM_SetRandomMods(Actor* myActor);
void ITEM_InitMods();
void ITEM_InitBaseItems();
void ITEM_GetDescription(Actor* myActor, char description[]);
int  ITEM_GetWeaponDamage(Actor* myActor, float equipMod);
void ITEM_GetModDesc(Actor* myActor, int modifier, char description[],int prefix);
Actor* ITEM_CreateSpecificItem(int x, int y, int baseType, int magicType,
                               int mod1, int mod2, int mod3, int mod4 );

void INVEN_Init();
void INVEN_ClearSlot(int slot);
void INVEN_AddItem(Actor* myActor);
void INVEN_Replace(int removedItem);
void INVEN_Organize();


void MENU_InitButtons();
void MENU_ActivateDrawSelected(char fromActor[], char toCanvas[]);
void MENU_WriteTextToButton(int index);
int  MENU_AddToIndex(int clonenum);
void MENU_CreateMenuButton(int i_x, int i_y, int index);
void MENU_CreateMenu(int i_x, int i_y);
void MENU_CreateItemListButton(int i_x, int i_y, int index, int i_type);
void MENU_CreateItemList(int i_x, int i_y, int i_type);
void MENU_MoveCanvasToScreen(char Canvas[]);
void MENU_MoveCanvasOffScreen(char Canvas[]);














Actor* ITEM_CreateSpecificItem(int x, int y, int baseType, int magicType,
                               int mod1, int mod2, int mod3, int mod4 )
{
    Actor* myActor;
    char temp[100];
 
 
//************************************************
//   IMPORTANT NOTE:                             |
//       Change "Draggable". "simplegear"        |
//       to the names of your Actor and          |
//       Animation.                              |
//                                               |
//       Or simply make Actor named              |
//      "Draggable" with Animation               |
//       named "simplegear".                     |
//************************************************
 
    myActor = CreateActor("Draggable", "simplegear", "(none)", "(none)", x, y, false);

   ChangeAnimationDirection(myActor->name, STOPPED);
 

   myActor->animpos = baseType;
 
    myActor->ItemBaseType = baseType;
    myActor->ItemMagicType = magicType;
    myActor->ItemMod1 = mod1;
    myActor->ItemMod2 = mod2;
    myActor->ItemMod3 = mod3;
    myActor->ItemMod4 = mod4;
 
 
    if(myActor->ItemMagicType > 3)
    {
        strcat(temp, RareNamePrefix[rand(10)]);
        strcat(temp, RareNameSuffix[rand(10)]);
 
       if(myActor->ItemMagicType > 5)
       {
           strcpy(temp, "");
           strcat(temp, EpicNamePrefix[rand(10)]);
           strcat(temp, EpicNameSuffix[rand(10)]);
       }
    }
    else
    {
        if(myActor->ItemMagicType > 0 && myActor->ItemMagicType != 2 )
        {
           strcat(temp, ItemModList[myActor->ItemMod1].prefix);
           strcat(temp, ItemModList[myActor->ItemMod2].prefix);
        }
 
        //********************************
        // Put the base type in its name |
        //********************************
 
        strcat(temp, BaseItemList[myActor->ItemBaseType].itemName);
 
        //********************************************************
        // If the item has a suffix, add the suffix to the name. |
        //********************************************************
 
 
    if(myActor->ItemMagicType > 1 )
        {
           strcat(temp, " of");
           strcat(temp, ItemModList[myActor->ItemMod3].suffix);
           strcat(temp, ItemModList[myActor->ItemMod4].suffix);
        }
 
 
    }
    strcpy(myActor->ItemName, temp);
 
    return myActor;
}

//*************************************************
//     This Function creates a random item at     |
//     x,y coordinates.                           |
//                                                |
//     The item created has no modifiers.         |
//                                                |
//*************************************************

Actor* ITEM_CreateRandom(int x, int y)
{
    Actor* myActor;
    int i;
 
 
//************************************************
//   IMPORTANT NOTE:                             |
//       Change "Draggable". "simplegear"        |
//       to the names of your Actor and          |
//       Animation.                              |
//                                               |
//       Or simply make Actor named              |
//      "Draggable" with Animation               |
//       named "simplegear".                     |
//************************************************
 
    myActor = CreateActor("Draggable", "simplegear", "(none)", "(none)", x, y, false);

    ChangeAnimationDirection(myActor->name, STOPPED);
   
i = rand(BASENUM);
    myActor->animpos = i;
   
myActor->ItemBaseType = i;
    myActor->ItemMagicType = 0;
    myActor->ItemMod1 = 0;
    myActor->ItemMod2 = 0;
    myActor->ItemMod3 = 0;
    myActor->ItemMod4 = 0;
 
    return myActor;
}


//********************************************************
//    ITEM_setRandomMods function                        |
//    adds modifiers to a pre-existiing item.            |
//                                                       |
//    You pass the actor to the function and it randomly |
//    adds modifiers to it from the ItemModList and      |
//    changes it's rarity type.                          |
//********************************************************
 
 

void ITEM_SetRandomMods(Actor* myActor)
{
    char temp[100];
 
    //Set Rarity
    myActor->ItemMagicType = rand(7);
 
    //*************************************************************
    // Add Random Mods                                            |
    //                                                            |
    // This checks to see if the item should have a prefix.       |
    // If the item is of the Normal type or No Prefix Magic type  |
    // this first Mod Slot (prefix slot) will be passed over.     |
    //*************************************************************

    if(myActor->ItemMagicType > 0 && myActor->ItemMagicType != 2 )
    {
      myActor->ItemMod1 = rand(MODNUM)+1;
    }
 
    //*************************************************************
    // This checks to see if the item should have a suffix.       |
    // If the item is of the Normal type or No Suffix Magic type  |
    // this third Mod Slot (suffix slot) will be passed over.     |
    //*************************************************************
 
    if(myActor->ItemMagicType > 1)
    {
       myActor->ItemMod3 = rand(MODNUM)+1;
    }
 
    //***************************************************************
    // This checks to see if the item should have a second prefix.  |
    // If the item is lower than Rare or single Prefix Rare type    |
    // this second Mod slot (prefix slot) will be passed over.      |
    //***************************************************************
 
    if(myActor->ItemMagicType > 3 && myActor->ItemMagicType != 5 )
    {
       myActor->ItemMod2 = rand(MODNUM)+1;
    }
 
    //****************************************************************
    // This checks to see if the item should have a second suffix.   |
    // if the item is not of the second suffix Rare or higher type   |
    // this forth Mod slot (suffix slot) will be passed over.        |
    //****************************************************************
 
    if(myActor->ItemMagicType > 4)
    {
       myActor->ItemMod4 = rand(MODNUM)+1;
    }
 
    //**********************************************************************
    // This Names the items based on the Prefixs, Suffixs, and Base type.  |
    //                                                                     |
    // If the item has a prefix then name the item with a prefix           |
    //                                                                     |
    // The first set of if statements checks to see if it is RARE or       |
    // EPIC. Then names it based on such.                                  |
    //**********************************************************************
 
    if(myActor->ItemMagicType > 3)
    {
        strcat(temp, RareNamePrefix[rand(10)]);
        strcat(temp, RareNameSuffix[rand(10)]);
 
       if(myActor->ItemMagicType > 5)
       {
           strcpy(temp, "");
           strcat(temp, EpicNamePrefix[rand(10)]);
           strcat(temp, EpicNameSuffix[rand(10)]);
       }
    }
    else
    {
        if(myActor->ItemMagicType > 0 && myActor->ItemMagicType != 2 )
        {
           strcat(temp, ItemModList[myActor->ItemMod1].prefix);
           strcat(temp, ItemModList[myActor->ItemMod2].prefix);
        }
 
        //********************************
        // Put the base type in its name |
        //********************************
 
        strcat(temp, BaseItemList[myActor->ItemBaseType].itemName);
 
        //********************************************************
        // If the item has a suffix, add the suffix to the name. |
        //********************************************************
 
   
    if(myActor->ItemMagicType > 1 )
        {
           strcat(temp, " of");
           strcat(temp, ItemModList[myActor->ItemMod3].suffix);
           strcat(temp, ItemModList[myActor->ItemMod4].suffix);
        }
 
 
    }
    strcpy(myActor->ItemName, temp);
}


//*************************************
//  ITEM_getWeaponDamage returns the  |
//  damage integer of the weapon      |
//  including MODS on weapon and      |
//  MODS on equipment.                |
// ************************************





int ITEM_GetWeaponDamage(Actor* myActor, float equipMod)
{
   int i = BaseItemList[myActor->ItemBaseType].itemPoints;

    if(ItemModList[myActor->ItemMod1].modType == 1)
    {
       i = i + (BaseItemList[myActor->ItemBaseType].itemPoints *
             ItemModList[myActor->ItemMod1].modPercPrefix);
    }

    if(ItemModList[myActor->ItemMod2].modType == 1)
    {
       i = i + (BaseItemList[myActor->ItemBaseType].itemPoints *
             ItemModList[myActor->ItemMod2].modPercPrefix);
    }

    if(ItemModList[myActor->ItemMod3].modType == 1)
    {
       i = i + (BaseItemList[myActor->ItemBaseType].itemPoints *
             ItemModList[myActor->ItemMod3].modPercSuffix);
    }

    if(ItemModList[myActor->ItemMod4].modType == 1)
    {
       i = i + (BaseItemList[myActor->ItemBaseType].itemPoints *
             ItemModList[myActor->ItemMod4].modPercSuffix);
    }



    i = i + (BaseItemList[myActor->ItemBaseType].itemPoints * equipMod);

    return i;
}


//*********************************************
//  ITEM_getDescription function writes a     |
//  description of the item passed to it.     |
//                                            |
//  It requires an array large enough to hold |
//  the description.                          |
//                                            |
//  A char array of [250] should be more than |
//  enough.                                   |
//*********************************************

void ITEM_GetDescription(Actor* myActor, char description[])
{
    char temp[50];
    char newline[2] = "\n";
    int namelen = strlen(myActor->ItemName);
    int i;
    int runOnce = 0;
    float equipMOD = .5; //add 50% more damage to base weapon
 
 
    strcpy(description, "");
 


 
      //FOR LOOP FOR SPLITTING LONG ITEM NAMES INTO TWO LINES
      if(namelen > 25)
      {
          for(i = 0; i < namelen; i++)
          {
              if(i >= (namelen)/2
                 && myActor->ItemName[i] == ' ' && runOnce == 0)
              {
                  description[i] = newline[0];
                  i++;
                  runOnce = 1;
              }
              description[i] = myActor->ItemName[i];
          }
      }
      else
      {
          strcpy(description, myActor->ItemName);
      }
 
 
    strcat (description, "\n\n");

    // Type
    strcat (description, MagicTypes[myActor->ItemMagicType]);
    strcat (description, " ");
    strcat (description, BaseItemList[myActor->ItemBaseType].itemName);
    strcat (description, "\n");
    sprintf(temp, "Damage: %d", ITEM_GetWeaponDamage(myActor, equipMOD));
    strcat (description, temp);
    strcat (description, "\n----------------------\n");
 
    ITEM_GetModDesc(myActor, myActor->ItemMod1 , description, 1);
    ITEM_GetModDesc(myActor, myActor->ItemMod2 , description, 1);
    ITEM_GetModDesc(myActor, myActor->ItemMod3 , description, 0);
    ITEM_GetModDesc(myActor, myActor->ItemMod4 , description, 0);
 
}
 

void ITEM_GetModDesc(Actor* myActor, int modifier, char description[], int prefix)
{
    char temp[150];
    int i;

    if(modifier)
    {
        //****************************************************************
        // Uses the description in the mod list + the point modifier to  |
        // write a description of the Modifier.                          |
        //****************************************************************
        if(prefix)
        {
            if(ItemModList[modifier].modPointsPrefix)
            {
                sprintf (temp, ItemModList[modifier].modDescription,
                           ItemModList[modifier].modPointsPrefix );
            }
            if(ItemModList[modifier].modPercPrefix)
            {
                i = (ItemModList[modifier].modPercPrefix)*100;
                sprintf (temp, ItemModList[modifier].modDescription, i);
 
            }
            if(ItemModList[modifier].modPointsPrefix == 0
                && ItemModList[modifier].modPercPrefix == 0)
            {
                strcpy (temp, ItemModList[modifier].modDescription);
            }
        }
        else
        {
            if(ItemModList[modifier].modPointsSuffix)
            {
                sprintf (temp, ItemModList[modifier].modDescription,
                           ItemModList[modifier].modPointsSuffix );
            }
 
            if(ItemModList[modifier].modPercSuffix)
            {
                i = (ItemModList[modifier].modPercSuffix)*100;
                sprintf (temp, ItemModList[modifier].modDescription, i);
 
            }
 
            if(ItemModList[modifier].modPointsSuffix == 0
                && ItemModList[modifier].modPercSuffix == 0)
            {
                strcpy (temp, ItemModList[modifier].modDescription);
            }
        }
 
 
        strcat (description, temp);
        strcat (description, "\n\n");
    }


}






void INVEN_ClearSlot(int slot)
{
    Inventory[slot][0] = 0;
    Inventory[slot][1] = 0;
    Inventory[slot][2] = 0;
    Inventory[slot][3] = 0;
    Inventory[slot][4] = 0;
    Inventory[slot][5] = 0;
    Inventory[slot][6] = 0;
    Inventory[slot][7] = 0;
    strcpy(Inventory_ItemName[slot], "");
}

void INVEN_AddItem(Actor* myActor)
{
    int i;
 
 
    if(!Inventory[INVENTORY_MAX-1][0])
    {
        Inventory[INVENTORY_MAX-1][0] = 1; //slot filled
        Inventory[INVENTORY_MAX-1][1] = myActor->ItemEquipped;
        Inventory[INVENTORY_MAX-1][2] = myActor->ItemBaseType;
        Inventory[INVENTORY_MAX-1][3] = myActor->ItemMagicType;
        Inventory[INVENTORY_MAX-1][4] = myActor->ItemMod1;
        Inventory[INVENTORY_MAX-1][5] = myActor->ItemMod2;
        Inventory[INVENTORY_MAX-1][6] = myActor->ItemMod3;
        Inventory[INVENTORY_MAX-1][7] = myActor->ItemMod4;
 
        strcpy(Inventory_ItemName[INVENTORY_MAX-1], myActor->ItemName);
 
 
 
 
 
 
 
 
    }
    INVEN_Organize();
 
}



void INVEN_Replace(int removedItem)
{
    int i;
 
    for(i = INVENTORY_MAX-1; i > removedItem; i--)
    {
        if(Inventory[i][0])
        {
            Inventory[removedItem][0] = 1; //slot filled
            Inventory[removedItem][1] = Inventory[i][1];
            Inventory[removedItem][2] = Inventory[i][2];
            Inventory[removedItem][3] = Inventory[i][3];
            Inventory[removedItem][4] = Inventory[i][4];
            Inventory[removedItem][5] = Inventory[i][5];
            Inventory[removedItem][6] = Inventory[i][6];
            Inventory[removedItem][7] = Inventory[i][7];
 
            strcpy(Inventory_ItemName[removedItem], Inventory_ItemName[i] );
 
            INVEN_ClearSlot(i);
            break;
        }
    }
}

void INVEN_Organize()
{
    int i;
    for(i=0; i < INVENTORY_MAX; i++)
    {
        if(!Inventory[i][0])
        {
            INVEN_Replace(i);
        }
    }
}




//**********************************************************
//   MENU FUNCTIONS
//
//
//**********************************************************



void MENU_ActivateDrawSelected(char fromActor[], char toCanvas[])
{
    Actor* myActor = getclone(fromActor);
    Actor* myCanvas = getclone(toCanvas);
 

   WF_Selector.x = myActor->xscreen - myCanvas->xscreen;
    WF_Selector.y = myActor->yscreen - myCanvas->yscreen;
 
    WF_Selector.width = myActor->width;
    WF_Selector.height = myActor->height;
    SendActivationEvent(toCanvas);
}




void MENU_WriteTextToButton(int index)
{
    Actor* myActor;
    char temp[30];

    sprintf(temp, "MenuText.%d", MenuButtons[index]);
    myActor = getclone(temp);
    strcpy(myActor->text, MenuButtonTexts[index]);
}




int MENU_AddToIndex(int clonenum)
{
    int i;
 
    for(i = 0; i < MENU_MAX_INDEX; i++)
    {
        if(MenuButtons[i] == -1)
        {
            MenuButtons[i] = clonenum;
            return i;
        }
    }
    return -1;
}



void MENU_CreateMenuButton(int i_x, int i_y, int index)
{
    Actor* myActor;
    //int index = -1;
 
    myActor = CreateActor("MenuText", "icon", "InventoryPane", "(none)", i_x +15, i_y + 5, false);
 
    MenuButtons[index] = myActor->cloneindex;
 
    if(index != -1 && index < MENU_MAX_INDEX)
    {
        MENU_WriteTextToButton(index);
    }
    else
    {
        strcpy(myActor->text,"ERROR!!");
    }
 
    myActor = CreateActor("MenuHitBox", "icon", "InventoryPane", "(none)", i_x, i_y, false);
    if(index != -1 && index < MENU_MAX_INDEX)
    {
        MenuButtons[index] = myActor->cloneindex;
    }
    myActor->Menu_Index = index;
 
}


void MENU_CreateMenu(int i_x, int i_y)
{
    int i;
    for(i = 0; i < MENU_MAX_INDEX; i++)
    {
        MENU_CreateMenuButton(i_x, i_y + (50*i), i);
    }

}



void MENU_CreateItemListButton(int i_x, int i_y, int index, int i_type)
{
    Actor* myActor;
    char blank[2] = " ";
    char temp[250];
    char temp2[250];
    int i;
 
    for( i = 0; i < 250; i++)
        {
            temp[i] = blank[0];
            temp2[i] = blank[0];
        }
 
    strcpy(temp,Inventory_ItemName[index]);
 
 
 
 
        for( i = 0; i < INVEN_MAX_NAME_VALUE; i++)
        {
            temp2[i] = temp[i];
        }
 
        temp2[INVEN_MAX_NAME_VALUE-1] = blank[1];
 
 
 
 
 
 
    if(i_type != BaseItemList[Inventory[index][2]].itemType)
    {
        //doNothing
    }
    else
    {
        if(index != -1 && index < INVENTORY_MAX)
        {
            myActor = CreateActor("ItemSlotText", "icon", "InventoryPane2", "(none)", i_x + 3, i_y, false);
            strcpy(myActor->text, temp2);
            myActor = CreateActor("ItemHitBox", "icon", "InventoryPane2", "(none)", i_x, i_y, false);
            strcpy(myActor->ItemName, Inventory_ItemName[index]);
            myActor->ItemBaseType = Inventory[index][2];
            myActor->ItemMagicType = Inventory[index][3];
            myActor->ItemMod1 = Inventory[index][4];
            myActor->ItemMod2 = Inventory[index][5];
            myActor->ItemMod3 = Inventory[index][6];
            myActor->ItemMod4 = Inventory[index][7];
        }
        else
        {
            myActor = CreateActor("ItemSlotText", "icon", "InventoryPane", "(none)", i_x + 3, i_y, false);
            strcpy(myActor->text, "FAILURE");
            myActor = CreateActor("ItemHitBox", "icon", "InventoryPane", "(none)", i_x, i_y, false);
 
        }
    }
 
}

void MENU_CreateItemList(int i_x, int i_y, int i_type)
{
    int i;
    int pos = 0;
 
    for(i = 0; i < INVENTORY_MAX; i++)
    {
        if(Inventory[i][0])
        {
 
            switch(i_type)
            {
            case 0: //Weapons Menu
                if(BaseItemList[Inventory[i][2]].itemType == 1) //If Weapon
                {
                    MENU_CreateItemListButton(i_x, i_y + (20*pos), i, 1);
                    pos++;
                }
                break;
 
            case 1: //Apparel Menu
                if(BaseItemList[Inventory[i][2]].itemType >= 2 && BaseItemList[Inventory[i][2]].itemType <= 9) //If Apparel
                {
                    MENU_CreateItemListButton(i_x, i_y + (20*pos), i, BaseItemList[Inventory[i][2]].itemType );
                    pos++;
                }
                break;
 
            case 2: //Potions Menu
                if(BaseItemList[Inventory[i][2]].itemType == 10)
                {
 
                    MENU_CreateItemListButton(i_x, i_y + (20*pos), i, 10);
                    pos++;
                }
                break;
 
            case 3: //Quest Menu
                if(BaseItemList[Inventory[i][2]].itemType == 11)
                {
                    MENU_CreateItemListButton(i_x, i_y + (20*pos), i, 11);
                    pos++;
                }
                break;
 
            case 4:
                if(BaseItemList[Inventory[i][2]].itemType == 1) //If Weapon
                {
                    MENU_CreateItemListButton(i_x, i_y + (20*pos), i, 0);
                    pos++;
                }
                break;
            }
 
 
        }
 
    }
 
}

void MENU_MoveCanvasToScreen(char Canvas[])
{
    Actor* myCanvas = getclone(Canvas);

    myCanvas->x = view.x;
    myCanvas->y = view.y;
}

void MENU_MoveCanvasOffScreen(char Canvas[])
{
    Actor* myCanvas = getclone(Canvas);

    myCanvas->x = -(myCanvas->width + 10);
    myCanvas->y =  -(myCanvas->height + 10);
}







//******************************************
//    Current Item Mods Section            |
//                                         |
//    This section will be removed and     |
//    Mods will be added from a text file  |
//    for easier addition and modification |
//******************************************
 
ItemModifer IM_None = { "", "", "", 0, 0, 0, 0, 0, 0, 0 };
ItemModifer IM_FireDamage = { "Fiery ", " Flame", "Adds %d points\n of fire damage",
                              4, 42, 90, 0, 0, 0, 0 };
 
ItemModifer IM_ColdDamage = { "Icy ", " Ice", "Adds %d points of\n cold damage",
                              5, 45, 60, 0, 0, 0, 0 };
 
ItemModifer IM_ElecDamage = { "Shocking ", " Static", "Adds %d points\n of electric damage",
                              6, 69, 80, 0, 0, 0, 0 };
 
ItemModifer IM_PosnDamage = { "Toxic ", " Poison", "Adds %d points\n of poison damage",
                              7, 66, 78, 0, 0, 0, 0 };
 
ItemModifer IM_PhysDamage = { "Butcher's ", " Wounding", "Increases damage\n by %d%%",
                              1, 0, 0, 1.2, 2.5, 0, 0 };
 
ItemModifer IM_Test = { "Longnamed ", " Longnames", "This is only a test name,\n non useable, just sayin'.....",
                              1, 0, 0, 0, 0, 0, 0 };




//******************************
//    Basic types of items     |
// itemName(char), itemType(i), itemPoints(i), itemRate(f) itemValue(i), itemStack(i), itemEquip
//******************************


BaseItem BaseItem_Sword = { "Sword", 1, 50, 0, 0, 0};
BaseItem BaseItem_Dagger = { "Dagger", 1, 20, 0, 0, 0};
BaseItem BaseItem_Bow = { "Bow", 1, 35, 0,  0, 0};
BaseItem BaseItem_Potion = { "Potion", 10, 35, 0,  0, 0};
BaseItem BaseItem_QuestItem = { "Deckard's Trinket", 11, 35, 0,  0, 0};
BaseItem BaseItem_Armor = { "Armor", 3, 35, 0,  0, 0};


//**************************************************
// Initialize the current mods into the mod list,  |
// put this function into the CREATE ACTOR EVENT   |
// of the view.                                    |
//**************************************************
void ITEM_initMods()
{
    ItemModList[0] = IM_None;
    ItemModList[1] = IM_FireDamage;
    ItemModList[2] = IM_ColdDamage;
    ItemModList[3] = IM_ElecDamage;
    ItemModList[4] = IM_PosnDamage;
    ItemModList[5] = IM_PhysDamage;
    ItemModList[6] = IM_Test;
}

void ITEM_initBaseItems()
{
    BaseItemList[0] = BaseItem_Sword;
    BaseItemList[1] = BaseItem_Dagger;
    BaseItemList[2] = BaseItem_Bow;
    BaseItemList[3] = BaseItem_Potion;
    BaseItemList[4] = BaseItem_QuestItem;
    BaseItemList[5] = BaseItem_Armor;
}




void MENU_initButtons()
{
    int i;
    for(i = 0; i < MENU_MAX_INDEX; i++)
    {
 
        MenuButtons[i] = -1;
    }
}




void INVEN_init()
{
    int i;
    for(i=0; i < INVENTORY_MAX; i++)
    {
        INVEN_ClearSlot(i);
    }
 
}
Attachments
InventSCRNSHT-2.PNG
InventSCRNSHT-1.PNG
inventoryzip.zip
(244.42 KiB) Downloaded 150 times
Last edited by EvanAgain on Wed Feb 13, 2013 8:24 pm, edited 23 times in total.
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Inventory System + Random Item Gen

Postby EvanAgain » Fri Jan 25, 2013 3:27 am

What's wrong here....


Code: Select all
//Script for items
struct ItemModifier;

typedef struct ItemModifier{
    char prefix[30];
    char suffix[30];
    char description[150];
    int  damageType; //None, Melee, Ranged, Fire, Cold, Electric, Poison, Magic, Sonic, Acid, Holy, Evil
    int  resistType;
    int  attribType;  //None, Str, Dex, Int, Con, Wis, Luk
    int  modPoints;
    float  modPerc;      //0.0 - 1.0
    int  special;        //Special Modifiers for increased funness and awesome.
}ItemModifer;


char BaseTypes[10][50] = {"Sword" , "Dagger", "Bow"};
char MagicTypes[10][50] = {"Normal", "Magic", "Rare", "Epic"};


ItemModifer IM_FireDamage = { "Fiery", "Of Flames", "Adds 10 points of fire damage", 4, 0, 0, 10, 0, 0 };
ItemModifer IM_ColdDamage = { "Icy", "Of Ice", "Adds 10 points of cold damage", 5, 0, 0, 10, 0, 0 };
ItemModifer IM_ElecDamage = { "Shocking", "Of Lightning", "Adds 10 points of electric damage", 6, 0, 0, 10, 0, 0 };
ItemModifer IM_PosnDamage = { "Toxic", "Of Poison", "Adds 10 points of poison damage", 7, 0, 0, 10, 0, 0 };


//ERROR ON THIS LINE
ItemModifer ItemModList[4] = { IM_FireDamage, IM_ColdDamage, IM_ElecDamage, IM_PosnDamage};
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Inventory System + Random Item Gen

Postby skydereign » Fri Jan 25, 2013 4:29 am

According to C, nothing is wrong. But, gE seems to have a problem with passing structs as values in an array (it's in the EiC code). So, you'll have to use an init function to handle that.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Inventory System + Random Item Gen

Postby EvanAgain » Fri Jan 25, 2013 5:07 am

yeah, I separated it down to just putting each one in individually.


So here is the next problem I am having. After figuring out the string cat problem. I can't access the struct.. :/

Code: Select all
int i = 0;
Actor* myActor = 0;
char temp[100];

actor_to_screen(&xmouse, &ymouse);



myActor = CreateActor("Draggable", "simplegear", "(none)", "(none)", xmouse, ymouse, false);

i = rand(3);
myActor->animpos = i;

myActor->ItemBaseType = i;

//Add Random Mods
myActor->ItemMod1 = rand(4);
myActor->ItemMod2 = rand(4);
myActor->ItemMod3 = rand(4);
myActor->ItemMod4 = rand(4);

strcat(temp, ItemModList[myActor->ItemMod1].prefix);
strcat(temp, " ");
strcat(temp, ItemModList[myActor->ItemMod2].prefix);
strcat(temp, " ");
strcat(temp, BaseTypes[myActor->ItemBaseType]);
strcat(temp, " ");
strcat(temp, ItemModList[myActor->ItemMod3].suffix);
strcat(temp, " ");
strcat(temp, ItemModList[myActor->ItemMod4].suffix);


strcpy(myActor->ItemName, temp);


The mods just don't work...
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Inventory System + Random Item Gen

Postby EvanAgain » Fri Jan 25, 2013 5:51 am

ItemModList[0] = IM_FireDamage;
ItemModList[1] = IM_ColdDamage;
ItemModList[2] = IM_ElecDamage;
ItemModList[3] = IM_PosnDamage;

Can't be in global code?

Annoying...
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Inventory System + Random Item Gen

Postby skydereign » Fri Jan 25, 2013 5:58 am

EvanAgain wrote:ItemModList[0] = IM_FireDamage;
ItemModList[1] = IM_ColdDamage;
ItemModList[2] = IM_ElecDamage;
ItemModList[3] = IM_PosnDamage;

Can't be in global code?

Annoying...

Right. That is code that needs to execute. That is why I mentioned you need an init function. Global code is meant purely for declaring things in global scope.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Inventory System + Random Item Gen

Postby EvanAgain » Fri Jan 25, 2013 6:06 am

got it, I will create one in the future. I plan on being able to load all items from a list so that the items will be easily modded.
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Inventory System + Random Item Gen

Postby EvanAgain » Sat Jan 26, 2013 7:00 am

Template Code is continuously updated.

I added as much commenting as I possibly could think that explains what each function does.

If there is something that you don't understand and you would like to use the code, or would like to understand more about how it works, Reply, or try google.

You can use the ged file provided to test the template code. I will update the ged to feature the latest template code and screenshot. But for future updates, just replace the template code in the Global Code section under "items"
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: UPDATED: Inventory + Random Item Gen

Postby EvanAgain » Mon Jan 28, 2013 5:33 pm

Bump Update:

I am creating the actual Inventory now, the GUI in which will be used to Equip, Use, Sell, Drop, and look at available items.

I am going with the "skyrim" style of inventory as it uses the weight system rather than the slot system. I realize that this may cause problems with "arrays" as I decided to go with a constant size so their will be a slot cap but it will be higher than the weight cap. I may eventually even add a dynamic resizing feature to remove the slot cap and only have a weight cap to keep the game from overloading the memory. But since the inventory is made up of an array of integers the inventory will always be relatively light on memory.

For now the inventory window doesn't "hold" anything. It just shows the visual representation of how the inventory and main menus will work. I play on using this menu system through out the entire game.
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: UPDATED: Inventory + Random Item Gen

Postby moonforge » Tue Jan 29, 2013 11:54 am

So, you're planning on implementing this system in a future game of yours?
If so, good luck, because you'll have to figure out how that fire damage and other types of damages affect the different enemies.
I AM glad to see that you're working hard on making an interactive menu.

Keep up the good work!
http://wannowandrichardsgames.weebly.com/

"You don't have to win to be a winner. You just have to pretend to be better than everyone else."

+ 1 please?
User avatar
moonforge
 
Posts: 45
Joined: Mon Jan 28, 2013 3:58 am
Location: CENSORED
Score: 8 Give a positive score

Re: UPDATED: Inventory + Random Item Gen

Postby EvanAgain » Tue Jan 29, 2013 6:56 pm

moonforge wrote:So, you're planning on implementing this system in a future game of yours?
If so, good luck, because you'll have to figure out how that fire damage and other types of damages affect the different enemies.
I AM glad to see that you're working hard on making an interactive menu.

Keep up the good work!



Quite simple actually, since every "creature" will have the same base struct and functions. Basically, a function that checks damage for a player will also be what checks damage for a monster.

Each monster will have a set of resistances and damage types, even skills and mods. Basically, each monster will act as an player character controlled by the Computer. When I get my action-RPG template finished it will be as easy as using a special "creation" tool to create the structs for the game. This will allow for many different items and monsters.

But the function will check the "collided" monster against its instanced stats. Each monster instance will have its own stats stored within it's actor. So lets say I use "Reduce Fire Resistance" on a monster, but there are other monsters of the same type around it. Only the affected monster's stats will be reduced, then checked into the function for dealing damage, then updated into the monster's stats and then checked to see if it died.

This is just one small piece to the giant puzzle of creating my game. I practically have the entire game in my head but I am slowly getting it into a usable state.
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: UPDATED JAN29: Inventory+Random Item Gen

Postby moonforge » Wed Jan 30, 2013 1:55 am

Sounds like an ambitious project! :lol:

If you need any help with it, you can always PM me for help. (not sure if those damage functions are out of my league)
This seems like something that could into something great. I've seen too many good projects stopped because they were too much work. If you need help, just ask. There are plenty of people around the forums who would be DELIGHTED to help.

Good Luck!

~moonforge
http://wannowandrichardsgames.weebly.com/

"You don't have to win to be a winner. You just have to pretend to be better than everyone else."

+ 1 please?
User avatar
moonforge
 
Posts: 45
Joined: Mon Jan 28, 2013 3:58 am
Location: CENSORED
Score: 8 Give a positive score

Re: UPDATED JAN29: Inventory+Random Item Gen

Postby EvanAgain » Wed Jan 30, 2013 4:00 am

OHH!! Believe me I tried starting a project. But I have never worked in a team before, it would be a good experience. But yes, this project is fairly large.... I have so much to do and, well, plenty of time.

I don't know how to write a team document to make sure that the code works together properly, and most of it is still not certain. I started this project about a year or two ago and then had to delay it because I lost access to a computer.

I so far have 3 portions started, Map Editor, Menus, and Pathfinding.

Things to do:

The map editor, which needs to be finished and refined.

The AI pathfinding.

The combat system, (Action RPG Diablo clone style)

Character development

and the whole skill engine with particle effects and the works.

AND the quest system

Also, this set of code will eventually turn into the complete GUI system. I am trying to make it as automated and customizable as possible. But for now just functional..

Tools that need to be crafted are: The Item Mod creator, The Base Item creator

..... To be honest.. There is SOOO much work to do that most of the plans are just in my head. Once I get a functioning version of everything then it will just come down to refinement and content creation.



Still to come in the inventory system:

Item viewer
Options for: Use, Equip, Drop
Gold Amount and slot's left..
Keyboard control
Window creation/deletion
A shop prototype for : Buy and Sell

This will then get tied into the character sheet/development system:

Character Stats
Damages, (You damages will be viewed separated into categories physical/arcane/fire/ice/lightning/poison/holy/evil
Resistance (physical/arcane/fire/ice/lightning/poison/holy/evil)
Karma (will decide your quests and holy/evil resistance and damage buffs)
Worn Equipment
feats and perks


This will then get tied into the Skill and Spell page:

Skill trees
Spell book

This will then get tied into the Main Menu

Options
Save
Quit


Then I will start prototyping a combat system which will work with how damage is dealt. But before damage can be messed with, a hero must be born. As well as 1 test subject.

I will use a standard 1 actor vs 1 actor for prototyping.

Melee attack- Use Mouse button skill 1 "Normal Attack". The player will move to the target, once in range will begin to attack the target.

Attack process:
Move to player into range of target
Begin reducing target damage based on Attack Algorithm: of Attacks per number of frame.
On damage frame reduce target health based on Damage Algorithm: of Players Damage/Accuracy/Critical versus Target Defense/Dodge & Block/Resistance
Check for target death after each attack
On Target death, destroy target, Stop attacking.


Ranged Attack- Use Mouse button skill "Ranged Attack". The player will fire an actor at velocity based on character and standard speeds.

Skill Attack - Use Mouse button skill "Skill Attack" Use skill on target.

Spell Attack- Use Mouse button skill "Spell Attack" Use spell on target.
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: UPDATED JAN29: Inventory+Random Item Gen

Postby moonforge » Thu Jan 31, 2013 3:22 am

First of all, on you item screen, when your mouse isn't over a weapon it shouldn't display the attack information. Even after I got rid of an item it still showed the info in the description area of the screen.

Second, I was wondering why you would need to randomly generate items within your own inventory. Shouldn't a random generator be in something like a chest?
Just throwing that out there.

Don't get me wrong, this is a very good project. I would like to see a few improvements, allow I DO like it.

~moonforge
http://wannowandrichardsgames.weebly.com/

"You don't have to win to be a winner. You just have to pretend to be better than everyone else."

+ 1 please?
User avatar
moonforge
 
Posts: 45
Joined: Mon Jan 28, 2013 3:58 am
Location: CENSORED
Score: 8 Give a positive score

Re: UPDATED JAN29: Inventory+Random Item Gen

Postby EvanAgain » Thu Jan 31, 2013 4:25 am

moonforge wrote:First of all, on you item screen, when your mouse isn't over a weapon it shouldn't display the attack information. Even after I got rid of an item it still showed the info in the description area of the screen.

Second, I was wondering why you would need to randomly generate items within your own inventory. Shouldn't a random generator be in something like a chest?
Just throwing that out there.

Don't get me wrong, this is a very good project. I would like to see a few improvements, allow I DO like it.

~moonforge


Ok, the display information is just that, a simple display. It doesn't have a clear function, it doesn't need one. The display in this demo isn't even what is going to be in the real thing. I am still working on a different way to display information within the inventory.

Also, the items aren't generated TO the inventory, they are generated (at the moment) on a background canvas using a generate random item function. It's not how the actual game will work, its just for the demo, you know, testing and debugging. It just makes the process faster.

After the item is generated, you click it and pick up the item and it gets stored into the inventory.

I am still working on other things, but bare in mind that this is purely a FUNCTIONS test and not a live demo of how the game will operate.


Originally, the mouse over the item when you generate the item is simply to make sure the items were generating properly, also, it's to make sure that the item generated once picked up is properly stored into the inventory.


So, while, thanks for your consideration, but don't worry so much about those small things. It's for debugging and testing only. Now, if you notice any bugs such as items not displaying proper information, or, some other bugs that make a function potentially fatal to the program, feel free to point those out.

I just got the button press for displaying the inventory to the view, but some odd reason I can't get the menu's to appear above all other objects. That is what I am working on currently.
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Next

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest