size_t CChar::NPC_OnHearName(LPCTSTR pszText) const { ADDTOCALLSTACK("CChar::NPC_OnHearName"); // Did I just hear my name in this text ? // should be able to deal with "hi Dennis" in the future. // RETURN: // index to skip past the name. LPCTSTR pszName = GetName(); size_t i = FindStrWord(pszText, pszName); if ( i ) return i; // Named the chars type ? (must come first !) CCharBase *pCharDef = Char_GetDef(); pszName = pCharDef->GetTradeName(); for ( i = 0; pszText[i] != '\0'; i++ ) { if ( pszName[i] == '\0' ) { // found name while ( ISWHITESPACE(pszText[i]) ) i++; return i; // char name found } if ( toupper(pszName[i]) != toupper(pszText[i]) ) // not the name break; } return 0; }
size_t CChar::NPC_OnHearName( LPCTSTR pszText ) const { ADDTOCALLSTACK("CChar::NPC_OnHearName"); // Did I just hear my name in this text ? // should be able to deal with "hi Dennis" in the future. // RETURN: // index to skip past the name. LPCTSTR pszName = GetName(); size_t i = FindStrWord( pszText, pszName ); if ( i ) return( i ); if ( m_pNPC ) { // My title ? if ( m_pNPC->m_Brain == NPCBRAIN_GUARD ) { if ( ! strnicmp( pszText, "GUARD ", 6 )) return 6; } else if ( NPC_IsVendor()) { if ( ! strnicmp( pszText, "VENDOR ", 7 )) return 7; } } CCharBase * pCharDef = Char_GetDef(); // Named the chars type ? (must come first !) pszName = pCharDef->GetTradeName(); for ( i = 0; pszText[i] != '\0'; i++ ) { if ( pszName[i] == '\0' ) { // found name. while ( ISWHITESPACE( pszText[i] )) i++; return( i ); // Char name found } if ( toupper( pszName[i] ) != toupper( pszText[i] )) // not the name. break; } return( 0 ); }
bool CChar::NPC_OnTrainHear( CChar * pCharSrc, lpctstr pszCmd ) { ADDTOCALLSTACK("CChar::NPC_OnTrainHear"); // We are asking for training ? if ( ! m_pNPC ) return false; // Check the NPC is capable of teaching if ( (m_pNPC->m_Brain < NPCBRAIN_HUMAN) || (m_pNPC->m_Brain > NPCBRAIN_STABLE) || (m_pNPC->m_Brain == NPCBRAIN_GUARD) ) return false; // Check the NPC isn't busy fighting if ( Memory_FindObjTypes( pCharSrc, MEMORY_FIGHT|MEMORY_HARMEDBY|MEMORY_IRRITATEDBY|MEMORY_AGGREIVED )) { Speak( g_Cfg.GetDefaultMsg( DEFMSG_NPC_TRAINER_ENEMY ) ); return true; } // Did they mention a skill name i recognize ? TemporaryString pszMsg; for ( size_t i = 0; i < g_Cfg.m_iMaxSkill; i++ ) { if ( !g_Cfg.m_SkillIndexDefs.IsValidIndex(static_cast<SKILL_TYPE>(i)) ) continue; lpctstr pSkillKey = g_Cfg.GetSkillKey(static_cast<SKILL_TYPE>(i)); if ( FindStrWord( pszCmd, pSkillKey ) <= 0) continue; // Can we train in this ? int iTrainCost = NPC_OnTrainCheck(pCharSrc, static_cast<SKILL_TYPE>(i)) * g_Cfg.m_iTrainSkillCost; if ( iTrainCost <= 0 ) return true; sprintf(pszMsg, g_Cfg.GetDefaultMsg(DEFMSG_NPC_TRAINER_PRICE), iTrainCost, static_cast<lpctstr>(pSkillKey)); Speak(pszMsg); CItemMemory * pMemory = Memory_AddObjTypes( pCharSrc, MEMORY_SPEAK ); if ( pMemory ) { pMemory->m_itEqMemory.m_Action = NPC_MEM_ACT_SPEAK_TRAIN; pMemory->m_itEqMemory.m_Skill = (word)(i); } return true; } // What can he teach me about ? // Just tell them what we can teach them or set up a memory to train. strcpy( pszMsg, g_Cfg.GetDefaultMsg( DEFMSG_NPC_TRAINER_PRICE_1 ) ); lpctstr pPrvSkill = NULL; size_t iCount = 0; for ( size_t i = 0; i < g_Cfg.m_iMaxSkill; i++ ) { if ( !g_Cfg.m_SkillIndexDefs.IsValidIndex(static_cast<SKILL_TYPE>(i)) ) continue; int iDiff = NPC_GetTrainMax(pCharSrc, static_cast<SKILL_TYPE>(i)) - pCharSrc->Skill_GetBase(static_cast<SKILL_TYPE>(i)); if ( iDiff <= 0 ) continue; if ( iCount > 6 ) { pPrvSkill = g_Cfg.GetDefaultMsg( DEFMSG_NPC_TRAINER_PRICE_2 ); break; } if ( iCount > 1 ) { strcat( pszMsg, g_Cfg.GetDefaultMsg( DEFMSG_NPC_TRAINER_PRICE_3 ) ); } if ( pPrvSkill ) { strcat( pszMsg, pPrvSkill ); } pPrvSkill = g_Cfg.GetSkillKey(static_cast<SKILL_TYPE>(i)); iCount++; } if ( iCount == 0 ) { Speak( g_Cfg.GetDefaultMsg( DEFMSG_NPC_TRAINER_THATSALL_3 ) ); return true; } if ( iCount > 1 ) { strcat( pszMsg, g_Cfg.GetDefaultMsg( DEFMSG_NPC_TRAINER_THATSALL_4 ) ); } strcat( pszMsg, pPrvSkill ); strcat( pszMsg, "." ); Speak( pszMsg ); return true; }