Pastebin

New pastes are no longer accepted · Stats

Latest Pastes

wedding

void world_execute_weddings(void *world_void)
{
    World *world = static_cast<World *>(world_void);

    double now = Timer::GetTime();

    UTIL_FOREACH(world->maps, map)
    {
        UTIL_FOREACH(map->npcs, npc)
        {
            if (npc->marriage && npc->marriage->request_accepted)
            {
                if (!npc->marriage->partner[0] || !npc->marriage->partner[1])
                {
                    npc->ShowDialog(world->i18n.Format("wedding_error"));
                    npc->marriage = 0;

                    continue;
                }
                else if (!npc->marriage->partner[0]->online || !npc->marriage->partner[1]->online)
                {
                    npc->ShowDialog(world->i18n.Format("wedding_missingpartner"));
                    npc->marriage = 0;

                    continue;
                }
                else if (npc->marriage->partner[0]->map != npc->map || npc->marriage->partner[1]->map != npc->map)
                {
                    npc->ShowDialog(world->i18n.Format("wedding_missingpartner"));
                    npc->marriage = 0;

                    continue;
                }
                else if ((npc->marriage->state == 5 && npc->marriage->partner_accepted[0]) || (npc->marriage->state == 8 && npc->marriage->partner_accepted[1]))
                {
                    ++npc->marriage->state;
                }
                else if (npc->marriage->last_execution + (util::to_int(world->config["PriestDialogInterval"])) <= now)
                {
                    switch (npc->marriage->state)
                    {
                        case 1:
                        {
                            npc->ShowDialog(world->i18n.Format("wedding_text1", util::ucfirst(npc->marriage->partner[0]->name), util::ucfirst(npc->marriage->partner[1]->name)));
                            ++npc->marriage->state;
                        }
                        break;

                        case 2:
                        {
                            npc->ShowDialog(world->i18n.Format("wedding_text2"));
                            ++npc->marriage->state;
                        }
                        break;

                        case 3:
                        {
                            npc->ShowDialog(world->i18n.Format("wedding_doyou", util::ucfirst(npc->marriage->partner[0]->name), util::ucfirst(npc->marriage->partner[1]->name)));
                            ++npc->marriage->state;
                        }
                        break;

                        case 4:
                        {
                            PacketBuilder builder(PACKET_PRIEST, PACKET_REPLY);
                            builder.AddChar(PRIEST_REQUEST);
                            npc->marriage->partner[0]->player->client->Send(builder);
                            ++npc->marriage->state;
                        }
                        break;

                        case 5:
                        {
                            ++npc->marriage->state;
                        }
                        break;

                        case 6:
                        {
                            npc->ShowDialog(world->i18n.Format("wedding_doyou", util::ucfirst(npc->marriage->partner[1]->name), util::ucfirst(npc->marriage->partner[0]->name)));
                            ++npc->marriage->state;
                        }
                        break;

                        case 7:
                        {
                            PacketBuilder builder(PACKET_PRIEST, PACKET_REPLY);
                            builder.AddChar(PRIEST_REQUEST);
                            npc->marriage->partner[1]->player->client->Send(builder);
                            ++npc->marriage->state;
                        }
                        break;

                        case 8:
                        {
                            ++npc->marriage->state;
                        }
                        break;

                        case 9:
                        {
                            npc->ShowDialog(world->i18n.Format("wedding_ring1"));
                            ++npc->marriage->state;
                        }
                        break;

                        case 10:
                        {
                            PacketBuilder builder(PACKET_ITEM, static_cast<PacketAction>(26));
                            builder.AddShort(util::to_int(world->config["WeddingRing"]));
                            builder.AddThree(1);
                            for (int i = 0; i < 2; ++i)
                            {
                                npc->marriage->partner[i]->AddItem(util::to_int(world->config["WeddingRing"]), 1);
                                npc->marriage->partner[i]->player->client->Send(builder);
                            }
                            ++npc->marriage->state;
                        }

                        case 11:
                        {
                            npc->ShowDialog(world->i18n.Format("wedding_ring2"));
                            ++npc->marriage->state;
                        }
                        break;

                        case 12:
                        {
                            int effect = util::to_int(util::explode(',', world->config["WeddingEffects"])[0]);

                            for (int i = 0; i < 2; ++i)
                                npc->marriage->partner[i]->Effect(effect);

                            npc->ShowDialog(world->i18n.Format("wedding_finish1", util::ucfirst(npc->marriage->partner[0]->name), util::ucfirst(npc->marriage->partner[1]->name)));
                            ++npc->marriage->state;
                        }
                        break;

                        case 13:
                        {
                            int effect = util::to_int(util::explode(',', world->config["WeddingEffects"])[1]);

                            for (int i = 0; i < 2; ++i)
                                npc->marriage->partner[i]->Effect(effect);

                            ++npc->marriage->state;
                        }
                        break;

                        case 14:
                        {
                            npc->ShowDialog(world->i18n.Format("wedding_finish2"));

                            PacketBuilder reply;
                            reply.SetID(PACKET_JUKEBOX, PACKET_USE);
                            reply.AddShort(util::rand(7, 20));

                            UTIL_FOREACH(npc->marriage->partner[0]->map->characters, character)
                            {
                                character->player->client->Send(reply);
                            }

                            int effect = util::to_int(util::explode(',', world->config["WeddingEffects"])[2]);

                            for (int i = 0; i < 2; ++i)
                                npc->marriage->partner[i]->Effect(effect);

                            npc->marriage->partner[0]->partner = npc->marriage->partner[1]->name;
                            npc->marriage->partner[0]->fiance = "";

                            npc->marriage->partner[1]->partner = npc->marriage->partner[0]->name;
                            npc->marriage->partner[1]->fiance = "";
                            npc->marriage = 0;
                        }
                        break;

                        default:

                        Console::Err("Invalid state for marriage ceremony.");
                        npc->marriage = 0;
                    }

                    if (npc->marriage)
                    npc->marriage->last_execution = Timer::GetTime();
                }
            }
        }
    }
}