What's new

-Tibia 7.60 [7.6] Corpse Loot Owner

Status
Not open for further replies.

Thorge D

Advanced User
Joined
Jul 24, 2014
Messages
300
Reaction score
29
1. Autor: Baabuseek
2. Link do oryginalnego tematu:
3. Opis: Loot z cia?a jest dost?pny przez ile? sekund (do ustawienia w config.lua) tylko dla osoby kt?ra zada?a najwi?ksze obra?enia dla danego potwora,
Wszyscy inni kt?rzy uczestniczyli w walce lub nie przez ten czas nie mog? otworzy? ani przesun?? cia?a.
W przypadku party mo?e to zrobi? ka?dy jego uczestnik.

4. Kod:

w actions.cpp pod
[CPP]#include "item.h"[/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
#include <sstream>
#endif //BBK_LOOT_OWNER [/CPP]
dalej w actions.cpp szukamy:
[CPP]#ifdef TLM_HOUSE_SYSTEM
if (Item::items[itemid].isDoor)
{
Tile* tile = game->getTile(pos);
House* house = tile? tile->getHouse() : NULL;

if (house && player->access < g_config.ACCESS_HOUSE && house->getPlayerRights(pos, player->getName()) <= HOUSE_GUEST)
{
player->sendCancel("You are not allowed to open this door.");
return false;
}
}
#endif //TLM_HOUSE_SYSTEM [/CPP]
i dodajemy pod:
[CPP]#ifdef _BBK_LOOT_OWNER
if(item->getOwner() != "" && player->getName() != item->getOwner() && (player->party == 0 || game->getPlayerByName(item->getOwner())->party == 0 || player->party != game->getPlayerByName(item->getOwner())->party)){
std::stringstream info;
if(item->getOwnerTime() > g_config.getGlobalNumber("ownerTime", 30)){
info << "Nie jestes wlascicielem. Poczekaj 1 sekunde.";
}else{
info << "Nie jestes wlascicielem. Poczekaj " << item->getOwnerTime() << (item->getOwnerTime()>4?" sekund.":(item->getOwnerTime()>1?" sekundy.":(item->getOwnerTime()>0?" sekunde.":" sekund.")));
}
player->sendCancel(info.str().c_str());
return false;
}
#endif //BBK_LOOT_OWNER [/CPP]
w game.cpp pod:
[CPP]//Get all creatures that will gain xp from this kill..
CreatureState* attackedCreatureState = NULL;
std::vector<long> creaturelist;
if(!(dynamic_cast<Player*>(attackedCreature) && game->getWorldType() != WORLD_TYPE_PVP_ENFORCED)){
creaturelist = attackedCreature->getInflicatedDamageCreatureList();
CreatureStateVec& creatureStateVec = creaturestates[tile];
for(CreatureStateVec::iterator csIt = creatureStateVec.begin(); csIt != creatureStateVec.end(); ++csIt) {
if(csIt->first == attackedCreature) {
attackedCreatureState = &csIt->second;
break;
}
}
} [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
Player *highPlayer = NULL;
exp_t gainExp = 0;
#endif //BBK_LOOT_OWNER [/CPP]
troszke ni?ej pod:
[CPP]Player *gainExpPlayer = dynamic_cast<Player*>(gainExpCreature);

if(gainExpPlayer) {
gainExpPlayer->addExp(gainedExperience); [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
if(gainExp < gainedExperience){
highPlayer = gainExpPlayer;
gainExp = gainedExperience;
}
#endif //BBK_LOOT_OWNER [/CPP]
dalej w game.cpp pod:
[CPP]//Add creature to attackerlist
attackedCreatureState->attackerlist.push_back(gainExpCreature);
}
}
}

