/****************************************                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          /*********************************
**        DragonBlade   Ver 1.0.0      **
**      © Copyright by Ryan Best 1992  **
**          All Rights Reserved.       **
*****************************************/
#include "DB.h"

extern	WindowPtr	gPictureWindow, gGameWindow, gCastleWindow, gDungeonWindow;
extern	Boolean		gDone, gWNEImplemented;
extern	EventRecord	gTheEvent;
extern	MenuHandle	gAppleMenu,gEditMenu,gFileMenu,gOptionsMenu,gSpecialMenu;
extern	Rect		gIntroRect, gTavernRect, gBankRect, gRollerRect, gStoreRect, gCharRect0,
					gCharRect1, gCharRect2, gCharRect3,gItemsRect, gMapRect, gSpellsRect,gSrcRect,
					gGuildRect,gHealerRect,gArmoryRect,gdungeonRect,gPrisonRect, gStatsRect, 
					gUseRect,gPanicRect, gMoveRect, gDungDispRect;
extern	PicHandle	gThePicture, gConsolePicture, gDungeon1, gLeftWall, gCenterWall, gRightWall,
					gLeftDoor,gRightDoor,gFlatWall,gFlatDoor,gOpenSpace,gFarWall,gFarDoor,gCLWall,gCRWall,
					gCOpenSpace,gCLDoor,gCRDoor,gCFWall,gCFDoor;
extern	CIconHandle	gShieldIcon, gRingIcon, gSphereIcon,gFlailIcon,gCloakIcon,gArrowIcon,gDaggerIcon,
					gSwordIcon,gHelmetIcon,gTorchIcon,gBookIcon,gGlovesIcon,gBurnedIcon,gArmorIcon;
extern int			gSndOn,gPauseOn,gPanicOn, gInCastle, gPartyNum,gNewChar, gSndNum, gLight,gLightSpell, 
					gItemUseScreen, gCurChar, gInPrison,gDialogNum,gDisplay,gDungLevel,gXLoc,gYLoc,
					gView,gResistFire,gResistIce,gPartyInvis;
extern	long		gStats[6], gDungParty[4],gWhichChar,glastWhen;
extern	Point		glastWhere;
extern	DialogPtr	gCastleDialog,gBankDialog;
extern	RGBColor	gNameBack, gStatsBack, gSpecName,gNormName,gMessBack, gBlack;
 
extern	struct	CharInfo 
{
	Str255	name;
	int		type;
	int		race;
	int		level;
	int		exp;
	int		status;
	int		hits;
	int		dmg;
	int		age;
	int		str;
	int		wis;
	int		itl;
	int		con;
	int		dex;
	int		items[7];	
	int		itemsInUse[7];			/* what items are being used */
	int		gold;
	int	 	bank;
	int		mspells[4],cspells[4];
	int		dngLevel, xLoc, yLoc,Pos;	
};
extern	struct	CharInfo	GameChars[8];						/*  Can store up to 8 chars per game  */

extern	struct	ItemInfo 
{
	Str255			name;
	unsigned char	type;
	unsigned char	status;		/* whether item is in use or not */
	unsigned char	instore;
	unsigned char	level;
	Byte			attrib;
	unsigned char	dmg;
	unsigned char	def;
	unsigned char	con;
};
extern	struct	ItemInfo	GameItems[101];

extern	struct	DungInfo 				
{
unsigned int	XY[10][10];		/*  x, y  rooms location */
unsigned int	N[100];			/* 100 rooms w/north walls */
unsigned int	S[100];			/* 100 rooms w/south walls */
unsigned int	E[100];			/* 100 rooms w/east walls */
unsigned int	W[100];			/* 100 rooms w/west walls */
unsigned int	SA[100];
};
extern	struct	DungInfo	Dungeon[1];	

/************************ MagicStore ****************************/

MagicStore()
{

int			itemType, store_id, slot, z, x,count,theitem, itemHit,  
			y,dialogDone = FALSE,itemCount[9]; 
Handle		itemHandle;
Rect		itemRect;
Str255		text;
long		price;
unsigned	min,max;

gSndNum=19402;
PlaySound();

if (gDungParty[0]==99)		/* no char, then go away! */
{
	ClearMessage();
		DrawString("\pWe're busy casting spells. Come back later.");
	return;
}
z=DeadCharMsg();
	if (z == -1)			/* dead char */
		return;

	gDisplay=0;				/* items */
	ListItems();
	gDialogNum=128;
	DoDialog();
	
 	ParamText (GameChars[gCurChar].name,"\p","\p ","\p ");	 
		ClearMessage();	
	DrawString(GameChars[gCurChar].name);DrawString("\p has entered the magic shoppe.");
	RGBBackColor(&gStatsBack);
	
	GetDItem(gCastleDialog, OKAY_ITEM, &itemType, &itemHandle, &itemRect);
	HiliteControl(itemHandle, 0);

z=4;	 
count=0;

for (x=0;x<=7;x++)		/** List 8 items in store **/
	{
		GetDItem(gCastleDialog, z, &itemType, &itemHandle, &itemRect);
			SetCTitle(itemHandle,GameItems[x+40].name);
			itemCount[count]=x+40;		/** counter for items in store ***/
			z=z+2;
		count++;
	}

	NumToString(GameChars[gCurChar].gold,text);		/** account balance **/
	GetDItem(gCastleDialog, 22, &itemType, &itemHandle, &itemRect);
RGBForeColor(&gSpecName);
	SetIText(itemHandle,text);	
RGBForeColor(&gBlack); 		
	
	while (dialogDone == FALSE)
	{
		ModalDialog(NIL_POINTER, &itemHit);
			switch (itemHit)
			{
				case 1:								/* LEAVE */
					DisposeDialog(gCastleDialog);
					dialogDone = TRUE;
					SetPort(gGameWindow);
					break;
				case 4:	
					theitem=itemCount[0];			 
					BuyItem(theitem,itemHit,price);
					break;
				case 6: 
					theitem=itemCount[1];			 
					BuyItem(theitem,itemHit,price);
					break;
				case 8: 
					theitem=itemCount[2];			 
					BuyItem(theitem,itemHit,price);
					break;
				case 10:
					theitem=itemCount[3];			 
					BuyItem(theitem,itemHit,price);
					break;
				case 12:
					theitem=itemCount[4];			 
					BuyItem(theitem,itemHit,price);
					break;
				case 14:
					theitem=itemCount[5];			 
					BuyItem(theitem,itemHit,price);
					break;
				case 16:
					theitem=itemCount[6];			 
					BuyItem(theitem,itemHit,price);
					break;
				case 18:
					theitem=itemCount[7];			 
					BuyItem(theitem,itemHit,price);
					break;
		}
	}
	
}


