Пример #1
0
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;
}
Пример #2
0
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;
                }
		    }
	    }
    }
}
Пример #3
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;
}
Пример #4
0
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;
        }
    }
}
Пример #5
0
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);
}
Пример #6
0
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();
}
Пример #7
0
void CRecastContainer::Del(RECASTTYPE type)
{
    RecastList_t* PRecastList = GetRecastList(type);

    for (uint16 i = 0; i < PRecastList->size(); ++i)
	{
        delete PRecastList->at(i);
	}
    PRecastList->clear();
}
Пример #8
0
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;
    }
}
Пример #9
0
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);
}
Пример #10
0
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;
}
Пример #11
0
void CRecastContainer::ResetAbilities()
{
    RecastList_t* PRecastList = GetRecastList(RECAST_ABILITY);

    for (auto&& recast : *PRecastList)
    {
        if (recast.ID != 0)
        {
            Load(RECAST_ABILITY, recast.ID, 0);
        }
    }
}
Пример #12
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);
	    }
    }
}
Пример #13
0
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);
    }
}
Пример #14
0
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;
}
Пример #15
0
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;
}
Пример #16
0
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;
        }
	}
}
Пример #17
0
void CRecastContainer::Del(RECASTTYPE type)
{
    RecastList_t* PRecastList = GetRecastList(type);
    if (type == RECAST_ABILITY)
    {
        for (auto&& recast : *PRecastList)
        {
            recast.RecastTime = 0;
        }
    }
    else
    {
        PRecastList->clear();
    }
}
Пример #18
0
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;
        }
	}
}
Пример #19
0
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());
    }
}
Пример #20
0
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);
    }
}
Пример #21
0
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;
                }
            }
        }
    }
}
Пример #22
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;
    }
}
Пример #23
0
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);
}
Пример #24
0
void CRecastContainer::DeleteByIndex(RECASTTYPE type, uint8 index)
{
	RecastList_t* PRecastList = GetRecastList(type);
	delete PRecastList->at(index);
	PRecastList->erase(PRecastList->begin() + index);
}