Player *player = dynamic_cast<Player*>(attacker);
if(player){
player->sendStats(); [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
game->startOwner(corpseitem, highPlayer);
#endif //BBK_LOOT_OWNER [/CPP]
dalej w game.cpp w funkcji:
[CPP]bool Game::eek:nPrepareMoveThing(Creature* player, const Thing* thing,
const Position& fromPos, const Position& toPos, int count)
{[/CPP]
pod:
[CPP]else {
const Item* item = dynamic_cast<const Item*>(thing);
if(item) { [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
Item *aitem = const_cast<Item*>(item);
if(aitem->getOwner() != "" && player->getName() != aitem->getOwner() && (dynamic_cast<Player*>(player)->party == 0 || getPlayerByName(aitem->getOwner())->party == 0 || dynamic_cast<Player*>(player)->party != getPlayerByName(aitem->getOwner())->party)){
std::stringstream info;
if(aitem->getOwnerTime() > g_config.getGlobalNumber("ownerTime", 30)){
info << "Nie jestes wlascicielem. Poczekaj 1 sekunde.";
}else{
info << "Nie jestes wlascicielem. Poczekaj " << aitem->getOwnerTime() << (aitem->getOwnerTime()>4?" sekund.":(aitem->getOwnerTime()>1?" sekundy.":(aitem->getOwnerTime()>0?" sekunde.":" sekund.")));
}
player->sendCancel(info.str().c_str());
return false;
}
#endif //BBK_LOOT_OWNER [/CPP]
dalej w game.cpp nad:
[CPP]void Game::checkSpawns(int t)
{
OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "Game::checkSpawns()"); [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
void Game::startOwner(Item* item, Player* player){
if(item->getOwner() != "")
return;
item->setOwner(player->getName());
//item->setOwnerTime(30);
item->setOwnerTime(g_config.getGlobalNumber("ownerTime", 30));
unsigned long otime = g_config.getGlobalNumber("ownerTime", 30);
if(otime == 0)
return;
if(otime < g_config.getGlobalNumber("ownerTime", 30))
otime = g_config.getGlobalNumber("ownerTime", 30);
//otime = (otime/30)+30;
item->useThing();
list<ownerBlock*>::iterator it;
for(it = ownerVector.begin();it != ownerVector.end();it++){
if((*it)->ownerTime == otime){
(*it)->ownerItems.push_back(item);
return;
}
}
ownerBlock* db = new ownerBlock;
db->ownerTime = otime;
db->ownerItems.clear();
db->ownerItems.push_back(item);
ownerVector.push_back(db);
}
#endif //BBK_LOOT_OWNER [/CPP]
i nad:
[CPP]#ifdef YUR_CMD_EXT
void Game::setMaxPlayers(uint32_t newmax)
{
OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "Game::setMaxPlayers()");
max_players = newmax;
Status::instance()->playersmax = newmax;
}
#endif //YUR_CMD_EXT [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
long Game::checkOwner()
{
OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "Game::checkOwner()");

list<ownerBlock*>::iterator it;
for(it = ownerVector.begin();it != ownerVector.end();){
(*it)->ownerTime -= 1;

list<Item*>::iterator it5;
for(it5 = (*it)->ownerItems.begin(); it5 != (*it)->ownerItems.end(); it5++){
Item* item = *it5;
int sot = item->getOwnerTime()-1;
item->setOwnerTime(sot);
}
if((*it)->ownerTime <= 0){
list<Item*>::iterator it2;
for(it2 = (*it)->ownerItems.begin(); it2 != (*it)->ownerItems.end(); it2++){
Item* item = *it2;
item->setOwner("");
}
delete *it;
it = ownerVector.erase(it);
}
else{
it++;
}
}
addEvent(makeTask(1000, std::mem_fun(&Game::checkOwner)));
}
#endif //BBK_LOOT_OWNER [/CPP]
w item.cpp w funkcji:
[CPP]Item::Item(const unsigned short _type) { [/CPP]
pod:
[CPP]isDecaying = 0;
specialDescription = NULL;
text = NULL; [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
owner = NULL;
ownerTime = 0;
#endif //BBK_LOOT_OWNER [/CPP]
dalej w item.cpp w funkcji:
[CPP]Item::Item(const Item &i){ [/CPP]
pod:
[CPP]if(i.specialDescription != NULL){
specialDescription = new std::string(*(i.specialDescription));
}
else{
specialDescription = NULL;
}
if(i.text != NULL){
text = new std::string(*(i.text));
}
else{
text = NULL;
} [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
owner = NULL;
ownerTime = 0;
#endif //BBK_LOOT_OWNER [/CPP]
w funkcji:
[CPP]Item::Item(const unsigned short _type, unsigned short _count) { [/CPP]
pod:
[CPP]isDecaying = 0;
specialDescription = NULL;
text = NULL; [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
owner = NULL;
ownerTime = 0;
#endif //BBK_LOOT_OWNER [/CPP]
dalej w item.cpp w funkcji:
[CPP]Item::Item()
{ [/CPP]
pod:
[CPP]uniqueId = 0;
specialDescription = NULL;
text = NULL; [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
owner = NULL;
ownerTime = 0;
#endif //BBK_LOOT_OWNER [/CPP]
ci?gle w item.cpp, znajdujemy:
[CPP]if(text){
s.str(""); //empty the stringstream
s << *text;
xmlSetProp(ret, (const xmlChar*)"text", (const xmlChar*)s.str().c_str());
} [/CPP]
i dodajemy pod:
[CPP]#ifdef _BBK_LOOT_OWNER
if(owner){ //No need to save if text is empty..
s.str(""); //empty the stringstream
s << *owner;
xmlSetProp(ret, (const xmlChar*)"owner", (const xmlChar*)s.str().c_str());
}
if(ownerTime){ //No need to save if text is empty..
s.str(""); //empty the stringstream
s << *ownerTime;
xmlSetProp(ret, (const xmlChar*)"ownerTime", (const xmlChar*)s.str().c_str());
}
#endif //BBK_LOOT_OWNER [/CPP]
na samym dole tego pliku (item.cpp) dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
std::string Item::getOwner()
{
if(!owner)
return std::string("");
return *owner;
}
void Item::setOwner(std::string name){
if(owner){
delete owner;
owner = NULL;
}
if(name.length() > 1){
owner = new std::string(name);
}
}

int Item::getOwnerTime()
{
if(!ownerTime)
return int("");
return *ownerTime;
}
void Item::setOwnerTime(int time){
if(ownerTime){
delete ownerTime;
ownerTime = NULL;
}
if(time > 1){
ownerTime = new int(time);
}
}
#endif //BBK_LOOT_OWNER [/CPP]
przechodzimy do otserv.cpp
szukamy:
[CPP]#ifdef YUR_READABLES
std::cout << ":: Loading readables.xml... ";
if (!Readables::Load(&g_game))
{
ErrorMessage("Could not load readables.xml!");
return -1;
}
std::cout << "[done]" << std::endl;
#endif //YUR_READABLES [/CPP]
i dodajemy pod:
[CPP]#ifdef _BBK_LOOT_OWNER
g_game.addEvent(makeTask(1000, std::mem_fun(&Game::checkOwner)));
#endif //BBK_LOOT_OWNER [/CPP]
w game.h szukamy:
[CPP]#ifdef YUR_CMD_EXT
void setMaxPlayers(uint32_t newmax);
#endif //YUR_CMD_EXT [/CPP]
i dodajemy pod:
[CPP]#ifdef _BBK_LOOT_OWNER
long checkOwner();
#endif //BBK_LOOT_OWNER [/CPP]
dalej w game.h pod:
[CPP]void checkDecay(int t); [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
void startOwner(Item* item, Player* player);
struct ownerBlock{
long ownerTime;
std::list<Item*> ownerItems;
};
std::list<ownerBlock*> ownerVector;
#endif //BBK_LOOT_OWNER [/CPP]
w item.h pod:
[CPP]std::string *specialDescription;
std::string *text; //text written [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
std::string *owner;
int *ownerTime;
#endif //BBK_LOOT_OWNER [/CPP]
dalej w item.h pod:
[CPP]private:
int useCount;

public: [/CPP]
dodajemy:
[CPP]#ifdef _BBK_LOOT_OWNER
std::string Item::getOwner();
void setOwner(std::string name);
int Item::getOwnerTime();
void setOwnerTime(int time);
#endif //BBK_LOOT_OWNER [/CPP]
na koniec dodajemy do projektu:
Code:
-D_BBK_LOOT_OWNER

i do config.lua:
[LUA]-- OWNER TIME
ownerTime = 30 [/LUA]

Tyle.
 
Status
Not open for further replies.
Top