示例#1
0
bool CBattleEntity::Rest(float rate)
{
    if (health.hp != health.maxhp || health.mp != health.maxmp) {
        // recover 20% HP
        uint32 recoverHP = (float)health.maxhp*rate;
        uint32 recoverMP = (float)health.maxmp*rate;
        addHP(recoverHP);
        addMP(recoverMP);

        // lower TP
        addTP(rate*-500);
        return true;
    }

    return false;
}
示例#2
0
文件: CPlayer.cpp 项目: hjqqq/Forever
void CPlayer::useItem(int itemID)
{
   std::string machineName = this->getMachineName();
   size_t idx = machineName.find("Server");
   if(idx != std::string::npos) {
      // Server端處理

      CItemInfo* pItemInfo = CItem::getInfo(itemID);
      if(pItemInfo == NULL)
         return;

      if(pItemInfo->getClassType() == WEAPON) {
		   CWeaponInfo *pWp = (CWeaponInfo*) pItemInfo;
         if(this->getLevel() >= pWp->getLevel()) {
            if(ONE_HAND == pWp->getWield())
			      wearToEquipSlot(MAIN_HAND, itemID);
            else if(TWO_HAND == pWp->getWield())
			      wearToEquipSlot(OFF_HAND, itemID);
         }
	   }
      else if(pItemInfo->getClassType() == ARMOR) {
		   CArmorInfo *pAm = (CArmorInfo*) pItemInfo;
         if(this->getLevel() >= pAm->getLevel()) {
		      if(CLOTHES == pAm->getWear())
			      wearToEquipSlot(CHEST, itemID);
		      else if(BELTS == pAm->getWear())
			      wearToEquipSlot(BELT, itemID);
		      else if(PANTS == pAm->getWear())
			      wearToEquipSlot(LEGS, itemID);
		      else if(PAULDRONS == pAm->getWear())
			      wearToEquipSlot(SHOULDER, itemID);
		      else if(GLOVES == pAm->getWear())
			      wearToEquipSlot(GLOVE, itemID);
		      else if(BOOTS == pAm->getWear())
			      wearToEquipSlot(BOOT, itemID);
         }
	   }
      else if(pItemInfo->getClassType() == CONSUMABLE) {
         CConsumableInfo *pConsumableInfo = (CConsumableInfo *)pItemInfo;
         if(this->getLevel() >= pConsumableInfo->getLevel()) {
            if(pConsumableInfo->getEffect() == EDIBLE_SKILL)
               addSkill(pConsumableInfo->getMuch());  // 學習某項技能   
            else if(pConsumableInfo->getEffect() == EDIBLE_HP) {
               if(getHPMax() == getHP())
                    return;

               addHP(pConsumableInfo->getMuch());     // 補血
               // Todo: 藥水是否有CD時間
            }
            else if(pConsumableInfo->getEffect() == EDIBLE_MP) {
               if(getMP() == getMPMax())
                  return;

               addMP(pConsumableInfo->getMuch());     // 補魔
               // Todo: 藥水是否有CD時間
            }
            else
               return;

            // 背包物品減一
            m_pBackpack->removeItem(itemID);
         }
      }
   }
   else {
      // Client端處理
   }
}