本文整理汇总了C++中CCodeChainCtx::SaveAndDefineItemVar方法的典型用法代码示例。如果您正苦于以下问题:C++ CCodeChainCtx::SaveAndDefineItemVar方法的具体用法?C++ CCodeChainCtx::SaveAndDefineItemVar怎么用?C++ CCodeChainCtx::SaveAndDefineItemVar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCodeChainCtx
的用法示例。
在下文中一共展示了CCodeChainCtx::SaveAndDefineItemVar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FireGetMaxHP
int CArmorClass::FireGetMaxHP (CItemCtx &ItemCtx, int iMaxHP) const
// FireGetMaxHP
//
// Fire GetMaxHP event
{
SEventHandlerDesc Event;
if (FindEventHandlerArmorClass(evtGetMaxHP, &Event))
{
// Setup arguments
CCodeChainCtx Ctx;
Ctx.SaveAndDefineSourceVar(ItemCtx.GetSource());
Ctx.SaveAndDefineItemVar(ItemCtx);
Ctx.DefineInteger(CONSTLIT("aMaxHP"), iMaxHP);
ICCItem *pResult = Ctx.Run(Event);
if (pResult->IsError())
ItemCtx.GetSource()->ReportEventError(GET_MAX_HP_EVENT, pResult);
else if (!pResult->IsNil())
iMaxHP = Max(0, pResult->GetIntegerValue());
Ctx.Discard(pResult);
}
return iMaxHP;
}
示例2: if
COverlayType *CDeviceClass::FireGetOverlayType (CItemCtx &ItemCtx) const
// FireGetOverlayType
//
// Fire GetOverlayType event
{
SEventHandlerDesc Event;
if (FindEventHandlerDeviceClass(evtGetOverlayType, &Event))
{
// Setup arguments
CCodeChainCtx Ctx;
Ctx.SaveAndDefineSourceVar(ItemCtx.GetSource());
Ctx.SaveAndDefineItemVar(ItemCtx);
ICCItem *pResult = Ctx.Run(Event);
DWORD dwUNID = 0;
if (pResult->IsError())
ItemCtx.GetSource()->ReportEventError(GET_OVERLAY_TYPE_EVENT, pResult);
else if (!pResult->IsNil())
dwUNID = pResult->GetIntegerValue();
Ctx.Discard(pResult);
// Done
return COverlayType::AsType(g_pUniverse->FindDesignType(dwUNID));
}
else
return GetOverlayType();
}
示例3: FireOnArmorDamage
void CArmorClass::FireOnArmorDamage (CItemCtx &ItemCtx, SDamageCtx &Ctx)
// FireOnArmorDamage
//
// Fires OnArmorDamage event
{
SEventHandlerDesc Event;
if (FindEventHandlerArmorClass(evtOnArmorDamage, &Event))
{
// Setup arguments
CCodeChainCtx CCCtx;
CCCtx.SaveAndDefineSourceVar(ItemCtx.GetSource());
CCCtx.SaveAndDefineItemVar(ItemCtx);
CCCtx.DefineInteger(CONSTLIT("aArmorHP"), Ctx.iHPLeft);
CCCtx.DefineInteger(CONSTLIT("aArmorSeg"), Ctx.iSectHit);
CCCtx.DefineSpaceObject(CONSTLIT("aAttacker"), Ctx.Attacker.GetObj());
CCCtx.DefineSpaceObject(CONSTLIT("aCause"), Ctx.pCause);
CCCtx.DefineDamageEffects(CONSTLIT("aDamageEffects"), Ctx);
CCCtx.DefineInteger(CONSTLIT("aDamageHP"), Ctx.iDamage);
CCCtx.DefineString(CONSTLIT("aDamageType"), GetDamageShortName(Ctx.Damage.GetDamageType()));
CCCtx.DefineInteger(CONSTLIT("aHitDir"), Ctx.iDirection);
CCCtx.DefineVector(CONSTLIT("aHitPos"), Ctx.vHitPos);
CCCtx.DefineSpaceObject(CONSTLIT("aOrderGiver"), (Ctx.Attacker.GetObj() ? Ctx.Attacker.GetObj()->GetOrderGiver(Ctx.Attacker.GetCause()) : NULL));
CCCtx.DefineItemType(CONSTLIT("aWeaponType"), Ctx.pDesc->GetWeaponType());
ICCItem *pResult = CCCtx.Run(Event);
// If we return Nil, then nothing
if (pResult->IsNil())
NULL;
// If we return an integer, then this is the damage that armor should take
else if (pResult->IsInteger())
Ctx.iDamage = pResult->GetIntegerValue();
// If we return a list, then we it to be a DamageEffects list (modifications to
// aDamageEffects)
else if (pResult->IsList())
LoadDamageEffectsFromItem(pResult, Ctx);
CCCtx.Discard(pResult);
}
}
示例4: EnhanceItem
void CRandomEnhancementGenerator::EnhanceItem (CItem &Item)
// EnhanceItem
//
// Enhances the given item
{
// See if this item is enhanced
if (mathRandom(1, 100) > m_iChance)
return;
// If we have code, execute the code to figure out the mod
if (m_pCode)
{
CCodeChainCtx Ctx;
// Save the previous value of gItem
Ctx.SaveAndDefineItemVar(Item);
// Execute the code
ICCItem *pResult = Ctx.Run(m_pCode); // LATER:Event
// If we have an error, report it
DWORD dwMods;
if (pResult->IsError())
{
CString sError = strPatternSubst(CONSTLIT("Generate Enhancement: %s"), pResult->GetStringValue());
kernelDebugLogMessage(sError);
dwMods = 0;
}
// Otherwise, the result code is the mods
else
dwMods = (DWORD)pResult->GetIntegerValue();
// Done with code
Ctx.Discard(pResult);
// Enhance the item
Item.AddEnhancement(dwMods);
}
// Otherwise, if we have a constant mod, apply that
else if (m_dwMods)
{
Item.AddEnhancement(m_dwMods);
}
// Otherwise, we need to generate a random mod appropriate to the
// particular item
else
{
DWORD dwMods;
CItemType *pType = Item.GetType();
int iRoll = mathRandom(1, 100);
switch (pType->GetCategory())
{
case itemcatArmor:
case itemcatShields:
if (iRoll < 40)
// HP + 10%
dwMods = 0x0101;
else if (iRoll < 65)
// HP + 20%
dwMods = 0x0102;
else if (iRoll < 80)
// HP + 30%
dwMods = 0x0103;
else if (iRoll < 90)
// Damage Adj at 50% (and 75%)
dwMods = 0x0A05 + (mathRandom(0, 3) << 4);
else if (iRoll < 95)
// Immunity to special ion attacks
dwMods = 0x0C00;
else
// Regeneration
dwMods = 0x0200;
break;
case itemcatWeapon:
if (iRoll < 50)
// Damage + 10%
dwMods = 0x0101;
else if (iRoll < 80)
// Damage + 20%
dwMods = 0x0102;
else if (iRoll < 95)
// Damage + 30%
dwMods = 0x0103;
//.........这里部分代码省略.........