n_eventnpc.cpp
上传用户:garry_shen
上传日期:2015-04-15
资源大小:45647k
文件大小:51k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. // N_EventNpc.cpp: implementation of the CN_EventNpc class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "......goodsGoodsGoods.h"
  6. #include "....Npc.h"
  7. #include "......Common.h"
  8. #include "N_EventNpc.h"
  9. #include "......config.h"
  10. #include "......commandcheck.h"
  11. extern char g_tszPathName[256];
  12. extern rmfullglobals myglobs;
  13. extern void GetXFileName(CPlayerInfo * lpPlayerInfo);
  14. //////////////////////////////////////////////////////////////////////
  15. // Construction/Destruction
  16. //////////////////////////////////////////////////////////////////////
  17. CN_EventNpc::CN_EventNpc(char *szPath, char *szNpcFile):CN_Disciple(szPath, szNpcFile)
  18. {
  19. FILE *pFile = NULL;
  20. char szFileName[512], szBuf1[512], szBuf2[512];
  21. int nAskType = 0;
  22. g_HasEvent = 0;
  23. g_pNpcEvent = NULL;
  24. list<CEventAsk>::iterator iterEventAsk;
  25. char szKeyWord[128] = "NULL";
  26. nLimitCount = 0;
  27. strcpy(szFileName, szPath);
  28. strcat(szFileName, "\");
  29. strcat(szFileName, szNpcFile);
  30.     pFile = fopen(szFileName,"r");
  31. if(pFile != NULL)
  32. {
  33.         while(fscanf(pFile,"%s",szBuf1)!=EOF)
  34. {
  35.             if(strcmp(szBuf1,"ㄆン") == 0)
  36. {
  37. fscanf(pFile,"%s",szBuf1);
  38. if(strcmp(szBuf1,"礚") != 0)
  39. {
  40. strcpy(szBuf2, g_tszPathName);
  41. strcat(szBuf2, "\Event\");
  42. strcat(szBuf2, szBuf1);
  43. LoadNpcEventFile(szBuf2);
  44. for(iterEventAsk = (g_pNpcEvent->EventAskList).begin(); iterEventAsk != (g_pNpcEvent->EventAskList).end(); iterEventAsk++)
  45. {
  46. switch(iterEventAsk->AskType)
  47. {
  48. case EV_KEYWORD_Visible :
  49. nAskType = NPCASK_visible;
  50. break;
  51. case EV_KEYWORD_Invisible :
  52. nAskType = 0;
  53. break;
  54. default :
  55. nAskType = 0;
  56. break;
  57. }
  58. strcpy(szKeyWord,(iterEventAsk->KeyWord).c_str());
  59. AddAsk(szKeyWord, nAskType, "");
  60. }
  61. }
  62. }else if(!strcmp(szBuf1,"禦芥")) {
  63. FILE *sfp=NULL;
  64. int kp=0;
  65. fscanf(pFile,"%s",szBuf1);
  66. if(strcmp(szBuf1,"礚") != 0) {
  67. strcpy(szBuf2, g_tszPathName);
  68. strcat(szBuf2, "\Event\");
  69. strcat(szBuf2, szBuf1);
  70. sfp = fopen(szBuf2,"r");
  71. nAsk = 0;
  72.  while(fscanf(sfp,"%s",szBuf1)!=EOF) {
  73.  //AssSale(szBuf1, 0,"");
  74.  }
  75. }
  76. }
  77. } // while
  78. fclose(pFile);
  79. }else{
  80. }
  81. }
  82. CN_EventNpc::~CN_EventNpc()
  83. {
  84. }
  85. void CN_EventNpc::LoadNpcEventFile(char *szNpcEventFile)
  86. {
  87.     // Load NPC Event File
  88.     FILE *pFile;
  89.     CString szStr;
  90.     //char szBuf1[64], szBuf2[64], szBuf3[64], szBuf4[64];
  91. char szBuf1[512], szBuf2[512], szBuf3[512], szBuf4[512];
  92.     int nBuf1 = 0, nBuf2 = 0, nBuf3 = 0, nBuf4 = 0;
  93.     CEventAsk*   pEventAsk = NULL;
  94.     CEventLimit* pEventLimit = NULL;
  95.     CEventRun*   pEventRun = NULL;
  96. // initialize g_pNpcEvent start
  97.     pFile = fopen(szNpcEventFile,"r");
  98. if(pFile != NULL)
  99. {
  100. g_pNpcEvent = new CNpcEvent;
  101. g_HasEvent = 1;
  102.         (g_pNpcEvent->EventAskList).clear();
  103.         while(fscanf(pFile,"%s",szBuf1)!=EOF)     //while [AskItem]
  104. {
  105.             szStr = szBuf1;
  106.             if(szStr == "[AskEnd]")
  107.             {
  108.                 continue;
  109.             }
  110.             else if(szStr == "[AskItem]")
  111.             {
  112.                 if(fscanf(pFile, "%s %s %s", szBuf1, szBuf2, szBuf3) == 3)
  113.                 {
  114.                     nBuf1 = atoi(szBuf2);
  115.                     nBuf2 = atoi(szBuf3);
  116.                     pEventAsk = new CEventAsk(szBuf1, nBuf1, nBuf2);
  117.                     while(fscanf(pFile,"%s",szBuf1)!=EOF)     //while [Default]
  118.                     {
  119.                         szStr = szBuf1;
  120.                         if(szStr == "[AskEnd]")
  121.                         {
  122.                             break;
  123.                         }
  124.                         else if(szStr == "[DefaultEnd]")
  125.                         {
  126.                             break;
  127.                         }
  128.                         else if(szStr == "[Default]")
  129.                         {
  130. // Read Default EventRun data
  131.                             fscanf(pFile,"%s",szBuf1);
  132.                             szStr = szBuf1;
  133.                             if(szStr == "[No]")
  134.                             {
  135.                                 fscanf(pFile,"%s",szBuf1);
  136.                                 if(strcmp(szBuf1, "NULLMSG") == 0)
  137.                                 {
  138.                                     strcpy(szBuf1, "");
  139.                                 }
  140.                                 pEventAsk->MsgDefaultWhenNo = szBuf1;
  141.                                 while(fscanf(pFile,"%s",szBuf1)!=EOF)     //while [Event] when [No]
  142.                                 {
  143.                                     szStr = szBuf1;
  144.                                     if(szStr == "[NoEnd]")
  145.                                     {
  146.                                         break;
  147.                                     }
  148.                                     if(szStr == "[EventRun]")
  149.                                     {
  150.                                         if(fscanf(pFile, "%s %s %s %s", szBuf1, szBuf2, szBuf3, szBuf4) == 4)
  151.                                         {
  152.                                             pEventRun = new CEventRun;
  153.                                             nBuf1 = atoi(szBuf1);
  154.                                             pEventRun->EventRunType = nBuf1;
  155.                                             pEventRun->EventRunItemName = szBuf2;
  156.                                              nBuf3 = atoi(szBuf3);
  157.                                             pEventRun->EventRunValue = nBuf3;
  158.                                      nBuf4 = atoi(szBuf4);
  159.                                pEventRun->EventRunGoodKind = nBuf4;
  160.                                         }
  161.                                         (pEventAsk->DefaultEventRunListWhenNo).push_back(*pEventRun);
  162.                                         delete pEventRun;
  163.                                     }
  164.                                 }    //while [Default Event] when [No]
  165.                             }    //if [Default No]
  166.                             fscanf(pFile,"%s",szBuf1);
  167.                             szStr = szBuf1;
  168.                             if(szStr == "[Yes]")
  169.                             {
  170.                                 fscanf(pFile,"%s",szBuf1);
  171.                                 if(strcmp(szBuf1, "NULLMSG") == 0)
  172.                                 {
  173.                                     strcpy(szBuf1, "");
  174.                                 }
  175.                                 pEventAsk->MsgDefaultWhenYes = szBuf1;
  176.                                 while(fscanf(pFile,"%s",szBuf1)!=EOF)     //while [Event] when [Yes]
  177.                                 {
  178.                                     szStr = szBuf1;
  179.                                     if(szStr == "[YesEnd]")
  180.                                     {
  181.                                         break;
  182.                                     }
  183.                                     else if(szStr == "[EventRun]")
  184.                                     {
  185.                                         if(fscanf(pFile, "%s %s %s %s", szBuf1, szBuf2, szBuf3, szBuf4) == 4)
  186.                                         {
  187.                                             pEventRun = new CEventRun;
  188.                                             nBuf1 = atoi(szBuf1);
  189.                                             pEventRun->EventRunType = nBuf1;
  190.                                             pEventRun->EventRunItemName = szBuf2;
  191.                                             nBuf3 = atoi(szBuf3);   
  192.                                             pEventRun->EventRunValue = nBuf3;
  193.                                 nBuf4 = atoi(szBuf4);
  194.                                pEventRun->EventRunGoodKind = nBuf4;
  195.                                         }
  196.                                         (pEventAsk->DefaultEventRunListWhenYes).push_back(*pEventRun);
  197.                                         delete pEventRun;
  198.                                     }
  199.                                 }    //while [Default Event] when [Yes]
  200.                             }    // if [DefaultYes]
  201.                         }
  202.                     }    //while [Default]
  203. // Read EventRun after checking limits
  204.                     while(fscanf(pFile,"%s",szBuf1)!=EOF)     //while [Limit]
  205.                     {
  206.                         szStr = szBuf1;
  207.                         if(szStr == "[AskEnd]")
  208.                         {
  209.                             break;
  210.                         }
  211.                         else if(szStr == "[LimitEnd]")
  212.                         {
  213.                             continue;
  214.                         }
  215.                         else if(szStr == "[Limit]")
  216.                         {
  217.                             if(fscanf(pFile, "%s %s %s %s", szBuf1, szBuf2, szBuf3, szBuf4) == 4)
  218.                             {
  219.                                 pEventLimit = new CEventLimit;
  220.                                 nBuf1 = atoi(szBuf1);
  221.                                 pEventLimit->LimitType = nBuf1;
  222.                                 pEventLimit->LimitItemName = szBuf2;
  223.                                 nBuf3 = atoi(szBuf3);
  224.                                 pEventLimit->LimitValue = nBuf3;
  225.                                 nBuf4 = atoi(szBuf4);
  226.                                 pEventLimit->LimitGoodKind = nBuf4;
  227.                                 fscanf(pFile,"%s",szBuf1);
  228.                                 szStr = szBuf1;
  229.                                 if(szStr == "[No]")
  230.                                 {
  231.                                     fscanf(pFile,"%s",szBuf1);
  232.                                     if(strcmp(szBuf1, "NULLMSG") == 0)
  233.                                     {
  234.                                         strcpy(szBuf1, "");
  235.                                     }
  236.                                     pEventLimit->MsgWhenNo = szBuf1;
  237.                                     while(fscanf(pFile,"%s",szBuf1)!=EOF)     //while [Event] when [No]
  238.                                     {
  239.                                         szStr = szBuf1;
  240.                                         if(szStr == "[NoEnd]")
  241.                                         {
  242.                                             break;
  243.                                         }
  244.                                         if(szStr == "[EventRun]")
  245.                                         {
  246.                                             if(fscanf(pFile, "%s %s %s %s", szBuf1, szBuf2, szBuf3, szBuf4) == 4)
  247.                                             {
  248.                                                 pEventRun = new CEventRun;
  249.                                                 nBuf1 = atoi(szBuf1);
  250.                                                 pEventRun->EventRunType = nBuf1;
  251.                                                 pEventRun->EventRunItemName = szBuf2;
  252.                                                 nBuf3 = atoi(szBuf3);
  253.                                                 pEventRun->EventRunValue = nBuf3;
  254.                                 nBuf4 = atoi(szBuf4);
  255.                                  pEventRun->EventRunGoodKind = nBuf4;
  256.                                             }
  257.                                             (pEventLimit->EventRunListWhenNo).push_back(*pEventRun);
  258.                                             delete pEventRun;
  259.                                         }
  260.                                     }    //while [Event] when [No]
  261.                                 }    //if [No]
  262.                                 fscanf(pFile,"%s",szBuf1);
  263.                                 szStr = szBuf1;
  264.                                 if(szStr == "[Yes]")
  265.                                 {
  266.                                     fscanf(pFile,"%s",szBuf1);
  267.                                     if(strcmp(szBuf1, "NULLMSG") == 0)
  268.                                     {
  269.                                         strcpy(szBuf1, "");
  270.                                     }
  271.                                     pEventLimit->MsgWhenYes = szBuf1;
  272.                                     while(fscanf(pFile,"%s",szBuf1)!=EOF)     //while [Event] when [Yes]
  273.                                     {
  274.                                         szStr = szBuf1;
  275.                                         if(szStr == "[YesEnd]")
  276.                                         {
  277.                                             break;
  278.                                         }
  279.                                         else if(szStr == "[EventRun]")
  280.                                         {
  281.                                             if(fscanf(pFile, "%s %s %s %s", szBuf1, szBuf2, szBuf3, szBuf4) == 4)
  282.                                             {
  283.                                                 pEventRun = new CEventRun;
  284.                                                 nBuf1 = atoi(szBuf1);
  285.                                                 pEventRun->EventRunType = nBuf1;
  286.                                                 pEventRun->EventRunItemName = szBuf2;
  287.                                                 nBuf3 = atoi(szBuf3);
  288.                                                 pEventRun->EventRunValue = nBuf3;
  289.                                 nBuf4 = atoi(szBuf4);
  290.                                  pEventRun->EventRunGoodKind = nBuf4;
  291.                                             }
  292.                                             (pEventLimit->EventRunListWhenYes).push_back(*pEventRun);
  293.                                             delete pEventRun;
  294.                                         }
  295.                                     }    //while [Event] when [Yes]
  296.                                 }    // if [Yes]
  297.                             }
  298.                             (pEventAsk->LimitList).push_back(*pEventLimit);
  299.                             delete pEventLimit;
  300.                         }
  301.                     }    //while [Limit]
  302.                 }
  303.                 (g_pNpcEvent->EventAskList).push_back(*pEventAsk);
  304.                 delete pEventAsk;
  305.             }
  306.         }    //while [AskItem]
  307.         fclose(pFile);
  308.     }
  309. }
  310. TRetInfo CN_EventNpc::DoAsk(CPlayerInfo *who, CString szName)
  311. {
  312. TRetInfo ri;
  313. list<CEventAsk>::iterator iterEventAsk;
  314. ri = CNpc::DoAsk(who, szName,"$NONE$");
  315. if (!ri.bRet) return ri;
  316.     if(g_HasEvent == 1){
  317. for(iterEventAsk = (g_pNpcEvent->EventAskList).begin(); iterEventAsk != (g_pNpcEvent->EventAskList).end(); iterEventAsk++)
  318. {
  319. if ( !strcmp(szName, (iterEventAsk->KeyWord).c_str() ) ){
  320. ri = DoEventLimit(who, iterEventAsk);
  321. return ri;
  322. }
  323. }
  324. }
  325. ri.bRet = TRUE;
  326. return ri;
  327. }
  328. TRetInfo CN_EventNpc::DoEventLimit(CPlayerInfo *who, list<CEventAsk>::iterator iterEventAsk)
  329. {
  330. int IsYes = -1;
  331. TRetInfo ri;
  332.     list<CEventLimit>::iterator iterLimit, iterEndLimit;
  333. char szLimitItemName[64] = "NULL";
  334. CGoods *pGood = NULL;
  335. POSITION pos;
  336. switch(iterEventAsk->LimitChoose)
  337. {
  338. case EV_LIMITCHOOSE_All :
  339. IsYes = 1;
  340. for(iterLimit = (iterEventAsk->LimitList).begin(); iterLimit != (iterEventAsk->LimitList).end(); iterLimit++)
  341.          {
  342. strcpy(szLimitItemName, (iterLimit->LimitItemName).c_str());
  343. switch(iterLimit->LimitType){
  344.                         case EV_LIMIT_NotDefine:
  345. ri.szRet = "iterEventAsk->LimitType=LIMIT_NotDefine";
  346.                                 break;
  347.                         case EV_LIMIT_GoodHasGot:
  348. if(who->GetGoods(szLimitItemName) == NULL)
  349. {
  350. IsYes = 0;
  351. }
  352.                                 break;
  353.                         case EV_LIMIT_GoodHasNotGot:
  354. if(who->GetGoods(szLimitItemName) != NULL)
  355. {
  356. IsYes = 0;
  357. }
  358.                              break;
  359.                         case EV_LIMIT_GoodCountMore:
  360. if(who->GetGoodCount(szLimitItemName) <= iterLimit->LimitValue){
  361. IsYes = 0;
  362. }
  363.                     break;
  364.                         case EV_LIMIT_GoodCountEqual:
  365. if(who->GetGoodCount(szLimitItemName) != iterLimit->LimitValue)
  366. {
  367. IsYes = 0;
  368. }
  369.                                 break;
  370.                         case EV_LIMIT_GoodCountLess:
  371. if(who->GetGoodCount(szLimitItemName) >= iterLimit->LimitValue)
  372. {
  373. IsYes = 0;
  374. }
  375.                                 break;
  376.                         case EV_LIMIT_MoneyMore:
  377. if(who->nMoney <= iterLimit->LimitValue){
  378. IsYes = 0;
  379. }
  380.                                 break;
  381.                         case EV_LIMIT_MoneyLess:
  382. if(who->nMoney >= iterLimit->LimitValue){
  383. IsYes = 0;
  384. }
  385.                                 break;
  386.                         case EV_LIMIT_StatusPointMore:
  387. if( strcmp("