n_eventnpc.cpp
上传用户:garry_shen
上传日期:2015-04-15
资源大小:45647k
文件大小:51k
- // N_EventNpc.cpp: implementation of the CN_EventNpc class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "......goodsGoodsGoods.h"
- #include "....Npc.h"
- #include "......Common.h"
- #include "N_EventNpc.h"
- #include "......config.h"
- #include "......commandcheck.h"
- extern char g_tszPathName[256];
- extern rmfullglobals myglobs;
- extern void GetXFileName(CPlayerInfo * lpPlayerInfo);
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CN_EventNpc::CN_EventNpc(char *szPath, char *szNpcFile):CN_Disciple(szPath, szNpcFile)
- {
- FILE *pFile = NULL;
- char szFileName[512], szBuf1[512], szBuf2[512];
- int nAskType = 0;
- g_HasEvent = 0;
- g_pNpcEvent = NULL;
- list<CEventAsk>::iterator iterEventAsk;
- char szKeyWord[128] = "NULL";
- nLimitCount = 0;
- strcpy(szFileName, szPath);
- strcat(szFileName, "\");
- strcat(szFileName, szNpcFile);
- pFile = fopen(szFileName,"r");
- if(pFile != NULL)
- {
- while(fscanf(pFile,"%s",szBuf1)!=EOF)
- {
- if(strcmp(szBuf1,"ㄆン") == 0)
- {
- fscanf(pFile,"%s",szBuf1);
- if(strcmp(szBuf1,"礚") != 0)
- {
- strcpy(szBuf2, g_tszPathName);
- strcat(szBuf2, "\Event\");
- strcat(szBuf2, szBuf1);
- LoadNpcEventFile(szBuf2);
- for(iterEventAsk = (g_pNpcEvent->EventAskList).begin(); iterEventAsk != (g_pNpcEvent->EventAskList).end(); iterEventAsk++)
- {
- switch(iterEventAsk->AskType)
- {
- case EV_KEYWORD_Visible :
- nAskType = NPCASK_visible;
- break;
- case EV_KEYWORD_Invisible :
- nAskType = 0;
- break;
- default :
- nAskType = 0;
- break;
- }
- strcpy(szKeyWord,(iterEventAsk->KeyWord).c_str());
- AddAsk(szKeyWord, nAskType, "");
- }
- }
- }else if(!strcmp(szBuf1,"禦芥")) {
- FILE *sfp=NULL;
- int kp=0;
- fscanf(pFile,"%s",szBuf1);
- if(strcmp(szBuf1,"礚") != 0) {
- strcpy(szBuf2, g_tszPathName);
- strcat(szBuf2, "\Event\");
- strcat(szBuf2, szBuf1);
- sfp = fopen(szBuf2,"r");
- nAsk = 0;
- while(fscanf(sfp,"%s",szBuf1)!=EOF) {
- //AssSale(szBuf1, 0,"");
- }
- }
- }
- } // while
- fclose(pFile);
- }else{
- }
- }
- CN_EventNpc::~CN_EventNpc()
- {
- }
- void CN_EventNpc::LoadNpcEventFile(char *szNpcEventFile)
- {
- // Load NPC Event File
- FILE *pFile;
- CString szStr;
- //char szBuf1[64], szBuf2[64], szBuf3[64], szBuf4[64];
- char szBuf1[512], szBuf2[512], szBuf3[512], szBuf4[512];
- int nBuf1 = 0, nBuf2 = 0, nBuf3 = 0, nBuf4 = 0;
- CEventAsk* pEventAsk = NULL;
- CEventLimit* pEventLimit = NULL;
- CEventRun* pEventRun = NULL;
- // initialize g_pNpcEvent start
- pFile = fopen(szNpcEventFile,"r");
- if(pFile != NULL)
- {
- g_pNpcEvent = new CNpcEvent;
- g_HasEvent = 1;
- (g_pNpcEvent->EventAskList).clear();
- while(fscanf(pFile,"%s",szBuf1)!=EOF) //while [AskItem]
- {
- szStr = szBuf1;
- if(szStr == "[AskEnd]")
- {
- continue;
- }
- else if(szStr == "[AskItem]")
- {
- if(fscanf(pFile, "%s %s %s", szBuf1, szBuf2, szBuf3) == 3)
- {
- nBuf1 = atoi(szBuf2);
- nBuf2 = atoi(szBuf3);
- pEventAsk = new CEventAsk(szBuf1, nBuf1, nBuf2);
- while(fscanf(pFile,"%s",szBuf1)!=EOF) //while [Default]
- {
- szStr = szBuf1;
- if(szStr == "[AskEnd]")
- {
- break;
- }
- else if(szStr == "[DefaultEnd]")
- {
- break;
- }
- else if(szStr == "[Default]")
- {
- // Read Default EventRun data
- fscanf(pFile,"%s",szBuf1);
- szStr = szBuf1;
- if(szStr == "[No]")
- {
- fscanf(pFile,"%s",szBuf1);
- if(strcmp(szBuf1, "NULLMSG") == 0)
- {
- strcpy(szBuf1, "");
- }
- pEventAsk->MsgDefaultWhenNo = szBuf1;
- while(fscanf(pFile,"%s",szBuf1)!=EOF) //while [Event] when [No]
- {
- szStr = szBuf1;
- if(szStr == "[NoEnd]")
- {
- break;
- }
- if(szStr == "[EventRun]")
- {
- if(fscanf(pFile, "%s %s %s %s", szBuf1, szBuf2, szBuf3, szBuf4) == 4)
- {
- pEventRun = new CEventRun;
- nBuf1 = atoi(szBuf1);
- pEventRun->EventRunType = nBuf1;
- pEventRun->EventRunItemName = szBuf2;
- nBuf3 = atoi(szBuf3);
- pEventRun->EventRunValue = nBuf3;
- nBuf4 = atoi(szBuf4);
- pEventRun->EventRunGoodKind = nBuf4;
- }
- (pEventAsk->DefaultEventRunListWhenNo).push_back(*pEventRun);
- delete pEventRun;
- }
- } //while [Default Event] when [No]
- } //if [Default No]
- fscanf(pFile,"%s",szBuf1);
- szStr = szBuf1;
- if(szStr == "[Yes]")
- {
- fscanf(pFile,"%s",szBuf1);
- if(strcmp(szBuf1, "NULLMSG") == 0)
- {
- strcpy(szBuf1, "");
- }
- pEventAsk->MsgDefaultWhenYes = szBuf1;
- while(fscanf(pFile,"%s",szBuf1)!=EOF) //while [Event] when [Yes]
- {
- szStr = szBuf1;
- if(szStr == "[YesEnd]")
- {
- break;
- }
- else if(szStr == "[EventRun]")
- {
- if(fscanf(pFile, "%s %s %s %s", szBuf1, szBuf2, szBuf3, szBuf4) == 4)
- {
- pEventRun = new CEventRun;
- nBuf1 = atoi(szBuf1);
- pEventRun->EventRunType = nBuf1;
- pEventRun->EventRunItemName = szBuf2;
- nBuf3 = atoi(szBuf3);
- pEventRun->EventRunValue = nBuf3;
- nBuf4 = atoi(szBuf4);
- pEventRun->EventRunGoodKind = nBuf4;
- }
- (pEventAsk->DefaultEventRunListWhenYes).push_back(*pEventRun);
- delete pEventRun;
- }
- } //while [Default Event] when [Yes]
- } // if [DefaultYes]
- }
- } //while [Default]
- // Read EventRun after checking limits
- while(fscanf(pFile,"%s",szBuf1)!=EOF) //while [Limit]
- {
- szStr = szBuf1;
- if(szStr == "[AskEnd]")
- {
- break;
- }
- else if(szStr == "[LimitEnd]")
- {
- continue;
- }
- else if(szStr == "[Limit]")
- {
- if(fscanf(pFile, "%s %s %s %s", szBuf1, szBuf2, szBuf3, szBuf4) == 4)
- {
- pEventLimit = new CEventLimit;
- nBuf1 = atoi(szBuf1);
- pEventLimit->LimitType = nBuf1;
- pEventLimit->LimitItemName = szBuf2;
- nBuf3 = atoi(szBuf3);
- pEventLimit->LimitValue = nBuf3;
- nBuf4 = atoi(szBuf4);
- pEventLimit->LimitGoodKind = nBuf4;
- fscanf(pFile,"%s",szBuf1);
- szStr = szBuf1;
- if(szStr == "[No]")
- {
- fscanf(pFile,"%s",szBuf1);
- if(strcmp(szBuf1, "NULLMSG") == 0)
- {
- strcpy(szBuf1, "");
- }
- pEventLimit->MsgWhenNo = szBuf1;
- while(fscanf(pFile,"%s",szBuf1)!=EOF) //while [Event] when [No]
- {
- szStr = szBuf1;
- if(szStr == "[NoEnd]")
- {
- break;
- }
- if(szStr == "[EventRun]")
- {
- if(fscanf(pFile, "%s %s %s %s", szBuf1, szBuf2, szBuf3, szBuf4) == 4)
- {
- pEventRun = new CEventRun;
- nBuf1 = atoi(szBuf1);
- pEventRun->EventRunType = nBuf1;
- pEventRun->EventRunItemName = szBuf2;
- nBuf3 = atoi(szBuf3);
- pEventRun->EventRunValue = nBuf3;
- nBuf4 = atoi(szBuf4);
- pEventRun->EventRunGoodKind = nBuf4;
- }
- (pEventLimit->EventRunListWhenNo).push_back(*pEventRun);
- delete pEventRun;
- }
- } //while [Event] when [No]
- } //if [No]
- fscanf(pFile,"%s",szBuf1);
- szStr = szBuf1;
- if(szStr == "[Yes]")
- {
- fscanf(pFile,"%s",szBuf1);
- if(strcmp(szBuf1, "NULLMSG") == 0)
- {
- strcpy(szBuf1, "");
- }
- pEventLimit->MsgWhenYes = szBuf1;
- while(fscanf(pFile,"%s",szBuf1)!=EOF) //while [Event] when [Yes]
- {
- szStr = szBuf1;
- if(szStr == "[YesEnd]")
- {
- break;
- }
- else if(szStr == "[EventRun]")
- {
- if(fscanf(pFile, "%s %s %s %s", szBuf1, szBuf2, szBuf3, szBuf4) == 4)
- {
- pEventRun = new CEventRun;
- nBuf1 = atoi(szBuf1);
- pEventRun->EventRunType = nBuf1;
- pEventRun->EventRunItemName = szBuf2;
- nBuf3 = atoi(szBuf3);
- pEventRun->EventRunValue = nBuf3;
- nBuf4 = atoi(szBuf4);
- pEventRun->EventRunGoodKind = nBuf4;
- }
- (pEventLimit->EventRunListWhenYes).push_back(*pEventRun);
- delete pEventRun;
- }
- } //while [Event] when [Yes]
- } // if [Yes]
- }
- (pEventAsk->LimitList).push_back(*pEventLimit);
- delete pEventLimit;
- }
- } //while [Limit]
- }
- (g_pNpcEvent->EventAskList).push_back(*pEventAsk);
- delete pEventAsk;
- }
- } //while [AskItem]
- fclose(pFile);
- }
- }
- TRetInfo CN_EventNpc::DoAsk(CPlayerInfo *who, CString szName)
- {
- TRetInfo ri;
- list<CEventAsk>::iterator iterEventAsk;
- ri = CNpc::DoAsk(who, szName,"$NONE$");
- if (!ri.bRet) return ri;
- if(g_HasEvent == 1){
- for(iterEventAsk = (g_pNpcEvent->EventAskList).begin(); iterEventAsk != (g_pNpcEvent->EventAskList).end(); iterEventAsk++)
- {
- if ( !strcmp(szName, (iterEventAsk->KeyWord).c_str() ) ){
- ri = DoEventLimit(who, iterEventAsk);
- return ri;
- }
- }
- }
- ri.bRet = TRUE;
- return ri;
- }
- TRetInfo CN_EventNpc::DoEventLimit(CPlayerInfo *who, list<CEventAsk>::iterator iterEventAsk)
- {
- int IsYes = -1;
- TRetInfo ri;
- list<CEventLimit>::iterator iterLimit, iterEndLimit;
- char szLimitItemName[64] = "NULL";
- CGoods *pGood = NULL;
- POSITION pos;
- switch(iterEventAsk->LimitChoose)
- {
- case EV_LIMITCHOOSE_All :
- IsYes = 1;
- for(iterLimit = (iterEventAsk->LimitList).begin(); iterLimit != (iterEventAsk->LimitList).end(); iterLimit++)
- {
- strcpy(szLimitItemName, (iterLimit->LimitItemName).c_str());
- switch(iterLimit->LimitType){
- case EV_LIMIT_NotDefine:
- ri.szRet = "iterEventAsk->LimitType=LIMIT_NotDefine";
- break;
- case EV_LIMIT_GoodHasGot:
- if(who->GetGoods(szLimitItemName) == NULL)
- {
- IsYes = 0;
- }
- break;
- case EV_LIMIT_GoodHasNotGot:
- if(who->GetGoods(szLimitItemName) != NULL)
- {
- IsYes = 0;
- }
- break;
- case EV_LIMIT_GoodCountMore:
- if(who->GetGoodCount(szLimitItemName) <= iterLimit->LimitValue){
- IsYes = 0;
- }
- break;
- case EV_LIMIT_GoodCountEqual:
- if(who->GetGoodCount(szLimitItemName) != iterLimit->LimitValue)
- {
- IsYes = 0;
- }
- break;
- case EV_LIMIT_GoodCountLess:
- if(who->GetGoodCount(szLimitItemName) >= iterLimit->LimitValue)
- {
- IsYes = 0;
- }
- break;
- case EV_LIMIT_MoneyMore:
- if(who->nMoney <= iterLimit->LimitValue){
- IsYes = 0;
- }
- break;
- case EV_LIMIT_MoneyLess:
- if(who->nMoney >= iterLimit->LimitValue){
- IsYes = 0;
- }
- break;
- case EV_LIMIT_StatusPointMore:
- if( strcmp("