Пример #1
0
void CPlayer::updateEquipAttr()
{
   std::string machineName = this->getMachineName();
   size_t idx = machineName.find("Server");
   if(idx != std::string::npos) {
      // Server端處理

	   std::map<EquipSlot , int>::iterator pi = m_mEquip.begin();
	   AdvancedAttribute advAttr;
	   AttributeSet(advAttr);
	   ObscureAttribute obsAttr;
	   AttributeClear(obsAttr);
	   BasicAttributeSet(getLevel(), getBasAttr(), advAttr, obsAttr);		//取得角色初始素質
	   while (m_mEquip.end() != pi)
	   {
		   CWeaponInfo* wp = (CWeaponInfo*) CItem::getInfo(pi->second);
		   if(NULL == wp)
		   {
			   break;
		   }
		   AttributeAdd (advAttr, wp->getBaseAttr());
		   AttributeAdd (advAttr, wp->getExtendAttr());
   		
		   pi++;
	   }
	   advAttr.iHP = getHP();
	   advAttr.iMP = getMP();
	   setAdvAttr(advAttr);
	   updateSkillAvailable();
   }
   else {
      // Client端處理

      updateSkillAvailable();
   }
}
Пример #2
0
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端處理
   }
}
Пример #3
0
void Character::varMP(const int val){
    setMP(getMP() + val);
    return;
}
Пример #4
0
void Player::save(){
	char sql[10000];
	sprintf_s(sql, 10000, "update keymap set ");
	for(int i=0; i<90; i++){
		char temp[100];
		if(i!=89)
			sprintf_s(temp, 100, "pos%d=%d, ", i, keys[i]);
		else
			sprintf_s(temp, 100, "pos%d=%d where charid=%d; ", i, keys[i], getPlayerid());
		strcat_s(sql, 10000, temp);
	}
	MySQL::insert(sql);
	sprintf_s(sql, 10000, "update characters set level=%d, job=%d, str=%d, dex=%d, intt=%d, luk=%d, chp=%d, mhp=%d, cmp=%d, mmp=%d, ap=%d, sp=%d, exp=%d, fame=%d, map=%d, gender=%d, skin=%d, eyes=%d, hair=%d, mesos=%d where id=%d", getLevel(), getJob(), getStr(), getDex(), getInt(), getLuk(), getHP(), getRMHP(), getMP(), getRMMP(), getAp(), getSp(), getExp(), getFame(), getMap(), getGender(), getSkin(), getEyes(), getHair(), inv->getMesos() ,getPlayerid());
	MySQL::insert(sql);
	char temp[1000];
	sprintf_s(sql, 10000, "delete from equip where charid=%d;", getPlayerid());
	MySQL::insert(sql);
	bool firstrun = true;
	for(int i=0; i<inv->getEquipNum(); i++){
		if(firstrun == true){
			sprintf_s(sql, 10000, "INSERT INTO equip VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", inv->getEquip(i)->id, Drops::equips[inv->getEquip(i)->id].type ,getPlayerid(), inv->getEquipPos(i), inv->getEquip(i)->slots, inv->getEquip(i)->scrolls,
				inv->getEquip(i)->istr, inv->getEquip(i)->idex, inv->getEquip(i)->iint, inv->getEquip(i)->iluk, inv->getEquip(i)->ihp, inv->getEquip(i)->imp, inv->getEquip(i)->iwatk, inv->getEquip(i)->imatk, inv->getEquip(i)->iwdef, 
				inv->getEquip(i)->imdef, inv->getEquip(i)->iacc, inv->getEquip(i)->iavo, inv->getEquip(i)->ihand, inv->getEquip(i)->ijump, inv->getEquip(i)->ispeed);
			firstrun = false;
		}
		else{
			sprintf_s(temp, 1000, ",(%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", inv->getEquip(i)->id, Drops::equips[inv->getEquip(i)->id].type ,getPlayerid(), inv->getEquipPos(i), inv->getEquip(i)->slots, inv->getEquip(i)->scrolls,
				inv->getEquip(i)->istr, inv->getEquip(i)->idex, inv->getEquip(i)->iint, inv->getEquip(i)->iluk, inv->getEquip(i)->ihp, inv->getEquip(i)->imp, inv->getEquip(i)->iwatk, inv->getEquip(i)->imatk, inv->getEquip(i)->iwdef, 
				inv->getEquip(i)->imdef, inv->getEquip(i)->iacc, inv->getEquip(i)->iavo, inv->getEquip(i)->ihand, inv->getEquip(i)->ijump, inv->getEquip(i)->ispeed);
			strcat_s(sql, 10000, temp);
		}
	}
	MySQL::insert(sql);
	sprintf_s(sql, 10000, "delete from skills where charid=%d;", getPlayerid());
	MySQL::insert(sql);
	firstrun = true;
	for(int i=0; i<skills->getSkillsNum(); i++){
		if(firstrun == true){
			sprintf_s(sql, 10000, "INSERT INTO skills VALUES (%d, %d, %d)", getPlayerid(), skills->getSkillID(i), skills->getSkillLevel(skills->getSkillID(i)));
			firstrun = false;
		}
		else{
			sprintf_s(temp, 1000, ",(%d, %d, %d)", getPlayerid(), skills->getSkillID(i), skills->getSkillLevel(skills->getSkillID(i)));
			strcat_s(sql, 10000, temp);
		}
	}
	MySQL::insert(sql);
	sprintf_s(sql, 10000, "DELETE FROM items WHERE charid=%d;", getPlayerid());
	MySQL::insert(sql);
	firstrun = true;
	for(int i=0; i<inv->getItemNum(); i++){
		if(firstrun == true){
			sprintf_s(sql, 10000, "INSERT INTO items VALUES (%d, %d, %d, %d, %d)", inv->getItem(i)->id, getPlayerid() ,inv->getItem(i)->inv, inv->getItem(i)->pos, inv->getItem(i)->amount);
			firstrun = false;
		}
		else{
			sprintf_s(temp, 1000, ",(%d, %d, %d, %d, %d)", inv->getItem(i)->id, getPlayerid() ,inv->getItem(i)->inv, inv->getItem(i)->pos, inv->getItem(i)->amount);
			strcat_s(sql, 10000, temp);
		}
	}
	MySQL::insert(sql);
}
void Character::adjustMP( int delta )
{
	setMP(getMP() + delta);
}