本文整理汇总了C++中CChar::GetName方法的典型用法代码示例。如果您正苦于以下问题:C++ CChar::GetName方法的具体用法?C++ CChar::GetName怎么用?C++ CChar::GetName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CChar
的用法示例。
在下文中一共展示了CChar::GetName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MessageEvent
// ---------------------------------------------------------
bool CPartyDef::MessageEvent( CGrayUID uidDst, CGrayUID uidSrc, const NCHAR *pText, int ilenmsg )
{
ADDTOCALLSTACK("CPartyDef::MessageEvent");
UNREFERENCED_PARAMETER(ilenmsg);
if ( pText == NULL )
return false;
if ( uidDst && !IsInParty(uidDst.CharFind()) )
return false;
CChar *pFrom = uidSrc.CharFind();
CChar *pTo = NULL;
if ( uidDst )
pTo = uidDst.CharFind();
TCHAR *szText = Str_GetTemp();
CvtNUNICODEToSystem(szText, MAX_TALK_BUFFER, pText, MAX_TALK_BUFFER);
if ( !m_pSpeechFunction.IsEmpty() )
{
TRIGRET_TYPE tr = TRIGRET_RET_FALSE;
CScriptTriggerArgs Args;
Args.m_iN1 = uidSrc;
Args.m_iN2 = uidDst;
Args.m_s1 = szText;
Args.m_s1_raw = szText;
if ( r_Call(m_pSpeechFunction, &g_Serv, &Args, NULL, &tr) )
{
if ( tr == TRIGRET_RET_TRUE )
return false;
}
}
if ( g_Log.IsLoggedMask(LOGM_PLAYER_SPEAK) )
g_Log.Event(LOGM_PLAYER_SPEAK, "%lx:'%s' Says '%s' in party to '%s'\n", pFrom->m_pClient->GetSocketID(), pFrom->GetName(), szText, pTo ? pTo->GetName() : "all");
sprintf(szText, g_Cfg.GetDefaultMsg(DEFMSG_PARTY_MSG), pText);
PacketPartyChat cmd(pFrom, pText);
if ( pTo )
SendMemberMsg(pTo, &cmd);
else
SendAll(&cmd);
return true;
}
示例2: Cmd_Skill_Tracking
//.........这里部分代码省略.........
NPCBRAIN_MONSTER,
NPCBRAIN_HUMAN,
NPCBRAIN_NONE // players
};
if ( track_sel >= COUNTOF(sm_Track_Brain))
track_sel = COUNTOF(sm_Track_Brain)-1;
NPCBRAIN_TYPE track_type = sm_Track_Brain[ track_sel ];
CMenuItem item[ minimum( MAX_MENU_ITEMS, COUNTOF( m_tmMenu.m_Item )) ];
size_t count = 0;
item[0].m_sText = g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_SKILLMENU_TITLE );
m_tmMenu.m_Item[0] = track_sel;
CWorldSearch AreaChars( m_pChar->GetTopPoint(), m_pChar->Skill_GetBase(SKILL_TRACKING)/10 + 10 );
for (;;)
{
CChar * pChar = AreaChars.GetChar();
if ( pChar == NULL )
break;
if ( m_pChar == pChar )
continue;
if ( GetPrivLevel() < pChar->GetPrivLevel() && pChar->IsStatFlag(STATF_Insubstantial) )
continue;
CCharBase * pCharDef = pChar->Char_GetDef();
NPCBRAIN_TYPE basic_type = pChar->GetNPCBrain();
if ( basic_type == NPCBRAIN_DRAGON )
basic_type = NPCBRAIN_MONSTER;
if ( track_type != basic_type && track_type != NPCBRAIN_QTY )
{
if ( track_type != NPCBRAIN_NONE ) // no match.
continue;
if ( pChar->IsStatFlag( STATF_DEAD )) // can't track ghosts
continue;
if ( ! pChar->m_pPlayer )
continue;
// Check action difficulty when trying to track players
int tracking = m_pChar->Skill_GetBase( SKILL_TRACKING );
int detectHidden = m_pChar->Skill_GetBase( SKILL_DETECTINGHIDDEN );
if ( g_Cfg.m_iFeatureML & FEATURE_ML_RACIAL_BONUS && pChar->IsElf() )
tracking /= 2; // elves are more difficult to track (Difficult to Track racial trait)
int hiding = pChar->Skill_GetBase( SKILL_HIDING );
int stealth = pChar->Skill_GetBase( SKILL_STEALTH );
int divisor = maximum(hiding + stealth, 1);
int chance;
if ( g_Cfg.m_iFeatureSE & FEATURE_SE_UPDATE )
chance = 50 * (tracking * 2 + detectHidden) / divisor;
else
chance = 50 * (tracking + detectHidden + 10 * Calc_GetRandVal(20) ) / divisor;
if ( Calc_GetRandVal(100) > chance )
continue;
}
count ++;
item[count].m_id = static_cast<WORD>(pCharDef->m_trackID);
item[count].m_color = 0;
item[count].m_sText = pChar->GetName();
m_tmMenu.m_Item[count] = pChar->GetUID();
if ( count >= (COUNTOF( item )-1) )
break;
}
// Some credit for trying.
if ( count > 0 )
{
m_pChar->Skill_UseQuick( SKILL_TRACKING, 20 + Calc_GetRandLLVal( 30 ));
ASSERT(count < COUNTOF(item));
addItemMenu( CLIMODE_MENU_SKILL_TRACK, item, count );
return( true );
}
else
{
m_pChar->Skill_UseQuick( SKILL_TRACKING, 10 + Calc_GetRandLLVal( 30 ));
}
}
// Tracking failed or was cancelled.
static LPCTSTR const sm_Track_FailMsg[] =
{
g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_CANCEL ),
g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_FAIL_ANIMAL ),
g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_FAIL_MONSTER ),
g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_FAIL_HUMAN ),
g_Cfg.GetDefaultMsg( DEFMSG_TRACKING_FAIL_HUMAN )
};
if (track_sel >= COUNTOF(sm_Track_FailMsg))
track_sel = COUNTOF(sm_Track_FailMsg) - 1;
SysMessage( sm_Track_FailMsg[track_sel] );
return( false );
}
示例3: NPC_OnHearPetCmdTarg
bool CChar::NPC_OnHearPetCmdTarg( int iCmd, CChar *pSrc, CObjBase *pObj, const CPointMap &pt, LPCTSTR pszArgs )
{
ADDTOCALLSTACK("CChar::NPC_OnHearPetCmdTarg");
// Pet commands that required a target.
if ( m_fIgnoreNextPetCmd )
{
m_fIgnoreNextPetCmd = false;
return false;
}
switch ( iCmd )
{
case PC_FOLLOW:
case PC_STAY:
case PC_STOP:
{
// Pet friends can use only these commands
if ( Memory_FindObjTypes(pSrc, MEMORY_FRIEND) )
break;
}
default:
{
// All others commands are avaible only to pet owner
if ( !NPC_IsOwnedBy(pSrc, true) )
return false;
}
}
if ( IsStatFlag(STATF_DEAD) )
{
// Bonded NPCs still placed on world even when dead.
// They can listen to commands, but not to these commands below
if ( iCmd == PC_GUARD || iCmd == PC_GUARD_ME || iCmd == PC_ATTACK || iCmd == PC_KILL || iCmd == PC_TRANSFER || iCmd == PC_DROP || iCmd == PC_DROP_ALL )
return true;
}
bool bSuccess = false;
CItem *pItemTarg = dynamic_cast<CItem *>(pObj);
CChar *pCharTarg = dynamic_cast<CChar *>(pObj);
switch ( iCmd )
{
case PC_ATTACK:
case PC_KILL:
{
if ( !pCharTarg || pCharTarg == pSrc )
break;
bSuccess = pCharTarg->OnAttackedBy(pSrc, 1, true); // we know who told them to do this.
if ( bSuccess )
bSuccess = Fight_Attack(pCharTarg, true);
break;
}
case PC_FOLLOW:
if ( !pCharTarg )
break;
m_Act_Targ = pCharTarg->GetUID();
bSuccess = Skill_Start(NPCACT_FOLLOW_TARG);
break;
case PC_FRIEND:
{
if ( !pCharTarg || !pCharTarg->m_pPlayer || pCharTarg == pSrc )
{
Speak(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_CONFUSED));
break;
}
CItemMemory *pMemory = Memory_FindObjTypes(pCharTarg, MEMORY_FRIEND);
if ( pMemory )
{
pSrc->SysMessage(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_FRIEND_ALREADY));
break;
}
pSrc->SysMessagef(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_FRIEND_SUCCESS1), GetName(), pCharTarg->GetName());
pCharTarg->SysMessagef(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_FRIEND_SUCCESS2), pSrc->GetName(), GetName());
Memory_AddObjTypes(pCharTarg, MEMORY_FRIEND);
m_Act_Targ = pCharTarg->GetUID();
bSuccess = Skill_Start(NPCACT_FOLLOW_TARG);
break;
}
case PC_UNFRIEND:
{
if ( !pCharTarg || !pCharTarg->m_pPlayer )
{
Speak(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_CONFUSED));
break;
}
CItemMemory *pMemory = Memory_FindObjTypes(pCharTarg, MEMORY_FRIEND);
if ( !pMemory )
{
pSrc->SysMessage(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_UNFRIEND_NOTFRIEND));
break;
}
pSrc->SysMessagef(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_UNFRIEND_SUCCESS1), GetName(), pCharTarg->GetName());
pCharTarg->SysMessagef(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_UNFRIEND_SUCCESS2), pSrc->GetName(), GetName());
pMemory->Delete();
//.........这里部分代码省略.........
示例4: NPC_GetHostilityLevelToward
int CChar::NPC_GetHostilityLevelToward( const CChar * pCharTarg ) const
{
ADDTOCALLSTACK("CChar::NPC_GetHostilityLevelToward");
// What is my general hostility level toward this type of creature ?
//
// based on:
// npc vs player, (evil npc's don't like players regurdless of align, xcept in town)
// karma (we are of different alignments)
// creature body type. (allie groups)
// hunger, (they could be food)
// memories of this creature.
//
// DO NOT consider:
// strength, he is far stronger or waeker than me.
// health, i may be near death.
// location (guarded area), (xcept in the case that evil people like other evils in town)
// loot, etc.
//
// RETURN:
// 100 = extreme hatred.
// 0 = neutral.
// -100 = love them
//
if ( !pCharTarg || !m_pNPC )
return 0;
int iHostility = 0;
// if it is a pet - register it the same as it's master.
CChar * pCharOwn = pCharTarg->NPC_PetGetOwner();
if ( pCharOwn != NULL && pCharOwn != this )
{
static int sm_iReentrant = 0;
if (sm_iReentrant > 32)
{
DEBUG_ERR(("Too many owners (circular ownership?) to continue acquiring hostility level towards %s uid=0%lx\n", pCharOwn->GetName(), pCharOwn->GetUID().GetPrivateUID()));
return 0;
}
++sm_iReentrant;
iHostility = NPC_GetHostilityLevelToward( pCharOwn );
--sm_iReentrant;
return iHostility;
}
int iKarma = Stat_GetAdjusted(STAT_KARMA);
bool fDoMemBase = false;
if ( Noto_IsEvil() && // i am evil.
(m_pArea && !m_pArea->IsGuarded()) && // we are not in an evil town.
pCharTarg->m_pPlayer ) // my target is a player.
{
// If i'm evil i give no benefit to players with bad karma.
// I hate all players.
// Unless i'm in a guarded area. then they are cool.
iHostility = 51;
}
else if ( m_pNPC->m_Brain == NPCBRAIN_BERSERK ) // i'm beserk.
{
// beserks just hate everyone all the time.
iHostility = 100;
}
else if ( pCharTarg->m_pNPC && // my target is an NPC
pCharTarg->m_pNPC->m_Brain != NPCBRAIN_BERSERK && // ok to hate beserks.
! g_Cfg.m_fMonsterFight ) // monsters are not supposed to fight other monsters !
{
iHostility = -50;
fDoMemBase = true; // set this low in case we are defending ourselves. but not attack for hunger.
}
else
{
// base hostillity on karma diff.
int iKarmaTarg = pCharTarg->Stat_GetAdjusted(STAT_KARMA);
if ( Noto_IsEvil())
{
// I'm evil.
if ( iKarmaTarg > 0 )
{
iHostility += ( iKarmaTarg ) / 1024;
}
}
else if ( iKarma > 300 )
{
// I'm good and my target is evil.
if ( iKarmaTarg < -100 )
{
iHostility += ( -iKarmaTarg ) / 1024;
}
}
}
// Based on just creature type.
if ( ! fDoMemBase )
//.........这里部分代码省略.........
示例5: OnTick
//.........这里部分代码省略.........
// Lightning ? // wind, rain,
switch ( GetWeather() )
{
case WEATHER_CLOUDY:
break;
case WEATHER_SNOW:
if ( ! Calc_GetRandVal(5) )
sound = sm_SfxWind[ Calc_GetRandVal( CountOf( sm_SfxWind )) ];
break;
case WEATHER_RAIN:
{
int iVal = Calc_GetRandVal(30);
if ( iVal < 5 )
{
// Mess up the light levels for a sec..
LightFlash();
sound = sm_SfxThunder[ Calc_GetRandVal( CountOf( sm_SfxThunder )) ];
}
else if ( iVal < 10 )
sound = sm_SfxRain[ Calc_GetRandVal( CountOf( sm_SfxRain )) ];
else if ( iVal < 15 )
sound = sm_SfxWind[ Calc_GetRandVal( CountOf( sm_SfxWind )) ];
}
break;
default:
break;
}
}
// Check environ changes and inform clients of it.
ProfileTask charactersTask(PROFILE_CHARS);
CChar * pCharNext = nullptr;
CChar * pChar = static_cast <CChar*>( m_Chars_Active.GetHead());
for ( ; pChar != nullptr; pChar = pCharNext )
{
EXC_TRYSUB("TickChar");
pCharNext = pChar->GetNext();
if (( fEnvironChange ) && ( IsTrigUsed(TRIGGER_ENVIRONCHANGE) ))
pChar->OnTrigger(CTRIG_EnvironChange, pChar);
if ( pChar->IsClient())
{
CClient * pClient = pChar->GetClient();
ASSERT( pClient );
if ( sound )
pClient->addSound(sound, pChar);
if ( fLightChange && ! pChar->IsStatFlag( STATF_DEAD | STATF_NIGHTSIGHT ))
pClient->addLight();
if ( fWeatherChange )
pClient->addWeather(GetWeather());
if ( iRegionPeriodic && pChar->m_pArea )
{
if ( ( iRegionPeriodic == 2 ) && IsTrigUsed(TRIGGER_REGPERIODIC))
{
pChar->m_pArea->OnRegionTrigger( pChar, RTRIG_REGPERIODIC );
--iRegionPeriodic;
}
if ( IsTrigUsed(TRIGGER_CLIPERIODIC) )
pChar->m_pArea->OnRegionTrigger( pChar, RTRIG_CLIPERIODIC );
}
}
EXC_CATCHSUB("Sector");
EXC_DEBUGSUB_START;
CPointMap pt = GetBasePoint();
g_Log.EventDebug("#0 char 0%x '%s'\n", (dword)(pChar->GetUID()), pChar->GetName());
g_Log.EventDebug("#0 sector #%d [%d,%d,%d,%d]\n", GetIndex(), pt.m_x, pt.m_y, pt.m_z, pt.m_map);
EXC_DEBUGSUB_END;
}
ProfileTask overheadTask(PROFILE_OVERHEAD);
EXC_SET_BLOCK("check map cache");
if (fCanSleep && m_iMapBlockCacheTime < iCurTime) // Only if the sector can sleep.
{
// delete the static CServerMapBlock items that have not been used recently.
m_iMapBlockCacheTime = CServerTime::GetCurrentTime().GetTimeRaw() + g_Cfg.m_iMapCacheTime ;
CheckMapBlockCache();
}
EXC_CATCH;
SetTimeoutS(30); // Sector is Awake, make it tick after 30 seconds.
EXC_DEBUG_START;
CPointMap pt = GetBasePoint();
g_Log.EventError("#4 sector #%d [%hd,%hd,%hhd,%hhu]\n", GetIndex(), pt.m_x, pt.m_y, pt.m_z, pt.m_map);
EXC_DEBUG_END;
return true;
}
示例6: Use_CarveCorpse
bool CChar::Use_CarveCorpse( CItemCorpse * pCorpse )
{
ADDTOCALLSTACK("CChar::Use_CarveCorpse");
CREID_TYPE CorpseID = pCorpse->m_itCorpse.m_BaseID;
CCharBase *pCorpseDef = CCharBase::FindCharBase(CorpseID);
if ( !pCorpseDef || pCorpse->m_itCorpse.m_carved )
{
SysMessageDefault(DEFMSG_CARVE_CORPSE_NOTHING);
return false;
}
CChar *pChar = pCorpse->m_uidLink.CharFind();
CPointMap pnt = pCorpse->GetTopLevelObj()->GetTopPoint();
UpdateAnimate(ANIM_BOW);
if ( pCorpse->m_TagDefs.GetKeyNum("BLOOD") )
{
CItem *pBlood = CItem::CreateBase(ITEMID_BLOOD4);
ASSERT(pBlood);
pBlood->SetHue(pCorpseDef->m_wBloodHue);
pBlood->MoveToDecay(pnt, 5 * TICK_PER_SEC);
}
size_t iItems = 0;
for ( size_t i = 0; i < pCorpseDef->m_BaseResources.GetCount(); i++ )
{
long long iQty = pCorpseDef->m_BaseResources[i].GetResQty();
RESOURCE_ID rid = pCorpseDef->m_BaseResources[i].GetResourceID();
if ( rid.GetResType() != RES_ITEMDEF )
continue;
ITEMID_TYPE id = static_cast<ITEMID_TYPE>(rid.GetResIndex());
if ( id == ITEMID_NOTHING )
break;
iItems++;
CItem *pPart = CItem::CreateTemplate(id, NULL, this);
ASSERT(pPart);
switch ( pPart->GetType() )
{
case IT_FOOD:
case IT_FOOD_RAW:
case IT_MEAT_RAW:
SysMessageDefault(DEFMSG_CARVE_CORPSE_MEAT);
//pPart->m_itFood.m_MeatType = CorpseID;
break;
case IT_HIDE:
SysMessageDefault(DEFMSG_CARVE_CORPSE_HIDES);
//pPart->m_itSkin.m_creid = CorpseID;
if ( (g_Cfg.m_iRacialFlags & RACIALF_HUMAN_WORKHORSE) && IsHuman() ) // humans always find 10% bonus when gathering hides, ores and logs (Workhorse racial trait)
iQty = iQty * 110 / 100;
break;
case IT_FEATHER:
SysMessageDefault(DEFMSG_CARVE_CORPSE_FEATHERS);
//pPart->m_itSkin.m_creid = CorpseID;
break;
case IT_WOOL:
SysMessageDefault(DEFMSG_CARVE_CORPSE_WOOL);
//pPart->m_itSkin.m_creid = CorpseID;
break;
/*case IT_DRAGON_SCALE: // TO-DO (typedef IT_DRAGON_SCALE doesn't exist yet)
SysMessageDefault(DEFMSG_CARVE_CORPSE_SCALES);
//pPart->m_itSkin.m_creid = CorpseID;
break;*/
default:
break;
}
if ( iQty > 1 )
pPart->SetAmount(static_cast<WORD>(iQty));
if ( pChar && pChar->m_pPlayer )
{
TCHAR *pszMsg = Str_GetTemp();
sprintf(pszMsg, g_Cfg.GetDefaultMsg(DEFMSG_CORPSE_NAME), pPart->GetName(), pChar->GetName());
pPart->SetName(pszMsg);
pPart->m_uidLink = pChar->GetUID();
pPart->MoveToDecay(pnt, pPart->GetDecayTime());
continue;
}
pCorpse->ContentAdd(pPart);
}
if ( iItems < 1 )
SysMessageDefault(DEFMSG_CARVE_CORPSE_NOTHING);
CheckCorpseCrime(pCorpse, false, false);
pCorpse->m_itCorpse.m_carved = 1; // mark as been carved
pCorpse->m_itCorpse.m_uidKiller = GetUID(); // by you
if ( pChar && pChar->m_pPlayer )
pCorpse->SetTimeout(0); // reset corpse timer to make it turn bones
return true;
}
示例7: NPC_OnHearPetCmdTarg
bool CChar::NPC_OnHearPetCmdTarg(int iCmd, CChar *pSrc, CObjBase *pObj, const CPointMap &pt, LPCTSTR pszArgs)
{
ADDTOCALLSTACK("CChar::NPC_OnHearPetCmdTarg");
// Pet commands that required a target.
if ( m_fIgnoreNextPetCmd )
{
m_fIgnoreNextPetCmd = false;
return false;
}
if ( !NPC_PetCheckAccess(iCmd, pSrc) )
return true;
bool bSuccess = false;
CItem *pItemTarg = dynamic_cast<CItem *>(pObj);
CChar *pCharTarg = dynamic_cast<CChar *>(pObj);
switch ( iCmd )
{
case PC_ATTACK:
case PC_KILL:
{
if ( !pCharTarg || (pCharTarg == this) || (pCharTarg == pSrc) )
break;
bSuccess = pCharTarg->OnAttackedBy(pSrc, true);
if ( bSuccess )
bSuccess = Fight_Attack(pCharTarg, true);
break;
}
case PC_FOLLOW:
if ( !pCharTarg || (pCharTarg == this) )
break;
m_Act_Targ = pCharTarg->GetUID();
bSuccess = Skill_Start(NPCACT_FOLLOW_TARG);
break;
case PC_FRIEND:
{
if ( !pCharTarg || !pCharTarg->m_pPlayer || (pCharTarg == pSrc) )
{
Speak(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_CONFUSED));
break;
}
CItemMemory *pMemory = Memory_FindObjTypes(pCharTarg, MEMORY_FRIEND);
if ( pMemory )
{
pSrc->SysMessage(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_FRIEND_ALREADY));
break;
}
pSrc->SysMessagef(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_FRIEND_SUCCESS1), GetName(), pCharTarg->GetName());
pCharTarg->SysMessagef(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_FRIEND_SUCCESS2), pSrc->GetName(), GetName());
Memory_AddObjTypes(pCharTarg, MEMORY_FRIEND);
m_Act_Targ = pCharTarg->GetUID();
bSuccess = Skill_Start(NPCACT_FOLLOW_TARG);
break;
}
case PC_UNFRIEND:
{
if ( !pCharTarg || !pCharTarg->m_pPlayer )
{
Speak(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_CONFUSED));
break;
}
CItemMemory *pMemory = Memory_FindObjTypes(pCharTarg, MEMORY_FRIEND);
if ( !pMemory )
{
pSrc->SysMessage(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_UNFRIEND_NOTFRIEND));
break;
}
pSrc->SysMessagef(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_UNFRIEND_SUCCESS1), GetName(), pCharTarg->GetName());
pCharTarg->SysMessagef(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_UNFRIEND_SUCCESS2), pSrc->GetName(), GetName());
pMemory->Delete();
m_Act_Targ = pSrc->GetUID();
bSuccess = Skill_Start(NPCACT_FOLLOW_TARG);
break;
}
case PC_GO:
if ( !pt.IsValidPoint() )
break;
m_Act_p = pt;
bSuccess = Skill_Start(NPCACT_GOTO);
break;
case PC_GUARD:
if ( !pCharTarg || (pCharTarg == this) )
break;
pCharTarg->SysMessagef(g_Cfg.GetDefaultMsg(DEFMSG_NPC_PET_TARG_GUARD_SUCCESS), GetName());
m_Act_Targ = pCharTarg->GetUID();
bSuccess = Skill_Start(NPCACT_GUARD_TARG);
break;
case PC_TRANSFER:
if ( !pCharTarg || !pCharTarg->m_pClient )
//.........这里部分代码省略.........
示例8: r_LoadVal
bool CItemStone::r_LoadVal( CScript & s ) // Load an item Script
{
ADDTOCALLSTACK("CItemStone::r_LoadVal");
EXC_TRY("LoadVal");
switch ( FindTableSorted( s.GetKey(), sm_szLoadKeys, COUNTOF( sm_szLoadKeys )-1 ))
{
case STC_ABBREV: // "ABBREV"
m_sAbbrev = s.GetArgStr();
return true;
case STC_ALIGN: // "ALIGN"
SetAlignType(static_cast<STONEALIGN_TYPE>(s.GetArgVal()));
return true;
case STC_MasterUid:
{
if ( s.HasArgs() )
{
CGrayUID pNewMasterUid = (DWORD) s.GetArgVal();
CChar * pChar = pNewMasterUid.CharFind();
if ( !pChar )
{
DEBUG_ERR(( "MASTERUID called on non char 0%lx uid.\n", (DWORD)pNewMasterUid ));
return( false );
}
CStoneMember * pNewMaster = GetMember( pChar );
if ( !pNewMaster )
{
DEBUG_ERR(( "MASTERUID called on char 0%lx (%s) that is not a valid member of stone with 0x%lx uid.\n", (DWORD)pNewMasterUid, pChar->GetName(), (DWORD)GetUID() ));
return( false );
}
CStoneMember * pMaster = GetMasterMember();
if ( pMaster )
{
if ( pMaster->GetLinkUID() == pNewMasterUid )
return( true );
pMaster->SetPriv(STONEPRIV_MEMBER);
//pMaster->SetLoyalTo(pChar);
}
//pNewMaster->SetLoyalTo(pChar);
pNewMaster->SetPriv(STONEPRIV_MASTER);
}
else
{
DEBUG_ERR(( "MASTERUID called without arguments.\n" ));
return( false );
}
}
return( true );
case STC_MEMBER: // "MEMBER"
{
TCHAR *Arg_ppCmd[8]; // Maximum parameters in one line
size_t Arg_Qty = Str_ParseCmds( s.GetArgStr(), Arg_ppCmd, COUNTOF( Arg_ppCmd ), "," );
if (Arg_Qty < 1) // must at least provide the member uid
return false;
new CStoneMember(
this,
ahextoi(Arg_ppCmd[0]), // Member's UID
Arg_Qty > 2 ? static_cast<STONEPRIV_TYPE>(ATOI(Arg_ppCmd[2])) : STONEPRIV_CANDIDATE, // Members priv level (use as a type)
Arg_Qty > 1 ? Arg_ppCmd[1] : "", // Title
ahextoi(Arg_ppCmd[3]), // Member is loyal to this
Arg_Qty > 4 ? (ATOI( Arg_ppCmd[4] ) != 0) : 0, // Paperdoll stone abbreviation (also if they declared war)
Arg_Qty > 5 ? (ATOI( Arg_ppCmd[5] ) != 0) : 0, // If we declared war
Arg_Qty > 6 ? ATOI( Arg_ppCmd[6] ) : 0); // AccountGold
}
return true;
case STC_WEBPAGE: // "WEBPAGE"
m_sWebPageURL = s.GetArgStr();
return true;
}
if ( s.IsKeyHead( sm_szLoadKeys[STC_CHARTER], 7 ))
{
unsigned int i = ATOI(s.GetKey() + 7);
if ( i >= COUNTOF(m_sCharter))
return( false );
m_sCharter[i] = s.GetArgStr();
return( true );
}
return CItem::r_LoadVal(s);
EXC_CATCH;
EXC_DEBUG_START;
EXC_ADD_SCRIPT;
EXC_DEBUG_END;
return false;
}
示例9: r_WriteVal
//.........这里部分代码省略.........
return true;
case STC_WEBPAGE: // "WEBPAGE"
sVal = GetWebPageURL();
return true;
case STC_AbbreviationToggle:
{
CStoneMember * pMember = GetMember(pCharSrc);
CVarDefCont * pResult = NULL;
if ( pMember == NULL )
{
pResult = g_Exp.m_VarDefs.GetKey("STONECONFIG_VARIOUSNAME_NONMEMBER");
}
else
{
pResult = pMember->IsAbbrevOn() ? g_Exp.m_VarDefs.GetKey("STONECONFIG_VARIOUSNAME_ABBREVON") :
g_Exp.m_VarDefs.GetKey("STONECONFIG_VARIOUSNAME_ABBREVOFF");
}
sVal = pResult ? pResult->GetValStr() : "";
}
return true;
case STC_AlignType:
sVal = GetAlignName();
return true;
case STC_LoyalTo:
{
CStoneMember * pMember = GetMember(pCharSrc);
CVarDefCont * pResult = NULL;
if ( pMember == NULL )
{
pResult = g_Exp.m_VarDefs.GetKey("STONECONFIG_VARIOUSNAME_NONMEMBER");
}
else
{
CChar * pLoyalTo = pMember->GetLoyalToUID().CharFind();
if ((pLoyalTo == NULL) || (pLoyalTo == pCharSrc ))
{
pResult = g_Exp.m_VarDefs.GetKey("STONECONFIG_VARIOUSNAME_YOURSELF");
}
else
{
sVal = pLoyalTo->GetName();
return true;
}
}
sVal = pResult ? pResult->GetValStr() : "";
}
return( true );
case STC_Master:
{
CChar * pMaster = GetMaster();
sVal = (pMaster) ? pMaster->GetName() : g_Exp.m_VarDefs.GetKeyStr("STONECONFIG_VARIOUSNAME_PENDVOTE");
}
return( true );
case STC_MasterGenderTitle:
{
CChar * pMaster = GetMaster();
if ( pMaster == NULL )
sVal = ""; // If no master (vote pending)
else if ( pMaster->Char_GetDef()->IsFemale())
sVal = g_Exp.m_VarDefs.GetKeyStr("STONECONFIG_VARIOUSNAME_MASTERGENDERFEMALE");
else
sVal = g_Exp.m_VarDefs.GetKeyStr("STONECONFIG_VARIOUSNAME_MASTERGENDERMALE");
}
return( true );
case STC_MasterTitle:
{
CStoneMember * pMember = GetMasterMember();
sVal = (pMember) ? pMember->GetTitle() : "";
}
return( true );
case STC_MasterUid:
{
CChar * pMaster = GetMaster();
if ( pMaster )
sVal.FormatHex( (DWORD) pMaster->GetUID() );
else
sVal.FormatHex( (DWORD) 0 );
}
return( true );
default:
return( CItem::r_WriteVal( pszKey, sVal, pSrc ));
}
EXC_CATCH;
EXC_DEBUG_START;
EXC_ADD_KEYRET(pSrc);
EXC_DEBUG_END;
return false;
}
示例10: Handle
//o---------------------------------------------------------------------------o
//| Function : void buyItem(CSocket *mSock)
//| Date : Unknown
//| Programmer : UOX3 DevTeam
//o---------------------------------------------------------------------------o
//| Purpose : Called when player buys an item from a vendor
//o---------------------------------------------------------------------------o
bool CPIBuyItem::Handle(void)
{
UI16 i;
UI32 playergoldtotal, goldtotal = 0;
bool soldout = false, clear = false;
CChar *mChar = tSock->CurrcharObj();
CItem *p = mChar->GetPackItem();
if (!ValidateObject(p))
return true;
ITEMLIST bitems;
std::vector<UI08> layer;
std::vector<UI16> amount;
// vector for storing all objects that actually end up in user backpack
std::vector< CItem * > boughtItems;
CChar *npc = calcCharObjFromSer(tSock->GetDWord(3));
UI16 itemtotal = static_cast<UI16>((tSock->GetWord(1) - 8) / 7);
if (itemtotal > 511)
return true;
boughtItems.reserve(itemtotal);
bitems.resize(itemtotal);
amount.resize(itemtotal);
layer.resize(itemtotal);
int baseOffset = 0;
for (i = 0; i < itemtotal; ++i)
{
baseOffset = 7 * i;
layer[i] = tSock->GetByte(8 + baseOffset);
bitems[i] = calcItemObjFromSer(tSock->GetDWord(9 + baseOffset));
amount[i] = tSock->GetWord(13 + baseOffset);
goldtotal += (amount[i] * (bitems[i]->GetBuyValue()));
}
bool useBank = (goldtotal >= static_cast<UI32>(cwmWorldState->ServerData()->BuyThreshold()));
if (useBank)
playergoldtotal = GetBankCount(mChar, 0x0EED);
else
playergoldtotal = GetItemAmount(mChar, 0x0EED);
if (playergoldtotal >= goldtotal || mChar->IsGM())
{
for (i = 0; i < itemtotal; ++i)
{
if (bitems[i]->GetAmount() < amount[i])
soldout = true;
// Check if onBuyFromVendor JS event is present for each item being purchased
// If true, and a return false has been returned from the script, halt the purchase
UI16 targTrig = bitems[i]->GetScriptTrigger();
cScript *toExecute = JSMapping->GetScript(targTrig);
if (toExecute != NULL)
if (toExecute->OnBuyFromVendor(tSock, npc, bitems[i]))
{
bitems.clear(); //needed???
return true;
}
}
if (soldout)
{
npc->TextMessage(tSock, 1336, TALK, false);
clear = true;
}
else
{
if (mChar->IsGM())
npc->TextMessage(NULL, 1337, TALK, false, mChar->GetName().c_str());
else
{
if (goldtotal == 1)
npc->TextMessage(NULL, 1338, TALK, false, mChar->GetName().c_str(), goldtotal);
else
npc->TextMessage(NULL, 1339, TALK, false, mChar->GetName().c_str(), goldtotal);
Effects->goldSound(tSock, goldtotal);
}
clear = true;
if (!mChar->IsGM())
if (useBank)
DeleteBankItem(mChar, goldtotal, 0x0EED);
else
DeleteItemAmount(mChar, goldtotal, 0x0EED);
CItem *biTemp;
CItem *iMade = NULL;
UI16 j;
for (i = 0; i < itemtotal; ++i)
{
//.........这里部分代码省略.........
示例11: NPC_GetHostilityLevelToward
int CChar::NPC_GetHostilityLevelToward(const CChar *pCharTarg) const
{
ADDTOCALLSTACK("CChar::NPC_GetHostilityLevelToward");
// What is my general hostility level toward this type of creature ?
//
// based on:
// npc vs player (evil npc's don't like players)
// creature body type (allie groups)
//
// RETURN:
// 100 = extreme hatred.
// 0 = neutral.
// -100 = love them
if ( !m_pNPC || !pCharTarg )
return 0;
// If it's a pet, inherit hostility from it's master
CChar *pCharOwn = pCharTarg->NPC_PetGetOwner();
if ( pCharOwn && (pCharOwn != this) )
{
static int sm_iReentrant = 0;
if ( sm_iReentrant > 32 )
{
DEBUG_ERR(("Too many owners (circular ownership?) to continue acquiring hostility level towards %s uid=0%lx\n", pCharOwn->GetName(), pCharOwn->GetUID().GetPrivateUID()));
return 0;
}
++sm_iReentrant;
int iHostility = NPC_GetHostilityLevelToward(pCharOwn);
--sm_iReentrant;
return iHostility;
}
if ( m_pNPC->m_Brain == NPCBRAIN_BERSERK ) // Beserks always hate everyone
return 100;
if ( pCharTarg->m_pPlayer )
return 100;
if ( pCharTarg->m_pNPC )
{
if ( !g_Cfg.m_fMonsterFight ) // Monsters are not supposed to fight other monsters!
return 0;
if ( GetDispID() == pCharTarg->GetDispID() ) // I will never attack those of my own kind
return -100;
else if ( NPC_GetAllyGroupType(GetDispID()) == NPC_GetAllyGroupType(pCharTarg->GetDispID()) )
return -50;
else if ( m_pNPC->m_Brain == pCharTarg->m_pNPC->m_Brain )
return -30;
return 100;
}
return 0;
}
示例12: OnTick
//.........这里部分代码省略.........
}
}
// regen all creatures and do AI
ProfileTask charactersTask(PROFILE_CHARS);
CChar * pCharNext = NULL;
CChar * pChar = static_cast<CChar *>(m_Chars_Active.GetHead());
for ( ; pChar != NULL; pChar = pCharNext )
{
EXC_TRYSUB("TickChar");
pCharNext = pChar->GetNext();
if ( fEnvironChange && IsTrigUsed(TRIGGER_ENVIRONCHANGE) )
pChar->OnTrigger(CTRIG_EnvironChange, pChar);
if ( pChar->m_pClient )
{
if ( sound )
pChar->m_pClient->addSound(sound, pChar);
if ( fLightChange && !pChar->IsStatFlag(STATF_DEAD|STATF_NightSight) )
pChar->m_pClient->addLight();
if ( fWeatherChange )
pChar->m_pClient->addWeather(GetWeather());
if ( iRegionPeriodic && pChar->m_pArea )
{
if ( (iRegionPeriodic == 2) && IsTrigUsed(TRIGGER_REGPERIODIC) )
{
pChar->m_pArea->OnRegionTrigger(pChar, RTRIG_REGPERIODIC);
iRegionPeriodic--;
}
if ( IsTrigUsed(TRIGGER_CLIPERIODIC) )
pChar->m_pArea->OnRegionTrigger(pChar, RTRIG_CLIPERIODIC);
}
}
// Can only die on your own tick.
if ( !pChar->OnTick() )
pChar->Delete();
EXC_CATCHSUB("Sector");
EXC_DEBUGSUB_START;
CPointMap pt = GetBasePoint();
g_Log.EventDebug("char 0%lx '%s'\n", static_cast<DWORD>(pChar->GetUID()), pChar->GetName());
g_Log.EventDebug("sector #%d [%d,%d,%d,%d]\n", GetIndex(), pt.m_x, pt.m_y, pt.m_z, pt.m_map);
EXC_DEBUGSUB_END;
}
// decay items on ground = time out spells / gates etc.. etc..
// No need to check these so often !
ProfileTask itemsTask(PROFILE_ITEMS);
CItem * pItemNext = NULL;
CItem * pItem = dynamic_cast <CItem*>( m_Items_Timer.GetHead());
for ( ; pItem != NULL; pItem = pItemNext )
{
EXC_TRYSUB("TickItem");
pItemNext = pItem->GetNext();
EXC_SETSUB("TimerExpired");
if ( pItem->IsTimerExpired() )
{
EXC_SETSUB("ItemTick");
if ( !pItem->OnTick() )
{
EXC_SETSUB("ItemDelete");
pItem->Delete();
}
else
{
EXC_SETSUB("TimerExpired2");
if ( pItem->IsTimerExpired() ) // forgot to clear the timer.? strange.
{
EXC_SETSUB("SetTimeout");
pItem->SetTimeout(-1);
}
}
}
EXC_SETSUB("UpdateFlags");
pItem->OnTickStatusUpdate();
#ifdef _WIN32
EXC_CATCHSUB("Sector");
EXC_DEBUGSUB_START;
CPointMap pt = GetBasePoint();
g_Log.EventError("item 0%lx '%s' [timer=%lld, type=%lld]\n", static_cast<DWORD>(pItem->GetUID()), pItem->GetName(), pItem->GetTimerAdjusted(), static_cast<int>(pItem->GetType()));
g_Log.EventError("sector #%d [%d,%d,%d,%d]\n", GetIndex(), pt.m_x, pt.m_y, pt.m_z, pt.m_map);
EXC_DEBUGSUB_END;
#else
}
#ifndef _DEBUG
catch ( const CGrayError& e )
示例13: Process
//.........这里部分代码省略.........
case 'P':
{
UI32 networkTimeCount = cwmWorldState->ServerProfile()->NetworkTimeCount();
UI32 timerTimeCount = cwmWorldState->ServerProfile()->TimerTimeCount();
UI32 autoTimeCount = cwmWorldState->ServerProfile()->AutoTimeCount();
UI32 loopTimeCount = cwmWorldState->ServerProfile()->LoopTimeCount();
// 1/13/2003 - Dreoth - Log Performance Information enhancements
LogEcho( true );
Log( "--- Starting Performance Dump ---", "performance.log");
Log( "\tPerformace Dump:", "performance.log");
Log( "\tNetwork code: %.2fmsec [%i samples]", "performance.log", (R32)((R32)cwmWorldState->ServerProfile()->NetworkTime()/(R32)networkTimeCount), networkTimeCount);
Log( "\tTimer code: %.2fmsec [%i samples]", "performance.log", (R32)((R32)cwmWorldState->ServerProfile()->TimerTime()/(R32)timerTimeCount), timerTimeCount);
Log( "\tAuto code: %.2fmsec [%i samples]", "performance.log", (R32)((R32)cwmWorldState->ServerProfile()->AutoTime()/(R32)autoTimeCount), autoTimeCount);
Log( "\tLoop Time: %.2fmsec [%i samples]", "performance.log", (R32)((R32)cwmWorldState->ServerProfile()->LoopTime()/(R32)loopTimeCount), loopTimeCount);
ObjectFactory *ourFac = ObjectFactory::getSingletonPtr();
Log( "\tCharacters: %i/%i - Items: %i/%i (Dynamic)", "performance.log", ourFac->CountOfObjects( OT_CHAR ), ourFac->SizeOfObjects( OT_CHAR ), ourFac->CountOfObjects( OT_ITEM ), ourFac->SizeOfObjects( OT_ITEM ) );
Log( "\tSimulation Cycles: %f per sec", "performance.log", (1000.0*(1.0/(R32)((R32)cwmWorldState->ServerProfile()->LoopTime()/(R32)loopTimeCount))));
Log( "\tBytes sent: %i", "performance.log", cwmWorldState->ServerProfile()->GlobalSent());
Log( "\tBytes Received: %i", "performance.log", cwmWorldState->ServerProfile()->GlobalReceived());
Log( "--- Performance Dump Complete ---", "performance.log");
LogEcho( false );
break;
}
case 'W':
// Display logged in chars
messageLoop << "CMD: Current Users in the World:";
j = 0;
CSocket *iSock;
Network->PushConn();
for( iSock = Network->FirstSocket(); !Network->FinishedSockets(); iSock = Network->NextSocket() )
{
++j;
CChar *mChar = iSock->CurrcharObj();
sprintf( temp, " %i) %s [%x %x %x %x]", j - 1, mChar->GetName().c_str(), mChar->GetSerial( 1 ), mChar->GetSerial( 2 ), mChar->GetSerial( 3 ), mChar->GetSerial( 4 ) );
messageLoop << temp;
}
Network->PopConn();
sprintf( temp, " Total users online: %i", j );
messageLoop << temp;
break;
case 'M':
size_t tmp, total;
total = 0;
tmp = 0;
messageLoop << "CMD: UOX Memory Information:";
messageLoop << " Cache:";
sprintf( temp, " Tiles: %u bytes", Map->GetTileMem() );
messageLoop << temp;
sprintf( temp, " Multis: %u bytes", Map->GetMultisMem() );
messageLoop << temp;
size_t m, n;
m = ObjectFactory::getSingleton().SizeOfObjects( OT_CHAR );
total += tmp = m + m*sizeof( CTEffect ) + m*sizeof(char) + m*sizeof(int)*5;
sprintf( temp, " Characters: %u bytes [%u chars ( %u allocated )]", tmp, ObjectFactory::getSingleton().CountOfObjects( OT_CHAR ), m );
messageLoop << temp;
n = ObjectFactory::getSingleton().SizeOfObjects( OT_ITEM );
total += tmp = n + n * sizeof( int ) * 4;
sprintf( temp, " Items: %u bytes [%u items ( %u allocated )]", tmp, ObjectFactory::getSingleton().CountOfObjects( OT_ITEM ), n );
messageLoop << temp;
sprintf( temp, " You save I: %i & C: %i bytes!", m * sizeof(CItem) - ObjectFactory::getSingleton().CountOfObjects( OT_ITEM ), m * sizeof( CChar ) - ObjectFactory::getSingleton().CountOfObjects( OT_CHAR ) );
total += tmp = 69 * sizeof( SpellInfo );
sprintf( temp, " Spells: %i bytes", tmp );
messageLoop << " Sizes:";
sprintf( temp, " CItem : %i bytes", sizeof( CItem ) );
messageLoop << temp;
sprintf( temp, " CChar : %i bytes", sizeof( CChar ) );