本文整理汇总了C++中CChar::GetUID方法的典型用法代码示例。如果您正苦于以下问题:C++ CChar::GetUID方法的具体用法?C++ CChar::GetUID怎么用?C++ CChar::GetUID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CChar
的用法示例。
在下文中一共展示了CChar::GetUID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenerateChar
void CItemSpawn::GenerateChar(CResourceDef *pDef)
{
ADDTOCALLSTACK("CitemSpawn:GenerateChar");
RESOURCE_ID_BASE rid = pDef->GetResourceID();
if ( rid.GetResType() == RES_SPAWN )
{
const CRandGroupDef *pSpawnGroup = static_cast<const CRandGroupDef *>(pDef);
ASSERT(pSpawnGroup);
size_t i = pSpawnGroup->GetRandMemberIndex();
if ( i != pSpawnGroup->BadMemberIndex() )
rid = pSpawnGroup->GetMemberID(i);
}
if ( (rid.GetResType() != RES_CHARDEF) && (rid.GetResType() != RES_UNKNOWN) )
return;
CPointMap pt = GetTopPoint();
CRegionBase *pRegion = pt.GetRegion(REGION_TYPE_AREA);
if ( !pRegion )
return;
CChar *pChar = CChar::CreateBasic(static_cast<CREID_TYPE>(rid.GetResIndex()));
if ( !pChar )
return;
pChar->NPC_LoadScript(true);
pChar->StatFlag_Set(STATF_Spawned);
// Try placing the char near the spawn
if ( !pChar->MoveNearObj(this, m_itSpawnChar.m_DistMax) || !pChar->CanSeeLOS(pt) )
{
// If this fails, try placing the char over the spawn
if ( !pChar->MoveTo(pt) )
{
DEBUG_ERR(("Spawn UID:0%lx is unable to place a character inside the world.\n", static_cast<DWORD>(GetUID())));
pChar->Delete();
return;
}
}
AddObj(pChar->GetUID());
pChar->NPC_CreateTrigger(); // removed from NPC_LoadScript() and triggered after char placement and attachment to the spawnitem
pChar->Update();
size_t iCount = GetTopSector()->GetCharComplexity();
if ( iCount > g_Cfg.m_iMaxCharComplexity )
g_Log.Event(LOGL_WARN, "%" FMTSIZE_T " chars at %s. Sector too complex!\n", iCount, GetTopSector()->GetBasePoint().WriteUsed());
}
示例2: GenerateChar
void CItemSpawn::GenerateChar(CResourceDef *pDef)
{
ADDTOCALLSTACK("CitemSpawn:GenerateChar");
if ( !IsTopLevel() )
return;
RESOURCE_ID_BASE rid = pDef->GetResourceID();
if ( rid.GetResType() == RES_SPAWN )
{
const CRandGroupDef *pSpawnGroup = static_cast<const CRandGroupDef *>(pDef);
ASSERT(pSpawnGroup);
size_t i = pSpawnGroup->GetRandMemberIndex();
if ( i != pSpawnGroup->BadMemberIndex() )
rid = pSpawnGroup->GetMemberID(i);
}
if ( (rid.GetResType() != RES_CHARDEF) && (rid.GetResType() != RES_UNKNOWN) )
return;
CChar *pChar = CChar::CreateBasic(static_cast<CREID_TYPE>(rid.GetResIndex()));
if ( !pChar )
return;
CPointMap pt = GetTopPoint();
pChar->NPC_LoadScript(true);
pChar->StatFlag_Set(STATF_Spawned);
pChar->MoveTo(pt);
// Check if the NPC can spawn in this region
CRegionBase *pRegion = GetTopPoint().GetRegion(REGION_TYPE_AREA);
if ( !pRegion || (pRegion->IsGuarded() && pChar->Noto_IsEvil()) )
{
pChar->Delete();
return;
}
AddObj(pChar->GetUID());
pChar->NPC_CreateTrigger(); // removed from NPC_LoadScript() and triggered after char placement and attachment to the spawnitem
pChar->Update();
size_t iCount = GetTopSector()->GetCharComplexity();
if ( iCount > g_Cfg.m_iMaxCharComplexity )
g_Log.Event(LOGL_WARN, "%d chars at %s. Sector too complex!\n", iCount, GetTopSector()->GetBasePoint().WriteUsed());
}
示例3: r_Write
void CItemSpawn::r_Write(CScript & s)
{
ADDTOCALLSTACK("CitemSpawn:r_Write");
EXC_TRY("Write");
CItem::r_Write(s);
WORD iTotal = GetCount();
if (iTotal <= 0)
return;
for (WORD i = 0; i < iTotal; i++)
{
if (!m_obj[i].IsValidUID())
continue;
CChar * pObj = m_obj[i].CharFind();
if (pObj)
s.WriteKeyHex("ADDOBJ",pObj->GetUID());
}
EXC_CATCH;
}
示例4: Cmd_Skill_Tracking
//.........这里部分代码省略.........
static const NPCBRAIN_TYPE sm_Track_Brain[] =
{
NPCBRAIN_QTY, // not used here
NPCBRAIN_ANIMAL,
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 )
break;
if ( pChar == m_pChar )
continue;
if ( pChar->GetNPCBrain() != track_type )
continue;
if ( pChar->IsStatFlag(STATF_DEAD) ) // can't track ghosts
continue;
if ( pChar->m_pPlayer )
{
// Prevent track hidden GMs
if ( pChar->IsStatFlag(STATF_Insubstantial) && (pChar->GetPrivLevel() > GetPrivLevel()) )
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_iRacialFlags & RACIALF_ELF_DIFFTRACK) && 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;
}
CCharBase *pCharDef = pChar->Char_GetDef();
if ( !pCharDef )
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
{
// Tracking failed or cancelled
m_pChar->Skill_UseQuick(SKILL_TRACKING, 10 + Calc_GetRandLLVal(30));
static LPCTSTR const sm_Track_FailMsg[] =
{
g_Cfg.GetDefaultMsg(DEFMSG_TRACKING_FAIL_ANIMAL),
g_Cfg.GetDefaultMsg(DEFMSG_TRACKING_FAIL_MONSTER),
g_Cfg.GetDefaultMsg(DEFMSG_TRACKING_FAIL_PEOPLE),
g_Cfg.GetDefaultMsg(DEFMSG_TRACKING_FAIL_PEOPLE)
};
if ( sm_Track_FailMsg[track_sel - 1] )
SysMessage(sm_Track_FailMsg[track_sel - 1]);
}
}
return false;
}
示例5: OnTick
//.........这里部分代码省略.........
// regen all creatures and do AI
ProfileTask charactersTask(PROFILE_CHARS);
//pChar = STATIC_CAST <CChar*>( m_Chars_Active.GetHead());
CChar * pCharNext = NULL;
CChar * pChar = dynamic_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->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 );
}
}
// 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 )
示例6: GenerateChar
void CItemSpawn::GenerateChar(CResourceDef * pDef)
{
ADDTOCALLSTACK("CitemSpawn:GenerateChar");
if ( !IsTopLevel() || ( m_itSpawnChar.m_current >= GetAmount() ) || ( GetTopSector()->GetCharComplexity() > g_Cfg.m_iMaxCharComplexity ))
return;
int iDistMax = m_itSpawnChar.m_DistMax;
RESOURCE_ID_BASE rid = pDef->GetResourceID();
if ( rid.GetResType() == RES_SPAWN )
{
const CRandGroupDef * pSpawnGroup = STATIC_CAST <const CRandGroupDef *>(pDef);
ASSERT(pSpawnGroup);
size_t i = pSpawnGroup->GetRandMemberIndex();
if ( i != pSpawnGroup->BadMemberIndex() )
{
rid = pSpawnGroup->GetMemberID(i);
}
}
if (( rid.GetResType() != RES_CHARDEF ) && ( rid.GetResType() != RES_UNKNOWN ))
return;
CREID_TYPE id = static_cast<CREID_TYPE>(rid.GetResIndex());
bool isBadPlaceToSpawn = false;
CChar * pChar = CChar::CreateBasic(id);
if( pChar == NULL )
{
return;
}
pChar->NPC_LoadScript(true);
AddObj(pChar->GetUID());
pChar->m_uidSpawnItem = GetUID(); // SpawnItem for this char
pChar->StatFlag_Set( STATF_Spawned );
pChar->MoveTo(GetTopPoint());
pChar->NPC_CreateTrigger(); //Removed from NPC_LoadScript() and triggered after char placement
if( pChar->GetRegion() == NULL )
{
isBadPlaceToSpawn = true;
}
else if( pChar->GetRegion()->IsGuarded() && pChar->Noto_IsEvil() )
{
isBadPlaceToSpawn = true;
}
// Deny definitely known a bad place to spawn (like red NPCs in guarded areas)
// Usually caused by wide range near the edge of the towns
if( isBadPlaceToSpawn )
{
pChar->Delete();
//m_itSpawnChar.m_current--;
return;
}
ASSERT(pChar->m_pNPC);
if ( iDistMax )
{
pChar->m_ptHome = GetTopPoint();
pChar->m_pNPC->m_Home_Dist_Wander = static_cast<WORD>(iDistMax);
}
pChar->Update();
}
示例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;
}
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();
//.........这里部分代码省略.........
示例8: Use_CarveCorpse
void 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;
}
CChar *pChar = pCorpse->m_uidLink.CharFind();
CPointMap pnt = pCorpse->GetTopLevelObj()->GetTopPoint();
UpdateAnimate(ANIM_BOW);
if ( pCorpse->m_TagDefs.GetKeyNum("BLOOD", true) )
{
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<unsigned int>(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
}
示例9: 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 )
//.........这里部分代码省略.........
示例10: 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;
}
示例11: 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 )
//.........这里部分代码省略.........
示例12: 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 ( iCmd == PC_FOLLOW || iCmd == PC_STAY || iCmd == PC_STOP )
{
// Pet friends can use only these commands
if ( ! NPC_IsOwnedBy( pSrc ) && Memory_FindObjTypes( pSrc, MEMORY_FRIEND ) == NULL )
return false;
}
else
{
// All others commands are avaible only to pet owner
if ( ! NPC_IsOwnedBy( pSrc, true ) )
return false;
}
if ( m_fIgnoreNextPetCmd == true )
{
m_fIgnoreNextPetCmd = false;
return(false);
}
bool fSuccess = false; // No they won't do it.
// Could be NULL
CItem * pItemTarg = dynamic_cast<CItem*>(pObj);
CChar * pCharTarg = dynamic_cast<CChar*>(pObj);
switch ( iCmd )
{
case PC_GO:
// Go to the location x,y
if ( ! pt.IsValidPoint())
break;
m_Act_p = pt;
fSuccess = Skill_Start( NPCACT_GOTO );
break;
case PC_GUARD:
if ( pObj == NULL )
break;
m_Act_Targ = pObj->GetUID();
fSuccess = Skill_Start( NPCACT_GUARD_TARG );
break;
case PC_TRANSFER:
// transfer ownership via the transfer command.
if ( pCharTarg == NULL )
break;
if ( pCharTarg->IsClient() )
{
if ( IsSetOF(OF_PetSlots) )
{
if ( !pCharTarg->FollowersUpdate(this, static_cast<short>(maximum(1, GetDefNum("FOLLOWERSLOTS", true, true))), true) )
{
pSrc->SysMessageDefault( DEFMSG_PETSLOTS_TRY_TRANSFER );
break;
}
}
fSuccess = NPC_PetSetOwner( pCharTarg );
}
break;
case PC_KILL:
case PC_ATTACK:
// Attack the target.
if ( pCharTarg == NULL )
break;
// refuse to attack friends.
if ( NPC_IsOwnedBy( pCharTarg, true ))
{
fSuccess = false; // take no commands
break;
}
fSuccess = pCharTarg->OnAttackedBy( pSrc, 1, true ); // we know who told them to do this.
if ( fSuccess )
{
fSuccess = Fight_Attack( pCharTarg, true );
}
break;
case PC_FOLLOW:
if ( pCharTarg == NULL )
break;
m_Act_Targ = pCharTarg->GetUID();
fSuccess = Skill_Start( NPCACT_FOLLOW_TARG );
break;
case PC_FRIEND:
// Not the same as owner,
if ( pCharTarg == NULL )
break;
Memory_AddObjTypes( pCharTarg, MEMORY_FRIEND );
break;
case PC_PRICE: // "PRICE" the vendor item.
if ( pItemTarg == NULL )
break;
if ( ! NPC_IsVendor())
//.........这里部分代码省略.........
示例13: 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;
}
示例14: 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;
}
示例15: Export
bool CWorld::Export( LPCTSTR pszFilename, const CChar * pSrc, WORD wModeFlags, int iDist, int dx, int dy )
{
ADDTOCALLSTACK("CWorld::Export");
// wModeFlags = IMPFLAGS_TYPE
// Just get the items in the local area to export.
// dx = change in x from world to file.
// dy = change in y
if ( pSrc == NULL )
return( false );
size_t iLen = strlen( pszFilename );
if ( iLen <= 4 )
return( false );
CScript s;
if ( ! s.Open( pszFilename, OF_WRITE|OF_TEXT|OF_DEFAULTMODE ))
return( false );
if ( wModeFlags & IMPFLAGS_RELATIVE )
{
dx -= pSrc->GetTopPoint().m_x;
dy -= pSrc->GetTopPoint().m_y;
}
if ( ! strcmpi( pszFilename + (iLen - 4), ".WSC" ))
{
// Export as UOX format. for world forge stuff.
int index = 0;
CWorldSearch AreaItems( pSrc->GetTopPoint(), iDist );
AreaItems.SetSearchSquare(true);
for (;;)
{
CItem * pItem = AreaItems.GetItem();
if ( pItem == NULL )
break;
pItem->WriteUOX( s, index++ );
}
return( true );
}
// (???NPC) Chars and the stuff they are carrying.
if ( wModeFlags & IMPFLAGS_CHARS )
{
CWorldSearch AreaChars( pSrc->GetTopPoint(), iDist );
AreaChars.SetSearchSquare(true);
AreaChars.SetAllShow( pSrc->IsPriv( PRIV_ALLSHOW )); // show logged out chars?
for (;;)
{
CChar * pChar = AreaChars.GetChar();
if ( pChar == NULL )
break;
if ( !(wModeFlags & IMPFLAGS_SELF) )
{
if ( pChar->GetUID() == pSrc->GetUID() )
{
continue;
}
}
pChar->r_WriteSafe( s );
}
}
if ( wModeFlags & IMPFLAGS_ITEMS )
{
// Items on the ground.
CWorldSearch AreaItems( pSrc->GetTopPoint(), iDist );
AreaItems.SetSearchSquare(true);
AreaItems.SetAllShow( pSrc->IsPriv( PRIV_ALLSHOW )); // show logged out chars?
for (;;)
{
CItem * pItem = AreaItems.GetItem();
if ( pItem == NULL )
break;
pItem->r_WriteSafe( s );
}
}
return( true );
}