void CRandomItems::AddItems (SItemAddCtx &Ctx) // AddItems // // Add items { int i, j; int iRoll = mathRandom(1, 1000); bool bAllAtOnce = (m_iDamaged == 0 && m_Enhanced.GetChance() == 0); for (i = 0; i < m_iCount; i++) { iRoll -= m_Table[i].iProbability; if (iRoll <= 0) { CItemType *pType = m_Table[i].pType; int iCount = pType->GetNumberAppearing().Roll(); // If we don't have a chance of enhancement or damage, just optimize the // result by adding a group of items. if (bAllAtOnce) Ctx.ItemList.AddItem(CItem(m_Table[i].pType, iCount)); // If this is armor, then treat them as a block else if (pType->GetCategory() == itemcatArmor) { CItem Item(m_Table[i].pType, iCount); if (mathRandom(1, 100) <= m_iDamaged) Item.SetDamaged(); else m_Enhanced.EnhanceItem(Item); Ctx.ItemList.AddItem(Item); } // Otherwise, enhance/damage each item individually else { for (j = 0; j < iCount; j++) { CItem Item(m_Table[i].pType, 1); if (mathRandom(1, 100) <= m_iDamaged) Item.SetDamaged(); else m_Enhanced.EnhanceItem(Item); Ctx.ItemList.AddItem(Item); } } break; } } }
void CDanceGroupFairlyLandProcessor::SendAllStorageBoxReward() { SharedPtr<std::list<FairlyLandReward> > shareLstReward(new std::list<FairlyLandReward>); for (GroupPersonalMapIt GPit = m_mapGroupIndexPcInfo.begin(); GPit != m_mapGroupIndexPcInfo.end(); ++GPit) { for (PersonalInfoMapIt Pit = GPit->second.begin(); Pit != GPit->second.end(); ++Pit) { FairlyLandReward reward; reward.nRoleID = Pit->first; //发奖励 std::list<RewardItem> listReward; Pit->second.GetStorageBoxItems(listReward); for (std::list<RewardItem>::iterator RIt = listReward.begin(); RIt != listReward.end(); ++RIt) { reward.bonus.m_listItems.push_back(CItem(RIt->m_nItemId, RIt->m_nCount, RIt->m_nDuration, false)); } if (!reward.bonus.m_listItems.empty()) { shareLstReward->push_back(reward); } //清除数据 Pit->second.ClearStorageBoxItems(); } } g_pQueryMgr->AddQuery(QUERY_DanceGroupFairlyLandClearAllStorageBoxReward, shareLstReward); }
CItem GetItemFromArg (CCodeChain &CC, ICCItem *pArg) // GetItemFromArg // // Arg can be an UNID or an item { if (pArg->IsList()) return CreateItemFromList(CC, pArg); else if (pArg->IsInteger()) { CItemType *pType = g_pUniverse->FindItemType(pArg->GetIntegerValue()); if (pType == NULL) return CItem(); return CItem(pType, 1); } else return CItem(); }
void CDanceGroupFairlyLandProcessor::SendAllPassedReward() { // 清理内存,并且把数据打包出去 std::list<FairlyLandReward> *lstRewards = new std::list<FairlyLandReward>; for (GroupPersonalMapIt GPit = m_mapGroupIndexPcInfo.begin(); GPit != m_mapGroupIndexPcInfo.end(); ++GPit) { GroupInfoMapIt Git = m_mapGroupInfo.find(GPit->first); if (m_mapGroupInfo.end() == Git) continue; // 下一个舞团 for (PersonalInfoMapIt Pit = GPit->second.begin(); Pit != GPit->second.end(); ++Pit) { FairlyLandReward reward; reward.nRoleID = Pit->first; FairlyLandChapterReward passReward; for (std::set<int>::iterator iter = Pit->second.m_setPassRewardFalg.begin(); iter != Pit->second.m_setPassRewardFalg.end(); ++iter) { if (*iter >= Git->second.GetCurChapterLvl()) // 当前关卡,还没有通 continue; FairlyLandChapterReward tempReward; GetChapterPassReward(tempReward, *iter, Pit->second.m_nSex); passReward += tempReward; } //发奖励 for (std::list<RewardItem>::iterator RIt = passReward.m_listItems.begin(); RIt != passReward.m_listItems.end(); ++RIt) { reward.bonus.m_listItems.push_back(CItem(RIt->m_nItemId, (unsigned short)RIt->m_nCount, RIt->m_nDuration, false)); } reward.bonus.m_nMoney = passReward.m_nMoney; reward.bonus.m_nBindMCoin = passReward.m_nBindMB; //清除标志位 Pit->second.m_setPassRewardFalg.clear(); Pit->second.m_setJoinRewardFalg.clear(); // Pit->second.ClearPassedChapterReward(); // 清除掉这些数据 if (!reward.bonus.m_listItems.empty() || reward.bonus.m_nMoney != 0 || reward.bonus.m_nBindMCoin != 0) { lstRewards->push_back(reward); } } } SharedPtr<std::list<FairlyLandReward> > sharedLstReward(lstRewards); g_pQueryMgr->AddQuery(QUERY_DanceGroupFairlyLandClearAllPassedReward, sharedLstReward); }
void CUIHelper::CreateClassInfoArmor (CShipClass *pClass, int x, int y, int cxWidth, DWORD dwOptions, int *retcyHeight, IAnimatron **retpInfo) const // CreateClassInfoArmor // // Creates info about the ship class' armor { // Edge condition if (pClass->GetHullSectionCount() == 0) { if (retcyHeight) *retcyHeight = 0; CAniSequencer::Create(CVector(x, y), (CAniSequencer **)retpInfo); return; } // Get the armor used CArmorClass *pArmor = pClass->GetHullSection(0)->pArmor; // Compute the max armor limit CString sMaxArmor; if ((pClass->GetMaxArmorMass() % 1000) == 0) sMaxArmor = strPatternSubst(CONSTLIT("%d"), pClass->GetMaxArmorMass() / 1000); else sMaxArmor = strPatternSubst(CONSTLIT("%d.%d"), pClass->GetMaxArmorMass() / 1000, ((pClass->GetMaxArmorMass() % 1000) + 50) / 100); // Info CreateClassInfoItem(CItem(pArmor->GetItemType(), 1), x, y, cxWidth, dwOptions, strPatternSubst(CONSTLIT("\noptional upgrade up to %s ton segments"), sMaxArmor), retcyHeight, retpInfo); }
int CArmorClass::CalcBalance (void) // CalcBalance // // Determines whether the given item is balanced for its level. Negative numbers // mean the item is underpowered. Positive numbers mean the item is overpowered. { int i; int iBalance = 0; int iLevel = m_pItemType->GetLevel(); // Regeneration if (!m_Regen.IsEmpty()) { if (m_fPhotoRepair) iBalance += m_Regen.GetHPPerEra(); else iBalance += 5 * m_Regen.GetHPPerEra(); } // Stealth if (m_iStealth >= 12) iBalance += 4; else if (m_iStealth >= 10) iBalance += 3; else if (m_iStealth >= 8) iBalance += 2; else if (m_iStealth >= 6) iBalance += 1; // Immunities if (m_fDisintegrationImmune) { if (iLevel <= 10) iBalance += 3; } if (m_iBlindingDamageAdj <= 20 && iLevel < BLIND_IMMUNE_LEVEL) iBalance += 1; else if (m_iBlindingDamageAdj > 0 && iLevel >= BLIND_IMMUNE_LEVEL) iBalance -= 1; if (m_fRadiationImmune && iLevel < RADIATION_IMMUNE_LEVEL) iBalance += 2; else if (!m_fRadiationImmune && iLevel >= RADIATION_IMMUNE_LEVEL) iBalance -= 2; if (m_iEMPDamageAdj <= 20 && iLevel < EMP_IMMUNE_LEVEL) iBalance += 2; else if (m_iEMPDamageAdj > 0 && iLevel >= EMP_IMMUNE_LEVEL) iBalance -= 2; if (m_iDeviceDamageAdj <= 20 && iLevel < DEVICE_DAMAGE_IMMUNE_LEVEL) iBalance += 2; else if (m_iDeviceDamageAdj > 0 && iLevel >= DEVICE_DAMAGE_IMMUNE_LEVEL) iBalance -= 2; if (m_iBlindingDamageAdj > 20 || m_iEMPDamageAdj > 20 || m_iDeviceDamageAdj > 20) { if (m_iBlindingDamageAdj <= 33 || m_iEMPDamageAdj <= 33 || m_iDeviceDamageAdj <= 33) iBalance += 2; else if (m_iBlindingDamageAdj <= 50 || m_iEMPDamageAdj <= 50 || m_iDeviceDamageAdj <= 50) iBalance += 1; } if (m_fPhotoRecharge) iBalance += 2; // Matched sets if (m_iArmorCompleteBonus) { int iPercent = m_iArmorCompleteBonus * 100 / m_iHitPoints; iBalance += (iPercent + 5) / 10; } // Damage Adjustment int iBalanceAdj = 0; for (i = 0; i < damageCount; i++) { int iStdAdj; int iDamageAdj; m_DamageAdj.GetAdjAndDefault((DamageTypes)i, &iDamageAdj, &iStdAdj); if (iStdAdj != iDamageAdj) { if (iDamageAdj > 0) { int iBonus = (int)((100.0 * (iStdAdj - iDamageAdj) / iDamageAdj) + 0.5); if (iBonus > 0) iBalanceAdj += iBonus / 4; else iBalanceAdj -= ((int)((100.0 * iDamageAdj / iStdAdj) + 0.5) - 100) / 4; } else if (iStdAdj > 0) { iBalanceAdj += iStdAdj; } } } iBalance += (Max(Min(iBalanceAdj, 100), -100)) / 5; // Reflection for (i = 0; i < damageCount; i++) { if (m_Reflective.InSet((DamageTypes)i)) iBalance += 8; } // Hit Points if (m_iHitPoints > 0) { int iDiff = (m_iHitPoints - STD_STATS[iLevel - 1].iHP); if (iDiff > 0) iBalance += iDiff * 20 / STD_STATS[iLevel - 1].iHP; else if (m_iHitPoints > 0) iBalance -= (STD_STATS[iLevel - 1].iHP * 20 / m_iHitPoints) - 20; else iBalance -= 40; } // Mass int iMass = CItem(m_pItemType, 1).GetMassKg(); if (iMass > 0) { int iDiff = (iMass - STD_STATS[iLevel - 1].iMass); // Armor twice as massive can have double the hit points if (iDiff > 0) iBalance -= iDiff * 20 / STD_STATS[iLevel - 1].iMass; // Armor half as massive can have 3/4 hit points else if (iMass > 0) iBalance += (STD_STATS[iLevel - 1].iMass * 10 / iMass) - 10; else iBalance += 100; } // Repair tech int iRepair = iLevel - m_iRepairTech; if (iRepair < 0) iBalance += 2 * iRepair; else if (iRepair > 0) iBalance += iRepair; // Repair cost int iStdRepairCost = STD_STATS[m_iRepairTech - 1].iRepairCost; int iDiff = iStdRepairCost - m_iRepairCost; if (iDiff < 0) iBalance += Max(-8, 2 * iDiff / iStdRepairCost); else if (iDiff > 0) iBalance += 5 * iDiff / iStdRepairCost; // Power consumption if (m_iPowerUse) { int iPercent = m_iPowerUse * 100 / CShieldClass::GetStdPower(iLevel); iBalance -= iPercent; } // Meteorsteel if (m_fShieldInterference) iBalance -= 12; // Decay if (!m_Decay.IsEmpty()) { iBalance -= 4 * m_Decay.GetHPPerEra(); } return 5 * iBalance; }
void CSingleDevice::AddDevices (SDeviceGenerateCtx &Ctx) // AddDevices // // Add devices to list { int i; if (m_pItemType == NULL) return; int iCount = m_Count.Roll(); for (i = 0; i < iCount; i++) { // Initialize the desc SDeviceDesc Desc; Desc.Item = CItem(m_pItemType, 1); if (mathRandom(1, 100) <= m_iDamaged) Desc.Item.SetDamaged(); else m_Enhanced.EnhanceItem(Desc.Item); // Find the default settings for the device slot for this device SDeviceDesc SlotDesc; bool bUseSlotDesc = (Ctx.pRoot ? Ctx.pRoot->FindDefaultDesc(Desc.Item, &SlotDesc) : false); // Set the device position appropriately, either from the <Device> element, // from the slot descriptor at the root, or from defaults. if (!m_bDefaultPos) { Desc.iPosAngle = m_iPosAngle; Desc.iPosRadius = m_iPosRadius; Desc.iPosZ = m_iPosZ; Desc.b3DPosition = m_b3DPosition; } else if (bUseSlotDesc) { Desc.iPosAngle = SlotDesc.iPosAngle; Desc.iPosRadius = SlotDesc.iPosRadius; Desc.iPosZ = SlotDesc.iPosZ; Desc.b3DPosition = SlotDesc.b3DPosition; } // Set the device fire arc appropriately. if (!m_bDefaultFireArc) { Desc.bOmnidirectional = m_bOmnidirectional; Desc.iMinFireArc = m_iMinFireArc; Desc.iMaxFireArc = m_iMaxFireArc; } else if (bUseSlotDesc) { Desc.bOmnidirectional = SlotDesc.bOmnidirectional; Desc.iMinFireArc = SlotDesc.iMinFireArc; Desc.iMaxFireArc = SlotDesc.iMaxFireArc; } // Set linked fire if (!m_bDefaultLinkedFire) Desc.dwLinkedFireOptions = m_dwLinkedFireOptions; else if (bUseSlotDesc) Desc.dwLinkedFireOptions = SlotDesc.dwLinkedFireOptions; else Desc.dwLinkedFireOptions = 0; Desc.bSecondary = m_bSecondary; // Slot bonus if (!m_bDefaultSlotBonus) Desc.iSlotBonus = m_iSlotBonus; else if (bUseSlotDesc) Desc.iSlotBonus = SlotDesc.iSlotBonus; else Desc.iSlotBonus = 0; // Add extra items if (m_pExtraItems) { CItemListManipulator ItemList(Desc.ExtraItems); SItemAddCtx ItemCtx(ItemList); ItemCtx.iLevel = Ctx.iLevel; m_pExtraItems->AddItems(ItemCtx); } // Done Ctx.pResult->AddDeviceDesc(Desc); } }
void CNewGameSession::SetShipClass (CShipClass *pClass, int x, int y, int cxWidth) // SetShipClass // // Sets the ship class { int i; const CPlayerSettings *pPlayerSettings = pClass->GetPlayerSettings(); const CVisualPalette &VI = m_HI.GetVisuals(); const CG16bitFont &MediumBoldFont = VI.GetFont(fontMediumBold); const CG16bitFont &SubTitleFont = VI.GetFont(fontSubTitle); // Ship class name SetShipClassName(pClass->GetName(), x, y, cxWidth); SetShipClassDesc(pPlayerSettings->GetDesc(), x, y, cxWidth); // Offset int yOffset = SMALL_BUTTON_HEIGHT + SMALL_SPACING_VERT + MediumBoldFont.GetHeight() + 2 * SubTitleFont.GetHeight(); // Ship class image SetShipClassImage(pClass, x, y + yOffset, cxWidth); // Delete previous info DeleteElement(ID_SHIP_CLASS_INFO); // Create a sequencer for all class info components CAniSequencer *pClassInfo; CAniSequencer::Create(CVector(x, y + yOffset + SubTitleFont.GetHeight()), &pClassInfo); pClassInfo->SetID(ID_SHIP_CLASS_INFO); // Generate default devices for the ship class CDeviceDescList Devices; pClass->GenerateDevices(1, Devices); // Generate list of all weapons, sorted by level and name TSortMap<CString, CItem> RightSide; for (i = 0; i < Devices.GetCount(); i++) { CDeviceClass *pDevice = Devices.GetDeviceClass(i); if (pDevice->GetCategory() == itemcatWeapon || pDevice->GetCategory() == itemcatLauncher) RightSide.Insert(strPatternSubst(CONSTLIT("%02d_%02d_%s"), 1, pDevice->GetLevel(), pDevice->GetName()), CItem(pDevice->GetItemType(), 1)); } // Add shields TSortMap<CString, CItem> LeftSide; CDeviceClass *pShields = Devices.GetNamedDevice(devShields); if (pShields) RightSide.Insert(strPatternSubst(CONSTLIT("%02d_%02d_%s"), 2, pShields->GetLevel(), pShields->GetName()), CItem(pShields->GetItemType(), 1)); // Add armor RightSide.Insert(CONSTLIT("03"), CItem(g_pUniverse->GetItemType(0), SPECIAL_ARMOR)); // Add reactor LeftSide.Insert(CONSTLIT("01"), CItem(g_pUniverse->GetItemType(0), SPECIAL_REACTOR)); // Add engines LeftSide.Insert(CONSTLIT("02"), CItem(g_pUniverse->GetItemType(0), SPECIAL_DRIVE)); // Add cargo LeftSide.Insert(CONSTLIT("03"), CItem(g_pUniverse->GetItemType(0), SPECIAL_CARGO)); // Add misc devices for (i = 0; i < Devices.GetCount(); i++) { CDeviceClass *pDevice = Devices.GetDeviceClass(i); if (pDevice->GetCategory() == itemcatMiscDevice) LeftSide.Insert(strPatternSubst(CONSTLIT("%02d_%02d_%s"), 4, pDevice->GetLevel(), pDevice->GetName()), CItem(pDevice->GetItemType(), 1)); } // Add device slots LeftSide.Insert(CONSTLIT("05"), CItem(g_pUniverse->GetItemType(0), SPECIAL_DEVICE_SLOTS)); // Set the ship class info. All weapons go to the right of the ship image int xPos = (cxWidth / 2) + (SHIP_IMAGE_RECT_WIDTH / 2); int yPos = 0; int cxInfo = (cxWidth - xPos); for (i = 0; i < RightSide.GetCount(); i++) { int cyInfo; IAnimatron *pInfo; AddClassInfo(pClass, Devices, RightSide[i], xPos, yPos, cxInfo, 0, &cyInfo, &pInfo); pClassInfo->AddTrack(pInfo, 0); yPos += cyInfo + ITEM_INFO_PADDING_VERT; } // Misc devices go on the left xPos = (cxWidth / 2) - (SHIP_IMAGE_RECT_WIDTH / 2); yPos = 0; cxInfo = xPos; for (i = 0; i < LeftSide.GetCount(); i++) { int cyInfo; IAnimatron *pInfo; AddClassInfo(pClass, Devices, LeftSide[i], xPos, yPos, cxInfo, CUIHelper::OPTION_ITEM_RIGHT_ALIGN, &cyInfo, &pInfo); pClassInfo->AddTrack(pInfo, 0); yPos += cyInfo + ITEM_INFO_PADDING_VERT; } m_pRoot->AddLine(pClassInfo); }