Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Character.CPP
- In:
- Character::Character(std::string name, World *world)
- Add: (Around line 350)
- this->pet = 0;
- this->has_pet = false;
- this->pet_transfer = false;
- Now we need to add some new functions:
- void Character::KillPet()
- {
- if(!this->pet)
- {
- return;
- }
- if(this->has_pet)
- {
- UTIL_FOREACH(this->pet->map->characters, character)
- {
- if(character->InRange(this->pet))
- {
- this->pet->RemoveFromView(character);
- }
- }
- this->has_pet = false;
- //this->pet->RemoveFromView(this->player->character);
- this->pet->map->npcs.erase(
- std::remove(this->pet->map->npcs.begin(), this->pet->map->npcs.end(), this->pet),
- this->pet->map->npcs.end());
- }
- }
- void Character::SpawnPet(int pet)
- {
- if(!this->map->GetTile(this->x, this->y).Walkable(false))
- {
- this->StatusMsg("You are unable to summon at this time.");
- this->has_pet = false;
- return;
- }
- unsigned char index = this->map->GenerateNPCIndex();
- if (index > 250)return;
- this->pet = new NPC(this->map, pet, this->x, this->y, 1, 1, index, true, true);
- this->pet->SetOwner(this);
- this->map->npcs.push_back(this->pet);
- this->pet->Spawn();
- }
- void Character::PetTransfer()
- {
- bool pettransfer = false;
- bool following = this->pet->following;
- bool guarding = this->pet->guarding;
- bool attacking = this->pet->attacking;
- if(this->has_pet && !this->pet_transfer)
- {
- UTIL_FOREACH(this->pet->map->characters, character)
- {
- if (character->InRange(this->pet))
- {
- this->pet->RemoveFromView(character);
- }
- }
- //this->pet->RemoveFromView(this->player->character);
- this->pet->map->npcs.erase(
- std::remove(this->pet->map->npcs.begin(), this->pet->map->npcs.end(), this->pet),
- this->pet->map->npcs.end());
- this->has_pet = false;
- pettransfer = true;
- }
- if(!this->has_pet && pettransfer == true)
- {
- unsigned char index = this->map->GenerateNPCIndex();
- if (index > 250)
- {
- return;
- }
- if(!this->map->Walkable(this->x, this->y))
- {
- this->StatusMsg("Your summon was despawned due to being off-map");
- return;
- }
- this->pet = new NPC(this->map, this->pet->id, this->x, this->y, 1, 1, index, true, true);
- this->pet->SetOwner(this);
- this->map->npcs.push_back(this->pet);
- this->pet->Spawn();
- this->has_pet = true;
- if(following) this->pet->following = true;
- else if(attacking) this->pet->attacking = true;
- else if(guarding) this->pet->guarding = true;
- }
- }
- #Character.HPP
- In:
- class Character : public Command_Source
- {
- public:
- Add: (Around Line 170)
- NPC *pet;
- bool has_pet;
- bool pet_transfer;
- void PetTransfer();
- void KillPet();
- void SpawnPet(int pet);
- #NPC.HPP
- In:
- class NPC
- {
- public:
- Add:
- bool pet;
- Character *owner;
- bool following = false;
- bool attacking = false;
- bool guarding = false;
- NPC *pet_target = 0;
- void SetOwner(Character *character);
- void Pet(NPC *npc);
- void PetDamage(NPC *from, int amount, int spell_id = -1);
- void WalkXY(int x, int y);
- void DirectionNeeded(int x, int y);
- Then find:
- NPC(Map *map, short id, unsigned char x, unsigned char y, unsigned char spawn_type, short spawn_time, unsigned char index, bool temporary = false);
- and add bool pet = false, Character *owner = 0; in the brackets.
- It should look like this:
- NPC(Map *map, short id, unsigned char x, unsigned char y, unsigned char spawn_type, short spawn_time, unsigned char index, bool temporary = false, bool pet = false, Character *owner = 0);
- #NPC.CPP
- Change:
- NPC::NPC(Map *map, short id, unsigned char x, unsigned char y, unsigned char spawn_type, short spawn_time, unsigned char index, bool temporary)
- To:
- NPC::NPC(Map *map, short id, unsigned char x, unsigned char y, unsigned char spawn_type, short spawn_time, unsigned char index, bool temporary, bool pet, Character* owner)
- Also add this in the function:
- this->owner = owner;
- this->pet = pet;
- In NPC::Act() find:
- Character *attacker = 0;
- unsigned char attacker_distance = static_cast<int>(this->map->world->config["NPCChaseDistance"]);
- unsigned short attacker_damage = 0;
- And add this below it:
- if(this->Data().type == ENF::Pet)
- {
- if(!this->owner)
- {
- this->Die();
- return;
- }
- if(this->owner)
- {
- if(this->following || (this->guarding && !this->pet_target))
- {
- int distance_to_owner = util::path_length(this->owner->x, this->owner->y, this->x, this->y);
- if(distance_to_owner > 2)
- {
- this->WalkXY(this->owner->x, this->owner->y);
- return;
- }
- if(distance_to_owner > 7)
- {
- this->owner->PetTransfer();
- }
- }
- else if(this->guarding || this->attacking)
- {
- if(this->attacking && !this->pet_target)
- {
- NPC *closest = 0;
- unsigned char closest_distance = static_cast<int>(this->map->world->config["NPCChaseDistance"]);
- UTIL_FOREACH(this->map->npcs, npc)
- {
- int distance = util::path_length(npc->x, npc->y, this->x, this->y);
- if (distance < closest_distance)
- {
- closest = npc;
- closest_distance = distance;
- }
- }
- if(closest)
- {
- this->pet_target = closest;
- }
- }
- if(this->pet_target)
- {
- if(util::path_length(this->pet_target->x, this->pet_target->y, this->x, this->y < 8))
- {
- int dist = util::path_length(this->pet_target->x, this->pet_target->y, this->x, this->y);
- if(dist > 1)
- {
- WalkXY(this->pet_target->x, this->pet_target->y);
- return;
- }
- else
- {
- this->DirectionNeeded(this->pet_target->x, this->pet_target->y);
- // This should be handled when attacking, but what ever.
- UTIL_FOREACH(this->map->characters, character)
- {
- PacketBuilder builder(PACKET_NPC, PACKET_PLAYER, 18);
- builder.AddByte(255);
- builder.AddChar(this->index);
- builder.AddChar(1 + (character->hp == 0));
- builder.AddChar(this->direction);
- builder.AddShort(0);
- builder.AddThree(0);
- builder.AddThree(this->pet_target->hp);
- builder.AddByte(255);
- builder.AddByte(255);
- if(!character->InRange(this))
- {
- continue;
- }
- character->Send(builder);
- }
- //
- int dmg = util::rand(this->Data().mindam, this->Data().maxdam);
- return;
- }
- }
- else
- {
- this->pet_target = 0;
- }
- }
- }
- }
- }
- Next goto void NPC::Killed(Character *from, int amount, int spell_id)
- Under:
- this->alive = false;
- Add:
- if(this->pet)
- {
- this->owner->StatusMsg("Your summon died...");
- this->owner->has_pet = 0;
- this->owner->pet = 0;
- }
- Now we need to add some functions:
- void NPC::Pet(NPC *npc)
- {
- this->pet = npc;
- }
- void NPC::SetOwner(Character *character)
- {
- this->owner = character;
- }
- void NPC::DirectionNeeded(int x, int y)
- {
- int xdiff = this->x - x;
- int ydiff = this->y - y;
- int absxdiff = std::abs(xdiff);
- int absydiff = std::abs(ydiff);
- if (absxdiff > absydiff)
- {
- if (xdiff < 0)
- {
- this->direction = DIRECTION_RIGHT;
- }
- else
- {
- this->direction = DIRECTION_LEFT;
- }
- }
- else
- {
- if (ydiff < 0)
- {
- this->direction = DIRECTION_DOWN;
- }
- else
- {
- this->direction = DIRECTION_UP;
- }
- }
- }
- void NPC::WalkXY(int x, int y)
- {
- int xdiff = this->x - x;
- int ydiff = this->y - y;
- int absxdiff = std::abs(xdiff);
- int absydiff = std::abs(ydiff);
- if ((absxdiff == 1 && absydiff == 0) || (absxdiff == 0 && absydiff == 1) || (absxdiff == 0 && absydiff == 0))
- {
- //this->Attack(attacker);
- return;
- }
- else if (absxdiff > absydiff)
- {
- if (xdiff < 0)
- {
- this->direction = DIRECTION_RIGHT;
- }
- else
- {
- this->direction = DIRECTION_LEFT;
- }
- }
- else
- {
- if (ydiff < 0)
- {
- this->direction = DIRECTION_DOWN;
- }
- else
- {
- this->direction = DIRECTION_UP;
- }
- }
- if (!this->Walk(this->direction))
- {
- this->Walk(static_cast<Direction>(util::rand(0,3)));
- }
- return;
- }
- void NPC::PetDamage(NPC *from, int amount, int spell_id)
- {
- int limitamount = std::min(this->hp, amount);
- if (this->map->world->config["LimitDamage"])
- {
- amount = limitamount;
- }
- if (this->Data().type == ENF::Passive || this->Data().type == ENF::Aggressive)
- {
- this->hp -= amount;
- }
- else
- {
- this->hp = 0;
- amount = 0;
- }
- if (this->totaldamage + limitamount > this->totaldamage)
- this->totaldamage += limitamount;
- NPC_Opponent *opponent(new NPC_Opponent);
- bool found = false;
- UTIL_FOREACH(this->damagelist, checkopp)
- {
- if (checkopp->attacker == from->owner)
- {
- found = true;
- if (checkopp->damage + limitamount > checkopp->damage)
- checkopp->damage += limitamount;
- checkopp->last_hit = Timer::GetTime();
- }
- }
- if (!found)
- {
- opponent->attacker = from->owner;
- opponent->damage = limitamount;
- opponent->last_hit = Timer::GetTime();
- this->damagelist.push_back(opponent);
- opponent->attacker->unregister_npc.push_back(this);
- }
- if (this->hp > 0)
- {
- PacketBuilder builder(spell_id == -1 ? PACKET_NPC : PACKET_CAST, PACKET_REPLY, 14);
- if (spell_id != -1)
- builder.AddShort(spell_id);
- builder.AddShort(from->index);
- builder.AddChar(from->direction);
- builder.AddShort(this->index);
- builder.AddThree(amount);
- builder.AddShort(util::clamp<int>(double(this->hp) / double(this->Data().hp) * 100.0, 0, 100));
- if (spell_id != -1)
- builder.AddShort(from->owner->tp);
- else
- builder.AddChar(1); // ?
- UTIL_FOREACH(this->map->characters, character)
- {
- if (character->InRange(this))
- {
- character->Send(builder);
- }
- }
- }
- else
- {
- if(this == from->pet_target)
- {
- from->pet_target = 0;
- }
- this->Killed(from->owner, amount, spell_id);
- }
- }
- #EODATA.HPP
- In:
- class ENF
- {
- public:
- enum Type
- {
- Add:
- Pet
- #MAP.CPP
- #Now this you may want to change to your likings:
- Find: npc->Damage(from, amount);
- In:
- void Map::Attack(Character *from, Direction direction)
- And add this below:
- if(from->has_pet)
- {
- if(!from->pet->following && from->pet->pet_target == 0)
- {
- from->pet->pet_target = npc;
- }
- }
- ### SPAWNING
- ## For item spawning:
- handlers/item.cpp
- Find:
- switch (item.type)
- {
- case EIF::Teleport:
- {
- Now add this first inside the brackets:
- if(item.scrollmap != 0 && item.scrollx == 252)
- {
- if(character->has_pet)
- {
- character->KillPet();
- character->has_pet = false;
- break;
- }
- character->SpawnPet(item.scrollmap);
- character->has_pet = true;
- character->pet->guarding = true;
- if(item.scrolly == 1)
- {
- break;
- }
- }
- ## For spawning via spells:
- #MAP.CPP
- Find:
- void Map::SpellSelf(Character *from, unsigned short spell_id)
- {
- Add this below from->tp -= spell.tp;
- if(spell.mindam == 123)
- {
- std::string n_name = this->world->enf->Get(spell.maxdam).name;
- if(!from->has_pet)
- {
- from->SpawnPet(spell.maxdam);
- from->has_pet = true;
- from->pet->guarding = true;
- from->StatusMsg("You summoned a "+n_name+"!");
- }
- else
- {
- if(from->pet->id == spell.maxdam)
- {
- from->StatusMsg("You despawned your "+n_name+"!");
- from->KillPet();
- from->has_pet = false;
- return; // no tp for reclaiming
- }
- else
- {
- std::string old_name = this->world->enf->Get(from->pet->id).name;
- from->KillPet();
- from->SpawnPet(spell.maxdam);
- from->has_pet = true;
- from->pet->guarding = true;
- from->StatusMsg("You replaced your "+old_name+" with a "+n_name);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement