bool CRecastContainer::HasRecast(RECASTTYPE type, uint16 id) { RecastList_t* PRecastList = GetRecastList(type); for (uint16 i = 0; i < PRecastList->size(); ++i) { if (PRecastList->at(i)->ID == id && PRecastList->at(i)->RecastTime > 0) { if (PRecastList->at(i)->chargeTime == 0) { return true; } else { int charges = PRecastList->at(i)->maxCharges - ((PRecastList->at(i)->RecastTime - (gettick() - PRecastList->at(i)->TimeStamp)) / (PRecastList->at(i)->chargeTime * 1000)) - 1; //TODO: multiple charges (BST Ready) if (charges < 1) { return true; } } } } return false; }
void CRecastContainer::Check(uint32 tick) { DSP_DEBUG_BREAK_IF(tick == 0); for (uint8 type = 0; type < MAX_RECASTTPE_SIZE; ++type) { RecastList_t* PRecastList = GetRecastList((RECASTTYPE)type); for (uint16 i = 0; i < PRecastList->size(); ++i) { Recast_t* recast = PRecastList->at(i); if (tick >= (recast->TimeStamp + recast->RecastTime)) { if (type == RECAST_ITEM) { CItem* PItem = m_PChar->getStorage(LOC_INVENTORY)->GetItem(recast->ID); m_PChar->pushPacket(new CInventoryItemPacket(PItem, LOC_INVENTORY, recast->ID)); m_PChar->pushPacket(new CInventoryFinishPacket()); } if (type == RECAST_ITEM || type == RECAST_MAGIC || type == RECAST_LOOT) { PRecastList->erase(PRecastList->begin() + i--); delete recast; } else { recast->RecastTime = 0; } } } } }
bool CRecastContainer::HasRecast(RECASTTYPE type, uint16 id, uint32 recast) { RecastList_t* PRecastList = GetRecastList(type); for (uint16 i = 0; i < PRecastList->size(); ++i) { if (PRecastList->at(i).ID == id && PRecastList->at(i).RecastTime > 0) { if (PRecastList->at(i).chargeTime == 0) { return true; } else { //a request to use more charges than the maximum only applies to abilities who share normal recasts with charges (ie. sic) if ( recast > PRecastList->at(i).maxCharges ) { return true; } auto charges = PRecastList->at(i).maxCharges - ((PRecastList->at(i).RecastTime - (uint32)(time(nullptr) - PRecastList->at(i).TimeStamp)) / (PRecastList->at(i).chargeTime)) - 1; if (charges < recast) { return true; } } } } return false; }
void CRecastContainer::Add(RECASTTYPE type, uint16 id, uint32 duration, uint32 chargeTime, uint8 maxCharges) { Recast_t* recast = GetRecast(type, id); if( recast == NULL) { Recast_t* newRecast = new Recast_t; newRecast->ID = id; newRecast->TimeStamp = gettick(); newRecast->RecastTime = duration; newRecast->chargeTime = chargeTime; newRecast->maxCharges = maxCharges; GetRecastList(type)->push_back(newRecast); } else { if (chargeTime == 0) { recast->TimeStamp = gettick(); recast->RecastTime = duration; } else { if (recast->RecastTime == 0) { recast->TimeStamp = gettick(); } recast->RecastTime += chargeTime * 1000; recast->chargeTime = chargeTime; recast->maxCharges = maxCharges; } } }
void CRecastContainer::DeleteByIndex(RECASTTYPE type, uint8 index) { RecastList_t* PRecastList = GetRecastList(type); if (type == RECAST_ABILITY) Sql_Query(SqlHandle, "DELETE FROM char_recast WHERE charid = %u AND id = %u;", m_PChar->id, PRecastList->at(index)->ID); delete PRecastList->at(index); PRecastList->erase(PRecastList->begin() + index); }
bool CRecastContainer::Has(RECASTTYPE type, uint16 id) { RecastList_t* PRecastList = GetRecastList(type); return std::find_if(PRecastList->begin(), PRecastList->end(), [&id](auto& recast) { return recast.ID == id; }) != PRecastList->end(); }
void CRecastContainer::Del(RECASTTYPE type) { RecastList_t* PRecastList = GetRecastList(type); for (uint16 i = 0; i < PRecastList->size(); ++i) { delete PRecastList->at(i); } PRecastList->clear(); }
Recast_t* CRecastContainer::Load(RECASTTYPE type, uint16 id, uint32 duration, uint32 chargeTime, uint8 maxCharges) { Recast_t* recast = GetRecast(type, id); if (recast == nullptr) { GetRecastList(type)->push_back({id, time(nullptr), duration, chargeTime, maxCharges}); return &GetRecastList(type)->back(); } else { if (chargeTime) { recast->chargeTime = chargeTime; } if (maxCharges) { recast->maxCharges = maxCharges; } if (recast->chargeTime == 0) { recast->TimeStamp = time(nullptr); recast->RecastTime = duration; } else { if (recast->RecastTime == 0) { recast->TimeStamp = time(nullptr); } else if (recast->RecastTime + duration > recast->chargeTime * recast->maxCharges) { auto diff = (recast->RecastTime + duration) - (recast->chargeTime * recast->maxCharges); recast->TimeStamp += diff; duration -= diff; } recast->RecastTime += duration; } return recast; } }
void CRecastContainer::Del(RECASTTYPE type) { RecastList_t* PRecastList = GetRecastList(type); for (uint16 i = 0; i < PRecastList->size(); ++i) { delete PRecastList->at(i); } PRecastList->clear(); if (type == RECAST_ABILITY) Sql_Query(SqlHandle, "DELETE FROM char_recast WHERE charid = %u;", m_PChar->id); }
Recast_t* CRecastContainer::GetRecast(RECASTTYPE type, uint16 id) { RecastList_t* list = GetRecastList(type); for (auto&& recast : *list) { if (recast.ID == id) { return &recast; } } return nullptr; }
void CRecastContainer::ResetAbilities() { RecastList_t* PRecastList = GetRecastList(RECAST_ABILITY); for (auto&& recast : *PRecastList) { if (recast.ID != 0) { Load(RECAST_ABILITY, recast.ID, 0); } } }
CRecastContainer::~CRecastContainer() { for (uint8 type = 0; type < MAX_RECASTTPE_SIZE; ++type) { RecastList_t* PRecastList = GetRecastList((RECASTTYPE)type); for (uint16 i = 0; i < PRecastList->size(); ++i) { delete PRecastList->at(i); } } }
void CRecastContainer::DeleteByIndex(RECASTTYPE type, uint8 index) { RecastList_t* PRecastList = GetRecastList(type); if (type == RECAST_ABILITY) { PRecastList->at(index).RecastTime = 0; } else { PRecastList->erase(PRecastList->begin() + index); } }
Recast_t* CRecastContainer::GetRecast(RECASTTYPE type, uint16 id) { RecastList_t* list = GetRecastList(type); for (std::vector<Recast_t*>::iterator it = list->begin() ; it != list->end(); ++it) { Recast_t* recast = *it; if( recast->ID == id) { return recast; } } return NULL; }
bool CRecastContainer::Has(RECASTTYPE type, uint16 id) { RecastList_t* PRecastList = GetRecastList(type); for (uint16 i = 0; i < PRecastList->size(); ++i) { if (PRecastList->at(i)->ID == id) { return true; } } return false; }
void CRecastContainer::Del(RECASTTYPE type, uint16 id) { RecastList_t* PRecastList = GetRecastList(type); for (uint16 i = 0; i < PRecastList->size(); ++i) { if (PRecastList->at(i)->ID == id) { delete PRecastList->at(i); PRecastList->erase(PRecastList->begin() + i); return; } } }
void CRecastContainer::Del(RECASTTYPE type) { RecastList_t* PRecastList = GetRecastList(type); if (type == RECAST_ABILITY) { for (auto&& recast : *PRecastList) { recast.RecastTime = 0; } } else { PRecastList->clear(); } }
void CRecastContainer::Del(RECASTTYPE type, uint16 id) { RecastList_t* PRecastList = GetRecastList(type); for (uint16 i = 0; i < PRecastList->size(); ++i) { if (PRecastList->at(i)->ID == id) { if (type == RECAST_ABILITY) Sql_Query(SqlHandle, "DELETE FROM char_recast WHERE charid = %u AND id = %u;", m_PChar->id, PRecastList->at(i)->ID); delete PRecastList->at(i); PRecastList->erase(PRecastList->begin() + i); return; } } }
void CRecastContainer::Del(RECASTTYPE type, uint16 id) { RecastList_t* PRecastList = GetRecastList(type); if (type == RECAST_ABILITY) { if (auto recast = GetRecast(RECAST_ABILITY, id)) { recast->RecastTime = 0; } } else { PRecastList->erase(std::remove_if(PRecastList->begin(), PRecastList->end(), [&id](auto& recast) { return recast.ID == id; }), PRecastList->end()); } }
void CRecastContainer::ResetAbilities() { RecastList_t* PRecastList = GetRecastList(RECAST_ABILITY); uint32 timestamp = 0; uint32 recastTime = 0; Recast_t* twoHour = GetRecast(RECAST_ABILITY, 0); if (twoHour != NULL) { timestamp = twoHour->TimeStamp; recastTime = twoHour->RecastTime; } PRecastList->clear(); if (twoHour != NULL) { Recast_t* newTwoHour = new Recast_t; newTwoHour->ID = 0; newTwoHour->TimeStamp = timestamp; newTwoHour->RecastTime = recastTime; PRecastList->push_back(newTwoHour); } }
void CRecastContainer::Check() { for (auto type : {RECAST_MAGIC, RECAST_ABILITY}) { RecastList_t* PRecastList = GetRecastList(type); for (uint16 i = 0; i < PRecastList->size(); ++i) { Recast_t* recast = &PRecastList->at(i); if (time(nullptr) >= (recast->TimeStamp + recast->RecastTime)) { if (type == RECAST_MAGIC) { PRecastList->erase(PRecastList->begin() + i--); } else { recast->RecastTime = 0; } } } } }
Recast_t* CRecastContainer::Load(RECASTTYPE type, uint16 id, uint32 duration, uint32 chargeTime, uint8 maxCharges) { Recast_t* recast = GetRecast(type, id); if (recast == nullptr) { Recast_t* newRecast = new Recast_t; newRecast->ID = id; newRecast->TimeStamp = time(nullptr); newRecast->RecastTime = duration; newRecast->chargeTime = chargeTime; newRecast->maxCharges = maxCharges; GetRecastList(type)->push_back(newRecast); return newRecast; } else { if (chargeTime == 0) { recast->TimeStamp = time(nullptr); recast->RecastTime = duration; } else { if (recast->RecastTime == 0) { recast->TimeStamp = time(nullptr); } recast->RecastTime += chargeTime; recast->chargeTime = chargeTime; recast->maxCharges = maxCharges; } return recast; } }
void CRecastContainer::ResetAbilities() { RecastList_t* PRecastList = GetRecastList(RECAST_ABILITY); uint32 timestamp = 0; uint32 recastTime = 0; Recast_t* twoHour = GetRecast(RECAST_ABILITY, 0); if (twoHour != nullptr) { timestamp = twoHour->TimeStamp; recastTime = twoHour->RecastTime; } PRecastList->clear(); if (twoHour != nullptr) { Recast_t* newTwoHour = new Recast_t; newTwoHour->ID = 0; newTwoHour->TimeStamp = timestamp; newTwoHour->RecastTime = recastTime; PRecastList->push_back(newTwoHour); } Sql_Query(SqlHandle, "DELETE FROM char_recast WHERE charid = %u AND id != 0;", m_PChar->id); }
void CRecastContainer::DeleteByIndex(RECASTTYPE type, uint8 index) { RecastList_t* PRecastList = GetRecastList(type); delete PRecastList->at(index); PRecastList->erase(PRecastList->begin() + index); }